/[winpt]/trunk/Src/wptKeygenDlg.cpp
ViewVC logotype

Diff of /trunk/Src/wptKeygenDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 201 by twoaday, Sat Apr 22 18:30:24 2006 UTC revision 211 by twoaday, Sun May 7 12:36:48 2006 UTC
# Line 33  Line 33 
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 {
# Line 92  static const char key_params_one_with_co Line 92  static const char key_params_one_with_co
92          "Key-Usage: %s\n"                "Key-Usage: %s\n"      
93          "Name-Real: %s\n"                "Name-Real: %s\n"      
94          "Name-Comment: %s\n"          "Name-Comment: %s\n"
95          "Name-Email: %s\n"          "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";
# Line 354  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 354  keygen_dlg_proc (HWND dlg, UINT msg, WPA
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;
# Line 413  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 414  keygen_dlg_proc (HWND dlg, UINT msg, WPA
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                  || check_email_address (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;
# Line 447  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 452  keygen_dlg_proc (HWND dlg, UINT msg, WPA
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 = native_to_utf8 (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                  free_if_alloc (utf8_name);              else
             }  
             else {  
                 char *utf8_name, *utf8_comment;  
                 utf8_name = native_to_utf8 (name);  
                 utf8_comment = native_to_utf8 (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                  free_if_alloc (utf8_name);              free_if_alloc (utf8_name);
474                  free_if_alloc (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);
# Line 482  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 479  keygen_dlg_proc (HWND dlg, UINT msg, WPA
479                  wipememory (p, strlen (p));  /* burn the passphrase! */                  wipememory (p, strlen (p));  /* burn the passphrase! */
480                  free_if_alloc (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                  free_if_alloc (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);
# Line 521  keygen_wizard_dlg_proc (HWND dlg, UINT m Line 517  keygen_wizard_dlg_proc (HWND dlg, UINT m
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            
# Line 546  keygen_wizard_dlg_proc (HWND dlg, UINT m Line 542  keygen_wizard_dlg_proc (HWND dlg, UINT m
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);
# Line 558  keygen_wizard_dlg_proc (HWND dlg, UINT m Line 554  keygen_wizard_dlg_proc (HWND dlg, UINT m
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                  || check_email_address (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 = native_to_utf8 (name);              }
             if (!utf8_name)  
                 BUG (0);  
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,
# Line 592  keygen_wizard_dlg_proc (HWND dlg, UINT m Line 590  keygen_wizard_dlg_proc (HWND dlg, UINT m
590              free_if_alloc (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);
             keygen_cb (NULL, NULL, 0, 0, 0);  
594              if (p) {              if (p) {
595                  wipememory (p, strlen (p));                  wipememory (p, strlen (p));
596                  free_if_alloc (p);                  free_if_alloc (p);
# Line 604  keygen_wizard_dlg_proc (HWND dlg, UINT m Line 601  keygen_wizard_dlg_proc (HWND dlg, UINT m
601                  free_if_alloc (fpr);                  free_if_alloc (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              free_if_alloc (fpr);              free_if_alloc (fpr);

Legend:
Removed from v.201  
changed lines
  Added in v.211

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26