18 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
*/ |
*/ |
21 |
|
|
22 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
23 |
#include <config.h> |
#include <config.h> |
24 |
#endif |
#endif |
42 |
|
|
43 |
#define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled) |
#define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled) |
44 |
|
|
|
static struct listview_column_s klist_enc[] = { |
|
|
{0, 242, (char *)_("User ID")}, |
|
|
{1, 80, (char *)_("Key ID")}, |
|
|
{3, 46, (char *)_("Size")}, |
|
|
{4, 50, (char *)_("Cipher")}, |
|
|
{5, 70, (char *)_("Validity")}, |
|
|
{0, 0, NULL} |
|
|
}; |
|
|
#define KLIST_ENC_ITEMS (DIM(klist_enc) -1) |
|
|
|
|
|
static struct listview_column_s klist[] = { |
|
|
{0, 242, (char *)_("User ID")}, |
|
|
{1, 78, (char *)_("Key ID")}, |
|
|
{2, 52, (char *)_("Type")}, |
|
|
{3, 68, (char *)_("Size")}, |
|
|
{4, 66, (char *)_("Cipher")}, |
|
|
{5, 70, (char *)_("Validity")}, |
|
|
{6, 40, (char *)_("Trust")}, |
|
|
{7, 72, (char *)_("Creation")}, |
|
|
{0, 0, NULL} |
|
|
}; |
|
|
#define KLIST_ITEMS (DIM(klist) - 1) |
|
|
|
|
45 |
struct key_array_s { |
struct key_array_s { |
46 |
char keyid[32]; |
char keyid[32]; |
47 |
int checked; |
int checked; |
201 |
get_key_created (long timestamp) |
get_key_created (long timestamp) |
202 |
{ |
{ |
203 |
static char timebuf[128]; |
static char timebuf[128]; |
204 |
|
const char *dat; |
205 |
struct tm *warp; |
struct tm *warp; |
206 |
|
|
207 |
if (timestamp == 0 || timestamp == -1) |
if (timestamp == 0 || timestamp == -1) |
208 |
return "????" "-??" "-??"; |
return "????" "-??" "-??"; |
209 |
warp = localtime( ×tamp ); |
dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1); |
210 |
_snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d", |
if (dat) |
211 |
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday ); |
return dat; |
212 |
|
warp = localtime (×tamp); |
213 |
|
_snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d", |
214 |
|
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday); |
215 |
return timebuf; |
return timebuf; |
216 |
} /* get_key_created */ |
} |
217 |
|
|
218 |
|
|
219 |
/* Return a string presentation of the time @timestamp. */ |
/* Return a string presentation of the time @timestamp. */ |
242 |
else if (type == 2) |
else if (type == 2) |
243 |
return _("Key Pair (Card)"); |
return _("Key Pair (Card)"); |
244 |
return _("Public Key"); |
return _("Public Key"); |
245 |
} /* get_key_type */ |
} |
246 |
|
|
247 |
|
|
248 |
const char* |
const char* |
268 |
} |
} |
269 |
_snprintf( size_id, sizeof (size_id) - 1, "%d", size_main ); |
_snprintf( size_id, sizeof (size_id) - 1, "%d", size_main ); |
270 |
return size_id; |
return size_id; |
271 |
} /* get_key_size */ |
} |
272 |
|
|
273 |
|
|
274 |
const char* |
const char* |
275 |
|
get_key_pubalgo2 (gpgme_pubkey_algo_t alg) |
276 |
|
{ |
277 |
|
switch (alg) { |
278 |
|
case GPGME_PK_DSA: return "D"; |
279 |
|
case GPGME_PK_RSA: return "R"; |
280 |
|
case GPGME_PK_ELG: return "G"; |
281 |
|
default: return "?"; |
282 |
|
} |
283 |
|
return "?"; |
284 |
|
} |
285 |
|
|
286 |
|
const char* |
287 |
get_key_pubalgo (gpgme_pubkey_algo_t alg) |
get_key_pubalgo (gpgme_pubkey_algo_t alg) |
288 |
{ |
{ |
289 |
switch (alg) { |
switch (alg) { |
325 |
} |
} |
326 |
} |
} |
327 |
return fpr_md; |
return fpr_md; |
328 |
} /* get_key_fpr */ |
} |
329 |
|
|
330 |
|
|
331 |
const char * |
const char * |
374 |
if (uididx < 0 || count_userids (key) > uididx) |
if (uididx < 0 || count_userids (key) > uididx) |
375 |
uididx = 0; |
uididx = 0; |
376 |
if (listmode) { |
if (listmode) { |
377 |
const char *s; |
const char *s; |
|
|
|
378 |
if (key->revoked) |
if (key->revoked) |
379 |
s = _("Revoked"); |
s = _("Revoked"); |
380 |
else if (key->expired) |
else if (key->expired) |
381 |
s = _("Expired"); |
s = _("Expired"); |
382 |
else if (key->disabled) |
else if (key->disabled) |
383 |
s = _("Disabled"); |
s = _("Disabled"); |
384 |
else |
else |
385 |
s = ""; |
s = ""; |
|
|
|
386 |
/* if the key has a special status, we don't continue to figure out |
/* if the key has a special status, we don't continue to figure out |
387 |
what any user-id validities. */ |
what any user-id validities. */ |
388 |
if (*s) |
if (*s) |
487 |
static const char* |
static const char* |
488 |
calc_validity (gpg_group_t grp) |
calc_validity (gpg_group_t grp) |
489 |
{ |
{ |
490 |
int valid=0; |
int valid = 0; |
491 |
gpg_member_t mbr; |
gpg_member_t mbr; |
492 |
gpgme_key_t key; |
gpgme_key_t key; |
493 |
|
|
537 |
static int |
static int |
538 |
keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode) |
keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode) |
539 |
{ |
{ |
540 |
|
struct listview_column_s klist_enc[] = { |
541 |
|
{0, 242, (char *)_("User ID")}, |
542 |
|
{1, 80, (char *)_("Key ID")}, |
543 |
|
{3, 46, (char *)_("Size")}, |
544 |
|
{4, 50, (char *)_("Cipher")}, |
545 |
|
{5, 70, (char *)_("Validity")}, |
546 |
|
{0, 0, NULL} |
547 |
|
}; |
548 |
|
|
549 |
|
struct listview_column_s klist[] = { |
550 |
|
{0, 240, (char *)_("User ID")}, |
551 |
|
{1, 78, (char *)_("Key ID")}, |
552 |
|
{2, 52, (char *)_("Type")}, |
553 |
|
{3, 66, (char *)_("Size")}, |
554 |
|
{4, 60, (char *)_("Cipher")}, |
555 |
|
{5, 66, (char *)_("Validity")}, |
556 |
|
{6, 58, (char *)_("Trust")}, |
557 |
|
{7, 72, (char *)_("Creation")}, |
558 |
|
{0, 0, NULL} |
559 |
|
}; |
560 |
|
|
561 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
562 |
listview_column_t col; |
listview_column_t col; |
563 |
int j, n = 0; |
int j, n = 0; |
564 |
int rc = 0; |
int rc = 0; |
565 |
|
|
566 |
rc = listview_new (&lv); |
rc = listview_new (&lv); |
567 |
if( rc ) |
if (rc) |
568 |
return rc; |
return rc; |
569 |
|
|
570 |
lv->ctrl = ctrl; |
lv->ctrl = ctrl; |
571 |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) { |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) { |
572 |
col = klist_enc; |
col = klist_enc; |
573 |
n = KLIST_ENC_ITEMS; |
n = (DIM(klist_enc) -1); |
574 |
} |
} |
575 |
else if ((mode & KEYLIST_SIGN)) { |
else if ((mode & KEYLIST_SIGN)) { |
576 |
col = klist_enc; |
col = klist_enc; |
577 |
n = KLIST_ENC_ITEMS - 1; |
n = (DIM(klist_enc) - 1) - 1; |
578 |
} |
} |
579 |
else { |
else { |
580 |
col = klist; |
col = klist; |
581 |
n = KLIST_ITEMS; |
n = (DIM(klist) - 1); |
582 |
} |
} |
583 |
|
|
584 |
for( j = 0; j < n; j++ ) |
for( j = 0; j < n; j++ ) |
690 |
/* we check the pubkey algorithm here to make sure that no ElGamal |
/* we check the pubkey algorithm here to make sure that no ElGamal |
691 |
sign+encrypt key is used in _any_ mode */ |
sign+encrypt key is used in _any_ mode */ |
692 |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
693 |
log_debug ("ElGamal (E+S) key found: %s (%s)\n", |
log_debug ("ElGamal (E+S) key found: %s (%s)\n", |
694 |
key->uids->name, key->subkeys->keyid); |
key->uids->name, key->subkeys->keyid); |
695 |
return 0; |
return 0; |
696 |
} |
} |
697 |
|
|
698 |
|
|
699 |
if (listview_add_item2 (lv, " ", (void *)key)) |
if (listview_add_item2 (lv, " ", (void *)key)) |
700 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
701 |
|
|
702 |
attr = key->uids->uid; |
attr = key->uids->uid; |
703 |
memset (&lvi, 0, sizeof lvi); |
memset (&lvi, 0, sizeof lvi); |
704 |
lvi.mask = LVIF_TEXT | LVIF_PARAM; |
lvi.mask = LVIF_TEXT | LVIF_PARAM; |
705 |
lvi.pszText = (char *)attr; |
lvi.pszText = (char *)attr; |
706 |
lvi.lParam = (LPARAM )key; |
lvi.lParam = (LPARAM )key; |
707 |
if (ListView_SetItem( lv->ctrl, &lvi ) == FALSE) |
if (ListView_SetItem (lv->ctrl, &lvi) == FALSE) |
708 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
709 |
|
|
710 |
if (uididx == -1) { /* request the primary user-id of the key. */ |
if (uididx == -1) { /* request the primary user-id of the key. */ |
716 |
if (!u || u->revoked || uididx < 0) |
if (!u || u->revoked || uididx < 0) |
717 |
uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */ |
uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */ |
718 |
u = get_nth_userid (key, uididx); |
u = get_nth_userid (key, uididx); |
|
/*attr = key->uids->uid; XXX*/ |
|
719 |
attr = u->uid; |
attr = u->uid; |
720 |
} |
} |
721 |
if (attr == NULL || strlen (attr) < 5) { /* normal userids are >= 5 chars */ |
if (attr == NULL || strlen (attr) < 5) { /* normal userids are >= 5 chars */ |
776 |
} |
} |
777 |
|
|
778 |
|
|
779 |
|
/* Update a single column @col but for each element in the |
780 |
|
listview @lv. */ |
781 |
|
void |
782 |
|
keylist_upd_col (listview_ctrl_t lv, int col) |
783 |
|
{ |
784 |
|
gpgme_key_t key; |
785 |
|
const char *s; |
786 |
|
char buf[32]; |
787 |
|
int i; |
788 |
|
|
789 |
|
for (i=0; i < listview_count_items (lv, 0); i++) { |
790 |
|
key = (gpgme_key_t)listview_get_item2 (lv, i); |
791 |
|
if (!key) |
792 |
|
continue; |
793 |
|
switch (col) { |
794 |
|
case KM_COL_KEYID: |
795 |
|
_snprintf (buf, sizeof (buf)-1, "0x%s", key->subkeys->keyid+8); |
796 |
|
listview_add_sub_item (lv, i, col, buf); |
797 |
|
break; |
798 |
|
|
799 |
|
case KM_COL_CIPHER: |
800 |
|
s = get_key_algo (key, 0); |
801 |
|
listview_add_sub_item (lv, i, col, s); |
802 |
|
break; |
803 |
|
|
804 |
|
case KM_COL_TYPE: |
805 |
|
s = find_secret_key (key)? "pub/sec" : "pub"; |
806 |
|
listview_add_sub_item (lv, i, col, s); |
807 |
|
break; |
808 |
|
|
809 |
|
case KM_COL_CREAT: |
810 |
|
s = get_key_created (key->subkeys->timestamp); |
811 |
|
listview_add_sub_item (lv, i, col, s); |
812 |
|
break; |
813 |
|
} |
814 |
|
} |
815 |
|
} |
816 |
|
|
817 |
|
/* Update the listview item at position @pos with the data from |
818 |
|
the key @key. */ |
819 |
void |
void |
820 |
keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key) |
keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key) |
821 |
{ |
{ |
822 |
const char *s; |
const char *s; |
823 |
|
char *uid; |
824 |
char tmp[32]; |
char tmp[32]; |
825 |
|
|
826 |
listview_set_item2 (lv, pos, (void *)key); |
listview_set_item2 (lv, pos, (void *)key); |
827 |
/* the only mode we support is KYLIST_LIST in the Key Manager */ |
/* the only mode we support is KYLIST_LIST in the Key Manager */ |
828 |
|
|
829 |
s = key->uids->uid; |
s = key->uids->uid; |
830 |
if (s) |
if (s) { |
831 |
listview_add_sub_item (lv, pos, 0, s); |
uid = utf8_to_wincp2 (s); |
832 |
|
listview_add_sub_item (lv, pos, 0, uid); |
833 |
|
free (uid); |
834 |
|
} |
835 |
|
|
836 |
s = key->subkeys->keyid; |
s = key->subkeys->keyid; |
837 |
if (s) { |
if (s) { |
884 |
if (mode & KEYLIST_ALL) { |
if (mode & KEYLIST_ALL) { |
885 |
uids = count_userids (key); |
uids = count_userids (key); |
886 |
rc = do_addkey (lv, key, uids, i, 0); |
rc = do_addkey (lv, key, uids, i, 0); |
887 |
if( rc ) |
if (rc) |
888 |
return rc; |
return rc; |
889 |
} |
} |
890 |
else if (mode & KEYLIST_LIST) |
else if (mode & KEYLIST_LIST) |
897 |
return rc; |
return rc; |
898 |
} |
} |
899 |
else { |
else { |
900 |
for( uids = 0; uids < count_userids (key); uids++ ) { |
for (uids = 0; uids < count_userids (key); uids++) { |
901 |
rc = do_addkey( lv, key, uids, i, -1 ); |
rc = do_addkey (lv, key, uids, i, -1); |
902 |
if( rc ) |
if (rc) |
903 |
return rc; |
return rc; |
904 |
} |
} |
905 |
} |
} |
938 |
static int |
static int |
939 |
key_check_validity (const char *validity) |
key_check_validity (const char *validity) |
940 |
{ |
{ |
941 |
if (strstr (validity, "Unknown") || |
if (strstr (validity, _("Unknown")) || |
942 |
strstr (validity, "Undefined") || |
strstr (validity, _("Undefined")) || |
943 |
strstr (validity, "Never") || |
strstr (validity, _("Never")) || |
944 |
strstr (validity, "None")) |
strstr (validity, _("None"))) |
945 |
return 0; |
return 0; |
946 |
return 1; |
return 1; |
947 |
} |
} |