137 |
} |
} |
138 |
|
|
139 |
|
|
|
/* Check if the selected key is protected and en- or disable the |
|
|
passphrase control. */ |
|
|
static void |
|
|
do_check_protection (HWND dlg) |
|
|
{ |
|
|
gpgme_key_t key; |
|
|
struct winpt_key_s k; |
|
|
int idx, protec; |
|
|
|
|
|
idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0); |
|
|
key = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
|
|
CB_GETITEMDATA, (WPARAM)idx, 0); |
|
|
if (!key) |
|
|
return; |
|
|
if (winpt_get_seckey (key->subkeys->keyid, &k)) |
|
|
BUG (0); |
|
|
protec = k.is_protected; |
|
|
if (!protec) |
|
|
protec = k.ext->gloflags.divert_to_card; |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), |
|
|
protec? TRUE : FALSE); |
|
|
} |
|
|
|
|
140 |
|
|
141 |
/* Dialog box procedure to choose the signature class. */ |
/* Dialog box procedure to choose the signature class. */ |
142 |
BOOL CALLBACK |
BOOL CALLBACK |
222 |
|
|
223 |
/* Display all needed information about the key @key in the dialog @dlg. */ |
/* Display all needed information about the key @key in the dialog @dlg. */ |
224 |
static void |
static void |
225 |
display_keyinfo (HWND dlg, winpt_key_t key) |
display_keyinfo (HWND dlg, listview_ctrl_t list, winpt_key_t key) |
226 |
{ |
{ |
227 |
StringBuffer kinf; |
StringBuffer kinf; |
228 |
struct native_uid_s *u; |
struct native_uid_s *u; |
229 |
char tmp[256]; |
char tmp[256]; |
|
int len; |
|
230 |
|
|
231 |
_snprintf (tmp, DIM (tmp) -1, |
_snprintf (tmp, DIM (tmp) -1, |
232 |
_("pub %d/0x%s created: %s expires: %s\n\n" |
_("pub %d/0x%s created: %s expires: %s\n\n" |
236 |
get_key_created (key->ctx->subkeys->timestamp), |
get_key_created (key->ctx->subkeys->timestamp), |
237 |
get_expire_date (key->ctx), |
get_expire_date (key->ctx), |
238 |
get_printable_fpr (key->ctx->subkeys->fpr)); |
get_printable_fpr (key->ctx->subkeys->fpr)); |
239 |
kinf = tmp; |
kinf = tmp; |
240 |
for (len=0, u = key->ext->uids; u; u = u->next) { |
SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, kinf.getBuffer ()); |
241 |
|
|
242 |
|
for (u = key->ext->uids; u; u = u->next) { |
243 |
if (u->revoked) |
if (u->revoked) |
244 |
continue; |
continue; |
245 |
if (len++ > 2) |
listview_add_item (list, ""); |
246 |
break; |
listview_add_sub_item (list, 0, 0, u->name); |
247 |
kinf = kinf + " \""; |
listview_add_sub_item (list, 0, 1, u->email); |
|
if (strlen (u->uid) > 128) { |
|
|
kinf.add (u->uid, 128); |
|
|
kinf += "..."; |
|
|
// FIXME: make sure at least the e-mail address will be shown! |
|
|
} |
|
|
else |
|
|
kinf += u->uid; |
|
|
kinf += "\"\n"; |
|
248 |
} |
} |
|
SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, kinf.getBuffer ()); |
|
249 |
} |
} |
250 |
|
|
251 |
|
|
295 |
else |
else |
296 |
expires = 1; |
expires = 1; |
297 |
_snprintf (keymsg, DIM (keymsg)-1, "%04d-%02d-%02d", |
_snprintf (keymsg, DIM (keymsg)-1, "%04d-%02d-%02d", |
298 |
st.wYear, st.wMonth, st.wDay); |
st.wYear, st.wMonth, st.wDay); |
299 |
} |
} |
300 |
|
|
301 |
assert (key->ctx->subkeys->keyid != NULL); /* should be always true. */ |
if (key->ctx->subkeys->keyid == NULL) |
302 |
|
BUG (0); /* should be always true. */ |
303 |
ke.setKeyID (key->ctx->subkeys->keyid); |
ke.setKeyID (key->ctx->subkeys->keyid); |
304 |
|
|
|
// XXX: callback hangs after bad passphrase |
|
305 |
passphrase_cb_s cb; |
passphrase_cb_s cb; |
306 |
set_gpg_auto_passphrase_cb (&cb, _("Key Edit")); |
set_gpg_auto_passphrase_cb (&cb, _("Key Edit")); |
307 |
ke.setPassphraseCallback (passphrase_cb, (void*)&cb); |
ke.setPassphraseCallback (passphrase_cb, (void*)&cb); |
308 |
|
|
309 |
HWND klist = GetDlgItem (dlg, IDC_KEYSIGN_KEYLIST); |
HWND klist = GetDlgItem (dlg, IDC_KEYSIGN_KEYLIST); |
310 |
idx = SendMessage (klist, CB_GETCURSEL, 0, 0); |
idx = SendMessage (klist, CB_GETCURSEL, 0, 0); |
311 |
k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
k = (gpgme_key_t)SendMessage (klist, CB_GETITEMDATA, (WPARAM)idx, 0); |
|
CB_GETITEMDATA, (WPARAM)idx, 0); |
|
312 |
if (k != NULL) |
if (k != NULL) |
313 |
ke.setLocalUser (k); |
ke.setLocalUser (k); |
314 |
|
|
315 |
err = ke.signKey (type, sig_class, expires? keymsg : "0"); |
err = ke.signKey (type, sig_class, expires? keymsg : "0"); |
316 |
release_gpg_passphrase_cb (&cb); |
release_gpg_passphrase_cb (&cb); |
317 |
if (err) { |
if (cb.cancel) |
318 |
|
return TRUE; |
319 |
|
else if (err) { |
320 |
msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR); |
321 |
return TRUE; |
return TRUE; |
322 |
} |
} |
323 |
else if (ke.getResult () != 0) { |
else if (ke.getResult () != 0) { |
324 |
show_balloon_msg (klist, _("This key is already signed by your key"), |
show_balloon_msg (klist, _("This key is already signed by your key"), |
325 |
IDI_INFORMATION); |
IDI_INFORMATION); |
326 |
return TRUE; |
return TRUE; |
327 |
} |
} |
328 |
else { |
else { |
329 |
status_box (dlg, _("Key successfully signed."), _("Key Signing")); |
status_box (dlg, _("Key successfully signed."), _("Key Signing")); |
330 |
key->update = 1; |
key->update = 1; |
331 |
} |
} |
332 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
333 |
return TRUE; |
return TRUE; |
334 |
} |
} |
335 |
|
|
336 |
|
|
337 |
|
static listview_ctrl_t |
338 |
|
init_uidlist (HWND dlg) |
339 |
|
{ |
340 |
|
struct listview_column_s cols[] = { |
341 |
|
{0, 190, (char *)_("Name")}, |
342 |
|
{1, 150, (char *)_("E-Mail")}}; |
343 |
|
|
344 |
|
listview_ctrl_t list; |
345 |
|
listview_new (&list, GetDlgItem (dlg, IDC_KEYSIGN_UIDLIST)); |
346 |
|
listview_add_column (list, &cols[0]); |
347 |
|
listview_add_column (list, &cols[1]); |
348 |
|
return list; |
349 |
|
} |
350 |
|
|
351 |
|
|
352 |
/* Dialog box procedure to sign a key. */ |
/* Dialog box procedure to sign a key. */ |
353 |
BOOL CALLBACK |
BOOL CALLBACK |
354 |
keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
355 |
{ |
{ |
356 |
static winpt_key_t key; |
static winpt_key_t key; |
357 |
|
static listview_ctrl_t list; |
358 |
char buf[MAX_PATH+128+1]; |
char buf[MAX_PATH+128+1]; |
359 |
const char *s; |
const char *s; |
360 |
|
|
369 |
_("Key Signing"), MB_ERR); |
_("Key Signing"), MB_ERR); |
370 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
371 |
return TRUE; |
return TRUE; |
372 |
} |
} |
373 |
display_keyinfo (dlg, key); |
list = init_uidlist (dlg); |
374 |
|
display_keyinfo (dlg, list, key); |
375 |
SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)")); |
SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)")); |
376 |
SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on")); |
SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on")); |
377 |
SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably")); |
SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably")); |
402 |
get_photo_tmpname (key->ctx, buf, DIM(buf)-1); |
get_photo_tmpname (key->ctx, buf, DIM(buf)-1); |
403 |
DeleteFile (buf); |
DeleteFile (buf); |
404 |
} |
} |
405 |
|
if (list != NULL) { |
406 |
|
listview_release (list); |
407 |
|
list = NULL; |
408 |
|
} |
409 |
break; |
break; |
410 |
|
|
411 |
case WM_PAINT: |
case WM_PAINT: |