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