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