321 |
return "???"; |
return "???"; |
322 |
} |
} |
323 |
|
|
324 |
|
|
325 |
const char* |
const char* |
326 |
get_key_fpr (gpgme_key_t key) |
get_key_fpr (gpgme_key_t key) |
327 |
{ |
{ |
573 |
|
|
574 |
/* Create a listview for listing keys. Use the mode given in @mode |
/* Create a listview for listing keys. Use the mode given in @mode |
575 |
and the control is given in @ctrl. */ |
and the control is given in @ctrl. */ |
576 |
static int |
static void |
577 |
keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode) |
keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode) |
578 |
{ |
{ |
579 |
struct listview_column_s klist_enc[] = { |
struct listview_column_s klist_enc[] = { |
595 |
{7, 72, (char *)_("Creation")}, |
{7, 72, (char *)_("Creation")}, |
596 |
{0, 0, NULL} |
{0, 0, NULL} |
597 |
}; |
}; |
598 |
HICON ico[4]; |
HICON ico[6]; |
599 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
600 |
listview_column_t col; |
listview_column_t col; |
601 |
int j, n = 0, ext_chk = 0; |
int j, n = 0, ext_chk = 0; |
620 |
listview_add_column (lv, &col[j]); |
listview_add_column (lv, &col[j]); |
621 |
listview_set_ext_style (lv); |
listview_set_ext_style (lv); |
622 |
if (ext_chk) |
if (ext_chk) |
623 |
listview_set_chkbox_style (lv); |
listview_set_chkbox_style (lv); |
624 |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY); |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY); |
625 |
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR); |
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR); |
626 |
ico[2] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_DOWNARROW); |
ico[2] = LoadIcon (glob_hinst, (LPCTSTR)IDI_REV_KEYPAIR); |
627 |
ico[3] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_UPARROW); |
ico[3] = LoadIcon (glob_hinst, (LPCTSTR)IDI_REV_PUBKEY); |
628 |
listview_set_image_list (lv, 22, 14, ico, 4); |
ico[4] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_DOWNARROW); |
629 |
|
ico[5] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_UPARROW); |
630 |
|
listview_set_image_list (lv, 22, 14, ico, DIM (ico)); |
631 |
listview_del_all_items (lv); |
listview_del_all_items (lv); |
632 |
|
|
633 |
*r_lv = lv; |
*r_lv = lv; |
|
return 0; |
|
634 |
} |
} |
635 |
|
|
636 |
|
|
669 |
int mode, int sortby) |
int mode, int sortby) |
670 |
{ |
{ |
671 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
|
int rc = 0; |
|
672 |
|
|
673 |
rc = keylist_build (&lv, ctrl, mode); |
keylist_build (&lv, ctrl, mode); |
|
if (rc) |
|
|
return NULL; |
|
674 |
keylist_load_keycache (lv, mode, pubkc, seckc); |
keylist_load_keycache (lv, mode, pubkc, seckc); |
675 |
keylist_sort (lv, sortby); |
keylist_sort (lv, sortby); |
676 |
if (mode & KEYLIST_ENCRYPT_MIN) |
if (mode & KEYLIST_ENCRYPT_MIN) |
704 |
static int |
static int |
705 |
find_secret_key (gpgme_key_t key) |
find_secret_key (gpgme_key_t key) |
706 |
{ |
{ |
|
const char *keyid; |
|
707 |
winpt_key_s skey; |
winpt_key_s skey; |
708 |
|
|
709 |
memset (&skey, 0, sizeof (skey)); |
if (!key->subkeys->keyid) |
|
keyid = key->subkeys->keyid; |
|
|
if (!keyid) |
|
710 |
return 0; |
return 0; |
711 |
winpt_get_seckey (keyid, &skey); |
memset (&skey, 0, sizeof (skey)); |
712 |
|
winpt_get_seckey (key->subkeys->keyid, &skey); |
713 |
if (skey.ext && skey.ext->gloflags.divert_to_card) |
if (skey.ext && skey.ext->gloflags.divert_to_card) |
714 |
return 2; |
return 2; |
715 |
return skey.ctx? 1 : 0; |
return skey.ctx? 1 : 0; |
716 |
} |
} |
717 |
|
|
718 |
|
|
719 |
|
/* Enumeration for possible key icons. */ |
720 |
|
enum key_icontype_t { |
721 |
|
IMG_KEY_PUB = 0, |
722 |
|
IMG_KEY_PAIR = 1, |
723 |
|
IMG_KEY_PAIR_REV = 2, |
724 |
|
IMG_KEY_PUB_REV = 3 |
725 |
|
}; |
726 |
|
|
727 |
|
|
728 |
|
static int |
729 |
|
key_get_image_id (gpgme_key_t key) |
730 |
|
{ |
731 |
|
if (find_secret_key (key)) |
732 |
|
return key->revoked ? IMG_KEY_PAIR_REV :IMG_KEY_PAIR; |
733 |
|
if (key->revoked) |
734 |
|
return IMG_KEY_PUB_REV; |
735 |
|
return IMG_KEY_PUB; |
736 |
|
} |
737 |
|
|
738 |
|
|
739 |
static int |
static int |
740 |
do_addkey (listview_ctrl_t lv, struct keycache_s *ctx, gpgme_key_t key, |
do_addkey (listview_ctrl_t lv, struct keycache_s *ctx, gpgme_key_t key, |
741 |
int uididx, int keyidx, int list) |
int uididx, int keyidx, int list) |
743 |
LV_ITEM lvi; |
LV_ITEM lvi; |
744 |
gpgme_user_id_t u; |
gpgme_user_id_t u; |
745 |
gpgme_subkey_t k; |
gpgme_subkey_t k; |
746 |
char fmt[128], *p; |
char *p; |
747 |
const char *attr; |
const char *attr; |
748 |
u32 key_attr; |
int idx = 0; |
|
int idx = 0; |
|
749 |
|
|
750 |
/* we check the pubkey algorithm here to make sure that no ElGamal |
/* we check the pubkey algorithm here to make sure that no ElGamal |
751 |
sign+encrypt key is used in _any_ mode */ |
sign+encrypt key is used in _any_ mode */ |
762 |
memset (&lvi, 0, sizeof lvi); |
memset (&lvi, 0, sizeof lvi); |
763 |
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; |
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; |
764 |
lvi.pszText = (char *)attr; |
lvi.pszText = (char *)attr; |
765 |
lvi.iImage = find_secret_key (key)? 1 : 0; |
lvi.iImage = key_get_image_id (key); |
766 |
lvi.lParam = (LPARAM )ctx; |
lvi.lParam = (LPARAM )ctx; |
767 |
if (ListView_SetItem (lv->ctrl, &lvi) == FALSE) |
if (ListView_SetItem (lv->ctrl, &lvi) == FALSE) |
768 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
785 |
else |
else |
786 |
listview_add_sub_item (lv, 0, idx++, attr); |
listview_add_sub_item (lv, 0, idx++, attr); |
787 |
k = get_nth_key (key, keyidx); |
k = get_nth_key (key, keyidx); |
788 |
if (k && k->keyid) { |
if (k && k->keyid != NULL) { |
789 |
_snprintf (fmt, DIM (fmt) -1, "0x%s", k->keyid + 8); |
char keyid[16+1]; |
790 |
listview_add_sub_item (lv, 0, idx++, fmt); |
|
791 |
|
_snprintf (keyid, DIM (keyid) -1, "0x%s", k->keyid + 8); |
792 |
|
listview_add_sub_item (lv, 0, idx++, keyid); |
793 |
} |
} |
794 |
if (list > 0) { |
if (list > 0) { |
795 |
key_attr = find_secret_key (key); |
DWORD key_attr = find_secret_key (key); |
796 |
if (!key_attr) |
if (!key_attr) |
797 |
attr = "pub"; |
attr = "pub"; |
798 |
else |
else |
801 |
} |
} |
802 |
if (lv->cols >= 2) { |
if (lv->cols >= 2) { |
803 |
attr = get_key_size (key, list == -1? keyidx+1 : 0); |
attr = get_key_size (key, list == -1? keyidx+1 : 0); |
804 |
if (attr) |
if (attr != NULL) |
805 |
listview_add_sub_item (lv, 0, idx++, attr); |
listview_add_sub_item (lv, 0, idx++, attr); |
806 |
} |
} |
807 |
if (lv->cols >= 3) { |
if (lv->cols >= 3) { |
808 |
attr = get_key_algo (key, list == -1? keyidx+1 : 0); |
attr = get_key_algo (key, list == -1? keyidx+1 : 0); |
809 |
if (attr) |
if (attr != NULL) |
810 |
listview_add_sub_item( lv, 0, idx++, attr); |
listview_add_sub_item( lv, 0, idx++, attr); |
811 |
} |
} |
812 |
if (lv->cols >= 4) { |
if (lv->cols >= 4) { |
813 |
p = get_key_status( key, uididx, list > 0? 1 : 0 ); |
p = get_key_status (key, uididx, list > 0? 1 : 0); |
814 |
if (!p) |
if (p != NULL) |
815 |
return WPTERR_GENERAL; |
listview_add_sub_item (lv, 0, idx++, p); |
|
listview_add_sub_item (lv, 0, idx++, p); |
|
816 |
free_if_alloc (p); |
free_if_alloc (p); |
817 |
} |
} |
818 |
if (lv->cols >= 5) { |
if (lv->cols >= 5) { |
819 |
attr = get_key_trust (key, uididx, list > 0? 1 : 0); |
attr = get_key_trust (key, uididx, list > 0? 1 : 0); |
820 |
listview_add_sub_item (lv, 0, idx++, attr); |
listview_add_sub_item (lv, 0, idx++, attr); |
821 |
} |
} |
822 |
if( lv->cols >= 6 ) { |
if (lv->cols >= 6) { |
823 |
k = get_nth_key (key, keyidx); |
k = get_nth_key (key, keyidx); |
824 |
key_attr = k->timestamp; |
if (k->timestamp > 0) { |
825 |
if( key_attr ) { |
attr = get_key_created (k->timestamp); |
826 |
attr = get_key_created (key_attr); |
listview_add_sub_item (lv, 0, idx++, attr); |
827 |
listview_add_sub_item( lv, 0, idx++, attr ); |
} |
|
} |
|
828 |
} |
} |
829 |
|
|
830 |
return 0; |
return 0; |