/[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 48 by werner, Mon Oct 31 21:14:11 2005 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 91  static const char key_params_one_with_co Line 91  static const char key_params_one_with_co
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";
# Line 119  gpg_genkey_params (int keytype, int bits Line 119  gpg_genkey_params (int keytype, int bits
119      if (keytype == GPG_KEYGEN_NONE)      if (keytype == GPG_KEYGEN_NONE)
120          return NULL;          return NULL;
121            
122      if( comment && *comment ) {      size = strlen (user) + strlen (email) + strlen (passphrase) + addsize + 48;
123          size = strlen (key_params_with_comment)      if (comment && *comment)
124              + 16          size += strlen (key_params_with_comment) + strlen (comment);
125              + strlen( user )      else
126              + addsize          size += strlen (key_params);
127              + strlen( comment )      if (expdate)
128              + strlen( email )          size += strlen (expdate) + 1;
129              +  strlen( passphrase ) + 32;      p = new char[size+1];
130      }      if (!p)
131      else {          BUG (0);
132          size = strlen( key_params )      /* XXX: simply the whole switch-case code. */
133              + 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 ) {  
134          switch( keytype ) {          switch( keytype ) {
135          case GPG_KEYGEN_DSA_ELG:          case GPG_KEYGEN_DSA_ELG:
136              sprintf (p, key_params_with_comment,              sprintf (p, key_params_with_comment,
# Line 184  gpg_genkey_params (int keytype, int bits Line 172  gpg_genkey_params (int keytype, int bits
172              break;              break;
173                            
174          default:          default:
175              if (p)              free_if_alloc (p);
                 free (p);  
             p = NULL;  
176              break;              break;
177          }          }
178      }      }
# Line 232  gpg_genkey_params (int keytype, int bits Line 218  gpg_genkey_params (int keytype, int bits
218              break;              break;
219                            
220          default:          default:
221              if (p)              free_if_alloc (p);
                 free (p);  
             p = NULL;  
222              break;              break;
223          }          }
224      }      }
# Line 261  gpg_genkey (const char *params, gpgme_pr Line 245  gpg_genkey (const char *params, gpgme_pr
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;
# Line 289  clear_dlg_fields (HWND dlg) Line 273  clear_dlg_fields (HWND dlg)
273  static void  static void
274  backup_keyrings (HWND dlg)  backup_keyrings (HWND dlg)
275  {  {
276        const char *name;
277        char *path = NULL;
278        char *keyring = NULL;
279      int id;      int id;
     char *path = NULL, *keyring = NULL;  
     const char * name;  
280            
281      path = get_gnupg_path ();      path = get_gnupg_path ();
282      if (!path)      if (!path)
# Line 304  backup_keyrings (HWND dlg) Line 289  backup_keyrings (HWND dlg)
289                     "Backup your keyrings now?"),                     "Backup your keyrings now?"),
290                   _("WARNING - Important hint" ), MB_YESNO);                   _("WARNING - Important hint" ), MB_YESNO);
291      if (id == IDYES) {      if (id == IDYES) {
292          name = get_filename_dlg( dlg, 1, _("Destination for Public Keyring"), NULL, "pubring.gpg" );          name = get_filesave_dlg (dlg, _("Destination for Public Keyring"),
293                                     NULL, "pubring.gpg");
294          if( name ) {          if( name ) {
295              keyring = make_filename( path, "pubring", "gpg" );              keyring = make_filename (path, "pubring", "gpg");
296              if( !CopyFile( keyring, name, FALSE ) )              if( !CopyFile (keyring, name, FALSE))
297                  log_box( _("Key Generation"), MB_ERR,                  log_box (_("Key Generation"), MB_ERR,
298                           _("Could not copy %s -> %s"), keyring, name );                               _("Could not copy %s -> %s"), keyring, name);
299              free_if_alloc( keyring );              free_if_alloc (keyring);
300          }          }
301          name = get_filename_dlg( dlg, 1, _("Destination for Secret Keyring"), NULL, "secring.gpg" );          name = get_filesave_dlg (dlg, _("Destination for Secret Keyring"),
302                                     NULL, "secring.gpg");
303          if( name ) {          if( name ) {
304              keyring = make_filename( path, "secring", "gpg" );              keyring = make_filename (path, "secring", "gpg");
305              if( !CopyFile( keyring, name, FALSE ) )              if (!CopyFile (keyring, name, FALSE))
306                  log_box( _("Key Generation"), MB_ERR,                  log_box (_("Key Generation"), MB_ERR,
307                           _("Could not copy %s -> %s"), keyring, name );                           _("Could not copy %s -> %s"), keyring, name);
308              free_if_alloc( keyring );              free_if_alloc (keyring);
309          }          }
310      }      }
311      free_if_alloc( path );      free_if_alloc (path);
312  }  }
313    
314    
# Line 329  backup_keyrings (HWND dlg) Line 316  backup_keyrings (HWND dlg)
316  static void  static void
317  fill_keytype_box (HWND dlg)  fill_keytype_box (HWND dlg)
318  {  {
319      HWND cb = GetDlgItem (dlg, IDC_KEYGEN_KEYTYPE );      HWND cb = GetDlgItem (dlg, IDC_KEYGEN_KEYTYPE);
320    
321  #define addstr( cb, str ) \  #define addstr(cb, str) \
322      SendMessage( (cb), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)(str) )      SendMessage ((cb), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)(str))
323      addstr( cb, _("DSA and ELG (default)") );      addstr (cb, _("DSA and ELG (default)"));
324      addstr( cb, _("DSA and RSA") );      addstr (cb, _("DSA and RSA"));
325      addstr( cb, _("DSA sign only") );      addstr (cb, _("DSA sign only"));
326      addstr( cb, _("RSA sign only") );      addstr (cb, _("RSA sign only"));
327      addstr( cb, _("RSA sign and encrypt") );      addstr (cb, _("RSA sign and encrypt"));
328      addstr( cb, _("RSA and RSA (PGP)") );      addstr (cb, _("RSA and RSA (PGP)") );
329      SendMessage( cb, CB_SETCURSEL, 0, 0 );      SendMessage (cb, CB_SETCURSEL, 0, 0);
330  #undef addstr  #undef addstr
331  }  }
332    
# Line 355  keygen_check_date (SYSTEMTIME *st) Line 342  keygen_check_date (SYSTEMTIME *st)
342      if (st->wYear > t.wYear || st->wMonth > t.wMonth)      if (st->wYear > t.wYear || st->wMonth > t.wMonth)
343          return 1;          return 1;
344      else if (st->wYear < t.wYear || st->wMonth < t.wMonth || st->wDay < t.wDay)      else if (st->wYear < t.wYear || st->wMonth < t.wMonth || st->wDay < t.wDay)
345          return 0;                return 0;
346      return 1;      return 1;
347  }  }
348    
# Line 367  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 pwd[128], pwd2[128];      char email[128];
359        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;
362      char * p;        int cancel = 0;
363        char *p;
364            
365      switch ( msg ) {      switch ( msg ) {
366      case WM_INITDIALOG:      case WM_INITDIALOG:
367          if (lparam != NULL)          if (lparam != 0)
368              ctx = (genkey_s *)lparam;              ctx = (genkey_s *)lparam;
369          SetWindowText( dlg, _("Key Generation") );          SetWindowText (dlg, _("Key Generation"));
370          SetDlgItemText( dlg, IDC_KEYGEN_INFO,          SetDlgItemText(dlg, IDC_KEYGEN_INFO,
371                          _("NOTE: Key generation can be a lengthy process! Please wait until "                          _("NOTE: Key generation can be a lengthy process! Please wait until "
372                            "you get the message that key generation was finished.") );                            "you get the message that key generation was finished."));
373          SetDlgItemText( dlg, IDC_KEYGEN_SUBKEYINF, _("Subkey size in &bits"));          SetDlgItemText (dlg, IDC_KEYGEN_SUBKEYINF, _("Subkey size in &bits"));
374          SetDlgItemText( dlg, IDC_KEYGEN_NAMEINF, _("&Real name") );          SetDlgItemText (dlg, IDC_KEYGEN_NAMEINF, _("&Real name"));
375          SetDlgItemText( dlg, IDC_KEYGEN_COMMINF, _("&Comment (optional)") );          SetDlgItemText (dlg, IDC_KEYGEN_COMMINF, _("&Comment (optional)"));
376          SetDlgItemText( dlg, IDC_KEYGEN_EMAILINF, _("Email &address") );          SetDlgItemText (dlg, IDC_KEYGEN_EMAILINF, _("Email &address"));
377          SetDlgItemText( dlg, IDC_KEYGEN_EXPINF, _("&Expire date"));          SetDlgItemText (dlg, IDC_KEYGEN_EXPINF, _("&Expire date"));
378          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") );  
379          SetDlgItemText (dlg, IDC_KEYGEN_EXPNEVER, _("&Never"));          SetDlgItemText (dlg, IDC_KEYGEN_EXPNEVER, _("&Never"));
380          SetDlgItemText (dlg, IDC_KEYGEN_HIDEPWD, _("&Hide Typing"));          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
381    
382          SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, 2048, FALSE);          SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, DFAULT_KEYSIZE, FALSE);
383          CheckDlgButton (dlg, IDC_KEYGEN_HIDEPWD, BST_CHECKED);          CheckDlgButton (dlg, IDC_KEYGEN_HIDEPWD, BST_CHECKED);
384          CheckDlgButton (dlg, IDC_KEYGEN_EXPNEVER, BST_CHECKED);          CheckDlgButton (dlg, IDC_KEYGEN_EXPNEVER, BST_CHECKED);
385          EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), FALSE);          EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), FALSE);
# Line 402  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 389  keygen_dlg_proc (HWND dlg, UINT msg, WPA
389          return TRUE;          return TRUE;
390                    
391      case WM_SYSCOMMAND:      case WM_SYSCOMMAND:
392          if (LOWORD (wparam) == SC_CLOSE) {          if (LOWORD (wparam) == SC_CLOSE)
             SetDlgItemText (dlg, IDC_KEYGEN_PASSPHRASE, "");  
             SetDlgItemText (dlg, IDC_KEYGEN_PWDCHECK, "");  
393              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
         }  
394          return FALSE;          return FALSE;
395                    
396      case WM_COMMAND:      case WM_COMMAND:
# Line 415  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 399  keygen_dlg_proc (HWND dlg, UINT msg, WPA
399              int never = IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER);              int never = IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER);
400              EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), !never);              EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), !never);
401          }          }
         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);  
         }  
402    
403          switch( LOWORD( wparam ) ) {          switch (LOWORD (wparam)) {
404          case IDOK:          case IDOK:
405              bits = GetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, NULL, FALSE);              bits = GetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, NULL, FALSE);
406              if (bits < 1024 || bits > 4096) {              if (bits < 1024 || bits > 4096) {
# Line 435  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 409  keygen_dlg_proc (HWND dlg, UINT msg, WPA
409                  return FALSE;                  return FALSE;
410              }              }
411              if (bits > DFAULT_KEYSIZE) {              if (bits > DFAULT_KEYSIZE) {
412                  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?"),
413                                    _("Key Generation"), MB_YESNO);                                    _("Key Generation"), MB_YESNO);
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, comment, sizeof comment -1 );              use_comment = GetDlgItemText_utf8 (dlg, IDC_KEYGEN_COMMENT,
435              if( use_comment > 0 && strchr( comment, '@' ) ) {                                                 &utf8_comment);
436                  msg_box( dlg, _("Please do NOT enter the email address in the comment field."),              if (use_comment > 0 && strchr (utf8_comment, '@')) {
437                           _("Key Generation"), MB_INFO );                  msg_box (dlg, _("Please do NOT enter the email address in the comment field."),
438                             _("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 469  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 448  keygen_dlg_proc (HWND dlg, UINT msg, WPA
448                  _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);
449                  expire = t;                  expire = t;
450              }              }
451                
452              if( !GetDlgItemText( dlg, IDC_KEYGEN_PASSPHRASE, pwd, sizeof pwd -1 ) ) {              pwd = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel);
453                  msg_box( dlg, _("Please enter the passphrase."),              if (cancel) {
454                           _("Key Generation"), MB_ERR );                  sfree_if_alloc (pwd);
455                  return FALSE;                  free_if_alloc (utf8_name);
456              }                  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, "" );  
457                  return FALSE;                  return FALSE;
458              }              }
459                                                if (!pwd) {
460              if( !use_comment && !strlen( comment ) ) {                  msg_box (dlg, _("Please enter the passphrase."),
461                  char *utf8_name;                           _("Key Generation"), MB_ERR);
462                  utf8_name = wincp_to_utf8 (name, strlen (name));                  free_if_alloc (utf8_name);
463                  if( !utf8_name )                  free_if_alloc (utf8_comment);
464                      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 );  
465              }              }
466              keygen_cb_dlg_create( );  
467                if (!use_comment && !strlen (utf8_comment))
468                    p = gpg_genkey_params (keytype, bits, utf8_name, NULL,
469                                           email, expire, pwd);
470                else
471                    p = gpg_genkey_params (keytype, bits, utf8_name, utf8_comment,
472                                           email, expire, pwd);
473                free_if_alloc (utf8_name);
474                free_if_alloc (utf8_comment);
475                keygen_cb_dlg_create ();
476              err = gpg_genkey (p, keygen_cb, &fpr);              err = gpg_genkey (p, keygen_cb, &fpr);
477              wipememory (pwd, sizeof (pwd));                  sfree_if_alloc (pwd);
478              wipememory (pwd2, sizeof (pwd2));              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);
483              keygen_cb (NULL, NULL, 0, 0, 0); /* flush */              if (err) {
484              if( err ) {                  free_if_alloc (fpr);
485                  if (fpr)                  msg_box (dlg, gpgme_strerror (err), _("Key Generation"), MB_ERR);
                     free (fpr);  
                 msg_box (dlg, gpgme_strerror( err ), _("Key Generation"), MB_ERR);  
486                  return FALSE;                  return FALSE;
487              }              }
488              status_box( dlg, _("Key Generation completed"), _("GnuPG Status") );              status_box (dlg, _("Key Generation completed"), _("GnuPG Status"));
489                            
490              keycache_update (0, fpr);              keycache_update (0, fpr);
491              keycache_update (1, fpr);              keycache_update (1, fpr);
492              if (ctx->first_start == 0 && ctx != NULL)              free_if_alloc (fpr);            
                 get_pubkey (fpr, &ctx->newkey);  
             if (fpr)  
                 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              SetDlgItemText (dlg, IDC_KEYGEN_PASSPHRASE, "");              if (ctx)
503              SetDlgItemText (dlg, IDC_KEYGEN_PWDCHECK, "");                  ctx->cancel = 1;
504              EndDialog (dlg, FALSE);              EndDialog (dlg, FALSE);        
505              return FALSE;              return FALSE;
506          }          }
507          break;          break;
# Line 576  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 594  keygen_wizard_dlg_proc (HWND dlg, UINT m Line 535  keygen_wizard_dlg_proc (HWND dlg, UINT m
535          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."));
536          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."));
537          SetWindowText (dlg, _("Key Generation Wizard"));          SetWindowText (dlg, _("Key Generation Wizard"));
538            SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
539            SetDlgItemText (dlg, IDC_KEYWIZARD_EXPERT, _("E&xpert"));
540          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
541          center_window (dlg, NULL);          center_window (dlg, NULL);
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, NULL);                              keygen_dlg_proc, 0);
553              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
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;

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26