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 |
|
|
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_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; |
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 = sigs; 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) |
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 |
{ |
{ |
188 |
if (keyidx > 0) { |
if (keyidx > 0) { |
189 |
k = get_nth_key (key, keyidx-1); |
k = get_nth_key (key, keyidx-1); |
190 |
subalg = get_key_pubalgo (k->pubkey_algo); |
subalg = get_key_pubalgo (k->pubkey_algo); |
191 |
_snprintf( algo_id, DIM (algo_id)-1, "%s", subalg); |
_snprintf (algo_id, DIM (algo_id)-1, "%s", subalg); |
192 |
return algo_id; |
return algo_id; |
193 |
} |
} |
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); |
212 |
} /* get_key_algo */ |
} |
213 |
|
|
214 |
|
|
215 |
const char* |
const char* |
217 |
{ |
{ |
218 |
static char timebuf[128]; |
static char timebuf[128]; |
219 |
struct tm *warp; |
struct tm *warp; |
220 |
|
const char *dat; |
221 |
|
|
222 |
if (timestamp == 0 || timestamp == -1) |
if (timestamp < 1) |
223 |
return "????" "-??" "-??"; |
return "????" "-??" "-??"; |
224 |
warp = localtime( ×tamp ); |
dat = get_locale_date (timestamp, timebuf, DIM (timebuf)-1); |
225 |
_snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d", |
if (dat) |
226 |
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday ); |
return dat; |
227 |
|
/* Fallback if locate date conversion failed. */ |
228 |
|
warp = localtime (×tamp); |
229 |
|
_snprintf (timebuf, DIM (timebuf) - 1, "%04d-%02d-%02d", |
230 |
|
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday); |
231 |
return timebuf; |
return timebuf; |
232 |
} /* get_key_created */ |
} |
233 |
|
|
234 |
|
|
235 |
/* Return a string presentation of the time @timestamp. */ |
/* Return a string presentation of the time @timestamp. */ |
238 |
{ |
{ |
239 |
static char timebuf[64]; |
static char timebuf[64]; |
240 |
struct tm *warp; |
struct tm *warp; |
241 |
|
const char *dat; |
242 |
|
|
243 |
if( !timestamp ) |
if (timestamp == 0) |
244 |
return _("Never"); |
return _("Never"); |
245 |
warp = localtime( ×tamp ); |
dat = get_locale_date (timestamp, timebuf, DIM (timebuf)-1); |
246 |
_snprintf (timebuf, sizeof timebuf -1, "%04d-%02d-%02d", |
if (dat) |
247 |
|
return dat; |
248 |
|
warp = localtime (×tamp); |
249 |
|
_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 |
} |
} |
262 |
else if (type == 2) |
else if (type == 2) |
263 |
return _("Key Pair (Card)"); |
return _("Key Pair (Card)"); |
264 |
return _("Public Key"); |
return _("Public Key"); |
265 |
} /* get_key_type */ |
} |
266 |
|
|
267 |
|
|
268 |
const char* |
const char* |
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", size_main, size_sub ); |
_snprintf (size_id, DIM (size_id) - 1, "%d/%d", |
287 |
|
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 |
} /* get_key_size */ |
} |
293 |
|
|
294 |
|
|
295 |
|
const char* |
296 |
|
get_key_pubalgo2 (gpgme_pubkey_algo_t alg) |
297 |
|
{ |
298 |
|
switch (alg) { |
299 |
|
case GPGME_PK_DSA: return "D"; |
300 |
|
case GPGME_PK_RSA: return "R"; |
301 |
|
case GPGME_PK_ELG: return "G"; |
302 |
|
default: return "?"; |
303 |
|
} |
304 |
|
return "?"; |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
const char* |
const char* |
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 "???"; |
322 |
} |
} |
323 |
|
|
324 |
const char * |
|
325 |
|
const char* |
326 |
get_key_fpr (gpgme_key_t key) |
get_key_fpr (gpgme_key_t key) |
327 |
{ |
{ |
328 |
static char fpr_md[64]; |
static char fpr_md[64]; |
351 |
} |
} |
352 |
} |
} |
353 |
return fpr_md; |
return fpr_md; |
354 |
} /* get_key_fpr */ |
} |
355 |
|
|
356 |
|
|
357 |
|
/* Extract the key ID from the fingerprint. |
358 |
|
A long ID will be converted into a short ID. */ |
359 |
|
const char* |
360 |
|
get_keyid_from_fpr (const char *fpr) |
361 |
|
{ |
362 |
|
if (!fpr) |
363 |
|
return "????????"; |
364 |
|
if (strlen (fpr) == 40) |
365 |
|
fpr += 32; |
366 |
|
else if (strlen (fpr) == 32) |
367 |
|
fpr += 24; |
368 |
|
else if (strlen (fpr) == 16) |
369 |
|
fpr += 8; |
370 |
|
else |
371 |
|
return "????????"; |
372 |
|
return fpr; |
373 |
|
} |
374 |
|
|
375 |
|
|
376 |
const char * |
const char* |
377 |
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) |
378 |
{ |
{ |
379 |
if (key) |
if (key) |
387 |
case GPGME_VALIDITY_MARGINAL: |
case GPGME_VALIDITY_MARGINAL: |
388 |
return _("Marginal"); |
return _("Marginal"); |
389 |
case GPGME_VALIDITY_FULL: |
case GPGME_VALIDITY_FULL: |
|
case GPGME_VALIDITY_ULTIMATE: |
|
390 |
return _("Full"); |
return _("Full"); |
391 |
|
case GPGME_VALIDITY_ULTIMATE: |
392 |
|
return _("Ultimate"); |
393 |
} |
} |
394 |
return ""; |
return ""; |
395 |
} |
} |
396 |
|
|
397 |
|
|
398 |
const char * |
const char* |
399 |
get_key_trust (gpgme_key_t key, int uididx, int listmode) |
get_key_trust (gpgme_key_t key, int uididx, int listmode) |
400 |
{ |
{ |
401 |
return get_key_trust2 (key, 0, uididx, listmode); |
return get_key_trust2 (key, 0, uididx, listmode); |
402 |
} |
} |
403 |
|
|
404 |
|
|
405 |
const char * |
const char* |
406 |
get_key_trust_str (int val) |
get_key_trust_str (int val) |
407 |
{ |
{ |
408 |
return get_key_trust2 (NULL, val, 0, 0); |
return get_key_trust2 (NULL, val, 0, 0); |
421 |
uididx = 0; |
uididx = 0; |
422 |
if (listmode) { |
if (listmode) { |
423 |
const char *s; |
const char *s; |
|
|
|
424 |
if (key->revoked) |
if (key->revoked) |
425 |
s = _("Revoked"); |
s = _("Revoked"); |
426 |
else if (key->expired) |
else if (key->expired) |
429 |
s = _("Disabled"); |
s = _("Disabled"); |
430 |
else |
else |
431 |
s = ""; |
s = ""; |
|
|
|
432 |
/* 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 |
433 |
what any user-id validities. */ |
the user-id validities. */ |
434 |
if (*s) |
if (*s) |
435 |
return m_strdup (s); |
return m_strdup (s); |
436 |
} |
} |
441 |
} |
} |
442 |
|
|
443 |
|
|
444 |
|
/* Return human readable description of the key @key. */ |
445 |
|
char* |
446 |
|
get_key_desc (gpgme_key_t key) |
447 |
|
{ |
448 |
|
gpgme_key_t sk; |
449 |
|
const char *state, *alg, *type; |
450 |
|
char *p; |
451 |
|
|
452 |
|
/* XXX: problems with the German translation. */ |
453 |
|
state = ""; |
454 |
|
if (key->disabled) |
455 |
|
state = _("Disabled"); |
456 |
|
if (key->expired) |
457 |
|
state = _("Expired"); |
458 |
|
if (key->revoked) |
459 |
|
state = _("Revoked"); |
460 |
|
alg = "OpenPGP"; |
461 |
|
if (strlen (key->subkeys->fpr) == 32) |
462 |
|
alg = "RSA Legacy"; |
463 |
|
type = _("public key"); |
464 |
|
if (!get_seckey (key->subkeys->keyid+8, &sk)) |
465 |
|
type = _("key pair"); |
466 |
|
p = new char[strlen (state) + strlen (alg) + strlen (type) + 4 + 1]; |
467 |
|
if (!p) |
468 |
|
BUG (0); |
469 |
|
sprintf (p, "%s %s %s", state, alg, type); |
470 |
|
return p; |
471 |
|
} |
472 |
|
|
473 |
|
|
474 |
/* Integer comparsion of @a and @b. |
/* Integer comparsion of @a and @b. |
475 |
Return values: same as in strcmp. */ |
Return values: same as in strcmp. */ |
476 |
static inline int |
static inline int |
492 |
return GPGME_VALIDITY_ULTIMATE+1; |
return GPGME_VALIDITY_ULTIMATE+1; |
493 |
else if (k->expired) |
else if (k->expired) |
494 |
return GPGME_VALIDITY_ULTIMATE+2; |
return GPGME_VALIDITY_ULTIMATE+2; |
495 |
|
else if (k->disabled) |
496 |
|
return GPGME_VALIDITY_ULTIMATE+3; |
497 |
return k->uids->validity; |
return k->uids->validity; |
498 |
} |
} |
499 |
|
|
502 |
static int CALLBACK |
static int CALLBACK |
503 |
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
504 |
{ |
{ |
505 |
|
struct keycache_s *aa, *bb; |
506 |
gpgme_key_t a, b; |
gpgme_key_t a, b; |
507 |
int cmpresult = 0; |
int cmpresult = 0; |
508 |
|
|
509 |
a = (gpgme_key_t)first; |
aa = (struct keycache_s *)first; |
510 |
b = (gpgme_key_t)second; |
bb = (struct keycache_s *)second; |
511 |
if (!a || !b) |
if (!aa || !bb) |
512 |
BUG (NULL); |
BUG (NULL); |
513 |
|
a = aa->key; |
514 |
|
b = bb->key; |
515 |
|
|
516 |
switch (sortby & ~KEYLIST_SORT_DESC) { |
switch (sortby & ~KEYLIST_SORT_DESC) { |
517 |
case KEY_SORT_USERID: |
case KEY_SORT_USERID: |
564 |
} |
} |
565 |
|
|
566 |
|
|
|
/* 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"); |
|
|
} |
|
|
|
|
|
|
|
567 |
int |
int |
568 |
keylist_add_groups( listview_ctrl_t lv ) |
keylist_add_groups (listview_ctrl_t lv) |
569 |
{ |
{ |
|
#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 |
|
570 |
return 0; |
return 0; |
571 |
} /* keylist_add_groups */ |
} |
572 |
|
|
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[] = { |
584 |
{5, 70, (char *)_("Validity")}, |
{5, 70, (char *)_("Validity")}, |
585 |
{0, 0, NULL} |
{0, 0, NULL} |
586 |
}; |
}; |
|
|
|
587 |
struct listview_column_s klist[] = { |
struct listview_column_s klist[] = { |
588 |
{0, 242, (char *)_("User ID")}, |
{0, 240, (char *)_("User ID")}, |
589 |
{1, 78, (char *)_("Key ID")}, |
{1, 78, (char *)_("Key ID")}, |
590 |
{2, 52, (char *)_("Type")}, |
{2, 52, (char *)_("Type")}, |
591 |
{3, 68, (char *)_("Size")}, |
{3, 66, (char *)_("Size")}, |
592 |
{4, 66, (char *)_("Cipher")}, |
{4, 60, (char *)_("Cipher")}, |
593 |
{5, 70, (char *)_("Validity")}, |
{5, 66, (char *)_("Validity")}, |
594 |
{6, 40, (char *)_("Trust")}, |
{6, 58, (char *)_("Trust")}, |
595 |
{7, 72, (char *)_("Creation")}, |
{7, 72, (char *)_("Creation")}, |
596 |
{0, 0, NULL} |
{0, 0, NULL} |
597 |
}; |
}; |
598 |
|
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; |
int j, n = 0, ext_chk = 0; |
|
int kl_nolist = 0; |
|
|
int rc = 0; |
|
|
|
|
|
rc = listview_new (&lv); |
|
|
if (rc) |
|
|
return rc; |
|
602 |
|
|
603 |
lv->ctrl = ctrl; |
listview_new (&lv, ctrl); |
604 |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) { |
if (mode & KEYLIST_ENCRYPT_MIN) { |
605 |
col = klist_enc; |
col = klist_enc; |
606 |
n = (DIM(klist_enc) -1); |
n = (DIM (klist_enc) -1); |
607 |
|
ext_chk = 1; |
608 |
} |
} |
609 |
else if ((mode & KEYLIST_SIGN)) { |
else if ((mode & KEYLIST_SIGN)) { |
610 |
col = klist_enc; |
col = klist_enc; |
611 |
n = (DIM(klist_enc) - 1) - 1; |
n = (DIM (klist_enc) - 1) - 1; |
612 |
|
ext_chk = 1; |
613 |
} |
} |
614 |
else { |
else { |
615 |
col = klist; |
col = klist; |
616 |
n = (DIM(klist) - 1); |
n = (DIM (klist) - 1); |
617 |
} |
} |
618 |
|
|
619 |
for( j = 0; j < n; j++ ) |
for (j = 0; j < n; j++) |
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) |
623 |
|
listview_set_chkbox_style (lv); |
624 |
|
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY); |
625 |
|
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR); |
626 |
|
ico[2] = LoadIcon (glob_hinst, (LPCTSTR)IDI_REV_KEYPAIR); |
627 |
|
ico[3] = LoadIcon (glob_hinst, (LPCTSTR)IDI_REV_PUBKEY); |
628 |
|
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); |
632 |
|
|
633 |
*r_lv = lv; |
*r_lv = lv; |
|
|
|
|
return 0; |
|
634 |
} |
} |
635 |
|
|
636 |
|
|
640 |
{ |
{ |
641 |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
642 |
gpgme_key_t key, skey; |
gpgme_key_t key, skey; |
643 |
const char * keyid; |
struct keycache_s *c; |
644 |
|
const char *keyid; |
645 |
|
|
646 |
if (pubkc && seckc) { |
if (pubkc && seckc) { |
647 |
gpg_keycache_rewind (pubkc); |
gpg_keycache_rewind (pubkc); |
648 |
while (!gpg_keycache_next_key (pubkc, 0, &key)) { |
while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) { |
649 |
keyid = key->subkeys->keyid; |
keyid = key->subkeys->keyid; |
650 |
if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey)) |
if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey)) |
651 |
keylist_add_key (lv, mode, key); |
keylist_add_key (lv, mode, c, key); |
652 |
} |
} |
653 |
} |
} |
654 |
else if (pubkc) { |
else if (pubkc) { |
655 |
gpg_keycache_rewind (pubkc); |
gpg_keycache_rewind (pubkc); |
656 |
while (!err) { |
while (!err) { |
657 |
err = gpg_keycache_next_key (pubkc, 0, &key); |
err = gpg_keycache_next_key2 (pubkc, 0, &c, &key); |
658 |
if (!err) |
if (!err) |
659 |
keylist_add_key (lv, mode, key); |
keylist_add_key (lv, mode, c, key); |
660 |
} |
} |
661 |
} |
} |
662 |
} |
} |
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) || (mode & KEYLIST_ENCRYPT_MIN)) |
if (mode & KEYLIST_ENCRYPT_MIN) |
677 |
keylist_add_groups (lv); |
keylist_add_groups (lv); |
678 |
return lv; |
return lv; |
679 |
} |
} |
683 |
int |
int |
684 |
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) |
685 |
{ |
{ |
686 |
listview_del_all (lv); |
listview_del_all_items (lv); |
687 |
keylist_load_keycache( lv, mode, pubkc, NULL ); |
keylist_load_keycache (lv, mode, pubkc, NULL); |
688 |
keylist_sort (lv, sortby); |
keylist_sort (lv, sortby); |
689 |
return 0; |
return 0; |
690 |
} |
} |
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, gpgme_key_t key, int uididx, int keyidx, int list) |
do_addkey (listview_ctrl_t lv, struct keycache_s *ctx, gpgme_key_t key, |
741 |
|
int uididx, int keyidx, int list) |
742 |
{ |
{ |
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 */ |
752 |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
753 |
log_debug ("ElGamal (E+S) key found: %s (%s)\n", |
log_debug ("ElGamal (E+S) key found: %s (%s)\n", |
754 |
key->uids->name, key->subkeys->keyid); |
key->uids->name, key->subkeys->keyid); |
755 |
return 0; |
return 0; |
756 |
} |
} |
757 |
|
|
758 |
|
if (listview_add_item2 (lv, " ", (void *)ctx)) |
|
if (listview_add_item2 (lv, " ", (void *)key)) |
|
759 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
760 |
|
|
761 |
attr = key->uids->uid; |
attr = ctx->uids->uid; |
762 |
memset (&lvi, 0, sizeof lvi); |
memset (&lvi, 0, sizeof lvi); |
763 |
lvi.mask = LVIF_TEXT | LVIF_PARAM; |
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; |
764 |
lvi.pszText = (char *)attr; |
lvi.pszText = (char *)attr; |
765 |
lvi.lParam = (LPARAM )key; |
lvi.iImage = key_get_image_id (key); |
766 |
if (ListView_SetItem( lv->ctrl, &lvi ) == FALSE) |
lvi.lParam = (LPARAM )ctx; |
767 |
|
if (ListView_SetItem (lv->ctrl, &lvi) == FALSE) |
768 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
769 |
|
|
770 |
if (uididx == -1) { /* request the primary user-id of the key. */ |
if (uididx == -1) { /* request the primary user-id of the key. */ |
771 |
attr = key->uids->uid; |
attr = ctx->uids->uid; |
772 |
uididx = 0; |
uididx = 0; |
773 |
} |
} |
774 |
else { |
else { |
775 |
u = get_nth_userid (key, uididx); |
u = get_nth_userid (key, uididx); |
776 |
if (!u || u->revoked || uididx < 0) |
if (!u || u->revoked || uididx < 0) |
777 |
uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */ |
uididx = 0; |
778 |
u = get_nth_userid (key, uididx); |
u = get_nth_userid (key, uididx); |
779 |
attr = u->uid; |
attr = u->uid; |
780 |
} |
} |
781 |
if (attr == NULL || strlen (attr) < 5) { /* normal userids are >= 5 chars */ |
if (attr == NULL || strlen (attr) < 5) { /* normal userids are > 5 chars */ |
782 |
attr = _("Invalid User ID"); |
attr = _("Invalid User ID"); |
783 |
listview_add_sub_item (lv, 0, idx++, attr); |
listview_add_sub_item (lv, 0, idx++, attr); |
784 |
} |
} |
785 |
else { |
else |
786 |
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); |
|
|
} |
|
|
} |
|
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, sizeof 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; |
831 |
} |
} |
832 |
|
|
833 |
|
|
834 |
|
/* Update a single column @col but for each element in the |
835 |
|
listview @lv. */ |
836 |
|
void |
837 |
|
keylist_upd_col (listview_ctrl_t lv, int col) |
838 |
|
{ |
839 |
|
gpgme_key_t key; |
840 |
|
const char *s; |
841 |
|
char buf[32], *p; |
842 |
|
int i; |
843 |
|
|
844 |
|
for (i=0; i < listview_count_items (lv, 0); i++) { |
845 |
|
key = km_get_key_ptr (lv, i, NULL); |
846 |
|
if (!key) |
847 |
|
continue; |
848 |
|
switch (col) { |
849 |
|
case KM_COL_KEYID: |
850 |
|
_snprintf (buf, DIM (buf)-1, "0x%s", key->subkeys->keyid+8); |
851 |
|
listview_add_sub_item (lv, i, col, buf); |
852 |
|
break; |
853 |
|
|
854 |
|
case KM_COL_CIPHER: |
855 |
|
s = get_key_algo (key, 0); |
856 |
|
listview_add_sub_item (lv, i, col, s); |
857 |
|
break; |
858 |
|
|
859 |
|
case KM_COL_TYPE: |
860 |
|
s = find_secret_key (key)? "pub/sec" : "pub"; |
861 |
|
listview_add_sub_item (lv, i, col, s); |
862 |
|
break; |
863 |
|
|
864 |
|
case KM_COL_CREAT: |
865 |
|
s = get_key_created (key->subkeys->timestamp); |
866 |
|
listview_add_sub_item (lv, i, col, s); |
867 |
|
break; |
868 |
|
|
869 |
|
case KM_COL_DESC: |
870 |
|
p = get_key_desc (key); |
871 |
|
listview_add_sub_item (lv, i, col, p); |
872 |
|
free_if_alloc (p); |
873 |
|
break; |
874 |
|
} |
875 |
|
} |
876 |
|
} |
877 |
|
|
878 |
|
|
879 |
|
/* Update the listview item at position @pos with the data from |
880 |
|
the key @key. */ |
881 |
void |
void |
882 |
keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key) |
keylist_upd_key (listview_ctrl_t lv, int pos, |
883 |
|
struct keycache_s *ctx, gpgme_key_t key) |
884 |
{ |
{ |
885 |
const char *s; |
const char *s; |
886 |
|
char *p; |
887 |
char tmp[32]; |
char tmp[32]; |
888 |
|
|
889 |
listview_set_item2 (lv, pos, (void *)key); |
listview_set_item2 (lv, pos, (void *)ctx); |
890 |
/* the only mode we support is KYLIST_LIST in the Key Manager */ |
/* the only mode we support is KEYLIST_LIST in the Key Manager */ |
891 |
|
|
892 |
s = key->uids->uid; |
s = ctx->uids->uid; |
893 |
if (s) |
if (s) |
894 |
listview_add_sub_item (lv, pos, 0, s); |
listview_add_sub_item (lv, pos, KM_COL_UID, s); |
895 |
|
|
896 |
s = key->subkeys->keyid; |
s = key->subkeys->keyid; |
897 |
if (s) { |
if (s) { |
898 |
sprintf (tmp, "0x%s", s+8); |
sprintf (tmp, "0x%s", s+8); |
899 |
listview_add_sub_item (lv, pos, 1, tmp); |
listview_add_sub_item (lv, pos, KM_COL_KEYID, tmp); |
900 |
} |
} |
901 |
|
|
902 |
s = find_secret_key (key)? "pub/sec" : "pub"; |
s = find_secret_key (key)? "pub/sec" : "pub"; |
903 |
listview_add_sub_item (lv, pos, 2, s); |
listview_add_sub_item (lv, pos, KM_COL_TYPE, s); |
904 |
|
|
905 |
s = get_key_size (key, 0); |
s = get_key_size (key, 0); |
906 |
if (s) |
if (s) |
907 |
listview_add_sub_item (lv, pos, 3, s); |
listview_add_sub_item (lv, pos, KM_COL_SIZE, s); |
908 |
|
|
909 |
s = get_key_algo (key, 0); |
s = get_key_algo (key, 0); |
910 |
if (s) |
if (s) |
911 |
listview_add_sub_item (lv, pos, 4, s); |
listview_add_sub_item (lv, pos, KM_COL_CIPHER, s); |
912 |
|
|
913 |
s = get_key_status (key, 0, 1); |
p = get_key_status (key, 0, 1); |
914 |
if (s) |
if (p) { |
915 |
listview_add_sub_item (lv, pos, 5, s); |
listview_add_sub_item (lv, pos, KM_COL_VALID, p); |
916 |
|
free_if_alloc (p); |
917 |
|
} |
918 |
|
|
919 |
s = get_key_trust (key, 0, 1); |
s = get_key_trust (key, 0, 1); |
920 |
if (s) |
if (s) |
921 |
listview_add_sub_item (lv, pos, 6, s); |
listview_add_sub_item (lv, pos, KM_COL_TRUST, s); |
922 |
|
|
923 |
long t = key->subkeys->timestamp; |
long t = key->subkeys->timestamp; |
924 |
s = get_key_created (t); |
s = get_key_created (t); |
925 |
if (s) |
if (s) |
926 |
listview_add_sub_item (lv, pos, 7, s); |
listview_add_sub_item (lv, pos, KM_COL_CREAT, s); |
927 |
} |
} |
928 |
|
|
929 |
|
|
930 |
int |
int |
931 |
keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key) |
keylist_add_key (listview_ctrl_t lv, int mode, |
932 |
|
struct keycache_s *ctx, gpgme_key_t key) |
933 |
{ |
{ |
934 |
int uids, rc = 0, i; |
int uids, rc = 0, i; |
935 |
gpgme_subkey_t k; |
gpgme_subkey_t k; |
946 |
|
|
947 |
if (mode & KEYLIST_ALL) { |
if (mode & KEYLIST_ALL) { |
948 |
uids = count_userids (key); |
uids = count_userids (key); |
949 |
rc = do_addkey (lv, key, uids, i, 0); |
rc = do_addkey (lv, ctx, key, uids, i, 0); |
950 |
if( rc ) |
if (rc) |
951 |
return rc; |
return rc; |
952 |
} |
} |
953 |
else if (mode & KEYLIST_LIST) |
else if (mode & KEYLIST_LIST) |
954 |
return do_addkey (lv, key, -1, i, 1); |
return do_addkey (lv, ctx, key, -1, i, 1); |
955 |
else if (mode & KEYLIST_ENCRYPT) { |
else if (mode & KEYLIST_ENCRYPT) { |
956 |
if (k->can_encrypt && key_is_useable (k)) { |
if (k->can_encrypt && key_is_useable (k)) { |
957 |
if (mode & KEYLIST_FLAG_FILE) { |
if (mode & KEYLIST_FLAG_FILE) { |
958 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
959 |
if (rc) |
if (rc) |
960 |
return rc; |
return rc; |
961 |
} |
} |
962 |
else { |
else { |
963 |
for( uids = 0; uids < count_userids (key); uids++ ) { |
for (uids = 0; uids < count_userids (key); uids++) { |
964 |
rc = do_addkey( lv, key, uids, i, -1 ); |
rc = do_addkey (lv, ctx, key, uids, i, -1); |
965 |
if( rc ) |
if (rc) |
966 |
return rc; |
return rc; |
967 |
} |
} |
968 |
} |
} |
971 |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
972 |
if( k->can_encrypt && key_is_useable (k)) |
if( k->can_encrypt && key_is_useable (k)) |
973 |
{ |
{ |
974 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
975 |
return rc; |
return rc; |
976 |
} |
} |
977 |
} |
} |
979 |
if (k->can_sign |
if (k->can_sign |
980 |
&& find_secret_key (key) |
&& find_secret_key (key) |
981 |
&& key_is_useable (k)) { |
&& key_is_useable (k)) { |
982 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
983 |
if (rc) |
if (rc) |
984 |
return rc; |
return rc; |
985 |
} |
} |
987 |
} |
} |
988 |
|
|
989 |
return rc; |
return rc; |
990 |
} /* keylist_add_key */ |
} |
991 |
|
|
992 |
|
|
993 |
int |
int |
994 |
keylist_sort (listview_ctrl_t lv, int sortby) |
keylist_sort (listview_ctrl_t lv, int sortby) |
995 |
{ |
{ |
996 |
return listview_sort_items (lv, sortby, keylist_cmp_cb); |
return listview_sort_items (lv, sortby, keylist_cmp_cb); |
997 |
} |
} |
998 |
|
|
999 |
|
|
1000 |
/* Check that the validity @validity is at least >= marginal. */ |
/* Check that the validity @validity is at least >= marginal. */ |
1001 |
static int |
static int |
1002 |
key_check_validity (const char *validity) |
key_check_validity (gpgme_key_t key) |
1003 |
{ |
{ |
1004 |
if (strstr (validity, _("Unknown")) || |
gpgme_user_id_t u; |
1005 |
strstr (validity, _("Undefined")) || |
|
1006 |
strstr (validity, _("Never")) || |
for (u=key->uids; u; u =u->next) { |
1007 |
strstr (validity, _("None"))) |
if (u->validity >= GPGME_VALIDITY_MARGINAL) |
1008 |
return 0; |
return -1; |
1009 |
return 1; |
} |
1010 |
|
|
1011 |
|
return 0; |
1012 |
} |
} |
1013 |
|
|
1014 |
|
|
1017 |
fully trusted. @r_count returns the number of selected keys. |
fully trusted. @r_count returns the number of selected keys. |
1018 |
Return value: the key list on success, NULL otherwise. */ |
Return value: the key list on success, NULL otherwise. */ |
1019 |
gpgme_key_t* |
gpgme_key_t* |
1020 |
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) |
1021 |
{ |
{ |
1022 |
int count = 0, force_trust = 0; |
key_array_s *ka = NULL; |
1023 |
|
keycache_s *c; |
1024 |
|
gpgme_key_t *keybuf, key; |
1025 |
|
size_t count = 0; |
1026 |
|
int force_trust = 0; |
1027 |
int n, j, ka_pos = 0, rc = 0; |
int n, j, ka_pos = 0, rc = 0; |
1028 |
int k_pos=0; |
int k_pos=0; |
|
char keyid[32], valid[32], id[100]; |
|
|
key_array_s *ka = NULL; |
|
|
gpgme_key_t *keybuf; |
|
1029 |
|
|
1030 |
n = listview_count_items( lv, 0 ); |
n = listview_count_items (lv, 0); |
1031 |
|
|
1032 |
ka = key_array_new( n ); |
ka = key_array_new (n); |
1033 |
if (!ka) |
if (!ka) |
1034 |
BUG (NULL); |
BUG (NULL); |
1035 |
|
|
1036 |
keybuf = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); |
keybuf = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t)); |
1037 |
if (!keybuf) |
if (!keybuf) |
1038 |
BUG (NULL); |
BUG (NULL); |
1039 |
|
|
1040 |
for( j = 0; j < n; j++ ) { |
for (j = 0; j < n; j++) { |
1041 |
if( listview_get_item_state (lv, j) || n == 1) { |
if (listview_get_item_state (lv, j) || n == 1) { |
1042 |
listview_get_item_text (lv, j, 0, id, sizeof id-1); |
key = km_get_key_ptr (lv, j, &c); |
1043 |
listview_get_item_text (lv, j, 1, keyid, sizeof keyid - 1); |
if (!key) |
1044 |
listview_get_item_text (lv, j, 4, valid, sizeof valid -1); |
BUG (0); |
1045 |
if( !key_check_validity (valid) |
if (!key_check_validity (key) && |
1046 |
&& !key_array_search( ka, ka_pos, keyid )) { |
!key_array_search (ka, ka_pos, key->subkeys->keyid)) { |
1047 |
char *warn = new char[512+strlen (id) + 1]; |
char *warn = new char[512+strlen (c->uids->uid) + 1]; |
1048 |
if (!warn) |
if (!warn) |
1049 |
BUG (0); |
BUG (0); |
1050 |
sprintf (warn, |
sprintf (warn, |
1052 |
"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" |
1053 |
"doing, you may answer the next question with yes\n" |
"doing, you may answer the next question with yes\n" |
1054 |
"\n" |
"\n" |
1055 |
"Use \"%s\" anyway?"), id); |
"Use \"%s\" anyway?"), c->uids->uid); |
1056 |
if (reg_prefs.always_trust) |
if (reg_prefs.always_trust) |
1057 |
rc = IDYES; |
rc = IDYES; |
1058 |
else |
else |
1059 |
rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK); |
rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK); |
1060 |
if (rc == IDYES) { |
if (rc == IDYES) { |
1061 |
gpgme_key_t k; |
keybuf[k_pos++] = key; |
|
get_pubkey (keyid, &k); |
|
|
keybuf[k_pos++] = k; |
|
1062 |
force_trust++; |
force_trust++; |
1063 |
ka[ka_pos].checked = 1; |
ka[ka_pos].checked = 1; |
1064 |
strcpy (ka[ka_pos++].keyid, keyid); |
strcpy (ka[ka_pos++].keyid, key->subkeys->keyid); |
1065 |
count++; |
count++; |
1066 |
} |
} |
1067 |
free_if_alloc (warn); |
free_if_alloc (warn); |
1068 |
} |
} |
1069 |
else { |
else { |
1070 |
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; |
|
1071 |
count++; |
count++; |
1072 |
} |
} |
1073 |
} |
} |
1082 |
|
|
1083 |
|
|
1084 |
static int |
static int |
1085 |
keylist_get_keyflags (const char *buf, size_t buflen) |
keylist_get_keyflags (gpgme_key_t key) |
1086 |
{ |
{ |
1087 |
int c = 0, flags = 0; |
int flags = KEYFLAG_NONE; |
1088 |
|
|
1089 |
if( *buf != '[' ) |
if (key->revoked) |
1090 |
return KEYFLAG_NONE; |
flags |= KEYFLAG_REVOKED; |
1091 |
while (buf && c != ']') |
if (key->expired) |
1092 |
{ |
flags |= KEYFLAG_EXPIRED; |
1093 |
c = *buf++; |
if (key->disabled) |
1094 |
if (c == 'R') |
flags |= KEYFLAG_DISABLED; |
|
flags |= KEYFLAG_REVOKED; |
|
|
if (c == 'E') |
|
|
flags |= KEYFLAG_EXPIRED; |
|
|
if (c == 'D') |
|
|
flags |= KEYFLAG_DISABLED; |
|
|
} |
|
1095 |
|
|
1096 |
return flags; |
return flags; |
1097 |
} /* keylist_get_keyflags */ |
} |
1098 |
|
|
1099 |
|
|
1100 |
gpgme_key_t* |
gpgme_key_t* |
1101 |
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) |
1102 |
{ |
{ |
1103 |
gpgme_key_t* rset; |
struct keycache_s *c; |
1104 |
gpgme_key_t k; |
gpgme_key_t *rset; |
1105 |
int i, n, id, k_pos=0; |
gpgme_key_t key; |
1106 |
char keyid[32], t[128], t2[128]; |
size_t k_pos = 0; |
1107 |
|
int i, n, id; |
1108 |
|
|
1109 |
n = listview_count_items (lv, 0); |
n = listview_count_items (lv, 0); |
1110 |
if (!n) |
if (!n) |
1111 |
return 0; |
return 0; |
1112 |
rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); |
rset = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t)); |
1113 |
if (!rset) |
if (!rset) |
1114 |
BUG (NULL); |
BUG (NULL); |
1115 |
for( i = 0; i < n; i++ ) { |
for (i = 0; i < n; i++) { |
1116 |
if( !listview_get_item_state( lv, i ) ) |
if (!listview_get_item_state (lv, i)) |
1117 |
continue; |
continue; |
1118 |
listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 ); |
key = km_get_key_ptr (lv, i, &c); |
1119 |
switch( listype ) { |
switch (listype) { |
1120 |
case KEYLIST_LIST: |
case KEYLIST_LIST: |
1121 |
listview_get_item_text( lv, i, 5, t, sizeof t - 1 ); |
if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) { |
1122 |
if( keylist_get_keyflags( t, strlen( t ) ) & KEYFLAG_REVOKED ) { |
id = printf_box (_("Recipients"), MB_INFO|MB_YESNO, |
1123 |
_snprintf( t2, sizeof t2 -1, |
_("KeyID %s.\nDo you really want to export a revoked key?"), |
1124 |
_("KeyID %s.\nDo you really want to export a revoked key?"), keyid ); |
c->uids->uid); |
1125 |
id = msg_box( lv->ctrl, t2, _("Recipients"), MB_INFO|MB_YESNO ); |
if (id == IDNO) |
1126 |
if( id == IDNO ) |
continue; |
|
continue; |
|
1127 |
} |
} |
1128 |
break; |
break; |
1129 |
} |
} |
1130 |
get_pubkey (keyid, &k); |
rset[k_pos++] = key; |
|
rset[k_pos++] = k; |
|
1131 |
} |
} |
1132 |
if (r_count) |
if (r_count) |
1133 |
*r_count = k_pos; |
*r_count = k_pos; |
1134 |
return rset; |
return rset; |
1135 |
} /* keylist_enum_recipients */ |
} |
1136 |
|
|
1137 |
|
|
1138 |
void |
void |
1139 |
seclist_destroy (keylist_t * list) |
seclist_destroy (keylist_t *list) |
1140 |
{ |
{ |
1141 |
keylist_t l2; |
keylist_t l2; |
1142 |
while (*list) { |
while (*list) { |
1145 |
*list = l2; |
*list = l2; |
1146 |
} |
} |
1147 |
list = NULL; |
list = NULL; |
1148 |
} /* seclist_destroy */ |
} |
1149 |
|
|
1150 |
|
|
1151 |
void |
void |
1182 |
if (key->disabled || !key_is_useable (key->subkeys)) |
if (key->disabled || !key_is_useable (key->subkeys)) |
1183 |
continue; |
continue; |
1184 |
|
|
1185 |
uid = utf8_to_wincp (id, strlen (id)); |
uid = utf8_to_native (id); |
1186 |
size = strlen( uid ) + strlen( keyid ) + 32; |
size = strlen (uid) + strlen (keyid) + 32; |
1187 |
inf = new char[size+1]; |
inf = new char[size+1]; |
1188 |
if( !inf ) |
if (!inf) |
1189 |
BUG( NULL ); |
BUG (NULL); |
1190 |
_snprintf (inf, size, "%s (%s/0x%s)", uid, |
_snprintf (inf, size, "%s (%s/0x%s)", uid, |
1191 |
get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8); |
get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8); |
1192 |
combox_add_string (kb, inf); |
combox_add_string (kb, inf); |
1193 |
free_if_alloc (inf); |
free_if_alloc (inf); |
1204 |
l2->next = l; |
l2->next = l; |
1205 |
} |
} |
1206 |
} |
} |
1207 |
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); |
1208 |
SendMessage( kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key ); |
pos++, l2=l2->next) |
1209 |
SendMessage( kb, CB_SETCURSEL, 0, 0 ); |
SendMessage (kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key); |
1210 |
|
SendMessage (kb, CB_SETCURSEL, 0, 0); |
1211 |
*ret_list = list; |
*ret_list = list; |
1212 |
} |
} |
1213 |
|
|