32 |
#include "wptErrors.h" |
#include "wptErrors.h" |
33 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
34 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
35 |
|
#include "wptContext.h" |
36 |
|
|
37 |
|
|
38 |
#define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled) |
#define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled) |
155 |
count_subkeys (gpgme_key_t key) |
count_subkeys (gpgme_key_t key) |
156 |
{ |
{ |
157 |
gpgme_subkey_t k; |
gpgme_subkey_t k; |
158 |
int n = -1; /* ignore primary key */ |
int n = 1; |
159 |
|
|
160 |
k = key->subkeys; |
k = key->subkeys; |
161 |
if (!n) |
if (!k) |
162 |
return 0; |
return 0; |
163 |
while (k->next) { |
while (k->next) { |
164 |
k = k->next; |
k = k->next; |
293 |
{ |
{ |
294 |
switch (alg) { |
switch (alg) { |
295 |
case GPGME_PK_DSA: return "DSA"; |
case GPGME_PK_DSA: return "DSA"; |
296 |
|
case GPGME_PK_ELG: |
297 |
case GPGME_PK_ELG_E: return "ELG"; |
case GPGME_PK_ELG_E: return "ELG"; |
298 |
case GPGME_PK_RSA: return "RSA"; |
case GPGME_PK_RSA: return "RSA"; |
299 |
} |
} |
586 |
gpgme_key_t key, skey; |
gpgme_key_t key, skey; |
587 |
const char * keyid; |
const char * keyid; |
588 |
|
|
589 |
if( pubkc && seckc ) { |
if (pubkc && seckc) { |
590 |
gpgme_keycache_rewind( pubkc ); |
gpgme_keycache_rewind (pubkc); |
591 |
while( !gpgme_keycache_next_key( pubkc, 0, &key ) ) { |
while (!gpgme_keycache_next_key (pubkc, 0, &key)) { |
592 |
keyid = key->subkeys->keyid; |
keyid = key->subkeys->keyid; |
593 |
if( keyid && !gpgme_keycache_find_key( seckc, keyid, 0, &skey ) ) |
if (keyid && !gpgme_keycache_find_key (seckc, keyid, 0, &skey)) |
594 |
keylist_add_key (lv, mode, key); |
keylist_add_key (lv, mode, key); |
595 |
} |
} |
596 |
} |
} |
610 |
int mode, int sortby) |
int mode, int sortby) |
611 |
{ |
{ |
612 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
613 |
int rc = 0; |
int rc = 0; |
614 |
|
|
615 |
rc = keylist_build (&lv, ctrl, mode); |
rc = keylist_build (&lv, ctrl, mode); |
616 |
if (rc) |
if (rc) |
617 |
return NULL; |
return NULL; |
618 |
keylist_load_keycache (lv, mode, pubkc, seckc); |
keylist_load_keycache (lv, mode, pubkc, seckc); |
619 |
keylist_sort (lv, sortby); |
keylist_sort (lv, sortby); |
620 |
if( (mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN) ) |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) |
621 |
keylist_add_groups (lv); |
keylist_add_groups (lv); |
622 |
return lv; |
return lv; |
623 |
} /* keylist_load */ |
} /* keylist_load */ |
660 |
do_addkey (listview_ctrl_t lv, gpgme_key_t key, int uididx, int keyidx, int list) |
do_addkey (listview_ctrl_t lv, gpgme_key_t key, int uididx, int keyidx, int list) |
661 |
{ |
{ |
662 |
LV_ITEM lvi; |
LV_ITEM lvi; |
|
gpgme_key_t seckey; |
|
663 |
gpgme_user_id_t u; |
gpgme_user_id_t u; |
664 |
gpgme_subkey_t k; |
gpgme_subkey_t k; |
665 |
char fmt[128]; |
char fmt[128]; |
666 |
const char *attr; |
const char *attr; |
667 |
u32 key_attr; |
u32 key_attr; |
668 |
int idx = 0; |
int idx = 0; |
669 |
|
|
670 |
/* we check the pubkey algorithm here to make sure that no ElGamal |
/* we check the pubkey algorithm here to make sure that no ElGamal |
671 |
sign+encrypt key is used in _any_ mode */ |
sign+encrypt key is used in _any_ mode */ |
672 |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
673 |
|
log_debug ("ElGamal (E+S) key found: %s (%s)\n", |
674 |
|
key->uids->name, key->subkeys->keyid); |
675 |
return 0; |
return 0; |
676 |
|
} |
677 |
|
|
678 |
|
|
679 |
if (listview_add_item2 (lv, " ", (void *)key)) |
if (listview_add_item2 (lv, " ", (void *)key)) |
680 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
687 |
if( ListView_SetItem( lv->ctrl, &lvi ) == FALSE ) |
if( ListView_SetItem( lv->ctrl, &lvi ) == FALSE ) |
688 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
689 |
|
|
690 |
if( uididx == -1 ) { |
if( uididx == -1 ) { /* request the primary user-id of the key. */ |
|
/* request the primary user-id of the key. */ |
|
691 |
attr = key->uids->uid; |
attr = key->uids->uid; |
692 |
uididx = 0; |
uididx = 0; |
693 |
} |
} |
704 |
} |
} |
705 |
else { |
else { |
706 |
char * uid = utf8_to_wincp (attr, strlen (attr)); |
char * uid = utf8_to_wincp (attr, strlen (attr)); |
707 |
if( uid ) { |
if (uid) { |
708 |
listview_add_sub_item( lv, 0, idx++, uid ); |
listview_add_sub_item( lv, 0, idx++, uid ); |
709 |
free( uid ); |
free (uid); |
710 |
} |
} |
711 |
} |
} |
712 |
k = get_nth_key (key, keyidx); |
k = get_nth_key (key, keyidx); |
713 |
attr = k->keyid; |
if( k && k->keyid ) { |
714 |
if( attr ) { |
_snprintf( fmt, sizeof fmt -1, "0x%s", k->keyid + 8 ); |
|
_snprintf( fmt, sizeof fmt -1, "0x%s", attr + 8 ); |
|
715 |
listview_add_sub_item( lv, 0, idx++, fmt ); |
listview_add_sub_item( lv, 0, idx++, fmt ); |
716 |
} |
} |
717 |
if (list > 0) { |
if (list > 0) { |
718 |
attr = find_secret_key (key)? "pub/sec" : "pub"; |
attr = find_secret_key (key)? "pub/sec" : "pub"; |
719 |
if (strchr( attr, '/')) { |
if (strchr( attr, '/')) { |
720 |
const char * kid; |
struct winpt_key_s k; |
721 |
kid = key->subkeys->keyid; |
winpt_get_seckey (key->subkeys->keyid, &k); |
722 |
get_seckey( kid, &seckey ); |
if (k.ext->gloflags.divert_to_card) |
723 |
/*if( gpgme_key_get_ulong_attr( seckey, GPGME_ATTR_DIVERT_CARD, NULL, 0 ) ) |
attr = "pub/crd"; |
|
attr = "pub/crd"; XXX*/ |
|
724 |
} |
} |
725 |
listview_add_sub_item( lv, 0, idx++, attr ); |
listview_add_sub_item( lv, 0, idx++, attr ); |
726 |
} |
} |
808 |
{ |
{ |
809 |
int uids, rc = 0, i, n = 0; |
int uids, rc = 0, i, n = 0; |
810 |
gpgme_subkey_t k; |
gpgme_subkey_t k; |
811 |
|
|
812 |
for (i = 0; i < count_subkeys (key); i++) { |
for (k=key->subkeys, i = 0; i < count_subkeys (key); i++, k=k->next) { |
813 |
k = get_nth_key (key, i); |
if (k->invalid) { |
814 |
if (k->invalid) |
log_debug ("keylist_add_key: invalid key %s\n", key->uids->name); |
815 |
continue; /* Don't use invalid keys */ |
continue; /* Don't use invalid keys */ |
816 |
|
} |
817 |
|
|
818 |
if (mode & KEYLIST_ALL) { |
if (mode & KEYLIST_ALL) { |
819 |
uids = count_userids (key); |
uids = count_userids (key); |
888 |
int k_pos=0; |
int k_pos=0; |
889 |
char keyid[32], valid[32], id[100]; |
char keyid[32], valid[32], id[100]; |
890 |
key_array_s *ka = NULL; |
key_array_s *ka = NULL; |
|
gpgme_error_t err; |
|
891 |
gpgme_key_t *keybuf; |
gpgme_key_t *keybuf; |
892 |
|
|
893 |
n = listview_count_items( lv, 0 ); |
n = listview_count_items( lv, 0 ); |