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 |
#include <windows.h> |
#include <windows.h> |
22 |
#include <commctrl.h> |
#include <commctrl.h> |
23 |
#include <time.h> |
#include <time.h> |
33 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
34 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
35 |
|
|
36 |
|
|
37 |
|
#define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled) |
38 |
|
|
39 |
static struct listview_column_s klist_enc[] = { |
static struct listview_column_s klist_enc[] = { |
40 |
{0, 242, (char *)_("User ID")}, |
{0, 242, (char *)_("User ID")}, |
41 |
{1, 80, (char *)_("Key ID")}, |
{1, 80, (char *)_("Key ID")}, |
106 |
} /* key_array_search */ |
} /* key_array_search */ |
107 |
|
|
108 |
|
|
109 |
|
gpgme_user_id_t |
110 |
|
get_nth_userid (gpgme_key_t key, int idx) |
111 |
|
{ |
112 |
|
gpgme_user_id_t t; |
113 |
|
|
114 |
|
if (!key->uids) |
115 |
|
return NULL; |
116 |
|
t = key->uids; |
117 |
|
while (idx-- && t->next) |
118 |
|
t = t->next; |
119 |
|
return t; |
120 |
|
} |
121 |
|
|
122 |
|
|
123 |
|
int |
124 |
|
count_userids (gpgme_key_t key) |
125 |
|
{ |
126 |
|
gpgme_user_id_t u; |
127 |
|
int n = 0; |
128 |
|
|
129 |
|
u = key->uids; |
130 |
|
if (!u) |
131 |
|
return 0; |
132 |
|
while (u->next) { |
133 |
|
u = u->next; |
134 |
|
n++; |
135 |
|
} |
136 |
|
return n; |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
gpgme_subkey_t |
141 |
|
get_nth_key (gpgme_key_t key, int idx) |
142 |
|
{ |
143 |
|
gpgme_subkey_t t; |
144 |
|
|
145 |
|
if (!key->subkeys) |
146 |
|
return NULL; |
147 |
|
t = key->subkeys; |
148 |
|
while (idx-- && t->next) |
149 |
|
t = t->next; |
150 |
|
return t; |
151 |
|
} |
152 |
|
|
153 |
|
int |
154 |
|
count_subkeys (gpgme_key_t key) |
155 |
|
{ |
156 |
|
gpgme_subkey_t k; |
157 |
|
int n = -1; /* ignore primary key */ |
158 |
|
|
159 |
|
k = key->subkeys; |
160 |
|
if (!n) |
161 |
|
return 0; |
162 |
|
while (k->next) { |
163 |
|
k = k->next; |
164 |
|
n++; |
165 |
|
} |
166 |
|
return n; |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
gpgme_key_sig_t |
171 |
|
get_nth_uid_sig (gpgme_user_id_t uid, int idx) |
172 |
|
{ |
173 |
|
gpgme_key_sig_t ks; |
174 |
|
|
175 |
|
if (!uid->signatures) |
176 |
|
return NULL; |
177 |
|
ks = uid->signatures; |
178 |
|
while (idx-- && ks->next) |
179 |
|
ks = ks->next; |
180 |
|
return ks; |
181 |
|
} |
182 |
|
|
183 |
|
int |
184 |
|
count_uid_sigs (gpgme_user_id_t uid) |
185 |
|
{ |
186 |
|
gpgme_key_sig_t k; |
187 |
|
int n = 0; |
188 |
|
|
189 |
|
if (!uid->signatures) |
190 |
|
return 0; |
191 |
|
k = uid->signatures; |
192 |
|
while (k->next) |
193 |
|
n++; |
194 |
|
return n; |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
const char* |
const char* |
199 |
get_key_algo (gpgme_key_t key, int keyidx) |
get_key_algo (gpgme_key_t key, int keyidx) |
200 |
{ |
{ |
201 |
static char algo_id[128]; |
static char algo_id[128]; |
202 |
|
gpgme_subkey_t k; |
203 |
char alg[32]; |
char alg[32]; |
204 |
const char *subalg; |
const char *subalg; |
205 |
int n, algo_main, algo_sub; |
int n=0; |
206 |
|
|
207 |
if (keyidx > 0) { |
if (keyidx > 0) { |
208 |
algo_main = gpgme_key_get_ulong_attr( key, GPGME_ATTR_ALGO, NULL, keyidx-1 ); |
k = get_nth_key (key, keyidx-1); |
209 |
subalg = gpgme_key_expand_attr( GPGME_ATTR_ALGO, algo_main ); |
subalg = get_key_pubalgo (k->pubkey_algo); |
210 |
_snprintf( algo_id, DIM (algo_id)-1, "%s", subalg); |
_snprintf( algo_id, DIM (algo_id)-1, "%s", subalg); |
211 |
return algo_id; |
return algo_id; |
212 |
} |
} |
213 |
algo_main = gpgme_key_get_ulong_attr (key, GPGME_ATTR_ALGO, NULL, 0); |
strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo)); |
214 |
strcpy (alg, gpgme_key_expand_attr (GPGME_ATTR_ALGO, algo_main)); |
n = count_subkeys (key); |
|
n = gpgme_key_count_items (key, GPGME_ATTR_KEYID); |
|
215 |
if (n > 1) { |
if (n > 1) { |
216 |
algo_sub = gpgme_key_get_ulong_attr (key, GPGME_ATTR_ALGO, NULL, n-1); |
k = get_nth_key (key, n-1); |
217 |
subalg = gpgme_key_expand_attr (GPGME_ATTR_ALGO, algo_sub); |
subalg = get_key_pubalgo (k->pubkey_algo); |
218 |
_snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg); |
_snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg); |
219 |
return algo_id; |
return algo_id; |
220 |
} |
} |
221 |
return gpgme_key_expand_attr (GPGME_ATTR_ALGO, algo_main); |
return get_key_pubalgo (key->subkeys->pubkey_algo); |
222 |
} /* get_key_algo */ |
} /* get_key_algo */ |
223 |
|
|
224 |
|
|
228 |
static char timebuf[128]; |
static char timebuf[128]; |
229 |
struct tm *warp; |
struct tm *warp; |
230 |
|
|
231 |
if( timestamp == 0 || timestamp == -1 ) |
if (timestamp == 0 || timestamp == -1) |
232 |
return "????-??-??"; |
return "????-??-??"; |
233 |
warp = localtime( ×tamp ); |
warp = localtime( ×tamp ); |
234 |
_snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d", |
_snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d", |
265 |
get_key_size (gpgme_key_t key, int keyidx) |
get_key_size (gpgme_key_t key, int keyidx) |
266 |
{ |
{ |
267 |
static char size_id[64]; |
static char size_id[64]; |
268 |
|
gpgme_subkey_t k; |
269 |
int n, size_main, size_sub; |
int n, size_main, size_sub; |
270 |
|
|
271 |
if (keyidx > 0) { |
if (keyidx > 0) { |
272 |
size_main = gpgme_key_get_ulong_attr (key, GPGME_ATTR_LEN, NULL, keyidx-1); |
k = get_nth_key (key, keyidx-1); |
273 |
|
size_main = k->length; |
274 |
_snprintf (size_id, DIM (size_id)-1, "%d", size_main); |
_snprintf (size_id, DIM (size_id)-1, "%d", size_main); |
275 |
return size_id; |
return size_id; |
276 |
} |
} |
277 |
size_main = gpgme_key_get_ulong_attr (key, GPGME_ATTR_LEN, NULL, 0); |
size_main = key->subkeys->length; |
278 |
n = gpgme_key_count_items (key, GPGME_ATTR_KEYID); |
n = count_subkeys (key); |
279 |
if (n > 1) { |
if (n > 1) { |
280 |
size_sub = gpgme_key_get_ulong_attr( key, GPGME_ATTR_LEN, NULL, n-1 ); |
k = get_nth_key (key, n-1); |
281 |
|
size_sub = k->length; |
282 |
_snprintf( size_id, sizeof (size_id) - 1, "%d/%d", size_main, size_sub ); |
_snprintf( size_id, sizeof (size_id) - 1, "%d/%d", size_main, size_sub ); |
283 |
return size_id; |
return size_id; |
284 |
} |
} |
287 |
} /* get_key_size */ |
} /* get_key_size */ |
288 |
|
|
289 |
|
|
290 |
|
const char* |
291 |
|
get_key_pubalgo (gpgme_pubkey_algo_t alg) |
292 |
|
{ |
293 |
|
switch (alg) { |
294 |
|
case GPGME_PK_DSA: return "DSA"; |
295 |
|
case GPGME_PK_ELG_E: return "ELG"; |
296 |
|
case GPGME_PK_RSA: return "RSA"; |
297 |
|
} |
298 |
|
return "???"; |
299 |
|
} |
300 |
|
|
301 |
const char * |
const char * |
302 |
get_key_fpr (gpgme_key_t key) |
get_key_fpr (gpgme_key_t key) |
303 |
{ |
{ |
307 |
size_t i=0; |
size_t i=0; |
308 |
|
|
309 |
memset (fpr_md, 0, sizeof (fpr_md)); |
memset (fpr_md, 0, sizeof (fpr_md)); |
310 |
fpr = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, 0); |
fpr = key->subkeys->fpr; |
311 |
if (!fpr || !*fpr) { |
if (!fpr || !*fpr) { |
312 |
memset (tmp, '0', 40); |
memset (tmp, '0', 40); |
313 |
fpr = tmp; |
fpr = tmp; |
330 |
} /* get_key_fpr */ |
} /* get_key_fpr */ |
331 |
|
|
332 |
|
|
333 |
static const char * |
const char * |
334 |
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) |
335 |
{ |
{ |
336 |
if (key) |
if (key) |
337 |
val = gpgme_key_get_ulong_attr (key, GPGME_ATTR_OTRUST, NULL, uididx); |
val = key->owner_trust; /* uididx?? */ |
338 |
switch (val) { |
switch (val) { |
339 |
case GPGME_TRUST_UNKNOWN: |
case GPGME_VALIDITY_UNKNOWN: |
340 |
case GPGME_TRUST_DONTKNOW: |
case GPGME_VALIDITY_UNDEFINED: |
341 |
return "None"; |
return "None"; |
342 |
case GPGME_TRUST_NEVER: |
case GPGME_VALIDITY_NEVER: |
343 |
return "Never"; |
return "Never"; |
344 |
case GPGME_TRUST_MARGINAL: |
case GPGME_VALIDITY_MARGINAL: |
345 |
return "Marginal"; |
return "Marginal"; |
346 |
case GPGME_TRUST_FULLY: |
case GPGME_VALIDITY_FULL: |
347 |
case GPGME_TRUST_ULTIMATE: |
case GPGME_VALIDITY_ULTIMATE: |
348 |
return "Full"; |
return "Full"; |
349 |
} |
} |
350 |
return ""; |
return ""; |
368 |
char* |
char* |
369 |
get_key_status (gpgme_key_t key, int uididx, int listmode) |
get_key_status (gpgme_key_t key, int uididx, int listmode) |
370 |
{ |
{ |
371 |
|
gpgme_user_id_t u; |
372 |
char fmt[64], * p; |
char fmt[64], * p; |
373 |
const char * attr; |
const char * attr; |
374 |
int i = 0; |
int i = 0; |
375 |
u32 key_attr =0; |
u32 key_attr =0; |
376 |
|
|
377 |
if (uididx < 0 || gpgme_key_count_items (key, GPGME_ATTR_USERID) > uididx) |
if (uididx < 0 || count_userids (key) > uididx) |
378 |
uididx = 0; |
uididx = 0; |
379 |
memset (fmt, 0, sizeof (fmt)); |
memset (fmt, 0, sizeof (fmt)); |
380 |
if (listmode) { |
if (listmode) { |
381 |
if (gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_REVOKED, NULL, 0)) |
if (key->revoked) |
382 |
sprintf (fmt, "Revoked"); |
sprintf (fmt, "Revoked"); |
383 |
else if (gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_EXPIRED, NULL, 0)) |
else if (key->expired) |
384 |
sprintf (fmt, "Expired"); |
sprintf (fmt, "Expired"); |
385 |
else if (gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_DISABLED, NULL, 0)) |
else if (key->disabled) |
386 |
sprintf (fmt, "Disabled"); |
sprintf (fmt, "Disabled"); |
387 |
/* 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 |
388 |
what any user-id validities. */ |
what any user-id validities. */ |
389 |
if (strlen (fmt) > 0) |
if (strlen (fmt) > 0) |
390 |
return m_strdup (fmt); |
return m_strdup (fmt); |
391 |
} |
} |
392 |
|
u = get_nth_userid (key, uididx); |
393 |
key_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_VALIDITY, NULL, uididx); |
key_attr = u->validity; |
394 |
attr = gpgme_key_expand_attr (GPGME_ATTR_VALIDITY, key_attr); |
attr = get_key_trust2 (NULL, key_attr, 0, 0); |
395 |
p = new char[strlen( attr ) + 2]; |
p = new char[strlen( attr ) + 2]; |
396 |
|
if (!p) |
397 |
|
BUG (NULL); |
398 |
sprintf (p, "%s", attr); |
sprintf (p, "%s", attr); |
399 |
return p; |
return p; |
400 |
} /* get_key_status */ |
} /* get_key_status */ |
424 |
b = (gpgme_key_t)second; |
b = (gpgme_key_t)second; |
425 |
|
|
426 |
switch( sortby & ~KEYLIST_SORT_DESC ) { |
switch( sortby & ~KEYLIST_SORT_DESC ) { |
427 |
case GPGME_ATTR_USERID: |
case KEY_SORT_USERID: |
428 |
aa = gpgme_key_get_string_attr( a, GPGME_ATTR_USERID, NULL, 0 ); |
aa = a->uids->uid; |
429 |
bb = gpgme_key_get_string_attr( b, GPGME_ATTR_USERID, NULL, 0 ); |
bb = b->uids->uid; |
430 |
cmpresult = strcmpi( aa? aa : "", bb? bb : "" ); |
cmpresult = strcmpi (aa? aa : "", bb? bb : ""); |
431 |
break; |
break; |
432 |
|
|
433 |
case GPGME_ATTR_KEYID: |
case KEY_SORT_KEYID: |
434 |
aa = gpgme_key_get_string_attr( a, GPGME_ATTR_KEYID, NULL, 0) + 8; |
aa = a->subkeys->keyid+8; |
435 |
bb = gpgme_key_get_string_attr( b, GPGME_ATTR_KEYID, NULL, 0) + 8; |
bb = b->subkeys->keyid+8; |
436 |
cmpresult = strcmpi( aa? aa : "", bb? bb : "" ); |
cmpresult = strcmpi( aa? aa : "", bb? bb : "" ); |
437 |
break; |
break; |
438 |
|
|
439 |
case GPGME_ATTR_VALIDITY: |
case KEY_SORT_VALIDITY: |
440 |
na = gpgme_key_get_ulong_attr( a, GPGME_ATTR_VALIDITY, NULL, 0 ); |
na = a->uids->validity; |
441 |
nb = gpgme_key_get_ulong_attr( b, GPGME_ATTR_VALIDITY, NULL, 0 ); |
nb = b->uids->validity; |
442 |
cmpresult = int_cmp( na, nb ); |
cmpresult = int_cmp (na, nb); |
443 |
break; |
break; |
444 |
|
|
445 |
case GPGME_ATTR_OTRUST: |
case KEY_SORT_OTRUST: |
446 |
na = gpgme_key_get_ulong_attr (a, GPGME_ATTR_OTRUST, NULL, 0); |
na = a->owner_trust; |
447 |
nb = gpgme_key_get_ulong_attr (b, GPGME_ATTR_OTRUST, NULL, 0); |
nb = b->owner_trust; |
448 |
cmpresult = int_cmp (na, nb); |
cmpresult = int_cmp (na, nb); |
449 |
break; |
break; |
450 |
|
|
451 |
case GPGME_ATTR_IS_SECRET: |
case KEY_SORT_IS_SECRET: |
452 |
aa = gpgme_key_get_string_attr( a, GPGME_ATTR_KEYID, NULL, 0 ); |
aa = a->subkeys->keyid; |
453 |
bb = gpgme_key_get_string_attr( b, GPGME_ATTR_KEYID, NULL, 0 ); |
bb = b->subkeys->keyid; |
454 |
get_seckey( aa, &a ); |
get_seckey (aa, &a); |
455 |
get_seckey( bb, &b ); |
get_seckey (bb, &b); |
456 |
if( a ) |
if (a) |
457 |
na = gpgme_key_get_ulong_attr( a, GPGME_ATTR_IS_SECRET, NULL, 0 ); |
na = a->secret; |
458 |
if( b ) |
if (b) |
459 |
nb = gpgme_key_get_ulong_attr( b, GPGME_ATTR_IS_SECRET, NULL, 0 ); |
nb = b->secret; |
460 |
cmpresult = int_cmp( na, nb ); |
cmpresult = int_cmp (na, nb); |
461 |
break; |
break; |
462 |
|
|
463 |
case GPGME_ATTR_LEN: |
case KEY_SORT_LEN: |
464 |
na = gpgme_key_get_ulong_attr( a, GPGME_ATTR_LEN, NULL, 0 ); |
na = a->subkeys->length; |
465 |
nb = gpgme_key_get_ulong_attr( b, GPGME_ATTR_LEN, NULL, 0 ); |
nb = b->subkeys->length; |
466 |
cmpresult = int_cmp( na, nb ); |
cmpresult = int_cmp( na, nb ); |
467 |
break; |
break; |
468 |
|
|
469 |
case GPGME_ATTR_CREATED: |
case KEY_SORT_CREATED: |
470 |
ta = gpgme_key_get_ulong_attr( a, GPGME_ATTR_CREATED, NULL, 0 ); |
ta = a->subkeys->timestamp; |
471 |
tb = gpgme_key_get_ulong_attr( b, GPGME_ATTR_CREATED, NULL, 0 ); |
tb = b->subkeys->timestamp; |
472 |
strcpy( tmpa, get_key_created( ta ) ); aa = tmpa; |
strcpy( tmpa, get_key_created( ta ) ); aa = tmpa; |
473 |
strcpy( tmpb, get_key_created( tb ) ); bb = tmpb; |
strcpy( tmpb, get_key_created( tb ) ); bb = tmpb; |
474 |
cmpresult = strcmpi( aa? aa : "", bb? bb : "" ); |
cmpresult = strcmpi( aa? aa : "", bb? bb : "" ); |
475 |
break; |
break; |
476 |
|
|
477 |
case GPGME_ATTR_ALGO: |
case KEY_SORT_ALGO: |
478 |
aa = gpgme_key_get_string_attr (a, GPGME_ATTR_ALGO, NULL, 0); |
na = a->subkeys->pubkey_algo; |
479 |
bb = gpgme_key_get_string_attr (b, GPGME_ATTR_ALGO, NULL, 0); |
nb = b->subkeys->pubkey_algo; |
480 |
cmpresult = strcmpi (aa? aa : "", bb? bb : ""); |
cmpresult = int_cmp (na, nb); |
481 |
break; |
break; |
482 |
|
|
483 |
default: |
default: |
484 |
aa = gpgme_key_get_string_attr( a, GPGME_ATTR_USERID, NULL, 0 ); |
aa = a->uids->uid; |
485 |
bb = gpgme_key_get_string_attr( b, GPGME_ATTR_USERID, NULL, 0 ); |
bb = b->uids->uid; |
486 |
cmpresult = strcmpi( aa? aa : "", bb? bb : "" ); |
cmpresult = strcmpi( aa? aa : "", bb? bb : "" ); |
487 |
break; |
break; |
488 |
} |
} |
503 |
for( mbr = grp->list; mbr; mbr = mbr->next ) { |
for( mbr = grp->list; mbr; mbr = mbr->next ) { |
504 |
if( get_pubkey( mbr->name, &key ) ) |
if( get_pubkey( mbr->name, &key ) ) |
505 |
continue; |
continue; |
506 |
valid = gpgme_key_get_ulong_attr( key, GPGME_ATTR_KEY_VALIDITY, NULL, 0 ); |
valid = key->uids->validity; |
507 |
switch( valid ) { |
switch( valid ) { |
508 |
case GPGME_VALIDITY_MARGINAL: |
case GPGME_VALIDITY_MARGINAL: |
509 |
case GPGME_VALIDITY_NEVER: |
case GPGME_VALIDITY_NEVER: |
510 |
case GPGME_VALIDITY_UNDEFINED: |
case GPGME_VALIDITY_UNDEFINED: |
511 |
return gpgme_key_expand_attr( GPGME_ATTR_VALIDITY, valid ); |
return get_key_trust2 (NULL, valid, 0, 0); |
512 |
} |
} |
513 |
} |
} |
514 |
return gpgme_key_expand_attr( GPGME_ATTR_VALIDITY, GPGME_VALIDITY_FULL ); |
return _("Full"); |
515 |
} /* calc_validity */ |
} /* calc_validity */ |
516 |
|
|
517 |
|
|
518 |
int |
int |
519 |
keylist_add_groups( listview_ctrl_t lv ) |
keylist_add_groups( listview_ctrl_t lv ) |
520 |
{ |
{ |
521 |
|
#if 0 |
522 |
gpg_optfile_t gh; |
gpg_optfile_t gh; |
523 |
gpg_group_t grp; |
gpg_group_t grp; |
524 |
const char *valid; |
const char *valid; |
536 |
listview_add_sub_item( lv, 0, 3, "Unknown" ); |
listview_add_sub_item( lv, 0, 3, "Unknown" ); |
537 |
listview_add_sub_item( lv, 0, 4, valid?valid : "Unknown" ); |
listview_add_sub_item( lv, 0, 4, valid?valid : "Unknown" ); |
538 |
} |
} |
539 |
|
#endif |
540 |
return 0; |
return 0; |
541 |
} /* keylist_add_groups */ |
} /* keylist_add_groups */ |
542 |
|
|
580 |
keylist_load_keycache (listview_ctrl_t lv, int mode, |
keylist_load_keycache (listview_ctrl_t lv, int mode, |
581 |
gpgme_keycache_t pubkc, gpgme_keycache_t seckc) |
gpgme_keycache_t pubkc, gpgme_keycache_t seckc) |
582 |
{ |
{ |
583 |
gpgme_error_t err = GPGME_No_Error; |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
584 |
gpgme_key_t key, skey; |
gpgme_key_t key, skey; |
585 |
const char * keyid; |
const char * keyid; |
586 |
|
|
587 |
if( pubkc && seckc ) { |
if( pubkc && seckc ) { |
588 |
gpgme_keycache_rewind( pubkc ); |
gpgme_keycache_rewind( pubkc ); |
589 |
while( !gpgme_keycache_next_key( pubkc, 0, &key ) ) { |
while( !gpgme_keycache_next_key( pubkc, 0, &key ) ) { |
590 |
keyid = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, 0 ); |
keyid = key->subkeys->keyid; |
591 |
if( keyid && !gpgme_keycache_find_key( seckc, keyid, 0, &skey ) ) |
if( keyid && !gpgme_keycache_find_key( seckc, keyid, 0, &skey ) ) |
592 |
keylist_add_key (lv, mode, key); |
keylist_add_key (lv, mode, key); |
593 |
} |
} |
646 |
const char * keyid; |
const char * keyid; |
647 |
gpgme_key_t skey; |
gpgme_key_t skey; |
648 |
|
|
649 |
keyid = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, 0 ); |
keyid = key->subkeys->keyid; |
650 |
if( !keyid ) |
if (!keyid) |
651 |
return 0; |
return 0; |
652 |
get_seckey( keyid, &skey ); |
get_seckey (keyid, &skey); |
653 |
return skey? 1 : 0; |
return skey? 1 : 0; |
654 |
} /* find_secret_key */ |
} /* find_secret_key */ |
655 |
|
|
659 |
{ |
{ |
660 |
LV_ITEM lvi; |
LV_ITEM lvi; |
661 |
gpgme_key_t seckey; |
gpgme_key_t seckey; |
662 |
|
gpgme_user_id_t u; |
663 |
|
gpgme_subkey_t k; |
664 |
char fmt[128]; |
char fmt[128]; |
665 |
const char *attr; |
const char *attr; |
666 |
u32 key_attr; |
u32 key_attr; |
668 |
|
|
669 |
/* we check the pubkey algorithm here to make sure that no ElGamal |
/* we check the pubkey algorithm here to make sure that no ElGamal |
670 |
sign+encrypt key is used in _any_ mode */ |
sign+encrypt key is used in _any_ mode */ |
671 |
if (list != 1 && gpgme_key_get_ulong_attr( key, GPGME_ATTR_ALGO, NULL, 0) |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) |
|
== GPGME_PK_ELG_ES ) |
|
672 |
return 0; |
return 0; |
673 |
|
|
674 |
if (listview_add_item2 (lv, " ", (void *)key)) |
if (listview_add_item2 (lv, " ", (void *)key)) |
675 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
676 |
|
|
677 |
attr = gpgme_key_get_string_attr( key, GPGME_ATTR_USERID, NULL, 0 ); |
attr = key->uids->uid; |
678 |
memset( &lvi, 0, sizeof lvi ); |
memset( &lvi, 0, sizeof lvi ); |
679 |
lvi.mask = LVIF_TEXT | LVIF_PARAM; |
lvi.mask = LVIF_TEXT | LVIF_PARAM; |
680 |
lvi.pszText = (char *)attr; |
lvi.pszText = (char *)attr; |
684 |
|
|
685 |
if( uididx == -1 ) { |
if( uididx == -1 ) { |
686 |
/* request the primary user-id of the key. */ |
/* request the primary user-id of the key. */ |
687 |
attr = gpgme_key_get_string_attr (key, GPGME_ATTR_USERID, NULL, 0); |
attr = key->uids->uid; |
688 |
uididx = 0; |
uididx = 0; |
689 |
} |
} |
690 |
else { |
else { |
691 |
if( gpgme_key_get_ulong_attr( key, GPGME_ATTR_UID_REVOKED, NULL, uididx ) || uididx < 0 ) |
u = get_nth_userid (key, uididx); |
692 |
|
if (!u || u->revoked || uididx < 0) |
693 |
uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */ |
uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */ |
694 |
attr = gpgme_key_get_string_attr( key, GPGME_ATTR_USERID, NULL, uididx ); |
u = get_nth_userid (key, uididx); |
695 |
|
attr = key->uids->uid; |
696 |
} |
} |
697 |
if( attr == NULL || strlen( attr ) < 5 ) { /* normal userids are >= 5 chars */ |
if( attr == NULL || strlen( attr ) < 5 ) { /* normal userids are >= 5 chars */ |
698 |
attr = _("Invalid User ID"); |
attr = _("Invalid User ID"); |
705 |
free( uid ); |
free( uid ); |
706 |
} |
} |
707 |
} |
} |
708 |
attr = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, keyidx ); |
k = get_nth_key (key, keyidx); |
709 |
|
attr = k->keyid; |
710 |
if( attr ) { |
if( attr ) { |
711 |
_snprintf( fmt, sizeof fmt -1, "0x%s", attr + 8 ); |
_snprintf( fmt, sizeof fmt -1, "0x%s", attr + 8 ); |
712 |
listview_add_sub_item( lv, 0, idx++, fmt ); |
listview_add_sub_item( lv, 0, idx++, fmt ); |
713 |
} |
} |
|
|
|
714 |
if (list > 0) { |
if (list > 0) { |
715 |
attr = find_secret_key (key)? "pub/sec" : "pub"; |
attr = find_secret_key (key)? "pub/sec" : "pub"; |
716 |
if (strchr( attr, '/')) { |
if (strchr( attr, '/')) { |
717 |
const char * kid; |
const char * kid; |
718 |
kid = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0); |
kid = key->subkeys->keyid; |
719 |
get_seckey( kid, &seckey ); |
get_seckey( kid, &seckey ); |
720 |
if( gpgme_key_get_ulong_attr( seckey, GPGME_ATTR_DIVERT_CARD, NULL, 0 ) ) |
/*if( gpgme_key_get_ulong_attr( seckey, GPGME_ATTR_DIVERT_CARD, NULL, 0 ) ) |
721 |
attr = "pub/crd"; |
attr = "pub/crd"; XXX*/ |
722 |
} |
} |
723 |
listview_add_sub_item( lv, 0, idx++, attr ); |
listview_add_sub_item( lv, 0, idx++, attr ); |
724 |
} |
} |
744 |
listview_add_sub_item (lv, 0, idx++, s); |
listview_add_sub_item (lv, 0, idx++, s); |
745 |
} |
} |
746 |
if( lv->cols >= 6 ) { |
if( lv->cols >= 6 ) { |
747 |
key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_CREATED, NULL, keyidx ); |
k = get_nth_key (key, keyidx); |
748 |
|
key_attr = k->timestamp; |
749 |
if( key_attr ) { |
if( key_attr ) { |
750 |
attr = gpgme_key_expand_attr( GPGME_ATTR_CREATED, key_attr ); |
attr = get_key_created (key_attr); |
751 |
listview_add_sub_item( lv, 0, idx++, attr ); |
listview_add_sub_item( lv, 0, idx++, attr ); |
752 |
} |
} |
753 |
} |
} |
765 |
listview_set_item2 (lv, pos, (void *)key); |
listview_set_item2 (lv, pos, (void *)key); |
766 |
/* the only mode we support is KYLIST_LIST in the Key Manager */ |
/* the only mode we support is KYLIST_LIST in the Key Manager */ |
767 |
|
|
768 |
s = gpgme_key_get_string_attr (key, GPGME_ATTR_USERID, NULL, 0); |
s = key->uids->uid; |
769 |
if (s) |
if (s) |
770 |
listview_add_sub_item (lv, pos, 0, s); |
listview_add_sub_item (lv, pos, 0, s); |
771 |
|
|
772 |
s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0); |
s = key->subkeys->keyid; |
773 |
if (s) { |
if (s) { |
774 |
sprintf (tmp, "0x%s", s+8); |
sprintf (tmp, "0x%s", s+8); |
775 |
listview_add_sub_item (lv, pos, 1, tmp); |
listview_add_sub_item (lv, pos, 1, tmp); |
794 |
if (s) |
if (s) |
795 |
listview_add_sub_item (lv, pos, 6, s); |
listview_add_sub_item (lv, pos, 6, s); |
796 |
|
|
797 |
long t = gpgme_key_get_ulong_attr (key, GPGME_ATTR_CREATED, NULL, 0); |
long t = key->subkeys->timestamp; |
798 |
s = get_key_created (t); |
s = get_key_created (t); |
799 |
if (s) |
if (s) |
800 |
listview_add_sub_item (lv, pos, 7, s); |
listview_add_sub_item (lv, pos, 7, s); |
805 |
keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key) |
keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key) |
806 |
{ |
{ |
807 |
int uids, rc = 0, i, n = 0; |
int uids, rc = 0, i, n = 0; |
808 |
|
gpgme_subkey_t k; |
809 |
|
|
810 |
for (i = 0; i < gpgme_key_count_items (key, GPGME_ATTR_KEYID); i++) { |
for (i = 0; i < count_subkeys (key); i++) { |
811 |
if (gpgme_key_get_ulong_attr( key, GPGME_ATTR_KEY_INVALID, NULL, i)) |
k = get_nth_key (key, i); |
812 |
|
if (k->invalid) |
813 |
continue; /* Don't use invalid keys */ |
continue; /* Don't use invalid keys */ |
814 |
|
|
815 |
if (mode & KEYLIST_ALL) { |
if (mode & KEYLIST_ALL) { |
816 |
uids = gpgme_key_count_items (key, GPGME_ATTR_USERID); |
uids = count_userids (key); |
817 |
rc = do_addkey (lv, key, uids, i, 0); |
rc = do_addkey (lv, key, uids, i, 0); |
818 |
if( rc ) |
if( rc ) |
819 |
return rc; |
return rc; |
821 |
else if (mode & KEYLIST_LIST) |
else if (mode & KEYLIST_LIST) |
822 |
return do_addkey (lv, key, -1, i, 1); |
return do_addkey (lv, key, -1, i, 1); |
823 |
else if (mode & KEYLIST_ENCRYPT) { |
else if (mode & KEYLIST_ENCRYPT) { |
824 |
if (gpgme_key_get_cability (key, GPGME_ATTR_CAN_ENCRYPT, i) |
if (k->can_encrypt && key_is_useable (k)) { |
|
&& gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_USABLE, NULL, i)) |
|
|
{ |
|
825 |
if (mode & KEYLIST_FLAG_FILE) { |
if (mode & KEYLIST_FLAG_FILE) { |
826 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, key, -1, i, -1); |
827 |
if (rc) |
if (rc) |
828 |
return rc; |
return rc; |
829 |
} |
} |
830 |
else { |
else { |
831 |
for( uids = 0; uids < gpgme_key_count_items( key, GPGME_ATTR_USERID ); uids++ ) { |
for( uids = 0; uids < count_userids (key); uids++ ) { |
832 |
rc = do_addkey( lv, key, uids, i, -1 ); |
rc = do_addkey( lv, key, uids, i, -1 ); |
833 |
if( rc ) |
if( rc ) |
834 |
return rc; |
return rc; |
837 |
} |
} |
838 |
} |
} |
839 |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
840 |
if( gpgme_key_get_cability (key, GPGME_ATTR_CAN_ENCRYPT, i) |
if( k->can_encrypt && key_is_useable (k)) |
|
&& gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_USABLE, NULL, i)) |
|
841 |
{ |
{ |
842 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, key, -1, i, -1); |
843 |
return rc; |
return rc; |
844 |
} |
} |
845 |
} |
} |
846 |
else if (mode & KEYLIST_SIGN) { |
else if (mode & KEYLIST_SIGN) { |
847 |
if ( gpgme_key_get_cability( key, GPGME_ATTR_CAN_SIGN, i ) |
if ( k->can_sign |
848 |
&& find_secret_key( key ) |
&& find_secret_key( key ) |
849 |
&& gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_USABLE, NULL, i)) |
&& key_is_useable (k)) |
850 |
{ |
{ |
851 |
rc = do_addkey (lv, key, -1, i, -1); |
rc = do_addkey (lv, key, -1, i, -1); |
852 |
if( rc ) |
if( rc ) |
877 |
} /* key_check_validity */ |
} /* key_check_validity */ |
878 |
|
|
879 |
|
|
880 |
gpgme_recipients_t |
gpgme_key_t* |
881 |
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) |
882 |
{ |
{ |
883 |
int count = 0, force_trust = 0; |
int count = 0, force_trust = 0; |
884 |
int n, j, ka_pos = 0, rc = 0; |
int n, j, ka_pos = 0, rc = 0; |
885 |
|
int k_pos=0; |
886 |
char keyid[32], valid[32], id[100]; |
char keyid[32], valid[32], id[100]; |
887 |
key_array_s *ka = NULL; |
key_array_s *ka = NULL; |
888 |
gpgme_error_t err; |
gpgme_error_t err; |
889 |
gpgme_recipients_t rset; |
gpgme_key_t *keybuf; |
890 |
|
|
|
err = gpgme_recipients_new( &rset ); |
|
|
if( err ) |
|
|
BUG( NULL ); |
|
|
|
|
891 |
n = listview_count_items( lv, 0 ); |
n = listview_count_items( lv, 0 ); |
892 |
ka = key_array_new( n ); |
ka = key_array_new( n ); |
893 |
if ( !ka ) |
if ( !ka ) |
894 |
BUG( NULL ); |
BUG (NULL); |
895 |
|
|
896 |
|
keybuf = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); |
897 |
|
if (!keybuf) |
898 |
|
BUG (NULL); |
899 |
|
|
900 |
for( j = 0; j < n; j++ ) { |
for( j = 0; j < n; j++ ) { |
901 |
if( listview_get_item_state( lv, j ) || n == 1 ) { |
if( listview_get_item_state( lv, j ) || n == 1 ) { |
902 |
listview_get_item_text( lv, j, 1, keyid, sizeof keyid - 1 ); |
listview_get_item_text( lv, j, 1, keyid, sizeof keyid - 1 ); |
903 |
listview_get_item_text( lv, j, 4, valid, sizeof valid -1 ); |
listview_get_item_text( lv, j, 4, valid, sizeof valid -1 ); |
904 |
listview_get_item_text( lv, j, 0, id, sizeof id-1 ); |
listview_get_item_text( lv, j, 0, id, sizeof id-1 ); |
905 |
if( !strncmp( keyid, "gpg_group_t", 5 ) ) { |
/*if( !strncmp( keyid, "gpg_group_t", 5 ) ) { |
906 |
listview_get_item_text( lv, j, 0, id, sizeof id -1 ); |
listview_get_item_text( lv, j, 0, id, sizeof id -1 ); |
907 |
rc = km_groupdb_expand_recipients( id, rset ); |
rc = km_groupdb_expand_recipients( id, rset ); |
908 |
if( rc ) |
if( rc ) |
909 |
force_trust++; |
force_trust++; |
910 |
} |
}*/ |
911 |
else if( !key_check_validity( valid ) |
if( !key_check_validity( valid ) |
912 |
&& !key_array_search( ka, ka_pos, keyid ) ) { |
&& !key_array_search( ka, ka_pos, keyid ) ) { |
913 |
char *warn = new char[512+strlen (id) + 1]; |
char *warn = new char[512+strlen (id) + 1]; |
914 |
if (!warn) |
if (!warn) |
924 |
else |
else |
925 |
rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK); |
rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK); |
926 |
if (rc == IDYES) { |
if (rc == IDYES) { |
927 |
gpgme_recipients_add_name_with_validity (rset, keyid, GPGME_VALIDITY_FULL); |
gpgme_key_t k; |
928 |
|
get_pubkey (keyid, &k); |
929 |
|
keybuf[k_pos++] = k; |
930 |
force_trust++; |
force_trust++; |
931 |
ka[ka_pos].checked = 1; |
ka[ka_pos].checked = 1; |
932 |
strcpy (ka[ka_pos++].keyid, keyid); |
strcpy (ka[ka_pos++].keyid, keyid); |
933 |
|
count++; |
934 |
} |
} |
935 |
free_if_alloc (warn); |
free_if_alloc (warn); |
936 |
} |
} |
937 |
else { |
else { |
938 |
|
gpgme_key_t k; |
939 |
listview_get_item_text( lv, j, 1, keyid, sizeof keyid -1 ); |
listview_get_item_text( lv, j, 1, keyid, sizeof keyid -1 ); |
940 |
gpgme_recipients_add_name( rset, keyid ); |
get_pubkey (keyid, &k); |
941 |
|
keybuf[k_pos++] = k; |
942 |
count++; |
count++; |
943 |
} |
} |
944 |
} |
} |
948 |
*r_force_trust = force_trust; |
*r_force_trust = force_trust; |
949 |
if (r_count) |
if (r_count) |
950 |
*r_count = count; |
*r_count = count; |
951 |
return rset; |
return keybuf; |
952 |
} /* keylist_get_recipients */ |
} /* keylist_get_recipients */ |
953 |
|
|
954 |
|
|
974 |
} /* keylist_get_keyflags */ |
} /* keylist_get_keyflags */ |
975 |
|
|
976 |
|
|
977 |
gpgme_recipients_t |
gpgme_key_t* |
978 |
keylist_enum_recipients (listview_ctrl_t lv, int listype) |
keylist_enum_recipients (listview_ctrl_t lv, int listype, int *r_count) |
979 |
{ |
{ |
980 |
gpgme_recipients_t rset; |
gpgme_key_t* rset; |
981 |
int i, n, id; |
gpgme_key_t k; |
982 |
|
int i, n, id, k_pos=0; |
983 |
char keyid[32], t[128], t2[128]; |
char keyid[32], t[128], t2[128]; |
984 |
|
|
|
if( gpgme_recipients_new( &rset ) ) |
|
|
BUG( NULL ); |
|
|
|
|
985 |
n = listview_count_items( lv, 0 ); |
n = listview_count_items( lv, 0 ); |
986 |
|
if (!n) |
987 |
|
return 0; |
988 |
|
rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); |
989 |
|
if (!rset) |
990 |
|
BUG (NULL); |
991 |
for( i = 0; i < n; i++ ) { |
for( i = 0; i < n; i++ ) { |
992 |
if( !listview_get_item_state( lv, i ) ) |
if( !listview_get_item_state( lv, i ) ) |
993 |
continue; |
continue; |
1004 |
} |
} |
1005 |
break; |
break; |
1006 |
} |
} |
1007 |
gpgme_recipients_add_name( rset, keyid ); |
get_pubkey (keyid, &k); |
1008 |
|
rset[k_pos++] = k; |
1009 |
} |
} |
1010 |
|
if (r_count) |
1011 |
|
*r_count = k_pos; |
1012 |
return rset; |
return rset; |
1013 |
} /* keylist_enum_recipients */ |
} /* keylist_enum_recipients */ |
1014 |
|
|
1032 |
gpgme_keycache_t kc = NULL; |
gpgme_keycache_t kc = NULL; |
1033 |
gpgme_key_t key = NULL; |
gpgme_key_t key = NULL; |
1034 |
HWND kb; |
HWND kb; |
1035 |
keylist_t list=NULL, l, l2; |
keylist_t list=NULL, l, l2; |
|
gpgme_attr_t name_attr = GPGME_ATTR_USERID; |
|
1036 |
long pos = 0; |
long pos = 0; |
1037 |
|
|
1038 |
SendDlgItemMessage (dlg, ctlid, CB_RESETCONTENT, 0, 0); |
SendDlgItemMessage (dlg, ctlid, CB_RESETCONTENT, 0, 0); |
1041 |
if (!kc) |
if (!kc) |
1042 |
BUG (0); |
BUG (0); |
1043 |
gpgme_keycache_rewind (kc); |
gpgme_keycache_rewind (kc); |
1044 |
|
|
|
if (flags & KEYLIST_FLAG_SHORT) |
|
|
name_attr = GPGME_ATTR_NAME; |
|
1045 |
while (!gpgme_keycache_next_key (kc, 1, &key)) { |
while (!gpgme_keycache_next_key (kc, 1, &key)) { |
1046 |
char * inf = NULL, * uid = NULL; |
char * inf = NULL, * uid = NULL; |
1047 |
const char * id; |
const char * id; |
1048 |
const char * keyid; |
const char * keyid; |
1049 |
int algo; |
int algo; |
1050 |
size_t size = 0; |
size_t size = 0; |
1051 |
|
|
1052 |
id = gpgme_key_get_string_attr (key, name_attr, NULL, 0); |
if (flags & KEYLIST_FLAG_SHORT) |
1053 |
keyid = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0); |
id = key->uids->name; |
1054 |
algo = gpgme_key_get_ulong_attr (key, GPGME_ATTR_ALGO, NULL, 0); |
else |
1055 |
|
id = key->uids->uid; |
1056 |
|
keyid = key->subkeys->keyid; |
1057 |
|
algo = key->subkeys->pubkey_algo; |
1058 |
if (!id || !keyid) |
if (!id || !keyid) |
1059 |
continue; /* fixme: error? */ |
continue; /* fixme: error? */ |
1060 |
if (!gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_USABLE, NULL, 0)) |
if (!key_is_useable (key->subkeys)) |
1061 |
continue; |
continue; |
1062 |
|
|
1063 |
uid = utf8_to_wincp (id, strlen (id)); |
uid = utf8_to_wincp (id, strlen (id)); |
1065 |
inf = new char[size+1]; |
inf = new char[size+1]; |
1066 |
if( !inf ) |
if( !inf ) |
1067 |
BUG( NULL ); |
BUG( NULL ); |
1068 |
_snprintf(inf, size, _("%s (%s/0x%s)"), uid, |
_snprintf (inf, size, _("%s (%s/0x%s)"), uid, |
1069 |
gpgme_key_expand_attr (GPGME_ATTR_ALGO, algo), keyid + 8); |
get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8); |
|
|
|
1070 |
combox_add_string (kb, inf); |
combox_add_string (kb, inf); |
1071 |
free_if_alloc (inf); |
free_if_alloc (inf); |
1072 |
free (uid); |
free (uid); |
1076 |
l->key = key; |
l->key = key; |
1077 |
if (!list) |
if (!list) |
1078 |
list = l; |
list = l; |
1079 |
else |
else { |
|
{ |
|
1080 |
for( l2 = list; l2->next; l2 = l2->next ) |
for( l2 = list; l2->next; l2 = l2->next ) |
1081 |
; |
; |
1082 |
l2->next = l; |
l2->next = l; |