/[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 129 by twoaday, Wed Dec 7 08:11:34 2005 UTC revision 130 by twoaday, Fri Dec 30 14:06:39 2005 UTC
# 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 = (char *)malloc (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 289  clear_dlg_fields (HWND dlg) Line 277  clear_dlg_fields (HWND dlg)
277  static void  static void
278  backup_keyrings (HWND dlg)  backup_keyrings (HWND dlg)
279  {  {
280        const char *name;
281        char *path = NULL;
282        char *keyring = NULL;
283      int id;      int id;
     char *path = NULL, *keyring = NULL;  
     const char * name;  
284            
285      path = get_gnupg_path ();      path = get_gnupg_path ();
286      if (!path)      if (!path)
# Line 304  backup_keyrings (HWND dlg) Line 293  backup_keyrings (HWND dlg)
293                     "Backup your keyrings now?"),                     "Backup your keyrings now?"),
294                   _("WARNING - Important hint" ), MB_YESNO);                   _("WARNING - Important hint" ), MB_YESNO);
295      if (id == IDYES) {      if (id == IDYES) {
296          name = get_filesave_dlg( dlg, _("Destination for Public Keyring"), NULL, "pubring.gpg" );          name = get_filesave_dlg (dlg, _("Destination for Public Keyring"),
297                                     NULL, "pubring.gpg");
298          if( name ) {          if( name ) {
299              keyring = make_filename( path, "pubring", "gpg" );              keyring = make_filename (path, "pubring", "gpg");
300              if( !CopyFile( keyring, name, FALSE ) )              if( !CopyFile (keyring, name, FALSE))
301                  log_box( _("Key Generation"), MB_ERR,                  log_box (_("Key Generation"), MB_ERR,
302                           _("Could not copy %s -> %s"), keyring, name );                               _("Could not copy %s -> %s"), keyring, name);
303              free_if_alloc( keyring );              free_if_alloc (keyring);
304          }          }
305          name = get_filesave_dlg( dlg, _("Destination for Secret Keyring"), NULL, "secring.gpg" );          name = get_filesave_dlg (dlg, _("Destination for Secret Keyring"),
306                                     NULL, "secring.gpg");
307          if( name ) {          if( name ) {
308              keyring = make_filename( path, "secring", "gpg" );              keyring = make_filename (path, "secring", "gpg");
309              if( !CopyFile( keyring, name, FALSE ) )              if (!CopyFile (keyring, name, FALSE))
310                  log_box( _("Key Generation"), MB_ERR,                  log_box (_("Key Generation"), MB_ERR,
311                           _("Could not copy %s -> %s"), keyring, name );                           _("Could not copy %s -> %s"), keyring, name);
312              free_if_alloc( keyring );              free_if_alloc (keyring);
313          }          }
314      }      }
315      free_if_alloc( path );      free_if_alloc (path);
316  }  }
317    
318    
# Line 329  backup_keyrings (HWND dlg) Line 320  backup_keyrings (HWND dlg)
320  static void  static void
321  fill_keytype_box (HWND dlg)  fill_keytype_box (HWND dlg)
322  {  {
323      HWND cb = GetDlgItem (dlg, IDC_KEYGEN_KEYTYPE );      HWND cb = GetDlgItem (dlg, IDC_KEYGEN_KEYTYPE);
324    
325  #define addstr( cb, str ) \  #define addstr(cb, str) \
326      SendMessage( (cb), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)(str) )      SendMessage ((cb), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)(str))
327      addstr( cb, _("DSA and ELG (default)") );      addstr (cb, _("DSA and ELG (default)"));
328      addstr( cb, _("DSA and RSA") );      addstr (cb, _("DSA and RSA"));
329      addstr( cb, _("DSA sign only") );      addstr (cb, _("DSA sign only"));
330      addstr( cb, _("RSA sign only") );      addstr (cb, _("RSA sign only"));
331      addstr( cb, _("RSA sign and encrypt") );      addstr (cb, _("RSA sign and encrypt"));
332      addstr( cb, _("RSA and RSA (PGP)") );      addstr (cb, _("RSA and RSA (PGP)") );
333      SendMessage( cb, CB_SETCURSEL, 0, 0 );      SendMessage (cb, CB_SETCURSEL, 0, 0);
334  #undef addstr  #undef addstr
335  }  }
336    
# Line 355  keygen_check_date (SYSTEMTIME *st) Line 346  keygen_check_date (SYSTEMTIME *st)
346      if (st->wYear > t.wYear || st->wMonth > t.wMonth)      if (st->wYear > t.wYear || st->wMonth > t.wMonth)
347          return 1;          return 1;
348      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)
349          return 0;                return 0;
350      return 1;      return 1;
351  }  }
352    
# Line 368  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 359  keygen_dlg_proc (HWND dlg, UINT msg, WPA
359      SYSTEMTIME st;      SYSTEMTIME st;
360      gpgme_error_t err;      gpgme_error_t err;
361      char name[128] = {0}, email[128] = {0}, comment[128] = {0};      char name[128] = {0}, email[128] = {0}, comment[128] = {0};
362      char pwd[128], pwd2[128];      char *pwd;
363      char t[64], *expire = NULL, *fpr=NULL;      char t[64], *expire = NULL, *fpr=NULL;
364      int bits, use_comment, keytype = 0;          int bits, use_comment, keytype = 0;
365      char * p;        int cancel = 0;
366        char *p;
367            
368      switch ( msg ) {      switch ( msg ) {
369      case WM_INITDIALOG:      case WM_INITDIALOG:
370          if (lparam != 0)          if (lparam != 0)
371              ctx = (genkey_s *)lparam;              ctx = (genkey_s *)lparam;
372          SetWindowText( dlg, _("Key Generation") );          SetWindowText (dlg, _("Key Generation"));
373          SetDlgItemText( dlg, IDC_KEYGEN_INFO,          SetDlgItemText(dlg, IDC_KEYGEN_INFO,
374                          _("NOTE: Key generation can be a lengthy process! Please wait until "                          _("NOTE: Key generation can be a lengthy process! Please wait until "
375                            "you get the message that key generation was finished.") );                            "you get the message that key generation was finished."));
376          SetDlgItemText( dlg, IDC_KEYGEN_SUBKEYINF, _("Subkey size in &bits"));          SetDlgItemText (dlg, IDC_KEYGEN_SUBKEYINF, _("Subkey size in &bits"));
377          SetDlgItemText( dlg, IDC_KEYGEN_NAMEINF, _("&Real name") );          SetDlgItemText (dlg, IDC_KEYGEN_NAMEINF, _("&Real name"));
378          SetDlgItemText( dlg, IDC_KEYGEN_COMMINF, _("&Comment (optional)") );          SetDlgItemText (dlg, IDC_KEYGEN_COMMINF, _("&Comment (optional)"));
379          SetDlgItemText( dlg, IDC_KEYGEN_EMAILINF, _("Email &address") );          SetDlgItemText (dlg, IDC_KEYGEN_EMAILINF, _("Email &address"));
380          SetDlgItemText( dlg, IDC_KEYGEN_EXPINF, _("&Expire date"));          SetDlgItemText (dlg, IDC_KEYGEN_EXPINF, _("&Expire date"));
381          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") );  
382          SetDlgItemText (dlg, IDC_KEYGEN_EXPNEVER, _("&Never"));          SetDlgItemText (dlg, IDC_KEYGEN_EXPNEVER, _("&Never"));
         SetDlgItemText (dlg, IDC_KEYGEN_HIDEPWD, _("&Hide Typing"));  
383          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
384    
385          SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, 2048, FALSE);          SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, DFAULT_KEYSIZE, FALSE);
386          CheckDlgButton (dlg, IDC_KEYGEN_HIDEPWD, BST_CHECKED);          CheckDlgButton (dlg, IDC_KEYGEN_HIDEPWD, BST_CHECKED);
387          CheckDlgButton (dlg, IDC_KEYGEN_EXPNEVER, BST_CHECKED);          CheckDlgButton (dlg, IDC_KEYGEN_EXPNEVER, BST_CHECKED);
388          EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), FALSE);          EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), FALSE);
# Line 403  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 392  keygen_dlg_proc (HWND dlg, UINT msg, WPA
392          return TRUE;          return TRUE;
393                    
394      case WM_SYSCOMMAND:      case WM_SYSCOMMAND:
395          if (LOWORD (wparam) == SC_CLOSE) {          if (LOWORD (wparam) == SC_CLOSE)
             SetDlgItemText (dlg, IDC_KEYGEN_PASSPHRASE, "");  
             SetDlgItemText (dlg, IDC_KEYGEN_PWDCHECK, "");  
396              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
         }  
397          return FALSE;          return FALSE;
398                    
399      case WM_COMMAND:      case WM_COMMAND:
# Line 416  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 402  keygen_dlg_proc (HWND dlg, UINT msg, WPA
402              int never = IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER);              int never = IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER);
403              EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), !never);              EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), !never);
404          }          }
         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);  
         }  
405    
406          switch( LOWORD( wparam ) ) {          switch (LOWORD (wparam)) {
407          case IDOK:          case IDOK:
408              bits = GetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, NULL, FALSE);              bits = GetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, NULL, FALSE);
409              if (bits < 1024 || bits > 4096) {              if (bits < 1024 || bits > 4096) {
# Line 436  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 412  keygen_dlg_proc (HWND dlg, UINT msg, WPA
412                  return FALSE;                  return FALSE;
413              }              }
414              if (bits > DFAULT_KEYSIZE) {              if (bits > DFAULT_KEYSIZE) {
415                  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?"),
416                                    _("Key Generation"), MB_YESNO);                                    _("Key Generation"), MB_YESNO);
417                  if (id == IDNO)                  if (id == IDNO)
418                      bits = DFAULT_KEYSIZE;                      bits = DFAULT_KEYSIZE;
419              }              }
420              if( !GetDlgItemText( dlg, IDC_KEYGEN_NAME, name, sizeof name - 1 ) ) {              if (!GetDlgItemText (dlg, IDC_KEYGEN_NAME, name, sizeof (name) - 1)) {
421                  msg_box( dlg, _("Please enter the name."), _("Key Generation"), MB_ERR );                  msg_box( dlg, _("Please enter the name."), _("Key Generation"), MB_ERR);
422                  return FALSE;                  return FALSE;
423              }              }
424              if (strchr (name, '@')) {              if (strchr (name, '@')) {
# Line 450  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 426  keygen_dlg_proc (HWND dlg, UINT msg, WPA
426                           _("Key Generation"), MB_INFO);                           _("Key Generation"), MB_INFO);
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, '@') ) {                  || !strchr (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                  return FALSE;                  return FALSE;
434              }              }
435              use_comment = GetDlgItemText( dlg, IDC_KEYGEN_COMMENT, comment, sizeof comment -1 );              use_comment = GetDlgItemText(dlg, IDC_KEYGEN_COMMENT,
436              if( use_comment > 0 && strchr( comment, '@' ) ) {                                           comment, sizeof (comment) -1);
437                  msg_box( dlg, _("Please do NOT enter the email address in the comment field."),              if (use_comment > 0 && strchr (comment, '@')) {
438                           _("Key Generation"), MB_INFO );                  msg_box (dlg, _("Please do NOT enter the email address in the comment field."),
439                             _("Key Generation"), MB_INFO);
440                  return FALSE;                  return FALSE;
441              }              }
442              keytype = SendDlgItemMessage (dlg, IDC_KEYGEN_KEYTYPE, CB_GETCURSEL, 0, 0) + 1;              keytype = SendDlgItemMessage (dlg, IDC_KEYGEN_KEYTYPE, CB_GETCURSEL, 0, 0) + 1;
# Line 470  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 447  keygen_dlg_proc (HWND dlg, UINT msg, WPA
447                  _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);
448                  expire = t;                  expire = t;
449              }              }
450                
451              if( !GetDlgItemText( dlg, IDC_KEYGEN_PASSPHRASE, pwd, sizeof pwd -1 ) ) {              pwd = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel);
452                  msg_box( dlg, _("Please enter the passphrase."),              if (cancel) {
453                           _("Key Generation"), MB_ERR );                  sfree_if_alloc (pwd);
                 return FALSE;  
             }  
             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, "" );  
454                  return FALSE;                  return FALSE;
455              }              }
456                                                if (!pwd) {
457              if( !use_comment && !strlen( comment ) ) {                  msg_box (dlg, _("Please enter the passphrase."),
458                             _("Key Generation"), MB_ERR);
459                    return FALSE;
460                }
461    
462                if (!use_comment && !strlen (comment)) {
463                  char *utf8_name;                  char *utf8_name;
464                  utf8_name = wincp_to_utf8 (name, strlen (name));                  utf8_name = wincp_to_utf8 (name, strlen (name));
465                  if( !utf8_name )                  if (!utf8_name)
466                      BUG( dlg );                      BUG (0);
467                  p = gpg_genkey_params( keytype, bits, utf8_name, NULL, email, expire, pwd );                  p = gpg_genkey_params (keytype, bits, utf8_name, NULL,
468                  free( utf8_name );                                         email, expire, pwd);
469                    safe_free (utf8_name);
470              }              }
471              else {              else {
472                  char *utf8_name, *utf8_comment;                  char *utf8_name, *utf8_comment;
473                  utf8_name = wincp_to_utf8 (name, strlen (name));                  utf8_name = wincp_to_utf8 (name, strlen (name));
474                  utf8_comment = wincp_to_utf8 (comment, strlen (comment));                                utf8_comment = wincp_to_utf8 (comment, strlen (comment));              
475                  if( !utf8_name || !utf8_comment )                  if( !utf8_name || !utf8_comment )
476                      BUG( dlg );                      BUG (0);
477                  p = gpg_genkey_params( keytype, bits, utf8_name, utf8_comment, email, expire, pwd );                  p = gpg_genkey_params (keytype, bits, utf8_name, utf8_comment,
478                  free( utf8_name );                                         email, expire, pwd);
479                  free( utf8_comment );                  safe_free (utf8_name);
480                    safe_free (utf8_comment);
481              }              }
482              keygen_cb_dlg_create( );              keygen_cb_dlg_create ();
483              err = gpg_genkey (p, keygen_cb, &fpr);              err = gpg_genkey (p, keygen_cb, &fpr);
484              wipememory (pwd, sizeof (pwd));                  sfree_if_alloc (pwd);
             wipememory (pwd2, sizeof (pwd2));  
485              if (p) {              if (p) {
486                  wipememory (p, strlen (p));  /* burn the passphrase! */                  wipememory (p, strlen (p));  /* burn the passphrase! */
487                  free (p);                  free (p);
# Line 539  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 489  keygen_dlg_proc (HWND dlg, UINT msg, WPA
489              keygen_cb_dlg_destroy ();              keygen_cb_dlg_destroy ();
490              keygen_cb (NULL, NULL, 0, 0, 0); /* flush */              keygen_cb (NULL, NULL, 0, 0, 0); /* flush */
491              if (err) {              if (err) {
492                  if (fpr)                  safe_free (fpr);
                     free (fpr);  
493                  msg_box (dlg, gpgme_strerror (err), _("Key Generation"), MB_ERR);                  msg_box (dlg, gpgme_strerror (err), _("Key Generation"), MB_ERR);
494                  return FALSE;                  return FALSE;
495              }              }
# Line 558  keygen_dlg_proc (HWND dlg, UINT msg, WPA Line 507  keygen_dlg_proc (HWND dlg, UINT msg, WPA
507              return TRUE;              return TRUE;
508                            
509          case IDCANCEL:          case IDCANCEL:
             SetDlgItemText (dlg, IDC_KEYGEN_PASSPHRASE, "");  
             SetDlgItemText (dlg, IDC_KEYGEN_PWDCHECK, "");  
510              EndDialog (dlg, FALSE);              EndDialog (dlg, FALSE);
511              return FALSE;              return FALSE;
512          }          }

Legend:
Removed from v.129  
changed lines
  Added in v.130

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26