1 |
/* wptKeylist.cpp - Keylist element |
/* wptKeylist.cpp - Keylist element |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-2006 Timo Schulz |
3 |
* Copyright (C) 2004 Andreas Jobs |
* Copyright (C) 2004 Andreas Jobs |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
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 |
38 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
39 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
40 |
#include "wptContext.h" |
#include "wptContext.h" |
41 |
|
#include "wptVersion.h" |
42 |
|
#include "resource.h" |
43 |
|
|
44 |
#define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled) |
#define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled) |
45 |
|
|
|
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) |
|
|
|
|
46 |
struct key_array_s { |
struct key_array_s { |
47 |
char keyid[32]; |
char keyid[32]; |
48 |
int checked; |
int checked; |
52 |
|
|
53 |
|
|
54 |
static key_array_s* |
static key_array_s* |
55 |
key_array_new( size_t items ) |
key_array_new (int items) |
56 |
{ |
{ |
57 |
key_array_s *ka; |
key_array_s *ka; |
58 |
size_t j; |
int j; |
59 |
|
|
60 |
if( items == 0 ) |
if (items == 0) |
61 |
return NULL; |
return NULL; |
62 |
ka = new key_array_s[items + 1]; |
ka = new key_array_s[items + 1]; |
63 |
if( ka == NULL ) |
if (!ka) |
64 |
return NULL; |
BUG (NULL); |
65 |
for ( j = 0; j < items; j++ ) |
for (j = 0; j < items; j++) |
66 |
ka[j].checked = 0; |
ka[j].checked = 0; |
67 |
return ka; |
return ka; |
68 |
} /* key_array_new */ |
} |
69 |
|
|
70 |
|
|
71 |
static void |
static void |
72 |
key_array_release( key_array_s *ka ) |
key_array_release (key_array_s *ka) |
73 |
{ |
{ |
74 |
free_if_alloc( ka ); |
free_if_alloc (ka); |
75 |
} /* key_array_release */ |
} |
76 |
|
|
77 |
|
|
78 |
|
/* Check if the keyid @keyid is in the key array @ka. |
79 |
|
Return value: 1 if it exists, 0 otherwise. */ |
80 |
static int |
static int |
81 |
key_array_search( key_array_s *ka, size_t items, const char *keyid ) |
key_array_search (key_array_s *ka, int items, const char *keyid) |
82 |
{ |
{ |
83 |
size_t j; |
int j; |
84 |
|
|
85 |
/* fixme: we need a faster search method */ |
for (j = 0; j < items; j++) { |
86 |
for( j = 0; j < items; j++ ) { |
if (!strcmp (keyid, ka[j].keyid )) |
|
if( !strcmp( keyid, ka[j].keyid ) ) |
|
87 |
return 1; |
return 1; |
88 |
} |
} |
|
|
|
89 |
return 0; |
return 0; |
90 |
} /* key_array_search */ |
} |
91 |
|
|
92 |
|
|
93 |
gpgme_user_id_t |
gpgme_user_id_t |
152 |
} |
} |
153 |
|
|
154 |
|
|
155 |
|
/* Return the self signature of the key @keyid. |
156 |
|
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_user_id_t uid, 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; |
162 |
|
int off = 0; |
163 |
|
|
164 |
|
if (strlen (keyid) == 8) |
165 |
|
off = 8; |
166 |
|
|
167 |
for (s = uid->signatures; s; s = s->next) { |
for (s = uid->signatures; s; s = s->next) { |
168 |
if (!strcmp (s->keyid+8, 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; |
171 |
if (first) |
if (first) |
189 |
if (keyidx > 0) { |
if (keyidx > 0) { |
190 |
k = get_nth_key (key, keyidx-1); |
k = get_nth_key (key, keyidx-1); |
191 |
subalg = get_key_pubalgo (k->pubkey_algo); |
subalg = get_key_pubalgo (k->pubkey_algo); |
192 |
_snprintf( algo_id, DIM (algo_id)-1, "%s", subalg); |
_snprintf (algo_id, DIM (algo_id)-1, "%s", subalg); |
193 |
return algo_id; |
return algo_id; |
194 |
} |
} |
195 |
strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo)); |
strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo)); |
201 |
return algo_id; |
return algo_id; |
202 |
} |
} |
203 |
return get_key_pubalgo (key->subkeys->pubkey_algo); |
return get_key_pubalgo (key->subkeys->pubkey_algo); |
204 |
} /* get_key_algo */ |
} |
205 |
|
|
206 |
|
|
207 |
const char* |
const char* |
209 |
{ |
{ |
210 |
static char timebuf[128]; |
static char timebuf[128]; |
211 |
struct tm *warp; |
struct tm *warp; |
212 |
|
const char *dat; |
213 |
|
|
214 |
if (timestamp == 0 || timestamp == -1) |
if (timestamp < 1) |
215 |
return "????" "-??" "-??"; |
return "????" "-??" "-??"; |
216 |
warp = localtime( ×tamp ); |
dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1); |
217 |
_snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d", |
if (dat) |
218 |
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday ); |
return dat; |
219 |
|
warp = localtime (×tamp); |
220 |
|
_snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d", |
221 |
|
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday); |
222 |
return timebuf; |
return timebuf; |
223 |
} /* get_key_created */ |
} |
224 |
|
|
225 |
|
|
226 |
/* Return a string presentation of the time @timestamp. */ |
/* Return a string presentation of the time @timestamp. */ |
229 |
{ |
{ |
230 |
static char timebuf[64]; |
static char timebuf[64]; |
231 |
struct tm *warp; |
struct tm *warp; |
232 |
|
const char *dat; |
233 |
|
|
234 |
if( !timestamp ) |
if (timestamp == 0) |
235 |
return _("Never"); |
return _("Never"); |
236 |
warp = localtime( ×tamp ); |
dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1); |
237 |
|
if (dat) |
238 |
|
return dat; |
239 |
|
warp = localtime (×tamp); |
240 |
_snprintf (timebuf, sizeof timebuf -1, "%04d-%02d-%02d", |
_snprintf (timebuf, sizeof timebuf -1, "%04d-%02d-%02d", |
241 |
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday); |
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday); |
242 |
return timebuf; |
return timebuf; |
253 |
else if (type == 2) |
else if (type == 2) |
254 |
return _("Key Pair (Card)"); |
return _("Key Pair (Card)"); |
255 |
return _("Public Key"); |
return _("Public Key"); |
256 |
} /* get_key_type */ |
} |
257 |
|
|
258 |
|
|
259 |
const char* |
const char* |
274 |
if (n > 1) { |
if (n > 1) { |
275 |
k = get_nth_key (key, n-1); |
k = get_nth_key (key, n-1); |
276 |
size_sub = k->length; |
size_sub = k->length; |
277 |
_snprintf( size_id, sizeof (size_id) - 1, "%d/%d", size_main, size_sub ); |
_snprintf (size_id, sizeof (size_id) - 1, "%d/%d", |
278 |
|
size_main, size_sub); |
279 |
return size_id; |
return size_id; |
280 |
} |
} |
281 |
_snprintf( size_id, sizeof (size_id) - 1, "%d", size_main ); |
_snprintf( size_id, sizeof (size_id) - 1, "%d", size_main ); |
282 |
return size_id; |
return size_id; |
283 |
} /* get_key_size */ |
} |
284 |
|
|
285 |
|
|
286 |
|
const char* |
287 |
|
get_key_pubalgo2 (gpgme_pubkey_algo_t alg) |
288 |
|
{ |
289 |
|
switch (alg) { |
290 |
|
case GPGME_PK_DSA: return "D"; |
291 |
|
case GPGME_PK_RSA: return "R"; |
292 |
|
case GPGME_PK_ELG: return "G"; |
293 |
|
default: return "?"; |
294 |
|
} |
295 |
|
return "?"; |
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
const char* |
const char* |
303 |
case GPGME_PK_DSA: return "DSA"; |
case GPGME_PK_DSA: return "DSA"; |
304 |
case GPGME_PK_ELG: |
case GPGME_PK_ELG: |
305 |
case GPGME_PK_ELG_E: return "ELG"; |
case GPGME_PK_ELG_E: return "ELG"; |
306 |
|
case 0: /* XXX: gpgme returned pubkey algo 0 for a RSA made sig. */ |
307 |
case GPGME_PK_RSA: return "RSA"; |
case GPGME_PK_RSA: return "RSA"; |
308 |
default: return "???"; |
default: return "???"; |
309 |
} |
} |
310 |
return "???"; |
return "???"; |
311 |
} |
} |
312 |
|
|
313 |
const char * |
const char* |
314 |
get_key_fpr (gpgme_key_t key) |
get_key_fpr (gpgme_key_t key) |
315 |
{ |
{ |
316 |
static char fpr_md[64]; |
static char fpr_md[64]; |
339 |
} |
} |
340 |
} |
} |
341 |
return fpr_md; |
return fpr_md; |
342 |
} /* get_key_fpr */ |
} |
343 |
|
|
344 |
|
|
345 |
const char * |
/* Extract the key ID from the fingerprint. |
346 |
|
A long ID will be converted into a short ID. */ |
347 |
|
const char* |
348 |
|
get_keyid_from_fpr (const char *fpr) |
349 |
|
{ |
350 |
|
if (!fpr) |
351 |
|
return "????????"; |
352 |
|
if (strlen (fpr) == 40) |
353 |
|
fpr += 32; |
354 |
|
else if (strlen (fpr) == 32) |
355 |
|
fpr += 24; |
356 |
|
else if (strlen (fpr) == 16) |
357 |
|
fpr += 8; |
358 |
|
else |
359 |
|
return "????????"; |
360 |
|
return fpr; |
361 |
|
} |
362 |
|
|
363 |
|
|
364 |
|
const char* |
365 |
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) |
366 |
{ |
{ |
367 |
if (key) |
if (key) |
369 |
switch (val) { |
switch (val) { |
370 |
case GPGME_VALIDITY_UNKNOWN: |
case GPGME_VALIDITY_UNKNOWN: |
371 |
case GPGME_VALIDITY_UNDEFINED: |
case GPGME_VALIDITY_UNDEFINED: |
372 |
return "None"; |
return _("None"); |
373 |
case GPGME_VALIDITY_NEVER: |
case GPGME_VALIDITY_NEVER: |
374 |
return "Never"; |
return _("Never"); |
375 |
case GPGME_VALIDITY_MARGINAL: |
case GPGME_VALIDITY_MARGINAL: |
376 |
return "Marginal"; |
return _("Marginal"); |
377 |
case GPGME_VALIDITY_FULL: |
case GPGME_VALIDITY_FULL: |
378 |
case GPGME_VALIDITY_ULTIMATE: |
case GPGME_VALIDITY_ULTIMATE: |
379 |
return "Full"; |
return _("Full"); |
380 |
} |
} |
381 |
return ""; |
return ""; |
382 |
} |
} |
383 |
|
|
384 |
|
|
385 |
const char * |
const char* |
386 |
get_key_trust (gpgme_key_t key, int uididx, int listmode) |
get_key_trust (gpgme_key_t key, int uididx, int listmode) |
387 |
{ |
{ |
388 |
return get_key_trust2 (key, 0, uididx, listmode); |
return get_key_trust2 (key, 0, uididx, listmode); |
389 |
} |
} |
390 |
|
|
391 |
|
|
392 |
const char * |
const char* |
393 |
get_key_trust_str (int val) |
get_key_trust_str (int val) |
394 |
{ |
{ |
395 |
return get_key_trust2 (NULL, val, 0, 0); |
return get_key_trust2 (NULL, val, 0, 0); |
407 |
if (uididx < 0 || count_userids (key) > uididx) |
if (uididx < 0 || count_userids (key) > uididx) |
408 |
uididx = 0; |
uididx = 0; |
409 |
if (listmode) { |
if (listmode) { |
410 |
const char *s; |
const char *s; |
|
|
|
411 |
if (key->revoked) |
if (key->revoked) |
412 |
s = _("Revoked"); |
s = _("Revoked"); |
413 |
else if (key->expired) |
else if (key->expired) |
414 |
s = _("Expired"); |
s = _("Expired"); |
415 |
else if (key->disabled) |
else if (key->disabled) |
416 |
s = _("Disabled"); |
s = _("Disabled"); |
417 |
else |
else |
418 |
s = ""; |
s = ""; |
|
|
|
419 |
/* 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 |
420 |
what any user-id validities. */ |
the user-id validities. */ |
421 |
if (*s) |
if (*s) |
422 |
return m_strdup (s); |
return m_strdup (s); |
423 |
} |
} |
428 |
} |
} |
429 |
|
|
430 |
|
|
431 |
|
/* Return human readable description of the key @key. */ |
432 |
|
char* |
433 |
|
get_key_desc (gpgme_key_t key) |
434 |
|
{ |
435 |
|
gpgme_key_t sk; |
436 |
|
const char *state, *alg, *type; |
437 |
|
char *p; |
438 |
|
|
439 |
|
/* XXX: problems with the German translation. */ |
440 |
|
state = ""; |
441 |
|
if (key->disabled) |
442 |
|
state = _("Disabled"); |
443 |
|
if (key->expired) |
444 |
|
state = _("Expired"); |
445 |
|
if (key->revoked) |
446 |
|
state = _("Revoked"); |
447 |
|
alg = "OpenPGP"; |
448 |
|
if (strlen (key->subkeys->fpr) == 32) |
449 |
|
alg = "RSA Legacy"; |
450 |
|
type = _("public key"); |
451 |
|
if (!get_seckey (key->subkeys->keyid+8, &sk)) |
452 |
|
type = _("key pair"); |
453 |
|
p = new char[strlen (state) + strlen (alg) + strlen (type) + 4 + 1]; |
454 |
|
if (!p) |
455 |
|
BUG (0); |
456 |
|
sprintf (p, "%s %s %s", state, alg, type); |
457 |
|
return p; |
458 |
|
} |
459 |
|
|
460 |
|
|
461 |
/* Integer comparsion of @a and @b. |
/* Integer comparsion of @a and @b. |
462 |
Return values: same as in strcmp. */ |
Return values: same as in strcmp. */ |
463 |
static inline int |
static inline int |
479 |
return GPGME_VALIDITY_ULTIMATE+1; |
return GPGME_VALIDITY_ULTIMATE+1; |
480 |
else if (k->expired) |
else if (k->expired) |
481 |
return GPGME_VALIDITY_ULTIMATE+2; |
return GPGME_VALIDITY_ULTIMATE+2; |
482 |
|
else if (k->disabled) |
483 |
|
return GPGME_VALIDITY_ULTIMATE+3; |
484 |
return k->uids->validity; |
return k->uids->validity; |
485 |
} |
} |
486 |
|
|
489 |
static int CALLBACK |
static int CALLBACK |
490 |
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
491 |
{ |
{ |
492 |
|
struct keycache_s *aa, *bb; |
493 |
gpgme_key_t a, b; |
gpgme_key_t a, b; |
494 |
int cmpresult = 0; |
int cmpresult = 0; |
495 |
|
|
496 |
a = (gpgme_key_t)first; |
aa = (struct keycache_s *)first; |
497 |
b = (gpgme_key_t)second; |
bb = (struct keycache_s *)second; |
498 |
if (!a || !b) |
if (!aa || !bb) |
499 |
BUG (NULL); |
BUG (NULL); |
500 |
|
a = aa->key; |
501 |
|
b = bb->key; |
502 |
|
|
503 |
switch (sortby & ~KEYLIST_SORT_DESC) { |
switch (sortby & ~KEYLIST_SORT_DESC) { |
504 |
case KEY_SORT_USERID: |
case KEY_SORT_USERID: |
551 |
} |
} |
552 |
|
|
553 |
|
|
|
/* 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"); |
|
|
} |
|
|
|
|
|
|
|
554 |
int |
int |
555 |
keylist_add_groups( listview_ctrl_t lv ) |
keylist_add_groups (listview_ctrl_t lv) |
556 |
{ |
{ |
|
#if 0 |
|
|
gpg_optfile_t gh; |
|
|
gpg_group_t grp; |
|
|
const char *valid; |
|
|
|
|
|
gh = km_groupdb_open( ); |
|
|
if( !gh ) |
|
|
return WPTERR_FILE_OPEN; |
|
|
|
|
|
for( grp = gh->grp; grp; grp = grp->next ) { |
|
|
valid = calc_validity( grp ); |
|
|
listview_add_item( lv, " " ); |
|
|
listview_add_sub_item( lv, 0, 0, grp->name ); |
|
|
listview_add_sub_item( lv, 0, 1, "gpg_group_t" ); |
|
|
listview_add_sub_item( lv, 0, 2, "" ); |
|
|
listview_add_sub_item( lv, 0, 3, "Unknown" ); |
|
|
listview_add_sub_item( lv, 0, 4, valid?valid : "Unknown" ); |
|
|
} |
|
|
#endif |
|
557 |
return 0; |
return 0; |
558 |
} /* keylist_add_groups */ |
} |
559 |
|
|
560 |
|
|
561 |
/* Create a listview for listing keys. Use the mode given in @mode |
/* Create a listview for listing keys. Use the mode given in @mode |
563 |
static int |
static int |
564 |
keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode) |
keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode) |
565 |
{ |
{ |
566 |
|
struct listview_column_s klist_enc[] = { |
567 |
|
{0, 242, (char *)_("User ID")}, |
568 |
|
{1, 80, (char *)_("Key ID")}, |
569 |
|
{3, 46, (char *)_("Size")}, |
570 |
|
{4, 50, (char *)_("Cipher")}, |
571 |
|
{5, 70, (char *)_("Validity")}, |
572 |
|
{0, 0, NULL} |
573 |
|
}; |
574 |
|
struct listview_column_s klist[] = { |
575 |
|
{0, 240, (char *)_("User ID")}, |
576 |
|
{1, 78, (char *)_("Key ID")}, |
577 |
|
{2, 52, (char *)_("Type")}, |
578 |
|
{3, 66, (char *)_("Size")}, |
579 |
|
{4, 60, (char *)_("Cipher")}, |
580 |
|
{5, 66, (char *)_("Validity")}, |
581 |
|
{6, 58, (char *)_("Trust")}, |
582 |
|
{7, 72, (char *)_("Creation")}, |
583 |
|
{0, 0, NULL} |
584 |
|
}; |
585 |
|
HICON ico[2]; |
586 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
587 |
listview_column_t col; |
listview_column_t col; |
588 |
int j, n = 0; |
int j, n = 0, ext_chk = 0; |
589 |
int rc = 0; |
int rc = 0; |
590 |
|
|
591 |
rc = listview_new (&lv); |
rc = listview_new (&lv); |
592 |
if( rc ) |
if (rc) |
593 |
return rc; |
return rc; |
594 |
|
|
595 |
lv->ctrl = ctrl; |
lv->ctrl = ctrl; |
596 |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) { |
if (mode & KEYLIST_ENCRYPT_MIN) { |
597 |
col = klist_enc; |
col = klist_enc; |
598 |
n = KLIST_ENC_ITEMS; |
n = (DIM(klist_enc) -1); |
599 |
|
ext_chk = 1; |
600 |
} |
} |
601 |
else if ((mode & KEYLIST_SIGN)) { |
else if ((mode & KEYLIST_SIGN)) { |
602 |
col = klist_enc; |
col = klist_enc; |
603 |
n = KLIST_ENC_ITEMS - 1; |
n = (DIM(klist_enc) - 1) - 1; |
604 |
|
ext_chk = 1; |
605 |
} |
} |
606 |
else { |
else { |
607 |
col = klist; |
col = klist; |
608 |
n = KLIST_ITEMS; |
n = (DIM(klist) - 1); |
609 |
} |
} |
610 |
|
|
611 |
for( j = 0; j < n; j++ ) |
for (j = 0; j < n; j++) |
612 |
listview_add_column( lv, &col[j] ); |
listview_add_column (lv, &col[j]); |
613 |
listview_set_ext_style( lv ); |
listview_set_ext_style (lv); |
614 |
|
if (ext_chk) |
615 |
|
listview_set_chkbox_style (lv); |
616 |
|
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY); |
617 |
|
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR); |
618 |
|
listview_set_image_list (lv, 22, 14, ico, 2); |
619 |
|
listview_del_all_items (lv); |
620 |
|
|
621 |
*r_lv = lv; |
*r_lv = lv; |
|
|
|
622 |
return 0; |
return 0; |
623 |
} |
} |
624 |
|
|
629 |
{ |
{ |
630 |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
631 |
gpgme_key_t key, skey; |
gpgme_key_t key, skey; |
632 |
const char * keyid; |
struct keycache_s *c; |
633 |
|
const char *keyid; |
634 |
|
|
635 |
if (pubkc && seckc) { |
if (pubkc && seckc) { |
636 |
gpg_keycache_rewind (pubkc); |
gpg_keycache_rewind (pubkc); |
637 |
while (!gpg_keycache_next_key (pubkc, 0, &key)) { |
while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) { |
638 |
keyid = key->subkeys->keyid; |
keyid = key->subkeys->keyid; |
639 |
if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey)) |
if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey)) |
640 |
keylist_add_key (lv, mode, key); |
keylist_add_key (lv, mode, c, key); |
641 |
} |
} |
642 |
} |
} |
643 |
else if (pubkc) { |
else if (pubkc) { |
644 |
gpg_keycache_rewind (pubkc); |
gpg_keycache_rewind (pubkc); |
645 |
while (!err) { |
while (!err) { |
646 |
err = gpg_keycache_next_key (pubkc, 0, &key); |
err = gpg_keycache_next_key2 (pubkc, 0, &c, &key); |
647 |
if (!err) |
if (!err) |
648 |
keylist_add_key (lv, mode, key); |
keylist_add_key (lv, mode, c, key); |
649 |
} |
} |
650 |
} |
} |
651 |
} |
} |
665 |
return NULL; |
return NULL; |
666 |
keylist_load_keycache (lv, mode, pubkc, seckc); |
keylist_load_keycache (lv, mode, pubkc, seckc); |
667 |
keylist_sort (lv, sortby); |
keylist_sort (lv, sortby); |
668 |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) |
if (mode & KEYLIST_ENCRYPT_MIN) |
669 |
keylist_add_groups (lv); |
keylist_add_groups (lv); |
670 |
return lv; |
return lv; |
671 |
} |
} |
675 |
int |
int |
676 |
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) |
677 |
{ |
{ |
678 |
listview_del_all (lv); |
listview_del_all_items (lv); |
679 |
keylist_load_keycache( lv, mode, pubkc, NULL ); |
keylist_load_keycache (lv, mode, pubkc, NULL); |
680 |
keylist_sort (lv, sortby); |
keylist_sort (lv, sortby); |
681 |
return 0; |
return 0; |
682 |
} |
} |
711 |
|
|
712 |
|
|
713 |
static int |
static int |
714 |
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, |
715 |
|
int uididx, int keyidx, int list) |
716 |
{ |
{ |
717 |
LV_ITEM lvi; |
LV_ITEM lvi; |
718 |
gpgme_user_id_t u; |
gpgme_user_id_t u; |
725 |
/* we check the pubkey algorithm here to make sure that no ElGamal |
/* we check the pubkey algorithm here to make sure that no ElGamal |
726 |
sign+encrypt key is used in _any_ mode */ |
sign+encrypt key is used in _any_ mode */ |
727 |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
728 |
log_debug ("ElGamal (E+S) key found: %s (%s)\n", |
log_debug ("ElGamal (E+S) key found: %s (%s)\n", |
729 |
key->uids->name, key->subkeys->keyid); |
key->uids->name, key->subkeys->keyid); |
730 |
return 0; |
return 0; |
731 |
} |
} |
732 |
|
|
733 |
|
if (listview_add_item2 (lv, " ", (void *)ctx)) |
|
if (listview_add_item2 (lv, " ", (void *)key)) |
|
734 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
735 |
|
|
736 |
attr = key->uids->uid; |
attr = ctx->uids->uid; |
737 |
memset (&lvi, 0, sizeof lvi); |
memset (&lvi, 0, sizeof lvi); |
738 |
lvi.mask = LVIF_TEXT | LVIF_PARAM; |
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; |
739 |
lvi.pszText = (char *)attr; |
lvi.pszText = (char *)attr; |
740 |
lvi.lParam = (LPARAM )key; |
lvi.iImage = find_secret_key (key)? 1 : 0; |
741 |
if (ListView_SetItem( lv->ctrl, &lvi ) == FALSE) |
lvi.lParam = (LPARAM )ctx; |
742 |
|
if (ListView_SetItem (lv->ctrl, &lvi) == FALSE) |
743 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
744 |
|
|
745 |
if (uididx == -1) { /* request the primary user-id of the key. */ |
if (uididx == -1) { /* request the primary user-id of the key. */ |
746 |
attr = key->uids->uid; |
attr = ctx->uids->uid; |
747 |
uididx = 0; |
uididx = 0; |
748 |
} |
} |
749 |
else { |
else { |
750 |
u = get_nth_userid (key, uididx); |
u = get_nth_userid (key, uididx); |
751 |
if (!u || u->revoked || uididx < 0) |
if (!u || u->revoked || uididx < 0) |
752 |
uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */ |
uididx = 0; |
753 |
u = get_nth_userid (key, uididx); |
u = get_nth_userid (key, uididx); |
|
/*attr = key->uids->uid; XXX*/ |
|
754 |
attr = u->uid; |
attr = u->uid; |
755 |
} |
} |
756 |
if (attr == NULL || strlen (attr) < 5) { /* normal userids are >= 5 chars */ |
if (attr == NULL || strlen (attr) < 5) { /* normal userids are > 5 chars */ |
757 |
attr = _("Invalid User ID"); |
attr = _("Invalid User ID"); |
758 |
listview_add_sub_item (lv, 0, idx++, attr); |
listview_add_sub_item (lv, 0, idx++, attr); |
759 |
} |
} |
760 |
else { |
else |
761 |
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); |
|
|
} |
|
|
} |
|
762 |
k = get_nth_key (key, keyidx); |
k = get_nth_key (key, keyidx); |
763 |
if (k && k->keyid) { |
if (k && k->keyid) { |
764 |
_snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8); |
_snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8); |
765 |
listview_add_sub_item( lv, 0, idx++, fmt ); |
listview_add_sub_item (lv, 0, idx++, fmt); |
766 |
} |
} |
767 |
if (list > 0) { |
if (list > 0) { |
768 |
key_attr = find_secret_key (key); |
key_attr = find_secret_key (key); |
782 |
if (attr) |
if (attr) |
783 |
listview_add_sub_item( lv, 0, idx++, attr); |
listview_add_sub_item( lv, 0, idx++, attr); |
784 |
} |
} |
785 |
if( lv->cols >= 4 ) { |
if (lv->cols >= 4) { |
786 |
p = get_key_status( key, uididx, list > 0? 1 : 0 ); |
p = get_key_status( key, uididx, list > 0? 1 : 0 ); |
787 |
if (!p) |
if (!p) |
788 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
806 |
} |
} |
807 |
|
|
808 |
|
|
809 |
|
/* Update a single column @col but for each element in the |
810 |
|
listview @lv. */ |
811 |
void |
void |
812 |
keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key) |
keylist_upd_col (listview_ctrl_t lv, int col) |
813 |
{ |
{ |
814 |
|
gpgme_key_t key; |
815 |
const char *s; |
const char *s; |
816 |
|
char buf[32], *p; |
817 |
|
int i; |
818 |
|
|
819 |
|
for (i=0; i < listview_count_items (lv, 0); i++) { |
820 |
|
key = km_get_key_ptr (lv, i, NULL); |
821 |
|
if (!key) |
822 |
|
continue; |
823 |
|
switch (col) { |
824 |
|
case KM_COL_KEYID: |
825 |
|
_snprintf (buf, sizeof (buf)-1, "0x%s", key->subkeys->keyid+8); |
826 |
|
listview_add_sub_item (lv, i, col, buf); |
827 |
|
break; |
828 |
|
|
829 |
|
case KM_COL_CIPHER: |
830 |
|
s = get_key_algo (key, 0); |
831 |
|
listview_add_sub_item (lv, i, col, s); |
832 |
|
break; |
833 |
|
|
834 |
|
case KM_COL_TYPE: |
835 |
|
s = find_secret_key (key)? "pub/sec" : "pub"; |
836 |
|
listview_add_sub_item (lv, i, col, s); |
837 |
|
break; |
838 |
|
|
839 |
|
case KM_COL_CREAT: |
840 |
|
s = get_key_created (key->subkeys->timestamp); |
841 |
|
listview_add_sub_item (lv, i, col, s); |
842 |
|
break; |
843 |
|
|
844 |
|
case KM_COL_DESC: |
845 |
|
p = get_key_desc (key); |
846 |
|
listview_add_sub_item (lv, i, col, p); |
847 |
|
free_if_alloc (p); |
848 |
|
break; |
849 |
|
} |
850 |
|
} |
851 |
|
} |
852 |
|
|
853 |
|
|
854 |
|
/* Update the listview item at position @pos with the data from |
855 |
|
the key @key. */ |
856 |
|
void |
857 |
|
keylist_upd_key (listview_ctrl_t lv, int pos, |
858 |
|
struct keycache_s *ctx, gpgme_key_t key) |
859 |
|
{ |
860 |
|
const char *s; |
861 |
|
char *p; |
862 |
char tmp[32]; |
char tmp[32]; |
863 |
|
|
864 |
listview_set_item2 (lv, pos, (void *)key); |
listview_set_item2 (lv, pos, (void *)ctx); |
865 |
/* the only mode we support is KYLIST_LIST in the Key Manager */ |
/* the only mode we support is KEYLIST_LIST in the Key Manager */ |
866 |
|
|
867 |
s = key->uids->uid; |
s = ctx->uids->uid; |
868 |
if (s) |
if (s) |
869 |
listview_add_sub_item (lv, pos, 0, s); |
listview_add_sub_item (lv, pos, KM_COL_UID, s); |
870 |
|
|
871 |
s = key->subkeys->keyid; |
s = key->subkeys->keyid; |
872 |
if (s) { |
if (s) { |
873 |
sprintf (tmp, "0x%s", s+8); |
sprintf (tmp, "0x%s", s+8); |
874 |
listview_add_sub_item (lv, pos, 1, tmp); |
listview_add_sub_item (lv, pos, KM_COL_KEYID, tmp); |
875 |
} |
} |
876 |
|
|
877 |
s = find_secret_key (key)? "pub/sec" : "pub"; |
s = find_secret_key (key)? "pub/sec" : "pub"; |
878 |
listview_add_sub_item (lv, pos, 2, s); |
listview_add_sub_item (lv, pos, KM_COL_TYPE, s); |
879 |
|
|
880 |
s = get_key_size (key, 0); |
s = get_key_size (key, 0); |
881 |
if (s) |
if (s) |
882 |
listview_add_sub_item (lv, pos, 3, s); |
listview_add_sub_item (lv, pos, KM_COL_SIZE, s); |
883 |
|
|
884 |
s = get_key_algo (key, 0); |
s = get_key_algo (key, 0); |
885 |
if (s) |
if (s) |
886 |
listview_add_sub_item (lv, pos, 4, s); |
listview_add_sub_item (lv, pos, KM_COL_CIPHER, s); |
887 |
|
|
888 |
s = get_key_status (key, 0, 1); |
p = get_key_status (key, 0, 1); |
889 |
if (s) |
if (p) { |
890 |
listview_add_sub_item (lv, pos, 5, s); |
listview_add_sub_item (lv, pos, KM_COL_VALID, p); |
891 |
|
free_if_alloc (p); |
892 |
|
} |
893 |
|
|
894 |
s = get_key_trust (key, 0, 1); |
s = get_key_trust (key, 0, 1); |
895 |
if (s) |
if (s) |
896 |
listview_add_sub_item (lv, pos, 6, s); |
listview_add_sub_item (lv, pos, KM_COL_TRUST, s); |
897 |
|
|
898 |
long t = key->subkeys->timestamp; |
long t = key->subkeys->timestamp; |
899 |
s = get_key_created (t); |
s = get_key_created (t); |
900 |
if (s) |
if (s) |
901 |
listview_add_sub_item (lv, pos, 7, s); |
listview_add_sub_item (lv, pos, KM_COL_CREAT, s); |
902 |
} |
} |
903 |
|
|
904 |
|
|
905 |
int |
int |
906 |
keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key) |
keylist_add_key (listview_ctrl_t lv, int mode, |
907 |
|
struct keycache_s *ctx, gpgme_key_t key) |
908 |
{ |
{ |
909 |
int uids, rc = 0, i; |
int uids, rc = 0, i; |
910 |
gpgme_subkey_t k; |
gpgme_subkey_t k; |
911 |
|
|
912 |
/* if the entire key is disabled, just return. */ |
/* if the entire key is disabled, just return. */ |
913 |
if (key->disabled) |
if (key->disabled && !(mode & KEYLIST_LIST)) |
914 |
return 0; |
return 0; |
915 |
|
|
916 |
for (k=key->subkeys, i = 0; i < count_subkeys (key); i++, k=k->next) { |
for (k=key->subkeys, i = 0; i < count_subkeys (key); i++, k=k->next) { |
921 |
|
|
922 |
if (mode & KEYLIST_ALL) { |
if (mode & KEYLIST_ALL) { |
923 |
uids = count_userids (key); |
uids = count_userids (key); |
924 |
rc = do_addkey (lv, key, uids, i, 0); |
rc = do_addkey (lv, ctx, key, uids, i, 0); |
925 |
if( rc ) |
if (rc) |
926 |
return rc; |
return rc; |
927 |
} |
} |
928 |
else if (mode & KEYLIST_LIST) |
else if (mode & KEYLIST_LIST) |
929 |
return do_addkey (lv, key, -1, i, 1); |
return do_addkey (lv, ctx, key, -1, i, 1); |
930 |
else if (mode & KEYLIST_ENCRYPT) { |
else if (mode & KEYLIST_ENCRYPT) { |
931 |
if (k->can_encrypt && key_is_useable (k)) { |
if (k->can_encrypt && key_is_useable (k)) { |
932 |
if (mode & KEYLIST_FLAG_FILE) { |
if (mode & KEYLIST_FLAG_FILE) { |
933 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
934 |
if (rc) |
if (rc) |
935 |
return rc; |
return rc; |
936 |
} |
} |
937 |
else { |
else { |
938 |
for( uids = 0; uids < count_userids (key); uids++ ) { |
for (uids = 0; uids < count_userids (key); uids++) { |
939 |
rc = do_addkey( lv, key, uids, i, -1 ); |
rc = do_addkey (lv, ctx, key, uids, i, -1); |
940 |
if( rc ) |
if (rc) |
941 |
return rc; |
return rc; |
942 |
} |
} |
943 |
} |
} |
946 |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
947 |
if( k->can_encrypt && key_is_useable (k)) |
if( k->can_encrypt && key_is_useable (k)) |
948 |
{ |
{ |
949 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
950 |
return rc; |
return rc; |
951 |
} |
} |
952 |
} |
} |
954 |
if (k->can_sign |
if (k->can_sign |
955 |
&& find_secret_key (key) |
&& find_secret_key (key) |
956 |
&& key_is_useable (k)) { |
&& key_is_useable (k)) { |
957 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
958 |
if (rc) |
if (rc) |
959 |
return rc; |
return rc; |
960 |
} |
} |
962 |
} |
} |
963 |
|
|
964 |
return rc; |
return rc; |
965 |
} /* keylist_add_key */ |
} |
966 |
|
|
967 |
|
|
968 |
int |
int |
969 |
keylist_sort (listview_ctrl_t lv, int sortby) |
keylist_sort (listview_ctrl_t lv, int sortby) |
970 |
{ |
{ |
971 |
return listview_sort_items (lv, sortby, keylist_cmp_cb); |
return listview_sort_items (lv, sortby, keylist_cmp_cb); |
972 |
} |
} |
973 |
|
|
974 |
|
|
975 |
/* Check that the validity @validity is at least >= marginal. */ |
/* Check that the validity @validity is at least >= marginal. */ |
976 |
static int |
static int |
977 |
key_check_validity (const char *validity) |
key_check_validity (gpgme_key_t key) |
978 |
{ |
{ |
979 |
if (strstr (validity, "Unknown") || |
gpgme_user_id_t u; |
980 |
strstr (validity, "Undefined") || |
|
981 |
strstr (validity, "Never") || |
for (u=key->uids; u; u =u->next) { |
982 |
strstr (validity, "None")) |
if (u->validity >= GPGME_VALIDITY_MARGINAL) |
983 |
return 0; |
return -1; |
984 |
return 1; |
} |
985 |
|
|
986 |
|
return 0; |
987 |
} |
} |
988 |
|
|
989 |
|
|
994 |
gpgme_key_t* |
gpgme_key_t* |
995 |
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, int *r_count) |
996 |
{ |
{ |
997 |
|
key_array_s *ka = NULL; |
998 |
|
keycache_s *c; |
999 |
|
gpgme_key_t *keybuf, key; |
1000 |
int count = 0, force_trust = 0; |
int count = 0, force_trust = 0; |
1001 |
int n, j, ka_pos = 0, rc = 0; |
int n, j, ka_pos = 0, rc = 0; |
1002 |
int k_pos=0; |
int k_pos=0; |
|
char keyid[32], valid[32], id[100]; |
|
|
key_array_s *ka = NULL; |
|
|
gpgme_key_t *keybuf; |
|
1003 |
|
|
1004 |
n = listview_count_items( lv, 0 ); |
n = listview_count_items (lv, 0); |
1005 |
|
|
1006 |
ka = key_array_new( n ); |
ka = key_array_new (n); |
1007 |
if (!ka) |
if (!ka) |
1008 |
BUG (NULL); |
BUG (NULL); |
1009 |
|
|
1010 |
keybuf = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); |
keybuf = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t)); |
1011 |
if (!keybuf) |
if (!keybuf) |
1012 |
BUG (NULL); |
BUG (NULL); |
1013 |
|
|
1014 |
for( j = 0; j < n; j++ ) { |
for (j = 0; j < n; j++) { |
1015 |
if( listview_get_item_state (lv, j) || n == 1) { |
if (listview_get_item_state (lv, j) || n == 1) { |
1016 |
listview_get_item_text (lv, j, 0, id, sizeof id-1); |
key = km_get_key_ptr (lv, j, &c); |
1017 |
listview_get_item_text (lv, j, 1, keyid, sizeof keyid - 1); |
if (!key) |
1018 |
listview_get_item_text (lv, j, 4, valid, sizeof valid -1); |
BUG (0); |
1019 |
if( !key_check_validity (valid) |
if (!key_check_validity (key) && |
1020 |
&& !key_array_search( ka, ka_pos, keyid )) { |
!key_array_search (ka, ka_pos, key->subkeys->keyid)) { |
1021 |
char *warn = new char[512+strlen (id) + 1]; |
char *warn = new char[512+strlen (c->uids->uid) + 1]; |
1022 |
if (!warn) |
if (!warn) |
1023 |
BUG (0); |
BUG (0); |
1024 |
sprintf (warn, |
sprintf (warn, |
1026 |
"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" |
1027 |
"doing, you may answer the next question with yes\n" |
"doing, you may answer the next question with yes\n" |
1028 |
"\n" |
"\n" |
1029 |
"Use \"%s\" anyway?"), id); |
"Use \"%s\" anyway?"), c->uids->uid); |
1030 |
if (reg_prefs.always_trust) |
if (reg_prefs.always_trust) |
1031 |
rc = IDYES; |
rc = IDYES; |
1032 |
else |
else |
1033 |
rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK); |
rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK); |
1034 |
if (rc == IDYES) { |
if (rc == IDYES) { |
1035 |
gpgme_key_t k; |
keybuf[k_pos++] = key; |
|
get_pubkey (keyid, &k); |
|
|
keybuf[k_pos++] = k; |
|
1036 |
force_trust++; |
force_trust++; |
1037 |
ka[ka_pos].checked = 1; |
ka[ka_pos].checked = 1; |
1038 |
strcpy (ka[ka_pos++].keyid, keyid); |
strcpy (ka[ka_pos++].keyid, key->subkeys->keyid); |
1039 |
count++; |
count++; |
1040 |
} |
} |
1041 |
free_if_alloc (warn); |
free_if_alloc (warn); |
1042 |
} |
} |
1043 |
else { |
else { |
1044 |
gpgme_key_t k; |
keybuf[k_pos++] = key; |
|
listview_get_item_text( lv, j, 1, keyid, sizeof keyid -1 ); |
|
|
get_pubkey (keyid, &k); |
|
|
keybuf[k_pos++] = k; |
|
1045 |
count++; |
count++; |
1046 |
} |
} |
1047 |
} |
} |
1056 |
|
|
1057 |
|
|
1058 |
static int |
static int |
1059 |
keylist_get_keyflags (const char *buf, size_t buflen) |
keylist_get_keyflags (gpgme_key_t key) |
1060 |
{ |
{ |
1061 |
int c = 0, flags = 0; |
int flags = KEYFLAG_NONE; |
1062 |
|
|
1063 |
if( *buf != '[' ) |
if (key->revoked) |
1064 |
return KEYFLAG_NONE; |
flags |= KEYFLAG_REVOKED; |
1065 |
while (buf && c != ']') |
if (key->expired) |
1066 |
{ |
flags |= KEYFLAG_EXPIRED; |
1067 |
c = *buf++; |
if (key->disabled) |
1068 |
if (c == 'R') |
flags |= KEYFLAG_DISABLED; |
|
flags |= KEYFLAG_REVOKED; |
|
|
if (c == 'E') |
|
|
flags |= KEYFLAG_EXPIRED; |
|
|
if (c == 'D') |
|
|
flags |= KEYFLAG_DISABLED; |
|
|
} |
|
1069 |
|
|
1070 |
return flags; |
return flags; |
1071 |
} /* keylist_get_keyflags */ |
} |
1072 |
|
|
1073 |
|
|
1074 |
gpgme_key_t* |
gpgme_key_t* |
1075 |
keylist_enum_recipients (listview_ctrl_t lv, int listype, int *r_count) |
keylist_enum_recipients (listview_ctrl_t lv, int listype, int *r_count) |
1076 |
{ |
{ |
1077 |
gpgme_key_t* rset; |
struct keycache_s *c; |
1078 |
gpgme_key_t k; |
gpgme_key_t *rset; |
1079 |
|
gpgme_key_t key; |
1080 |
int i, n, id, k_pos=0; |
int i, n, id, k_pos=0; |
|
char keyid[32], t[128], t2[128]; |
|
1081 |
|
|
1082 |
n = listview_count_items (lv, 0); |
n = listview_count_items (lv, 0); |
1083 |
if (!n) |
if (!n) |
1084 |
return 0; |
return 0; |
1085 |
rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); |
rset = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t)); |
1086 |
if (!rset) |
if (!rset) |
1087 |
BUG (NULL); |
BUG (NULL); |
1088 |
for( i = 0; i < n; i++ ) { |
for (i = 0; i < n; i++) { |
1089 |
if( !listview_get_item_state( lv, i ) ) |
if (!listview_get_item_state (lv, i)) |
1090 |
continue; |
continue; |
1091 |
listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 ); |
key = km_get_key_ptr (lv, i, &c); |
1092 |
switch( listype ) { |
switch (listype) { |
1093 |
case KEYLIST_LIST: |
case KEYLIST_LIST: |
1094 |
listview_get_item_text( lv, i, 5, t, sizeof t - 1 ); |
if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) { |
1095 |
if( keylist_get_keyflags( t, strlen( t ) ) & KEYFLAG_REVOKED ) { |
id = printf_box (_("Recipients"), MB_INFO|MB_YESNO, |
1096 |
_snprintf( t2, sizeof t2 -1, |
_("KeyID %s.\nDo you really want to export a revoked key?"), |
1097 |
_("KeyID %s.\nDo you really want to export a revoked key?"), keyid ); |
c->uids->uid); |
1098 |
id = msg_box( lv->ctrl, t2, _("Recipients"), MB_INFO|MB_YESNO ); |
if (id == IDNO) |
1099 |
if( id == IDNO ) |
continue; |
|
continue; |
|
1100 |
} |
} |
1101 |
break; |
break; |
1102 |
} |
} |
1103 |
get_pubkey (keyid, &k); |
rset[k_pos++] = key; |
|
rset[k_pos++] = k; |
|
1104 |
} |
} |
1105 |
if (r_count) |
if (r_count) |
1106 |
*r_count = k_pos; |
*r_count = k_pos; |
1107 |
return rset; |
return rset; |
1108 |
} /* keylist_enum_recipients */ |
} |
1109 |
|
|
1110 |
|
|
1111 |
void |
void |
1112 |
seclist_destroy (keylist_t * list) |
seclist_destroy (keylist_t *list) |
1113 |
{ |
{ |
1114 |
keylist_t l2; |
keylist_t l2; |
1115 |
while (*list) { |
while (*list) { |
1118 |
*list = l2; |
*list = l2; |
1119 |
} |
} |
1120 |
list = NULL; |
list = NULL; |
1121 |
} /* seclist_destroy */ |
} |
1122 |
|
|
1123 |
|
|
1124 |
void |
void |
1155 |
if (key->disabled || !key_is_useable (key->subkeys)) |
if (key->disabled || !key_is_useable (key->subkeys)) |
1156 |
continue; |
continue; |
1157 |
|
|
1158 |
uid = utf8_to_wincp (id, strlen (id)); |
uid = utf8_to_native (id); |
1159 |
size = strlen( uid ) + strlen( keyid ) + 32; |
size = strlen (uid) + strlen (keyid) + 32; |
1160 |
inf = new char[size+1]; |
inf = new char[size+1]; |
1161 |
if( !inf ) |
if (!inf) |
1162 |
BUG( NULL ); |
BUG (NULL); |
1163 |
_snprintf (inf, size, "%s (%s/0x%s)", uid, |
_snprintf (inf, size, "%s (%s/0x%s)", uid, |
1164 |
get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8); |
get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8); |
1165 |
combox_add_string (kb, inf); |
combox_add_string (kb, inf); |
1166 |
free_if_alloc (inf); |
free_if_alloc (inf); |
1177 |
l2->next = l; |
l2->next = l; |
1178 |
} |
} |
1179 |
} |
} |
1180 |
for( pos = 0, l2=list; pos < SendMessage( kb, CB_GETCOUNT, 0, 0 ); pos++, l2=l2->next ) |
for (pos = 0, l2=list; pos < SendMessage (kb, CB_GETCOUNT, 0, 0); |
1181 |
SendMessage( kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key ); |
pos++, l2=l2->next) |
1182 |
SendMessage( kb, CB_SETCURSEL, 0, 0 ); |
SendMessage (kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key); |
1183 |
|
SendMessage (kb, CB_SETCURSEL, 0, 0); |
1184 |
*ret_list = list; |
*ret_list = list; |
1185 |
} |
} |
1186 |
|
|