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

Annotation of /trunk/Src/wptKeygenDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (hide annotations)
Mon Oct 31 14:04:59 2005 UTC (19 years, 4 months ago) by werner
File size: 22559 byte(s)
Minor changes; compiles now but gettext is still missing.

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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26