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