303 |
case GPGME_PK_DSA: return "DSA"; |
case GPGME_PK_DSA: return "DSA"; |
304 |
case GPGME_PK_ELG: |
case GPGME_PK_ELG: |
305 |
case GPGME_PK_ELG_E: return "ELG"; |
case GPGME_PK_ELG_E: return "ELG"; |
306 |
|
case 0: /* XXX: gpgme returned pubkey algo 0 for a RSA made sig. */ |
307 |
case GPGME_PK_RSA: return "RSA"; |
case GPGME_PK_RSA: return "RSA"; |
308 |
default: return "???"; |
default: return "???"; |
309 |
} |
} |
342 |
} |
} |
343 |
|
|
344 |
|
|
345 |
|
/* Extract the key ID from the fingerprint. |
346 |
|
A long ID will be converted into a short ID. */ |
347 |
|
const char* |
348 |
|
get_keyid_from_fpr (const char *fpr) |
349 |
|
{ |
350 |
|
if (!fpr) |
351 |
|
return "????????"; |
352 |
|
if (strlen (fpr) == 40) |
353 |
|
fpr += 32; |
354 |
|
else if (strlen (fpr) == 32) |
355 |
|
fpr += 24; |
356 |
|
else if (strlen (fpr) == 16) |
357 |
|
fpr += 8; |
358 |
|
else |
359 |
|
return "????????"; |
360 |
|
return fpr; |
361 |
|
} |
362 |
|
|
363 |
|
|
364 |
const char* |
const char* |
365 |
get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode) |
get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode) |
366 |
{ |
{ |
489 |
static int CALLBACK |
static int CALLBACK |
490 |
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
491 |
{ |
{ |
492 |
|
struct keycache_s *aa, *bb; |
493 |
gpgme_key_t a, b; |
gpgme_key_t a, b; |
494 |
int cmpresult = 0; |
int cmpresult = 0; |
495 |
|
|
496 |
a = (gpgme_key_t)first; |
aa = (struct keycache_s *)first; |
497 |
b = (gpgme_key_t)second; |
bb = (struct keycache_s *)second; |
498 |
if (!a || !b) |
if (!aa || !bb) |
499 |
BUG (NULL); |
BUG (NULL); |
500 |
|
a = aa->key; |
501 |
|
b = bb->key; |
502 |
|
|
503 |
switch (sortby & ~KEYLIST_SORT_DESC) { |
switch (sortby & ~KEYLIST_SORT_DESC) { |
504 |
case KEY_SORT_USERID: |
case KEY_SORT_USERID: |
629 |
{ |
{ |
630 |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
631 |
gpgme_key_t key, skey; |
gpgme_key_t key, skey; |
632 |
const char * keyid; |
struct keycache_s *c; |
633 |
|
const char *keyid; |
634 |
|
|
635 |
if (pubkc && seckc) { |
if (pubkc && seckc) { |
636 |
gpg_keycache_rewind (pubkc); |
gpg_keycache_rewind (pubkc); |
637 |
while (!gpg_keycache_next_key (pubkc, 0, &key)) { |
while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) { |
638 |
keyid = key->subkeys->keyid; |
keyid = key->subkeys->keyid; |
639 |
if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey)) |
if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey)) |
640 |
keylist_add_key (lv, mode, key); |
keylist_add_key (lv, mode, c, key); |
641 |
} |
} |
642 |
} |
} |
643 |
else if (pubkc) { |
else if (pubkc) { |
644 |
gpg_keycache_rewind (pubkc); |
gpg_keycache_rewind (pubkc); |
645 |
while (!err) { |
while (!err) { |
646 |
err = gpg_keycache_next_key (pubkc, 0, &key); |
err = gpg_keycache_next_key2 (pubkc, 0, &c, &key); |
647 |
if (!err) |
if (!err) |
648 |
keylist_add_key (lv, mode, key); |
keylist_add_key (lv, mode, c, key); |
649 |
} |
} |
650 |
} |
} |
651 |
} |
} |
711 |
|
|
712 |
|
|
713 |
static int |
static int |
714 |
do_addkey (listview_ctrl_t lv, gpgme_key_t key, int uididx, int keyidx, int list) |
do_addkey (listview_ctrl_t lv, struct keycache_s *ctx, gpgme_key_t key, |
715 |
|
int uididx, int keyidx, int list) |
716 |
{ |
{ |
717 |
LV_ITEM lvi; |
LV_ITEM lvi; |
718 |
gpgme_user_id_t u; |
gpgme_user_id_t u; |
729 |
key->uids->name, key->subkeys->keyid); |
key->uids->name, key->subkeys->keyid); |
730 |
return 0; |
return 0; |
731 |
} |
} |
732 |
|
|
733 |
if (listview_add_item2 (lv, " ", (void *)key)) |
if (listview_add_item2 (lv, " ", (void *)ctx)) |
734 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
735 |
|
|
736 |
attr = key->uids->uid; |
attr = ctx->uids->uid; |
737 |
memset (&lvi, 0, sizeof lvi); |
memset (&lvi, 0, sizeof lvi); |
738 |
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; |
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; |
739 |
lvi.pszText = (char *)attr; |
lvi.pszText = (char *)attr; |
740 |
lvi.iImage = find_secret_key (key)? 1 : 0; |
lvi.iImage = find_secret_key (key)? 1 : 0; |
741 |
lvi.lParam = (LPARAM )key; |
lvi.lParam = (LPARAM )ctx; |
742 |
if (ListView_SetItem (lv->ctrl, &lvi) == FALSE) |
if (ListView_SetItem (lv->ctrl, &lvi) == FALSE) |
743 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
744 |
|
|
745 |
if (uididx == -1) { /* request the primary user-id of the key. */ |
if (uididx == -1) { /* request the primary user-id of the key. */ |
746 |
attr = key->uids->uid; |
attr = ctx->uids->uid; |
747 |
uididx = 0; |
uididx = 0; |
748 |
} |
} |
749 |
else { |
else { |
757 |
attr = _("Invalid User ID"); |
attr = _("Invalid User ID"); |
758 |
listview_add_sub_item (lv, 0, idx++, attr); |
listview_add_sub_item (lv, 0, idx++, attr); |
759 |
} |
} |
760 |
else { |
else |
761 |
char *uid = utf8_to_native (attr); |
listview_add_sub_item (lv, 0, idx++, attr); |
|
if (uid) { |
|
|
listview_add_sub_item (lv, 0, idx++, uid); |
|
|
free (uid); |
|
|
} |
|
|
} |
|
762 |
k = get_nth_key (key, keyidx); |
k = get_nth_key (key, keyidx); |
763 |
if (k && k->keyid) { |
if (k && k->keyid) { |
764 |
_snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8); |
_snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8); |
765 |
listview_add_sub_item( lv, 0, idx++, fmt ); |
listview_add_sub_item (lv, 0, idx++, fmt); |
766 |
} |
} |
767 |
if (list > 0) { |
if (list > 0) { |
768 |
key_attr = find_secret_key (key); |
key_attr = find_secret_key (key); |
817 |
int i; |
int i; |
818 |
|
|
819 |
for (i=0; i < listview_count_items (lv, 0); i++) { |
for (i=0; i < listview_count_items (lv, 0); i++) { |
820 |
key = (gpgme_key_t)listview_get_item2 (lv, i); |
key = km_get_key_ptr (lv, i, NULL); |
821 |
if (!key) |
if (!key) |
822 |
continue; |
continue; |
823 |
switch (col) { |
switch (col) { |
854 |
/* Update the listview item at position @pos with the data from |
/* Update the listview item at position @pos with the data from |
855 |
the key @key. */ |
the key @key. */ |
856 |
void |
void |
857 |
keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key) |
keylist_upd_key (listview_ctrl_t lv, int pos, |
858 |
|
struct keycache_s *ctx, gpgme_key_t key) |
859 |
{ |
{ |
860 |
const char *s; |
const char *s; |
861 |
char *uid, *p; |
char *p; |
862 |
char tmp[32]; |
char tmp[32]; |
863 |
|
|
864 |
listview_set_item2 (lv, pos, (void *)key); |
listview_set_item2 (lv, pos, (void *)ctx); |
865 |
/* the only mode we support is KYLIST_LIST in the Key Manager */ |
/* the only mode we support is KEYLIST_LIST in the Key Manager */ |
866 |
|
|
867 |
s = key->uids->uid; |
s = ctx->uids->uid; |
868 |
if (s) { |
if (s) |
869 |
uid = utf8_to_native (s); |
listview_add_sub_item (lv, pos, KM_COL_UID, s); |
|
listview_add_sub_item (lv, pos, KM_COL_UID, uid); |
|
|
free (uid); |
|
|
} |
|
870 |
|
|
871 |
s = key->subkeys->keyid; |
s = key->subkeys->keyid; |
872 |
if (s) { |
if (s) { |
903 |
|
|
904 |
|
|
905 |
int |
int |
906 |
keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key) |
keylist_add_key (listview_ctrl_t lv, int mode, |
907 |
|
struct keycache_s *ctx, gpgme_key_t key) |
908 |
{ |
{ |
909 |
int uids, rc = 0, i; |
int uids, rc = 0, i; |
910 |
gpgme_subkey_t k; |
gpgme_subkey_t k; |
921 |
|
|
922 |
if (mode & KEYLIST_ALL) { |
if (mode & KEYLIST_ALL) { |
923 |
uids = count_userids (key); |
uids = count_userids (key); |
924 |
rc = do_addkey (lv, key, uids, i, 0); |
rc = do_addkey (lv, ctx, key, uids, i, 0); |
925 |
if (rc) |
if (rc) |
926 |
return rc; |
return rc; |
927 |
} |
} |
928 |
else if (mode & KEYLIST_LIST) |
else if (mode & KEYLIST_LIST) |
929 |
return do_addkey (lv, key, -1, i, 1); |
return do_addkey (lv, ctx, key, -1, i, 1); |
930 |
else if (mode & KEYLIST_ENCRYPT) { |
else if (mode & KEYLIST_ENCRYPT) { |
931 |
if (k->can_encrypt && key_is_useable (k)) { |
if (k->can_encrypt && key_is_useable (k)) { |
932 |
if (mode & KEYLIST_FLAG_FILE) { |
if (mode & KEYLIST_FLAG_FILE) { |
933 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
934 |
if (rc) |
if (rc) |
935 |
return rc; |
return rc; |
936 |
} |
} |
937 |
else { |
else { |
938 |
for (uids = 0; uids < count_userids (key); uids++) { |
for (uids = 0; uids < count_userids (key); uids++) { |
939 |
rc = do_addkey (lv, key, uids, i, -1); |
rc = do_addkey (lv, ctx, key, uids, i, -1); |
940 |
if (rc) |
if (rc) |
941 |
return rc; |
return rc; |
942 |
} |
} |
946 |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
947 |
if( k->can_encrypt && key_is_useable (k)) |
if( k->can_encrypt && key_is_useable (k)) |
948 |
{ |
{ |
949 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
950 |
return rc; |
return rc; |
951 |
} |
} |
952 |
} |
} |
954 |
if (k->can_sign |
if (k->can_sign |
955 |
&& find_secret_key (key) |
&& find_secret_key (key) |
956 |
&& key_is_useable (k)) { |
&& key_is_useable (k)) { |
957 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
958 |
if (rc) |
if (rc) |
959 |
return rc; |
return rc; |
960 |
} |
} |
995 |
keylist_get_recipients (listview_ctrl_t lv, int *r_force_trust, int *r_count) |
keylist_get_recipients (listview_ctrl_t lv, int *r_force_trust, int *r_count) |
996 |
{ |
{ |
997 |
key_array_s *ka = NULL; |
key_array_s *ka = NULL; |
998 |
|
keycache_s *c; |
999 |
gpgme_key_t *keybuf, key; |
gpgme_key_t *keybuf, key; |
1000 |
int count = 0, force_trust = 0; |
int count = 0, force_trust = 0; |
1001 |
int n, j, ka_pos = 0, rc = 0; |
int n, j, ka_pos = 0, rc = 0; |
1013 |
|
|
1014 |
for (j = 0; j < n; j++) { |
for (j = 0; j < n; j++) { |
1015 |
if (listview_get_item_state (lv, j) || n == 1) { |
if (listview_get_item_state (lv, j) || n == 1) { |
1016 |
key = (gpgme_key_t)listview_get_item2 (lv, j); |
key = km_get_key_ptr (lv, j, &c); |
1017 |
if (!key) |
if (!key) |
1018 |
BUG (0); |
BUG (0); |
1019 |
if (!key_check_validity (key) && |
if (!key_check_validity (key) && |
1020 |
!key_array_search (ka, ka_pos, key->subkeys->keyid)) { |
!key_array_search (ka, ka_pos, key->subkeys->keyid)) { |
1021 |
char *utf8_uid = utf8_to_native (key->uids->uid); |
char *warn = new char[512+strlen (c->uids->uid) + 1]; |
|
char *warn = new char[512+strlen (utf8_uid) + 1]; |
|
1022 |
if (!warn) |
if (!warn) |
1023 |
BUG (0); |
BUG (0); |
1024 |
sprintf (warn, |
sprintf (warn, |
1026 |
"named in the user ID. If you *really* know what you are\n" |
"named in the user ID. If you *really* know what you are\n" |
1027 |
"doing, you may answer the next question with yes\n" |
"doing, you may answer the next question with yes\n" |
1028 |
"\n" |
"\n" |
1029 |
"Use \"%s\" anyway?"), utf8_uid); |
"Use \"%s\" anyway?"), c->uids->uid); |
1030 |
if (reg_prefs.always_trust) |
if (reg_prefs.always_trust) |
1031 |
rc = IDYES; |
rc = IDYES; |
1032 |
else |
else |
1038 |
strcpy (ka[ka_pos++].keyid, key->subkeys->keyid); |
strcpy (ka[ka_pos++].keyid, key->subkeys->keyid); |
1039 |
count++; |
count++; |
1040 |
} |
} |
|
safe_free (utf8_uid); |
|
1041 |
free_if_alloc (warn); |
free_if_alloc (warn); |
1042 |
} |
} |
1043 |
else { |
else { |
1074 |
gpgme_key_t* |
gpgme_key_t* |
1075 |
keylist_enum_recipients (listview_ctrl_t lv, int listype, int *r_count) |
keylist_enum_recipients (listview_ctrl_t lv, int listype, int *r_count) |
1076 |
{ |
{ |
1077 |
|
struct keycache_s *c; |
1078 |
gpgme_key_t *rset; |
gpgme_key_t *rset; |
1079 |
gpgme_key_t key; |
gpgme_key_t key; |
1080 |
int i, n, id, k_pos=0; |
int i, n, id, k_pos=0; |
1088 |
for (i = 0; i < n; i++) { |
for (i = 0; i < n; i++) { |
1089 |
if (!listview_get_item_state (lv, i)) |
if (!listview_get_item_state (lv, i)) |
1090 |
continue; |
continue; |
1091 |
key = (gpgme_key_t)listview_get_item2 (lv, i); |
key = km_get_key_ptr (lv, i, &c); |
|
if (!key) |
|
|
BUG (0); |
|
1092 |
switch (listype) { |
switch (listype) { |
1093 |
case KEYLIST_LIST: |
case KEYLIST_LIST: |
1094 |
if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) { |
if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) { |
1095 |
id = printf_box (_("Recipients"), MB_INFO|MB_YESNO, |
id = printf_box (_("Recipients"), MB_INFO|MB_YESNO, |
1096 |
_("KeyID %s.\nDo you really want to export a revoked key?"), |
_("KeyID %s.\nDo you really want to export a revoked key?"), |
1097 |
key->uids->uid); |
c->uids->uid); |
1098 |
if (id == IDNO) |
if (id == IDNO) |
1099 |
continue; |
continue; |
1100 |
} |
} |