1 |
werner |
36 |
/* wptKeysignDlg.cpp - Key signing dialog |
2 |
twoaday |
170 |
* Copyright (C) 2001-2006 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 |
|
|
* 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 |
werner |
42 |
#ifdef HAVE_CONFIG_H |
21 |
|
|
#include <config.h> |
22 |
|
|
#endif |
23 |
|
|
|
24 |
werner |
36 |
#include <windows.h> |
25 |
|
|
#include <commctrl.h> |
26 |
twoaday |
181 |
#include <time.h> |
27 |
werner |
36 |
|
28 |
werner |
47 |
#include "resource.h" |
29 |
werner |
36 |
#include "wptGPG.h" |
30 |
|
|
#include "wptNLS.h" |
31 |
|
|
#include "wptW32API.h" |
32 |
|
|
#include "wptVersion.h" |
33 |
|
|
#include "wptTypes.h" |
34 |
|
|
#include "wptErrors.h" |
35 |
|
|
#include "wptCommonCtl.h" |
36 |
|
|
#include "wptContext.h" |
37 |
|
|
#include "wptDlgs.h" |
38 |
|
|
#include "wptUTF8.h" |
39 |
|
|
#include "wptRegistry.h" |
40 |
werner |
47 |
#include "wptKeylist.h" |
41 |
werner |
36 |
#include "wptKeyEdit.h" |
42 |
|
|
|
43 |
|
|
|
44 |
twoaday |
226 |
void key_unload_photo (HWND dlg); |
45 |
|
|
int key_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid); |
46 |
|
|
const char* get_photo_tmpname (HWND dlg); |
47 |
|
|
|
48 |
werner |
36 |
/* Return a beautified printable fingerprint of @fpr. */ |
49 |
|
|
static const char* |
50 |
|
|
get_printable_fpr (const char *fpr) |
51 |
|
|
{ |
52 |
twoaday |
225 |
static char pfpr[64]; |
53 |
werner |
36 |
int pos = 0; |
54 |
|
|
size_t i; |
55 |
|
|
|
56 |
|
|
for (i = 0; i < strlen (fpr); i += 4) { |
57 |
|
|
pfpr[pos++] = fpr[i]; |
58 |
|
|
pfpr[pos++] = fpr[i+1]; |
59 |
|
|
pfpr[pos++] = fpr[i+2]; |
60 |
|
|
pfpr[pos++] = fpr[i+3]; |
61 |
|
|
pfpr[pos++] = ' '; |
62 |
|
|
} |
63 |
|
|
return pfpr; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
/* Return human friendly information about the key @key. */ |
68 |
twoaday |
225 |
const char* |
69 |
werner |
36 |
get_keyinfo (gpgme_key_t key) |
70 |
|
|
{ |
71 |
|
|
static char buf[64+16]; |
72 |
|
|
struct winpt_key_s k; |
73 |
|
|
|
74 |
|
|
memset (&k, 0, sizeof (k)); |
75 |
twoaday |
225 |
if (winpt_get_seckey (key->subkeys->keyid, &k)) |
76 |
|
|
BUG (0); |
77 |
|
|
_snprintf (buf, DIM (buf)-1-16, _("%d-bit %s key, ID 0x%s"), |
78 |
|
|
key->subkeys->length, |
79 |
|
|
get_key_pubalgo (key->subkeys->pubkey_algo), |
80 |
|
|
key->subkeys->keyid+8); |
81 |
werner |
36 |
if (k.ext->gloflags.divert_to_card) |
82 |
|
|
strcat (buf, " (Card)"); |
83 |
|
|
return buf; |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
|
87 |
|
|
/* Fill the secret key combo-box with all entries from the cache. |
88 |
|
|
@dlg is the handle to the combo-box. @keyid show which key to skip. |
89 |
|
|
Return value: 0 on success. */ |
90 |
|
|
static int |
91 |
|
|
do_fill_seckeylist (HWND dlg, const char *keyid) |
92 |
|
|
{ |
93 |
|
|
gpg_keycache_t sec; |
94 |
twoaday |
167 |
gpgme_key_t pk, defkey; |
95 |
twoaday |
225 |
const char *s, *inf; |
96 |
twoaday |
167 |
char *uid, *p; |
97 |
|
|
int i = 0, n = 0, curr_sel = 0; |
98 |
twoaday |
225 |
int len = 0; |
99 |
werner |
36 |
|
100 |
|
|
sec = keycache_get_ctx (0); |
101 |
twoaday |
167 |
gpg_keycache_get_default_key (sec, &defkey); |
102 |
werner |
36 |
gpg_keycache_rewind (sec); |
103 |
|
|
while (!gpg_keycache_next_key (sec, 1, &pk)) { |
104 |
|
|
if (!pk) |
105 |
|
|
continue; |
106 |
|
|
s = pk->subkeys->keyid; |
107 |
|
|
if (!strcmp (s, keyid)) |
108 |
|
|
continue; |
109 |
|
|
/* skip all ElGamal sign+encrypt keys */ |
110 |
|
|
if (pk->subkeys->pubkey_algo == GPGME_PK_ELG) |
111 |
|
|
continue; |
112 |
|
|
/* make sure the public key is okay not: revoked, expired or disabled. */ |
113 |
|
|
if (pk->expired ||pk->revoked || pk->disabled) |
114 |
|
|
continue; |
115 |
|
|
s = pk->uids->name; |
116 |
|
|
if (!s) |
117 |
|
|
continue; |
118 |
twoaday |
167 |
if (defkey && !strcmp (defkey->subkeys->keyid, pk->subkeys->keyid)) |
119 |
|
|
curr_sel = i; |
120 |
twoaday |
187 |
uid = utf8_to_native (s); |
121 |
twoaday |
225 |
inf = get_keyinfo (pk); |
122 |
|
|
len = strlen (uid) + strlen (inf) + 8; |
123 |
|
|
p = new char[len+1]; |
124 |
werner |
36 |
if (!p) |
125 |
|
|
BUG (NULL); |
126 |
twoaday |
225 |
_snprintf (p, len, "%s (%s)", uid, inf); |
127 |
twoaday |
167 |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
128 |
|
|
CB_ADDSTRING, i, (LPARAM)(char *)p); |
129 |
|
|
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
130 |
|
|
CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk); |
131 |
werner |
36 |
free_if_alloc (p); |
132 |
twoaday |
225 |
safe_free (uid); |
133 |
werner |
36 |
n++; |
134 |
|
|
} |
135 |
twoaday |
167 |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
136 |
|
|
CB_SETCURSEL, (WPARAM)curr_sel, 0); |
137 |
werner |
36 |
if (!n) |
138 |
|
|
return -1; |
139 |
|
|
return 0; |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
|
143 |
|
|
/* Check if the selected key is protected and en- or disable the |
144 |
|
|
passphrase control. */ |
145 |
|
|
static void |
146 |
|
|
do_check_protection (HWND dlg) |
147 |
|
|
{ |
148 |
|
|
gpgme_key_t key; |
149 |
|
|
struct winpt_key_s k; |
150 |
twoaday |
212 |
int idx, protec; |
151 |
werner |
36 |
|
152 |
twoaday |
212 |
idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0); |
153 |
|
|
key = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
154 |
|
|
CB_GETITEMDATA, (WPARAM)idx, 0); |
155 |
werner |
36 |
if (key) { |
156 |
twoaday |
225 |
if (winpt_get_seckey (key->subkeys->keyid, &k)) |
157 |
|
|
BUG (0); |
158 |
werner |
36 |
protec = k.is_protected; |
159 |
|
|
if (!protec) |
160 |
|
|
protec = k.ext->gloflags.divert_to_card; |
161 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), protec? TRUE : FALSE); |
162 |
|
|
} |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
|
166 |
twoaday |
226 |
/* Show the photographic ID of the key in a separate dialog window. */ |
167 |
|
|
BOOL CALLBACK |
168 |
|
|
showphoto_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
169 |
|
|
{ |
170 |
|
|
static winpt_key_t key; |
171 |
|
|
char buf[100]; |
172 |
|
|
|
173 |
|
|
switch (msg) { |
174 |
|
|
case WM_INITDIALOG: |
175 |
|
|
key = (winpt_key_t)lparam; |
176 |
|
|
if (!key) |
177 |
|
|
BUG (0); |
178 |
|
|
key_load_photo (dlg, key->ctx, NULL); |
179 |
|
|
_snprintf (buf, sizeof (buf)-1, _("Photo of %s"), key->uid); |
180 |
|
|
SetWindowText (dlg, buf); |
181 |
|
|
SetForegroundWindow (dlg); |
182 |
|
|
break; |
183 |
|
|
|
184 |
|
|
case WM_PAINT: |
185 |
|
|
if (key->ext && key->ext->attrib.len > 0) { |
186 |
|
|
POINT p; |
187 |
|
|
p.x = p.y = 0; |
188 |
|
|
PTD_jpg_show (GetDlgItem (dlg, IDC_SHOWPHOTO_IMG), |
189 |
|
|
&p, get_photo_tmpname (dlg)); |
190 |
|
|
} |
191 |
|
|
break; |
192 |
|
|
|
193 |
|
|
case WM_DESTROY: |
194 |
|
|
key_unload_photo (dlg); |
195 |
|
|
break; |
196 |
|
|
|
197 |
|
|
case WM_COMMAND: |
198 |
|
|
switch (LOWORD (wparam)) { |
199 |
|
|
case IDCANCEL: |
200 |
|
|
case IDOK: |
201 |
|
|
EndDialog (dlg, TRUE); |
202 |
|
|
break; |
203 |
|
|
} |
204 |
|
|
break; |
205 |
|
|
} |
206 |
|
|
|
207 |
|
|
return FALSE; |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
|
211 |
werner |
36 |
/* Dialog box procedure to choose the signature class. */ |
212 |
|
|
BOOL CALLBACK |
213 |
|
|
sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
214 |
|
|
{ |
215 |
twoaday |
170 |
int sig_class = 0; |
216 |
|
|
|
217 |
werner |
36 |
switch (msg) { |
218 |
|
|
case WM_INITDIALOG: |
219 |
|
|
SetWindowText (dlg, _("Choose Signature Class")); |
220 |
twoaday |
225 |
SetDlgItemText (dlg, IDC_SIGCLASS_TITLEINF, |
221 |
|
|
_("How carefully have you verified the key you are about to sign actually belongs to the person? If you don't know what to anwser, use \"0\".")); |
222 |
|
|
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, |
223 |
|
|
_("(0) I will not answer (default)")); |
224 |
|
|
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, |
225 |
|
|
_("(1) I have not checked at all.")); |
226 |
|
|
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, |
227 |
|
|
_("(2) I have done causal checking.")); |
228 |
|
|
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, |
229 |
|
|
_("(3) I have done very careful checkings.")); |
230 |
werner |
36 |
CheckDlgButton (dlg, IDC_SIGCLASS_CLASS0, BST_CHECKED); |
231 |
|
|
SetForegroundWindow (dlg); |
232 |
|
|
center_window (dlg, NULL); |
233 |
|
|
return TRUE; |
234 |
|
|
|
235 |
|
|
case WM_COMMAND: |
236 |
twoaday |
170 |
switch (LOWORD (wparam)) { |
237 |
werner |
36 |
case IDOK: |
238 |
|
|
if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0)) |
239 |
twoaday |
170 |
sig_class = 0; |
240 |
werner |
36 |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1)) |
241 |
twoaday |
170 |
sig_class = 1; |
242 |
werner |
36 |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2)) |
243 |
twoaday |
170 |
sig_class = 2; |
244 |
werner |
36 |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3)) |
245 |
twoaday |
170 |
sig_class = 3; |
246 |
werner |
36 |
else |
247 |
twoaday |
170 |
sig_class = 0; |
248 |
|
|
EndDialog (dlg, sig_class); |
249 |
werner |
36 |
return TRUE; |
250 |
twoaday |
170 |
|
251 |
|
|
case IDCANCEL: |
252 |
|
|
EndDialog (dlg, 0); |
253 |
|
|
return TRUE; |
254 |
werner |
36 |
} |
255 |
|
|
break; |
256 |
|
|
} |
257 |
|
|
|
258 |
|
|
return FALSE; |
259 |
|
|
} |
260 |
|
|
|
261 |
|
|
|
262 |
|
|
/* Return the humand friendly expiration date of @key. */ |
263 |
|
|
static const char* |
264 |
|
|
get_expire_date (gpgme_key_t key) |
265 |
|
|
{ |
266 |
|
|
u32 u = key->subkeys->expires; |
267 |
|
|
if (!u) |
268 |
|
|
return _("never"); |
269 |
|
|
return get_key_expire_date (u); |
270 |
|
|
} |
271 |
|
|
|
272 |
twoaday |
225 |
|
273 |
twoaday |
181 |
/* Check if the given system time @st points to today. */ |
274 |
|
|
static int |
275 |
|
|
date_is_today (SYSTEMTIME *st) |
276 |
|
|
{ |
277 |
|
|
time_t t; |
278 |
|
|
struct tm *tm; |
279 |
|
|
|
280 |
|
|
t = time (NULL); |
281 |
|
|
tm = localtime (&t); |
282 |
|
|
if (st->wDay == tm->tm_mday && |
283 |
|
|
st->wYear == tm->tm_year+1900 && |
284 |
|
|
st->wMonth == tm->tm_mon+1) |
285 |
|
|
return -1; |
286 |
|
|
return 0; |
287 |
|
|
} |
288 |
|
|
|
289 |
|
|
|
290 |
werner |
36 |
/* Dialog box procedure to sign a key. */ |
291 |
|
|
BOOL CALLBACK |
292 |
|
|
keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
293 |
|
|
{ |
294 |
|
|
static winpt_key_t key; |
295 |
|
|
GpgKeyEdit *ke; |
296 |
|
|
gpgme_error_t err; |
297 |
|
|
gpgme_key_t k; |
298 |
|
|
SYSTEMTIME st; |
299 |
|
|
HWND h; |
300 |
|
|
char keymsg[2048], pwd[256]; |
301 |
|
|
const char *keyid, *s; |
302 |
|
|
int type, expires=0, idx; |
303 |
twoaday |
170 |
int sig_class = 0; |
304 |
werner |
36 |
|
305 |
twoaday |
177 |
switch (msg) { |
306 |
werner |
36 |
case WM_INITDIALOG: |
307 |
|
|
key = (winpt_key_t) lparam; |
308 |
twoaday |
225 |
if (!key) |
309 |
|
|
BUG (0); |
310 |
werner |
36 |
_snprintf (keymsg, sizeof keymsg -1, |
311 |
|
|
_("pub %d/%s created: %s expires: %s\n\n" |
312 |
|
|
"Primary key fingerprint: %s\n\n" |
313 |
|
|
"\t%s\n\n" |
314 |
|
|
"\nAre you really sure that you want to sign this key with YOUR key?\n"), |
315 |
|
|
key->ctx->subkeys->length, |
316 |
|
|
key->ctx->subkeys->keyid+8, |
317 |
|
|
get_key_created (key->ctx->subkeys->timestamp), |
318 |
|
|
get_expire_date (key->ctx), |
319 |
|
|
get_printable_fpr (key->ctx->subkeys->fpr), |
320 |
twoaday |
205 |
key->ext->uids->uid); |
321 |
werner |
36 |
s = key->ctx->subkeys->keyid; |
322 |
|
|
if (do_fill_seckeylist (dlg, s)) { |
323 |
|
|
msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR); |
324 |
|
|
EndDialog (dlg, FALSE); |
325 |
twoaday |
225 |
return TRUE; |
326 |
werner |
36 |
} |
327 |
twoaday |
176 |
do_check_protection (dlg); |
328 |
twoaday |
205 |
SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg); |
329 |
werner |
36 |
SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)")); |
330 |
|
|
SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on")); |
331 |
|
|
SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably")); |
332 |
|
|
SetDlgItemText (dlg, IDC_KEYSIGN_ASKLEVEL, _("&Ask for certification level")); |
333 |
|
|
SetDlgItemText (dlg, IDC_KEYSIGN_PWDINF, _("Passphrase")); |
334 |
twoaday |
88 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
335 |
|
|
SetDlgItemText (dlg, IDC_KEYSIGN_SHOWIMG, _("&Show photo")); |
336 |
twoaday |
178 |
SetDlgItemText (dlg, IDC_KEYSIGN_HIDE, _("&Hide Typing")); |
337 |
twoaday |
225 |
SetWindowText (dlg, _("Key Signing")); |
338 |
werner |
36 |
CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED); |
339 |
|
|
CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED); |
340 |
|
|
CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED); |
341 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE); |
342 |
|
|
if (reg_prefs.expert == 0) |
343 |
|
|
ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE); |
344 |
|
|
if (key->ext && key->ext->attrib.len > 0) |
345 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_SHOWIMG), TRUE); |
346 |
twoaday |
41 |
if (!reg_prefs.gpg.ask_cert_level) |
347 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_ASKLEVEL), FALSE); |
348 |
twoaday |
181 |
if (!reg_prefs.gpg.ask_cert_expire) |
349 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPSIG), FALSE); |
350 |
twoaday |
177 |
CheckDlgButton (dlg, IDC_KEYSIGN_HIDE, BST_CHECKED); |
351 |
werner |
36 |
SetForegroundWindow (dlg); |
352 |
|
|
h = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE); |
353 |
|
|
SetFocus (h); |
354 |
|
|
return FALSE; |
355 |
|
|
|
356 |
|
|
case WM_COMMAND: |
357 |
twoaday |
176 |
if (HIWORD (wparam) == CBN_SELCHANGE) { |
358 |
werner |
36 |
do_check_protection (dlg); |
359 |
|
|
break; |
360 |
|
|
} |
361 |
twoaday |
177 |
if (HIWORD (wparam) == BN_CLICKED && |
362 |
|
|
LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) { |
363 |
werner |
36 |
int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG); |
364 |
twoaday |
225 |
|
365 |
werner |
36 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE); |
366 |
|
|
} |
367 |
twoaday |
177 |
if (HIWORD (wparam) == BN_CLICKED && |
368 |
|
|
LOWORD (wparam) == IDC_KEYSIGN_HIDE) { |
369 |
|
|
HWND hwnd = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE); |
370 |
|
|
int hide = IsDlgButtonChecked (dlg, IDC_KEYSIGN_HIDE); |
371 |
twoaday |
225 |
|
372 |
twoaday |
177 |
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
373 |
|
|
SetFocus (hwnd); |
374 |
|
|
} |
375 |
werner |
36 |
|
376 |
twoaday |
170 |
switch (LOWORD (wparam)) { |
377 |
werner |
36 |
case IDOK: |
378 |
|
|
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL)) |
379 |
twoaday |
225 |
sig_class = dialog_box_param (glob_hinst, |
380 |
twoaday |
170 |
(LPCSTR)IDD_WINPT_SIGCLASS, dlg, |
381 |
|
|
sig_class_dlg_proc, (LPARAM)NULL, |
382 |
|
|
_("Choose Signature Class"), |
383 |
|
|
IDS_WINPT_SIGCLASS); |
384 |
werner |
36 |
type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL); |
385 |
|
|
if (type) |
386 |
|
|
type = GPG_EDITKEY_LSIGN; |
387 |
|
|
else |
388 |
|
|
type = GPG_EDITKEY_SIGN; |
389 |
|
|
|
390 |
|
|
if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) { |
391 |
|
|
type = GPG_EDITKEY_NRSIGN; |
392 |
|
|
if (type == GPG_EDITKEY_LSIGN) |
393 |
|
|
type = GPG_EDITKEY_NRLSIGN; |
394 |
|
|
} |
395 |
|
|
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) { |
396 |
|
|
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st); |
397 |
twoaday |
181 |
if (date_is_today (&st)) { |
398 |
|
|
msg_box (dlg, _("You cannot select today as the expiration date."), |
399 |
|
|
_("Key Signing"), MB_INFO); |
400 |
|
|
return TRUE; |
401 |
|
|
} |
402 |
|
|
else |
403 |
|
|
expires = 1; |
404 |
werner |
36 |
sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); |
405 |
|
|
} |
406 |
|
|
|
407 |
|
|
/* XXX: check for --ask-cert-level and --ask-cert-expire in the gpg.conf |
408 |
|
|
if an advanced button is checked and offer to add it to the config |
409 |
|
|
file. */ |
410 |
|
|
|
411 |
twoaday |
225 |
GetDlgItemText (dlg, IDC_KEYSIGN_PASSPHRASE, pwd, DIM (pwd)-1); |
412 |
werner |
36 |
keyid = key->ctx->subkeys->keyid; |
413 |
twoaday |
225 |
if (!keyid) { |
414 |
|
|
wipememory (pwd, sizeof (pwd)); |
415 |
|
|
msg_box (dlg, _("Could not get Key ID from key."), _("Key Signing"), MB_ERR); |
416 |
werner |
36 |
return TRUE; |
417 |
|
|
} |
418 |
|
|
ke = new GpgKeyEdit (keyid); |
419 |
|
|
if (!ke) |
420 |
|
|
BUG (NULL); |
421 |
|
|
ke->setPassphrase (pwd); |
422 |
|
|
idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0); |
423 |
|
|
k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
424 |
|
|
CB_GETITEMDATA, (WPARAM)idx, 0); |
425 |
|
|
if (k) |
426 |
|
|
ke->setLocalUser (k); |
427 |
|
|
|
428 |
twoaday |
170 |
err = ke->signKey (type, sig_class, expires? keymsg : "0"); |
429 |
twoaday |
129 |
wipememory (pwd, sizeof (pwd)); |
430 |
werner |
36 |
if (err) { |
431 |
|
|
delete ke; |
432 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR); |
433 |
|
|
return TRUE; |
434 |
|
|
} |
435 |
twoaday |
225 |
if (ke->getResult () != 0) { |
436 |
twoaday |
129 |
msg_box (dlg, _("This key is already signed by your key"), |
437 |
|
|
_("Key Signing"), MB_INFO); |
438 |
twoaday |
225 |
delete ke; |
439 |
|
|
return TRUE; |
440 |
|
|
} |
441 |
werner |
36 |
else { |
442 |
twoaday |
170 |
status_box (dlg, _("Key successfully signed."), _("Key Signing")); |
443 |
werner |
36 |
key->update = 1; |
444 |
|
|
} |
445 |
|
|
delete ke; |
446 |
|
|
EndDialog (dlg, TRUE); |
447 |
|
|
return TRUE; |
448 |
|
|
|
449 |
|
|
case IDCANCEL: |
450 |
|
|
EndDialog (dlg, FALSE); |
451 |
|
|
return TRUE; |
452 |
|
|
|
453 |
|
|
case IDC_KEYSIGN_SHOWIMG: |
454 |
twoaday |
226 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SHOWPHOTO, |
455 |
|
|
dlg, showphoto_dlg_proc, (LPARAM)key); |
456 |
werner |
36 |
return TRUE; |
457 |
|
|
} |
458 |
|
|
break; |
459 |
|
|
} |
460 |
|
|
|
461 |
|
|
return FALSE; |
462 |
|
|
} |