33 |
#include "wptW32API.h" |
#include "wptW32API.h" |
34 |
#include "wptVersion.h" |
#include "wptVersion.h" |
35 |
#include "wptErrors.h" |
#include "wptErrors.h" |
36 |
#include "wptUTF8.h" |
|
37 |
|
|
38 |
/* All valid key generation combination. */ |
/* All valid key generation combination. */ |
39 |
enum gpg_keytype_t { |
enum gpg_keytype_t { |
91 |
"Key-Length: %d\n" |
"Key-Length: %d\n" |
92 |
"Key-Usage: %s\n" |
"Key-Usage: %s\n" |
93 |
"Name-Real: %s\n" |
"Name-Real: %s\n" |
|
"Name-Email: %s\n" |
|
94 |
"Name-Comment: %s\n" |
"Name-Comment: %s\n" |
95 |
|
"Name-Email: %s\n" |
96 |
"Expire-Date: %s\n" |
"Expire-Date: %s\n" |
97 |
"Passphrase: %s\n" |
"Passphrase: %s\n" |
98 |
"</GnupgKeyParms>\n"; |
"</GnupgKeyParms>\n"; |
126 |
size += strlen (key_params); |
size += strlen (key_params); |
127 |
if (expdate) |
if (expdate) |
128 |
size += strlen (expdate) + 1; |
size += strlen (expdate) + 1; |
129 |
p = (char *)malloc (size+1); |
p = new char[size+1]; |
130 |
if (!p) |
if (!p) |
131 |
BUG (0); |
BUG (0); |
132 |
/* XXX: simply the whole switch-case code. */ |
/* XXX: simply the whole switch-case code. */ |
172 |
break; |
break; |
173 |
|
|
174 |
default: |
default: |
175 |
if (p) |
free_if_alloc (p); |
|
free (p); |
|
|
p = NULL; |
|
176 |
break; |
break; |
177 |
} |
} |
178 |
} |
} |
218 |
break; |
break; |
219 |
|
|
220 |
default: |
default: |
221 |
if (p) |
free_if_alloc (p); |
|
free (p); |
|
|
p = NULL; |
|
222 |
break; |
break; |
223 |
} |
} |
224 |
} |
} |
245 |
err = gpgme_op_genkey (ctx, params, NULL, NULL); |
err = gpgme_op_genkey (ctx, params, NULL, NULL); |
246 |
if (!err) { |
if (!err) { |
247 |
res = gpgme_op_genkey_result (ctx); |
res = gpgme_op_genkey_result (ctx); |
248 |
*fpr = res->fpr? strdup (res->fpr) : NULL; |
*fpr = res->fpr? m_strdup (res->fpr) : NULL; |
249 |
} |
} |
250 |
gpgme_release (ctx); |
gpgme_release (ctx); |
251 |
return err; |
return err; |
354 |
static genkey_s *ctx; |
static genkey_s *ctx; |
355 |
SYSTEMTIME st; |
SYSTEMTIME st; |
356 |
gpgme_error_t err; |
gpgme_error_t err; |
357 |
char name[128] = {0}, email[128] = {0}, comment[128] = {0}; |
char *utf8_name =NULL, *utf8_comment = NULL; |
358 |
|
char email[128]; |
359 |
char *pwd; |
char *pwd; |
360 |
char t[64], *expire = NULL, *fpr=NULL; |
char t[64], *expire = NULL, *fpr=NULL; |
361 |
int bits, use_comment, keytype = 0; |
int bits, use_comment, keytype = 0; |
414 |
if (id == IDNO) |
if (id == IDNO) |
415 |
bits = DFAULT_KEYSIZE; |
bits = DFAULT_KEYSIZE; |
416 |
} |
} |
417 |
if (!GetDlgItemText (dlg, IDC_KEYGEN_NAME, name, sizeof (name) - 1)) { |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYGEN_NAME, &utf8_name)) { |
418 |
msg_box( dlg, _("Please enter the name."), _("Key Generation"), MB_ERR); |
msg_box (dlg, _("Please enter the name."), _("Key Generation"), MB_ERR); |
419 |
return FALSE; |
return FALSE; |
420 |
} |
} |
421 |
if (strchr (name, '@')) { |
if (strchr (utf8_name, '@')) { |
422 |
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."), |
423 |
_("Key Generation"), MB_INFO); |
_("Key Generation"), MB_INFO); |
424 |
|
free_if_alloc (utf8_name); |
425 |
return FALSE; |
return FALSE; |
426 |
} |
} |
427 |
if (!GetDlgItemText (dlg, IDC_KEYGEN_EMAIL, email, sizeof (email) -1) |
if (!GetDlgItemText (dlg, IDC_KEYGEN_EMAIL, email, sizeof (email) -1) |
428 |
|| !strchr (email, '@')) { |
|| check_email_address (email)) { |
429 |
msg_box (dlg, _("Please enter a valid email address."), |
msg_box (dlg, _("Please enter a valid email address."), |
430 |
_("Key Generation"), MB_ERR); |
_("Key Generation"), MB_ERR); |
431 |
|
free_if_alloc (utf8_name); |
432 |
return FALSE; |
return FALSE; |
433 |
} |
} |
434 |
use_comment = GetDlgItemText(dlg, IDC_KEYGEN_COMMENT, |
use_comment = GetDlgItemText_utf8 (dlg, IDC_KEYGEN_COMMENT, |
435 |
comment, sizeof (comment) -1); |
&utf8_comment); |
436 |
if (use_comment > 0 && strchr (comment, '@')) { |
if (use_comment > 0 && strchr (utf8_comment, '@')) { |
437 |
msg_box (dlg, _("Please do NOT enter the email address in the comment field."), |
msg_box (dlg, _("Please do NOT enter the email address in the comment field."), |
438 |
_("Key Generation"), MB_INFO); |
_("Key Generation"), MB_INFO); |
439 |
|
free_if_alloc (utf8_name); |
440 |
|
free_if_alloc (utf8_comment); |
441 |
return FALSE; |
return FALSE; |
442 |
} |
} |
443 |
keytype = SendDlgItemMessage (dlg, IDC_KEYGEN_KEYTYPE, CB_GETCURSEL, 0, 0) + 1; |
keytype = SendDlgItemMessage (dlg, IDC_KEYGEN_KEYTYPE, CB_GETCURSEL, 0, 0) + 1; |
452 |
pwd = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel); |
pwd = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel); |
453 |
if (cancel) { |
if (cancel) { |
454 |
sfree_if_alloc (pwd); |
sfree_if_alloc (pwd); |
455 |
|
free_if_alloc (utf8_name); |
456 |
|
free_if_alloc (utf8_comment); |
457 |
return FALSE; |
return FALSE; |
458 |
} |
} |
459 |
if (!pwd) { |
if (!pwd) { |
460 |
msg_box (dlg, _("Please enter the passphrase."), |
msg_box (dlg, _("Please enter the passphrase."), |
461 |
_("Key Generation"), MB_ERR); |
_("Key Generation"), MB_ERR); |
462 |
|
free_if_alloc (utf8_name); |
463 |
|
free_if_alloc (utf8_comment); |
464 |
return FALSE; |
return FALSE; |
465 |
} |
} |
466 |
|
|
467 |
if (!use_comment && !strlen (comment)) { |
if (!use_comment && !strlen (utf8_comment)) |
|
char *utf8_name; |
|
|
utf8_name = wincp_to_utf8 (name, strlen (name)); |
|
|
if (!utf8_name) |
|
|
BUG (0); |
|
468 |
p = gpg_genkey_params (keytype, bits, utf8_name, NULL, |
p = gpg_genkey_params (keytype, bits, utf8_name, NULL, |
469 |
email, expire, pwd); |
email, expire, pwd); |
470 |
safe_free (utf8_name); |
else |
|
} |
|
|
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 (0); |
|
471 |
p = gpg_genkey_params (keytype, bits, utf8_name, utf8_comment, |
p = gpg_genkey_params (keytype, bits, utf8_name, utf8_comment, |
472 |
email, expire, pwd); |
email, expire, pwd); |
473 |
safe_free (utf8_name); |
free_if_alloc (utf8_name); |
474 |
safe_free (utf8_comment); |
free_if_alloc (utf8_comment); |
|
} |
|
475 |
keygen_cb_dlg_create (); |
keygen_cb_dlg_create (); |
476 |
err = gpg_genkey (p, keygen_cb, &fpr); |
err = gpg_genkey (p, keygen_cb, &fpr); |
477 |
sfree_if_alloc (pwd); |
sfree_if_alloc (pwd); |
478 |
if (p) { |
if (p) { |
479 |
wipememory (p, strlen (p)); /* burn the passphrase! */ |
wipememory (p, strlen (p)); /* burn the passphrase! */ |
480 |
free (p); |
free_if_alloc (p); |
481 |
} |
} |
482 |
keygen_cb_dlg_destroy (); |
keygen_cb_dlg_destroy (1); |
|
keygen_cb (NULL, NULL, 0, 0, 0); /* flush */ |
|
483 |
if (err) { |
if (err) { |
484 |
safe_free (fpr); |
free_if_alloc (fpr); |
485 |
msg_box (dlg, gpgme_strerror (err), _("Key Generation"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Key Generation"), MB_ERR); |
486 |
return FALSE; |
return FALSE; |
487 |
} |
} |
489 |
|
|
490 |
keycache_update (0, fpr); |
keycache_update (0, fpr); |
491 |
keycache_update (1, fpr); |
keycache_update (1, fpr); |
492 |
if (ctx != NULL && ctx->first_start == 0) |
free_if_alloc (fpr); |
|
get_pubkey (fpr, &ctx->newkey); |
|
|
safe_free (fpr); |
|
493 |
|
|
494 |
clear_dlg_fields (dlg); |
clear_dlg_fields (dlg); |
495 |
backup_keyrings (dlg); |
backup_keyrings (dlg); |
496 |
|
if (ctx) |
497 |
|
ctx->cancel = 0; |
498 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
499 |
return TRUE; |
return TRUE; |
500 |
|
|
501 |
case IDCANCEL: |
case IDCANCEL: |
502 |
EndDialog (dlg, FALSE); |
if (ctx) |
503 |
|
ctx->cancel = 1; |
504 |
|
EndDialog (dlg, FALSE); |
505 |
return FALSE; |
return FALSE; |
506 |
} |
} |
507 |
break; |
break; |
517 |
static genkey_s *ctx; |
static genkey_s *ctx; |
518 |
static int pubkey_algo = GPG_KEYGEN_DSA_ELG; |
static int pubkey_algo = GPG_KEYGEN_DSA_ELG; |
519 |
gpgme_error_t err; |
gpgme_error_t err; |
520 |
char name[128], email[128]; |
char email[128]; |
521 |
char * utf8_name, * p, *fpr=NULL; |
char *utf8_name=NULL, * p, *fpr=NULL; |
522 |
char * pass = NULL; |
char * pass = NULL; |
523 |
int cancel = 0; |
int cancel = 0; |
524 |
|
|
542 |
break; |
break; |
543 |
|
|
544 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
545 |
if( LOWORD( wparam ) == SC_CLOSE ) |
if (LOWORD (wparam) == SC_CLOSE) |
546 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
547 |
|
|
548 |
case WM_COMMAND: |
case WM_COMMAND: |
549 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD( wparam)) { |
550 |
case IDC_KEYWIZARD_EXPERT: |
case IDC_KEYWIZARD_EXPERT: |
551 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYGEN, dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYGEN, dlg, |
552 |
keygen_dlg_proc, 0); |
keygen_dlg_proc, 0); |
554 |
break; |
break; |
555 |
|
|
556 |
case IDOK: |
case IDOK: |
557 |
if( !GetDlgItemText( dlg, IDC_KEYWIZARD_NAME, name, sizeof name-1 ) ) { |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYWIZARD_NAME, &utf8_name)) { |
558 |
msg_box( dlg, _("Please enter the name."), |
msg_box (dlg, _("Please enter the name."), |
559 |
_("Key Generation Wizard"), MB_ERR ); |
_("Key Generation Wizard"), MB_ERR); |
560 |
return FALSE; |
return FALSE; |
561 |
} |
} |
562 |
if (strchr (name, '@')) { |
if (strchr (utf8_name, '@')) { |
563 |
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."), |
564 |
_("Key Generation Wizard"), MB_WARN); |
_("Key Generation Wizard"), MB_WARN); |
565 |
|
free_if_alloc (utf8_name); |
566 |
return FALSE; |
return FALSE; |
567 |
} |
} |
568 |
if( !GetDlgItemText( dlg, IDC_KEYWIZARD_EMAIL, email, sizeof email-1 ) |
if (!GetDlgItemText(dlg, IDC_KEYWIZARD_EMAIL, email, sizeof email-1 ) |
569 |
|| !strchr( email, '@' ) ) { |
|| check_email_address (email)) { |
570 |
msg_box( dlg, _("Please enter a valid email address."), |
msg_box (dlg, _("Please enter a valid email address."), |
571 |
_("Key Generation Wizard"), MB_ERR ); |
_("Key Generation Wizard"), MB_ERR); |
572 |
|
free_if_alloc (utf8_name); |
573 |
return FALSE; |
return FALSE; |
574 |
} |
} |
575 |
if (strchr (email, '<') || strchr (email, '>')) { |
if (strchr (email, '<') || strchr (email, '>')) { |
576 |
msg_box (dlg, _("Please do not add '<' or '>' to the email address."), |
msg_box (dlg, _("Please do not add '<' or '>' to the email address."), |
577 |
_("Key Generation Wizard"), MB_WARN); |
_("Key Generation Wizard"), MB_WARN); |
578 |
|
free_if_alloc (utf8_name); |
579 |
return FALSE; |
return FALSE; |
580 |
} |
} |
581 |
pass = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel); |
pass = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel); |
582 |
if (cancel) |
if (cancel) { |
583 |
|
free_if_alloc (utf8_name); |
584 |
return FALSE; |
return FALSE; |
585 |
utf8_name = wincp_to_utf8 (name, strlen (name)); |
} |
|
if( !utf8_name ) |
|
|
BUG( NULL ); |
|
586 |
if (IsDlgButtonChecked (dlg, IDC_KEYWIZARD_USERSA)) |
if (IsDlgButtonChecked (dlg, IDC_KEYWIZARD_USERSA)) |
587 |
pubkey_algo = GPG_KEYGEN_DSA_RSA; |
pubkey_algo = GPG_KEYGEN_DSA_RSA; |
588 |
p = gpg_genkey_params (pubkey_algo, DFAULT_KEYSIZE, utf8_name, |
p = gpg_genkey_params (pubkey_algo, DFAULT_KEYSIZE, utf8_name, |
589 |
NULL, email, NULL, pass); |
NULL, email, NULL, pass); |
590 |
free( utf8_name ); |
free_if_alloc (utf8_name); |
591 |
keygen_cb_dlg_create(); |
keygen_cb_dlg_create(); |
592 |
err = gpg_genkey (p, keygen_cb, &fpr); |
err = gpg_genkey (p, keygen_cb, &fpr); |
593 |
keygen_cb_dlg_destroy(); |
keygen_cb_dlg_destroy (1); |
594 |
keygen_cb( NULL, NULL, 0, 0, 0 ); |
if (p) { |
595 |
if( p ) { |
wipememory (p, strlen (p)); |
596 |
memset( p, 0, strlen( p ) ); |
free_if_alloc (p); |
|
free( p ); |
|
597 |
} |
} |
598 |
sfree_if_alloc (pass); |
sfree_if_alloc (pass); |
599 |
if( err ) { |
if (err) { |
600 |
msg_box( dlg, gpgme_strerror( err ), _("Key Generation Wizard"), MB_ERR ); |
msg_box (dlg, gpgme_strerror( err ), _("Key Generation Wizard"), MB_ERR); |
601 |
if (fpr) |
free_if_alloc (fpr); |
|
free (fpr); |
|
602 |
return FALSE; |
return FALSE; |
603 |
} |
} |
604 |
status_box( dlg, _("Key Generation completed"), _("GnuPG Status") ); |
status_box (dlg, _("Key Generation completed"), _("GnuPG Status")); |
|
|
|
605 |
keycache_update (0, fpr); |
keycache_update (0, fpr); |
606 |
keycache_update (1, fpr); |
keycache_update (1, fpr); |
607 |
if (ctx->first_start == 0 && ctx != NULL) |
free_if_alloc (fpr); |
608 |
get_pubkey (fpr, &ctx->newkey); |
|
|
if (fpr) |
|
|
free (fpr); |
|
609 |
backup_keyrings (dlg); |
backup_keyrings (dlg); |
610 |
|
if (ctx) |
611 |
|
ctx->cancel = 0; |
612 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
613 |
break; |
break; |
614 |
|
|
615 |
case IDCANCEL: |
case IDCANCEL: |
616 |
EndDialog( dlg, FALSE ); |
if (ctx) |
617 |
|
ctx->cancel = 1; |
618 |
|
EndDialog (dlg, FALSE); |
619 |
break; |
break; |
620 |
} |
} |
621 |
break; |
break; |