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 |
|
|
if (name != NULL) { |
178 |
twoaday |
344 |
char *keyring = make_filename (path, "pubring", "gpg"); |
179 |
twoaday |
314 |
if (!CopyFile (keyring, name, FALSE)) { |
180 |
|
|
log_box (_("Key Generation"), MB_ERR, |
181 |
|
|
_("Could not copy %s -> %s"), keyring, name); |
182 |
|
|
success = false; |
183 |
|
|
} |
184 |
|
|
free_if_alloc (keyring); |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
name = get_filesave_dlg (dlg, _("Destination for Secret Keyring"), |
188 |
|
|
NULL, "secring_bak.gpg"); |
189 |
|
|
if (name != NULL) { |
190 |
|
|
keyring = make_filename (path, "secring", "gpg"); |
191 |
|
|
if (!CopyFile (keyring, name, FALSE)) { |
192 |
|
|
log_box (_("Key Generation"), MB_ERR, |
193 |
twoaday |
130 |
_("Could not copy %s -> %s"), keyring, name); |
194 |
twoaday |
314 |
success = false; |
195 |
|
|
} |
196 |
|
|
free_if_alloc (keyring); |
197 |
werner |
36 |
} |
198 |
twoaday |
130 |
free_if_alloc (path); |
199 |
twoaday |
314 |
return success; |
200 |
werner |
36 |
} |
201 |
|
|
|
202 |
|
|
|
203 |
|
|
/* Fill in all valid GPG algorithms. */ |
204 |
|
|
static void |
205 |
|
|
fill_keytype_box (HWND dlg) |
206 |
|
|
{ |
207 |
twoaday |
130 |
HWND cb = GetDlgItem (dlg, IDC_KEYGEN_KEYTYPE); |
208 |
werner |
36 |
|
209 |
twoaday |
130 |
#define addstr(cb, str) \ |
210 |
|
|
SendMessage ((cb), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)(str)) |
211 |
twoaday |
328 |
addstr (cb, _("DSA and ELG")); |
212 |
twoaday |
130 |
addstr (cb, _("DSA and RSA")); |
213 |
|
|
addstr (cb, _("RSA and RSA (PGP)") ); |
214 |
twoaday |
328 |
SendMessage (cb, CB_SETCURSEL, 2, 0); |
215 |
werner |
36 |
#undef addstr |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
|
219 |
twoaday |
225 |
time_t w32_mktime (SYSTEMTIME *st); |
220 |
|
|
|
221 |
werner |
36 |
/* Check that the given date lies not in the past. |
222 |
|
|
Return value: 1 on success. */ |
223 |
|
|
int |
224 |
|
|
keygen_check_date (SYSTEMTIME *st) |
225 |
|
|
{ |
226 |
twoaday |
344 |
time_t date = w32_mktime (st); |
227 |
|
|
return date >= time (NULL)? 1 : 0; |
228 |
werner |
36 |
} |
229 |
|
|
|
230 |
|
|
|
231 |
|
|
/* Dialog box procedure for key generation. */ |
232 |
|
|
BOOL CALLBACK |
233 |
|
|
keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
234 |
|
|
{ |
235 |
|
|
static genkey_s *ctx; |
236 |
|
|
SYSTEMTIME st; |
237 |
|
|
gpgme_error_t err; |
238 |
twoaday |
204 |
char *utf8_name =NULL, *utf8_comment = NULL; |
239 |
twoaday |
314 |
char email[128], t[64]; |
240 |
twoaday |
130 |
char *pwd; |
241 |
twoaday |
314 |
char *expire = NULL, *fpr=NULL; |
242 |
twoaday |
130 |
int bits, use_comment, keytype = 0; |
243 |
|
|
int cancel = 0; |
244 |
|
|
char *p; |
245 |
werner |
36 |
|
246 |
twoaday |
225 |
switch (msg) { |
247 |
werner |
36 |
case WM_INITDIALOG: |
248 |
twoaday |
73 |
if (lparam != 0) |
249 |
werner |
36 |
ctx = (genkey_s *)lparam; |
250 |
twoaday |
130 |
SetWindowText (dlg, _("Key Generation")); |
251 |
|
|
SetDlgItemText(dlg, IDC_KEYGEN_INFO, |
252 |
werner |
36 |
_("NOTE: Key generation can be a lengthy process! Please wait until " |
253 |
twoaday |
248 |
"you get the message that key generation has finished.")); |
254 |
twoaday |
328 |
SetDlgItemText (dlg, IDC_KEYGEN_SUBKEYINF, _("Subkey size in &bits:")); |
255 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_NAMEINF, _("&Real name:")); |
256 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_COMMINF, _("&Comment (optional):")); |
257 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_EMAILINF, _("Email &address:")); |
258 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_EXPINF, _("&Expire date:")); |
259 |
|
|
SetDlgItemText (dlg, IDC_KEYGEN_KEYTYPEINF, _("Key &type:")); |
260 |
werner |
36 |
SetDlgItemText (dlg, IDC_KEYGEN_EXPNEVER, _("&Never")); |
261 |
twoaday |
101 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
262 |
werner |
36 |
|
263 |
twoaday |
130 |
SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, DFAULT_KEYSIZE, FALSE); |
264 |
werner |
36 |
CheckDlgButton (dlg, IDC_KEYGEN_HIDEPWD, BST_CHECKED); |
265 |
|
|
CheckDlgButton (dlg, IDC_KEYGEN_EXPNEVER, BST_CHECKED); |
266 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), FALSE); |
267 |
|
|
fill_keytype_box (dlg); |
268 |
|
|
center_window (dlg, NULL); |
269 |
|
|
SetForegroundWindow (dlg); |
270 |
|
|
return TRUE; |
271 |
twoaday |
328 |
|
272 |
|
|
case WM_DESTROY: |
273 |
|
|
balloon_msg_disable (); |
274 |
|
|
break; |
275 |
|
|
|
276 |
|
|
case WM_HELP: |
277 |
|
|
html_help_show(32); |
278 |
|
|
break; |
279 |
|
|
|
280 |
werner |
36 |
case WM_COMMAND: |
281 |
twoaday |
248 |
if (HIWORD (wparam) == CBN_SELCHANGE && |
282 |
|
|
LOWORD (wparam) == IDC_KEYGEN_KEYTYPE) { |
283 |
|
|
keytype = SendMessage ((HWND)lparam, CB_GETCURSEL, 0, 0); |
284 |
|
|
|
285 |
twoaday |
328 |
bits = DFAULT_KEYSIZE; |
286 |
twoaday |
248 |
SetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, bits, FALSE); |
287 |
|
|
} |
288 |
|
|
|
289 |
werner |
36 |
if (HIWORD (wparam) == BN_CLICKED && |
290 |
|
|
LOWORD (wparam) == IDC_KEYGEN_EXPNEVER) { |
291 |
|
|
int never = IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER); |
292 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), !never); |
293 |
|
|
} |
294 |
|
|
|
295 |
twoaday |
130 |
switch (LOWORD (wparam)) { |
296 |
werner |
36 |
case IDOK: |
297 |
twoaday |
328 |
balloon_msg_disable (); |
298 |
werner |
36 |
bits = GetDlgItemInt (dlg, IDC_KEYGEN_SUBKEYBITS, NULL, FALSE); |
299 |
twoaday |
328 |
if (bits < 2048 || bits > 4096) { |
300 |
|
|
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_SUBKEYBITS), |
301 |
|
|
_("Invalid keysize value. Allowed values 2048-4096 bits."), |
302 |
|
|
IDI_ERROR); |
303 |
werner |
36 |
return FALSE; |
304 |
|
|
} |
305 |
|
|
if (bits > DFAULT_KEYSIZE) { |
306 |
twoaday |
130 |
int id = msg_box (dlg, _("Do you really need such a large key?"), |
307 |
werner |
36 |
_("Key Generation"), MB_YESNO); |
308 |
|
|
if (id == IDNO) |
309 |
|
|
bits = DFAULT_KEYSIZE; |
310 |
|
|
} |
311 |
twoaday |
204 |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYGEN_NAME, &utf8_name)) { |
312 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_NAME), |
313 |
|
|
_("Please enter the name."), |
314 |
|
|
IDI_ERROR); |
315 |
werner |
36 |
return FALSE; |
316 |
|
|
} |
317 |
twoaday |
204 |
if (strchr (utf8_name, '@')) { |
318 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_NAME), |
319 |
|
|
_("Please do not enter the email address in the name field."), |
320 |
|
|
IDI_WARNING); |
321 |
twoaday |
204 |
free_if_alloc (utf8_name); |
322 |
werner |
36 |
return FALSE; |
323 |
|
|
} |
324 |
twoaday |
314 |
if (!GetDlgItemText (dlg, IDC_KEYGEN_EMAIL, email, DIM (email) -1) |
325 |
twoaday |
190 |
|| check_email_address (email)) { |
326 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_EMAIL), |
327 |
|
|
_("Please enter a valid email address."), |
328 |
|
|
IDI_ERROR); |
329 |
twoaday |
204 |
free_if_alloc (utf8_name); |
330 |
werner |
36 |
return FALSE; |
331 |
|
|
} |
332 |
twoaday |
204 |
use_comment = GetDlgItemText_utf8 (dlg, IDC_KEYGEN_COMMENT, |
333 |
|
|
&utf8_comment); |
334 |
|
|
if (use_comment > 0 && strchr (utf8_comment, '@')) { |
335 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_COMMENT), |
336 |
|
|
_("Please do NOT enter the email address in the comment field."), |
337 |
|
|
IDI_WARNING); |
338 |
twoaday |
204 |
free_if_alloc (utf8_name); |
339 |
|
|
free_if_alloc (utf8_comment); |
340 |
twoaday |
225 |
return TRUE; |
341 |
werner |
36 |
} |
342 |
|
|
keytype = SendDlgItemMessage (dlg, IDC_KEYGEN_KEYTYPE, CB_GETCURSEL, 0, 0) + 1; |
343 |
|
|
if (IsDlgButtonChecked (dlg, IDC_KEYGEN_EXPNEVER)) |
344 |
|
|
expire = NULL; |
345 |
|
|
else { |
346 |
|
|
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), &st); |
347 |
twoaday |
225 |
if (!keygen_check_date (&st)) { |
348 |
|
|
free_if_alloc (utf8_name); |
349 |
|
|
free_if_alloc (utf8_comment); |
350 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYGEN_EXPDATE), |
351 |
|
|
_("The date you have chosen has already passed or is today."), |
352 |
|
|
IDI_ERROR); |
353 |
twoaday |
225 |
return TRUE; |
354 |
|
|
} |
355 |
werner |
36 |
_snprintf (t, DIM (t)-1, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); |
356 |
|
|
expire = t; |
357 |
|
|
} |
358 |
twoaday |
130 |
|
359 |
twoaday |
314 |
/* We don't allow empty passphrases during key generation. */ |
360 |
twoaday |
229 |
pwd = request_passphrase2 (_("Key Generation"), |
361 |
twoaday |
314 |
PASSDLG_STRICT|PASSDLG_WARN_UTF8|PASSDLG_NOTEMPTY, &cancel); |
362 |
twoaday |
130 |
if (cancel) { |
363 |
|
|
sfree_if_alloc (pwd); |
364 |
twoaday |
204 |
free_if_alloc (utf8_name); |
365 |
|
|
free_if_alloc (utf8_comment); |
366 |
twoaday |
130 |
return FALSE; |
367 |
|
|
} |
368 |
|
|
if (!pwd) { |
369 |
|
|
msg_box (dlg, _("Please enter the passphrase."), |
370 |
|
|
_("Key Generation"), MB_ERR); |
371 |
twoaday |
204 |
free_if_alloc (utf8_name); |
372 |
|
|
free_if_alloc (utf8_comment); |
373 |
werner |
36 |
return FALSE; |
374 |
|
|
} |
375 |
twoaday |
130 |
|
376 |
twoaday |
314 |
p = gpg_genkey_params (keytype, bits, utf8_name, |
377 |
|
|
!use_comment && !utf8_comment? NULL :utf8_comment, |
378 |
|
|
email, expire, pwd); |
379 |
twoaday |
204 |
free_if_alloc (utf8_name); |
380 |
|
|
free_if_alloc (utf8_comment); |
381 |
twoaday |
130 |
keygen_cb_dlg_create (); |
382 |
werner |
36 |
err = gpg_genkey (p, keygen_cb, &fpr); |
383 |
twoaday |
130 |
sfree_if_alloc (pwd); |
384 |
twoaday |
314 |
sfree_if_alloc (p); /* burn the passphrase */ |
385 |
twoaday |
211 |
keygen_cb_dlg_destroy (1); |
386 |
twoaday |
115 |
if (err) { |
387 |
twoaday |
201 |
free_if_alloc (fpr); |
388 |
twoaday |
115 |
msg_box (dlg, gpgme_strerror (err), _("Key Generation"), MB_ERR); |
389 |
werner |
36 |
return FALSE; |
390 |
|
|
} |
391 |
twoaday |
115 |
status_box (dlg, _("Key Generation completed"), _("GnuPG Status")); |
392 |
werner |
36 |
|
393 |
|
|
keycache_update (0, fpr); |
394 |
|
|
keycache_update (1, fpr); |
395 |
twoaday |
201 |
free_if_alloc (fpr); |
396 |
werner |
36 |
|
397 |
twoaday |
314 |
reset_dlg_fields (dlg); |
398 |
werner |
36 |
backup_keyrings (dlg); |
399 |
twoaday |
150 |
if (ctx) |
400 |
|
|
ctx->cancel = 0; |
401 |
werner |
36 |
EndDialog (dlg, TRUE); |
402 |
|
|
return TRUE; |
403 |
|
|
|
404 |
|
|
case IDCANCEL: |
405 |
twoaday |
150 |
if (ctx) |
406 |
|
|
ctx->cancel = 1; |
407 |
|
|
EndDialog (dlg, FALSE); |
408 |
werner |
36 |
return FALSE; |
409 |
|
|
} |
410 |
|
|
break; |
411 |
|
|
} |
412 |
|
|
|
413 |
|
|
return FALSE; |
414 |
|
|
} |
415 |
|
|
|
416 |
|
|
|
417 |
twoaday |
234 |
/* Wizard like keygen dialog for novice users. */ |
418 |
werner |
36 |
BOOL CALLBACK |
419 |
|
|
keygen_wizard_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
420 |
|
|
{ |
421 |
|
|
static genkey_s *ctx; |
422 |
twoaday |
328 |
static int pubkey_algo = GPG_KEYGEN_RSA_RSA; |
423 |
werner |
36 |
gpgme_error_t err; |
424 |
twoaday |
204 |
char email[128]; |
425 |
twoaday |
234 |
char *utf8_name=NULL, *p, *fpr=NULL; |
426 |
|
|
char *pass = NULL; |
427 |
werner |
36 |
int cancel = 0; |
428 |
|
|
|
429 |
twoaday |
234 |
switch (msg) { |
430 |
werner |
36 |
case WM_INITDIALOG: |
431 |
|
|
ctx = (genkey_s *)lparam; |
432 |
twoaday |
328 |
ShowWindow (GetDlgItem (dlg, IDC_KEYWIZARD_USEOTHERPK), SW_HIDE); |
433 |
werner |
36 |
SetDlgItemText (dlg, IDC_KEYWIZARD_NAMEINF, _("Real name:")); |
434 |
|
|
SetDlgItemText (dlg, IDC_KEYWIZARD_EMAILINF, _("Email address:")); |
435 |
|
|
SetDlgItemText (dlg, IDC_KEYWIZARD_TITLEINF, _("Name and E-Mail Assignment")); |
436 |
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.")); |
437 |
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.")); |
438 |
werner |
36 |
SetWindowText (dlg, _("Key Generation Wizard")); |
439 |
twoaday |
105 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
440 |
werner |
36 |
SetForegroundWindow (dlg); |
441 |
|
|
center_window (dlg, NULL); |
442 |
|
|
break; |
443 |
twoaday |
328 |
|
444 |
|
|
case WM_DESTROY: |
445 |
|
|
balloon_msg_disable (); |
446 |
|
|
break; |
447 |
|
|
|
448 |
|
|
case WM_COMMAND: |
449 |
twoaday |
204 |
switch (LOWORD( wparam)) { |
450 |
werner |
36 |
case IDOK: |
451 |
twoaday |
328 |
balloon_msg_disable (); |
452 |
twoaday |
204 |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYWIZARD_NAME, &utf8_name)) { |
453 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYWIZARD_NAME), |
454 |
|
|
_("Please enter the name."), IDI_ERROR); |
455 |
werner |
36 |
return FALSE; |
456 |
|
|
} |
457 |
twoaday |
204 |
if (strchr (utf8_name, '@')) { |
458 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYWIZARD_NAME), |
459 |
|
|
_("Please do not enter the email address in the name field."), |
460 |
|
|
IDI_WARNING); |
461 |
twoaday |
204 |
free_if_alloc (utf8_name); |
462 |
werner |
36 |
return FALSE; |
463 |
|
|
} |
464 |
twoaday |
344 |
if (!GetDlgItemText (dlg, IDC_KEYWIZARD_EMAIL, email, DIM (email)-1) || |
465 |
|
|
check_email_address (email)) { |
466 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYWIZARD_EMAIL), |
467 |
|
|
_("Please enter a valid email address."), |
468 |
|
|
IDI_ERROR); |
469 |
twoaday |
204 |
free_if_alloc (utf8_name); |
470 |
werner |
36 |
return FALSE; |
471 |
|
|
} |
472 |
|
|
if (strchr (email, '<') || strchr (email, '>')) { |
473 |
twoaday |
328 |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYWIZARD_EMAIL), |
474 |
|
|
_("Please do not add '<' or '>' to the email address."), |
475 |
|
|
IDI_WARNING); |
476 |
twoaday |
204 |
free_if_alloc (utf8_name); |
477 |
werner |
36 |
return FALSE; |
478 |
|
|
} |
479 |
twoaday |
314 |
|
480 |
|
|
/* We don't allow empty passphrases during key generation. */ |
481 |
|
|
pass = request_passphrase2 (_("Key Generation"), |
482 |
|
|
PASSDLG_STRICT|PASSDLG_WARN_UTF8|PASSDLG_NOTEMPTY, &cancel); |
483 |
twoaday |
204 |
if (cancel) { |
484 |
|
|
free_if_alloc (utf8_name); |
485 |
werner |
36 |
return FALSE; |
486 |
twoaday |
204 |
} |
487 |
twoaday |
328 |
if (IsDlgButtonChecked (dlg, IDC_KEYWIZARD_USEOTHERPK)) |
488 |
twoaday |
344 |
pubkey_algo = GPG_KEYGEN_DSA_ELG; |
489 |
|
|
else |
490 |
|
|
pubkey_algo = GPG_KEYGEN_RSA_RSA; |
491 |
werner |
36 |
p = gpg_genkey_params (pubkey_algo, DFAULT_KEYSIZE, utf8_name, |
492 |
twoaday |
314 |
NULL, email, NULL, pass); |
493 |
twoaday |
201 |
free_if_alloc (utf8_name); |
494 |
werner |
36 |
keygen_cb_dlg_create(); |
495 |
|
|
err = gpg_genkey (p, keygen_cb, &fpr); |
496 |
twoaday |
211 |
keygen_cb_dlg_destroy (1); |
497 |
twoaday |
225 |
sfree_if_alloc (p); |
498 |
werner |
36 |
sfree_if_alloc (pass); |
499 |
twoaday |
201 |
if (err) { |
500 |
twoaday |
314 |
msg_box (dlg, gpgme_strerror (err), |
501 |
|
|
_("Key Generation Wizard"), MB_ERR); |
502 |
twoaday |
201 |
free_if_alloc (fpr); |
503 |
werner |
36 |
return FALSE; |
504 |
|
|
} |
505 |
twoaday |
204 |
status_box (dlg, _("Key Generation completed"), _("GnuPG Status")); |
506 |
werner |
36 |
keycache_update (0, fpr); |
507 |
|
|
keycache_update (1, fpr); |
508 |
twoaday |
201 |
free_if_alloc (fpr); |
509 |
twoaday |
150 |
|
510 |
werner |
36 |
backup_keyrings (dlg); |
511 |
twoaday |
314 |
if (ctx != NULL) |
512 |
twoaday |
256 |
ctx->cancel = 0; |
513 |
werner |
36 |
EndDialog (dlg, TRUE); |
514 |
|
|
break; |
515 |
|
|
|
516 |
|
|
case IDCANCEL: |
517 |
twoaday |
314 |
if (ctx != NULL) |
518 |
twoaday |
150 |
ctx->cancel = 1; |
519 |
|
|
EndDialog (dlg, FALSE); |
520 |
werner |
36 |
break; |
521 |
|
|
} |
522 |
|
|
break; |
523 |
|
|
} |
524 |
|
|
return FALSE; |
525 |
|
|
} |