410 |
} |
} |
411 |
|
|
412 |
|
|
413 |
|
/* To allow to sort the keys, we need to take care of |
414 |
|
the expired/revoke status also. */ |
415 |
|
static int |
416 |
|
get_ext_validity (gpgme_key_t k) |
417 |
|
{ |
418 |
|
if (k->revoked) |
419 |
|
return GPGME_VALIDITY_ULTIMATE+1; |
420 |
|
else if (k->expired) |
421 |
|
return GPGME_VALIDITY_ULTIMATE+2; |
422 |
|
return k->uids->validity; |
423 |
|
} |
424 |
|
|
425 |
|
|
426 |
/* List view sorting callback. */ |
/* List view sorting callback. */ |
427 |
static int CALLBACK |
static int CALLBACK |
428 |
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
429 |
{ |
{ |
430 |
gpgme_key_t a, b; |
gpgme_key_t a, b; |
431 |
int cmpresult = 0; |
int cmpresult = 0; |
432 |
|
|
433 |
a = (gpgme_key_t)first; |
a = (gpgme_key_t)first; |
445 |
b->subkeys->keyid+8); |
b->subkeys->keyid+8); |
446 |
break; |
break; |
447 |
|
|
448 |
case KEY_SORT_VALIDITY: /* XXX: handle expire, revoked */ |
case KEY_SORT_VALIDITY: |
449 |
cmpresult = int_cmp (a->uids->validity, b->uids->validity); |
cmpresult = int_cmp (get_ext_validity (a), |
450 |
|
get_ext_validity (b)); |
451 |
break; |
break; |
452 |
|
|
453 |
case KEY_SORT_OTRUST: /* XXX: handle expire, revoked */ |
case KEY_SORT_OTRUST: |
454 |
cmpresult = int_cmp (a->owner_trust, b->owner_trust); |
cmpresult = int_cmp (a->owner_trust, b->owner_trust); |
455 |
break; |
break; |
456 |
|
|
471 |
break; |
break; |
472 |
|
|
473 |
case KEY_SORT_ALGO: |
case KEY_SORT_ALGO: |
474 |
cmpresult = int_cmp (a->subkeys->pubkey_algo, |
cmpresult = int_cmp (a->subkeys->pubkey_algo, |
475 |
b->subkeys->pubkey_algo); |
b->subkeys->pubkey_algo); |
476 |
break; |
break; |
477 |
|
|
486 |
} |
} |
487 |
|
|
488 |
|
|
489 |
|
/* Return the validity of the group @grp. */ |
490 |
static const char* |
static const char* |
491 |
calc_validity (gpg_group_t grp) |
calc_validity (gpg_group_t grp) |
492 |
{ |
{ |
494 |
gpg_member_t mbr; |
gpg_member_t mbr; |
495 |
gpgme_key_t key; |
gpgme_key_t key; |
496 |
|
|
497 |
for( mbr = grp->list; mbr; mbr = mbr->next ) { |
for (mbr = grp->list; mbr; mbr = mbr->next) { |
498 |
if( get_pubkey( mbr->name, &key ) ) |
if (get_pubkey (mbr->name, &key)) |
499 |
continue; |
continue; |
500 |
valid = key->uids->validity; |
valid = key->uids->validity; |
501 |
switch( valid ) { |
switch (valid) { |
502 |
case GPGME_VALIDITY_MARGINAL: |
case GPGME_VALIDITY_MARGINAL: |
503 |
case GPGME_VALIDITY_NEVER: |
case GPGME_VALIDITY_NEVER: |
504 |
case GPGME_VALIDITY_UNDEFINED: |
case GPGME_VALIDITY_UNDEFINED: |
506 |
} |
} |
507 |
} |
} |
508 |
return _("Full"); |
return _("Full"); |
509 |
} /* calc_validity */ |
} |
510 |
|
|
511 |
|
|
512 |
int |
int |
535 |
} /* keylist_add_groups */ |
} /* keylist_add_groups */ |
536 |
|
|
537 |
|
|
538 |
|
/* Create a listview for listing keys. Use the mode given in @mode |
539 |
|
and the control is given in @ctrl. */ |
540 |
static int |
static int |
541 |
keylist_build( listview_ctrl_t *r_lv, HWND ctrl, int mode ) |
keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode) |
542 |
{ |
{ |
543 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
544 |
listview_column_t col; |
listview_column_t col; |
545 |
int j, n = 0; |
int j, n = 0; |
546 |
int kl_nolist = 0, rc = 0; |
int kl_nolist = 0, rc = 0; |
547 |
|
|
548 |
rc = listview_new( &lv ); |
rc = listview_new (&lv); |
549 |
if( rc ) |
if( rc ) |
550 |
return rc; |
return rc; |
551 |
|
|
552 |
lv->ctrl = ctrl; |
lv->ctrl = ctrl; |
553 |
if( (mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN) ) { |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) { |
554 |
col = klist_enc; |
col = klist_enc; |
555 |
n = KLIST_ENC_ITEMS; |
n = KLIST_ENC_ITEMS; |
556 |
} |
} |
557 |
else if( (mode & KEYLIST_SIGN) ) { |
else if ((mode & KEYLIST_SIGN)) { |
558 |
col = klist_enc; |
col = klist_enc; |
559 |
n = KLIST_ENC_ITEMS - 1; |
n = KLIST_ENC_ITEMS - 1; |
560 |
} |
} |
569 |
*r_lv = lv; |
*r_lv = lv; |
570 |
|
|
571 |
return 0; |
return 0; |
572 |
} /* keylist_build */ |
} |
573 |
|
|
574 |
|
|
575 |
static void |
static void |
596 |
keylist_add_key (lv, mode, key); |
keylist_add_key (lv, mode, key); |
597 |
} |
} |
598 |
} |
} |
599 |
} /* keylist_load_keycache */ |
} |
600 |
|
|
601 |
|
|
602 |
|
/* Load the list view @ctrl with the keys from the cache. |
603 |
|
Return value: list view context on success. */ |
604 |
listview_ctrl_t |
listview_ctrl_t |
605 |
keylist_load (HWND ctrl, gpg_keycache_t pubkc, gpg_keycache_t seckc, |
keylist_load (HWND ctrl, gpg_keycache_t pubkc, gpg_keycache_t seckc, |
606 |
int mode, int sortby) |
int mode, int sortby) |
616 |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) |
617 |
keylist_add_groups (lv); |
keylist_add_groups (lv); |
618 |
return lv; |
return lv; |
619 |
} /* keylist_load */ |
} |
620 |
|
|
621 |
|
|
622 |
|
/* Reload the given key list control @lv. */ |
623 |
int |
int |
624 |
keylist_reload( listview_ctrl_t lv, gpg_keycache_t pubkc, int mode, int sortby ) |
keylist_reload (listview_ctrl_t lv, gpg_keycache_t pubkc, int mode, int sortby) |
625 |
{ |
{ |
626 |
listview_del_all( lv ); |
listview_del_all (lv); |
627 |
keylist_load_keycache( lv, mode, pubkc, NULL ); |
keylist_load_keycache( lv, mode, pubkc, NULL ); |
628 |
keylist_sort( lv, sortby ); |
keylist_sort (lv, sortby); |
629 |
return 0; |
return 0; |
630 |
} /* keylist_reload */ |
} |
631 |
|
|
632 |
|
|
633 |
void |
void |
634 |
keylist_delete( listview_ctrl_t lv ) |
keylist_delete (listview_ctrl_t lv) |
635 |
{ |
{ |
636 |
if( lv ) { |
if (lv) { |
637 |
listview_release( lv ); |
listview_release (lv); |
638 |
} |
} |
639 |
} /* keylist_delete */ |
} |
640 |
|
|
641 |
|
|
642 |
|
/* Return if there is a secret for @key. |
643 |
|
0 means success. */ |
644 |
static int |
static int |
645 |
find_secret_key (gpgme_key_t key) |
find_secret_key (gpgme_key_t key) |
646 |
{ |
{ |
655 |
if (skey.ext && skey.ext->gloflags.divert_to_card) |
if (skey.ext && skey.ext->gloflags.divert_to_card) |
656 |
return 2; |
return 2; |
657 |
return skey.ctx? 1 : 0; |
return skey.ctx? 1 : 0; |
658 |
} /* find_secret_key */ |
} |
659 |
|
|
660 |
|
|
661 |
static int |
static int |
664 |
LV_ITEM lvi; |
LV_ITEM lvi; |
665 |
gpgme_user_id_t u; |
gpgme_user_id_t u; |
666 |
gpgme_subkey_t k; |
gpgme_subkey_t k; |
667 |
char fmt[128]; |
char fmt[128], *p; |
668 |
const char *attr; |
const char *attr; |
669 |
u32 key_attr; |
u32 key_attr; |
670 |
int idx = 0; |
int idx = 0; |
673 |
sign+encrypt key is used in _any_ mode */ |
sign+encrypt key is used in _any_ mode */ |
674 |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
675 |
log_debug ("ElGamal (E+S) key found: %s (%s)\n", |
log_debug ("ElGamal (E+S) key found: %s (%s)\n", |
676 |
key->uids->name, key->subkeys->keyid); |
key->uids->name, key->subkeys->keyid); |
677 |
return 0; |
return 0; |
678 |
} |
} |
679 |
|
|
680 |
|
|
681 |
if (listview_add_item2 (lv, " ", (void *)key)) |
if (listview_add_item2 (lv, " ", (void *)key)) |
682 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
683 |
|
|
684 |
attr = key->uids->uid; |
attr = key->uids->uid; |
685 |
memset( &lvi, 0, sizeof lvi ); |
memset (&lvi, 0, sizeof lvi); |
686 |
lvi.mask = LVIF_TEXT | LVIF_PARAM; |
lvi.mask = LVIF_TEXT | LVIF_PARAM; |
687 |
lvi.pszText = (char *)attr; |
lvi.pszText = (char *)attr; |
688 |
lvi.lParam = (LPARAM )key; |
lvi.lParam = (LPARAM )key; |
689 |
if( ListView_SetItem( lv->ctrl, &lvi ) == FALSE ) |
if (ListView_SetItem( lv->ctrl, &lvi ) == FALSE) |
690 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
691 |
|
|
692 |
if( uididx == -1 ) { /* request the primary user-id of the key. */ |
if (uididx == -1) { /* request the primary user-id of the key. */ |
693 |
attr = key->uids->uid; |
attr = key->uids->uid; |
694 |
uididx = 0; |
uididx = 0; |
695 |
} |
} |
698 |
if (!u || u->revoked || uididx < 0) |
if (!u || u->revoked || uididx < 0) |
699 |
uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */ |
uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */ |
700 |
u = get_nth_userid (key, uididx); |
u = get_nth_userid (key, uididx); |
701 |
attr = key->uids->uid; |
/*attr = key->uids->uid; XXX*/ |
702 |
|
attr = u->uid; |
703 |
} |
} |
704 |
if( attr == NULL || strlen( attr ) < 5 ) { /* normal userids are >= 5 chars */ |
if (attr == NULL || strlen (attr) < 5) { /* normal userids are >= 5 chars */ |
705 |
attr = _("Invalid User ID"); |
attr = _("Invalid User ID"); |
706 |
listview_add_sub_item( lv, 0, idx++, attr ); |
listview_add_sub_item (lv, 0, idx++, attr); |
707 |
} |
} |
708 |
else { |
else { |
709 |
char * uid = utf8_to_wincp (attr, strlen (attr)); |
char *uid = utf8_to_wincp (attr, strlen (attr)); |
710 |
if (uid) { |
if (uid) { |
711 |
listview_add_sub_item( lv, 0, idx++, uid ); |
listview_add_sub_item (lv, 0, idx++, uid); |
712 |
free (uid); |
free (uid); |
713 |
} |
} |
714 |
} |
} |
715 |
k = get_nth_key (key, keyidx); |
k = get_nth_key (key, keyidx); |
716 |
if( k && k->keyid ) { |
if (k && k->keyid) { |
717 |
_snprintf( fmt, sizeof fmt -1, "0x%s", k->keyid + 8 ); |
_snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8); |
718 |
listview_add_sub_item( lv, 0, idx++, fmt ); |
listview_add_sub_item( lv, 0, idx++, fmt ); |
719 |
} |
} |
720 |
if (list > 0) { |
if (list > 0) { |
736 |
listview_add_sub_item( lv, 0, idx++, attr); |
listview_add_sub_item( lv, 0, idx++, attr); |
737 |
} |
} |
738 |
if( lv->cols >= 4 ) { |
if( lv->cols >= 4 ) { |
739 |
char * status = get_key_status( key, uididx, list > 0? 1 : 0 ); |
p = get_key_status( key, uididx, list > 0? 1 : 0 ); |
740 |
if (!status) |
if (!p) |
741 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
742 |
listview_add_sub_item( lv, 0, idx++, status ); |
listview_add_sub_item (lv, 0, idx++, p); |
743 |
free_if_alloc( status ); |
free_if_alloc (p); |
744 |
} |
} |
745 |
if (lv->cols >= 5) { |
if (lv->cols >= 5) { |
746 |
const char * s = get_key_trust (key, uididx, list > 0? 1 : 0); |
attr = get_key_trust (key, uididx, list > 0? 1 : 0); |
747 |
listview_add_sub_item (lv, 0, idx++, s); |
listview_add_sub_item (lv, 0, idx++, attr); |
748 |
} |
} |
749 |
if( lv->cols >= 6 ) { |
if( lv->cols >= 6 ) { |
750 |
k = get_nth_key (key, keyidx); |
k = get_nth_key (key, keyidx); |
756 |
} |
} |
757 |
|
|
758 |
return 0; |
return 0; |
759 |
} /* do_addkey */ |
} |
760 |
|
|
761 |
|
|
762 |
void |
void |
1069 |
inf = new char[size+1]; |
inf = new char[size+1]; |
1070 |
if( !inf ) |
if( !inf ) |
1071 |
BUG( NULL ); |
BUG( NULL ); |
1072 |
_snprintf (inf, size, _("%s (%s/0x%s)"), uid, |
_snprintf (inf, size, "%s (%s/0x%s)", uid, |
1073 |
get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8); |
get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8); |
1074 |
combox_add_string (kb, inf); |
combox_add_string (kb, inf); |
1075 |
free_if_alloc (inf); |
free_if_alloc (inf); |