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

Contents of /trunk/Src/wptKeygenDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 101 - (show annotations)
Fri Nov 25 10:56:05 2005 UTC (19 years, 3 months ago) by twoaday
File size: 22573 byte(s)
Localized 'Cancel' buttons.
Fix 'addrevoker' hanging problem.


1 /* 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
26 #include "resource.h"
27 #include "wptTypes.h"
28 #include "wptNLS.h"
29 #include "wptGPG.h"
30 #include "wptCommonCtl.h"
31 #include "wptContext.h" /* for passphrase_s */
32 #include "wptDlgs.h"
33 #include "wptW32API.h"
34 #include "wptVersion.h"
35 #include "wptErrors.h"
36 #include "wptUTF8.h"
37
38 /* All valid key generation combination. */
39 enum gpg_keytype_t {
40 GPG_KEYGEN_NONE = 0,
41 GPG_KEYGEN_DSA_ELG = 1,
42 GPG_KEYGEN_DSA_RSA = 2,
43 GPG_KEYGEN_DSA_SIG = 3,
44 GPG_KEYGEN_RSA_SIG = 4,
45 GPG_KEYGEN_RSA = 5,
46 GPG_KEYGEN_RSA_RSA = 6 /*PGP*/
47 };
48
49
50 static const char key_params[] =
51 "<GnupgKeyParms format=\"internal\">\n"
52 "Key-Type: %s\n"
53 "Key-Usage: sign\n"
54 "Key-Length: %d\n"
55 "Subkey-Type: %s\n"
56 "Subkey-Length: %d\n"
57 "Name-Real: %s\n"
58 "Name-Email: %s\n"
59 "Expire-Date: %s\n"
60 "Passphrase: %s\n"
61 "</GnupgKeyParms>\n";
62
63 static const char key_params_with_comment[] =
64 "<GnupgKeyParms format=\"internal\">\n"
65 "Key-Type: %s\n"
66 "Key-Usage: sign\n"
67 "Key-Length: %d\n"
68 "Subkey-Type: %s\n"
69 "Subkey-Length: %d\n"
70 "Name-Real: %s\n"
71 "Name-Comment: %s\n"
72 "Name-Email: %s\n"
73 "Expire-Date: %s\n"
74 "Passphrase: %s\n"
75 "</GnupgKeyParms>\n";
76
77 static const char key_params_one[] =
78 "<GnupgKeyParms format=\"internal\">\n"
79 "Key-Type: %s\n"
80 "Key-Length: %d\n"
81 "Key-Usage: %s\n"
82 "Name-Real: %s\n"
83 "Name-Email: %s\n"
84 "Expire-Date: %s\n"
85 "Passphrase: %s\n"
86 "</GnupgKeyParms>\n";
87
88 static const char key_params_one_with_comment[] =
89 "<GnupgKeyParms format=\"internal\">\n"
90 "Key-Type: %s\n"
91 "Key-Length: %d\n"
92 "Key-Usage: %s\n"
93 "Name-Real: %s\n"
94 "Name-Email: %s\n"
95 "Name-Comment: %s\n"
96 "Expire-Date: %s\n"
97 "Passphrase: %s\n"
98 "</GnupgKeyParms>\n";
99
100
101 /* Generate the GPG specific genkey params with the given information.
102 @keytype: See valid combinations.
103 @bits: Length in bits.
104 @user: user-ID name
105 @comment: comment for the user-ID.
106 @email: email address.
107 @expdata: date of expiration or NULL.
108 @passphrase: the actual passphrase.
109 Return value: the gen. params. */
110 static char*
111 gpg_genkey_params (int keytype, int bits,
112 const char *user, const char *comment, const char *email,
113 const char *expdate, const char *passphrase)
114 {
115 char *p = NULL;
116 int addsize = strlen ("sign encrypt");
117 int size = 0;
118
119 if (keytype == GPG_KEYGEN_NONE)
120 return NULL;
121
122 if( comment && *comment ) {
123 size = strlen (key_params_with_comment)
124 + 16
125 + strlen( user )
126 + addsize
127 + strlen( comment )
128 + strlen( email )
129 + strlen( passphrase ) + 32;
130 }
131 else {
132 size = strlen( key_params )
133 + 16
134 + strlen( user )
135 + strlen( email )
136 + strlen( passphrase )
137 + addsize
138 + 32;
139 }
140 if( expdate )
141 size += strlen( expdate );
142 p = (char *)malloc( size+1 );
143 if( !p )
144 return NULL;
145 if( comment && *comment ) {
146 switch( keytype ) {
147 case GPG_KEYGEN_DSA_ELG:
148 sprintf (p, key_params_with_comment,
149 "DSA", 1024, "ELG-E", bits, user, comment, email,
150 expdate ? expdate : "0", passphrase);
151 break;
152
153 case GPG_KEYGEN_DSA_RSA:
154 sprintf( p, key_params_with_comment,
155 "DSA", 1024, "RSA", bits, user, comment, email,
156 expdate ? expdate : "0", passphrase );
157 break;
158
159 case GPG_KEYGEN_DSA_SIG:
160 sprintf( p, key_params_one_with_comment,
161 "DSA", 1024, "sign",
162 user, comment, email,
163 expdate ? expdate : "0", passphrase );
164 break;
165
166 case GPG_KEYGEN_RSA_SIG:
167 sprintf( p, key_params_one_with_comment,
168 "RSA", bits, "sign",
169 user, comment, email,
170 expdate ? expdate : "0", passphrase );
171 break;
172
173 case GPG_KEYGEN_RSA:
174 sprintf( p, key_params_one_with_comment,
175 "RSA", bits, "sign encrypt",
176 user, comment, email,
177 expdate ? expdate : "0", passphrase );
178 break;
179
180 case GPG_KEYGEN_RSA_RSA:
181 sprintf( p, key_params_with_comment,
182 "RSA", bits, "RSA", bits, user, comment, email,
183 expdate? expdate : "0", passphrase );
184 break;
185
186 default:
187 if (p)
188 free (p);
189 p = NULL;
190 break;
191 }
192 }
193 else {
194 switch ( keytype ) {
195 case GPG_KEYGEN_DSA_ELG:
196 sprintf( p, key_params,
197 "DSA", 1024, "ELG-E", bits, user, email,
198 expdate ? expdate : "0", passphrase );
199 break;
200
201 case GPG_KEYGEN_DSA_RSA:
202 sprintf( p, key_params,
203 "DSA", 1024, "RSA", bits, user, email,
204 expdate ? expdate : "0", passphrase );
205 break;
206
207 case GPG_KEYGEN_DSA_SIG:
208 sprintf( p, key_params_one,
209 "DSA", 1024, "sign",
210 user, email,
211 expdate ? expdate : "0", passphrase );
212 break;
213
214 case GPG_KEYGEN_RSA_SIG:
215 sprintf( p, key_params_one,
216 "RSA", bits, "sign",
217 user, email,
218 expdate ? expdate : "0", passphrase );
219 break;
220
221 case GPG_KEYGEN_RSA:
222 sprintf( p, key_params_one,
223 "RSA", bits, "sign encrypt",
224 user, email,
225 expdate ? expdate : "0", passphrase );
226 break;
227
228 case GPG_KEYGEN_RSA_RSA:
229 sprintf( p, key_params,
230 "RSA", bits, "RSA", bits, user, email,
231 expdate? expdate : "0", passphrase );
232 break;
233
234 default:
235 if (p)
236 free (p);
237 p = NULL;
238 break;
239 }
240 }
241 return p;
242 }
243
244
245 /* Generate a key with the given params @params. @prog_cb is a user defined
246 progress callback which is called during the generation.
247 @fpr will store the fingerprint of the generated key.
248 Return value: 0 on success. */
249 gpgme_error_t
250 gpg_genkey (const char *params, gpgme_progress_cb_t prog_cb, char **fpr)
251 {
252 gpgme_error_t err = 0;
253 gpgme_ctx_t ctx;
254 gpgme_genkey_result_t res;
255
256 err = gpgme_new(&ctx);
257 if (err)
258 return err;
259 if (prog_cb)
260 gpgme_set_progress_cb (ctx, prog_cb, NULL);
261 err = gpgme_op_genkey (ctx, params, NULL, NULL);
262 if (!err) {
263 res = gpgme_op_genkey_result (ctx);
264 *fpr = res->fpr? strdup (res->fpr) : NULL;
265 }
266 gpgme_release (ctx);
267 return err;
268 }
269
270
271
272 /* Clear all dialog fields. */
273 static void
274 clear_dlg_fields (HWND dlg)
275 {
276 SetDlgItemText (dlg, IDC_KEYGEN_SUBKEYBITS, "");
277 SetDlgItemText (dlg, IDC_KEYGEN_NAME, "");
278 SetDlgItemText (dlg, IDC_KEYGEN_EMAIL, "");
279 SetDlgItemText (dlg, IDC_KEYGEN_COMMENT, "");
280 SetDlgItemText (dlg, IDC_KEYGEN_EXPDATE, "");
281 SetDlgItemText (dlg, IDC_KEYGEN_PASSPHRASE, "");
282 SetDlgItemText (dlg, IDC_KEYGEN_PWDCHECK, "");
283 }
284
285
286 /* Ask the user if a keyring backup is wanted and if so,
287 backup both keyrings to the selected folder. @dlg is
288 the handle of the parent window.*/
289 static void
290 backup_keyrings (HWND dlg)
291 {
292 int id;
293 char *path = NULL, *keyring = NULL;
294 const char * name;
295
296 path = get_gnupg_path ();
297 if (!path)
298 BUG (dlg);
299 id = msg_box (dlg,
300 _("It is STRONGLY recommend that you backup your keyrings because they both "
301 "contain VERY important data.\nRemember that your hard disk can crash or the "
302 "files can be deleted by accident; so it is a good\nidea to store them on "
303 "a different mass stoarge like a floppy or CDR!\n\n"
304 "Backup your keyrings now?"),
305 _("WARNING - Important hint" ), MB_YESNO);
306 if (id == IDYES) {
307 name = get_filesave_dlg( dlg, _("Destination for Public Keyring"), NULL, "pubring.gpg" );
308 if( name ) {
309 keyring = make_filename( path, "pubring", "gpg" );
310 if( !CopyFile( keyring, name, FALSE ) )
311 log_box( _("Key Generation"), MB_ERR,
312 _("Could not copy %s -> %s"), keyring, name );
313 free_if_alloc( keyring );
314 }
315 name = get_filesave_dlg( dlg, _("Destination for Secret Keyring"), NULL, "secring.gpg" );
316 if( name ) {
317 keyring = make_filename( path, "secring", "gpg" );
318 if( !CopyFile( keyring, name, FALSE ) )
319 log_box( _("Key Generation"), MB_ERR,
320 _("Could not copy %s -> %s"), keyring, name );
321 free_if_alloc( keyring );
322 }
323 }
324 free_if_alloc( path );
325 }
326
327
328 /* Fill in all valid GPG algorithms. */
329 static void
330 fill_keytype_box (HWND dlg)
331 {
332 HWND cb = GetDlgItem (dlg, IDC_KEYGEN_KEYTYPE );
333
334 #define addstr( cb, str ) \
335 SendMessage( (cb), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)(str) )
336 addstr( cb, _("DSA and ELG (default)") );
337 addstr( cb, _("DSA and RSA") );
338 addstr( cb, _("DSA sign only") );
339 addstr( cb, _("RSA sign only") );
340 addstr( cb, _("RSA sign and encrypt") );
341 addstr( cb, _("RSA and RSA (PGP)") );
342 SendMessage( cb, CB_SETCURSEL, 0, 0 );
343 #undef addstr
344 }
345
346
347 /* Check that the given date lies not in the past.
348 Return value: 1 on success. */
349 int
350 keygen_check_date (SYSTEMTIME *st)
351 {
352 SYSTEMTIME t;
353
354 GetSystemTime (&t);
355 if (st->wYear > t.wYear || st->wMonth > t.wMonth)
356 return 1;
357 else if (st->wYear < t.wYear || st->wMonth < t.wMonth || st->wDay < t.wDay)
358 return 0;
359 return 1;
360 }
361
362
363 /* Dialog box procedure for key generation. */
364 BOOL CALLBACK
365 keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
366 {
367 static genkey_s *ctx;
368 SYSTEMTIME st;
369 gpgme_error_t err;
370 char name[128] = {0}, email[128] = {0}, comment[128] = {0};
371 char pwd[128], pwd2[128];
372 char t[64], *expire = NULL, *fpr=NULL;
373 int bits, use_comment, keytype = 0;
374 char * p;
375
376 switch ( msg ) {
377 case WM_INITDIALOG:
378 if (lparam != 0)
379 ctx = (genkey_s *)lparam;
380 SetWindowText( dlg, _("Key Generation") );
381 SetDlgItemText( dlg, IDC_KEYGEN_INFO,
382 _("NOTE: Key generation can be a lengthy process! Please wait until "
383 "you get the message that key generation was finished.") );
384 SetDlgItemText( dlg, IDC_KEYGEN_SUBKEYINF, _("Subkey size in &bits"));
385 SetDlgItemText( dlg, IDC_KEYGEN_NAMEINF, _("&Real name") );
386 SetDlgItemText( dlg, IDC_KEYGEN_COMMINF, _("&Comment (optional)") );
387 SetDlgItemText( dlg, IDC_KEYGEN_EMAILINF, _("Email &address") );
388 SetDlgItemText( dlg, IDC_KEYGEN_EXPINF, _("&Expire date"));
389 SetDlgItemText( dlg, IDC_KEYGEN_PWDINF, _("&Passphrase") );
390 SetDlgItemText( dlg, IDC_KEYGEN_REPWDINF, _("&Repeat passphrase") );
391 SetDlgItemText( dlg, IDC_KEYGEN_KEYTYPEINF, _("Key &type") );
392 SetDlgItemText (dlg, IDC_KEYGEN_EXPNEVER, _("&Never"));
393 SetDlgItemText (dlg, IDC_KEYGEN_HIDEPWD, _("&Hide Typing"));
394 SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
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 != NULL && ctx->first_start == 0)
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, 0);
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