83 |
int j; |
int j; |
84 |
|
|
85 |
for (j = 0; j < items; j++) { |
for (j = 0; j < items; j++) { |
86 |
if (!strcmp (keyid, ka[j].keyid )) |
if (!strcmp (keyid, ka[j].keyid)) |
87 |
return 1; |
return 1; |
88 |
} |
} |
89 |
return 0; |
return 0; |
155 |
/* Return the self signature of the key @keyid. |
/* Return the self signature of the key @keyid. |
156 |
If first is set, the first self sig will be returned. */ |
If first is set, the first self sig will be returned. */ |
157 |
gpgme_key_sig_t |
gpgme_key_sig_t |
158 |
get_selfsig (gpgme_user_id_t uid, const char *keyid, int first) |
get_selfsig (gpgme_key_sig_t sigs, const char *keyid, int first) |
159 |
{ |
{ |
160 |
gpgme_key_sig_t s, self_sig=NULL; |
gpgme_key_sig_t s, self_sig=NULL; |
161 |
long timestamp=0; |
long timestamp=0; |
164 |
if (strlen (keyid) == 8) |
if (strlen (keyid) == 8) |
165 |
off = 8; |
off = 8; |
166 |
|
|
167 |
for (s = uid->signatures; s; s = s->next) { |
for (s = sigs; s; s = s->next) { |
168 |
if (!strcmp (s->keyid+off, keyid) && s->timestamp > timestamp) { |
if (!strcmp (s->keyid+off, keyid) && s->timestamp > timestamp) { |
169 |
self_sig = s; |
self_sig = s; |
170 |
timestamp = s->timestamp; |
timestamp = s->timestamp; |
176 |
} |
} |
177 |
|
|
178 |
|
|
|
|
|
179 |
const char* |
const char* |
180 |
get_key_algo (gpgme_key_t key, int keyidx) |
get_key_algo (gpgme_key_t key, int keyidx) |
181 |
{ |
{ |
194 |
strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo)); |
strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo)); |
195 |
n = count_subkeys (key); |
n = count_subkeys (key); |
196 |
if (n > 1) { |
if (n > 1) { |
197 |
k = get_nth_key (key, n-1); |
do { |
198 |
|
k = get_nth_key (key, --n); |
199 |
|
if (k->revoked || k->expired) |
200 |
|
continue; |
201 |
|
else |
202 |
|
break; |
203 |
|
} while (n > 0); |
204 |
subalg = get_key_pubalgo (k->pubkey_algo); |
subalg = get_key_pubalgo (k->pubkey_algo); |
205 |
_snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg); |
if (k == key->subkeys) |
206 |
|
_snprintf (algo_id, DIM (algo_id)-1, "%s", subalg); |
207 |
|
else |
208 |
|
_snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg); |
209 |
return algo_id; |
return algo_id; |
210 |
} |
} |
211 |
return get_key_pubalgo (key->subkeys->pubkey_algo); |
return get_key_pubalgo (key->subkeys->pubkey_algo); |
221 |
|
|
222 |
if (timestamp < 1) |
if (timestamp < 1) |
223 |
return "????" "-??" "-??"; |
return "????" "-??" "-??"; |
224 |
dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1); |
dat = get_locale_date (timestamp, timebuf, DIM (timebuf)-1); |
225 |
if (dat) |
if (dat) |
226 |
return dat; |
return dat; |
227 |
|
/* Fallback if locate date conversion failed. */ |
228 |
warp = localtime (×tamp); |
warp = localtime (×tamp); |
229 |
_snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d", |
_snprintf (timebuf, DIM (timebuf) - 1, "%04d-%02d-%02d", |
230 |
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday); |
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday); |
231 |
return timebuf; |
return timebuf; |
232 |
} |
} |
242 |
|
|
243 |
if (timestamp == 0) |
if (timestamp == 0) |
244 |
return _("Never"); |
return _("Never"); |
245 |
dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1); |
dat = get_locale_date (timestamp, timebuf, DIM (timebuf)-1); |
246 |
if (dat) |
if (dat) |
247 |
return dat; |
return dat; |
248 |
warp = localtime (×tamp); |
warp = localtime (×tamp); |
249 |
_snprintf (timebuf, sizeof timebuf -1, "%04d-%02d-%02d", |
_snprintf (timebuf, DIM (timebuf) -1, "%04d-%02d-%02d", |
250 |
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday); |
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday); |
251 |
return timebuf; |
return timebuf; |
252 |
} |
} |
283 |
if (n > 1) { |
if (n > 1) { |
284 |
k = get_nth_key (key, n-1); |
k = get_nth_key (key, n-1); |
285 |
size_sub = k->length; |
size_sub = k->length; |
286 |
_snprintf (size_id, sizeof (size_id) - 1, "%d/%d", |
_snprintf (size_id, DIM (size_id) - 1, "%d/%d", |
287 |
size_main, size_sub); |
size_main, size_sub); |
288 |
return size_id; |
return size_id; |
289 |
} |
} |
290 |
_snprintf( size_id, sizeof (size_id) - 1, "%d", size_main ); |
_snprintf (size_id, DIM (size_id) - 1, "%d", size_main); |
291 |
return size_id; |
return size_id; |
292 |
} |
} |
293 |
|
|
312 |
case GPGME_PK_DSA: return "DSA"; |
case GPGME_PK_DSA: return "DSA"; |
313 |
case GPGME_PK_ELG: |
case GPGME_PK_ELG: |
314 |
case GPGME_PK_ELG_E: return "ELG"; |
case GPGME_PK_ELG_E: return "ELG"; |
315 |
case GPGME_PK_RSA: return "RSA"; |
case 0: /* XXX: do we still need this?? */ |
316 |
|
case GPGME_PK_RSA: |
317 |
|
case GPGME_PK_RSA_S: |
318 |
|
case GPGME_PK_RSA_E: return "RSA"; |
319 |
default: return "???"; |
default: return "???"; |
320 |
} |
} |
321 |
return "???"; |
return "???"; |
353 |
} |
} |
354 |
|
|
355 |
|
|
356 |
|
/* Extract the key ID from the fingerprint. |
357 |
|
A long ID will be converted into a short ID. */ |
358 |
|
const char* |
359 |
|
get_keyid_from_fpr (const char *fpr) |
360 |
|
{ |
361 |
|
if (!fpr) |
362 |
|
return "????????"; |
363 |
|
if (strlen (fpr) == 40) |
364 |
|
fpr += 32; |
365 |
|
else if (strlen (fpr) == 32) |
366 |
|
fpr += 24; |
367 |
|
else if (strlen (fpr) == 16) |
368 |
|
fpr += 8; |
369 |
|
else |
370 |
|
return "????????"; |
371 |
|
return fpr; |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
const char* |
const char* |
376 |
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) |
377 |
{ |
{ |
386 |
case GPGME_VALIDITY_MARGINAL: |
case GPGME_VALIDITY_MARGINAL: |
387 |
return _("Marginal"); |
return _("Marginal"); |
388 |
case GPGME_VALIDITY_FULL: |
case GPGME_VALIDITY_FULL: |
|
case GPGME_VALIDITY_ULTIMATE: |
|
389 |
return _("Full"); |
return _("Full"); |
390 |
|
case GPGME_VALIDITY_ULTIMATE: |
391 |
|
return _("Ultimate"); |
392 |
} |
} |
393 |
return ""; |
return ""; |
394 |
} |
} |
395 |
|
|
396 |
|
|
397 |
const char * |
const char* |
398 |
get_key_trust (gpgme_key_t key, int uididx, int listmode) |
get_key_trust (gpgme_key_t key, int uididx, int listmode) |
399 |
{ |
{ |
400 |
return get_key_trust2 (key, 0, uididx, listmode); |
return get_key_trust2 (key, 0, uididx, listmode); |
401 |
} |
} |
402 |
|
|
403 |
|
|
404 |
const char * |
const char* |
405 |
get_key_trust_str (int val) |
get_key_trust_str (int val) |
406 |
{ |
{ |
407 |
return get_key_trust2 (NULL, val, 0, 0); |
return get_key_trust2 (NULL, val, 0, 0); |
440 |
} |
} |
441 |
|
|
442 |
|
|
443 |
|
/* Return human readable description of the key @key. */ |
444 |
|
char* |
445 |
|
get_key_desc (gpgme_key_t key) |
446 |
|
{ |
447 |
|
gpgme_key_t sk; |
448 |
|
const char *state, *alg, *type; |
449 |
|
char *p; |
450 |
|
|
451 |
|
/* XXX: problems with the German translation. */ |
452 |
|
state = ""; |
453 |
|
if (key->disabled) |
454 |
|
state = _("Disabled"); |
455 |
|
if (key->expired) |
456 |
|
state = _("Expired"); |
457 |
|
if (key->revoked) |
458 |
|
state = _("Revoked"); |
459 |
|
alg = "OpenPGP"; |
460 |
|
if (strlen (key->subkeys->fpr) == 32) |
461 |
|
alg = "RSA Legacy"; |
462 |
|
type = _("public key"); |
463 |
|
if (!get_seckey (key->subkeys->keyid+8, &sk)) |
464 |
|
type = _("key pair"); |
465 |
|
p = new char[strlen (state) + strlen (alg) + strlen (type) + 4 + 1]; |
466 |
|
if (!p) |
467 |
|
BUG (0); |
468 |
|
sprintf (p, "%s %s %s", state, alg, type); |
469 |
|
return p; |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
/* Integer comparsion of @a and @b. |
/* Integer comparsion of @a and @b. |
474 |
Return values: same as in strcmp. */ |
Return values: same as in strcmp. */ |
475 |
static inline int |
static inline int |
491 |
return GPGME_VALIDITY_ULTIMATE+1; |
return GPGME_VALIDITY_ULTIMATE+1; |
492 |
else if (k->expired) |
else if (k->expired) |
493 |
return GPGME_VALIDITY_ULTIMATE+2; |
return GPGME_VALIDITY_ULTIMATE+2; |
494 |
|
else if (k->disabled) |
495 |
|
return GPGME_VALIDITY_ULTIMATE+3; |
496 |
return k->uids->validity; |
return k->uids->validity; |
497 |
} |
} |
498 |
|
|
501 |
static int CALLBACK |
static int CALLBACK |
502 |
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
503 |
{ |
{ |
504 |
|
struct keycache_s *aa, *bb; |
505 |
gpgme_key_t a, b; |
gpgme_key_t a, b; |
506 |
int cmpresult = 0; |
int cmpresult = 0; |
507 |
|
|
508 |
a = (gpgme_key_t)first; |
aa = (struct keycache_s *)first; |
509 |
b = (gpgme_key_t)second; |
bb = (struct keycache_s *)second; |
510 |
if (!a || !b) |
if (!aa || !bb) |
511 |
BUG (NULL); |
BUG (NULL); |
512 |
|
a = aa->key; |
513 |
|
b = bb->key; |
514 |
|
|
515 |
switch (sortby & ~KEYLIST_SORT_DESC) { |
switch (sortby & ~KEYLIST_SORT_DESC) { |
516 |
case KEY_SORT_USERID: |
case KEY_SORT_USERID: |
563 |
} |
} |
564 |
|
|
565 |
|
|
|
#if 0 |
|
|
/* Return the validity of the group @grp. */ |
|
|
static const char* |
|
|
calc_validity (gpg_group_t grp) |
|
|
{ |
|
|
int valid = 0; |
|
|
gpg_member_t mbr; |
|
|
gpgme_key_t key; |
|
|
|
|
|
for (mbr = grp->list; mbr; mbr = mbr->next) { |
|
|
if (get_pubkey (mbr->name, &key)) |
|
|
continue; |
|
|
valid = key->uids->validity; |
|
|
switch (valid) { |
|
|
case GPGME_VALIDITY_MARGINAL: |
|
|
case GPGME_VALIDITY_NEVER: |
|
|
case GPGME_VALIDITY_UNDEFINED: |
|
|
return get_key_trust2 (NULL, valid, 0, 0); |
|
|
} |
|
|
} |
|
|
return _("Full"); |
|
|
} |
|
|
#endif |
|
|
|
|
|
|
|
566 |
int |
int |
567 |
keylist_add_groups (listview_ctrl_t lv) |
keylist_add_groups (listview_ctrl_t lv) |
568 |
{ |
{ |
594 |
{7, 72, (char *)_("Creation")}, |
{7, 72, (char *)_("Creation")}, |
595 |
{0, 0, NULL} |
{0, 0, NULL} |
596 |
}; |
}; |
597 |
HICON ico[2]; |
HICON ico[4]; |
598 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
599 |
listview_column_t col; |
listview_column_t col; |
600 |
int j, n = 0; |
int j, n = 0, ext_chk = 0; |
|
int rc = 0; |
|
601 |
|
|
602 |
rc = listview_new (&lv); |
listview_new (&lv, ctrl); |
603 |
if (rc) |
if (mode & KEYLIST_ENCRYPT_MIN) { |
|
return rc; |
|
|
|
|
|
lv->ctrl = ctrl; |
|
|
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) { |
|
604 |
col = klist_enc; |
col = klist_enc; |
605 |
n = (DIM(klist_enc) -1); |
n = (DIM (klist_enc) -1); |
606 |
|
ext_chk = 1; |
607 |
} |
} |
608 |
else if ((mode & KEYLIST_SIGN)) { |
else if ((mode & KEYLIST_SIGN)) { |
609 |
col = klist_enc; |
col = klist_enc; |
610 |
n = (DIM(klist_enc) - 1) - 1; |
n = (DIM (klist_enc) - 1) - 1; |
611 |
|
ext_chk = 1; |
612 |
} |
} |
613 |
else { |
else { |
614 |
col = klist; |
col = klist; |
615 |
n = (DIM(klist) - 1); |
n = (DIM (klist) - 1); |
616 |
} |
} |
617 |
|
|
618 |
for (j = 0; j < n; j++) |
for (j = 0; j < n; j++) |
619 |
listview_add_column (lv, &col[j]); |
listview_add_column (lv, &col[j]); |
620 |
listview_set_ext_style (lv); |
listview_set_ext_style (lv); |
621 |
|
if (ext_chk) |
622 |
|
listview_set_chkbox_style (lv); |
623 |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY); |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY); |
624 |
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR); |
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR); |
625 |
listview_set_image_list (lv, ico, 2); |
ico[2] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_DOWNARROW); |
626 |
|
ico[3] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_UPARROW); |
627 |
|
listview_set_image_list (lv, 22, 14, ico, 4); |
628 |
|
listview_del_all_items (lv); |
629 |
|
|
630 |
*r_lv = lv; |
*r_lv = lv; |
631 |
return 0; |
return 0; |
638 |
{ |
{ |
639 |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
640 |
gpgme_key_t key, skey; |
gpgme_key_t key, skey; |
641 |
const char * keyid; |
struct keycache_s *c; |
642 |
|
const char *keyid; |
643 |
|
|
644 |
if (pubkc && seckc) { |
if (pubkc && seckc) { |
645 |
gpg_keycache_rewind (pubkc); |
gpg_keycache_rewind (pubkc); |
646 |
while (!gpg_keycache_next_key (pubkc, 0, &key)) { |
while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) { |
647 |
keyid = key->subkeys->keyid; |
keyid = key->subkeys->keyid; |
648 |
if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey)) |
if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey)) |
649 |
keylist_add_key (lv, mode, key); |
keylist_add_key (lv, mode, c, key); |
650 |
} |
} |
651 |
} |
} |
652 |
else if (pubkc) { |
else if (pubkc) { |
653 |
gpg_keycache_rewind (pubkc); |
gpg_keycache_rewind (pubkc); |
654 |
while (!err) { |
while (!err) { |
655 |
err = gpg_keycache_next_key (pubkc, 0, &key); |
err = gpg_keycache_next_key2 (pubkc, 0, &c, &key); |
656 |
if (!err) |
if (!err) |
657 |
keylist_add_key (lv, mode, key); |
keylist_add_key (lv, mode, c, key); |
658 |
} |
} |
659 |
} |
} |
660 |
} |
} |
674 |
return NULL; |
return NULL; |
675 |
keylist_load_keycache (lv, mode, pubkc, seckc); |
keylist_load_keycache (lv, mode, pubkc, seckc); |
676 |
keylist_sort (lv, sortby); |
keylist_sort (lv, sortby); |
677 |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) |
if (mode & KEYLIST_ENCRYPT_MIN) |
678 |
keylist_add_groups (lv); |
keylist_add_groups (lv); |
679 |
return lv; |
return lv; |
680 |
} |
} |
684 |
int |
int |
685 |
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) |
686 |
{ |
{ |
687 |
listview_del_all (lv); |
listview_del_all_items (lv); |
688 |
keylist_load_keycache( lv, mode, pubkc, NULL ); |
keylist_load_keycache (lv, mode, pubkc, NULL); |
689 |
keylist_sort (lv, sortby); |
keylist_sort (lv, sortby); |
690 |
return 0; |
return 0; |
691 |
} |
} |
720 |
|
|
721 |
|
|
722 |
static int |
static int |
723 |
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, |
724 |
|
int uididx, int keyidx, int list) |
725 |
{ |
{ |
726 |
LV_ITEM lvi; |
LV_ITEM lvi; |
727 |
gpgme_user_id_t u; |
gpgme_user_id_t u; |
738 |
key->uids->name, key->subkeys->keyid); |
key->uids->name, key->subkeys->keyid); |
739 |
return 0; |
return 0; |
740 |
} |
} |
741 |
|
|
742 |
if (listview_add_item2 (lv, " ", (void *)key)) |
if (listview_add_item2 (lv, " ", (void *)ctx)) |
743 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
744 |
|
|
745 |
attr = key->uids->uid; |
attr = ctx->uids->uid; |
746 |
memset (&lvi, 0, sizeof lvi); |
memset (&lvi, 0, sizeof lvi); |
747 |
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; |
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; |
748 |
lvi.pszText = (char *)attr; |
lvi.pszText = (char *)attr; |
749 |
lvi.iImage = find_secret_key (key)? 1 : 0; |
lvi.iImage = find_secret_key (key)? 1 : 0; |
750 |
lvi.lParam = (LPARAM )key; |
lvi.lParam = (LPARAM )ctx; |
751 |
if (ListView_SetItem (lv->ctrl, &lvi) == FALSE) |
if (ListView_SetItem (lv->ctrl, &lvi) == FALSE) |
752 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
753 |
|
|
754 |
if (uididx == -1) { /* request the primary user-id of the key. */ |
if (uididx == -1) { /* request the primary user-id of the key. */ |
755 |
attr = key->uids->uid; |
attr = ctx->uids->uid; |
756 |
uididx = 0; |
uididx = 0; |
757 |
} |
} |
758 |
else { |
else { |
766 |
attr = _("Invalid User ID"); |
attr = _("Invalid User ID"); |
767 |
listview_add_sub_item (lv, 0, idx++, attr); |
listview_add_sub_item (lv, 0, idx++, attr); |
768 |
} |
} |
769 |
else { |
else |
770 |
char *uid = utf8_to_wincp (attr, strlen (attr)); |
listview_add_sub_item (lv, 0, idx++, attr); |
|
if (uid) { |
|
|
listview_add_sub_item (lv, 0, idx++, uid); |
|
|
free (uid); |
|
|
} |
|
|
} |
|
771 |
k = get_nth_key (key, keyidx); |
k = get_nth_key (key, keyidx); |
772 |
if (k && k->keyid) { |
if (k && k->keyid) { |
773 |
_snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8); |
_snprintf (fmt, DIM (fmt) -1, "0x%s", k->keyid + 8); |
774 |
listview_add_sub_item( lv, 0, idx++, fmt ); |
listview_add_sub_item (lv, 0, idx++, fmt); |
775 |
} |
} |
776 |
if (list > 0) { |
if (list > 0) { |
777 |
key_attr = find_secret_key (key); |
key_attr = find_secret_key (key); |
791 |
if (attr) |
if (attr) |
792 |
listview_add_sub_item( lv, 0, idx++, attr); |
listview_add_sub_item( lv, 0, idx++, attr); |
793 |
} |
} |
794 |
if( lv->cols >= 4 ) { |
if (lv->cols >= 4) { |
795 |
p = get_key_status( key, uididx, list > 0? 1 : 0 ); |
p = get_key_status( key, uididx, list > 0? 1 : 0 ); |
796 |
if (!p) |
if (!p) |
797 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
822 |
{ |
{ |
823 |
gpgme_key_t key; |
gpgme_key_t key; |
824 |
const char *s; |
const char *s; |
825 |
char buf[32]; |
char buf[32], *p; |
826 |
int i; |
int i; |
827 |
|
|
828 |
for (i=0; i < listview_count_items (lv, 0); i++) { |
for (i=0; i < listview_count_items (lv, 0); i++) { |
829 |
key = (gpgme_key_t)listview_get_item2 (lv, i); |
key = km_get_key_ptr (lv, i, NULL); |
830 |
if (!key) |
if (!key) |
831 |
continue; |
continue; |
832 |
switch (col) { |
switch (col) { |
833 |
case KM_COL_KEYID: |
case KM_COL_KEYID: |
834 |
_snprintf (buf, sizeof (buf)-1, "0x%s", key->subkeys->keyid+8); |
_snprintf (buf, DIM (buf)-1, "0x%s", key->subkeys->keyid+8); |
835 |
listview_add_sub_item (lv, i, col, buf); |
listview_add_sub_item (lv, i, col, buf); |
836 |
break; |
break; |
837 |
|
|
849 |
s = get_key_created (key->subkeys->timestamp); |
s = get_key_created (key->subkeys->timestamp); |
850 |
listview_add_sub_item (lv, i, col, s); |
listview_add_sub_item (lv, i, col, s); |
851 |
break; |
break; |
852 |
|
|
853 |
|
case KM_COL_DESC: |
854 |
|
p = get_key_desc (key); |
855 |
|
listview_add_sub_item (lv, i, col, p); |
856 |
|
free_if_alloc (p); |
857 |
|
break; |
858 |
} |
} |
859 |
} |
} |
860 |
} |
} |
863 |
/* Update the listview item at position @pos with the data from |
/* Update the listview item at position @pos with the data from |
864 |
the key @key. */ |
the key @key. */ |
865 |
void |
void |
866 |
keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key) |
keylist_upd_key (listview_ctrl_t lv, int pos, |
867 |
|
struct keycache_s *ctx, gpgme_key_t key) |
868 |
{ |
{ |
869 |
const char *s; |
const char *s; |
870 |
char *uid; |
char *p; |
871 |
char tmp[32]; |
char tmp[32]; |
872 |
|
|
873 |
listview_set_item2 (lv, pos, (void *)key); |
listview_set_item2 (lv, pos, (void *)ctx); |
874 |
/* the only mode we support is KYLIST_LIST in the Key Manager */ |
/* the only mode we support is KEYLIST_LIST in the Key Manager */ |
875 |
|
|
876 |
s = key->uids->uid; |
s = ctx->uids->uid; |
877 |
if (s) { |
if (s) |
878 |
uid = utf8_to_wincp2 (s); |
listview_add_sub_item (lv, pos, KM_COL_UID, s); |
|
listview_add_sub_item (lv, pos, 0, uid); |
|
|
free (uid); |
|
|
} |
|
879 |
|
|
880 |
s = key->subkeys->keyid; |
s = key->subkeys->keyid; |
881 |
if (s) { |
if (s) { |
882 |
sprintf (tmp, "0x%s", s+8); |
sprintf (tmp, "0x%s", s+8); |
883 |
listview_add_sub_item (lv, pos, 1, tmp); |
listview_add_sub_item (lv, pos, KM_COL_KEYID, tmp); |
884 |
} |
} |
885 |
|
|
886 |
s = find_secret_key (key)? "pub/sec" : "pub"; |
s = find_secret_key (key)? "pub/sec" : "pub"; |
887 |
listview_add_sub_item (lv, pos, 2, s); |
listview_add_sub_item (lv, pos, KM_COL_TYPE, s); |
888 |
|
|
889 |
s = get_key_size (key, 0); |
s = get_key_size (key, 0); |
890 |
if (s) |
if (s) |
891 |
listview_add_sub_item (lv, pos, 3, s); |
listview_add_sub_item (lv, pos, KM_COL_SIZE, s); |
892 |
|
|
893 |
s = get_key_algo (key, 0); |
s = get_key_algo (key, 0); |
894 |
if (s) |
if (s) |
895 |
listview_add_sub_item (lv, pos, 4, s); |
listview_add_sub_item (lv, pos, KM_COL_CIPHER, s); |
896 |
|
|
897 |
s = get_key_status (key, 0, 1); |
p = get_key_status (key, 0, 1); |
898 |
if (s) |
if (p) { |
899 |
listview_add_sub_item (lv, pos, 5, s); |
listview_add_sub_item (lv, pos, KM_COL_VALID, p); |
900 |
|
free_if_alloc (p); |
901 |
|
} |
902 |
|
|
903 |
s = get_key_trust (key, 0, 1); |
s = get_key_trust (key, 0, 1); |
904 |
if (s) |
if (s) |
905 |
listview_add_sub_item (lv, pos, 6, s); |
listview_add_sub_item (lv, pos, KM_COL_TRUST, s); |
906 |
|
|
907 |
long t = key->subkeys->timestamp; |
long t = key->subkeys->timestamp; |
908 |
s = get_key_created (t); |
s = get_key_created (t); |
909 |
if (s) |
if (s) |
910 |
listview_add_sub_item (lv, pos, 7, s); |
listview_add_sub_item (lv, pos, KM_COL_CREAT, s); |
911 |
} |
} |
912 |
|
|
913 |
|
|
914 |
int |
int |
915 |
keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key) |
keylist_add_key (listview_ctrl_t lv, int mode, |
916 |
|
struct keycache_s *ctx, gpgme_key_t key) |
917 |
{ |
{ |
918 |
int uids, rc = 0, i; |
int uids, rc = 0, i; |
919 |
gpgme_subkey_t k; |
gpgme_subkey_t k; |
930 |
|
|
931 |
if (mode & KEYLIST_ALL) { |
if (mode & KEYLIST_ALL) { |
932 |
uids = count_userids (key); |
uids = count_userids (key); |
933 |
rc = do_addkey (lv, key, uids, i, 0); |
rc = do_addkey (lv, ctx, key, uids, i, 0); |
934 |
if (rc) |
if (rc) |
935 |
return rc; |
return rc; |
936 |
} |
} |
937 |
else if (mode & KEYLIST_LIST) |
else if (mode & KEYLIST_LIST) |
938 |
return do_addkey (lv, key, -1, i, 1); |
return do_addkey (lv, ctx, key, -1, i, 1); |
939 |
else if (mode & KEYLIST_ENCRYPT) { |
else if (mode & KEYLIST_ENCRYPT) { |
940 |
if (k->can_encrypt && key_is_useable (k)) { |
if (k->can_encrypt && key_is_useable (k)) { |
941 |
if (mode & KEYLIST_FLAG_FILE) { |
if (mode & KEYLIST_FLAG_FILE) { |
942 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
943 |
if (rc) |
if (rc) |
944 |
return rc; |
return rc; |
945 |
} |
} |
946 |
else { |
else { |
947 |
for (uids = 0; uids < count_userids (key); uids++) { |
for (uids = 0; uids < count_userids (key); uids++) { |
948 |
rc = do_addkey (lv, key, uids, i, -1); |
rc = do_addkey (lv, ctx, key, uids, i, -1); |
949 |
if (rc) |
if (rc) |
950 |
return rc; |
return rc; |
951 |
} |
} |
955 |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
956 |
if( k->can_encrypt && key_is_useable (k)) |
if( k->can_encrypt && key_is_useable (k)) |
957 |
{ |
{ |
958 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
959 |
return rc; |
return rc; |
960 |
} |
} |
961 |
} |
} |
963 |
if (k->can_sign |
if (k->can_sign |
964 |
&& find_secret_key (key) |
&& find_secret_key (key) |
965 |
&& key_is_useable (k)) { |
&& key_is_useable (k)) { |
966 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
967 |
if (rc) |
if (rc) |
968 |
return rc; |
return rc; |
969 |
} |
} |
976 |
|
|
977 |
int |
int |
978 |
keylist_sort (listview_ctrl_t lv, int sortby) |
keylist_sort (listview_ctrl_t lv, int sortby) |
979 |
{ |
{ |
980 |
return listview_sort_items (lv, sortby, keylist_cmp_cb); |
return listview_sort_items (lv, sortby, keylist_cmp_cb); |
981 |
} |
} |
982 |
|
|
1001 |
fully trusted. @r_count returns the number of selected keys. |
fully trusted. @r_count returns the number of selected keys. |
1002 |
Return value: the key list on success, NULL otherwise. */ |
Return value: the key list on success, NULL otherwise. */ |
1003 |
gpgme_key_t* |
gpgme_key_t* |
1004 |
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, size_t *r_count) |
1005 |
{ |
{ |
1006 |
key_array_s *ka = NULL; |
key_array_s *ka = NULL; |
1007 |
|
keycache_s *c; |
1008 |
gpgme_key_t *keybuf, key; |
gpgme_key_t *keybuf, key; |
1009 |
int count = 0, force_trust = 0; |
size_t count = 0; |
1010 |
|
int force_trust = 0; |
1011 |
int n, j, ka_pos = 0, rc = 0; |
int n, j, ka_pos = 0, rc = 0; |
1012 |
int k_pos=0; |
int k_pos=0; |
1013 |
|
|
1017 |
if (!ka) |
if (!ka) |
1018 |
BUG (NULL); |
BUG (NULL); |
1019 |
|
|
1020 |
keybuf = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); |
keybuf = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t)); |
1021 |
if (!keybuf) |
if (!keybuf) |
1022 |
BUG (NULL); |
BUG (NULL); |
1023 |
|
|
1024 |
for (j = 0; j < n; j++) { |
for (j = 0; j < n; j++) { |
1025 |
if (listview_get_item_state (lv, j) || n == 1) { |
if (listview_get_item_state (lv, j) || n == 1) { |
1026 |
key = (gpgme_key_t)listview_get_item2 (lv, j); |
key = km_get_key_ptr (lv, j, &c); |
1027 |
if (!key) |
if (!key) |
1028 |
BUG (0); |
BUG (0); |
1029 |
if (!key_check_validity (key) && |
if (!key_check_validity (key) && |
1030 |
!key_array_search (ka, ka_pos, key->subkeys->keyid)) { |
!key_array_search (ka, ka_pos, key->subkeys->keyid)) { |
1031 |
char *warn = new char[512+strlen (key->uids->uid) + 1]; |
char *warn = new char[512+strlen (c->uids->uid) + 1]; |
1032 |
if (!warn) |
if (!warn) |
1033 |
BUG (0); |
BUG (0); |
1034 |
sprintf (warn, |
sprintf (warn, |
1036 |
"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" |
1037 |
"doing, you may answer the next question with yes\n" |
"doing, you may answer the next question with yes\n" |
1038 |
"\n" |
"\n" |
1039 |
"Use \"%s\" anyway?"), key->uids->uid); |
"Use \"%s\" anyway?"), c->uids->uid); |
1040 |
if (reg_prefs.always_trust) |
if (reg_prefs.always_trust) |
1041 |
rc = IDYES; |
rc = IDYES; |
1042 |
else |
else |
1082 |
|
|
1083 |
|
|
1084 |
gpgme_key_t* |
gpgme_key_t* |
1085 |
keylist_enum_recipients (listview_ctrl_t lv, int listype, int *r_count) |
keylist_enum_recipients (listview_ctrl_t lv, int listype, size_t *r_count) |
1086 |
{ |
{ |
1087 |
|
struct keycache_s *c; |
1088 |
gpgme_key_t *rset; |
gpgme_key_t *rset; |
1089 |
gpgme_key_t key; |
gpgme_key_t key; |
1090 |
int i, n, id, k_pos=0; |
size_t k_pos = 0; |
1091 |
|
int i, n, id; |
1092 |
|
|
1093 |
n = listview_count_items (lv, 0); |
n = listview_count_items (lv, 0); |
1094 |
if (!n) |
if (!n) |
1095 |
return 0; |
return 0; |
1096 |
rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); |
rset = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t)); |
1097 |
if (!rset) |
if (!rset) |
1098 |
BUG (NULL); |
BUG (NULL); |
1099 |
for (i = 0; i < n; i++) { |
for (i = 0; i < n; i++) { |
1100 |
if (!listview_get_item_state (lv, i)) |
if (!listview_get_item_state (lv, i)) |
1101 |
continue; |
continue; |
1102 |
key = (gpgme_key_t)listview_get_item2 (lv, i); |
key = km_get_key_ptr (lv, i, &c); |
|
if (!key) |
|
|
BUG (0); |
|
1103 |
switch (listype) { |
switch (listype) { |
1104 |
case KEYLIST_LIST: |
case KEYLIST_LIST: |
1105 |
if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) { |
if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) { |
1106 |
id = printf_box (_("Recipients"), MB_INFO|MB_YESNO, |
id = printf_box (_("Recipients"), MB_INFO|MB_YESNO, |
1107 |
_("KeyID %s.\nDo you really want to export a revoked key?"), |
_("KeyID %s.\nDo you really want to export a revoked key?"), |
1108 |
key->uids->uid); |
c->uids->uid); |
1109 |
if (id == IDNO) |
if (id == IDNO) |
1110 |
continue; |
continue; |
1111 |
} |
} |
1166 |
if (key->disabled || !key_is_useable (key->subkeys)) |
if (key->disabled || !key_is_useable (key->subkeys)) |
1167 |
continue; |
continue; |
1168 |
|
|
1169 |
uid = utf8_to_wincp (id, strlen (id)); |
uid = utf8_to_native (id); |
1170 |
size = strlen (uid) + strlen (keyid) + 32; |
size = strlen (uid) + strlen (keyid) + 32; |
1171 |
inf = new char[size+1]; |
inf = new char[size+1]; |
1172 |
if (!inf) |
if (!inf) |