/[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 34 by twoaday, Wed Oct 26 11:20:09 2005 UTC revision 201 by twoaday, Sat Apr 22 18:30:24 2006 UTC
# Line 1  Line 1 
1  /* wptKeygenDlg.cpp - Key Generation dialog  /* wptKeygenDlg.cpp - Key Generation dialog
2   *      Copyright (C) 2000-2005 Timo Schulz   *      Copyright (C) 2000-2005 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
7   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
8   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
20  #include <windows.h>  #ifdef HAVE_CONFIG_H
21    #include <config.h>
22  #include "../resource.h"  #endif
23  #include "wptTypes.h"  
24  #include "wptNLS.h"  #include <windows.h>
25  #include "wptGPG.h"  
26  #include "wptCommonCtl.h"  #include "resource.h"
27  #include "wptContext.h" /* for passphrase_s */  #include "wptTypes.h"
28  #include "wptDlgs.h"  #include "wptNLS.h"
29  #include "wptW32API.h"  #include "wptGPG.h"
30  #include "wptVersion.h"  #include "wptCommonCtl.h"
31  #include "wptErrors.h"  #include "wptContext.h" /* for passphrase_s */
32  #include "wptUTF8.h"  #include "wptDlgs.h"
33    #include "wptW32API.h"
34  /* All valid key generation combination. */  #include "wptVersion.h"
35  enum gpg_keytype_t {  #include "wptErrors.h"
36      GPG_KEYGEN_NONE    = 0,  #include "wptUTF8.h"
37      GPG_KEYGEN_DSA_ELG = 1,  
38      GPG_KEYGEN_DSA_RSA = 2,  /* All valid key generation combination. */
39      GPG_KEYGEN_DSA_SIG = 3,  enum gpg_keytype_t {
40      GPG_KEYGEN_RSA_SIG = 4,          GPG_KEYGEN_NONE    = 0,
41      GPG_KEYGEN_RSA     = 5,      GPG_KEYGEN_DSA_ELG = 1,
42      GPG_KEYGEN_RSA_RSA = 6 /*PGP*/      GPG_KEYGEN_DSA_RSA = 2,
43  };      GPG_KEYGEN_DSA_SIG = 3,
44        GPG_KEYGEN_RSA_SIG = 4,    
45        GPG_KEYGEN_RSA     = 5,
46  static const char key_params[] =      GPG_KEYGEN_RSA_RSA = 6 /*PGP*/
47          "<GnupgKeyParms format=\"internal\">\n"  };
48          "Key-Type: %s\n"  
49          "Key-Usage: sign\n"  
50          "Key-Length: %d\n"  static const char key_params[] =
51          "Subkey-Type: %s\n"          "<GnupgKeyParms format=\"internal\">\n"
52          "Subkey-Length: %d\n"          "Key-Type: %s\n"
53          "Name-Real: %s\n"                "Key-Usage: sign\n"
54          "Name-Email: %s\n"          "Key-Length: %d\n"
55          "Expire-Date: %s\n"          "Subkey-Type: %s\n"
56          "Passphrase: %s\n"          "Subkey-Length: %d\n"
57          "</GnupgKeyParms>\n";          "Name-Real: %s\n"      
58            "Name-Email: %s\n"
59  static const char key_params_with_comment[] =          "Expire-Date: %s\n"
60          "<GnupgKeyParms format=\"internal\">\n"          "Passphrase: %s\n"
61          "Key-Type: %s\n"          "</GnupgKeyParms>\n";
62          "Key-Usage: sign\n"  
63          "Key-Length: %d\n"  static const char key_params_with_comment[] =
64          "Subkey-Type: %s\n"          "<GnupgKeyParms format=\"internal\">\n"
65          "Subkey-Length: %d\n"          "Key-Type: %s\n"
66          "Name-Real: %s\n"          "Key-Usage: sign\n"
67          "Name-Comment: %s\n"          "Key-Length: %d\n"
68          "Name-Email: %s\n"          "Subkey-Type: %s\n"
69          "Expire-Date: %s\n"          "Subkey-Length: %d\n"
70          "Passphrase: %s\n"          "Name-Real: %s\n"
71          "</GnupgKeyParms>\n";          "Name-Comment: %s\n"
72            "Name-Email: %s\n"
73  static const char key_params_one[] =          "Expire-Date: %s\n"
74          "<GnupgKeyParms format=\"internal\">\n"          "Passphrase: %s\n"
75          "Key-Type: %s\n"          "</GnupgKeyParms>\n";
76          "Key-Length: %d\n"  
77          "Key-Usage: %s\n"        static const char key_params_one[] =
78          "Name-Real: %s\n"                "<GnupgKeyParms format=\"internal\">\n"
79          "Name-Email: %s\n"          "Key-Type: %s\n"
80          "Expire-Date: %s\n"          "Key-Length: %d\n"
81          "Passphrase: %s\n"          "Key-Usage: %s\n"      
82          "</GnupgKeyParms>\n";          "Name-Real: %s\n"      
83            "Name-Email: %s\n"
84  static const char key_params_one_with_comment[] =          "Expire-Date: %s\n"
85          "<GnupgKeyParms format=\"internal\">\n"          "Passphrase: %s\n"
86          "Key-Type: %s\n"          "</GnupgKeyParms>\n";
87          "Key-Length: %d\n"  
88          "Key-Usage: %s\n"        static const char key_params_one_with_comment[] =
89          "Name-Real: %s\n"                "<GnupgKeyParms format=\"internal\">\n"
90          "Name-Email: %s\n"          "Key-Type: %s\n"
91          "Name-Comment: %s\n"          "Key-Length: %d\n"
92          "Expire-Date: %s\n"          "Key-Usage: %s\n"      
93          "Passphrase: %s\n"          "Name-Real: %s\n"      
94          "</GnupgKeyParms>\n";          "Name-Comment: %s\n"
95            "Name-Email: %s\n"
96            "Expire-Date: %s\n"
97  /* Generate the GPG specific genkey params with the given information.          "Passphrase: %s\n"
98     @keytype: See valid combinations.          "</GnupgKeyParms>\n";
99     @bits: Length in bits.  
100     @user: user-ID name  
101     @comment: comment for the user-ID.  /* Generate the GPG specific genkey params with the given information.
102     @email: email address.     @keytype: See valid combinations.
103     @expdata: date of expiration or NULL.     @bits: Length in bits.
104     @passphrase: the actual passphrase.     @user: user-ID name
105     Return value: the gen. params. */     @comment: comment for the user-ID.
106  static char*     @email: email address.
107  gpg_genkey_params (int keytype, int bits,     @expdata: date of expiration or NULL.
108                     const char *user, const char *comment, const char *email,     @passphrase: the actual passphrase.
109                     const char *expdate, const char *passphrase)     Return value: the gen. params. */
110  {  static char*
111      char *p = NULL;  gpg_genkey_params (int keytype, int bits,
112      int addsize = strlen ("sign encrypt");                     const char *user, const char *comment, const char *email,
113      int size = 0;                     const char *expdate, const char *passphrase)
114        {
115      if (keytype == GPG_KEYGEN_NONE)      char *p = NULL;
116          return NULL;      int addsize = strlen ("sign encrypt");
117            int size = 0;
118      if( comment && *comment ) {      
119          size = strlen (key_params_with_comment)      if (keytype == GPG_KEYGEN_NONE)
120              + 16          return NULL;
121              + strlen( user )      
122              + addsize      size = strlen (user) + strlen (email) + strlen (passphrase) + addsize + 48;
123              + strlen( comment )      if (comment && *comment)
124              + strlen( email )          size += strlen (key_params_with_comment) + strlen (comment);
125              +  strlen( passphrase ) + 32;      else
126      }          size += strlen (key_params);
127      else {      if (expdate)
128          size = strlen( key_params )          size += strlen (expdate) + 1;
129              + 16      p = new char[size+1];
130              + strlen( user )      if (!p)
131              + strlen( email )          BUG (0);
132              + strlen( passphrase )      /* XXX: simply the whole switch-case code. */
133              + addsize      if (comment && *comment) {
134              + 32;          switch( keytype ) {
135      }          case GPG_KEYGEN_DSA_ELG:
136      if( expdate )              sprintf (p, key_params_with_comment,
137          size += strlen( expdate );                       "DSA", 1024, "ELG-E", bits, user, comment, email,
138      p = (char *)malloc( size+1 );                       expdate ? expdate : "0", passphrase);
139      if( !p )              break;
140          return NULL;              
141      if( comment && *comment ) {          case GPG_KEYGEN_DSA_RSA:
142          switch( keytype ) {              sprintf( p, key_params_with_comment,
143          case GPG_KEYGEN_DSA_ELG:                       "DSA", 1024, "RSA", bits, user, comment, email,
144              sprintf (p, key_params_with_comment,                       expdate ? expdate : "0", passphrase );
145                       "DSA", 1024, "ELG-E", bits, user, comment, email,              break;
146                       expdate ? expdate : "0", passphrase);              
147              break;          case GPG_KEYGEN_DSA_SIG:
148                            sprintf( p, key_params_one_with_comment,
149          case GPG_KEYGEN_DSA_RSA:                       "DSA", 1024, "sign",
150              sprintf( p, key_params_with_comment,                       user, comment, email,
151                       "DSA", 1024, "RSA", bits, user, comment, email,                       expdate ? expdate : "0", passphrase );
152                       expdate ? expdate : "0", passphrase );              break;
153              break;              
154                        case GPG_KEYGEN_RSA_SIG:
155          case GPG_KEYGEN_DSA_SIG:              sprintf( p, key_params_one_with_comment,
156              sprintf( p, key_params_one_with_comment,                       "RSA", bits, "sign",
157                       "DSA", 1024, "sign",                       user, comment, email,
158                       user, comment, email,                       expdate ? expdate : "0", passphrase );
159                       expdate ? expdate : "0", passphrase );              break;
160              break;              
161                        case GPG_KEYGEN_RSA:
162          case GPG_KEYGEN_RSA_SIG:              sprintf( p, key_params_one_with_comment,
163              sprintf( p, key_params_one_with_comment,                      "RSA", bits, "sign encrypt",
164                       "RSA", bits, "sign",                      user, comment, email,
165                       user, comment, email,                      expdate ? expdate : "0", passphrase );
166                       expdate ? expdate : "0", passphrase );              break;
167              break;  
168                        case GPG_KEYGEN_RSA_RSA:
169          case GPG_KEYGEN_RSA:              sprintf( p, key_params_with_comment,
170              sprintf( p, key_params_one_with_comment,                       "RSA", bits, "RSA", bits, user, comment, email,
171                      "RSA", bits, "sign encrypt",                       expdate? expdate : "0", passphrase );
172                      user, comment, email,              break;
173                      expdate ? expdate : "0", passphrase );              
174              break;          default:
175                free_if_alloc (p);
176          case GPG_KEYGEN_RSA_RSA:              break;
177              sprintf( p, key_params_with_comment,          }
178                       "RSA", bits, "RSA", bits, user, comment, email,      }
179                       expdate? expdate : "0", passphrase );      else {
180              break;          switch ( keytype ) {
181                        case GPG_KEYGEN_DSA_ELG:
182          default:              sprintf( p, key_params,
183              if (p)                      "DSA", 1024, "ELG-E", bits, user, email,
184                  free (p);                      expdate ? expdate : "0", passphrase );
185              p = NULL;              break;
186              break;              
187          }          case GPG_KEYGEN_DSA_RSA:
188      }              sprintf( p, key_params,
189      else {                      "DSA", 1024, "RSA", bits, user, email,
190          switch ( keytype ) {                      expdate ? expdate : "0", passphrase );
191          case GPG_KEYGEN_DSA_ELG:              break;
192              sprintf( p, key_params,              
193                      "DSA", 1024, "ELG-E", bits, user, email,          case GPG_KEYGEN_DSA_SIG:
194                      expdate ? expdate : "0", passphrase );              sprintf( p, key_params_one,
195              break;                      "DSA", 1024, "sign",
196                                    user, email,
197          case GPG_KEYGEN_DSA_RSA:                      expdate ? expdate : "0", passphrase );
198              sprintf( p, key_params,              break;
199                      "DSA", 1024, "RSA", bits, user, email,              
200                      expdate ? expdate : "0", passphrase );          case GPG_KEYGEN_RSA_SIG:
201              break;              sprintf( p, key_params_one,
202                                    "RSA", bits, "sign",
203          case GPG_KEYGEN_DSA_SIG:                      user, email,
204              sprintf( p, key_params_one,                      expdate ? expdate : "0", passphrase );
205                      "DSA", 1024, "sign",              break;
206                      user, email,              
207                      expdate ? expdate : "0", passphrase );          case GPG_KEYGEN_RSA:
208              break;              sprintf( p, key_params_one,
209                                    "RSA", bits, "sign encrypt",
210          case GPG_KEYGEN_RSA_SIG:                      user, email,
211              sprintf( p, key_params_one,                      expdate ? expdate : "0", passphrase );
212                      "RSA", bits, "sign",              break;
213                      user, email,  
214                      expdate ? expdate : "0", passphrase );          case GPG_KEYGEN_RSA_RSA:
215              break;              sprintf( p, key_params,
216                                     "RSA", bits, "RSA", bits, user, email,
217          case GPG_KEYGEN_RSA:                       expdate? expdate : "0", passphrase );
218              sprintf( p, key_params_one,              break;
219                      "RSA", bits, "sign encrypt",              
220                      user, email,          default:
221                      expdate ? expdate : "0", passphrase );              free_if_alloc (p);
222              break;              break;
223            }
224          case GPG_KEYGEN_RSA_RSA:      }
225              sprintf( p, key_params,      return p;
226                       "RSA", bits, "RSA", bits, user, email,  }
227                       expdate? expdate : "0", passphrase );  
228              break;  
229                /* Generate a key with the given params @params. @prog_cb is a user defined
230          default:     progress callback which is called during the generation.
231              if (p)     @fpr will store the fingerprint of the generated key.
232                  free (p);     Return value: 0 on success. */
233              p = NULL;  gpgme_error_t
234              break;  gpg_genkey (const char *params, gpgme_progress_cb_t prog_cb, char **fpr)
235          }  {
236      }      gpgme_error_t err = 0;
237      return p;      gpgme_ctx_t ctx;
238  }      gpgme_genkey_result_t res;
239        
240        err = gpgme_new(&ctx);
241  /* Generate a key with the given params @params. @prog_cb is a user defined      if (err)
242     progress callback which is called during the generation.          return err;
243     @fpr will store the fingerprint of the generated key.      if (prog_cb)
244     Return value: 0 on success. */          gpgme_set_progress_cb (ctx, prog_cb, NULL);
245  gpgme_error_t      err = gpgme_op_genkey (ctx, params, NULL, NULL);
246  gpg_genkey (const char *params, gpgme_progress_cb_t prog_cb, char **fpr)      if (!err) {
247  {          res = gpgme_op_genkey_result (ctx);
248      gpgme_error_t err = 0;          *fpr = res->fpr? m_strdup (res->fpr) : NULL;
249      gpgme_ctx_t ctx;      }
250      gpgme_genkey_result_t res;      gpgme_release (ctx);
251            return err;
252      err = gpgme_new(&ctx);  }
253      if (err)  
254          return err;  
255      if (prog_cb)  
256          gpgme_set_progress_cb (ctx, prog_cb, NULL);  /* Clear all dialog fields. */
257      err = gpgme_op_genkey (ctx, params, NULL, NULL);  static void
258      if (!err) {  clear_dlg_fields (HWND dlg)
259          res = gpgme_op_genkey_result (ctx);  {
260          *fpr = res->fpr? strdup (res->fpr) : NULL;      SetDlgItemText (dlg, IDC_KEYGEN_SUBKEYBITS, "");
261      }      SetDlgItemText (dlg, IDC_KEYGEN_NAME, "");
262      gpgme_release (ctx);      SetDlgItemText (dlg, IDC_KEYGEN_EMAIL, "");
263      return err;      SetDlgItemText (dlg, IDC_KEYGEN_COMMENT, "");
264  }      SetDlgItemText (dlg, IDC_KEYGEN_EXPDATE, "");
265        SetDlgItemText (dlg, IDC_KEYGEN_PASSPHRASE, "");
266        SetDlgItemText (dlg, IDC_KEYGEN_PWDCHECK, "");
267    }
268  /* Clear all dialog fields. */  
269  static void  
270  clear_dlg_fields (HWND dlg)  /* Ask the user if a keyring backup is wanted and if so,
271  {     backup both keyrings to the selected folder. @dlg is
272      SetDlgItemText (dlg, IDC_KEYGEN_SUBKEYBITS, "");     the handle of the parent window.*/
273      SetDlgItemText (dlg, IDC_KEYGEN_NAME, "");  static void
274      SetDlgItemText (dlg, IDC_KEYGEN_EMAIL, "");  backup_keyrings (HWND dlg)
275      SetDlgItemText (dlg, IDC_KEYGEN_COMMENT, "");  {
276      SetDlgItemText (dlg, IDC_KEYGEN_EXPDATE, "");      const char *name;
277      SetDlgItemText (dlg, IDC_KEYGEN_PASSPHRASE, "");      char *path = NULL;
278      SetDlgItemText (dlg, IDC_KEYGEN_PWDCHECK, "");      char *keyring = NULL;
279  }      int id;
280        
281        path = get_gnupg_path ();
282  /* Ask the user if a keyring backup is wanted and if so,      if (!path)
283     backup both keyrings to the selected folder. @dlg is          BUG (dlg);
284     the handle of the parent window.*/      id = msg_box (dlg,
285  static void                   _("It is STRONGLY recommend that you backup your keyrings because they both "
286  backup_keyrings (HWND dlg)                     "contain VERY important data.\nRemember that your hard disk can crash or the "
287  {                     "files can be deleted by accident; so it is a good\nidea to store them on "
288      int id;                     "a different mass stoarge like a floppy or CDR!\n\n"
289      char *path = NULL, *keyring = NULL;                     "Backup your keyrings now?"),
290      const char * name;                   _("WARNING - Important hint" ), MB_YESNO);
291            if (id == IDYES) {
292      path = get_gnupg_path ();          name = get_filesave_dlg (dlg, _("Destination for Public Keyring"),
293      if (!path)                                   NULL, "pubring.gpg");
294          BUG (dlg);          if( name ) {
295      id = msg_box (dlg,              keyring = make_filename (path, "pubring", "gpg");
296                   _("It is STRONGLY recommend that you backup your keyrings because they both "              if( !CopyFile (keyring, name, FALSE))
297                     "contain VERY important data.\nRemember that your hard disk can crash or the "                  log_box (_("Key Generation"), MB_ERR,
298                     "files can be deleted by accident; so it is a good\nidea to store them on "                           _("Could not copy %s -> %s"), keyring, name);
299                     "a different mass stoarge like a floppy or CDR!\n\n"              free_if_alloc (keyring);
300                     "Backup your keyrings now?"),          }
301                   _("WARNING - Important hint" ), MB_YESNO);          name = get_filesave_dlg (dlg, _("Destination for Secret Keyring"),
302      if (id == IDYES) {                                   NULL, "secring.gpg");
303          name = get_filename_dlg( dlg, 1, _("Destination for Public Keyring"), NULL, "pubring.gpg" );          if( name ) {
304          if( name ) {              keyring = make_filename (path, "secring", "gpg");
305              keyring = make_filename( path, "pubring", "gpg" );              if (!CopyFile (keyring, name, FALSE))
306              if( !CopyFile( keyring, name, FALSE ) )                  log_box (_("Key Generation"), MB_ERR,
307                  log_box( _("Key Generation"), MB_ERR,                           _("Could not copy %s -> %s"), keyring, name);
308                           _("Could not copy %s -> %s"), keyring, name );                  free_if_alloc (keyring);
309              free_if_alloc( keyring );          }
310          }      }
311          name = get_filename_dlg( dlg, 1, _("Destination for Secret Keyring"), NULL, "secring.gpg" );      free_if_alloc (path);
312          if( name ) {  }
313              keyring = make_filename( path, "secring", "gpg" );  
314              if( !CopyFile( keyring, name, FALSE ) )  
315                  log_box( _("Key Generation"), MB_ERR,  /* Fill in all valid GPG algorithms. */
316                           _("Could not copy %s -> %s"), keyring, name );  static void
317              free_if_alloc( keyring );  fill_keytype_box (HWND dlg)
318          }  {
319      }      HWND cb = GetDlgItem (dlg, IDC_KEYGEN_KEYTYPE);
320      free_if_alloc( path );  
321  }  #define addstr(cb, str) \
322        SendMessage ((cb), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)(str))
323        addstr (cb, _("DSA and ELG (default)"));
324  /* Fill in all valid GPG algorithms. */      addstr (cb, _("DSA and RSA"));
325  static void      addstr (cb, _("DSA sign only"));
326  fill_keytype_box (HWND dlg)      addstr (cb, _("RSA sign only"));
327  {      addstr (cb, _("RSA sign and encrypt"));
328      HWND cb = GetDlgItem (dlg, IDC_KEYGEN_KEYTYPE );      addstr (cb, _("RSA and RSA (PGP)") );
329        SendMessage (cb, CB_SETCURSEL, 0, 0);
330  #define addstr( cb, str ) \  #undef addstr
331      SendMessage( (cb), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)(str) )  }
332      addstr( cb, _("DSA and ELG (default)") );  
333      addstr( cb, _("DSA and RSA") );  
334      addstr( cb, _("DSA sign only") );  /* Check that the given date lies not in the past.
335      addstr( cb, _("RSA sign only") );     Return value: 1 on success. */
336      addstr( cb, _("RSA sign and encrypt") );  int
337      addstr( cb, _("RSA and RSA (PGP)") );  keygen_check_date (SYSTEMTIME *st)
338      SendMessage( cb, CB_SETCURSEL, 0, 0 );  {      
339  #undef addstr      SYSTEMTIME t;
340  }          
341        GetSystemTime (&t);
342        if (st->wYear > t.wYear || st->wMonth > t.wMonth)
343  /* Check that the given date lies not in the past.          return 1;
344     Return value: 1 on success. */      else if (st->wYear < t.wYear || st->wMonth < t.wMonth || st->wDay < t.wDay)
345  int          return 0;
346  keygen_check_date (SYSTEMTIME *st)      return 1;
347  {        }
348      SYSTEMTIME t;  
349            
350      GetSystemTime (&t);  /* Dialog box procedure for key generation. */
351      if (st->wYear > t.wYear || st->wMonth > t.wMonth)  BOOL CALLBACK
352          return 1;  keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
353      else if (st->wYear < t.wYear || st->wMonth < t.wMonth || st->wDay < t.wDay)  {
354          return 0;            static genkey_s *ctx;
355      return 1;      SYSTEMTIME st;
356  }      gpgme_error_t err;
357        char name[128] = {0}, email[128] = {0}, comment[128] = {0};
358        char *pwd;
359  /* Dialog box procedure for key generation. */      char t[64], *expire = NULL, *fpr=NULL;
360  BOOL CALLBACK      int bits, use_comment, keytype = 0;
361  keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)      int cancel = 0;
362  {      char *p;
363      static genkey_s *ctx;      
364      SYSTEMTIME st;      switch ( msg ) {
365      gpgme_error_t err;      case WM_INITDIALOG:
366      char name[128] = {0}, email[128] = {0}, comment[128] = {0};          if (lparam != 0)
367      char pwd[128], pwd2[128];              ctx = (genkey_s *)lparam;
368      char t[64], *expire = NULL, *fpr=NULL;          SetWindowText (dlg, _("Key Generation"));
369      int bits, use_comment, keytype = 0;              SetDlgItemText(dlg, IDC_KEYGEN_INFO,
370      char * p;                            _("NOTE: Key generation can be a lengthy process! Please wait until "
371                                  "you get the message that key generation was finished."));
372      switch ( msg ) {          SetDlgItemText (dlg, IDC_KEYGEN_SUBKEYINF, _("Subkey size in &bits"));
373      case WM_INITDIALOG:          SetDlgItemText (dlg, IDC_KEYGEN_NAMEINF, _("&Real name"));
374          if (lparam != NULL)          SetDlgItemText (dlg, IDC_KEYGEN_COMMINF, _("&Comment (optional)"));
375              ctx = (genkey_s *)lparam;          SetDlgItemText (dlg, IDC_KEYGEN_EMAILINF, _("Email &address"));
376          SetWindowText( dlg, _("Key Generation") );          SetDlgItemText (dlg, IDC_KEYGEN_EXPINF, _("&Expire date"));
377          SetDlgItemText( dlg, IDC_KEYGEN_INFO,          SetDlgItemText (dlg, IDC_KEYGEN_KEYTYPEINF, _("Key &type"));
378                          _("NOTE: Key generation can be a lengthy process! Please wait until "          SetDlgItemText (dlg, IDC_KEYGEN_EXPNEVER, _("&Never"));
379                            "you get the message that key generation was finished.") );          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
380          SetDlgItemText( dlg, IDC_KEYGEN_SUBKEYINF, _("Subkey size in &bits"));  
381          SetDlgItemText( dlg, IDC_KEYGEN_NAMEINF, _("&Real name") );          SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, DFAULT_KEYSIZE, FALSE);
382          SetDlgItemText( dlg, IDC_KEYGEN_COMMINF, _("&Comment (optional)") );          CheckDlgButton (dlg, IDC_KEYGEN_HIDEPWD, BST_CHECKED);
383          SetDlgItemText( dlg, IDC_KEYGEN_EMAILINF, _("Email &address") );          CheckDlgButton (dlg, IDC_KEYGEN_EXPNEVER, BST_CHECKED);
384          SetDlgItemText( dlg, IDC_KEYGEN_EXPINF, _("&Expire date"));          EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), FALSE);
385          SetDlgItemText( dlg, IDC_KEYGEN_PWDINF, _("&Passphrase") );          fill_keytype_box (dlg);
386          SetDlgItemText( dlg, IDC_KEYGEN_REPWDINF, _("&Repeat passphrase") );          center_window (dlg, NULL);
387          SetDlgItemText( dlg, IDC_KEYGEN_KEYTYPEINF, _("Key &type") );          SetForegroundWindow (dlg);
388          SetDlgItemText (dlg, IDC_KEYGEN_EXPNEVER, _("&Never"));          return TRUE;
389          SetDlgItemText (dlg, IDC_KEYGEN_HIDEPWD, _("&Hide Typing"));          
390        case WM_SYSCOMMAND:
391          SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, 2048, FALSE);          if (LOWORD (wparam) == SC_CLOSE)
392          CheckDlgButton (dlg, IDC_KEYGEN_HIDEPWD, BST_CHECKED);              EndDialog (dlg, TRUE);
393          CheckDlgButton (dlg, IDC_KEYGEN_EXPNEVER, BST_CHECKED);          return FALSE;
394          EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), FALSE);          
395          fill_keytype_box (dlg);      case WM_COMMAND:
396          center_window (dlg, NULL);          if (HIWORD (wparam) == BN_CLICKED &&
397          SetForegroundWindow (dlg);              LOWORD (wparam) == IDC_KEYGEN_EXPNEVER) {
398          return TRUE;              int never = IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER);
399                        EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), !never);
400      case WM_SYSCOMMAND:          }
401          if (LOWORD (wparam) == SC_CLOSE) {  
402              SetDlgItemText (dlg, IDC_KEYGEN_PASSPHRASE, "");          switch (LOWORD (wparam)) {
403              SetDlgItemText (dlg, IDC_KEYGEN_PWDCHECK, "");          case IDOK:
404              EndDialog (dlg, TRUE);              bits = GetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, NULL, FALSE);
405          }              if (bits < 1024 || bits > 4096) {
406          return FALSE;                  msg_box (dlg, _("Invalid value. Allowed values 1024-4096 bits."),
407                                     _("Key Generation"), MB_ERR);
408      case WM_COMMAND:                  return FALSE;
409          if (HIWORD (wparam) == BN_CLICKED &&              }
410              LOWORD (wparam) == IDC_KEYGEN_EXPNEVER) {              if (bits > DFAULT_KEYSIZE) {
411              int never = IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER);                  int id = msg_box (dlg, _("Do you really need such a large key?"),
412              EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), !never);                                    _("Key Generation"), MB_YESNO);
413          }                  if (id == IDNO)
414          if (HIWORD (wparam) == BN_CLICKED                      bits = DFAULT_KEYSIZE;
415              && LOWORD (wparam) == IDC_KEYGEN_HIDEPWD) {              }
416              HWND hwnd_a = GetDlgItem (dlg, IDC_KEYGEN_PASSPHRASE);              if (!GetDlgItemText (dlg, IDC_KEYGEN_NAME, name, sizeof (name) - 1)) {
417              HWND hwnd_b = GetDlgItem (dlg, IDC_KEYGEN_PWDCHECK);                  msg_box( dlg, _("Please enter the name."), _("Key Generation"), MB_ERR);
418              int hide = IsDlgButtonChecked (dlg, IDC_KEYGEN_HIDEPWD);                  return FALSE;
419              SendMessage (hwnd_a, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);              }
420              SetFocus (hwnd_a);              if (strchr (name, '@')) {
421              SendMessage (hwnd_b, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);                  msg_box (dlg, _("Please do not enter the email address in the name field."),
422              SetFocus (hwnd_b);                           _("Key Generation"), MB_INFO);
423          }                  return FALSE;
424                }
425          switch( LOWORD( wparam ) ) {              if (!GetDlgItemText (dlg, IDC_KEYGEN_EMAIL, email, sizeof (email) -1)
426          case IDOK:                  || check_email_address (email)) {
427              bits = GetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, NULL, FALSE);                  msg_box (dlg, _("Please enter a valid email address."),
428              if (bits < 1024 || bits > 4096) {                           _("Key Generation"), MB_ERR);
429                  msg_box (dlg, _("Invalid value. Allowed values 1024-4096 bits."),                  return FALSE;
430                           _("Key Generation"), MB_ERR);              }
431                  return FALSE;              use_comment = GetDlgItemText(dlg, IDC_KEYGEN_COMMENT,
432              }                                           comment, sizeof (comment) -1);
433              if (bits > DFAULT_KEYSIZE) {              if (use_comment > 0 && strchr (comment, '@')) {
434                  int id = msg_box (dlg, _("Do you really need such a large key?"),                  msg_box (dlg, _("Please do NOT enter the email address in the comment field."),
435                                    _("Key Generation"), MB_YESNO);                           _("Key Generation"), MB_INFO);
436                  if (id == IDNO)                  return FALSE;
437                      bits = DFAULT_KEYSIZE;              }
438              }              keytype = SendDlgItemMessage (dlg, IDC_KEYGEN_KEYTYPE, CB_GETCURSEL, 0, 0) + 1;
439              if( !GetDlgItemText( dlg, IDC_KEYGEN_NAME, name, sizeof name - 1 ) ) {              if (IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER))
440                  msg_box( dlg, _("Please enter the name."), _("Key Generation"), MB_ERR );                  expire = NULL;
441                  return FALSE;              else {
442              }                  DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), &st);
443              if (strchr (name, '@')) {                  _snprintf (t, DIM (t)-1, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);
444                  msg_box (dlg, _("Please do not enter the email address in the name field."),                  expire = t;
445                           _("Key Generation"), MB_INFO);              }
446                  return FALSE;  
447              }              pwd = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel);
448              if( !GetDlgItemText(dlg, IDC_KEYGEN_EMAIL, email, sizeof email -1 )              if (cancel) {
449                  || !strchr( email, '@') ) {                  sfree_if_alloc (pwd);
450                  msg_box( dlg, _("Please enter a valid email address."),                  return FALSE;
451                           _("Key Generation"), MB_ERR );              }
452                  return FALSE;              if (!pwd) {
453              }                  msg_box (dlg, _("Please enter the passphrase."),
454              use_comment = GetDlgItemText( dlg, IDC_KEYGEN_COMMENT, comment, sizeof comment -1 );                           _("Key Generation"), MB_ERR);
455              if( use_comment > 0 && strchr( comment, '@' ) ) {                  return FALSE;
456                  msg_box( dlg, _("Please do NOT enter the email address in the comment field."),              }
457                           _("Key Generation"), MB_INFO );  
458                  return FALSE;              if (!use_comment && !strlen (comment)) {
459              }                  char *utf8_name;
460              keytype = SendDlgItemMessage (dlg, IDC_KEYGEN_KEYTYPE, CB_GETCURSEL, 0, 0) + 1;                  utf8_name = native_to_utf8 (name);
461              if (IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER))                  if (!utf8_name)
462                  expire = NULL;                      BUG (0);
463              else {                  p = gpg_genkey_params (keytype, bits, utf8_name, NULL,
464                  DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), &st);                                         email, expire, pwd);
465                  _snprintf (t, DIM (t)-1, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);                  free_if_alloc (utf8_name);
466                  expire = t;              }
467              }              else {
468                                char *utf8_name, *utf8_comment;
469              if( !GetDlgItemText( dlg, IDC_KEYGEN_PASSPHRASE, pwd, sizeof pwd -1 ) ) {                  utf8_name = native_to_utf8 (name);
470                  msg_box( dlg, _("Please enter the passphrase."),                  utf8_comment = native_to_utf8 (comment);
471                           _("Key Generation"), MB_ERR );                  if( !utf8_name || !utf8_comment )
472                  return FALSE;                      BUG (0);
473              }                  p = gpg_genkey_params (keytype, bits, utf8_name, utf8_comment,
474              else if (check_passwd_quality (pwd, 0)) {                                         email, expire, pwd);
475                  int id = msg_box( dlg, _("Your passphrase should be at least 8 characters"                  free_if_alloc (utf8_name);
476                                           " long\nand should contain non-alphabetic characters."                  free_if_alloc (utf8_comment);
477                                           "\n\nStill proceed?"),              }
478                                      _("Key Generation"), MB_ICONWARNING|MB_YESNO );              keygen_cb_dlg_create ();
479                  if( id == IDNO ) {              err = gpg_genkey (p, keygen_cb, &fpr);
480                      SetDlgItemText( dlg, IDC_KEYGEN_PASSPHRASE, "" );              sfree_if_alloc (pwd);
481                      SetDlgItemText( dlg, IDC_KEYGEN_PWDCHECK, "" );              if (p) {
482                      return FALSE;                  wipememory (p, strlen (p));  /* burn the passphrase! */
483                  }                  free_if_alloc (p);
484              }              }
485              if( !GetDlgItemText( dlg, IDC_KEYGEN_PWDCHECK, pwd2, sizeof pwd2 -1 ) ) {              keygen_cb_dlg_destroy ();
486                  msg_box( dlg, _("Please repeat the passphrase."),              keygen_cb (NULL, NULL, 0, 0, 0); /* flush */
487                           _("Key Generation"), MB_ERR );              if (err) {
488                  return FALSE;                  free_if_alloc (fpr);
489              }                  msg_box (dlg, gpgme_strerror (err), _("Key Generation"), MB_ERR);
490              if( strcmp( pwd, pwd2 ) ) {                  return FALSE;
491                  msg_box( dlg,  _("Passphrases are NOT identical!" ),              }
492                           _("Key Generation"), MB_ERR );              status_box (dlg, _("Key Generation completed"), _("GnuPG Status"));
493                  wipememory (pwd, sizeof (pwd));              
494                  wipememory (pwd2, sizeof (pwd2));              keycache_update (0, fpr);
495                  return FALSE;              keycache_update (1, fpr);
496              }              free_if_alloc (fpr);            
497              if( is_8bit_string( pwd ) ) {  
498                  msg_box( dlg, _("The passphrase contains 8-bit characters.\n"              clear_dlg_fields (dlg);
499                                  "It is not suggested to use charset specific characters."),              backup_keyrings (dlg);
500                           _("Key Generation"), MB_ERR );              if (ctx)
501                  wipememory (pwd, sizeof (pwd));                  ctx->cancel = 0;
502                  wipememory (pwd2, sizeof (pwd2));              EndDialog (dlg, TRUE);
503                  SetDlgItemText( dlg, IDC_KEYGEN_PASSPHRASE, "" );              return TRUE;
504                  SetDlgItemText( dlg, IDC_KEYGEN_PWDCHECK, "" );              
505                  return FALSE;          case IDCANCEL:
506              }              if (ctx)
507                                                    ctx->cancel = 1;
508              if( !use_comment && !strlen( comment ) ) {              EndDialog (dlg, FALSE);        
509                  char *utf8_name;              return FALSE;
510                  utf8_name = wincp_to_utf8 (name, strlen (name));          }
511                  if( !utf8_name )          break;
512                      BUG( dlg );      }
513                  p = gpg_genkey_params( keytype, bits, utf8_name, NULL, email, expire, pwd );      
514                  free( utf8_name );      return FALSE;
515              }  }
516              else {  
517                  char *utf8_name, *utf8_comment;  
518                  utf8_name = wincp_to_utf8 (name, strlen (name));  BOOL CALLBACK
519                  utf8_comment = wincp_to_utf8 (comment, strlen (comment));                keygen_wizard_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
520                  if( !utf8_name || !utf8_comment )  {
521                      BUG( dlg );      static genkey_s *ctx;
522                  p = gpg_genkey_params( keytype, bits, utf8_name, utf8_comment, email, expire, pwd );      static int pubkey_algo = GPG_KEYGEN_DSA_ELG;
523                  free( utf8_name );      gpgme_error_t err;
524                  free( utf8_comment );      char name[128], email[128];
525              }      char * utf8_name, * p, *fpr=NULL;
526              keygen_cb_dlg_create( );      char * pass = NULL;
527              err = gpg_genkey (p, keygen_cb, &fpr);      int cancel = 0;
528              wipememory (pwd, sizeof (pwd));          
529              wipememory (pwd2, sizeof (pwd2));  
530              if( p ) {      switch( msg ) {
531                  wipememory (p, strlen (p));  /* burn the passphrase! */      case WM_INITDIALOG:
532                  free (p);          ctx = (genkey_s *)lparam;
533              }          if (!ctx || (ctx && ctx->interactive == 0))
534              keygen_cb_dlg_destroy ();              EnableWindow (GetDlgItem (dlg, IDC_KEYWIZARD_EXPERT), FALSE);
535              keygen_cb (NULL, NULL, 0, 0, 0); /* flush */          SetDlgItemText (dlg, IDC_KEYWIZARD_USERSA, _("&Prefer RSA keys"));
536              if( err ) {          SetDlgItemText (dlg, IDC_KEYWIZARD_NAMEINF, _("Real name:"));
537                  if (fpr)          SetDlgItemText (dlg, IDC_KEYWIZARD_EMAILINF, _("Email address:"));
538                      free (fpr);          SetDlgItemText (dlg, IDC_KEYWIZARD_TITLEINF, _("Name and E-Mail Assignment"));
539                  msg_box (dlg, gpgme_strerror( err ), _("Key Generation"), MB_ERR);          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."));
540                  return FALSE;          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."));
541              }          SetWindowText (dlg, _("Key Generation Wizard"));
542              status_box( dlg, _("Key Generation completed"), _("GnuPG Status") );          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
543                        SetDlgItemText (dlg, IDC_KEYWIZARD_EXPERT, _("E&xpert"));
544              keycache_update (0, fpr);          SetForegroundWindow (dlg);
545              keycache_update (1, fpr);          center_window (dlg, NULL);
546              if (ctx->first_start == 0 && ctx != NULL)          break;
547                  get_pubkey (fpr, &ctx->newkey);  
548              if (fpr)      case WM_SYSCOMMAND:
549                  free (fpr);          if( LOWORD( wparam ) == SC_CLOSE )
550                EndDialog( dlg, FALSE );
551              clear_dlg_fields (dlg);  
552              backup_keyrings (dlg);      case WM_COMMAND:
553              EndDialog (dlg, TRUE);          switch( LOWORD( wparam ) ) {
554              return TRUE;          case IDC_KEYWIZARD_EXPERT:
555                            DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYGEN, dlg,
556          case IDCANCEL:                              keygen_dlg_proc, 0);
557              SetDlgItemText (dlg, IDC_KEYGEN_PASSPHRASE, "");              EndDialog (dlg, TRUE);
558              SetDlgItemText (dlg, IDC_KEYGEN_PWDCHECK, "");              break;
559              EndDialog (dlg, FALSE);  
560              return FALSE;          case IDOK:
561          }              if( !GetDlgItemText( dlg, IDC_KEYWIZARD_NAME, name, sizeof name-1 ) ) {
562          break;                  msg_box( dlg, _("Please enter the name."),
563      }                           _("Key Generation Wizard"), MB_ERR );
564                        return FALSE;
565      return FALSE;              }
566                if (strchr (name, '@')) {
567                    msg_box (dlg, _("Please do not enter the email address in the name field."),
568                             _("Key Generation Wizard"), MB_WARN);
569                    return FALSE;
570                }
571                if (!GetDlgItemText(dlg, IDC_KEYWIZARD_EMAIL, email, sizeof email-1 )
572                    || check_email_address (email)) {
573                    msg_box (dlg, _("Please enter a valid email address."),
574                             _("Key Generation Wizard"), MB_ERR);
575                    return FALSE;
576                }
577                if (strchr (email, '<') || strchr (email, '>')) {
578                    msg_box (dlg, _("Please do not add '<' or '>' to the email address."),
579                             _("Key Generation Wizard"), MB_WARN);
580                    return FALSE;
581                }
582                pass = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel);
583                if (cancel)
584                    return FALSE;
585                utf8_name = native_to_utf8 (name);
586                if (!utf8_name)
587                    BUG (0);
588                if (IsDlgButtonChecked (dlg, IDC_KEYWIZARD_USERSA))
589                    pubkey_algo = GPG_KEYGEN_DSA_RSA;
590                p = gpg_genkey_params (pubkey_algo, DFAULT_KEYSIZE, utf8_name,
591                                         NULL, email, NULL, pass);
592                free_if_alloc (utf8_name);
593                keygen_cb_dlg_create();
594                err = gpg_genkey (p, keygen_cb, &fpr);
595                keygen_cb_dlg_destroy();
596                keygen_cb (NULL, NULL, 0, 0, 0);
597                if (p) {
598                    wipememory (p, strlen (p));
599                    free_if_alloc (p);
600                }
601                sfree_if_alloc (pass);
602                if (err) {
603                    msg_box (dlg, gpgme_strerror( err ), _("Key Generation Wizard"), MB_ERR);
604                    free_if_alloc (fpr);
605                    return FALSE;
606                }
607                status_box( dlg, _("Key Generation completed"), _("GnuPG Status") );
608                
609                keycache_update (0, fpr);
610                keycache_update (1, fpr);
611                free_if_alloc (fpr);
612    
613                backup_keyrings (dlg);
614                if (ctx)
615                    ctx->cancel = 0;            
616                EndDialog (dlg, TRUE);
617                break;
618    
619            case IDCANCEL:
620                if (ctx)
621                    ctx->cancel = 1;
622                EndDialog (dlg, FALSE);
623                break;
624            }
625            break;
626        }
627        return FALSE;
628  }  }
   
   
 BOOL CALLBACK  
 keygen_wizard_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  
 {  
     static genkey_s *ctx;  
     static int pubkey_algo = GPG_KEYGEN_DSA_ELG;  
     gpgme_error_t err;  
     char name[128], email[128];  
     char * utf8_name, * p, *fpr=NULL;  
     char * pass = NULL;  
     int cancel = 0;  
       
   
     switch( msg ) {  
     case WM_INITDIALOG:  
         ctx = (genkey_s *)lparam;  
         if (!ctx || (ctx && ctx->interactive == 0))  
             EnableWindow (GetDlgItem (dlg, IDC_KEYWIZARD_EXPERT), FALSE);  
         SetDlgItemText (dlg, IDC_KEYWIZARD_USERSA, _("&Prefer RSA keys"));  
         SetDlgItemText (dlg, IDC_KEYWIZARD_NAMEINF, _("Real name:"));  
         SetDlgItemText (dlg, IDC_KEYWIZARD_EMAILINF, _("Email address:"));  
         SetDlgItemText (dlg, IDC_KEYWIZARD_TITLEINF, _("Name and E-Mail Assignment"));  
         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_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."));  
         SetWindowText (dlg, _("Key Generation Wizard"));  
         SetForegroundWindow (dlg);  
         center_window (dlg, NULL);  
         break;  
   
     case WM_SYSCOMMAND:  
         if( LOWORD( wparam ) == SC_CLOSE )  
             EndDialog( dlg, FALSE );  
   
     case WM_COMMAND:  
         switch( LOWORD( wparam ) ) {  
         case IDC_KEYWIZARD_EXPERT:  
             DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYGEN, dlg,  
                             keygen_dlg_proc, NULL);  
             EndDialog (dlg, TRUE);  
             break;  
   
         case IDOK:  
             if( !GetDlgItemText( dlg, IDC_KEYWIZARD_NAME, name, sizeof name-1 ) ) {  
                 msg_box( dlg, _("Please enter the name."),  
                          _("Key Generation Wizard"), MB_ERR );  
                 return FALSE;  
             }  
             if (strchr (name, '@')) {  
                 msg_box (dlg, _("Please do not enter the email address in the name field."),  
                          _("Key Generation Wizard"), MB_WARN);  
                 return FALSE;  
             }  
             if( !GetDlgItemText( dlg, IDC_KEYWIZARD_EMAIL, email, sizeof email-1 )  
                 || !strchr( email, '@' ) ) {  
                 msg_box( dlg, _("Please enter a valid email address."),  
                          _("Key Generation Wizard"), MB_ERR );  
                 return FALSE;  
             }  
             if (strchr (email, '<') || strchr (email, '>')) {  
                 msg_box (dlg, _("Please do not add '<' or '>' to the email address."),  
                          _("Key Generation Wizard"), MB_WARN);  
                 return FALSE;  
             }  
             pass = request_passphrase2 (_("Key Generation"), PASSDLG_STRICT, &cancel);  
             if (cancel)  
                 return FALSE;  
             utf8_name = wincp_to_utf8 (name, strlen (name));  
             if( !utf8_name )  
                 BUG( NULL );  
             if (IsDlgButtonChecked (dlg, IDC_KEYWIZARD_USERSA))  
                 pubkey_algo = GPG_KEYGEN_DSA_RSA;  
             p = gpg_genkey_params (pubkey_algo, DFAULT_KEYSIZE, utf8_name,  
                                      NULL, email, NULL, pass);  
             free( utf8_name );  
             keygen_cb_dlg_create();  
             err = gpg_genkey (p, keygen_cb, &fpr);  
             keygen_cb_dlg_destroy();  
             keygen_cb( NULL, NULL, 0, 0, 0 );  
             if( p ) {  
                 memset( p, 0, strlen( p ) );  
                 free( p );  
             }  
             sfree_if_alloc (pass);  
             if( err ) {  
                 msg_box( dlg, gpgme_strerror( err ), _("Key Generation Wizard"), MB_ERR );  
                 if (fpr)  
                     free (fpr);  
                 return FALSE;  
             }  
             status_box( dlg, _("Key Generation completed"), _("GnuPG Status") );  
               
             keycache_update (0, fpr);  
             keycache_update (1, fpr);  
             if (ctx->first_start == 0 && ctx != NULL)  
                 get_pubkey (fpr, &ctx->newkey);  
             if (fpr)  
                 free (fpr);  
             backup_keyrings (dlg);  
             EndDialog (dlg, TRUE);  
             break;  
   
         case IDCANCEL:  
             EndDialog( dlg, FALSE );  
             break;  
         }  
         break;  
     }  
     return FALSE;  
 }  

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26