[Winpt-commits] r344 - trunk/Src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sun Nov 27 15:56:53 CET 2011
Author: twoaday
Date: 2011-11-27 15:56:52 +0100 (Sun, 27 Nov 2011)
New Revision: 344
Modified:
trunk/Src/ChangeLog
trunk/Src/wptKeyEditDlgs.cpp
trunk/Src/wptKeygenDlg.cpp
trunk/Src/wptPassphraseCB.cpp
Log:
Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog 2011-11-27 13:28:00 UTC (rev 343)
+++ trunk/Src/ChangeLog 2011-11-27 14:56:52 UTC (rev 344)
@@ -3,6 +3,14 @@
* WinPT.cpp (check_os_version): New. Separated
function to check the OS verson.
Removed emulate utf8 bug legacy code.
+ * wptKeygenDlg.cpp (gpg_genkey_params): Use the bits
+ also for the primary key since we are now supporting DSAv2.
+ (keygen_wizard_dlg_proc): Adjusted for DSAv2.
+ * wptKeyEditDlgs.cpp (is_jpg_file): Modernized.
+ (keyedit_addsubkey_dlg_proc): Removed 1024-bit DSA check
+ and rewrote index to gpg menu mapping. Fixed wrong text label.
+
+ * Integrated patches from Remi FAVIER.
2007-08-03 Timo Schulz <twoaday at gmx.net>
Modified: trunk/Src/wptKeyEditDlgs.cpp
===================================================================
--- trunk/Src/wptKeyEditDlgs.cpp 2011-11-27 13:28:00 UTC (rev 343)
+++ trunk/Src/wptKeyEditDlgs.cpp 2011-11-27 14:56:52 UTC (rev 344)
@@ -1,5 +1,5 @@
/* wptKeyEditDlgs.cpp - GPG key edit dialogs
- * Copyright (C) 2002-2009 Timo Schulz
+ * Copyright (C) 2002-2009, 2011 Timo Schulz
*
* This file is part of WinPT.
*
@@ -303,16 +303,14 @@
bool
is_jpg_file (const char *fname)
{
- FILE *fp;
- BYTE buf[10];
- int n;
-
- fp = fopen (fname, "rb");
+ FILE *fp = fopen (fname, "rb");
if (!fp)
return false;
- n = fread (buf, 1, DIM (buf), fp);
+
+ BYTE buf[10];
+ size_t n = fread (buf, 1, DIM (buf), fp);
fclose (fp);
- if (n < (int)DIM (buf))
+ if (n < DIM (buf))
return false;
return buf[6] == 'J' && buf[7] == 'F' &&
buf[8] == 'I' && buf[9] == 'F';
@@ -626,6 +624,22 @@
}
+/* Helper to map dialog indexes to GPG addkey commands */
+typedef struct subkey_menu_t {
+ int index;
+ const char *text;
+ int gpg_index;
+ gpgme_pubkey_algo_t algo;
+};
+subkey_menu_t SUBKEY_MENU[] = {
+ {0, _("DSA (sign only)"), 3, GPGME_PK_DSA},
+ {1, _("ElGamal (encrypt only)"), 4, GPGME_PK_ELG_E},
+ {2, _("RSA (sign only)"), 5, GPGME_PK_RSA_E},
+ {3, _("RSA (encrypt only)"), 6, GPGME_PK_RSA_S}
+};
+#define N_SUBKEY_MENU 4
+
+
/* Dialog procedure for adding a new secondary key. */
BOOL CALLBACK
keyedit_addsubkey_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
@@ -650,10 +664,9 @@
SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO);
- listbox_add_string (hwnd, _("DSA (sign only)"));
- listbox_add_string (hwnd, _("ElGamal (encrypt only)"));
- listbox_add_string (hwnd, _("RSA (sign only)"));
- listbox_add_string (hwnd, _("RSA (encrypt only)"));
+ for (int i=0; i < N_SUBKEY_MENU; i++) {
+ listbox_add_string (hwnd, SUBKEY_MENU[i].text);
+ }
CheckDlgButton (dlg, IDC_ADDSUBKEY_EXPIRE, BST_CHECKED);
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE);
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_SIZE), FALSE);
@@ -674,78 +687,41 @@
else
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), TRUE);
}
- if (HIWORD (wparam) == LBN_SELCHANGE &&
- LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) {
- /* If DSA is selected, we disable the selection box since it
- is hardocded to 2048-bit. */
- index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0);
- EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_SIZE),
- index != 0? TRUE : FALSE);
- }
switch (LOWORD (wparam)) {
case IDOK:
keygen = (keygen_cb_t)ctx->opaque;
if (!keygen)
BUG (NULL);
- hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO);
- int map[4];
- /* this is for GPG 1.4.9 */
- map[0] = 2;
- map[1] = 4;
- map[2] = 5;
- map[3] = 6;
- /* >1.4.10 changed the menu IDs. */
- if (gpgver[0] == 1 && gpgver[1] >= 4 && gpgver[2] > 9) {
- map[0] = 3;
- map[1] = 5;
- map[2] = 4;
- map[3] = 6;
- }
-
/* Map combo box numbers to GPG answers. */
- switch (listbox_get_cursel (hwnd)) {
- case 0:
- case 1:
- case 2:
- case 3:
- break;
- default:
+ hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO);
+ index = listbox_get_cursel (hwnd);
+ if (index < 0 || index > N_SUBKEY_MENU) {
show_balloon_msg (GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO),
_("Please select one entry."), IDI_ERROR);
return FALSE;
}
- index = map[listbox_get_cursel (hwnd)];
size = get_keysize_from_box (dlg, IDC_ADDSUBKEY_SIZE);
- if (index == 2) /* DSA */
- size = 2048;
-
- hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE);
- DateTime_GetSystemtime (hwnd, &st);
+
+ DateTime_GetSystemtime (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), &st);
valid = w32_mktime (&st) - time (NULL);
valid /= 86400;
-
- keygen->bits = size;
- switch (index) {
- case 2: keygen->algo = GPGME_PK_DSA; break;
- case 4: keygen->algo = GPGME_PK_ELG_E; break;
- case 5: keygen->algo = GPGME_PK_RSA_S; break;
- case 6: keygen->algo = GPGME_PK_RSA_E; break;
- }
if (valid > 0)
keygen->expire = time (NULL) + valid*24*60*60;
-
+ keygen->bits = size;
+ keygen->algo = SUBKEY_MENU[index].algo;
+
{
GpgKeyEdit ke;
passphrase_cb_s pcb;
- set_gpg_auto_passphrase_cb (&pcb, _("Add Revoker"));
+ set_gpg_auto_passphrase_cb (&pcb, _("Add Subkey"));
ke.setPassphraseCallback (passphrase_cb, (void*)&pcb);
ke.setKeyID (ctx->keyid);
ke.setCallback (keygen_cb, NULL);
keygen_cb_dlg_create ();
- err = ke.addSubkey ((gpgme_pubkey_algo_t)index, size, valid);
+ err = ke.addSubkey ((gpgme_pubkey_algo_t)SUBKEY_MENU[index].gpg_index, size, valid);
release_gpg_passphrase_cb (&pcb);
}
@@ -754,8 +730,7 @@
if (err)
msg_box (dlg, gpgme_strerror (err), _("Add Subkey"), MB_ERR);
else {
- msg_box (dlg, _("Subkey successfully added."),
- _("GnuPG Status"), MB_OK);
+ msg_box (dlg, _("Subkey successfully added."), _("GnuPG Status"), MB_OK);
ctx->finished = 1;
}
EndDialog (dlg, TRUE);
@@ -1065,8 +1040,8 @@
struct listview_column_s cols[] = {
{0, 80, (char *)_("Description")},
{1, 78, (char *)_("Key ID")},
- {2, 66, (char *)_("Creation")},
- {3, 66, (char *)_("Expires")},
+ {2, 72, (char *)_("Creation")},
+ {3, 72, (char *)_("Expires")},
{4, 64, (char *)_("Status")},
{5, 16, (char *) "C"/*ertify*/},
{6, 16, (char *) "S"/*ign*/},
Modified: trunk/Src/wptKeygenDlg.cpp
===================================================================
--- trunk/Src/wptKeygenDlg.cpp 2011-11-27 13:28:00 UTC (rev 343)
+++ trunk/Src/wptKeygenDlg.cpp 2011-11-27 14:56:52 UTC (rev 344)
@@ -53,8 +53,8 @@
Return value: the gen. params. */
static char*
gpg_genkey_params (int keytype, int bits,
- const char *user, const char *comment, const char *email,
- const char *expdate, const char *pass)
+ const char *user, const char *comment, const char *email,
+ const char *expdate, const char *pass)
{
StringBuffer p;
char *param;
@@ -68,22 +68,23 @@
case GPG_KEYGEN_DSA_ELG:
case GPG_KEYGEN_DSA_RSA:
p = p + "Key-Type: DSA\n";
- p = p + "Key-Usage: sign\n";
- p = p + "Key-Length: 2048\n";
break;
case GPG_KEYGEN_RSA_RSA:
p = p + "Key-Type: RSA\n";
- p = p + "Key-Usage: sign\n";
- p = p + "Key-Length: " + (int)bits + "\n";
break;
default:
break;
}
+
+ /* DSA v2 supports larger keys >1024 bits */
+ p = p + "Key-Usage: sign\n";
+ p = p + "Key-Length: " + (int)bits + "\n";
/* The next phase is the subkey information if needed. */
- if (keytype == GPG_KEYGEN_DSA_ELG || keytype == GPG_KEYGEN_DSA_RSA ||
+ if (keytype == GPG_KEYGEN_DSA_ELG ||
+ keytype == GPG_KEYGEN_DSA_RSA ||
keytype == GPG_KEYGEN_RSA_RSA) {
if (keytype == GPG_KEYGEN_DSA_ELG)
p = p + "Subkey-Type: ELG-E\n";
@@ -158,13 +159,9 @@
static bool
backup_keyrings (HWND dlg)
{
- const char *name;
- char *keyring;
- char *path;
bool success = true;
- int id;
- id = msg_box (dlg,
+ int id = msg_box (dlg,
_("It is STRONGLY recommend that you backup your keyrings because they both "
"contain VERY important data.\nRemember that your hard disk can crash or the "
"files can be deleted by accident; so it is a good\nidea to store them on "
@@ -174,11 +171,11 @@
if (id != IDYES)
return false;
- path = get_gnupg_path ();
- name = get_filesave_dlg (dlg, _("Destination for Public Keyring"),
+ char *path = get_gnupg_path ();
+ const char *name = get_filesave_dlg (dlg, _("Destination for Public Keyring"),
NULL, "pubring_bak.gpg");
if (name != NULL) {
- keyring = make_filename (path, "pubring", "gpg");
+ char *keyring = make_filename (path, "pubring", "gpg");
if (!CopyFile (keyring, name, FALSE)) {
log_box (_("Key Generation"), MB_ERR,
_("Could not copy %s -> %s"), keyring, name);
@@ -226,11 +223,8 @@
int
keygen_check_date (SYSTEMTIME *st)
{
- time_t date, now;
-
- date = w32_mktime (st);
- now = time (NULL);
- return date>now? 1 : 0;
+ time_t date = w32_mktime (st);
+ return date >= time (NULL)? 1 : 0;
}
@@ -436,7 +430,6 @@
case WM_INITDIALOG:
ctx = (genkey_s *)lparam;
ShowWindow (GetDlgItem (dlg, IDC_KEYWIZARD_USEOTHERPK), SW_HIDE);
- //SetDlgItemText (dlg, IDC_KEYWIZARD_USEOTHERPK, _("&Prefer DSA/ELG keys"));
SetDlgItemText (dlg, IDC_KEYWIZARD_NAMEINF, _("Real name:"));
SetDlgItemText (dlg, IDC_KEYWIZARD_EMAILINF, _("Email address:"));
SetDlgItemText (dlg, IDC_KEYWIZARD_TITLEINF, _("Name and E-Mail Assignment"));
@@ -453,17 +446,6 @@
break;
case WM_COMMAND:
- switch (HIWORD (wparam)) {
- case BN_CLICKED:
- if ((int)LOWORD (wparam) == IDC_KEYWIZARD_USEOTHERPK &&
- IsDlgButtonChecked(dlg, IDC_KEYWIZARD_USEOTHERPK)) {
- msg_box (dlg, _("Because this limits the key size of the primary key to 1024-bit,\n"
- "this option is not recommend for long-term security keys."),
- _("Key Generation"), MB_INFO);
- }
-
- break;
- }
switch (LOWORD( wparam)) {
case IDOK:
balloon_msg_disable ();
@@ -479,8 +461,8 @@
free_if_alloc (utf8_name);
return FALSE;
}
- if (!GetDlgItemText (dlg, IDC_KEYWIZARD_EMAIL, email, DIM (email)-1)
- || check_email_address (email)) {
+ if (!GetDlgItemText (dlg, IDC_KEYWIZARD_EMAIL, email, DIM (email)-1) ||
+ check_email_address (email)) {
show_balloon_msg (GetDlgItem (dlg, IDC_KEYWIZARD_EMAIL),
_("Please enter a valid email address."),
IDI_ERROR);
@@ -503,7 +485,9 @@
return FALSE;
}
if (IsDlgButtonChecked (dlg, IDC_KEYWIZARD_USEOTHERPK))
- pubkey_algo = GPG_KEYGEN_DSA_ELG;
+ pubkey_algo = GPG_KEYGEN_DSA_ELG;
+ else
+ pubkey_algo = GPG_KEYGEN_RSA_RSA;
p = gpg_genkey_params (pubkey_algo, DFAULT_KEYSIZE, utf8_name,
NULL, email, NULL, pass);
free_if_alloc (utf8_name);
Modified: trunk/Src/wptPassphraseCB.cpp
===================================================================
--- trunk/Src/wptPassphraseCB.cpp 2011-11-27 13:28:00 UTC (rev 343)
+++ trunk/Src/wptPassphraseCB.cpp 2011-11-27 14:56:52 UTC (rev 344)
@@ -1,5 +1,5 @@
/* wptPassphraseCB.cpp - GPGME Passphrase Callback
- * Copyright (C) 2001, 2002-2006, 2009 Timo Schulz
+ * Copyright (C) 2001, 2002-2006, 2009, 2011 Timo Schulz
* Copyright (C) 2005 g10 Code GmbH
*
* This file is part of WinPT.
@@ -201,13 +201,11 @@
res = gpgme_op_decrypt_result (c->gpg);
if (!res)
res_sig = gpgme_op_sign_result (c->gpg);
- if (!c->is_card && reg_prefs.cache_time > 0 &&
- (res || res_sig)) {
+ if (!c->is_card && reg_prefs.cache_time > 0 && (res || res_sig)) {
if (agent_get_cache (c->keyid, &item))
agent_unlock_cache_entry (&item);
else
- agent_put_cache (c->keyid, c->pwd,
- reg_prefs.cache_time);
+ agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time);
}
}
c->cancel = 0;
@@ -255,10 +253,9 @@
char *desc, size_t desc_size)
{
gpgme_pubkey_algo_t algo;
- char usedkey[16+1];
- char mainkey[16+1];
- char *p, *uid;
- int n=0;
+ char usedkey[16 + 1];
+ char mainkey[16 + 1];
+ char *p;
algo = (gpgme_pubkey_algo_t)0;
/* Each uid_hint contains a long key-ID so it is at least 16 bytes. */
@@ -268,6 +265,7 @@
return -1;
}
+ int n = 0;
while ((p = strsep ((char**)&pass_info, " "))) {
switch (n++) {
case 0:
@@ -296,7 +294,7 @@
if (memcmp (sk->keyid, usedkey, 8) == 0)
break;
}
- uid = utf8_to_native (uid_hint);
+ char *uid = utf8_to_native (uid_hint);
if (strcmp (usedkey, mainkey))
_snprintf (desc, desc_size-1,
_("You need a passphrase to unlock the secret key for user:\n"
@@ -366,7 +364,7 @@
if (strlen (passphrase_info) < 16 &&
!strstr (passphrase_info, "OPENPGP")) {
/* assume symetric encryption. */
- int pos=2;
+ int pos = 2;
c->sym.sym_algo = atoi (passphrase_info);
if (c->sym.sym_algo > 9)
pos++;
@@ -505,22 +503,24 @@
int
check_passwd_quality (const char *pass, int strict)
{
- int i, nd=0, nc=0, n;
+ size_t i, nd = 0, nc = 0, na = 0, n;
/* A good passphrase should be at least 8 characters. */
n = strlen (pass);
if (n < 8)
return -1;
- for (i=0; i < n; i++) {
+ for (i = 0; i < n; i++) {
if (isdigit (pass[i]))
nd++;
if (isalpha (pass[i]))
nc++;
+ else
+ na++;
}
/* Check that the passphrase contains letters and numbers. */
- if (nd == n || nc == n)
+ if (nd == n || nc == n || na == n)
return -1;
return 0;
More information about the Winpt-commits
mailing list