22 |
#endif |
#endif |
23 |
|
|
24 |
#include <windows.h> |
#include <windows.h> |
25 |
|
#include <time.h> |
26 |
|
|
27 |
#include "resource.h" |
#include "resource.h" |
28 |
#include "wptTypes.h" |
#include "wptTypes.h" |
34 |
#include "wptW32API.h" |
#include "wptW32API.h" |
35 |
#include "wptVersion.h" |
#include "wptVersion.h" |
36 |
#include "wptErrors.h" |
#include "wptErrors.h" |
37 |
#include "wptUTF8.h" |
|
38 |
|
|
39 |
/* All valid key generation combination. */ |
/* All valid key generation combination. */ |
40 |
enum gpg_keytype_t { |
enum gpg_keytype_t { |
92 |
"Key-Length: %d\n" |
"Key-Length: %d\n" |
93 |
"Key-Usage: %s\n" |
"Key-Usage: %s\n" |
94 |
"Name-Real: %s\n" |
"Name-Real: %s\n" |
|
"Name-Email: %s\n" |
|
95 |
"Name-Comment: %s\n" |
"Name-Comment: %s\n" |
96 |
|
"Name-Email: %s\n" |
97 |
"Expire-Date: %s\n" |
"Expire-Date: %s\n" |
98 |
"Passphrase: %s\n" |
"Passphrase: %s\n" |
99 |
"</GnupgKeyParms>\n"; |
"</GnupgKeyParms>\n"; |
120 |
if (keytype == GPG_KEYGEN_NONE) |
if (keytype == GPG_KEYGEN_NONE) |
121 |
return NULL; |
return NULL; |
122 |
|
|
123 |
if( comment && *comment ) { |
size = strlen (user) + strlen (email) + strlen (passphrase) + addsize + 48; |
124 |
size = strlen (key_params_with_comment) |
if (comment && *comment) |
125 |
+ 16 |
size += strlen (key_params_with_comment) + strlen (comment); |
126 |
+ strlen( user ) |
else |
127 |
+ addsize |
size += strlen (key_params); |
128 |
+ strlen( comment ) |
if (expdate) |
129 |
+ strlen( email ) |
size += strlen (expdate) + 1; |
130 |
+ strlen( passphrase ) + 32; |
p = new char[size+1]; |
131 |
} |
if (!p) |
132 |
else { |
BUG (0); |
133 |
size = strlen( key_params ) |
/* XXX: simply the whole switch-case code. */ |
134 |
+ 16 |
if (comment && *comment) { |
|
+ strlen( user ) |
|
|
+ strlen( email ) |
|
|
+ strlen( passphrase ) |
|
|
+ addsize |
|
|
+ 32; |
|
|
} |
|
|
if( expdate ) |
|
|
size += strlen( expdate ); |
|
|
p = (char *)malloc( size+1 ); |
|
|
if( !p ) |
|
|
return NULL; |
|
|
if( comment && *comment ) { |
|
135 |
switch( keytype ) { |
switch( keytype ) { |
136 |
case GPG_KEYGEN_DSA_ELG: |
case GPG_KEYGEN_DSA_ELG: |
137 |
sprintf (p, key_params_with_comment, |
sprintf (p, key_params_with_comment, |
173 |
break; |
break; |
174 |
|
|
175 |
default: |
default: |
176 |
if (p) |
free_if_alloc (p); |
|
free (p); |
|
|
p = NULL; |
|
177 |
break; |
break; |
178 |
} |
} |
179 |
} |
} |
219 |
break; |
break; |
220 |
|
|
221 |
default: |
default: |
222 |
if (p) |
free_if_alloc (p); |
|
free (p); |
|
|
p = NULL; |
|
223 |
break; |
break; |
224 |
} |
} |
225 |
} |
} |
246 |
err = gpgme_op_genkey (ctx, params, NULL, NULL); |
err = gpgme_op_genkey (ctx, params, NULL, NULL); |
247 |
if (!err) { |
if (!err) { |
248 |
res = gpgme_op_genkey_result (ctx); |
res = gpgme_op_genkey_result (ctx); |
249 |
*fpr = res->fpr? strdup (res->fpr) : NULL; |
*fpr = res && res->fpr? m_strdup (res->fpr) : NULL; |
250 |
} |
} |
251 |
gpgme_release (ctx); |
gpgme_release (ctx); |
252 |
return err; |
return err; |
274 |
static void |
static void |
275 |
backup_keyrings (HWND dlg) |
backup_keyrings (HWND dlg) |
276 |
{ |
{ |
277 |
|
const char *name; |
278 |
|
char *path = NULL; |
279 |
|
char *keyring = NULL; |
280 |
int id; |
int id; |
|
char *path = NULL, *keyring = NULL; |
|
|
const char * name; |
|
281 |
|
|
282 |
path = get_gnupg_path (); |
path = get_gnupg_path (); |
283 |
if (!path) |
if (!path) |
290 |
"Backup your keyrings now?"), |
"Backup your keyrings now?"), |
291 |
_("WARNING - Important hint" ), MB_YESNO); |
_("WARNING - Important hint" ), MB_YESNO); |
292 |
if (id == IDYES) { |
if (id == IDYES) { |
293 |
name = get_filename_dlg( dlg, 1, _("Destination for Public Keyring"), NULL, "pubring.gpg" ); |
name = get_filesave_dlg (dlg, _("Destination for Public Keyring"), |
294 |
|
NULL, "pubring.gpg"); |
295 |
if( name ) { |
if( name ) { |
296 |
keyring = make_filename( path, "pubring", "gpg" ); |
keyring = make_filename (path, "pubring", "gpg"); |
297 |
if( !CopyFile( keyring, name, FALSE ) ) |
if( !CopyFile (keyring, name, FALSE)) |
298 |
log_box( _("Key Generation"), MB_ERR, |
log_box (_("Key Generation"), MB_ERR, |
299 |
_("Could not copy %s -> %s"), keyring, name ); |
_("Could not copy %s -> %s"), keyring, name); |
300 |
free_if_alloc( keyring ); |
free_if_alloc (keyring); |
301 |
} |
} |
302 |
name = get_filename_dlg( dlg, 1, _("Destination for Secret Keyring"), NULL, "secring.gpg" ); |
name = get_filesave_dlg (dlg, _("Destination for Secret Keyring"), |
303 |
if( name ) { |
NULL, "secring.gpg"); |
304 |
keyring = make_filename( path, "secring", "gpg" ); |
if (name) { |
305 |
if( !CopyFile( keyring, name, FALSE ) ) |
keyring = make_filename (path, "secring", "gpg"); |
306 |
log_box( _("Key Generation"), MB_ERR, |
if (!CopyFile (keyring, name, FALSE)) |
307 |
_("Could not copy %s -> %s"), keyring, name ); |
log_box (_("Key Generation"), MB_ERR, |
308 |
free_if_alloc( keyring ); |
_("Could not copy %s -> %s"), keyring, name); |
309 |
|
free_if_alloc (keyring); |
310 |
} |
} |
311 |
} |
} |
312 |
free_if_alloc( path ); |
free_if_alloc (path); |
313 |
} |
} |
314 |
|
|
315 |
|
|
317 |
static void |
static void |
318 |
fill_keytype_box (HWND dlg) |
fill_keytype_box (HWND dlg) |
319 |
{ |
{ |
320 |
HWND cb = GetDlgItem (dlg, IDC_KEYGEN_KEYTYPE ); |
HWND cb = GetDlgItem (dlg, IDC_KEYGEN_KEYTYPE); |
321 |
|
|
322 |
#define addstr( cb, str ) \ |
#define addstr(cb, str) \ |
323 |
SendMessage( (cb), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)(str) ) |
SendMessage ((cb), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)(str)) |
324 |
addstr( cb, _("DSA and ELG (default)") ); |
addstr (cb, _("DSA and ELG (default)")); |
325 |
addstr( cb, _("DSA and RSA") ); |
addstr (cb, _("DSA and RSA")); |
326 |
addstr( cb, _("DSA sign only") ); |
addstr (cb, _("DSA sign only")); |
327 |
addstr( cb, _("RSA sign only") ); |
addstr (cb, _("RSA sign only")); |
328 |
addstr( cb, _("RSA sign and encrypt") ); |
addstr (cb, _("RSA sign and encrypt")); |
329 |
addstr( cb, _("RSA and RSA (PGP)") ); |
addstr (cb, _("RSA and RSA (PGP)") ); |
330 |
SendMessage( cb, CB_SETCURSEL, 0, 0 ); |
SendMessage (cb, CB_SETCURSEL, 0, 0); |
331 |
#undef addstr |
#undef addstr |
332 |
} |
} |
333 |
|
|
334 |
|
|
335 |
|
time_t w32_mktime (SYSTEMTIME *st); |
336 |
|
|
337 |
/* Check that the given date lies not in the past. |
/* Check that the given date lies not in the past. |
338 |
Return value: 1 on success. */ |
Return value: 1 on success. */ |
339 |
int |
int |
340 |
keygen_check_date (SYSTEMTIME *st) |
keygen_check_date (SYSTEMTIME *st) |
341 |
{ |
{ |
342 |
SYSTEMTIME t; |
time_t dat, now; |
343 |
|
|
344 |
GetSystemTime (&t); |
dat = w32_mktime (st); |
345 |
if (st->wYear > t.wYear || st->wMonth > t.wMonth) |
now = time (NULL); |
346 |
|
if (dat >= now) |
347 |
return 1; |
return 1; |
348 |
else if (st->wYear < t.wYear || st->wMonth < t.wMonth || st->wDay < t.wDay) |
return 0; |
|
return 0; |
|
|
return 1; |
|
349 |
} |
} |
350 |
|
|
351 |
|
|
356 |
static genkey_s *ctx; |
static genkey_s *ctx; |
357 |
SYSTEMTIME st; |
SYSTEMTIME st; |
358 |
gpgme_error_t err; |
gpgme_error_t err; |
359 |
char name[128] = {0}, email[128] = {0}, comment[128] = {0}; |
char *utf8_name =NULL, *utf8_comment = NULL; |
360 |
char pwd[128], pwd2[128]; |
char email[128]; |
361 |
|
char *pwd; |
362 |
char t[64], *expire = NULL, *fpr=NULL; |
char t[64], *expire = NULL, *fpr=NULL; |
363 |
int bits, use_comment, keytype = 0; |
int bits, use_comment, keytype = 0; |
364 |
char * p; |
int cancel = 0; |
365 |
|
char *p; |
366 |
|
|
367 |
switch ( msg ) { |
switch (msg) { |
368 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
369 |
if (lparam != 0) |
if (lparam != 0) |
370 |
ctx = (genkey_s *)lparam; |
ctx = (genkey_s *)lparam; |
371 |
SetWindowText( dlg, _("Key Generation") ); |
SetWindowText (dlg, _("Key Generation")); |
372 |
SetDlgItemText( dlg, IDC_KEYGEN_INFO, |
SetDlgItemText(dlg, IDC_KEYGEN_INFO, |
373 |
_("NOTE: Key generation can be a lengthy process! Please wait until " |
_("NOTE: Key generation can be a lengthy process! Please wait until " |
374 |
"you get the message that key generation was finished.") ); |
"you get the message that key generation was finished.")); |
375 |
SetDlgItemText( dlg, IDC_KEYGEN_SUBKEYINF, _("Subkey size in &bits")); |
SetDlgItemText (dlg, IDC_KEYGEN_SUBKEYINF, _("Subkey size in &bits")); |
376 |
SetDlgItemText( dlg, IDC_KEYGEN_NAMEINF, _("&Real name") ); |
SetDlgItemText (dlg, IDC_KEYGEN_NAMEINF, _("&Real name")); |
377 |
SetDlgItemText( dlg, IDC_KEYGEN_COMMINF, _("&Comment (optional)") ); |
SetDlgItemText (dlg, IDC_KEYGEN_COMMINF, _("&Comment (optional)")); |
378 |
SetDlgItemText( dlg, IDC_KEYGEN_EMAILINF, _("Email &address") ); |
SetDlgItemText (dlg, IDC_KEYGEN_EMAILINF, _("Email &address")); |
379 |
SetDlgItemText( dlg, IDC_KEYGEN_EXPINF, _("&Expire date")); |
SetDlgItemText (dlg, IDC_KEYGEN_EXPINF, _("&Expire date")); |
380 |
SetDlgItemText( dlg, IDC_KEYGEN_PWDINF, _("&Passphrase") ); |
SetDlgItemText (dlg, IDC_KEYGEN_KEYTYPEINF, _("Key &type")); |
|
SetDlgItemText( dlg, IDC_KEYGEN_REPWDINF, _("&Repeat passphrase") ); |
|
|
SetDlgItemText( dlg, IDC_KEYGEN_KEYTYPEINF, _("Key &type") ); |
|
381 |
SetDlgItemText (dlg, IDC_KEYGEN_EXPNEVER, _("&Never")); |
SetDlgItemText (dlg, IDC_KEYGEN_EXPNEVER, _("&Never")); |
382 |
SetDlgItemText (dlg, IDC_KEYGEN_HIDEPWD, _("&Hide Typing")); |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
383 |
|
|
384 |
SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, 2048, FALSE); |
SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, DFAULT_KEYSIZE, FALSE); |
385 |
CheckDlgButton (dlg, IDC_KEYGEN_HIDEPWD, BST_CHECKED); |
CheckDlgButton (dlg, IDC_KEYGEN_HIDEPWD, BST_CHECKED); |
386 |
CheckDlgButton (dlg, IDC_KEYGEN_EXPNEVER, BST_CHECKED); |
CheckDlgButton (dlg, IDC_KEYGEN_EXPNEVER, BST_CHECKED); |
387 |
EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), FALSE); |
391 |
return TRUE; |
return TRUE; |
392 |
|
|
393 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
394 |
if (LOWORD (wparam) == SC_CLOSE) { |
if (LOWORD (wparam) == SC_CLOSE) |
|
SetDlgItemText (dlg, IDC_KEYGEN_PASSPHRASE, ""); |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_PWDCHECK, ""); |
|
395 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
|
} |
|
396 |
return FALSE; |
return FALSE; |
397 |
|
|
398 |
case WM_COMMAND: |
case WM_COMMAND: |
401 |
int never = IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER); |
int never = IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER); |
402 |
EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), !never); |
EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), !never); |
403 |
} |
} |
|
if (HIWORD (wparam) == BN_CLICKED |
|
|
&& LOWORD (wparam) == IDC_KEYGEN_HIDEPWD) { |
|
|
HWND hwnd_a = GetDlgItem (dlg, IDC_KEYGEN_PASSPHRASE); |
|
|
HWND hwnd_b = GetDlgItem (dlg, IDC_KEYGEN_PWDCHECK); |
|
|
int hide = IsDlgButtonChecked (dlg, IDC_KEYGEN_HIDEPWD); |
|
|
SendMessage (hwnd_a, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
|
|
SetFocus (hwnd_a); |
|
|
SendMessage (hwnd_b, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
|
|
SetFocus (hwnd_b); |
|
|
} |
|
404 |
|
|
405 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
406 |
case IDOK: |
case IDOK: |
407 |
bits = GetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, NULL, FALSE); |
bits = GetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, NULL, FALSE); |
408 |
if (bits < 1024 || bits > 4096) { |
if (bits < 1024 || bits > 4096) { |
411 |
return FALSE; |
return FALSE; |
412 |
} |
} |
413 |
if (bits > DFAULT_KEYSIZE) { |
if (bits > DFAULT_KEYSIZE) { |
414 |
int id = msg_box (dlg, _("Do you really need such a large key?"), |
int id = msg_box (dlg, _("Do you really need such a large key?"), |
415 |
_("Key Generation"), MB_YESNO); |
_("Key Generation"), MB_YESNO); |
416 |
if (id == IDNO) |
if (id == IDNO) |
417 |
bits = DFAULT_KEYSIZE; |
bits = DFAULT_KEYSIZE; |
418 |
} |
} |
419 |
if( !GetDlgItemText( dlg, IDC_KEYGEN_NAME, name, sizeof name - 1 ) ) { |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYGEN_NAME, &utf8_name)) { |
420 |
msg_box( dlg, _("Please enter the name."), _("Key Generation"), MB_ERR ); |
msg_box (dlg, _("Please enter the name."), _("Key Generation"), MB_ERR); |
421 |
return FALSE; |
return FALSE; |
422 |
} |
} |
423 |
if (strchr (name, '@')) { |
if (strchr (utf8_name, '@')) { |
424 |
msg_box (dlg, _("Please do not enter the email address in the name field."), |
msg_box (dlg, _("Please do not enter the email address in the name field."), |
425 |
_("Key Generation"), MB_INFO); |
_("Key Generation"), MB_INFO); |
426 |
|
free_if_alloc (utf8_name); |
427 |
return FALSE; |
return FALSE; |
428 |
} |
} |
429 |
if( !GetDlgItemText(dlg, IDC_KEYGEN_EMAIL, email, sizeof email -1 ) |
if (!GetDlgItemText (dlg, IDC_KEYGEN_EMAIL, email, sizeof (email) -1) |
430 |
|| !strchr( email, '@') ) { |
|| check_email_address (email)) { |
431 |
msg_box( dlg, _("Please enter a valid email address."), |
msg_box (dlg, _("Please enter a valid email address."), |
432 |
_("Key Generation"), MB_ERR ); |
_("Key Generation"), MB_ERR); |
433 |
|
free_if_alloc (utf8_name); |
434 |
return FALSE; |
return FALSE; |
435 |
} |
} |
436 |
use_comment = GetDlgItemText( dlg, IDC_KEYGEN_COMMENT, comment, sizeof comment -1 ); |
use_comment = GetDlgItemText_utf8 (dlg, IDC_KEYGEN_COMMENT, |
437 |
if( use_comment > 0 && strchr( comment, '@' ) ) { |
&utf8_comment); |
438 |
msg_box( dlg, _("Please do NOT enter the email address in the comment field."), |
if (use_comment > 0 && strchr (utf8_comment, '@')) { |
439 |
_("Key Generation"), MB_INFO ); |
msg_box (dlg, _("Please do NOT enter the email address in the comment field."), |
440 |
return FALSE; |
_("Key Generation"), MB_INFO); |
441 |
|
free_if_alloc (utf8_name); |
442 |
|
free_if_alloc (utf8_comment); |
443 |
|
return TRUE; |
444 |
} |
} |
445 |
keytype = SendDlgItemMessage (dlg, IDC_KEYGEN_KEYTYPE, CB_GETCURSEL, 0, 0) + 1; |
keytype = SendDlgItemMessage (dlg, IDC_KEYGEN_KEYTYPE, CB_GETCURSEL, 0, 0) + 1; |
446 |
if (IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER)) |
if (IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER)) |
447 |
expire = NULL; |
expire = NULL; |
448 |
else { |
else { |
449 |
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), &st); |
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), &st); |
450 |
|
if (!keygen_check_date (&st)) { |
451 |
|
free_if_alloc (utf8_name); |
452 |
|
free_if_alloc (utf8_comment); |
453 |
|
msg_box (dlg, _("The date you have chosen lies in the past."), |
454 |
|
_("Key Generation"), MB_ERR); |
455 |
|
return TRUE; |
456 |
|
} |
457 |
_snprintf (t, DIM (t)-1, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); |
_snprintf (t, DIM (t)-1, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); |
458 |
expire = t; |
expire = t; |
459 |
} |
} |
460 |
|
|
461 |
if( !GetDlgItemText( dlg, IDC_KEYGEN_PASSPHRASE, pwd, sizeof pwd -1 ) ) { |
pwd = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel); |
462 |
msg_box( dlg, _("Please enter the passphrase."), |
if (cancel) { |
463 |
_("Key Generation"), MB_ERR ); |
sfree_if_alloc (pwd); |
464 |
return FALSE; |
free_if_alloc (utf8_name); |
465 |
} |
free_if_alloc (utf8_comment); |
|
else if (check_passwd_quality (pwd, 0)) { |
|
|
int id = msg_box( dlg, _("Your passphrase should be at least 8 characters" |
|
|
" long\nand should contain non-alphabetic characters." |
|
|
"\n\nStill proceed?"), |
|
|
_("Key Generation"), MB_ICONWARNING|MB_YESNO ); |
|
|
if( id == IDNO ) { |
|
|
SetDlgItemText( dlg, IDC_KEYGEN_PASSPHRASE, "" ); |
|
|
SetDlgItemText( dlg, IDC_KEYGEN_PWDCHECK, "" ); |
|
|
return FALSE; |
|
|
} |
|
|
} |
|
|
if( !GetDlgItemText( dlg, IDC_KEYGEN_PWDCHECK, pwd2, sizeof pwd2 -1 ) ) { |
|
|
msg_box( dlg, _("Please repeat the passphrase."), |
|
|
_("Key Generation"), MB_ERR ); |
|
|
return FALSE; |
|
|
} |
|
|
if( strcmp( pwd, pwd2 ) ) { |
|
|
msg_box( dlg, _("Passphrases are NOT identical!" ), |
|
|
_("Key Generation"), MB_ERR ); |
|
|
wipememory (pwd, sizeof (pwd)); |
|
|
wipememory (pwd2, sizeof (pwd2)); |
|
|
return FALSE; |
|
|
} |
|
|
if( is_8bit_string( pwd ) ) { |
|
|
msg_box( dlg, _("The passphrase contains 8-bit characters.\n" |
|
|
"It is not suggested to use charset specific characters."), |
|
|
_("Key Generation"), MB_ERR ); |
|
|
wipememory (pwd, sizeof (pwd)); |
|
|
wipememory (pwd2, sizeof (pwd2)); |
|
|
SetDlgItemText( dlg, IDC_KEYGEN_PASSPHRASE, "" ); |
|
|
SetDlgItemText( dlg, IDC_KEYGEN_PWDCHECK, "" ); |
|
466 |
return FALSE; |
return FALSE; |
467 |
} |
} |
468 |
|
if (!pwd) { |
469 |
if( !use_comment && !strlen( comment ) ) { |
msg_box (dlg, _("Please enter the passphrase."), |
470 |
char *utf8_name; |
_("Key Generation"), MB_ERR); |
471 |
utf8_name = wincp_to_utf8 (name, strlen (name)); |
free_if_alloc (utf8_name); |
472 |
if( !utf8_name ) |
free_if_alloc (utf8_comment); |
473 |
BUG( dlg ); |
return FALSE; |
|
p = gpg_genkey_params( keytype, bits, utf8_name, NULL, email, expire, pwd ); |
|
|
free( utf8_name ); |
|
|
} |
|
|
else { |
|
|
char *utf8_name, *utf8_comment; |
|
|
utf8_name = wincp_to_utf8 (name, strlen (name)); |
|
|
utf8_comment = wincp_to_utf8 (comment, strlen (comment)); |
|
|
if( !utf8_name || !utf8_comment ) |
|
|
BUG( dlg ); |
|
|
p = gpg_genkey_params( keytype, bits, utf8_name, utf8_comment, email, expire, pwd ); |
|
|
free( utf8_name ); |
|
|
free( utf8_comment ); |
|
474 |
} |
} |
475 |
keygen_cb_dlg_create( ); |
|
476 |
|
if (!use_comment && !utf8_comment) |
477 |
|
p = gpg_genkey_params (keytype, bits, utf8_name, NULL, |
478 |
|
email, expire, pwd); |
479 |
|
else |
480 |
|
p = gpg_genkey_params (keytype, bits, utf8_name, utf8_comment, |
481 |
|
email, expire, pwd); |
482 |
|
free_if_alloc (utf8_name); |
483 |
|
free_if_alloc (utf8_comment); |
484 |
|
keygen_cb_dlg_create (); |
485 |
err = gpg_genkey (p, keygen_cb, &fpr); |
err = gpg_genkey (p, keygen_cb, &fpr); |
486 |
wipememory (pwd, sizeof (pwd)); |
sfree_if_alloc (pwd); |
487 |
wipememory (pwd2, sizeof (pwd2)); |
sfree_if_alloc (p); /* burn the passphrase! */ |
488 |
if( p ) { |
keygen_cb_dlg_destroy (1); |
489 |
wipememory (p, strlen (p)); /* burn the passphrase! */ |
if (err) { |
490 |
free (p); |
free_if_alloc (fpr); |
491 |
} |
msg_box (dlg, gpgme_strerror (err), _("Key Generation"), MB_ERR); |
|
keygen_cb_dlg_destroy (); |
|
|
keygen_cb (NULL, NULL, 0, 0, 0); /* flush */ |
|
|
if( err ) { |
|
|
if (fpr) |
|
|
free (fpr); |
|
|
msg_box (dlg, gpgme_strerror( err ), _("Key Generation"), MB_ERR); |
|
492 |
return FALSE; |
return FALSE; |
493 |
} |
} |
494 |
status_box( dlg, _("Key Generation completed"), _("GnuPG Status") ); |
status_box (dlg, _("Key Generation completed"), _("GnuPG Status")); |
495 |
|
|
496 |
keycache_update (0, fpr); |
keycache_update (0, fpr); |
497 |
keycache_update (1, fpr); |
keycache_update (1, fpr); |
498 |
if (ctx->first_start == 0 && ctx != NULL) |
free_if_alloc (fpr); |
|
get_pubkey (fpr, &ctx->newkey); |
|
|
if (fpr) |
|
|
free (fpr); |
|
499 |
|
|
500 |
clear_dlg_fields (dlg); |
clear_dlg_fields (dlg); |
501 |
backup_keyrings (dlg); |
backup_keyrings (dlg); |
502 |
|
if (ctx) |
503 |
|
ctx->cancel = 0; |
504 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
505 |
return TRUE; |
return TRUE; |
506 |
|
|
507 |
case IDCANCEL: |
case IDCANCEL: |
508 |
SetDlgItemText (dlg, IDC_KEYGEN_PASSPHRASE, ""); |
if (ctx) |
509 |
SetDlgItemText (dlg, IDC_KEYGEN_PWDCHECK, ""); |
ctx->cancel = 1; |
510 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
511 |
return FALSE; |
return FALSE; |
512 |
} |
} |
513 |
break; |
break; |
523 |
static genkey_s *ctx; |
static genkey_s *ctx; |
524 |
static int pubkey_algo = GPG_KEYGEN_DSA_ELG; |
static int pubkey_algo = GPG_KEYGEN_DSA_ELG; |
525 |
gpgme_error_t err; |
gpgme_error_t err; |
526 |
char name[128], email[128]; |
char email[128]; |
527 |
char * utf8_name, * p, *fpr=NULL; |
char *utf8_name=NULL, * p, *fpr=NULL; |
528 |
char * pass = NULL; |
char * pass = NULL; |
529 |
int cancel = 0; |
int cancel = 0; |
530 |
|
|
541 |
SetDlgItemText (dlg, IDC_KEYWIZARD_TEXT1INF, _("Every key pair must have a name associated with it. The name and\nemail address let your correspondents that your public key they are\nusing belongs to us.")); |
SetDlgItemText (dlg, IDC_KEYWIZARD_TEXT1INF, _("Every key pair must have a name associated with it. The name and\nemail address let your correspondents that your public key they are\nusing belongs to us.")); |
542 |
SetDlgItemText (dlg, IDC_KEYWIZARD_TEXT2INF, _("By accosiating an email address with your key pair, you will enable WinPT to assist your correspondents in selecting the correct public\nkey when communicating with you.")); |
SetDlgItemText (dlg, IDC_KEYWIZARD_TEXT2INF, _("By accosiating an email address with your key pair, you will enable WinPT to assist your correspondents in selecting the correct public\nkey when communicating with you.")); |
543 |
SetWindowText (dlg, _("Key Generation Wizard")); |
SetWindowText (dlg, _("Key Generation Wizard")); |
544 |
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
545 |
|
SetDlgItemText (dlg, IDC_KEYWIZARD_EXPERT, _("E&xpert")); |
546 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
547 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
548 |
break; |
break; |
549 |
|
|
|
case WM_SYSCOMMAND: |
|
|
if( LOWORD( wparam ) == SC_CLOSE ) |
|
|
EndDialog( dlg, FALSE ); |
|
|
|
|
550 |
case WM_COMMAND: |
case WM_COMMAND: |
551 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD( wparam)) { |
552 |
case IDC_KEYWIZARD_EXPERT: |
case IDC_KEYWIZARD_EXPERT: |
553 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYGEN, dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYGEN, dlg, |
554 |
keygen_dlg_proc, 0); |
keygen_dlg_proc, 0); |
556 |
break; |
break; |
557 |
|
|
558 |
case IDOK: |
case IDOK: |
559 |
if( !GetDlgItemText( dlg, IDC_KEYWIZARD_NAME, name, sizeof name-1 ) ) { |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYWIZARD_NAME, &utf8_name)) { |
560 |
msg_box( dlg, _("Please enter the name."), |
msg_box (dlg, _("Please enter the name."), |
561 |
_("Key Generation Wizard"), MB_ERR ); |
_("Key Generation Wizard"), MB_ERR); |
562 |
return FALSE; |
return FALSE; |
563 |
} |
} |
564 |
if (strchr (name, '@')) { |
if (strchr (utf8_name, '@')) { |
565 |
msg_box (dlg, _("Please do not enter the email address in the name field."), |
msg_box (dlg, _("Please do not enter the email address in the name field."), |
566 |
_("Key Generation Wizard"), MB_WARN); |
_("Key Generation Wizard"), MB_WARN); |
567 |
|
free_if_alloc (utf8_name); |
568 |
return FALSE; |
return FALSE; |
569 |
} |
} |
570 |
if( !GetDlgItemText( dlg, IDC_KEYWIZARD_EMAIL, email, sizeof email-1 ) |
if (!GetDlgItemText(dlg, IDC_KEYWIZARD_EMAIL, email, sizeof email-1 ) |
571 |
|| !strchr( email, '@' ) ) { |
|| check_email_address (email)) { |
572 |
msg_box( dlg, _("Please enter a valid email address."), |
msg_box (dlg, _("Please enter a valid email address."), |
573 |
_("Key Generation Wizard"), MB_ERR ); |
_("Key Generation Wizard"), MB_ERR); |
574 |
|
free_if_alloc (utf8_name); |
575 |
return FALSE; |
return FALSE; |
576 |
} |
} |
577 |
if (strchr (email, '<') || strchr (email, '>')) { |
if (strchr (email, '<') || strchr (email, '>')) { |
578 |
msg_box (dlg, _("Please do not add '<' or '>' to the email address."), |
msg_box (dlg, _("Please do not add '<' or '>' to the email address."), |
579 |
_("Key Generation Wizard"), MB_WARN); |
_("Key Generation Wizard"), MB_WARN); |
580 |
|
free_if_alloc (utf8_name); |
581 |
return FALSE; |
return FALSE; |
582 |
} |
} |
583 |
pass = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel); |
pass = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel); |
584 |
if (cancel) |
if (cancel) { |
585 |
|
free_if_alloc (utf8_name); |
586 |
return FALSE; |
return FALSE; |
587 |
utf8_name = wincp_to_utf8 (name, strlen (name)); |
} |
|
if( !utf8_name ) |
|
|
BUG( NULL ); |
|
588 |
if (IsDlgButtonChecked (dlg, IDC_KEYWIZARD_USERSA)) |
if (IsDlgButtonChecked (dlg, IDC_KEYWIZARD_USERSA)) |
589 |
pubkey_algo = GPG_KEYGEN_DSA_RSA; |
pubkey_algo = GPG_KEYGEN_DSA_RSA; |
590 |
p = gpg_genkey_params (pubkey_algo, DFAULT_KEYSIZE, utf8_name, |
p = gpg_genkey_params (pubkey_algo, DFAULT_KEYSIZE, utf8_name, |
591 |
NULL, email, NULL, pass); |
NULL, email, NULL, pass); |
592 |
free( utf8_name ); |
free_if_alloc (utf8_name); |
593 |
keygen_cb_dlg_create(); |
keygen_cb_dlg_create(); |
594 |
err = gpg_genkey (p, keygen_cb, &fpr); |
err = gpg_genkey (p, keygen_cb, &fpr); |
595 |
keygen_cb_dlg_destroy(); |
keygen_cb_dlg_destroy (1); |
596 |
keygen_cb( NULL, NULL, 0, 0, 0 ); |
sfree_if_alloc (p); |
|
if( p ) { |
|
|
memset( p, 0, strlen( p ) ); |
|
|
free( p ); |
|
|
} |
|
597 |
sfree_if_alloc (pass); |
sfree_if_alloc (pass); |
598 |
if( err ) { |
if (err) { |
599 |
msg_box( dlg, gpgme_strerror( err ), _("Key Generation Wizard"), MB_ERR ); |
msg_box (dlg, gpgme_strerror( err ), _("Key Generation Wizard"), MB_ERR); |
600 |
if (fpr) |
free_if_alloc (fpr); |
|
free (fpr); |
|
601 |
return FALSE; |
return FALSE; |
602 |
} |
} |
603 |
status_box( dlg, _("Key Generation completed"), _("GnuPG Status") ); |
status_box (dlg, _("Key Generation completed"), _("GnuPG Status")); |
|
|
|
604 |
keycache_update (0, fpr); |
keycache_update (0, fpr); |
605 |
keycache_update (1, fpr); |
keycache_update (1, fpr); |
606 |
if (ctx->first_start == 0 && ctx != NULL) |
free_if_alloc (fpr); |
607 |
get_pubkey (fpr, &ctx->newkey); |
|
|
if (fpr) |
|
|
free (fpr); |
|
608 |
backup_keyrings (dlg); |
backup_keyrings (dlg); |
609 |
|
if (ctx) |
610 |
|
ctx->cancel = 0; |
611 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
612 |
break; |
break; |
613 |
|
|
614 |
case IDCANCEL: |
case IDCANCEL: |
615 |
EndDialog( dlg, FALSE ); |
if (ctx) |
616 |
|
ctx->cancel = 1; |
617 |
|
EndDialog (dlg, FALSE); |
618 |
break; |
break; |
619 |
} |
} |
620 |
break; |
break; |