1 |
werner |
36 |
/* wptKeygenDlg.cpp - Key Generation dialog |
2 |
twoaday |
328 |
* Copyright (C) 2000-2007, 2009 Timo Schulz |
3 |
werner |
36 |
* |
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 |
|
|
#ifdef HAVE_CONFIG_H |
17 |
|
|
#include <config.h> |
18 |
|
|
#endif |
19 |
|
|
|
20 |
|
|
#include <windows.h> |
21 |
twoaday |
225 |
#include <time.h> |
22 |
werner |
36 |
|
23 |
werner |
47 |
#include "resource.h" |
24 |
werner |
36 |
#include "wptTypes.h" |
25 |
|
|
#include "wptNLS.h" |
26 |
|
|
#include "wptGPG.h" |
27 |
|
|
#include "wptCommonCtl.h" |
28 |
twoaday |
314 |
#include "wptContext.h" |
29 |
werner |
36 |
#include "wptDlgs.h" |
30 |
|
|
#include "wptW32API.h" |
31 |
|
|
#include "wptVersion.h" |
32 |
|
|
#include "wptErrors.h" |
33 |
twoaday |
314 |
#include "StringBuffer.h" |
34 |
werner |
36 |
|
35 |
twoaday |
204 |
|
36 |
werner |
36 |
/* All valid key generation combination. */ |
37 |
|
|
enum gpg_keytype_t { |
38 |
|
|
GPG_KEYGEN_NONE = 0, |
39 |
|
|
GPG_KEYGEN_DSA_ELG = 1, |
40 |
|
|
GPG_KEYGEN_DSA_RSA = 2, |
41 |
twoaday |
328 |
GPG_KEYGEN_RSA_RSA = 3 /*PGP*/ |
42 |
werner |
36 |
}; |
43 |
|
|
|
44 |
|
|
|
45 |
|
|
/* Generate the GPG specific genkey params with the given information. |
46 |
|
|
@keytype: See valid combinations. |
47 |
|
|
@bits: Length in bits. |
48 |
|
|
@user: user-ID name |
49 |
|
|
@comment: comment for the user-ID. |
50 |
|
|
@email: email address. |
51 |
|
|
@expdata: date of expiration or NULL. |
52 |
|
|
@passphrase: the actual passphrase. |
53 |
|
|
Return value: the gen. params. */ |
54 |
|
|
static char* |
55 |
twoaday |
314 |
gpg_genkey_params (int keytype, int bits, |
56 |
twoaday |
344 |
const char *user, const char *comment, const char *email, |
57 |
|
|
const char *expdate, const char *pass) |
58 |
werner |
36 |
{ |
59 |
twoaday |
314 |
StringBuffer p; |
60 |
|
|
char *param; |
61 |
|
|
|
62 |
werner |
36 |
if (keytype == GPG_KEYGEN_NONE) |
63 |
|
|
return NULL; |
64 |
|
|
|
65 |
twoaday |
314 |
p = "<GnupgKeyParms format=\"internal\">\n"; |
66 |
|
|
/* In this phase we set the primary key information fields. */ |
67 |
|
|
switch (keytype) { |
68 |
|
|
case GPG_KEYGEN_DSA_ELG: |
69 |
|
|
case GPG_KEYGEN_DSA_RSA: |
70 |
|
|
p = p + "Key-Type: DSA\n"; |
71 |
|
|
break; |
72 |
|
|
|
73 |
|
|
case GPG_KEYGEN_RSA_RSA: |
74 |
|
|
p = p + "Key-Type: RSA\n"; |
75 |
|
|
break; |
76 |
|
|
|
77 |
|
|
default: |
78 |
|
|
break; |
79 |
werner |
36 |
} |
80 |
twoaday |
344 |
|
81 |
|
|
/* DSA v2 supports larger keys >1024 bits */ |
82 |
|
|
p = p + "Key-Usage: sign\n"; |
83 |
|
|
p = p + "Key-Length: " + (int)bits + "\n"; |
84 |
werner |
36 |
|
85 |
twoaday |
314 |
/* The next phase is the subkey information if needed. */ |
86 |
twoaday |
344 |
if (keytype == GPG_KEYGEN_DSA_ELG || |
87 |
|
|
keytype == GPG_KEYGEN_DSA_RSA || |
88 |
twoaday |
314 |
keytype == GPG_KEYGEN_RSA_RSA) { |
89 |
|
|
if (keytype == GPG_KEYGEN_DSA_ELG) |
90 |
|
|
p = p + "Subkey-Type: ELG-E\n"; |
91 |
|
|
else if (keytype == GPG_KEYGEN_DSA_RSA || keytype == GPG_KEYGEN_RSA_RSA) |
92 |
|
|
p = p + "Subkey-Type: RSA\n"; |
93 |
|
|
p = p + "Subkey-Usage: encrypt\n"; |
94 |
|
|
p = p + "Subkey-Length: " + (int)bits + "\n"; |
95 |
werner |
36 |
} |
96 |
twoaday |
314 |
|
97 |
|
|
/* Followed by the user ID information. */ |
98 |
|
|
p = p + "Name-Real: " + user + "\n"; |
99 |
|
|
if (comment != NULL) |
100 |
|
|
p = p + "Name-Comment: " + comment + "\n"; |
101 |
|
|
p = p + "Name-Email: " + email + "\n"; |
102 |
|
|
|
103 |
|
|
if (expdate != NULL) |
104 |
|
|
p = p + "Expire-Date: " + expdate + "\n"; |
105 |
|
|
else |
106 |
|
|
p = p + "Expire-Date: 0\n"; |
107 |
|
|
p = p + "Passphrase: " + pass + "\n"; |
108 |
|
|
|
109 |
|
|
p = p + "</GnupgKeyParms>\n"; |
110 |
|
|
param = p.getBufferCopy (); |
111 |
|
|
p.wipeContents (); |
112 |
|
|
|
113 |
|
|
return param; |
114 |
twoaday |
32 |
} |
115 |
werner |
36 |
|
116 |
|
|
|
117 |
|
|
/* Generate a key with the given params @params. @prog_cb is a user defined |
118 |
|
|
progress callback which is called during the generation. |
119 |
|
|
@fpr will store the fingerprint of the generated key. |
120 |
|
|
Return value: 0 on success. */ |
121 |
|
|
gpgme_error_t |
122 |
|
|
gpg_genkey (const char *params, gpgme_progress_cb_t prog_cb, char **fpr) |
123 |
|
|
{ |
124 |
twoaday |
278 |
gpgme_error_t err; |
125 |
werner |
36 |
gpgme_ctx_t ctx; |
126 |
|
|
gpgme_genkey_result_t res; |
127 |
|
|
|
128 |
|
|
err = gpgme_new(&ctx); |
129 |
|
|
if (err) |
130 |
|
|
return err; |
131 |
|
|
if (prog_cb) |
132 |
|
|
gpgme_set_progress_cb (ctx, prog_cb, NULL); |
133 |
|
|
err = gpgme_op_genkey (ctx, params, NULL, NULL); |
134 |
|
|
if (!err) { |
135 |
|
|
res = gpgme_op_genkey_result (ctx); |
136 |
twoaday |
225 |
*fpr = res && res->fpr? m_strdup (res->fpr) : NULL; |
137 |
werner |
36 |
} |
138 |
|
|
gpgme_release (ctx); |
139 |
|
|
return err; |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
twoaday |
314 |
/* Reset all dialog fields to its initial value. */ |
145 |
werner |
36 |
static void |
146 |
twoaday |
314 |
reset_dlg_fields (HWND dlg) |
147 |
werner |
36 |
{ |
148 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_SUBKEYBITS, ""); |
149 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_NAME, ""); |
150 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_EMAIL, ""); |
151 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_COMMENT, ""); |
152 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_EXPDATE, ""); |
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
|
156 |
|
|
/* Ask the user if a keyring backup is wanted and if so, |
157 |
twoaday |
314 |
backup both keyrings to the selected folder. |
158 |
|
|
Return value: true on success. */ |
159 |
|
|
static bool |
160 |
werner |
36 |
backup_keyrings (HWND dlg) |
161 |
|
|
{ |
162 |
twoaday |
314 |
bool success = true; |
163 |
|
|
|
164 |
twoaday |
344 |
int id = msg_box (dlg, |
165 |
werner |
36 |
_("It is STRONGLY recommend that you backup your keyrings because they both " |
166 |
|
|
"contain VERY important data.\nRemember that your hard disk can crash or the " |
167 |
|
|
"files can be deleted by accident; so it is a good\nidea to store them on " |
168 |
|
|
"a different mass stoarge like a floppy or CDR!\n\n" |
169 |
|
|
"Backup your keyrings now?"), |
170 |
|
|
_("WARNING - Important hint" ), MB_YESNO); |
171 |
twoaday |
314 |
if (id != IDYES) |
172 |
|
|
return false; |
173 |
|
|
|
174 |
twoaday |
344 |
char *path = get_gnupg_path (); |
175 |
|
|
const char *name = get_filesave_dlg (dlg, _("Destination for Public Keyring"), |
176 |
twoaday |
314 |
NULL, "pubring_bak.gpg"); |
177 |
twoaday |
345 |
char *keyring; |
178 |
twoaday |
314 |
if (name != NULL) { |
179 |
twoaday |
345 |
keyring = make_filename (path, "pubring", "gpg"); |
180 |
twoaday |
314 |
if (!CopyFile (keyring, name, FALSE)) { |
181 |
|
|
log_box (_("Key Generation"), MB_ERR, |
182 |
|
|
_("Could not copy %s -> %s"), keyring, name); |
183 |
|
|
success = false; |
184 |
|
|
} |
185 |
|
|
free_if_alloc (keyring); |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
name = get_filesave_dlg (dlg, _("Destination for Secret Keyring"), |
189 |
|
|
NULL, "secring_bak.gpg"); |
190 |
|
|
if (name != NULL) { |
191 |
|
|
keyring = make_filename (path, "secring", "gpg"); |
192 |
|
|
if (!CopyFile (keyring, name, FALSE)) { |
193 |
|
|
log_box (_("Key Generation"), MB_ERR, |
194 |
twoaday |
130 |
_("Could not copy %s -> %s"), keyring, name); |
195 |
twoaday |
314 |
success = false; |
196 |
|
|
} |
197 |
|
|
free_if_alloc (keyring); |
198 |
werner |
36 |
} |
199 |
twoaday |
130 |
free_if_alloc (path); |
200 |
twoaday |
314 |
return success; |
201 |
werner |
36 |
} |
202 |
|
|
|
203 |
|
|
|
204 |
|
|
/* Fill in all valid GPG algorithms. */ |
205 |
|
|
static void |
206 |
|
|
fill_keytype_box (HWND dlg) |
207 |
|
|
{ |
208 |
twoaday |
130 |
HWND cb = GetDlgItem (dlg, IDC_KEYGEN_KEYTYPE); |
209 |
werner |
36 |
|
210 |
twoaday |
130 |
#define addstr(cb, str) \ |
211 |
|
|
SendMessage ((cb), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)(str)) |
212 |
twoaday |
328 |
addstr (cb, _("DSA and ELG")); |
213 |
twoaday |
130 |
addstr (cb, _("DSA and RSA")); |
214 |
|
|
addstr (cb, _("RSA and RSA (PGP)") ); |
215 |
twoaday |
328 |
SendMessage (cb, CB_SETCURSEL, 2, 0); |
216 |
werner |
36 |
#undef addstr |
217 |
|
|
} |
218 |
|
|
|
219 |
|
|
|
220 |
twoaday |
225 |
time_t w32_mktime (SYSTEMTIME *st); |
221 |
|
|
|
222 |
werner |
36 |
/* Check that the given date lies not in the past. |
223 |
|
|
Return value: 1 on success. */ |
224 |
|
|
int |
225 |
|
|
keygen_check_date (SYSTEMTIME *st) |
226 |
|
|
{ |
227 |
twoaday |
344 |
time_t date = w32_mktime (st); |
228 |
|
|
return date >= time (NULL)? 1 : 0; |
229 |
werner |
36 |
} |
230 |
|
|
|
231 |
|
|
|
232 |
|
|
/* Dialog box procedure for key generation. */ |
233 |
|
|
BOOL CALLBACK |
234 |
|
|
keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
235 |
|
|
{ |
236 |
|
|
static genkey_s *ctx; |
237 |
|
|
SYSTEMTIME st; |
238 |
|
|
gpgme_error_t err; |
239 |
twoaday |
204 |
char *utf8_name =NULL, *utf8_comment = NULL; |
240 |
twoaday |
314 |
char email[128], t[64]; |
241 |
twoaday |
130 |
char *pwd; |
242 |
twoaday |
314 |
char *expire = NULL, *fpr=NULL; |
243 |
twoaday |
130 |
int bits, use_comment, keytype = 0; |
244 |
|
|
int cancel = 0; |
245 |
|
|
char *p; |
246 |
werner |
36 |
|
247 |
twoaday |
225 |
switch (msg) { |
248 |
werner |
36 |
case WM_INITDIALOG: |
249 |
twoaday |
73 |
if (lparam != 0) |
250 |
werner |
36 |
ctx = (genkey_s *)lparam; |
251 |
twoaday |
130 |
SetWindowText (dlg, _("Key Generation")); |
252 |
|
|
SetDlgItemText(dlg, IDC_KEYGEN_INFO, |
253 |
werner |
36 |
_("NOTE: Key generation can be a lengthy process! Please wait until " |
254 |
twoaday |
248 |
"you get the message that key generation has finished.")); |
255 |
twoaday |
328 |
SetDlgItemText (dlg, IDC_KEYGEN_SUBKEYINF, _("Subkey size in &bits:")); |
256 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_NAMEINF, _("&Real name:")); |
257 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_COMMINF, _("&Comment (optional):")); |
258 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_EMAILINF, _("Email &address:")); |
259 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_EXPINF, _("&Expire date:")); |
260 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_KEYTYPEINF, _("Key &type:")); |
261 |
werner |
36 |
SetDlgItemText (dlg, IDC_KEYGEN_EXPNEVER, _("&Never")); |
262 |
twoaday |
101 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
263 |
werner |
36 |
|
264 |
twoaday |
130 |
SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, DFAULT_KEYSIZE, FALSE); |
265 |
werner |
36 |
CheckDlgButton (dlg, IDC_KEYGEN_HIDEPWD, BST_CHECKED); |
266 |
|
|
CheckDlgButton (dlg, IDC_KEYGEN_EXPNEVER, BST_CHECKED); |
267 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), FALSE); |
268 |
|
|
fill_keytype_box (dlg); |
269 |
|
|
center_window (dlg, NULL); |
270 |
|
|
SetForegroundWindow (dlg); |
271 |
|
|
return TRUE; |
272 |
twoaday |
328 |
|
273 |
|
|
case WM_DESTROY: |
274 |
|
|
balloon_msg_disable (); |
275 |
|
|
break; |
276 |
|
|
|
277 |
|
|
case WM_HELP: |
278 |
|
|
html_help_show(32); |
279 |
|
|
break; |
280 |
|
|
|
281 |
werner |
36 |
case WM_COMMAND: |
282 |
twoaday |
248 |
if (HIWORD (wparam) == CBN_SELCHANGE && |
283 |
|
|
LOWORD (wparam) == IDC_KEYGEN_KEYTYPE) { |
284 |
|
|
keytype = SendMessage ((HWND)lparam, CB_GETCURSEL, 0, 0); |
285 |
|
|
|
286 |
twoaday |
328 |
bits = DFAULT_KEYSIZE; |
287 |
twoaday |
248 |
SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, bits, FALSE); |
288 |
|
|
} |
289 |
|
|
|
290 |
werner |
36 |
if (HIWORD (wparam) == BN_CLICKED && |
291 |
|
|
LOWORD (wparam) == IDC_KEYGEN_EXPNEVER) { |
292 |
|
|
int never = IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER); |
293 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), !never); |
294 |
|
|
} |
295 |
|
|
|
296 |
twoaday |
130 |
switch (LOWORD (wparam)) { |
297 |
werner |
36 |
case IDOK: |
298 |
twoaday |
328 |
balloon_msg_disable (); |
299 |
werner |
36 |
bits = GetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, NULL, FALSE); |
300 |
twoaday |
328 |
if (bits < 2048 || bits > 4096) { |
301 |
|
|
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_SUBKEYBITS), |
302 |
|
|
_("Invalid keysize value. Allowed values 2048-4096 bits."), |
303 |
|
|
IDI_ERROR); |
304 |
werner |
36 |
return FALSE; |
305 |
|
|
} |
306 |
|
|
if (bits > DFAULT_KEYSIZE) { |
307 |
twoaday |
130 |
int id = msg_box (dlg, _("Do you really need such a large key?"), |
308 |
werner |
36 |
_("Key Generation"), MB_YESNO); |
309 |
|
|
if (id == IDNO) |
310 |
|
|
bits = DFAULT_KEYSIZE; |
311 |
|
|
} |
312 |
twoaday |
204 |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYGEN_NAME, &utf8_name)) { |
313 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_NAME), |
314 |
|
|
_("Please enter the name."), |
315 |
|
|
IDI_ERROR); |
316 |
werner |
36 |
return FALSE; |
317 |
|
|
} |
318 |
twoaday |
204 |
if (strchr (utf8_name, '@')) { |
319 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_NAME), |
320 |
|
|
_("Please do not enter the email address in the name field."), |
321 |
|
|
IDI_WARNING); |
322 |
twoaday |
204 |
free_if_alloc (utf8_name); |
323 |
werner |
36 |
return FALSE; |
324 |
|
|
} |
325 |
twoaday |
314 |
if (!GetDlgItemText (dlg, IDC_KEYGEN_EMAIL, email, DIM (email) -1) |
326 |
twoaday |
190 |
|| check_email_address (email)) { |
327 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_EMAIL), |
328 |
|
|
_("Please enter a valid email address."), |
329 |
|
|
IDI_ERROR); |
330 |
twoaday |
204 |
free_if_alloc (utf8_name); |
331 |
werner |
36 |
return FALSE; |
332 |
|
|
} |
333 |
twoaday |
204 |
use_comment = GetDlgItemText_utf8 (dlg, IDC_KEYGEN_COMMENT, |
334 |
|
|
&utf8_comment); |
335 |
|
|
if (use_comment > 0 && strchr (utf8_comment, '@')) { |
336 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_COMMENT), |
337 |
|
|
_("Please do NOT enter the email address in the comment field."), |
338 |
|
|
IDI_WARNING); |
339 |
twoaday |
204 |
free_if_alloc (utf8_name); |
340 |
|
|
free_if_alloc (utf8_comment); |
341 |
twoaday |
225 |
return TRUE; |
342 |
werner |
36 |
} |
343 |
|
|
keytype = SendDlgItemMessage (dlg, IDC_KEYGEN_KEYTYPE, CB_GETCURSEL, 0, 0) + 1; |
344 |
|
|
if (IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER)) |
345 |
|
|
expire = NULL; |
346 |
|
|
else { |
347 |
|
|
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), &st); |
348 |
twoaday |
225 |
if (!keygen_check_date (&st)) { |
349 |
|
|
free_if_alloc (utf8_name); |
350 |
|
|
free_if_alloc (utf8_comment); |
351 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), |
352 |
|
|
_("The date you have chosen has already passed or is today."), |
353 |
|
|
IDI_ERROR); |
354 |
twoaday |
225 |
return TRUE; |
355 |
|
|
} |
356 |
werner |
36 |
_snprintf (t, DIM (t)-1, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); |
357 |
|
|
expire = t; |
358 |
|
|
} |
359 |
twoaday |
130 |
|
360 |
twoaday |
314 |
/* We don't allow empty passphrases during key generation. */ |
361 |
twoaday |
229 |
pwd = request_passphrase2 (_("Key Generation"), |
362 |
twoaday |
314 |
PASSDLG_STRICT|PASSDLG_WARN_UTF8|PASSDLG_NOTEMPTY, &cancel); |
363 |
twoaday |
130 |
if (cancel) { |
364 |
|
|
sfree_if_alloc (pwd); |
365 |
twoaday |
204 |
free_if_alloc (utf8_name); |
366 |
|
|
free_if_alloc (utf8_comment); |
367 |
twoaday |
130 |
return FALSE; |
368 |
|
|
} |
369 |
|
|
if (!pwd) { |
370 |
|
|
msg_box (dlg, _("Please enter the passphrase."), |
371 |
|
|
_("Key Generation"), MB_ERR); |
372 |
twoaday |
204 |
free_if_alloc (utf8_name); |
373 |
|
|
free_if_alloc (utf8_comment); |
374 |
werner |
36 |
return FALSE; |
375 |
|
|
} |
376 |
twoaday |
130 |
|
377 |
twoaday |
314 |
p = gpg_genkey_params (keytype, bits, utf8_name, |
378 |
|
|
!use_comment && !utf8_comment? NULL :utf8_comment, |
379 |
|
|
email, expire, pwd); |
380 |
twoaday |
204 |
free_if_alloc (utf8_name); |
381 |
|
|
free_if_alloc (utf8_comment); |
382 |
twoaday |
130 |
keygen_cb_dlg_create (); |
383 |
werner |
36 |
err = gpg_genkey (p, keygen_cb, &fpr); |
384 |
twoaday |
130 |
sfree_if_alloc (pwd); |
385 |
twoaday |
314 |
sfree_if_alloc (p); /* burn the passphrase */ |
386 |
twoaday |
211 |
keygen_cb_dlg_destroy (1); |
387 |
twoaday |
115 |
if (err) { |
388 |
twoaday |
201 |
free_if_alloc (fpr); |
389 |
twoaday |
115 |
msg_box (dlg, gpgme_strerror (err), _("Key Generation"), MB_ERR); |
390 |
werner |
36 |
return FALSE; |
391 |
|
|
} |
392 |
twoaday |
115 |
status_box (dlg, _("Key Generation completed"), _("GnuPG Status")); |
393 |
werner |
36 |
|
394 |
|
|
keycache_update (0, fpr); |
395 |
|
|
keycache_update (1, fpr); |
396 |
twoaday |
201 |
free_if_alloc (fpr); |
397 |
werner |
36 |
|
398 |
twoaday |
314 |
reset_dlg_fields (dlg); |
399 |
werner |
36 |
backup_keyrings (dlg); |
400 |
twoaday |
150 |
if (ctx) |
401 |
|
|
ctx->cancel = 0; |
402 |
werner |
36 |
EndDialog (dlg, TRUE); |
403 |
|
|
return TRUE; |
404 |
|
|
|
405 |
|
|
case IDCANCEL: |
406 |
twoaday |
150 |
if (ctx) |
407 |
|
|
ctx->cancel = 1; |
408 |
|
|
EndDialog (dlg, FALSE); |
409 |
werner |
36 |
return FALSE; |
410 |
|
|
} |
411 |
|
|
break; |
412 |
|
|
} |
413 |
|
|
|
414 |
|
|
return FALSE; |
415 |
|
|
} |
416 |
|
|
|
417 |
|
|
|
418 |
twoaday |
234 |
/* Wizard like keygen dialog for novice users. */ |
419 |
werner |
36 |
BOOL CALLBACK |
420 |
|
|
keygen_wizard_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
421 |
|
|
{ |
422 |
|
|
static genkey_s *ctx; |
423 |
twoaday |
328 |
static int pubkey_algo = GPG_KEYGEN_RSA_RSA; |
424 |
werner |
36 |
gpgme_error_t err; |
425 |
twoaday |
204 |
char email[128]; |
426 |
twoaday |
234 |
char *utf8_name=NULL, *p, *fpr=NULL; |
427 |
|
|
char *pass = NULL; |
428 |
werner |
36 |
int cancel = 0; |
429 |
|
|
|
430 |
twoaday |
234 |
switch (msg) { |
431 |
werner |
36 |
case WM_INITDIALOG: |
432 |
|
|
ctx = (genkey_s *)lparam; |
433 |
twoaday |
328 |
ShowWindow (GetDlgItem (dlg, IDC_KEYWIZARD_USEOTHERPK), SW_HIDE); |
434 |
werner |
36 |
SetDlgItemText (dlg, IDC_KEYWIZARD_NAMEINF, _("Real name:")); |
435 |
|
|
SetDlgItemText (dlg, IDC_KEYWIZARD_EMAILINF, _("Email address:")); |
436 |
|
|
SetDlgItemText (dlg, IDC_KEYWIZARD_TITLEINF, _("Name and E-Mail Assignment")); |
437 |
twoaday |
234 |
SetDlgItemText (dlg, IDC_KEYWIZARD_TEXT1INF, _("Every key pair must have a name associated with it. The name and\nemail address let your correspondents know that your public key they\nare using belongs to us.")); |
438 |
twoaday |
229 |
SetDlgItemText (dlg, IDC_KEYWIZARD_TEXT2INF, _("By associating 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.")); |
439 |
werner |
36 |
SetWindowText (dlg, _("Key Generation Wizard")); |
440 |
twoaday |
105 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
441 |
werner |
36 |
SetForegroundWindow (dlg); |
442 |
|
|
center_window (dlg, NULL); |
443 |
|
|
break; |
444 |
twoaday |
328 |
|
445 |
|
|
case WM_DESTROY: |
446 |
|
|
balloon_msg_disable (); |
447 |
|
|
break; |
448 |
|
|
|
449 |
|
|
case WM_COMMAND: |
450 |
twoaday |
204 |
switch (LOWORD( wparam)) { |
451 |
werner |
36 |
case IDOK: |
452 |
twoaday |
328 |
balloon_msg_disable (); |
453 |
twoaday |
204 |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYWIZARD_NAME, &utf8_name)) { |
454 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYWIZARD_NAME), |
455 |
|
|
_("Please enter the name."), IDI_ERROR); |
456 |
werner |
36 |
return FALSE; |
457 |
|
|
} |
458 |
twoaday |
204 |
if (strchr (utf8_name, '@')) { |
459 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYWIZARD_NAME), |
460 |
|
|
_("Please do not enter the email address in the name field."), |
461 |
|
|
IDI_WARNING); |
462 |
twoaday |
204 |
free_if_alloc (utf8_name); |
463 |
werner |
36 |
return FALSE; |
464 |
|
|
} |
465 |
twoaday |
344 |
if (!GetDlgItemText (dlg, IDC_KEYWIZARD_EMAIL, email, DIM (email)-1) || |
466 |
|
|
check_email_address (email)) { |
467 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYWIZARD_EMAIL), |
468 |
|
|
_("Please enter a valid email address."), |
469 |
|
|
IDI_ERROR); |
470 |
twoaday |
204 |
free_if_alloc (utf8_name); |
471 |
werner |
36 |
return FALSE; |
472 |
|
|
} |
473 |
|
|
if (strchr (email, '<') || strchr (email, '>')) { |
474 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYWIZARD_EMAIL), |
475 |
|
|
_("Please do not add '<' or '>' to the email address."), |
476 |
|
|
IDI_WARNING); |
477 |
twoaday |
204 |
free_if_alloc (utf8_name); |
478 |
werner |
36 |
return FALSE; |
479 |
|
|
} |
480 |
twoaday |
314 |
|
481 |
|
|
/* We don't allow empty passphrases during key generation. */ |
482 |
|
|
pass = request_passphrase2 (_("Key Generation"), |
483 |
|
|
PASSDLG_STRICT|PASSDLG_WARN_UTF8|PASSDLG_NOTEMPTY, &cancel); |
484 |
twoaday |
204 |
if (cancel) { |
485 |
|
|
free_if_alloc (utf8_name); |
486 |
werner |
36 |
return FALSE; |
487 |
twoaday |
204 |
} |
488 |
twoaday |
328 |
if (IsDlgButtonChecked (dlg, IDC_KEYWIZARD_USEOTHERPK)) |
489 |
twoaday |
344 |
pubkey_algo = GPG_KEYGEN_DSA_ELG; |
490 |
|
|
else |
491 |
|
|
pubkey_algo = GPG_KEYGEN_RSA_RSA; |
492 |
werner |
36 |
p = gpg_genkey_params (pubkey_algo, DFAULT_KEYSIZE, utf8_name, |
493 |
twoaday |
314 |
NULL, email, NULL, pass); |
494 |
twoaday |
201 |
free_if_alloc (utf8_name); |
495 |
werner |
36 |
keygen_cb_dlg_create(); |
496 |
|
|
err = gpg_genkey (p, keygen_cb, &fpr); |
497 |
twoaday |
211 |
keygen_cb_dlg_destroy (1); |
498 |
twoaday |
225 |
sfree_if_alloc (p); |
499 |
werner |
36 |
sfree_if_alloc (pass); |
500 |
twoaday |
201 |
if (err) { |
501 |
twoaday |
314 |
msg_box (dlg, gpgme_strerror (err), |
502 |
|
|
_("Key Generation Wizard"), MB_ERR); |
503 |
twoaday |
201 |
free_if_alloc (fpr); |
504 |
werner |
36 |
return FALSE; |
505 |
|
|
} |
506 |
twoaday |
204 |
status_box (dlg, _("Key Generation completed"), _("GnuPG Status")); |
507 |
werner |
36 |
keycache_update (0, fpr); |
508 |
|
|
keycache_update (1, fpr); |
509 |
twoaday |
201 |
free_if_alloc (fpr); |
510 |
twoaday |
150 |
|
511 |
werner |
36 |
backup_keyrings (dlg); |
512 |
twoaday |
314 |
if (ctx != NULL) |
513 |
twoaday |
256 |
ctx->cancel = 0; |
514 |
werner |
36 |
EndDialog (dlg, TRUE); |
515 |
|
|
break; |
516 |
|
|
|
517 |
|
|
case IDCANCEL: |
518 |
twoaday |
314 |
if (ctx != NULL) |
519 |
twoaday |
150 |
ctx->cancel = 1; |
520 |
|
|
EndDialog (dlg, FALSE); |
521 |
werner |
36 |
break; |
522 |
|
|
} |
523 |
|
|
break; |
524 |
|
|
} |
525 |
|
|
return FALSE; |
526 |
|
|
} |