1 |
/* wptKeyEditDlgs.cpp - GPG key edit dialogs |
/* wptKeyEditDlgs.cpp - GPG key edit dialogs |
2 |
* Copyright (C) 2002-2005 Timo Schulz |
* Copyright (C) 2002-2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
47 |
CMD_ADDUID, |
CMD_ADDUID, |
48 |
CMD_ADDPHOTO, |
CMD_ADDPHOTO, |
49 |
CMD_ADDREVOKER, |
CMD_ADDREVOKER, |
|
/*CMD_FPR,*/ |
|
50 |
CMD_DELUID, |
CMD_DELUID, |
51 |
CMD_DELKEY, |
CMD_DELKEY, |
|
CMD_DELPHOTO, |
|
|
/*CMD_DELSIG,*/ |
|
52 |
CMD_EXPIRE, |
CMD_EXPIRE, |
|
/*CMD_PREF,*/ |
|
53 |
CMD_SHOWPREF, |
CMD_SHOWPREF, |
54 |
/*CMD_SETPREF,*/ |
//CMD_SETPREF, |
|
/*CMD_UPDPREF,*/ |
|
55 |
CMD_PASSWD, |
CMD_PASSWD, |
56 |
CMD_PRIMARY, |
CMD_PRIMARY, |
57 |
CMD_TRUST, |
CMD_TRUST, |
|
/*CMD_REVSIG,*/ |
|
58 |
CMD_REVUID, |
CMD_REVUID, |
59 |
CMD_REVKEY, |
CMD_REVKEY, |
60 |
CMD_DISABLE, |
CMD_DISABLE, |
61 |
CMD_ENABLE, |
CMD_ENABLE, |
62 |
/*CMD_SHOWPHOTO,*/ |
CMD_SIGN, |
63 |
|
CMD_LSIGN, |
64 |
|
CMD_CHECK |
65 |
|
}; |
66 |
|
|
67 |
|
struct cmdlist_s { |
68 |
|
const char *name; |
69 |
|
unsigned int need_pair:1; |
70 |
|
int id; |
71 |
|
} cmdlist[] = { |
72 |
|
{"ADDKEY", 1, CMD_ADDKEY}, |
73 |
|
{"ADDUID", 1, CMD_ADDUID}, |
74 |
|
{"ADDPHOTO", 1, CMD_ADDPHOTO}, |
75 |
|
{"ADDREVOKER", 1, CMD_ADDREVOKER}, |
76 |
|
{"DELUID", 1, CMD_DELUID}, |
77 |
|
{"DELKEY", 1, CMD_DELKEY}, |
78 |
|
{"EXPIRE", 1, CMD_EXPIRE}, |
79 |
|
{"SHOWPREF", 0, CMD_SHOWPREF}, |
80 |
|
/*{"SETPREF", 1, CMD_SETPREF},*/ |
81 |
|
{"PASSWD", 1, CMD_PASSWD}, |
82 |
|
{"PRIMARY", 1, CMD_PRIMARY}, |
83 |
|
{"TRUST", 0, CMD_TRUST}, |
84 |
|
{"REVUID", 1, CMD_REVUID}, |
85 |
|
{"REVKEY", 1, CMD_REVKEY}, |
86 |
|
{"DISABLE", 0, CMD_DISABLE}, |
87 |
|
{"ENABLE", 0, CMD_ENABLE}, |
88 |
|
{"SIGN", 0, CMD_SIGN}, |
89 |
|
{"LSIGN", 0, CMD_LSIGN}, |
90 |
|
{"CHECK", 0, CMD_CHECK}, |
91 |
|
{NULL, 0} |
92 |
}; |
}; |
93 |
|
|
94 |
|
|
113 |
UID_COL_CREATION = 3 |
UID_COL_CREATION = 3 |
114 |
}; |
}; |
115 |
|
|
116 |
struct keyedit_callback_s { |
/* Key edit callback context. */ |
117 |
|
struct keyedit_cb_s { |
118 |
const char *keyid; |
const char *keyid; |
119 |
const char *pass; |
const char *pass; |
120 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
121 |
void *opaque; |
void *opaque; |
122 |
unsigned int finished:1; |
unsigned int finished:1; |
123 |
|
unsigned int is_protected:1; |
124 |
}; |
}; |
125 |
typedef struct keyedit_callback_s KEYEDIT_CB; |
typedef struct keyedit_cb_s *keyedit_cb_t; |
126 |
|
|
127 |
|
|
128 |
struct keygen_callback_s { |
/* Key generation callback context. */ |
129 |
|
struct keygen_cb_s { |
130 |
int bits; |
int bits; |
131 |
int algo; |
int algo; |
132 |
u32 expire; |
u32 expire; |
133 |
char *fpr; |
char *fpr; |
134 |
}; |
}; |
135 |
typedef struct keygen_callback_s KEYGEN_CB; |
typedef struct keygen_cb_s *keygen_cb_t; |
136 |
|
|
137 |
|
|
138 |
static subclass_s keyedit_subkey_proc; |
static subclass_s keyedit_subkey_proc; |
140 |
|
|
141 |
int keygen_check_date (SYSTEMTIME *st); |
int keygen_check_date (SYSTEMTIME *st); |
142 |
void get_userid_preflist (char **r_prefs, int * r_flags); |
void get_userid_preflist (char **r_prefs, int * r_flags); |
143 |
char* get_subkey_fingerprint (const char *keyid); |
char* get_subkey_keyid (const char *keyid); |
144 |
|
|
145 |
|
|
146 |
/* Associate each key with a combo box entry. |
/* Associate each key with a combo box entry. |
165 |
continue; |
continue; |
166 |
s = key->uids->uid; |
s = key->uids->uid; |
167 |
kid = key->subkeys->keyid; |
kid = key->subkeys->keyid; |
168 |
if (!s || !strcmp (kid+8, k->keyid+2)) |
if (!s || !strcmp (kid+8, k->keyid)) |
169 |
continue; |
continue; |
170 |
u = utf8_to_wincp (s, strlen (s)); |
u = utf8_to_wincp (s, strlen (s)); |
171 |
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_ADDSTRING, |
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_ADDSTRING, |
208 |
listview_add_sub_item (lv, 0, 2, email && *email? email : ""); |
listview_add_sub_item (lv, 0, 2, email && *email? email : ""); |
209 |
listview_add_sub_item (lv, 0, 3, get_key_created (time (NULL))); |
listview_add_sub_item (lv, 0, 3, get_key_created (time (NULL))); |
210 |
free_if_alloc (p); |
free_if_alloc (p); |
211 |
} /* do_add_new_userid */ |
} |
212 |
|
|
213 |
|
|
214 |
static void |
static void |
215 |
do_add_new_subkey (listview_ctrl_t lv, KEYGEN_CB *keygen, unsigned int flags) |
do_add_new_subkey (listview_ctrl_t lv, keygen_cb_t keygen, unsigned int flags) |
216 |
{ |
{ |
217 |
char info[128], keyid[32]; |
char info[128], keyid[32]; |
218 |
const char * expdate, * s; |
const char * expdate, * s; |
222 |
_snprintf (info, sizeof info-1, "%d-bit %s", |
_snprintf (info, sizeof info-1, "%d-bit %s", |
223 |
keygen->bits, |
keygen->bits, |
224 |
get_key_pubalgo ((gpgme_pubkey_algo_t)keygen->algo)); |
get_key_pubalgo ((gpgme_pubkey_algo_t)keygen->algo)); |
225 |
_snprintf (keyid, sizeof keyid-1, "0x%s", keygen->fpr+32); |
_snprintf (keyid, sizeof keyid-1, "0x%s", keygen->fpr+8); |
226 |
n = listview_count_items (lv, 0); |
n = listview_count_items (lv, 0); |
227 |
listview_add_item_pos (lv, n); |
listview_add_item_pos (lv, n); |
228 |
listview_add_sub_item (lv, n, 0, info); |
listview_add_sub_item (lv, n, 0, info); |
229 |
listview_add_sub_item (lv, n, 1, keyid); |
listview_add_sub_item (lv, n, 1, keyid); |
230 |
listview_add_sub_item (lv, n, 2, get_key_created (time (NULL))); |
listview_add_sub_item (lv, n, 2, get_key_created (time (NULL))); |
231 |
listview_add_sub_item (lv, n, 3, expdate); |
listview_add_sub_item (lv, n, 3, expdate); |
232 |
if (flags & KM_FLAG_REVOKED) s = _("Revoked"); |
if (flags & KM_FLAG_REVOKED) |
233 |
else if (flags & KM_FLAG_EXPIRED) s = _("Expired"); |
s = _("Revoked"); |
234 |
else s = _("OK"); |
else if (flags & KM_FLAG_EXPIRED) |
235 |
|
s = _("Expired"); |
236 |
|
else |
237 |
|
s = _("OK"); |
238 |
listview_add_sub_item (lv, n, 4, s); |
listview_add_sub_item (lv, n, 4, s); |
239 |
} /* do_add_new_subkey */ |
} |
240 |
|
|
241 |
|
|
242 |
/* Try to find the GPG edit key index which belongs to the user ID |
/* Try to find the GPG edit key index which belongs to the user ID |
243 |
given by @name. If @r_inf != NULL, the info context will be returned. |
given by the email address @email, @name is used as a fallback. |
244 |
|
If @r_inf != NULL, the info context will be returned. |
245 |
Return value: index of the user ID or -1 on error. */ |
Return value: index of the user ID or -1 on error. */ |
246 |
static int |
static int |
247 |
do_find_userid (const char *keyid, const char *name, gpg_uid_info_t *r_inf) |
do_find_userid (const char *keyid, const char *email, |
248 |
|
const char *name, gpg_uid_info_t *r_inf) |
249 |
{ |
{ |
250 |
GpgKeyEdit *ke; |
GpgKeyEdit *ke; |
251 |
gpgme_error_t err; |
gpgme_error_t err; |
265 |
} |
} |
266 |
|
|
267 |
for (ui = inf; ui; ui = ui->next) { |
for (ui = inf; ui; ui = ui->next) { |
268 |
if (!strcmp (ui->email, name)) { |
if (name && email && ui->email && ui->name) { |
269 |
|
if (!strcmp (ui->email, email) && |
270 |
|
!strncmp (ui->name, name, strlen (name))) { |
271 |
|
pos = ui->index; |
272 |
|
break; |
273 |
|
} |
274 |
|
continue; |
275 |
|
} |
276 |
|
if (ui->email) { |
277 |
|
if (!strcmp (ui->email, email)) { |
278 |
|
pos = ui->index; |
279 |
|
break; |
280 |
|
} |
281 |
|
/* The email address is more unique, use the name just |
282 |
|
as the fallbck when no email address is available. */ |
283 |
|
continue; |
284 |
|
} |
285 |
|
if (ui->name && name && !strcmp (ui->name, name)) { |
286 |
pos = ui->index; |
pos = ui->index; |
287 |
break; |
break; |
288 |
} |
} |
352 |
|
|
353 |
case IDC_ADDPHOTO_SELFILE: |
case IDC_ADDPHOTO_SELFILE: |
354 |
s = get_fileopen_dlg (dlg, _("Select Image File"), |
s = get_fileopen_dlg (dlg, _("Select Image File"), |
355 |
_("JPEG Files (*.jpg, *.jpeg)\0*.jpg;*.jpeg\0\0"), |
"JPEG Files (*.jpg, *.jpeg)\0*.jpg;*.jpeg\0\0", |
356 |
NULL); |
NULL); |
357 |
if (s && !is_jpg_file (s)) { |
if (s && !is_jpg_file (s)) { |
358 |
log_box (_("Add Photo"), MB_ERR, |
log_box (_("Add Photo"), MB_ERR, |
385 |
BUG (NULL); |
BUG (NULL); |
386 |
if (k->is_protected) |
if (k->is_protected) |
387 |
ke->setPassphrase (pwd); |
ke->setPassphrase (pwd); |
388 |
|
else |
389 |
|
ke->setNoPassphrase (true); |
390 |
ec = ke->addPhotoid (file); |
ec = ke->addPhotoid (file); |
391 |
delete ke; |
delete ke; |
392 |
wipememory (pwd, sizeof (pwd)); |
wipememory (pwd, sizeof (pwd)); |
417 |
keyedit_addrevoker_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyedit_addrevoker_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
418 |
{ |
{ |
419 |
static winpt_key_t k; |
static winpt_key_t k; |
420 |
static gpgme_key_t seckey; |
static gpgme_key_t seckey; |
|
GpgKeyEdit *ke; |
|
421 |
gpgme_error_t err; |
gpgme_error_t err; |
422 |
|
GpgKeyEdit *ke; |
423 |
char uid[128], pwd[128]; |
char uid[128], pwd[128]; |
|
|
|
424 |
|
|
425 |
switch( msg ) { |
switch (msg) { |
426 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
427 |
k = (winpt_key_t)lparam; |
k = (winpt_key_t)lparam; |
428 |
if( !k ) |
if (!k) |
429 |
BUG( NULL ); |
BUG (NULL); |
430 |
if( get_seckey( k->keyid, &seckey ) ) |
if (get_seckey (k->keyid, &seckey)) |
431 |
BUG( NULL ); |
BUG (NULL); |
432 |
if (!k->is_protected) |
if (!k->is_protected) |
433 |
EnableWindow (GetDlgItem (dlg, IDC_ADDREV_PASS), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_ADDREV_PASS), FALSE); |
434 |
do_init_keylist (dlg, k); |
do_init_keylist (dlg, k); |
435 |
SetDlgItemText (dlg, IDC_ADDREV_INF, _("Appointing a key as designated revoker cannot be undone.")); |
SetDlgItemText (dlg, IDC_ADDREV_INF, |
436 |
|
_("Appointing a key as designated revoker cannot be undone.")); |
437 |
SetDlgItemText (dlg, IDC_ADDREV_KEYINF, _("Public key")); |
SetDlgItemText (dlg, IDC_ADDREV_KEYINF, _("Public key")); |
438 |
SetDlgItemText (dlg, IDC_ADDREV_PWDINF, _("Passphrase")); |
SetDlgItemText (dlg, IDC_ADDREV_PWDINF, _("Passphrase")); |
439 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
466 |
ke = new GpgKeyEdit (k->keyid); |
ke = new GpgKeyEdit (k->keyid); |
467 |
if (k->is_protected) |
if (k->is_protected) |
468 |
ke->setPassphrase (pwd); |
ke->setPassphrase (pwd); |
469 |
|
else |
470 |
|
ke->setNoPassphrase (true); |
471 |
err = ke->addDesignatedRevoker (uid); |
err = ke->addDesignatedRevoker (uid); |
472 |
delete ke; |
delete ke; |
473 |
memset (pwd, 0, sizeof pwd); |
wipememory (pwd, sizeof (pwd)); |
474 |
if (err) { |
if (err) { |
475 |
msg_box (dlg, gpgme_strerror (err), _("Add Revoker"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Add Revoker"), MB_ERR); |
476 |
return TRUE; |
return TRUE; |
477 |
} |
} |
478 |
else { |
else { |
479 |
k->update = 1; |
k->update = 1; |
480 |
msg_box (dlg, _("Revoker successfully addded."), _("GnuPG Status"), MB_OK); |
msg_box (dlg, _("Revoker successfully addded."), |
481 |
|
_("GnuPG Status"), MB_OK); |
482 |
} |
} |
483 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
484 |
break; |
break; |
485 |
|
|
486 |
case IDCANCEL: |
case IDCANCEL: |
487 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
488 |
break; |
break; |
489 |
} |
} |
490 |
break; |
break; |
497 |
BOOL CALLBACK |
BOOL CALLBACK |
498 |
keyedit_adduid_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyedit_adduid_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
499 |
{ |
{ |
500 |
static KEYEDIT_CB *ctx; |
static keyedit_cb_t ctx; |
501 |
gpgme_error_t err; |
gpgme_error_t err; |
502 |
GpgKeyEdit *ke; |
GpgKeyEdit *ke; |
503 |
char *utf8_name = NULL; |
char *utf8_name = NULL; |
504 |
char name[128], email[128], comment[128]; |
char name[128], email[128], comment[128]; |
505 |
int rc; |
int rc; |
506 |
|
|
507 |
switch ( msg ) { |
switch (msg) { |
508 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
509 |
ctx = (KEYEDIT_CB *)lparam; |
ctx = (keyedit_cb_t)lparam; |
510 |
if( !ctx ) |
if( !ctx ) |
511 |
dlg_fatal_error(dlg, "Could not get dialog param!"); |
dlg_fatal_error(dlg, "Could not get dialog param!"); |
512 |
SetWindowText (dlg, _("Add new User ID")); |
SetWindowText (dlg, _("Add new User ID")); |
518 |
return FALSE; |
return FALSE; |
519 |
|
|
520 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
521 |
if (LOWORD (wparam) == SC_CLOSE) { |
if (LOWORD (wparam) == SC_CLOSE) |
522 |
EndDialog(dlg, TRUE); |
EndDialog(dlg, TRUE); |
|
} |
|
523 |
return FALSE; |
return FALSE; |
524 |
|
|
525 |
case WM_COMMAND: |
case WM_COMMAND: |
539 |
msg_box( dlg, _("Please enter an email address."), _("UserID"), MB_ERR ); |
msg_box( dlg, _("Please enter an email address."), _("UserID"), MB_ERR ); |
540 |
return FALSE; |
return FALSE; |
541 |
} |
} |
542 |
if( !strchr( email, '@' ) || strchr (email, ' ')) { |
if (!strchr (email, '@' ) || strchr (email, ' ')) { |
543 |
msg_box( dlg, _("Invalid email address."), _("UserID"), MB_ERR ); |
msg_box (dlg, _("Invalid email address."), _("UserID"), MB_ERR); |
544 |
return FALSE; |
return FALSE; |
545 |
} |
} |
546 |
|
|
547 |
rc = GetDlgItemText( dlg, IDC_ADDUID_COMMENT, comment, sizeof comment -1 ); |
rc = GetDlgItemText (dlg, IDC_ADDUID_COMMENT, |
548 |
|
comment, sizeof comment -1); |
549 |
|
|
550 |
/* XXX: something is wrong with the encoding :-( */ |
/* XXX: something is wrong with the encoding :-( */ |
551 |
utf8_name = wincp_to_utf8 (name, strlen (name)); |
utf8_name = wincp_to_utf8 (name, strlen (name)); |
553 |
ke = new GpgKeyEdit (ctx->keyid); |
ke = new GpgKeyEdit (ctx->keyid); |
554 |
if (!ke) |
if (!ke) |
555 |
BUG (NULL); |
BUG (NULL); |
556 |
if (ctx->pass) |
if (ctx->is_protected) |
557 |
ke->setPassphrase (ctx->pass); |
ke->setPassphrase (ctx->pass); |
558 |
|
else |
559 |
|
ke->setNoPassphrase (true); |
560 |
err = ke->addUserid (utf8_name? utf8_name : name, |
err = ke->addUserid (utf8_name? utf8_name : name, |
561 |
rc > 0? comment : NULL, email); |
rc > 0? comment : NULL, email); |
562 |
if (err) |
if (err) |
583 |
} |
} |
584 |
|
|
585 |
|
|
|
static int |
|
|
diff_time (HWND dt, SYSTEMTIME *in_exp) |
|
|
{ |
|
|
SYSTEMTIME exp, now; |
|
|
double e=0, n=0; |
|
|
|
|
|
if (in_exp) |
|
|
memcpy (&exp, in_exp, sizeof (SYSTEMTIME)); |
|
|
else |
|
|
DateTime_GetSystemtime (dt, &exp); |
|
|
GetSystemTime (&now); |
|
|
SystemTimeToVariantTime (&exp, &e); |
|
|
SystemTimeToVariantTime (&now, &n); |
|
|
if (n > e) |
|
|
return 0; |
|
|
return (int)(e-n); |
|
|
} |
|
|
|
|
|
|
|
586 |
static void |
static void |
587 |
init_keysize_box (HWND dlg, int ctlid) |
init_keysize_box (HWND dlg, int ctlid) |
588 |
{ |
{ |
609 |
} |
} |
610 |
|
|
611 |
|
|
612 |
|
/* Create a time_t from a system time @st. */ |
613 |
|
time_t |
614 |
|
w32_mktime (SYSTEMTIME *st) |
615 |
|
{ |
616 |
|
struct tm tm; |
617 |
|
|
618 |
|
memset (&tm, 0, sizeof (tm)); |
619 |
|
tm.tm_year = st->wYear-1900; |
620 |
|
tm.tm_mday = st->wDay+1; |
621 |
|
tm.tm_mon = st->wMonth-1; |
622 |
|
return mktime (&tm); |
623 |
|
} |
624 |
|
|
625 |
|
|
626 |
|
/* Dialog procedure for adding a new secondary key. */ |
627 |
BOOL CALLBACK |
BOOL CALLBACK |
628 |
keyedit_addsubkey_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyedit_addsubkey_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
629 |
{ |
{ |
630 |
static KEYEDIT_CB *ctx; |
static keyedit_cb_t ctx; |
631 |
static KEYGEN_CB *keygen; |
static keygen_cb_t keygen; |
632 |
GpgKeyEdit *ke; |
GpgKeyEdit *ke; |
633 |
gpgme_error_t err; |
gpgme_error_t err; |
634 |
|
SYSTEMTIME st; |
635 |
HWND lb; |
HWND lb; |
636 |
int index, size, valid; |
int index, size, valid; |
637 |
|
|
638 |
switch (msg) { |
switch (msg) { |
639 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
640 |
ctx = (KEYEDIT_CB *)lparam; |
ctx = (keyedit_cb_t)lparam; |
641 |
if (!ctx) |
if (!ctx) |
642 |
dlg_fatal_error (dlg, "Could not get dialog param!"); |
dlg_fatal_error (dlg, "Could not get dialog param!"); |
643 |
keygen = (KEYGEN_CB *)ctx->opaque; |
keygen = (keygen_cb_t)ctx->opaque; |
644 |
|
|
645 |
SetWindowText (dlg, _("Add new Subkey")); |
SetWindowText (dlg, _("Add new Subkey")); |
646 |
SetDlgItemText (dlg, IDC_ADDSUBKEY_INFALGO, _("Key type")); |
SetDlgItemText (dlg, IDC_ADDSUBKEY_INFALGO, _("Key type")); |
661 |
return FALSE; |
return FALSE; |
662 |
|
|
663 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
664 |
if( LOWORD (wparam) == SC_CLOSE ) { |
if (LOWORD (wparam) == SC_CLOSE) { |
665 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
666 |
} |
} |
667 |
return FALSE; |
return FALSE; |
668 |
|
|
669 |
case WM_COMMAND: |
case WM_COMMAND: |
670 |
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_ADDSUBKEY_EXPIRE) { |
if (HIWORD (wparam) == BN_CLICKED && |
671 |
|
LOWORD (wparam) == IDC_ADDSUBKEY_EXPIRE) { |
672 |
if (IsDlgButtonChecked (dlg, IDC_ADDSUBKEY_EXPIRE)) |
if (IsDlgButtonChecked (dlg, IDC_ADDSUBKEY_EXPIRE)) |
673 |
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE); |
674 |
else |
else |
675 |
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), TRUE); |
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), TRUE); |
676 |
} |
} |
677 |
if (HIWORD (wparam) == LBN_SELCHANGE && LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) { |
if (HIWORD (wparam) == LBN_SELCHANGE && |
678 |
|
LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) { |
679 |
index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0); |
index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0); |
680 |
if (index == 0) |
if (index == 0) |
681 |
SendDlgItemMessage (dlg, IDC_ADDSUBKEY_SIZE, CB_SETCURSEL, 0, 0); |
SendDlgItemMessage (dlg, IDC_ADDSUBKEY_SIZE, CB_SETCURSEL, 0, 0); |
682 |
} |
} |
683 |
|
|
684 |
switch ( LOWORD(wparam) ) { |
switch (LOWORD (wparam)) { |
685 |
case IDOK: |
case IDOK: |
686 |
lb = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
lb = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
687 |
switch (listbox_get_cursel (lb)) { |
switch (listbox_get_cursel (lb)) { |
689 |
case 1: index = 4; break; |
case 1: index = 4; break; |
690 |
case 2: index = 5; break; |
case 2: index = 5; break; |
691 |
case 3: index = 6; break; |
case 3: index = 6; break; |
692 |
default: |
default: |
693 |
msg_box( dlg, _("Please select one entry."), _("Add Subkey"), MB_ERR ); |
msg_box (dlg, _("Please select one entry."), _("Add Subkey"), MB_ERR); |
694 |
return FALSE; |
return FALSE; |
695 |
} |
} |
696 |
size = get_keysize_from_box (dlg, IDC_ADDSUBKEY_SIZE); |
size = get_keysize_from_box (dlg, IDC_ADDSUBKEY_SIZE); |
697 |
if (index == 2 && size != 1024) { |
if (index == 2 && size != 1024) { |
698 |
msg_box( dlg,_("DSS uses a fixed keysize of 1024. Size changed."), _("Add Subkey"), MB_INFO ); |
msg_box (dlg,_("DSS uses a fixed keysize of 1024. Size changed."), |
699 |
|
_("Add Subkey"), MB_INFO); |
700 |
size = 1024; |
size = 1024; |
701 |
} |
} |
702 |
valid = diff_time (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), NULL); |
|
703 |
|
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), &st); |
704 |
|
valid = w32_mktime (&st) - time (NULL); |
705 |
|
valid /= 86400; |
706 |
|
|
707 |
keygen->bits = size; |
keygen->bits = size; |
708 |
switch (index) { |
switch (index) { |
718 |
if (!ke) |
if (!ke) |
719 |
BUG (NULL); |
BUG (NULL); |
720 |
ke->setCallback (keygen_cb, NULL); |
ke->setCallback (keygen_cb, NULL); |
721 |
if (ctx->pass) |
if (ctx->is_protected) |
722 |
ke->setPassphrase (ctx->pass); |
ke->setPassphrase (ctx->pass); |
723 |
|
else |
724 |
|
ke->setNoPassphrase (true); |
725 |
keygen_cb_dlg_create (); |
keygen_cb_dlg_create (); |
726 |
|
|
727 |
err = ke->addSubkey ((gpgme_pubkey_algo_t)index, size, valid); |
err = ke->addSubkey ((gpgme_pubkey_algo_t)index, size, valid); |
728 |
keygen->fpr = get_subkey_fingerprint (ctx->keyid); |
keygen->fpr = get_subkey_keyid (ctx->keyid); |
729 |
keygen_cb_dlg_destroy (); |
keygen_cb_dlg_destroy (); |
730 |
keygen_cb (NULL, NULL, 0, 0, 0); /* flush */ |
keygen_cb (NULL, NULL, 0, 0, 0); /* flush */ |
731 |
if (err) |
if (err) |
733 |
else { |
else { |
734 |
msg_box (dlg, _("Subkey successfully added."), _("GnuPG Status"), MB_OK); |
msg_box (dlg, _("Subkey successfully added."), _("GnuPG Status"), MB_OK); |
735 |
if (ctx->lv) |
if (ctx->lv) |
736 |
do_add_new_subkey (ctx->lv, keygen, /*XXXk->flags*/0); |
do_add_new_subkey (ctx->lv, keygen, 0); |
737 |
ctx->finished = 1; |
ctx->finished = 1; |
738 |
} |
} |
739 |
delete ke; |
delete ke; |
740 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
741 |
return TRUE; |
return TRUE; |
742 |
|
|
743 |
case IDCANCEL: |
case IDCANCEL: |
744 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
745 |
return FALSE; |
return FALSE; |
746 |
} |
} |
747 |
break; |
break; |
748 |
} |
} |
749 |
|
|
750 |
return FALSE; |
return FALSE; |
751 |
} /* keyedit_addsubkey_dlg_proc */ |
} |
752 |
|
|
753 |
|
|
754 |
BOOL |
BOOL |
755 |
keyedit_add_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
keyedit_add_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
756 |
{ |
{ |
757 |
KEYEDIT_CB cb; |
keyedit_cb_s cb; |
758 |
char *pass = NULL; |
char *pass = NULL; |
759 |
int cancel = 0; |
int cancel = 0; |
760 |
|
|
770 |
} |
} |
771 |
|
|
772 |
memset (&cb, 0, sizeof cb); |
memset (&cb, 0, sizeof cb); |
773 |
cb.pass = k->is_protected? pass : NULL; |
cb.is_protected = k->is_protected; |
774 |
|
cb.pass = pass; |
775 |
cb.lv = lv; |
cb.lv = lv; |
776 |
cb.keyid = k->keyid; |
cb.keyid = k->keyid; |
777 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDUID, |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDUID, |
788 |
|
|
789 |
|
|
790 |
char* |
char* |
791 |
get_subkey_fingerprint (const char *keyid) |
get_subkey_keyid (const char *keyid) |
792 |
{ |
{ |
793 |
gpgme_error_t err; |
gpgme_error_t err; |
794 |
gpgme_key_t key, main; |
gpgme_key_t key; |
795 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
796 |
gpgme_subkey_t last_sk, k, new_sk; |
gpgme_subkey_t subk; |
797 |
int n; |
char *kid; |
798 |
|
|
799 |
err = gpgme_new (&ctx); |
err = gpgme_new (&ctx); |
800 |
if (err) |
if (err) |
801 |
return NULL; |
return NULL; |
802 |
err = gpgme_get_key (ctx, keyid, &key, 0); |
err = gpgme_get_key (ctx, keyid, &key, 0); |
803 |
|
gpgme_release (ctx); |
804 |
if (err) |
if (err) |
805 |
return NULL; |
return NULL; |
806 |
/* XXX: this is very slow and complicated */ |
subk = get_nth_key (key, count_subkeys (key)); |
807 |
|
kid = strdup (subk->keyid); |
|
n = count_subkeys (key); |
|
|
last_sk = get_nth_key (key, n-1); |
|
|
new_sk = (gpgme_subkey_t)calloc (1, sizeof *new_sk); |
|
|
if (!new_sk) |
|
|
BUG (NULL); |
|
|
memcpy (new_sk, last_sk, sizeof *last_sk); |
|
|
new_sk->fpr = strdup (last_sk->fpr); |
|
|
new_sk->keyid = strdup (last_sk->keyid); |
|
|
|
|
|
get_pubkey (keyid, &main); |
|
|
for (k=main->subkeys; k->next; k=k->next) |
|
|
; |
|
|
k->next = new_sk; |
|
|
|
|
808 |
gpgme_key_release (key); |
gpgme_key_release (key); |
809 |
return new_sk->fpr; |
return kid; |
810 |
} |
} |
811 |
|
|
812 |
|
|
813 |
BOOL |
BOOL |
814 |
keyedit_add_subkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
keyedit_add_subkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
815 |
{ |
{ |
816 |
KEYEDIT_CB cb; |
keyedit_cb_s cb; |
817 |
KEYGEN_CB keygen; |
keygen_cb_s keygen; |
818 |
char *pass = NULL; |
char *pass = NULL; |
819 |
int cancel = 0; |
int cancel = 0; |
820 |
|
|
830 |
|
|
831 |
memset (&keygen, 0, sizeof (keygen)); |
memset (&keygen, 0, sizeof (keygen)); |
832 |
memset (&cb, 0, sizeof (cb)); |
memset (&cb, 0, sizeof (cb)); |
833 |
|
cb.lv = lv; |
834 |
cb.keyid = k->keyid; |
cb.keyid = k->keyid; |
835 |
cb.pass = k->is_protected? pass : NULL; |
cb.is_protected = k->is_protected; |
836 |
|
cb.pass = pass; |
837 |
cb.opaque = &keygen; |
cb.opaque = &keygen; |
838 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDSUBKEY, |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDSUBKEY, |
839 |
dlg, keyedit_addsubkey_dlg_proc, |
dlg, keyedit_addsubkey_dlg_proc, |
840 |
(LPARAM)&cb, _("Add new Subkey"), |
(LPARAM)&cb, _("Add new Subkey"), |
841 |
IDS_WINPT_KEYEDIT_ADDSUBKEY); |
IDS_WINPT_KEYEDIT_ADDSUBKEY); |
842 |
|
safe_free (keygen.fpr); |
843 |
if (cb.finished) |
if (cb.finished) |
844 |
k->update = 1; |
k->update = 1; |
845 |
|
|
871 |
ke = new GpgKeyEdit (k->keyid); |
ke = new GpgKeyEdit (k->keyid); |
872 |
if (!ke) |
if (!ke) |
873 |
BUG (NULL); |
BUG (NULL); |
874 |
ke->setPassphrase (pass); |
if (k->is_protected) |
875 |
err = ke->setPreferredKeyserver (0 /* XXX */, url->url); |
ke->setPassphrase (pass); |
876 |
|
else |
877 |
|
ke->setNoPassphrase (true); |
878 |
|
err = ke->setPreferredKeyserver (-1, url->url); |
879 |
if (!err) |
if (!err) |
880 |
msg_box (dlg, _("Preferred keyserver successfully set."), _("Key Edit"), MB_OK); |
msg_box (dlg, _("Preferred keyserver successfully set."), _("Key Edit"), MB_OK); |
881 |
|
|
882 |
sfree_if_alloc (pass); |
sfree_if_alloc (pass); |
883 |
delete ke; |
delete ke; |
884 |
delete url; |
delete url; |
885 |
return err == 0? 0 : WPTERR_GENERAL; |
return err == 0? 0 : WPTERR_GENERAL; |
886 |
} |
} |
887 |
|
|
892 |
keyedit_add_photo (winpt_key_t k, HWND dlg) |
keyedit_add_photo (winpt_key_t k, HWND dlg) |
893 |
{ |
{ |
894 |
if (!k->key_pair) { |
if (!k->key_pair) { |
895 |
msg_box (dlg, _("There is no secret key available!"), _("Add Photo"), MB_ERR); |
msg_box (dlg, _("There is no secret key available!"), |
896 |
|
_("Add Photo"), MB_ERR); |
897 |
return FALSE; |
return FALSE; |
898 |
} |
} |
899 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDPHOTO, dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDPHOTO, dlg, |
905 |
BOOL |
BOOL |
906 |
keyedit_add_revoker (winpt_key_t k, HWND dlg) |
keyedit_add_revoker (winpt_key_t k, HWND dlg) |
907 |
{ |
{ |
908 |
if( !k->key_pair ) { |
if (!k->key_pair) { |
909 |
msg_box( dlg, _("There is no secret key available!"), _("Add Revoker"), MB_ERR ); |
msg_box (dlg, _("There is no secret key available!"), _("Add Revoker"), MB_ERR); |
910 |
return FALSE; |
return FALSE; |
911 |
} |
} |
912 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDREV, dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDREV, dlg, |
913 |
keyedit_addrevoker_dlg_proc, (LPARAM)k); |
keyedit_addrevoker_dlg_proc, (LPARAM)k); |
914 |
return TRUE; |
return TRUE; |
915 |
} /* keyedit_add_revoker */ |
} |
916 |
|
|
917 |
|
|
918 |
|
/* Change ownertrust of the given key @key. |
919 |
|
Return TRUE if the ownertrust was changed. */ |
920 |
|
BOOL |
921 |
|
keyedit_change_ownertrust (winpt_key_t key, HWND dlg) |
922 |
|
{ |
923 |
|
int rc; |
924 |
|
|
925 |
|
rc = dialog_box_param (glob_hinst, |
926 |
|
(LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST, |
927 |
|
dlg, keyedit_ownertrust_dlg_proc, |
928 |
|
(LPARAM)key, _("Change Ownertrust"), |
929 |
|
IDS_WINPT_KEYEDIT_OWNERTRUST); |
930 |
|
if (rc == TRUE) { |
931 |
|
msg_box (dlg, _("Key status changed."), _("Key Edit"), MB_OK); |
932 |
|
key->update = 1; |
933 |
|
} |
934 |
|
return rc; |
935 |
|
} |
936 |
|
|
937 |
|
|
938 |
|
/* Check if the given key is supposed to have IDEA |
939 |
|
for secret key protection. */ |
940 |
static int |
static int |
941 |
is_idea_protect_algo (const char * keyid) |
is_idea_protect_algo (const char *keyid) |
942 |
{ |
{ |
943 |
winpt_key_s k; |
winpt_key_s k; |
944 |
const unsigned char *sym_prefs; |
const unsigned char *sym_prefs; |
946 |
|
|
947 |
memset (&k, 0, sizeof (k)); |
memset (&k, 0, sizeof (k)); |
948 |
if (winpt_get_pubkey (keyid, &k)) |
if (winpt_get_pubkey (keyid, &k)) |
949 |
BUG (NULL); |
BUG (0); |
950 |
sym_prefs = k.ext->sym_prefs; |
sym_prefs = k.ext->sym_prefs; |
951 |
|
if (!k.is_v3) |
952 |
|
return 0; |
953 |
if (!sym_prefs) |
if (!sym_prefs) |
954 |
return 1; /* assume that only v3 keys have no symmetric cipher preferences |
return 1; /* assume that only v3 keys have no symmetric cipher preferences |
955 |
and thus IDEA is explicit. */ |
and thus IDEA is explicit. */ |
958 |
if ((n == 0 || n == 1) && *sym_prefs == 0x01) |
if ((n == 0 || n == 1) && *sym_prefs == 0x01) |
959 |
return 1; |
return 1; |
960 |
return 0; |
return 0; |
961 |
} /* is_idea_protect_algo */ |
} |
962 |
|
|
963 |
|
|
964 |
BOOL |
BOOL |
965 |
keyedit_change_passwd( winpt_key_t k, HWND dlg ) |
keyedit_change_passwd (winpt_key_t k, HWND dlg) |
966 |
{ |
{ |
967 |
|
gpgme_error_t ec; |
968 |
GpgKeyEdit *ke; |
GpgKeyEdit *ke; |
969 |
gpgme_error_t ec; |
char *old_pass = NULL; |
970 |
char *old_pass = NULL, *new_pass = NULL; |
char *new_pass = NULL; |
971 |
int cancel = 0; |
int cancel = 0; |
972 |
|
|
973 |
if( !k->key_pair ) { |
if (!k->key_pair) { |
974 |
msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR ); |
msg_box (dlg, _("There is no secret key available!"), |
975 |
|
_("Key Edit"), MB_ERR); |
976 |
return FALSE; |
return FALSE; |
977 |
} |
} |
978 |
|
|
979 |
if( !idea_available && is_idea_protect_algo( k->keyid ) ) { |
if (!idea_available && is_idea_protect_algo (k->keyid)) { |
980 |
msg_box( dlg, _("Cannot change passphrase because the key\n" |
msg_box (dlg, _("Cannot change passphrase because the key\n" |
981 |
"is protected with the IDEA encryption algorithm."), |
"is protected with the IDEA encryption algorithm."), |
982 |
_("Key Edit"), MB_ERR ); |
_("Key Edit"), MB_ERR); |
983 |
return FALSE; |
return FALSE; |
984 |
} |
} |
985 |
|
|
986 |
if( k->is_protected ) { |
if (k->is_protected) { |
987 |
old_pass = request_passphrase( _("Current (old) Passphrase"), 1, &cancel ); |
old_pass = request_passphrase (_("Current (old) Passphrase"), 1, &cancel); |
988 |
if (cancel) |
if (cancel) |
989 |
return FALSE; |
return FALSE; |
990 |
} |
} |
991 |
new_pass = request_passphrase( _("New Passphrase" ), 1, &cancel ); |
new_pass = request_passphrase2 (_("New Passphrase" ), 1, &cancel); |
992 |
if( cancel ) { |
if (cancel) { |
993 |
free_if_alloc( old_pass ); |
free_if_alloc (old_pass); |
994 |
return FALSE; |
return FALSE; |
995 |
} |
} |
996 |
|
|
997 |
if( is_8bit_string( new_pass ) ) { |
if (is_8bit_string (new_pass)) { |
998 |
msg_box( dlg, _("The passphrase contains 8-bit characters.\n" |
msg_box (dlg, _("The passphrase contains 8-bit characters.\n" |
999 |
"It is not suggested to use charset specific characters."), |
"It is not suggested to use charset specific characters."), |
1000 |
_("Key Edit"), MB_ERR ); |
_("Key Edit"), MB_ERR); |
1001 |
free_if_alloc( old_pass ); |
free_if_alloc (old_pass); |
1002 |
free_if_alloc( new_pass ); |
free_if_alloc (new_pass); |
1003 |
return FALSE; |
return FALSE; |
1004 |
} |
} |
1005 |
|
|
1020 |
} |
} |
1021 |
|
|
1022 |
|
|
1023 |
|
/* Initialize sub key list from key @k and return |
1024 |
|
the new listview control. */ |
1025 |
listview_ctrl_t |
listview_ctrl_t |
1026 |
subkey_list_init( HWND dlg, winpt_key_t k ) |
subkey_list_init (HWND dlg, winpt_key_t k) |
1027 |
{ |
{ |
1028 |
LV_ITEM lvi; |
LV_ITEM lvi; |
1029 |
gpgme_key_t key; |
gpgme_key_t key; |
1049 |
msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR ); |
msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR ); |
1050 |
return NULL; |
return NULL; |
1051 |
} |
} |
1052 |
|
if (!k->ctx) |
1053 |
|
k->ctx = key; |
1054 |
nkeys = count_subkeys (key); |
nkeys = count_subkeys (key); |
1055 |
if( !nkeys ) { |
if( !nkeys ) { |
1056 |
msg_box( dlg, _("No subkey(s) found."), _("Key Edit"), MB_ERR ); |
msg_box (dlg, _("No subkey(s) found."), _("Key Edit"), MB_ERR); |
1057 |
return NULL; |
return NULL; |
1058 |
} |
} |
1059 |
|
|
1070 |
listview_add_sub_item( lv, 0, 1, "" ); |
listview_add_sub_item( lv, 0, 1, "" ); |
1071 |
memset( &lvi, 0, sizeof lvi ); |
memset( &lvi, 0, sizeof lvi ); |
1072 |
lvi.mask = LVIF_PARAM; |
lvi.mask = LVIF_PARAM; |
1073 |
lvi.lParam = (LPARAM )key; |
lvi.lParam = (LPARAM)key; |
1074 |
if( ListView_SetItem( lv->ctrl, &lvi ) == FALSE ) |
if( ListView_SetItem( lv->ctrl, &lvi ) == FALSE ) |
1075 |
return NULL; |
return NULL; |
1076 |
} |
} |
1143 |
}; |
}; |
1144 |
const char *attr; |
const char *attr; |
1145 |
|
|
1146 |
if (get_pubkey( k->keyid, &key)) { |
if (get_pubkey (k->keyid, &key)) { |
1147 |
msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR ); |
msg_box (dlg, _("Could not find key."), _("Key Edit"), MB_ERR); |
1148 |
return NULL; |
return NULL; |
1149 |
} |
} |
1150 |
|
|
1155 |
} |
} |
1156 |
|
|
1157 |
rc = listview_new (&lv); |
rc = listview_new (&lv); |
1158 |
if( rc ) |
if (rc) |
1159 |
BUG( dlg ); |
BUG (dlg); |
1160 |
lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST ); |
lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST ); |
1161 |
for( j = 0; cols[j].fieldname != NULL; j++ ) |
for( j = 0; cols[j].fieldname != NULL; j++ ) |
1162 |
listview_add_column( lv, &cols[j] ); |
listview_add_column( lv, &cols[j] ); |
1179 |
/* XXX: add comment if available */ |
/* XXX: add comment if available */ |
1180 |
attr = u->name; |
attr = u->name; |
1181 |
if (attr) { |
if (attr) { |
1182 |
char * uid = utf8_to_wincp (attr, strlen (attr)); |
char *uid = utf8_to_wincp (attr, strlen (attr)); |
1183 |
if (uid) { |
if (uid) { |
1184 |
listview_add_sub_item( lv, j, 1, uid ); |
listview_add_sub_item (lv, j, 1, uid); |
1185 |
free( uid ); |
free (uid); |
1186 |
} |
} |
1187 |
} |
} |
1188 |
else |
else |
1189 |
listview_add_sub_item( lv, j, 1, _("Invalid user ID") ); |
listview_add_sub_item (lv, j, 1, _("Invalid user ID")); |
1190 |
attr = u->email; |
attr = u->email; |
1191 |
if (attr) |
if (attr) |
1192 |
listview_add_sub_item (lv, j, 2, attr); |
listview_add_sub_item (lv, j, 2, attr); |
1193 |
|
|
1194 |
ks = get_selfsig (u, k->keyid+2, 1); |
ks = get_selfsig (u, k->keyid, 1); |
1195 |
if (ks) |
if (ks) |
1196 |
listview_add_sub_item (lv, j, 3, get_key_created (ks->timestamp)); |
listview_add_sub_item (lv, j, 3, get_key_created (ks->timestamp)); |
1197 |
} |
} |
1204 |
|
|
1205 |
|
|
1206 |
static void |
static void |
1207 |
do_init_cmdlist( HWND dlg ) |
do_init_cmdlist (HWND dlg, int is_keypair) |
1208 |
{ |
{ |
1209 |
const char *cmdlist[] = { |
const char *s; |
|
"ADDKEY", |
|
|
"ADDUID", |
|
|
"ADDPHOTO", |
|
|
"ADDREVOKER", |
|
|
/*"FPR",*/ |
|
|
"DELUID", |
|
|
"DELKEY", |
|
|
"DELPHOTO", |
|
|
/*"DELSIG",*/ |
|
|
"EXPIRE", |
|
|
/*"PREF",*/ |
|
|
"SHOWPREF", |
|
|
/*"SETPREF",*/ |
|
|
"PASSWD", |
|
|
"PRIMARY", |
|
|
"TRUST", |
|
|
/*"REVSIG",*/ |
|
|
"REVUID", |
|
|
"REVKEY", |
|
|
"DISABLE", |
|
|
"ENABLE", |
|
|
"SHOWPHOTO", |
|
|
NULL |
|
|
}; |
|
|
const char * s; |
|
1210 |
int i = 0; |
int i = 0; |
1211 |
|
|
1212 |
for( i = 0; (s=cmdlist[i]); i++ ) { |
for (i = 0; (s=cmdlist[i].name); i++) { |
1213 |
SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_ADDSTRING, 0, |
if (is_keypair) |
1214 |
(LPARAM)(char *)s ); |
SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_ADDSTRING, 0, |
1215 |
|
(LPARAM)(char *)s); |
1216 |
|
else if (!cmdlist[i].need_pair) |
1217 |
|
SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_ADDSTRING, 0, |
1218 |
|
(LPARAM)(char *)s); |
1219 |
} |
} |
1220 |
SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_SETCURSEL, 0, 0 ); |
SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_SETCURSEL, 0, 0); |
1221 |
} /* do_init_cmdlist */ |
} |
1222 |
|
|
1223 |
|
|
1224 |
|
/* Return 1 if the requested command is RFC2440. */ |
1225 |
static int |
static int |
1226 |
is_cmd_openpgp( int cmdid ) |
is_cmd_openpgp (int cmdid) |
1227 |
{ |
{ |
1228 |
switch( cmdid ) { |
switch (cmdid) { |
1229 |
case CMD_ADDKEY: |
case CMD_ADDKEY: |
1230 |
case CMD_ADDPHOTO: |
case CMD_ADDPHOTO: |
1231 |
case CMD_ADDREVOKER: |
case CMD_ADDREVOKER: |
1232 |
case CMD_DELPHOTO: |
//case CMD_SETPREF: |
|
/*case CMD_SHOWPHOTO:*/ |
|
|
/*case CMD_SETPREF:*/ |
|
1233 |
return 1; |
return 1; |
1234 |
} |
} |
1235 |
return 0; |
return 0; |
1236 |
} /* is_cmd_openpgp */ |
} |
1237 |
|
|
1238 |
|
|
1239 |
|
/* Display a message box with a short description of the commands. */ |
1240 |
static void |
static void |
1241 |
do_show_help( HWND dlg ) |
do_show_help (HWND dlg) |
1242 |
{ |
{ |
1243 |
char helptext[2048]; |
char helptext[2048]; |
1244 |
|
|
1245 |
_snprintf( helptext, sizeof helptext-1, |
_snprintf (helptext, sizeof (helptext)-1, |
1246 |
_(/*"FPR \t\tshow fingerprint\r\n"*/ |
_( |
1247 |
"ADDUID \t\tadd a user ID\r\n" |
"ADDUID \t\tadd a user ID\r\n" |
1248 |
"ADDPHOTO \t\tadd a photo ID\r\n" |
"ADDPHOTO \t\tadd a photo ID\r\n" |
1249 |
"DELUID \t\tdelete a user ID\r\n" |
"DELUID \t\tdelete a user ID\r\n" |
1250 |
"ADDKEY \t\tadd a secondard key\r\n" |
"ADDKEY \t\tadd a secondard key\r\n" |
1251 |
"DELKEY \t\tdelete a secondary key\r\n" |
"DELKEY \t\tdelete a secondary key\r\n" |
1252 |
"ADDREVOKER\t\tadd a revocation key\r\n" |
"ADDREVOKER\t\tadd a revocation key\r\n" |
|
/*"DELSIG \t\tdelete signatures\r\n"*/ |
|
1253 |
"EXPIRE \t\tchange the expire date\r\n" |
"EXPIRE \t\tchange the expire date\r\n" |
|
/*"PREF \t\tlist preferences (expert)\r\n" |
|
1254 |
"SHOWPREF \t\tlist preferences (verbose)\r\n" |
"SHOWPREF \t\tlist preferences (verbose)\r\n" |
1255 |
"SETPREF \t\tset preference list\r\n"*/ |
"SETPREF \t\tset preference list\r\n" |
1256 |
"UPDPREF \t\tupdated preferences\r\n" |
"UPDPREF \t\tupdated preferences\r\n" |
1257 |
"PASSWD \t\tchange the passphrase\r\n" |
"PASSWD \t\tchange the passphrase\r\n" |
1258 |
"PRIMARY \t\tflag user ID as primary\r\n" |
"PRIMARY \t\tflag user ID as primary\r\n" |
1259 |
"TRUST \t\tchange the ownertrust\r\n" |
"TRUST \t\tchange the ownertrust\r\n" |
|
/*"REVSIG \t\trevoke signatures\r\n"*/ |
|
1260 |
"REVUID \t\trevoke a user ID\r\n" |
"REVUID \t\trevoke a user ID\r\n" |
1261 |
"REVKEY \t\trevoke a secondary key\r\n" |
"REVKEY \t\trevoke a secondary key\r\n" |
1262 |
"DISABLE \t\tdisable a key\r\n" |
"DISABLE \t\tdisable a key\r\n" |
1263 |
"ENABLE \t\tenable a key\r\n" |
"ENABLE \t\tenable a key\r\n" |
1264 |
/*"SHOWPHOTO \t\tshow photo ID\r\n"*/) ); |
"SIGN \t\tsign a user-id (exportable)\r\n" |
1265 |
msg_box( dlg, helptext, _("Key Edit Help"), MB_OK ); |
"LSIGN \t\tsign a user-id (non-exportable)\r\n")); |
1266 |
} /* do_show_help */ |
msg_box (dlg, helptext, _("Key Edit Help"), MB_OK); |
1267 |
|
} |
1268 |
|
|
1269 |
|
|
1270 |
static int |
static int |
1316 |
} /* do_editkey_delkey */ |
} /* do_editkey_delkey */ |
1317 |
|
|
1318 |
|
|
1319 |
|
|
1320 |
/* Set the expiration date for the selected key in list view @lv. |
/* Set the expiration date for the selected key in list view @lv. |
1321 |
Return value: TRUE on success. */ |
Return value: TRUE on success. */ |
1322 |
static int |
static int |
1372 |
BUG (NULL); |
BUG (NULL); |
1373 |
if (k->is_protected) |
if (k->is_protected) |
1374 |
ke->setPassphrase (pass); |
ke->setPassphrase (pass); |
1375 |
err = ke->setKeyExpireDate (j, diff_time (NULL, &udd.st), true); |
else |
1376 |
|
ke->setNoPassphrase (true); |
1377 |
|
err = ke->setKeyExpireDate (j, w32_mktime (&udd.st), false); |
1378 |
if (err) |
if (err) |
1379 |
msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR); |
1380 |
else { |
else { |
1437 |
BUG (NULL); |
BUG (NULL); |
1438 |
if (k->is_protected) |
if (k->is_protected) |
1439 |
ke->setPassphrase (pass); |
ke->setPassphrase (pass); |
1440 |
|
else |
1441 |
|
ke->setNoPassphrase (true); |
1442 |
err = ke->revokeSubkey (j, 0, NULL); |
err = ke->revokeSubkey (j, 0, NULL); |
1443 |
if (err) |
if (err) |
1444 |
msg_box( dlg, gpgme_strerror (err), _("Revoke Subkey"), MB_ERR); |
msg_box( dlg, gpgme_strerror (err), _("Revoke Subkey"), MB_ERR); |
1460 |
{ |
{ |
1461 |
gpgme_error_t err; |
gpgme_error_t err; |
1462 |
GpgKeyEdit *ke; |
GpgKeyEdit *ke; |
1463 |
char buf[256], t[512]; |
char buf[128], email[128]; |
1464 |
char *pass=NULL; |
char inf[512]; |
1465 |
|
char *pass = NULL; |
1466 |
int cancel = 0, id = 0, j; |
int cancel = 0, id = 0, j; |
1467 |
|
|
1468 |
if (!k->key_pair) { |
if (!k->key_pair) { |
1469 |
msg_box( dlg, _("There is no secret key available!"), _("Revoke user ID"), MB_ERR ); |
msg_box (dlg, _("There is no secret key available!"), |
1470 |
|
_("Revoke user ID"), MB_ERR); |
1471 |
return FALSE; |
return FALSE; |
1472 |
} |
} |
1473 |
|
|
1474 |
if( listview_count_items( lv, 0 ) == 1 ) { |
if (listview_count_items (lv, 0) == 1) { |
1475 |
msg_box( dlg, _("Key has only one user ID."), _("Key Edit"), MB_ERR ); |
msg_box (dlg, _("Key has only one user ID."), _("Key Edit"), MB_ERR); |
1476 |
return FALSE; |
return FALSE; |
1477 |
} |
} |
1478 |
|
|
1481 |
return FALSE; |
return FALSE; |
1482 |
} |
} |
1483 |
|
|
1484 |
listview_get_item_text( lv, j, 0, buf, sizeof buf - 1 ); |
listview_get_item_text( lv, j, UID_COL_VALID, buf, sizeof buf - 1); |
1485 |
if( strstr( buf, _("Revoked") ) ) { |
if (strstr (buf, _("Revoked"))) { |
1486 |
msg_box( dlg, _("This user ID has been already revoked."), _("Key Edit"), MB_INFO ); |
msg_box (dlg, _("This user ID has been already revoked."), |
1487 |
|
_("Key Edit"), MB_INFO); |
1488 |
return FALSE; |
return FALSE; |
1489 |
} |
} |
1490 |
|
|
1491 |
listview_get_item_text (lv, j, 1, buf, sizeof buf -1); |
listview_get_item_text (lv, j, UID_COL_NAME, buf, sizeof buf -1); |
1492 |
_snprintf( t, sizeof t -1, _("user ID \"%s\".\n\n" |
_snprintf (inf, sizeof (inf) -1, _("user ID \"%s\".\n\n" |
1493 |
"Do you really want to revoke this user ID?"), buf ); |
"Do you really want to revoke this user ID?"), buf); |
1494 |
if( msg_box( dlg, t, _("Key Edit"), MB_WARN_ASK) == IDNO ) |
if (msg_box (dlg, inf, _("Key Edit"), MB_WARN_ASK) == IDNO) |
1495 |
return FALSE; |
return FALSE; |
1496 |
if( k->is_protected ) { |
if (k->is_protected) { |
1497 |
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1498 |
if (cancel) |
if (cancel) |
1499 |
return FALSE; |
return FALSE; |
1500 |
} |
} |
1501 |
listview_get_item_text (lv, j, 2, buf, sizeof (buf)-1); |
listview_get_item_text (lv, j, UID_COL_EMAIL, email, sizeof (email)-1); |
1502 |
id = do_find_userid (k->keyid, buf, NULL); |
listview_get_item_text (lv, j, UID_COL_NAME, buf, sizeof (buf)-1); |
1503 |
|
id = do_find_userid (k->keyid, email, buf, NULL); |
1504 |
if (id == -1) |
if (id == -1) |
1505 |
BUG (NULL); |
BUG (NULL); |
1506 |
|
|
1509 |
BUG (NULL); |
BUG (NULL); |
1510 |
if (k->is_protected) |
if (k->is_protected) |
1511 |
ke->setPassphrase (pass); |
ke->setPassphrase (pass); |
1512 |
|
else |
1513 |
|
ke->setNoPassphrase (true); |
1514 |
err = ke->revokeUserid (id); |
err = ke->revokeUserid (id); |
1515 |
if (err) |
if (err) |
1516 |
msg_box (dlg, gpgme_strerror (err), _("Revoke Signature"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Revoke User ID"), MB_ERR); |
1517 |
else { |
else { |
1518 |
listview_add_sub_item (lv, j, 0, _("Revoked")); |
listview_add_sub_item (lv, j, 0, _("Revoked")); |
1519 |
k->update = 1; |
k->update = 1; |
1538 |
return FALSE; |
return FALSE; |
1539 |
} |
} |
1540 |
listview_get_item_text (lv, j, 2, buf, sizeof buf-1); |
listview_get_item_text (lv, j, 2, buf, sizeof buf-1); |
1541 |
id = do_find_userid (k->keyid, buf, NULL); |
id = do_find_userid (k->keyid, buf, NULL, NULL); |
1542 |
if (id == -1) |
if (id == -1) |
1543 |
BUG (dlg); |
BUG (dlg); |
1544 |
if (k->is_protected) { |
if (k->is_protected) { |
1552 |
BUG (NULL); |
BUG (NULL); |
1553 |
if (k->is_protected) |
if (k->is_protected) |
1554 |
ke->setPassphrase (pass); |
ke->setPassphrase (pass); |
1555 |
|
else |
1556 |
|
ke->setNoPassphrase (true); |
1557 |
|
|
1558 |
get_userid_preflist (&prefs, &flags); |
get_userid_preflist (&prefs, &flags); |
1559 |
|
|
1560 |
rc = ke->setUseridPreferences (id, prefs); |
rc = ke->setUseridPreferences (id, prefs); |
1561 |
/* XXX */ |
if (rc) |
1562 |
|
msg_box (dlg, _("Could not set user ID preferences"), _("Key Edit"), MB_ERR); |
1563 |
|
|
1564 |
sfree_if_alloc (pass); |
sfree_if_alloc (pass); |
1565 |
free_if_alloc (prefs); |
free_if_alloc (prefs); |
1583 |
return FALSE; |
return FALSE; |
1584 |
} |
} |
1585 |
listview_get_item_text (lv, j, 2, buf, sizeof buf-1); |
listview_get_item_text (lv, j, 2, buf, sizeof buf-1); |
1586 |
id = do_find_userid (k->keyid, buf, NULL); |
id = do_find_userid (k->keyid, buf, NULL, NULL); |
1587 |
if (id == -1) |
if (id == -1) |
1588 |
BUG (dlg); |
BUG (dlg); |
1589 |
if (k->is_protected) { |
if (k->is_protected) { |
1595 |
ke = new GpgKeyEdit (k->keyid); |
ke = new GpgKeyEdit (k->keyid); |
1596 |
if (k->is_protected) |
if (k->is_protected) |
1597 |
ke->setPassphrase (pass); |
ke->setPassphrase (pass); |
1598 |
|
else |
1599 |
|
ke->setNoPassphrase (true); |
1600 |
err = ke->setPrimaryUserid (id); |
err = ke->setPrimaryUserid (id); |
1601 |
if (err) |
if (err) |
1602 |
msg_box (dlg, gpgme_strerror (err), _("Primary"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Primary"), MB_ERR); |
1663 |
BOOL CALLBACK |
BOOL CALLBACK |
1664 |
showpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
showpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1665 |
{ |
{ |
1666 |
static keyedit_callback_s *cb = NULL; |
static keyedit_cb_t cb = NULL; |
1667 |
gpg_uid_info_t inf=NULL; |
gpg_uid_info_t inf=NULL; |
1668 |
char buf[128]; |
char buf[128]; |
1669 |
int pos; |
int pos; |
1670 |
|
|
1671 |
switch (msg) { |
switch (msg) { |
1672 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
1673 |
cb = (keyedit_callback_s *)lparam; |
cb = (keyedit_cb_t)lparam; |
1674 |
if (cb == NULL) |
if (cb == NULL) |
1675 |
BUG (dlg); |
BUG (dlg); |
1676 |
pos = listview_get_curr_pos (cb->lv); |
pos = listview_get_curr_pos (cb->lv); |
1677 |
listview_get_item_text (cb->lv, pos, 2, buf, DIM (buf)-1); |
listview_get_item_text (cb->lv, pos, 2, buf, DIM (buf)-1); |
1678 |
SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf); |
SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf); |
1679 |
pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid, buf, &inf); |
pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid, |
1680 |
|
buf, NULL, &inf); |
1681 |
if (inf) { |
if (inf) { |
1682 |
const char *prefs = inf->prefs; |
const char *prefs = inf->prefs; |
1683 |
if (prefs && *prefs) { |
if (prefs && *prefs) { |
1715 |
static int |
static int |
1716 |
do_editkey_showpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
do_editkey_showpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1717 |
{ |
{ |
1718 |
struct keyedit_callback_s cb; |
struct keyedit_cb_s cb; |
1719 |
|
|
1720 |
if (k->is_v3) |
if (k->is_v3) |
1721 |
return TRUE; |
return TRUE; |
1739 |
{ |
{ |
1740 |
gpgme_error_t err; |
gpgme_error_t err; |
1741 |
GpgKeyEdit *ke; |
GpgKeyEdit *ke; |
1742 |
char buf[256], t[512]; |
char email[128], name[128]; |
1743 |
|
char inf[384]; |
1744 |
int j, id = 0; |
int j, id = 0; |
1745 |
|
|
1746 |
if (!k->key_pair) |
if (!k->key_pair) |
1747 |
return FALSE; /* XXX: see do_editkey_delsubkey */ |
return FALSE; /* XXX: see do_editkey_delsubkey */ |
1748 |
|
|
1749 |
if( listview_count_items( lv, 0 ) == 1 ) { |
if (listview_count_items (lv, 0) == 1) { |
1750 |
msg_box( dlg, _("Primary user ID can not be deleted!"), _("Key Edit"), MB_ERR ); |
msg_box (dlg, _("Primary user ID can not be deleted!"), |
1751 |
|
_("Key Edit"), MB_ERR); |
1752 |
return FALSE; |
return FALSE; |
1753 |
} |
} |
1754 |
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
if ((j = listview_get_curr_pos (lv)) == -1) { |
1755 |
msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR ); |
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
1756 |
return FALSE; |
return FALSE; |
1757 |
} |
} |
1758 |
|
|
1759 |
/* XXX: add a hint that also all signatures will be deleted? */ |
/* XXX: add a hint that also all signatures will be deleted? */ |
1760 |
listview_get_item_text( lv, j, 1, buf, DIM(buf) -1 ); |
listview_get_item_text (lv, j, UID_COL_NAME, name, DIM(name) -1); |
1761 |
_snprintf( t, DIM (t)-1, _("user ID \"%s\".\n\n" |
_snprintf (inf, DIM (inf)-1, _("user ID \"%s\".\n\n" |
1762 |
"Do you really want to delete this user ID?"), |
"Do you really want to delete this user ID?"), |
1763 |
buf); |
name); |
1764 |
if( msg_box( dlg, t, _("Key Edit"), MB_YESNO|MB_ICONWARNING ) == IDNO ) |
if (msg_box (dlg, inf, _("Key Edit"), MB_YESNO|MB_ICONWARNING) == IDNO) |
1765 |
return FALSE; |
return FALSE; |
1766 |
|
|
1767 |
listview_get_item_text (lv, j, 2, buf, DIM (buf)-1); |
listview_get_item_text (lv, j, UID_COL_EMAIL, email, DIM (email)-1); |
1768 |
id = do_find_userid (k->keyid, buf, NULL); |
listview_get_item_text (lv, j, UID_COL_NAME, name, DIM (name)-1); |
1769 |
|
id = do_find_userid (k->keyid, email, name, NULL); |
1770 |
if (id == -1) |
if (id == -1) |
1771 |
BUG (dlg); |
BUG (dlg); |
1772 |
|
|
1775 |
BUG (NULL); |
BUG (NULL); |
1776 |
|
|
1777 |
err = ke->delUserid (id); |
err = ke->delUserid (id); |
1778 |
if( err ) |
if (err) |
1779 |
msg_box( dlg, gpgme_strerror (err), _("Delete user ID"), MB_ERR ); |
msg_box (dlg, gpgme_strerror (err), _("Delete user ID"), MB_ERR); |
1780 |
else { |
else { |
1781 |
listview_del_item( lv, j ); |
listview_del_item (lv, j); |
1782 |
k->update = 1; |
k->update = 1; |
1783 |
status_box( dlg, _("User ID successfully deleted"), _("GnuPG Status") ); |
status_box (dlg, _("User ID successfully deleted"), _("GnuPG Status")); |
1784 |
} |
} |
1785 |
delete ke; |
delete ke; |
1786 |
return err? FALSE : TRUE; |
return err? FALSE : TRUE; |
1836 |
} /* uid_subclass_proc */ |
} /* uid_subclass_proc */ |
1837 |
|
|
1838 |
|
|
1839 |
|
static void |
1840 |
|
do_editkey_enable_disable (winpt_key_t k, HWND dlg, listview_ctrl_t lv, int enable) |
1841 |
|
{ |
1842 |
|
km_enable_disable_key (lv, dlg, 0, enable); |
1843 |
|
k->update = 1; |
1844 |
|
} |
1845 |
|
|
1846 |
|
|
1847 |
|
/* Return default secret key. */ |
1848 |
|
static gpgme_key_t |
1849 |
|
get_default_key (void) |
1850 |
|
{ |
1851 |
|
gpgme_key_t def_sk; |
1852 |
|
char *keyid = get_gnupg_default_key (); |
1853 |
|
|
1854 |
|
get_seckey (keyid, &def_sk); |
1855 |
|
free_if_alloc (keyid); |
1856 |
|
return def_sk; |
1857 |
|
} |
1858 |
|
|
1859 |
|
|
1860 |
|
static void |
1861 |
|
do_editkey_check (winpt_key_t k, HWND dlg) |
1862 |
|
{ |
1863 |
|
if (!k->ctx) |
1864 |
|
get_pubkey (k->keyid, &k->ctx); |
1865 |
|
if (!k->uid && k->ctx) |
1866 |
|
k->uid = k->ctx->uids->uid; |
1867 |
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSIG_TREE, dlg, |
1868 |
|
sigtree_dlg_proc, (LPARAM)k); |
1869 |
|
} |
1870 |
|
|
1871 |
|
|
1872 |
|
static int |
1873 |
|
do_editkey_sign_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv, int mode) |
1874 |
|
{ |
1875 |
|
gpgme_error_t err; |
1876 |
|
GpgKeyEdit *ke; |
1877 |
|
char *pass = NULL; |
1878 |
|
char email[64], name[128]; |
1879 |
|
int uid_index; |
1880 |
|
int cancel = 0; |
1881 |
|
|
1882 |
|
uid_index = listview_get_curr_pos (lv); |
1883 |
|
if (uid_index == -1) { |
1884 |
|
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
1885 |
|
return FALSE; |
1886 |
|
} |
1887 |
|
if (mode == CMD_SIGN) { |
1888 |
|
cancel = msg_box (dlg, _("Do you really want to make this sig exportable?"), |
1889 |
|
_("Key Edit"), MB_QUEST_ASK); |
1890 |
|
if (cancel == IDNO) |
1891 |
|
return FALSE; |
1892 |
|
} |
1893 |
|
|
1894 |
|
listview_get_item_text (lv, uid_index, UID_COL_EMAIL, email, sizeof (email)-1); |
1895 |
|
listview_get_item_text (lv, uid_index, UID_COL_NAME, name, sizeof (name)-1); |
1896 |
|
uid_index = do_find_userid (k->keyid, email, name, NULL); |
1897 |
|
if (k->is_protected) { |
1898 |
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1899 |
|
if (cancel) |
1900 |
|
return FALSE; |
1901 |
|
} |
1902 |
|
ke = new GpgKeyEdit (k->keyid); |
1903 |
|
if (k->is_protected) |
1904 |
|
ke->setPassphrase (pass); |
1905 |
|
else |
1906 |
|
ke->setNoPassphrase (true); |
1907 |
|
ke->setLocalUser (get_default_key ()); |
1908 |
|
err = ke->signUserid (uid_index, |
1909 |
|
mode == CMD_SIGN? GPG_EDITKEY_SIGN : GPG_EDITKEY_LSIGN, |
1910 |
|
0, NULL); |
1911 |
|
if (!err) { |
1912 |
|
msg_box (dlg, _("Key successfully signed."), _("Key Edit"), MB_OK); |
1913 |
|
k->update = 1; |
1914 |
|
} |
1915 |
|
else |
1916 |
|
msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR); |
1917 |
|
delete ke; |
1918 |
|
sfree_if_alloc (pass); |
1919 |
|
return !err? TRUE : FALSE; |
1920 |
|
} |
1921 |
|
|
1922 |
|
|
1923 |
|
static int |
1924 |
|
lookup_cmd (HWND dlg) |
1925 |
|
{ |
1926 |
|
char buf[64]; |
1927 |
|
int i; |
1928 |
|
|
1929 |
|
i = SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0); |
1930 |
|
if (i == LB_ERR) |
1931 |
|
return LB_ERR; |
1932 |
|
GetDlgItemText (dlg, IDC_KEYEDIT_CMD, buf, sizeof (buf)-1); |
1933 |
|
for (i=0; cmdlist[i].name != NULL; i++) { |
1934 |
|
if (!strcmp (buf, cmdlist[i].name)) |
1935 |
|
return cmdlist[i].id; |
1936 |
|
} |
1937 |
|
return LB_ERR; |
1938 |
|
} |
1939 |
|
|
1940 |
|
/* Dialog box procedure for the edit key dialog. */ |
1941 |
BOOL CALLBACK |
BOOL CALLBACK |
1942 |
keyedit_main_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyedit_main_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1943 |
{ |
{ |
1944 |
static winpt_key_t k; |
static winpt_key_t k; |
1945 |
static listview_ctrl_t lvsub = NULL, lvuid = NULL; |
static listview_ctrl_t lvsub = NULL, lvuid = NULL; |
1946 |
int cmd, idxsub = 0; |
int cmd; |
1947 |
HWND item; |
HWND item; |
1948 |
|
|
1949 |
switch( msg ) { |
switch( msg ) { |
1951 |
k = (winpt_key_t)lparam; |
k = (winpt_key_t)lparam; |
1952 |
if (!k) |
if (!k) |
1953 |
BUG (NULL); |
BUG (NULL); |
1954 |
do_init_cmdlist (dlg); |
do_init_cmdlist (dlg, k->key_pair); |
1955 |
lvsub = subkey_list_init (dlg, k); |
lvsub = subkey_list_init (dlg, k); |
1956 |
if( !lvsub ) |
if( !lvsub ) |
1957 |
BUG( NULL ); |
BUG( NULL ); |
1978 |
BUG( NULL ); |
BUG( NULL ); |
1979 |
} |
} |
1980 |
} |
} |
1981 |
if (!k->key_pair) { |
if (k->ctx->revoked) { |
1982 |
EnableWindow (GetDlgItem (dlg, IDC_KEYEDIT_CMD), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_KEYEDIT_CMD), FALSE); |
1983 |
EnableWindow (GetDlgItem (dlg, IDOK), FALSE); |
EnableWindow (GetDlgItem (dlg, IDOK), FALSE); |
1984 |
} |
} |
1986 |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
1987 |
SetDlgItemText (dlg, IDC_KEYEDIT_HELP, _("&Help")); |
SetDlgItemText (dlg, IDC_KEYEDIT_HELP, _("&Help")); |
1988 |
SetWindowText (dlg, _("Key Edit")); |
SetWindowText (dlg, _("Key Edit")); |
1989 |
SetForegroundWindow( dlg ); |
SetForegroundWindow (dlg); |
1990 |
center_window( dlg, NULL ); |
center_window (dlg, NULL); |
1991 |
return TRUE; |
return TRUE; |
1992 |
|
|
1993 |
case WM_DESTROY: |
case WM_DESTROY: |
2012 |
case WM_COMMAND: |
case WM_COMMAND: |
2013 |
switch( LOWORD( wparam ) ) { |
switch( LOWORD( wparam ) ) { |
2014 |
case IDOK: |
case IDOK: |
2015 |
cmd = SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0); |
cmd = lookup_cmd (dlg); |
2016 |
if (cmd == LB_ERR) { |
if (cmd == LB_ERR) { |
2017 |
msg_box( dlg, _("Please select a command."), _("Key Edit"), MB_INFO ); |
msg_box( dlg, _("Please select a command."), _("Key Edit"), MB_INFO ); |
2018 |
return FALSE; |
return FALSE; |
2019 |
} |
} |
|
idxsub = listview_get_curr_pos (lvsub); |
|
2020 |
if (k->is_v3 && is_cmd_openpgp (cmd)) { |
if (k->is_v3 && is_cmd_openpgp (cmd)) { |
2021 |
msg_box (dlg, _("This command cannot be used with PGP 2 (v3) keys.\n"), |
msg_box (dlg, _("This command cannot be used with PGP 2 (v3) keys.\n"), |
2022 |
_("Key Edit"), MB_ERR); |
_("Key Edit"), MB_ERR); |
2036 |
case CMD_DELUID: do_editkey_deluid( k, dlg, lvuid ); break; |
case CMD_DELUID: do_editkey_deluid( k, dlg, lvuid ); break; |
2037 |
case CMD_PASSWD: keyedit_change_passwd( k, dlg ); break; |
case CMD_PASSWD: keyedit_change_passwd( k, dlg ); break; |
2038 |
case CMD_PRIMARY: do_editkey_primary( k, dlg, lvuid ); break; |
case CMD_PRIMARY: do_editkey_primary( k, dlg, lvuid ); break; |
2039 |
case CMD_ENABLE: km_enable_disable_key( lvsub, dlg, idxsub, 1 ); break; |
case CMD_ENABLE: do_editkey_enable_disable (k, dlg, lvsub, 1); break; |
2040 |
case CMD_DISABLE: km_enable_disable_key( lvsub, dlg, idxsub, 0 ); break; |
case CMD_DISABLE: do_editkey_enable_disable (k, dlg, lvsub, 0); break; |
2041 |
|
case CMD_CHECK: do_editkey_check (k, dlg); break; |
2042 |
|
case CMD_TRUST: keyedit_change_ownertrust (k, dlg); break; |
2043 |
|
case CMD_SIGN: |
2044 |
|
case CMD_LSIGN: do_editkey_sign_userid (k, dlg, |
2045 |
|
lvuid, cmd); |
2046 |
|
break; |
2047 |
} |
} |
2048 |
break; |
break; |
2049 |
|
|
2058 |
break; |
break; |
2059 |
} |
} |
2060 |
return FALSE; |
return FALSE; |
2061 |
} /* keyedit_main_dlg_proc */ |
} |
2062 |
|
|