1 |
/* wptKeylist.cpp - Keylist element |
/* wptKeylist.cpp - Keylist element |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-2006, 2009 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. |
6 |
* |
* |
7 |
* WinPT is free software; you can redistribute it and/or |
* WinPT is free software; you can redistribute it and/or |
8 |
* modify it under the terms of the GNU General Public License |
* modify it under the terms of the GNU General Public License |
9 |
* as published by the Free Software Foundation; either version 2 |
* as published by the Free Software Foundation; either version 2 |
10 |
* of the License, or (at your option) any later version. |
* of the License, or (at your option) any later version. |
11 |
* |
* |
12 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
* General Public License for more details. |
* General Public License for more details. |
16 |
* |
*/ |
17 |
* You should have received a copy of the GNU General Public License |
#ifdef HAVE_CONFIG_H |
18 |
* along with WinPT; if not, write to the Free Software Foundation, |
#include <config.h> |
19 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
#endif |
20 |
*/ |
|
21 |
#include <windows.h> |
#include <windows.h> |
22 |
#include <commctrl.h> |
#include <commctrl.h> |
23 |
#include <time.h> |
#include <time.h> |
24 |
|
|
25 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
26 |
#include "wptTypes.h" |
#include "wptTypes.h" |
27 |
#include "wptGPG.h" |
#include "wptGPG.h" |
28 |
#include "wptKeylist.h" |
#include "wptKeylist.h" |
29 |
#include "wptKeyManager.h" |
#include "wptKeyManager.h" |
30 |
#include "wptW32API.h" |
#include "wptW32API.h" |
31 |
#include "wptNLS.h" |
#include "wptNLS.h" |
32 |
#include "wptErrors.h" |
#include "wptErrors.h" |
33 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
34 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
35 |
#include "wptContext.h" |
#include "wptContext.h" |
36 |
|
#include "wptVersion.h" |
37 |
|
#include "resource.h" |
38 |
#define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled) |
#include "StringBuffer.h" |
39 |
|
|
40 |
static struct listview_column_s klist_enc[] = { |
|
41 |
{0, 242, (char *)_("User ID")}, |
struct key_array_s { |
42 |
{1, 80, (char *)_("Key ID")}, |
char keyid[32]; |
43 |
{3, 46, (char *)_("Size")}, |
int checked; |
44 |
{4, 50, (char *)_("Cipher")}, |
}; |
45 |
{5, 70, (char *)_("Validity")}, |
|
46 |
{0, 0, NULL} |
|
47 |
}; |
static key_array_s* |
48 |
#define KLIST_ENC_ITEMS (DIM(klist_enc) -1) |
key_array_new (DWORD items) |
49 |
|
{ |
50 |
static struct listview_column_s klist[] = { |
key_array_s *ka; |
51 |
{0, 242, (char *)_("User ID")}, |
|
52 |
{1, 78, (char *)_("Key ID")}, |
if (items == 0) |
53 |
{2, 52, (char *)_("Type")}, |
BUG (NULL); |
54 |
{3, 68, (char *)_("Size")}, |
ka = new key_array_s[items + 1]; |
55 |
{4, 66, (char *)_("Cipher")}, |
if (!ka) |
56 |
{5, 70, (char *)_("Validity")}, |
BUG (NULL); |
57 |
{6, 40, (char *)_("Trust")}, |
for (DWORD i = 0; i < items; i++) |
58 |
{7, 72, (char *)_("Creation")}, |
ka[i].checked = 0; |
59 |
{0, 0, NULL} |
return ka; |
60 |
}; |
} |
61 |
#define KLIST_ITEMS (DIM(klist) - 1) |
|
62 |
|
static void |
63 |
struct key_array_s { |
key_array_release (key_array_s *ka) |
64 |
char keyid[32]; |
{ |
65 |
int checked; |
free_if_alloc (ka); |
66 |
}; |
} |
67 |
|
|
68 |
static int find_secret_key (gpgme_key_t key); |
|
69 |
|
/* Check if the keyid @keyid is in the key array @ka. |
70 |
|
Return value: 1 if it exists, 0 otherwise. */ |
71 |
static key_array_s* |
static int |
72 |
key_array_new( size_t items ) |
key_array_search (key_array_s *ka, DWORD items, const char *keyid) |
73 |
{ |
{ |
74 |
key_array_s *ka; |
for (DWORD i = 0; i < items; i++) { |
75 |
size_t j; |
if (!stricmp (keyid, ka[i].keyid)) |
76 |
|
return 1; |
77 |
if( items == 0 ) |
} |
78 |
return NULL; |
return 0; |
79 |
ka = new key_array_s[items + 1]; |
} |
80 |
if( ka == NULL ) |
|
81 |
return NULL; |
|
82 |
for ( j = 0; j < items; j++ ) |
/* Return if there is a secret for @key. |
83 |
ka[j].checked = 0; |
0 means success. */ |
84 |
return ka; |
static int |
85 |
} /* key_array_new */ |
find_secret_key (gpgme_key_t key) |
86 |
|
{ |
87 |
|
winpt_key_s skey; |
88 |
static void |
|
89 |
key_array_release( key_array_s *ka ) |
if (!key->subkeys->keyid) |
90 |
{ |
return 0; |
91 |
free_if_alloc( ka ); |
memset (&skey, 0, sizeof (skey)); |
92 |
} /* key_array_release */ |
if (winpt_get_seckey (key->subkeys->keyid, &skey)) |
93 |
|
return 0; |
94 |
|
if (skey.ext && skey.ext->gloflags.divert_to_card) |
95 |
static int |
return 2; |
96 |
key_array_search( key_array_s *ka, size_t items, const char *keyid ) |
return skey.ctx? 1 : 0; |
97 |
{ |
} |
98 |
size_t j; |
|
99 |
|
|
100 |
/* fixme: we need a faster search method */ |
/* Update the gpgme key pointer of a single entry. */ |
101 |
for( j = 0; j < items; j++ ) { |
static void |
102 |
if( !strcmp( keyid, ka[j].keyid ) ) |
update_key (keylist_ctrl_t kl, int pos, |
103 |
return 1; |
gpgme_key_t key) |
104 |
} |
{ |
105 |
|
if ((size_t)pos > kl->nkeys) |
106 |
return 0; |
BUG (0); |
107 |
} /* key_array_search */ |
kl->keys[pos] = key; |
108 |
|
} |
109 |
|
|
110 |
gpgme_user_id_t |
|
111 |
get_nth_userid (gpgme_key_t key, int idx) |
/* If @re_sorted == 0, then all keys from the key list control |
112 |
{ |
are stored as references in the array. |
113 |
gpgme_user_id_t t; |
Otherwise we just re-order the references in the array. */ |
114 |
|
static size_t |
115 |
if (!key->uids) |
update_keys (keylist_ctrl_t kl, int re_sorted, |
116 |
return NULL; |
gpgme_key_t **r_list) |
117 |
t = key->uids; |
{ |
118 |
while (idx-- && t->next) |
gpgme_key_t *rset; |
119 |
t = t->next; |
gpgme_key_t key; |
120 |
return t; |
listview_ctrl_t lv = kl->lv; |
121 |
} |
struct keycache_s *c; |
122 |
|
size_t k_pos; |
123 |
|
int nkeys; |
124 |
int |
|
125 |
count_userids (gpgme_key_t key) |
nkeys = listview_count_items (lv, 0); |
126 |
{ |
if (!nkeys) |
127 |
gpgme_user_id_t u; |
BUG (0); |
128 |
int n = 1; |
|
129 |
|
if (!re_sorted) { |
130 |
u = key->uids; |
rset = (gpgme_key_t*)calloc (nkeys+1, sizeof (gpgme_key_t)); |
131 |
if (!u) |
*r_list = rset; |
132 |
return 0; |
} |
133 |
while (u->next) { |
else |
134 |
u = u->next; |
rset = *r_list; |
135 |
n++; |
k_pos = 0; |
136 |
} |
for (int i = 0; i < nkeys; i++) { |
137 |
return n; |
key = km_get_key_ptr (kl, i, &c); |
138 |
} |
rset[k_pos++] = key; |
139 |
|
} |
140 |
|
return k_pos; |
141 |
gpgme_subkey_t |
} |
142 |
get_nth_key (gpgme_key_t key, int idx) |
|
143 |
{ |
|
144 |
gpgme_subkey_t t; |
gpgme_user_id_t |
145 |
|
get_nth_userid (gpgme_key_t key, int idx) |
146 |
if (!key->subkeys) |
{ |
147 |
return NULL; |
gpgme_user_id_t t; |
148 |
t = key->subkeys; |
|
149 |
while (idx-- && t->next) |
if (!key->uids) |
150 |
t = t->next; |
return NULL; |
151 |
return t; |
t = key->uids; |
152 |
} |
while (idx-- && t->next) |
153 |
|
t = t->next; |
154 |
|
return t; |
155 |
int |
} |
156 |
count_subkeys (gpgme_key_t key) |
|
157 |
{ |
|
158 |
gpgme_subkey_t k; |
int |
159 |
int n = 1; |
count_userids (gpgme_key_t key) |
160 |
|
{ |
161 |
k = key->subkeys; |
gpgme_user_id_t u; |
162 |
if (!k) |
int n = 1; |
163 |
return 0; |
|
164 |
while (k->next) { |
u = key->uids; |
165 |
k = k->next; |
if (!u) |
166 |
n++; |
return 0; |
167 |
} |
while (u->next) { |
168 |
return n; |
u = u->next; |
169 |
} |
n++; |
170 |
|
} |
171 |
|
return n; |
172 |
gpgme_key_sig_t |
} |
173 |
get_selfsig (gpgme_user_id_t uid, const char *keyid, int first) |
|
174 |
{ |
|
175 |
gpgme_key_sig_t s, self_sig=NULL; |
gpgme_subkey_t |
176 |
long timestamp=0; |
get_nth_key (gpgme_key_t key, int idx) |
177 |
|
{ |
178 |
for (s = uid->signatures; s; s = s->next) { |
gpgme_subkey_t t; |
179 |
if (!strcmp (s->keyid+8, keyid) && s->timestamp > timestamp) { |
|
180 |
self_sig = s; |
if (!key->subkeys) |
181 |
timestamp = s->timestamp; |
return NULL; |
182 |
if (first) |
t = key->subkeys; |
183 |
break; |
while (idx-- && t->next) |
184 |
} |
t = t->next; |
185 |
} |
return t; |
186 |
return self_sig; |
} |
187 |
} |
|
188 |
|
|
189 |
|
int |
190 |
|
count_subkeys (gpgme_key_t key) |
191 |
const char* |
{ |
192 |
get_key_algo (gpgme_key_t key, int keyidx) |
gpgme_subkey_t k; |
193 |
{ |
int n = 1; |
194 |
static char algo_id[128]; |
|
195 |
gpgme_subkey_t k; |
k = key->subkeys; |
196 |
char alg[32]; |
if (!k) |
197 |
const char *subalg; |
return 0; |
198 |
int n=0; |
while (k->next) { |
199 |
|
k = k->next; |
200 |
if (keyidx > 0) { |
n++; |
201 |
k = get_nth_key (key, keyidx-1); |
} |
202 |
subalg = get_key_pubalgo (k->pubkey_algo); |
return n; |
203 |
_snprintf( algo_id, DIM (algo_id)-1, "%s", subalg); |
} |
204 |
return algo_id; |
|
205 |
} |
|
206 |
strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo)); |
/* Return the self signature of the key @keyid. |
207 |
n = count_subkeys (key); |
If first is set, the first self sig will be returned. */ |
208 |
if (n > 1) { |
gpgme_key_sig_t |
209 |
k = get_nth_key (key, n-1); |
get_selfsig (gpgme_key_sig_t sigs, const char *keyid, int first) |
210 |
subalg = get_key_pubalgo (k->pubkey_algo); |
{ |
211 |
_snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg); |
gpgme_key_sig_t s, self_sig=NULL; |
212 |
return algo_id; |
long timestamp=0; |
213 |
} |
int off = 0; |
214 |
return get_key_pubalgo (key->subkeys->pubkey_algo); |
|
215 |
} /* get_key_algo */ |
if (strlen (keyid) == 8) |
216 |
|
off = 8; |
217 |
|
|
218 |
const char* |
for (s = sigs; s; s = s->next) { |
219 |
get_key_created( long timestamp ) |
if (!strcmp (s->keyid+off, keyid) && s->timestamp > timestamp) { |
220 |
{ |
self_sig = s; |
221 |
static char timebuf[128]; |
timestamp = s->timestamp; |
222 |
struct tm *warp; |
if (first) /* do not search for later self sigs. */ |
223 |
|
break; |
224 |
if (timestamp == 0 || timestamp == -1) |
} |
225 |
return "????-??-??"; |
} |
226 |
warp = localtime( ×tamp ); |
return self_sig; |
227 |
_snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d", |
} |
228 |
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday ); |
|
229 |
return timebuf; |
|
230 |
} /* get_key_created */ |
const char* |
231 |
|
get_key_algo (gpgme_key_t key, int keyidx) |
232 |
|
{ |
233 |
const char* |
static char algo_id[128]; |
234 |
get_key_expire_date (long timestamp) |
gpgme_subkey_t k; |
235 |
{ |
char alg[32]; |
236 |
static char timebuf[64]; |
const char *subalg; |
237 |
struct tm *warp; |
int n; |
238 |
|
|
239 |
if( !timestamp ) |
if (keyidx > 0) { |
240 |
return _("Never"); |
k = get_nth_key (key, keyidx-1); |
241 |
warp = localtime( ×tamp ); |
subalg = get_key_pubalgo (k->pubkey_algo); |
242 |
_snprintf( timebuf, sizeof timebuf -1, "%04d-%02d-%02d", |
_snprintf (algo_id, DIM (algo_id)-1, "%s", subalg); |
243 |
warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday ); |
return algo_id; |
244 |
return timebuf; |
} |
245 |
} /* get_key_expire_date */ |
strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo)); |
246 |
|
n = count_subkeys (key); |
247 |
|
if (n > 1) { |
248 |
const char* |
do { |
249 |
get_key_type (gpgme_key_t key) |
k = get_nth_key (key, --n); |
250 |
{ |
if (k->revoked || k->expired) |
251 |
int type = find_secret_key (key); |
continue; |
252 |
|
else |
253 |
if (type == 1) |
break; |
254 |
return _("Key Pair"); |
} while (n > 0); |
255 |
else if (type == 2) |
subalg = get_key_pubalgo (k->pubkey_algo); |
256 |
return _("Key Pair (Card)"); |
if (k == key->subkeys) |
257 |
return _("Public Key"); |
_snprintf (algo_id, DIM (algo_id)-1, "%s", subalg); |
258 |
} /* get_key_type */ |
else |
259 |
|
_snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg); |
260 |
|
return algo_id; |
261 |
const char* |
} |
262 |
get_key_size (gpgme_key_t key, int keyidx) |
return get_key_pubalgo (key->subkeys->pubkey_algo); |
263 |
{ |
} |
264 |
static char size_id[64]; |
|
265 |
gpgme_subkey_t k; |
|
266 |
int n, size_main, size_sub; |
const char* |
267 |
|
get_key_created (long timestamp) |
268 |
if (keyidx > 0) { |
{ |
269 |
k = get_nth_key (key, keyidx-1); |
static char timebuf[128]; |
270 |
size_main = k->length; |
|
271 |
_snprintf (size_id, DIM (size_id)-1, "%d", size_main); |
if (timestamp < 1) |
272 |
return size_id; |
return "????" "-??" "-??"; |
273 |
} |
if (!get_locale_date (timestamp, timebuf, DIM (timebuf)-1)) |
274 |
size_main = key->subkeys->length; |
return "????" "-??" "-??"; |
275 |
n = count_subkeys (key); |
return timebuf; |
276 |
if (n > 1) { |
} |
277 |
k = get_nth_key (key, n-1); |
|
278 |
size_sub = k->length; |
|
279 |
_snprintf( size_id, sizeof (size_id) - 1, "%d/%d", size_main, size_sub ); |
/* Return a string presentation of the time @timestamp. */ |
280 |
return size_id; |
const char* |
281 |
} |
get_key_expire_date (long timestamp) |
282 |
_snprintf( size_id, sizeof (size_id) - 1, "%d", size_main ); |
{ |
283 |
return size_id; |
static char timebuf[64]; |
284 |
} /* get_key_size */ |
|
285 |
|
if (timestamp == 0) |
286 |
|
return _("Never"); |
287 |
const char* |
if (!get_locale_date (timestamp, timebuf, DIM (timebuf)-1)) |
288 |
get_key_pubalgo (gpgme_pubkey_algo_t alg) |
return "????" "-??" "-??"; |
289 |
{ |
return timebuf; |
290 |
switch (alg) { |
} |
291 |
case GPGME_PK_DSA: return "DSA"; |
|
292 |
case GPGME_PK_ELG: |
|
293 |
case GPGME_PK_ELG_E: return "ELG"; |
const char* |
294 |
case GPGME_PK_RSA: return "RSA"; |
get_key_type (gpgme_key_t key) |
295 |
} |
{ |
296 |
return "???"; |
int type = find_secret_key (key); |
297 |
} |
|
298 |
|
if (type == 1) |
299 |
const char * |
return _("Key Pair"); |
300 |
get_key_fpr (gpgme_key_t key) |
else if (type == 2) |
301 |
{ |
return _("Key Pair (Card)"); |
302 |
static char fpr_md[64]; |
return _("Public Key"); |
303 |
const char *fpr; |
} |
304 |
char t[16], tmp[40]; |
|
305 |
size_t i=0; |
|
306 |
|
const char* |
307 |
memset (fpr_md, 0, sizeof (fpr_md)); |
get_key_size (gpgme_key_t key, int keyidx) |
308 |
fpr = key->subkeys->fpr; |
{ |
309 |
if (!fpr || !*fpr) { |
static char size_id[64]; |
310 |
memset (tmp, '0', 40); |
gpgme_subkey_t k; |
311 |
fpr = tmp; |
int n, size_main, size_sub; |
312 |
} |
|
313 |
if (strlen (fpr) == 32) { |
if (keyidx > 0) { |
314 |
strcat (fpr_md, " "); |
k = get_nth_key (key, keyidx-1); |
315 |
for (i=0; i < strlen (fpr)/2; i++) { |
size_main = k->length; |
316 |
sprintf (t, "%c%c ", fpr[2*i], fpr[2*i+1]); |
_snprintf (size_id, DIM (size_id)-1, "%d", size_main); |
317 |
strcat (fpr_md, t); |
return size_id; |
318 |
} |
} |
319 |
} |
size_main = key->subkeys->length; |
320 |
else { |
n = count_subkeys (key); |
321 |
strcat (fpr_md, " "); |
if (n > 1) { |
322 |
for (i = 0; i < strlen (fpr) / 4; i++) { |
k = get_nth_key (key, n-1); |
323 |
sprintf (t, "%c%c%c%c ", fpr[4*i], fpr[4*i+1], fpr[4*i+2], fpr[4*i+3]); |
size_sub = k->length; |
324 |
strcat (fpr_md, t); |
_snprintf (size_id, DIM (size_id) - 1, "%d/%d", |
325 |
} |
size_main, size_sub); |
326 |
} |
return size_id; |
327 |
return fpr_md; |
} |
328 |
} /* get_key_fpr */ |
_snprintf (size_id, DIM (size_id) - 1, "%d", size_main); |
329 |
|
return size_id; |
330 |
|
} |
331 |
const char * |
|
332 |
get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode) |
|
333 |
{ |
const char* |
334 |
if (key) |
get_key_pubalgo2 (gpgme_pubkey_algo_t alg) |
335 |
val = key->owner_trust; /* uididx?? */ |
{ |
336 |
switch (val) { |
switch (alg) { |
337 |
case GPGME_VALIDITY_UNKNOWN: |
case GPGME_PK_DSA: return "D"; |
338 |
case GPGME_VALIDITY_UNDEFINED: |
case GPGME_PK_RSA: return "R"; |
339 |
return "None"; |
case GPGME_PK_ELG: return "G"; |
340 |
case GPGME_VALIDITY_NEVER: |
default: return "?"; |
341 |
return "Never"; |
} |
342 |
case GPGME_VALIDITY_MARGINAL: |
return "?"; |
343 |
return "Marginal"; |
} |
344 |
case GPGME_VALIDITY_FULL: |
|
345 |
case GPGME_VALIDITY_ULTIMATE: |
|
346 |
return "Full"; |
const char* |
347 |
} |
get_key_pubalgo (gpgme_pubkey_algo_t alg) |
348 |
return ""; |
{ |
349 |
} |
switch (alg) { |
350 |
|
case GPGME_PK_DSA: |
351 |
|
return "DSA"; |
352 |
const char * |
|
353 |
get_key_trust (gpgme_key_t key, int uididx, int listmode) |
case GPGME_PK_ELG: |
354 |
{ |
case GPGME_PK_ELG_E: |
355 |
return get_key_trust2 (key, 0, uididx, listmode); |
return "ELG"; |
356 |
} |
|
357 |
|
case GPGME_PK_RSA: |
358 |
|
case GPGME_PK_RSA_S: |
359 |
const char * |
case GPGME_PK_RSA_E: |
360 |
get_key_trust_str (int val) |
return "RSA"; |
361 |
{ |
|
362 |
return get_key_trust2 (NULL, val, 0, 0); |
case 0: |
363 |
} |
/* Should never happen */ |
364 |
|
/*BUG (NULL);*/ |
365 |
|
|
366 |
char* |
default: |
367 |
get_key_status (gpgme_key_t key, int uididx, int listmode) |
return "???"; |
368 |
{ |
} |
369 |
gpgme_user_id_t u; |
|
370 |
char fmt[64], * p; |
return "???"; |
371 |
const char * attr; |
} |
372 |
int i = 0; |
|
373 |
u32 key_attr =0; |
|
374 |
|
const char* |
375 |
if (uididx < 0 || count_userids (key) > uididx) |
get_key_fpr (gpgme_key_t key) |
376 |
uididx = 0; |
{ |
377 |
memset (fmt, 0, sizeof (fmt)); |
static char fpr_md[64]; |
378 |
if (listmode) { |
const char *fpr; |
379 |
if (key->revoked) |
char t[16], tmp[40]; |
380 |
sprintf (fmt, "Revoked"); |
size_t i; |
381 |
else if (key->expired) |
|
382 |
sprintf (fmt, "Expired"); |
memset (fpr_md, 0, sizeof (fpr_md)); |
383 |
else if (key->disabled) |
fpr = key->subkeys->fpr; |
384 |
sprintf (fmt, "Disabled"); |
if (!fpr || !*fpr) { |
385 |
/* if the key has a special status, we don't continue to figure out |
memset (tmp, '0', 40); |
386 |
what any user-id validities. */ |
fpr = tmp; |
387 |
if (strlen (fmt) > 0) |
} |
388 |
return m_strdup (fmt); |
if (strlen (fpr) == 32) { |
389 |
} |
strcat (fpr_md, " "); |
390 |
u = get_nth_userid (key, uididx); |
for (i=0; i < strlen (fpr)/2; i++) { |
391 |
key_attr = u->validity; |
sprintf (t, "%c%c ", fpr[2*i], fpr[2*i+1]); |
392 |
attr = get_key_trust2 (NULL, key_attr, 0, 0); |
strcat (fpr_md, t); |
393 |
p = new char[strlen( attr ) + 2]; |
} |
394 |
if (!p) |
} |
395 |
BUG (NULL); |
else { |
396 |
sprintf (p, "%s", attr); |
strcat (fpr_md, " "); |
397 |
return p; |
for (i = 0; i < strlen (fpr) / 4; i++) { |
398 |
} /* get_key_status */ |
sprintf (t, "%c%c%c%c ", fpr[4*i], fpr[4*i+1], fpr[4*i+2], fpr[4*i+3]); |
399 |
|
strcat (fpr_md, t); |
400 |
|
} |
401 |
/* Integer comparsion of @a and @b. |
} |
402 |
Return values: same as in strcmp. */ |
return fpr_md; |
403 |
static inline int |
} |
404 |
int_cmp (int a, int b) |
|
405 |
{ |
|
406 |
if (a == b) return 0; |
/* Extract the key ID from the fingerprint. |
407 |
else if (a > b) return 1; |
A long ID will be converted into a short ID. */ |
408 |
else return -1; |
const char* |
409 |
return 0; |
get_keyid_from_fpr (const char *fpr) |
410 |
} |
{ |
411 |
|
if (!fpr) |
412 |
|
return "????????"; |
413 |
/* To allow to sort the keys, we need to take care of |
if (strlen (fpr) == 40) |
414 |
the expired/revoke status also. */ |
fpr += 32; |
415 |
static int |
else if (strlen (fpr) == 32) |
416 |
get_ext_validity (gpgme_key_t k) |
fpr += 24; |
417 |
{ |
else if (strlen (fpr) == 16) |
418 |
if (k->revoked) |
fpr += 8; |
419 |
return GPGME_VALIDITY_ULTIMATE+1; |
else |
420 |
else if (k->expired) |
return "????????"; |
421 |
return GPGME_VALIDITY_ULTIMATE+2; |
return fpr; |
422 |
return k->uids->validity; |
} |
423 |
} |
|
424 |
|
|
425 |
|
const char* |
426 |
/* List view sorting callback. */ |
get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode) |
427 |
static int CALLBACK |
{ |
428 |
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
if (key) |
429 |
{ |
val = key->owner_trust; /* uididx?? */ |
430 |
gpgme_key_t a, b; |
switch (val) { |
431 |
int cmpresult = 0; |
case GPGME_VALIDITY_UNKNOWN: |
432 |
|
case GPGME_VALIDITY_UNDEFINED: |
433 |
a = (gpgme_key_t)first; |
return _("None"); |
434 |
b = (gpgme_key_t)second; |
case GPGME_VALIDITY_NEVER: |
435 |
if (!a || !b) |
return _("Never"); |
436 |
BUG (NULL); |
case GPGME_VALIDITY_MARGINAL: |
437 |
|
return _("Marginal"); |
438 |
switch (sortby & ~KEYLIST_SORT_DESC) { |
case GPGME_VALIDITY_FULL: |
439 |
case KEY_SORT_USERID: |
return _("Full"); |
440 |
|
case GPGME_VALIDITY_ULTIMATE: |
441 |
|
return _("Ultimate"); |
442 |
|
} |
443 |
|
return ""; |
444 |
|
} |
445 |
|
|
446 |
|
|
447 |
|
const char* |
448 |
|
get_key_trust (gpgme_key_t key, int uididx, int listmode) |
449 |
|
{ |
450 |
|
return get_key_trust2 (key, 0, uididx, listmode); |
451 |
|
} |
452 |
|
|
453 |
|
|
454 |
|
const char* |
455 |
|
get_key_trust_str (int val) |
456 |
|
{ |
457 |
|
return get_key_trust2 (NULL, val, 0, 0); |
458 |
|
} |
459 |
|
|
460 |
|
|
461 |
|
/* Return the status of the key @key. */ |
462 |
|
char* |
463 |
|
get_key_status (gpgme_key_t key, int uididx, int listmode) |
464 |
|
{ |
465 |
|
gpgme_user_id_t u; |
466 |
|
const char *attr; |
467 |
|
u32 key_attr =0; |
468 |
|
|
469 |
|
if (uididx < 0 || count_userids (key) > uididx) |
470 |
|
uididx = 0; |
471 |
|
if (listmode) { |
472 |
|
const char *s; |
473 |
|
if (key->revoked) |
474 |
|
s = _("Revoked"); |
475 |
|
else if (key->expired) |
476 |
|
s = _("Expired"); |
477 |
|
else if (key->disabled) |
478 |
|
s = _("Disabled"); |
479 |
|
else |
480 |
|
s = ""; |
481 |
|
/* if the key has a special status, we don't continue to figure out |
482 |
|
the user-id validities. */ |
483 |
|
if (*s) |
484 |
|
return m_strdup (s); |
485 |
|
} |
486 |
|
u = get_nth_userid (key, uididx); |
487 |
|
key_attr = u->validity; |
488 |
|
attr = get_key_trust2 (NULL, key_attr, 0, 0); |
489 |
|
return m_strdup (attr); |
490 |
|
} |
491 |
|
|
492 |
|
|
493 |
|
/* Return human readable description of the key @key. */ |
494 |
|
char* |
495 |
|
get_key_desc (gpgme_key_t key) |
496 |
|
{ |
497 |
|
gpgme_key_t sk; |
498 |
|
const char *state, *alg, *type; |
499 |
|
char *desc; |
500 |
|
StringBuffer p; |
501 |
|
|
502 |
|
state = ""; |
503 |
|
if (key->disabled) |
504 |
|
state = _("Disabled"); |
505 |
|
if (key->expired) |
506 |
|
state = _("Expired"); |
507 |
|
if (key->revoked) |
508 |
|
state = _("Revoked"); |
509 |
|
|
510 |
|
/* If the fingerprint has 32 octets, we assume MD5 and thus |
511 |
|
an old, version 3, RSA key which is called 'Legacy' by other |
512 |
|
OpenPGP programs. */ |
513 |
|
if (strlen (key->subkeys->fpr) == 32) |
514 |
|
alg = "RSA Legacy"; |
515 |
|
else |
516 |
|
alg = "OpenPGP"; |
517 |
|
type = _("public key"); |
518 |
|
if (!get_seckey (key->subkeys->keyid+8, &sk)) |
519 |
|
type = _("key pair"); |
520 |
|
p = state; |
521 |
|
p = p + " " + alg + " " + type; |
522 |
|
desc = m_strdup (p.getBuffer ()); |
523 |
|
return desc; |
524 |
|
} |
525 |
|
|
526 |
|
|
527 |
|
/* Integer comparsion of @a and @b. |
528 |
|
Return values: same as in strcmp. */ |
529 |
|
static inline int |
530 |
|
int_cmp (int a, int b) |
531 |
|
{ |
532 |
|
if (a == b) return 0; |
533 |
|
else if (a > b) return 1; |
534 |
|
else return -1; |
535 |
|
return 0; |
536 |
|
} |
537 |
|
|
538 |
|
|
539 |
|
/* To allow to sort the keys, we need to take care of |
540 |
|
the expired/revoke status also. */ |
541 |
|
static int |
542 |
|
get_ext_validity (gpgme_key_t k) |
543 |
|
{ |
544 |
|
if (k->revoked) |
545 |
|
return GPGME_VALIDITY_ULTIMATE+1; |
546 |
|
else if (k->expired) |
547 |
|
return GPGME_VALIDITY_ULTIMATE+2; |
548 |
|
else if (k->disabled) |
549 |
|
return GPGME_VALIDITY_ULTIMATE+3; |
550 |
|
return k->uids->validity; |
551 |
|
} |
552 |
|
|
553 |
|
|
554 |
|
/* List view sorting callback. */ |
555 |
|
static int CALLBACK |
556 |
|
keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
557 |
|
{ |
558 |
|
struct keycache_s *aa, *bb; |
559 |
|
gpgme_key_t a, b; |
560 |
|
int cmpresult = 0; |
561 |
|
|
562 |
|
aa = (struct keycache_s *)first; |
563 |
|
bb = (struct keycache_s *)second; |
564 |
|
if (!aa || !bb) |
565 |
|
BUG (NULL); |
566 |
|
a = aa->key; |
567 |
|
b = bb->key; |
568 |
|
|
569 |
|
switch (sortby & ~KEYLIST_SORT_DESC) { |
570 |
|
case KEY_SORT_USERID: |
571 |
cmpresult = strcmpi (a->uids->uid, b->uids->uid); |
cmpresult = strcmpi (a->uids->uid, b->uids->uid); |
572 |
break; |
break; |
573 |
|
|
574 |
case KEY_SORT_KEYID: |
case KEY_SORT_KEYID: |
575 |
cmpresult = strcmpi (a->subkeys->keyid+8, |
cmpresult = strcmpi (a->subkeys->keyid+8, |
576 |
b->subkeys->keyid+8); |
b->subkeys->keyid+8); |
577 |
break; |
break; |
578 |
|
|
579 |
case KEY_SORT_VALIDITY: |
case KEY_SORT_VALIDITY: |
580 |
cmpresult = int_cmp (get_ext_validity (a), |
cmpresult = int_cmp (get_ext_validity (a), |
581 |
get_ext_validity (b)); |
get_ext_validity (b)); |
582 |
break; |
break; |
583 |
|
|
584 |
case KEY_SORT_OTRUST: |
case KEY_SORT_OTRUST: |
585 |
cmpresult = int_cmp (a->owner_trust, b->owner_trust); |
cmpresult = int_cmp (a->owner_trust, b->owner_trust); |
586 |
break; |
break; |
587 |
|
|
588 |
case KEY_SORT_IS_SECRET: |
case KEY_SORT_IS_SECRET: |
589 |
get_seckey (a->subkeys->keyid, &a); |
get_seckey (a->subkeys->keyid, &a); |
590 |
get_seckey (b->subkeys->keyid, &b); |
get_seckey (b->subkeys->keyid, &b); |
591 |
cmpresult = int_cmp (a? a->secret : 0, b? b->secret : 0); |
cmpresult = int_cmp (a? a->secret : 0, b? b->secret : 0); |
592 |
break; |
break; |
593 |
|
|
594 |
case KEY_SORT_LEN: |
case KEY_SORT_LEN: |
595 |
cmpresult = int_cmp (a->subkeys->length, |
cmpresult = int_cmp (a->subkeys->length, |
596 |
b->subkeys->length); |
b->subkeys->length); |
597 |
break; |
break; |
598 |
|
|
599 |
case KEY_SORT_CREATED: |
case KEY_SORT_CREATED: |
600 |
cmpresult = int_cmp (a->subkeys->timestamp, |
cmpresult = int_cmp (a->subkeys->timestamp, |
601 |
b->subkeys->timestamp); |
b->subkeys->timestamp); |
602 |
break; |
break; |
603 |
|
|
604 |
case KEY_SORT_ALGO: |
case KEY_SORT_ALGO: |
605 |
cmpresult = int_cmp (a->subkeys->pubkey_algo, |
cmpresult = int_cmp (a->subkeys->pubkey_algo, |
606 |
b->subkeys->pubkey_algo); |
b->subkeys->pubkey_algo); |
607 |
break; |
break; |
608 |
|
|
609 |
default: |
default: |
610 |
cmpresult = strcmpi (a->uids->uid, b->uids->uid); |
cmpresult = strcmpi (a->uids->uid, b->uids->uid); |
611 |
break; |
break; |
612 |
} |
} |
613 |
if (sortby & KEYLIST_SORT_DESC) |
if (sortby & KEYLIST_SORT_DESC) |
614 |
return (~cmpresult + 1); |
return (~cmpresult + 1); |
615 |
else |
else |
616 |
return cmpresult; |
return cmpresult; |
617 |
} |
} |
618 |
|
|
619 |
|
|
620 |
/* Return the validity of the group @grp. */ |
int |
621 |
static const char* |
keylist_add_groups (keylist_ctrl_t kl) |
622 |
calc_validity (gpg_group_t grp) |
{ |
623 |
{ |
return 0; |
624 |
int level = 0, valid; |
} |
625 |
gpg_member_t mbr; |
|
626 |
gpgme_key_t key; |
|
627 |
|
/* Synchronize the key array with the contents |
628 |
for (mbr = grp->list; mbr; mbr = mbr->next) { |
of the keylist. */ |
629 |
if (get_pubkey (mbr->name, &key)) |
void |
630 |
continue; |
keylist_sync (keylist_ctrl_t kl) |
631 |
valid = key->uids->validity; |
{ |
632 |
switch (valid) { |
free (kl->keys); |
633 |
case GPGME_VALIDITY_MARGINAL: |
kl->nkeys = update_keys (kl, 0, &kl->keys); |
634 |
case GPGME_VALIDITY_NEVER: |
} |
635 |
case GPGME_VALIDITY_UNDEFINED: |
|
636 |
return get_key_trust2 (NULL, valid, 0, 0); |
|
637 |
} |
/* Create a listview for listing keys. Use the mode given in @mode |
638 |
} |
and the control is given in @ctrl. */ |
639 |
return _("Full"); |
static void |
640 |
} |
keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode) |
641 |
|
{ |
642 |
|
struct listview_column_s klist_enc[] = { |
643 |
int |
{0, 242, (char *)_("User ID")}, |
644 |
keylist_add_groups( listview_ctrl_t lv ) |
{1, 80, (char *)_("Key ID")}, |
645 |
{ |
{3, 46, (char *)_("Size")}, |
646 |
#if 0 |
{4, 50, (char *)_("Cipher")}, |
647 |
gpg_optfile_t gh; |
{5, 70, (char *)_("Validity")}, |
648 |
gpg_group_t grp; |
{0, 0, NULL} |
649 |
const char *valid; |
}; |
650 |
|
struct listview_column_s klist[] = { |
651 |
gh = km_groupdb_open( ); |
{0, 240, (char *)_("User ID")}, |
652 |
if( !gh ) |
{1, 78, (char *)_("Key ID")}, |
653 |
return WPTERR_FILE_OPEN; |
{2, 52, (char *)_("Type")}, |
654 |
|
{3, 66, (char *)_("Size")}, |
655 |
for( grp = gh->grp; grp; grp = grp->next ) { |
{4, 60, (char *)_("Cipher")}, |
656 |
valid = calc_validity( grp ); |
{5, 66, (char *)_("Validity")}, |
657 |
listview_add_item( lv, " " ); |
{6, 58, (char *)_("Trust")}, |
658 |
listview_add_sub_item( lv, 0, 0, grp->name ); |
{7, 72, (char *)_("Creation")}, |
659 |
listview_add_sub_item( lv, 0, 1, "gpg_group_t" ); |
{0, 0, NULL} |
660 |
listview_add_sub_item( lv, 0, 2, "" ); |
}; |
661 |
listview_add_sub_item( lv, 0, 3, "Unknown" ); |
HICON ico[7]; |
662 |
listview_add_sub_item( lv, 0, 4, valid?valid : "Unknown" ); |
listview_ctrl_t lv; |
663 |
} |
listview_column_t col; |
664 |
#endif |
int ncols = 0, ext_chkbox = 0; |
665 |
return 0; |
|
666 |
} /* keylist_add_groups */ |
listview_new (&lv, ctrl); |
667 |
|
if (mode & KEYLIST_ENCRYPT_MIN) { |
668 |
|
col = klist_enc; |
669 |
/* Create a listview for listing keys. Use the mode given in @mode |
ncols = (DIM (klist_enc) - 1); |
670 |
and the control is given in @ctrl. */ |
ext_chkbox = 1; |
671 |
static int |
} |
672 |
keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode) |
else if (mode & KEYLIST_SIGN) { |
673 |
{ |
col = klist_enc; |
674 |
listview_ctrl_t lv; |
ncols = (DIM (klist_enc) - 1) - 1; |
675 |
listview_column_t col; |
ext_chkbox = 1; |
676 |
int j, n = 0; |
} |
677 |
int kl_nolist = 0, rc = 0; |
else { |
678 |
|
col = klist; |
679 |
rc = listview_new (&lv); |
ncols = (DIM (klist) - 1); |
680 |
if( rc ) |
} |
681 |
return rc; |
|
682 |
|
for (int j = 0; j < ncols; j++) |
683 |
lv->ctrl = ctrl; |
listview_add_column (lv, &col[j]); |
684 |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) { |
listview_set_ext_style (lv); |
685 |
col = klist_enc; |
if (ext_chkbox) |
686 |
n = KLIST_ENC_ITEMS; |
listview_set_chkbox_style (lv); |
687 |
} |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY); |
688 |
else if ((mode & KEYLIST_SIGN)) { |
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR); |
689 |
col = klist_enc; |
ico[2] = LoadIcon (glob_hinst, (LPCTSTR)IDI_REV_KEYPAIR); |
690 |
n = KLIST_ENC_ITEMS - 1; |
ico[3] = LoadIcon (glob_hinst, (LPCTSTR)IDI_REV_PUBKEY); |
691 |
} |
ico[4] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_DOWNARROW); |
692 |
else { |
ico[5] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_UPARROW); |
693 |
col = klist; |
ico[6] = LoadIcon (glob_hinst, (LPCTSTR)IDI_EXP_PUBKEY); |
694 |
n = KLIST_ITEMS; |
listview_set_image_list (lv, 20, 16, ico, 7); |
695 |
} |
listview_del_all_items (lv); |
696 |
|
listview_set_grid_style (lv); |
697 |
for( j = 0; j < n; j++ ) |
*r_lv = lv; |
698 |
listview_add_column( lv, &col[j] ); |
} |
699 |
listview_set_ext_style( lv ); |
|
700 |
*r_lv = lv; |
|
701 |
|
static void |
702 |
return 0; |
keylist_load_keycache (keylist_ctrl_t kl, int mode, |
703 |
} |
gpg_keycache_t pubkc, gpg_keycache_t seckc) |
704 |
|
{ |
705 |
|
gpgme_key_t key, skey; |
706 |
static void |
struct keycache_s *c; |
707 |
keylist_load_keycache (listview_ctrl_t lv, int mode, |
const char *keyid; |
708 |
gpg_keycache_t pubkc, gpg_keycache_t seckc) |
|
709 |
{ |
gpg_keycache_rewind (pubkc); |
710 |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
if (pubkc && seckc) { |
711 |
gpgme_key_t key, skey; |
while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) { |
712 |
const char * keyid; |
keyid = key->subkeys->keyid; |
713 |
|
if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey)) |
714 |
if (pubkc && seckc) { |
keylist_add_key (kl, mode, c, key); |
715 |
gpg_keycache_rewind (pubkc); |
} |
716 |
while (!gpg_keycache_next_key (pubkc, 0, &key)) { |
} |
717 |
keyid = key->subkeys->keyid; |
else if (pubkc) { |
718 |
if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey)) |
while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) |
719 |
keylist_add_key (lv, mode, key); |
keylist_add_key (kl, mode, c, key); |
720 |
} |
} |
721 |
} |
} |
722 |
else if (pubkc) { |
|
723 |
gpg_keycache_rewind (pubkc); |
|
724 |
while (!err) { |
/* Load the list view @ctrl with the keys from the cache. |
725 |
err = gpg_keycache_next_key (pubkc, 0, &key); |
Return value: list view context on success. */ |
726 |
if (!err) |
keylist_ctrl_t |
727 |
keylist_add_key (lv, mode, key); |
keylist_load (HWND ctrl, gpg_keycache_t pubkc, gpg_keycache_t seckc, |
728 |
} |
int mode, int sortby) |
729 |
} |
{ |
730 |
} |
keylist_ctrl_t kl; |
731 |
|
|
732 |
|
kl = new keylist_ctrl_s; |
733 |
/* Load the list view @ctrl with the keys from the cache. |
keylist_build (&kl->lv, ctrl, mode); |
734 |
Return value: list view context on success. */ |
keylist_load_keycache (kl, mode, pubkc, seckc); |
735 |
listview_ctrl_t |
kl->nkeys = update_keys (kl, 0, &kl->keys); |
736 |
keylist_load (HWND ctrl, gpg_keycache_t pubkc, gpg_keycache_t seckc, |
keylist_sort (kl, sortby); |
737 |
int mode, int sortby) |
return kl; |
738 |
{ |
} |
739 |
listview_ctrl_t lv; |
|
740 |
int rc = 0; |
|
741 |
|
/* Reload the given key list control @lv. */ |
742 |
rc = keylist_build (&lv, ctrl, mode); |
int |
743 |
if (rc) |
keylist_reload (keylist_ctrl_t kl, gpg_keycache_t pubkc, int mode, int sortby) |
744 |
return NULL; |
{ |
745 |
keylist_load_keycache (lv, mode, pubkc, seckc); |
listview_del_all_items (kl->lv); |
746 |
keylist_sort (lv, sortby); |
keylist_load_keycache (kl, mode, pubkc, NULL); |
747 |
if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) |
/* It is possible that the list shrinks or increases so we need to |
748 |
keylist_add_groups (lv); |
rebuild the list again. */ |
749 |
return lv; |
free (kl->keys); kl->keys = NULL; |
750 |
} |
kl->nkeys = update_keys (kl, 0, &kl->keys); |
751 |
|
keylist_sort (kl, sortby); |
752 |
|
return 0; |
753 |
/* Reload the given key list control @lv. */ |
} |
754 |
int |
|
755 |
keylist_reload (listview_ctrl_t lv, gpg_keycache_t pubkc, int mode, int sortby) |
|
756 |
{ |
void |
757 |
listview_del_all (lv); |
keylist_delete (keylist_ctrl_t kl) |
758 |
keylist_load_keycache( lv, mode, pubkc, NULL ); |
{ |
759 |
keylist_sort (lv, sortby); |
if (!kl) |
760 |
return 0; |
return; |
761 |
} |
if (kl->keys != NULL) { |
762 |
|
free (kl->keys); |
763 |
|
kl->keys = NULL; |
764 |
void |
} |
765 |
keylist_delete (listview_ctrl_t lv) |
if (kl->lv != NULL) { |
766 |
{ |
listview_release (kl->lv); |
767 |
if (lv) { |
kl->lv = NULL; |
768 |
listview_release (lv); |
} |
769 |
} |
} |
770 |
} |
|
771 |
|
|
772 |
|
|
773 |
/* Return if there is a secret for @key. |
|
774 |
0 means success. */ |
/* Enumeration for possible key icons. */ |
775 |
static int |
enum key_icontype_t { |
776 |
find_secret_key (gpgme_key_t key) |
IMG_KEY_PUB = 0, |
777 |
{ |
IMG_KEY_PAIR = 1, |
778 |
const char *keyid; |
IMG_KEY_PAIR_REV = 2, |
779 |
winpt_key_s skey; |
IMG_KEY_PUB_REV = 3, |
780 |
|
IMG_KEY_PUB_EXP = 6, |
781 |
memset (&skey, 0, sizeof (skey)); |
}; |
782 |
keyid = key->subkeys->keyid; |
|
783 |
if (!keyid) |
|
784 |
return 0; |
static int |
785 |
winpt_get_seckey (keyid, &skey); |
key_get_image_id (gpgme_key_t key) |
786 |
if (skey.ext && skey.ext->gloflags.divert_to_card) |
{ |
787 |
return 2; |
if (find_secret_key (key)) |
788 |
return skey.ctx? 1 : 0; |
return key->revoked ? IMG_KEY_PAIR_REV :IMG_KEY_PAIR; |
789 |
} |
if (key->revoked) |
790 |
|
return IMG_KEY_PUB_REV; |
791 |
|
if (key->expired) |
792 |
static int |
return IMG_KEY_PUB_EXP; |
793 |
do_addkey (listview_ctrl_t lv, gpgme_key_t key, int uididx, int keyidx, int list) |
return IMG_KEY_PUB; |
794 |
{ |
} |
795 |
LV_ITEM lvi; |
|
796 |
gpgme_user_id_t u; |
|
797 |
gpgme_subkey_t k; |
static int |
798 |
char fmt[128], *p; |
do_addkey (listview_ctrl_t lv, struct keycache_s *ctx, gpgme_key_t key, |
799 |
const char *attr; |
int uididx, int keyidx, int list) |
800 |
u32 key_attr; |
{ |
801 |
int idx = 0; |
gpgme_user_id_t u; |
802 |
|
gpgme_subkey_t k; |
803 |
/* we check the pubkey algorithm here to make sure that no ElGamal |
LV_ITEM lvi; |
804 |
sign+encrypt key is used in _any_ mode */ |
char *p; |
805 |
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
const char *attr; |
806 |
log_debug ("ElGamal (E+S) key found: %s (%s)\n", |
int idx = 0; |
807 |
key->uids->name, key->subkeys->keyid); |
|
808 |
return 0; |
/* we check the pubkey algorithm here to make sure that no ElGamal |
809 |
} |
sign+encrypt key is used in _any_ mode */ |
810 |
|
if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
811 |
|
log_debug ("ElGamal (E+S) key found: %s (%s)\n", |
812 |
if (listview_add_item2 (lv, " ", (void *)key)) |
key->uids->name, key->subkeys->keyid); |
813 |
return WPTERR_GENERAL; |
return 0; |
814 |
|
} |
815 |
attr = key->uids->uid; |
|
816 |
memset (&lvi, 0, sizeof lvi); |
if (listview_add_item2 (lv, " ", (void *)ctx)) |
817 |
lvi.mask = LVIF_TEXT | LVIF_PARAM; |
return WPTERR_GENERAL; |
818 |
lvi.pszText = (char *)attr; |
|
819 |
lvi.lParam = (LPARAM )key; |
attr = ctx->uids->uid; |
820 |
if (ListView_SetItem( lv->ctrl, &lvi ) == FALSE) |
memset (&lvi, 0, sizeof lvi); |
821 |
return WPTERR_GENERAL; |
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; |
822 |
|
lvi.pszText = (char *)attr; |
823 |
if (uididx == -1) { /* request the primary user-id of the key. */ |
lvi.iImage = key_get_image_id (key); |
824 |
attr = key->uids->uid; |
lvi.lParam = (LPARAM )ctx; |
825 |
uididx = 0; |
if (ListView_SetItem (lv->ctrl, &lvi) == FALSE) |
826 |
} |
return WPTERR_GENERAL; |
827 |
else { |
|
828 |
u = get_nth_userid (key, uididx); |
if (uididx == -1) { /* request the primary user-id of the key. */ |
829 |
if (!u || u->revoked || uididx < 0) |
attr = ctx->uids->uid; |
830 |
uididx = 0; /* fixme: this happen sometimes but it's illegal! (<0) */ |
uididx = 0; |
831 |
u = get_nth_userid (key, uididx); |
} |
832 |
/*attr = key->uids->uid; XXX*/ |
else { |
833 |
attr = u->uid; |
u = get_nth_userid (key, uididx); |
834 |
} |
if (!u || u->revoked || uididx < 0) |
835 |
if (attr == NULL || strlen (attr) < 5) { /* normal userids are >= 5 chars */ |
uididx = 0; |
836 |
attr = _("Invalid User ID"); |
u = get_nth_userid (key, uididx); |
837 |
listview_add_sub_item (lv, 0, idx++, attr); |
attr = u->uid; |
838 |
} |
} |
839 |
else { |
if (attr == NULL || strlen (attr) < 5) { /* normal userids are > 5 chars */ |
840 |
char *uid = utf8_to_wincp (attr, strlen (attr)); |
attr = _("Invalid User ID"); |
841 |
if (uid) { |
listview_add_sub_item (lv, 0, idx++, attr); |
842 |
listview_add_sub_item (lv, 0, idx++, uid); |
} |
843 |
free (uid); |
else |
844 |
} |
listview_add_sub_item (lv, 0, idx++, attr); |
845 |
} |
k = get_nth_key (key, keyidx); |
846 |
k = get_nth_key (key, keyidx); |
if (k && k->keyid != NULL) { |
847 |
if (k && k->keyid) { |
char keyid[16+1]; |
848 |
_snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8); |
|
849 |
listview_add_sub_item( lv, 0, idx++, fmt ); |
_snprintf (keyid, DIM (keyid) -1, "0x%s", k->keyid + 8); |
850 |
} |
listview_add_sub_item (lv, 0, idx++, keyid); |
851 |
if (list > 0) { |
} |
852 |
key_attr = find_secret_key (key); |
if (list > 0) { |
853 |
if (!key_attr) |
DWORD key_attr = find_secret_key (key); |
854 |
attr = "pub"; |
if (!key_attr) |
855 |
else |
attr = "pub"; |
856 |
attr = key_attr == 1? "pub/sec" : "pub/crd"; |
else |
857 |
listview_add_sub_item (lv, 0, idx++, attr); |
attr = key_attr == 1? "pub/sec" : "pub/crd"; |
858 |
} |
listview_add_sub_item (lv, 0, idx++, attr); |
859 |
if (lv->cols >= 2) { |
} |
860 |
attr = get_key_size (key, list == -1? keyidx+1 : 0); |
if (lv->cols >= 2) { |
861 |
if (attr) |
attr = get_key_size (key, list == -1? keyidx+1 : 0); |
862 |
listview_add_sub_item (lv, 0, idx++, attr); |
if (attr != NULL) |
863 |
} |
listview_add_sub_item (lv, 0, idx++, attr); |
864 |
if (lv->cols >= 3) { |
} |
865 |
attr = get_key_algo (key, list == -1? keyidx+1 : 0); |
if (lv->cols >= 3) { |
866 |
if (attr) |
attr = get_key_algo (key, list == -1? keyidx+1 : 0); |
867 |
listview_add_sub_item( lv, 0, idx++, attr); |
if (attr != NULL) |
868 |
} |
listview_add_sub_item( lv, 0, idx++, attr); |
869 |
if( lv->cols >= 4 ) { |
} |
870 |
p = get_key_status( key, uididx, list > 0? 1 : 0 ); |
if (lv->cols >= 4) { |
871 |
if (!p) |
p = get_key_status (key, uididx, list > 0? 1 : 0); |
872 |
return WPTERR_GENERAL; |
if (p != NULL) |
873 |
listview_add_sub_item (lv, 0, idx++, p); |
listview_add_sub_item (lv, 0, idx++, p); |
874 |
free_if_alloc (p); |
free_if_alloc (p); |
875 |
} |
} |
876 |
if (lv->cols >= 5) { |
if (lv->cols >= 5) { |
877 |
attr = get_key_trust (key, uididx, list > 0? 1 : 0); |
attr = get_key_trust (key, uididx, list > 0? 1 : 0); |
878 |
listview_add_sub_item (lv, 0, idx++, attr); |
listview_add_sub_item (lv, 0, idx++, attr); |
879 |
} |
} |
880 |
if( lv->cols >= 6 ) { |
if (lv->cols >= 6) { |
881 |
k = get_nth_key (key, keyidx); |
k = get_nth_key (key, keyidx); |
882 |
key_attr = k->timestamp; |
if (k->timestamp > 0) { |
883 |
if( key_attr ) { |
attr = get_key_created (k->timestamp); |
884 |
attr = get_key_created (key_attr); |
listview_add_sub_item (lv, 0, idx++, attr); |
885 |
listview_add_sub_item( lv, 0, idx++, attr ); |
} |
886 |
} |
} |
887 |
} |
|
888 |
|
return 0; |
889 |
return 0; |
} |
890 |
} |
|
891 |
|
|
892 |
|
/* Update a single column @col but for each element in the |
893 |
void |
listview @lv. */ |
894 |
keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key) |
void |
895 |
{ |
keylist_upd_col (keylist_ctrl_t kl, int col) |
896 |
const char *s; |
{ |
897 |
char tmp[32]; |
gpgme_key_t key; |
898 |
|
const char *s; |
899 |
listview_set_item2 (lv, pos, (void *)key); |
char buf[32], *p; |
900 |
/* the only mode we support is KYLIST_LIST in the Key Manager */ |
|
901 |
|
for (int i=0; i < listview_count_items (kl->lv, 0); i++) { |
902 |
s = key->uids->uid; |
key = km_get_key_ptr (kl, i, NULL); |
903 |
if (s) |
if (!key) |
904 |
listview_add_sub_item (lv, pos, 0, s); |
continue; |
905 |
|
switch (col) { |
906 |
s = key->subkeys->keyid; |
case KM_COL_KEYID: |
907 |
if (s) { |
_snprintf (buf, DIM (buf)-1, "0x%s", key->subkeys->keyid+8); |
908 |
sprintf (tmp, "0x%s", s+8); |
listview_add_sub_item (kl->lv, i, col, buf); |
909 |
listview_add_sub_item (lv, pos, 1, tmp); |
break; |
910 |
} |
|
911 |
|
case KM_COL_CIPHER: |
912 |
s = find_secret_key (key)? "pub/sec" : "pub"; |
s = get_key_algo (key, 0); |
913 |
listview_add_sub_item (lv, pos, 2, s); |
listview_add_sub_item (kl->lv, i, col, s); |
914 |
|
break; |
915 |
s = get_key_size (key, 0); |
|
916 |
if (s) |
case KM_COL_TYPE: |
917 |
listview_add_sub_item (lv, pos, 3, s); |
s = find_secret_key (key)? "pub/sec" : "pub"; |
918 |
|
listview_add_sub_item (kl->lv, i, col, s); |
919 |
s = get_key_algo (key, 0); |
break; |
920 |
if (s) |
|
921 |
listview_add_sub_item (lv, pos, 4, s); |
case KM_COL_CREAT: |
922 |
|
s = get_key_created (key->subkeys->timestamp); |
923 |
s = get_key_status (key, 0, 1); |
listview_add_sub_item (kl->lv, i, col, s); |
924 |
if (s) |
break; |
925 |
listview_add_sub_item (lv, pos, 5, s); |
|
926 |
|
case KM_COL_DESC: |
927 |
s = get_key_trust (key, 0, 1); |
p = get_key_desc (key); |
928 |
if (s) |
listview_add_sub_item (kl->lv, i, col, p); |
929 |
listview_add_sub_item (lv, pos, 6, s); |
free_if_alloc (p); |
930 |
|
break; |
931 |
long t = key->subkeys->timestamp; |
} |
932 |
s = get_key_created (t); |
} |
933 |
if (s) |
} |
934 |
listview_add_sub_item (lv, pos, 7, s); |
|
935 |
} |
|
936 |
|
/* Update the listview item at position @pos with the data from |
937 |
|
the key @key. */ |
938 |
int |
void |
939 |
keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key) |
keylist_upd_key (keylist_ctrl_t kl, int pos, |
940 |
{ |
struct keycache_s *ctx, gpgme_key_t key) |
941 |
int uids, rc = 0, i, n = 0; |
{ |
942 |
gpgme_subkey_t k; |
listview_ctrl_t lv = kl->lv; |
943 |
|
char *p; |
944 |
for (k=key->subkeys, i = 0; i < count_subkeys (key); i++, k=k->next) { |
char tmp[32]; |
945 |
if (k->invalid) { |
|
946 |
log_debug ("keylist_add_key: invalid key \"%s\"\n", key->uids->name); |
listview_set_item2 (lv, pos, (void *)ctx); |
947 |
continue; /* Don't use invalid keys */ |
update_key (kl, pos, key); |
948 |
} |
/* the only mode we support is KEYLIST_LIST in the Key Manager */ |
949 |
|
|
950 |
if (mode & KEYLIST_ALL) { |
const char *s = ctx->uids->uid; |
951 |
uids = count_userids (key); |
if (s) |
952 |
rc = do_addkey (lv, key, uids, i, 0); |
listview_add_sub_item (lv, pos, KM_COL_UID, s); |
953 |
if( rc ) |
|
954 |
return rc; |
s = key->subkeys->keyid; |
955 |
} |
if (s) { |
956 |
else if (mode & KEYLIST_LIST) |
sprintf (tmp, "0x%s", s+8); |
957 |
return do_addkey (lv, key, -1, i, 1); |
listview_add_sub_item (lv, pos, KM_COL_KEYID, tmp); |
958 |
else if (mode & KEYLIST_ENCRYPT) { |
} |
959 |
if (k->can_encrypt && key_is_useable (k)) { |
|
960 |
if (mode & KEYLIST_FLAG_FILE) { |
s = find_secret_key (key)? "pub/sec" : "pub"; |
961 |
rc = do_addkey (lv, key, -1, i, -1); |
listview_add_sub_item (lv, pos, KM_COL_TYPE, s); |
962 |
if (rc) |
|
963 |
return rc; |
s = get_key_size (key, 0); |
964 |
} |
if (s) |
965 |
else { |
listview_add_sub_item (lv, pos, KM_COL_SIZE, s); |
966 |
for( uids = 0; uids < count_userids (key); uids++ ) { |
|
967 |
rc = do_addkey( lv, key, uids, i, -1 ); |
s = get_key_algo (key, 0); |
968 |
if( rc ) |
if (s) |
969 |
return rc; |
listview_add_sub_item (lv, pos, KM_COL_CIPHER, s); |
970 |
} |
|
971 |
} |
p = get_key_status (key, 0, 1); |
972 |
} |
if (p) { |
973 |
} |
listview_add_sub_item (lv, pos, KM_COL_VALID, p); |
974 |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
free_if_alloc (p); |
975 |
if( k->can_encrypt && key_is_useable (k)) |
} |
976 |
{ |
|
977 |
rc = do_addkey (lv, key, -1, i, -1); |
s = get_key_trust (key, 0, 1); |
978 |
return rc; |
if (s) |
979 |
} |
listview_add_sub_item (lv, pos, KM_COL_TRUST, s); |
980 |
} |
|
981 |
else if (mode & KEYLIST_SIGN) { |
long t = key->subkeys->timestamp; |
982 |
if ( k->can_sign |
s = get_key_created (t); |
983 |
&& find_secret_key( key ) |
if (s) |
984 |
&& key_is_useable (k)) |
listview_add_sub_item (lv, pos, KM_COL_CREAT, s); |
985 |
{ |
} |
986 |
rc = do_addkey (lv, key, -1, i, -1); |
|
987 |
if( rc ) |
|
988 |
return rc; |
int |
989 |
} |
keylist_add_key (keylist_ctrl_t kl, int mode, |
990 |
} |
struct keycache_s *ctx, gpgme_key_t key) |
991 |
} |
{ |
992 |
|
gpgme_subkey_t k; |
993 |
return rc; |
listview_ctrl_t lv = kl->lv; |
994 |
} /* keylist_add_key */ |
int uids, rc, i; |
995 |
|
|
996 |
|
/* if the entire key is disabled, just return. */ |
997 |
int |
if (key->disabled && !(mode & KEYLIST_LIST)) |
998 |
keylist_sort (listview_ctrl_t lv, int sortby) |
return 0; |
999 |
{ |
|
1000 |
return listview_sort_items (lv, sortby, keylist_cmp_cb); |
for (k = key->subkeys, i = 0; i < count_subkeys (key); i++, k = k->next) { |
1001 |
} |
if (k->invalid) { |
1002 |
|
log_debug ("keylist_add_key: invalid key \"%s\"\n", |
1003 |
|
key->uids->name); |
1004 |
/* Check that the validity @validity is at least >= marginal. */ |
continue; /* Don't use invalid keys */ |
1005 |
static int |
} |
1006 |
key_check_validity (const char *validity) |
|
1007 |
{ |
if (mode & KEYLIST_ALL) { |
1008 |
if (strstr (validity, "Unknown") || |
uids = count_userids (key); |
1009 |
strstr (validity, "Undefined") || |
rc = do_addkey (lv, ctx, key, uids, i, 0); |
1010 |
strstr (validity, "Never") || |
if (rc) |
1011 |
strstr (validity, "None")) |
return rc; |
1012 |
return 0; |
} |
1013 |
return 1; |
else if (mode & KEYLIST_LIST) |
1014 |
} |
return do_addkey (lv, ctx, key, -1, i, 1); |
1015 |
|
else if (mode & KEYLIST_ENCRYPT) { |
1016 |
|
if (k->can_encrypt && key_is_useable (k)) { |
1017 |
/* Extract all selected recipients from the list @lv and return them |
if (mode & KEYLIST_FLAG_FILE) { |
1018 |
as a vector. @r_force_trust is >= 1 if one of the recipients is not |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
1019 |
fully trusted. @r_count returns the number of selected keys. |
if (rc) |
1020 |
Return value: the key list on success, NULL otherwise. */ |
return rc; |
1021 |
gpgme_key_t* |
} |
1022 |
keylist_get_recipients (listview_ctrl_t lv, int *r_force_trust, int *r_count) |
else { |
1023 |
{ |
for (uids = 0; uids < count_userids (key); uids++) { |
1024 |
int count = 0, force_trust = 0; |
rc = do_addkey (lv, ctx, key, uids, i, -1); |
1025 |
int n, j, ka_pos = 0, rc = 0; |
if (rc) |
1026 |
int k_pos=0; |
return rc; |
1027 |
char keyid[32], valid[32], id[100]; |
} |
1028 |
key_array_s *ka = NULL; |
} |
1029 |
gpgme_key_t *keybuf; |
} |
1030 |
|
} |
1031 |
n = listview_count_items( lv, 0 ); |
else if (mode & KEYLIST_ENCRYPT_MIN) { |
1032 |
|
if (k->can_encrypt && key_is_useable (k)) { |
1033 |
ka = key_array_new( n ); |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
1034 |
if (!ka) |
return rc; |
1035 |
BUG (NULL); |
} |
1036 |
|
} |
1037 |
keybuf = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); |
else if (mode & KEYLIST_SIGN) { |
1038 |
if (!keybuf) |
if (k->can_sign |
1039 |
BUG (NULL); |
&& find_secret_key (key) |
1040 |
|
&& key_is_useable (k)) { |
1041 |
for( j = 0; j < n; j++ ) { |
rc = do_addkey (lv, ctx, key, -1, i, -1); |
1042 |
if( listview_get_item_state (lv, j) || n == 1) { |
if (rc) |
1043 |
listview_get_item_text (lv, j, 0, id, sizeof id-1); |
return rc; |
1044 |
listview_get_item_text (lv, j, 1, keyid, sizeof keyid - 1); |
} |
1045 |
listview_get_item_text (lv, j, 4, valid, sizeof valid -1); |
} |
1046 |
if( !key_check_validity (valid) |
} |
1047 |
&& !key_array_search( ka, ka_pos, keyid )) { |
|
1048 |
char *warn = new char[512+strlen (id) + 1]; |
return 0; |
1049 |
if (!warn) |
} |
1050 |
BUG (0); |
|
1051 |
sprintf (warn, |
|
1052 |
_("It is NOT certain that the key belongs to the person\n" |
int |
1053 |
"named in the user ID. If you *really* know what you are\n" |
keylist_sort (keylist_ctrl_t kl, int sortby) |
1054 |
"doing, you may answer the next question with yes\n" |
{ |
1055 |
"\n" |
int ret = listview_sort_items (kl->lv, sortby, keylist_cmp_cb); |
1056 |
"Use \"%s\" anyway?"), id); |
kl->nkeys = update_keys (kl, 1, &kl->keys); |
1057 |
if (reg_prefs.always_trust) |
return ret; |
1058 |
rc = IDYES; |
} |
1059 |
else |
|
1060 |
rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK); |
|
1061 |
if (rc == IDYES) { |
/* Check that the validity @validity is at least >= marginal. */ |
1062 |
gpgme_key_t k; |
static int |
1063 |
get_pubkey (keyid, &k); |
key_check_validity (gpgme_key_t key) |
1064 |
keybuf[k_pos++] = k; |
{ |
1065 |
force_trust++; |
gpgme_user_id_t u; |
1066 |
ka[ka_pos].checked = 1; |
|
1067 |
strcpy (ka[ka_pos++].keyid, keyid); |
for (u=key->uids; u; u =u->next) { |
1068 |
count++; |
if (u->validity >= GPGME_VALIDITY_MARGINAL) |
1069 |
} |
return -1; |
1070 |
free_if_alloc (warn); |
} |
1071 |
} |
|
1072 |
else { |
return 0; |
1073 |
gpgme_key_t k; |
} |
1074 |
listview_get_item_text( lv, j, 1, keyid, sizeof keyid -1 ); |
|
1075 |
get_pubkey (keyid, &k); |
|
1076 |
keybuf[k_pos++] = k; |
/* Extract all selected recipients from the list @lv and return them |
1077 |
count++; |
as a vector. @r_force_trust is >= 1 if one of the recipients is not |
1078 |
} |
fully trusted. @r_count returns the number of selected keys. |
1079 |
} |
Return value: the key list on success, NULL otherwise. */ |
1080 |
} |
gpgme_key_t* |
1081 |
key_array_release (ka); |
keylist_get_recipients (keylist_ctrl_t kl, int *r_force_trust, size_t *r_count) |
1082 |
if (r_force_trust) |
|
1083 |
*r_force_trust = force_trust; |
{ |
1084 |
if (r_count) |
gpgme_key_t *keybuf, key; |
1085 |
*r_count = count; |
listview_ctrl_t lv = kl->lv; |
1086 |
return keybuf; |
key_array_s *ka = NULL; |
1087 |
} |
keycache_s *c; |
1088 |
|
size_t count = 0; |
1089 |
|
int force_trust = 0; |
1090 |
static int |
int nkeys, ka_pos = 0, rc = 0; |
1091 |
keylist_get_keyflags (const char *buf, size_t buflen) |
int k_pos=0; |
1092 |
{ |
|
1093 |
int c = 0, flags = 0; |
nkeys = listview_count_items (lv, 0); |
1094 |
|
ka = key_array_new (nkeys); |
1095 |
if( *buf != '[' ) |
keybuf = (gpgme_key_t*)calloc (nkeys+1, sizeof (gpgme_key_t)); |
1096 |
return KEYFLAG_NONE; |
if (!keybuf) |
1097 |
while (buf && c != ']') |
BUG (NULL); |
1098 |
{ |
|
1099 |
c = *buf++; |
for (int j = 0; j < nkeys; j++) { |
1100 |
if (c == 'R') |
if (listview_get_item_state (lv, j) || nkeys == 1) { |
1101 |
flags |= KEYFLAG_REVOKED; |
key = km_get_key_ptr (kl, j, &c); |
1102 |
if (c == 'E') |
if (!key) |
1103 |
flags |= KEYFLAG_EXPIRED; |
BUG (0); |
1104 |
if (c == 'D') |
if (!key_check_validity (key) && |
1105 |
flags |= KEYFLAG_DISABLED; |
!key_array_search (ka, ka_pos, key->subkeys->keyid)) { |
1106 |
} |
StringBuffer warn; |
1107 |
|
warn = warn + c->uids->uid + ":\n\n"; |
1108 |
return flags; |
warn = warn +_("It is NOT certain that the key belongs to the person\n" |
1109 |
} /* keylist_get_keyflags */ |
"named in the user ID. If you *really* know what you are\n" |
1110 |
|
"doing, you may answer the next question with no\n" |
1111 |
|
"\nSkip this key?"); |
1112 |
gpgme_key_t* |
rc = msg_box (NULL, warn.getBuffer(), _("Warning"), MB_WARN_ASK); |
1113 |
keylist_enum_recipients (listview_ctrl_t lv, int listype, int *r_count) |
if (reg_prefs.always_trust || rc == IDNO) { |
1114 |
{ |
keybuf[k_pos++] = key; |
1115 |
gpgme_key_t* rset; |
force_trust++; |
1116 |
gpgme_key_t k; |
ka[ka_pos].checked = 1; |
1117 |
int i, n, id, k_pos=0; |
strcpy (ka[ka_pos++].keyid, key->subkeys->keyid); |
1118 |
char keyid[32], t[128], t2[128]; |
count++; |
1119 |
|
} |
1120 |
n = listview_count_items (lv, 0); |
} |
1121 |
if (!n) |
else { |
1122 |
return 0; |
keybuf[k_pos++] = key; |
1123 |
rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); |
count++; |
1124 |
if (!rset) |
} |
1125 |
BUG (NULL); |
} |
1126 |
for( i = 0; i < n; i++ ) { |
} |
1127 |
if( !listview_get_item_state( lv, i ) ) |
key_array_release (ka); |
1128 |
continue; |
if (r_force_trust) |
1129 |
listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 ); |
*r_force_trust = force_trust; |
1130 |
switch( listype ) { |
if (r_count) |
1131 |
case KEYLIST_LIST: |
*r_count = count; |
1132 |
listview_get_item_text( lv, i, 5, t, sizeof t - 1 ); |
return keybuf; |
1133 |
if( keylist_get_keyflags( t, strlen( t ) ) & KEYFLAG_REVOKED ) { |
} |
1134 |
_snprintf( t2, sizeof t2 -1, |
|
1135 |
_("KeyID %s.\nDo you really want to export a revoked key?"), keyid ); |
|
1136 |
id = msg_box( lv->ctrl, t2, _("Recipients"), MB_INFO|MB_YESNO ); |
static int |
1137 |
if( id == IDNO ) |
keylist_get_keyflags (gpgme_key_t key) |
1138 |
continue; |
{ |
1139 |
} |
int flags = KEYFLAG_NONE; |
1140 |
break; |
|
1141 |
} |
if (key->revoked) |
1142 |
get_pubkey (keyid, &k); |
flags |= KEYFLAG_REVOKED; |
1143 |
rset[k_pos++] = k; |
if (key->expired) |
1144 |
} |
flags |= KEYFLAG_EXPIRED; |
1145 |
if (r_count) |
if (key->disabled) |
1146 |
*r_count = k_pos; |
flags |= KEYFLAG_DISABLED; |
1147 |
return rset; |
|
1148 |
} /* keylist_enum_recipients */ |
return flags; |
1149 |
|
} |
1150 |
|
|
1151 |
void |
|
1152 |
seclist_destroy (keylist_t * list) |
|
1153 |
{ |
gpgme_key_t* |
1154 |
keylist_t l2; |
keylist_enum_recipients (keylist_ctrl_t kl, int listype, size_t *r_count) |
1155 |
while (*list) { |
{ |
1156 |
l2 = (*list)->next; |
gpgme_key_t *rset; |
1157 |
safe_free (*list); |
gpgme_key_t key; |
1158 |
*list = l2; |
listview_ctrl_t lv = kl->lv; |
1159 |
} |
struct keycache_s *c; |
1160 |
list = NULL; |
size_t k_pos; |
1161 |
} /* seclist_destroy */ |
int nkeys, id; |
1162 |
|
|
1163 |
|
nkeys = listview_count_items (lv, 0); |
1164 |
void |
if (!nkeys) |
1165 |
seclist_init (HWND dlg, int ctlid, int flags, keylist_t * ret_list) |
return 0; |
1166 |
{ |
rset = (gpgme_key_t*)calloc (nkeys+1, sizeof (gpgme_key_t)); |
1167 |
gpg_keycache_t kc = NULL; |
if (!rset) |
1168 |
gpgme_key_t key = NULL; |
BUG (NULL); |
1169 |
HWND kb; |
k_pos = 0; |
1170 |
keylist_t list=NULL, l, l2; |
for (int i = 0; i < nkeys; i++) { |
1171 |
long pos = 0; |
if (!listview_get_item_state (lv, i)) |
1172 |
|
continue; |
1173 |
SendDlgItemMessage (dlg, ctlid, CB_RESETCONTENT, 0, 0); |
key = km_get_key_ptr (kl, i, &c); |
1174 |
kb = GetDlgItem (dlg, ctlid); |
switch (listype) { |
1175 |
kc = keycache_get_ctx (0); |
case KEYLIST_LIST: |
1176 |
if (!kc) |
if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) { |
1177 |
BUG (0); |
id = printf_box (_("Recipients"), MB_INFO|MB_YESNO, |
1178 |
gpg_keycache_rewind (kc); |
_("KeyID %s.\nDo you really want to export a revoked key?"), |
1179 |
|
c->uids->uid); |
1180 |
while (!gpg_keycache_next_key (kc, 1, &key)) { |
if (id == IDNO) |
1181 |
char * inf = NULL, * uid = NULL; |
continue; |
1182 |
const char * id; |
} |
1183 |
const char * keyid; |
break; |
1184 |
int algo; |
} |
1185 |
size_t size = 0; |
rset[k_pos++] = key; |
1186 |
|
} |
1187 |
if (flags & KEYLIST_FLAG_SHORT) |
if (r_count) |
1188 |
id = key->uids->name; |
*r_count = k_pos; |
1189 |
else |
return rset; |
1190 |
id = key->uids->uid; |
} |
1191 |
keyid = key->subkeys->keyid; |
|
1192 |
algo = key->subkeys->pubkey_algo; |
|
1193 |
if (!id || !keyid) |
void |
1194 |
continue; /* fixme: error? */ |
seclist_destroy (keylist_t *list) |
1195 |
if (!key_is_useable (key->subkeys)) |
{ |
1196 |
continue; |
keylist_t l2; |
1197 |
|
|
1198 |
uid = utf8_to_wincp (id, strlen (id)); |
while (*list) { |
1199 |
size = strlen( uid ) + strlen( keyid ) + 32; |
l2 = (*list)->next; |
1200 |
inf = new char[size+1]; |
safe_free (*list); |
1201 |
if( !inf ) |
*list = l2; |
1202 |
BUG( NULL ); |
} |
1203 |
_snprintf (inf, size, "%s (%s/0x%s)", uid, |
*list = NULL; |
1204 |
get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8); |
} |
1205 |
combox_add_string (kb, inf); |
|
1206 |
free_if_alloc (inf); |
|
1207 |
free (uid); |
void |
1208 |
l = (struct keylist_s *)calloc (1, sizeof * l); |
seclist_init (HWND dlg, int ctlid, int flags, keylist_t *ret_list) |
1209 |
if (!l) |
{ |
1210 |
BUG (0); |
gpg_keycache_t kc; |
1211 |
l->key = key; |
gpgme_key_t key = NULL; |
1212 |
if (!list) |
HWND kb; |
1213 |
list = l; |
keylist_t list=NULL, l, l2; |
1214 |
else { |
long pos; |
1215 |
for( l2 = list; l2->next; l2 = l2->next ) |
|
1216 |
; |
SendDlgItemMessage (dlg, ctlid, CB_RESETCONTENT, 0, 0); |
1217 |
l2->next = l; |
kb = GetDlgItem (dlg, ctlid); |
1218 |
} |
kc = keycache_get_ctx (0); |
1219 |
} |
if (!kc) |
1220 |
for( pos = 0, l2=list; pos < SendMessage( kb, CB_GETCOUNT, 0, 0 ); pos++, l2=l2->next ) |
BUG (0); |
1221 |
SendMessage( kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key ); |
gpg_keycache_rewind (kc); |
1222 |
SendMessage( kb, CB_SETCURSEL, 0, 0 ); |
|
1223 |
*ret_list = list; |
while (!gpg_keycache_next_key (kc, 1, &key)) { |
1224 |
} |
StringBuffer inf; |
1225 |
|
char *uid; |
1226 |
|
const char *id; |
1227 |
/* Select a secret key from the combo box with the ID @ctlid. |
|
1228 |
Return the code on success in @ret_key. */ |
if (key->disabled || !key_is_useable (key->subkeys)) |
1229 |
int |
continue; |
1230 |
seclist_select_key (HWND dlg, int ctlid, gpgme_key_t *ret_key) |
|
1231 |
{ |
if (flags & KEYLIST_FLAG_SHORT) |
1232 |
int pos; |
id = key->uids->name; |
1233 |
DWORD k = 0; |
else |
1234 |
|
id = key->uids->uid; |
1235 |
pos = SendDlgItemMessage (dlg, ctlid, CB_GETCURSEL, 0, 0); |
if (!id || !key->subkeys->keyid) |
1236 |
if (pos == CB_ERR) { |
continue; |
1237 |
msg_box (dlg, _("No key was selected."), _("Secret Key List"), MB_ERR); |
|
1238 |
*ret_key = NULL; |
uid = utf8_to_native (id); |
1239 |
} |
inf = uid; |
1240 |
else { |
inf = inf + " (" + get_key_pubalgo (key->subkeys->pubkey_algo) + "/"; |
1241 |
k = SendDlgItemMessage (dlg, ctlid, CB_GETITEMDATA, pos, 0); |
inf = inf + "0x" + (key->subkeys->keyid+8) + ")"; |
1242 |
*ret_key = (gpgme_key_t)k; |
|
1243 |
} |
combox_add_string (kb, inf.getBuffer ()); |
1244 |
return k? 0 : -1; |
safe_free (uid); |
1245 |
} |
l = (struct keylist_s *)calloc (1, sizeof * l); |
1246 |
|
if (!l) |
1247 |
|
BUG (0); |
1248 |
|
l->key = key; |
1249 |
|
if (!list) |
1250 |
|
list = l; |
1251 |
|
else { |
1252 |
|
for( l2 = list; l2->next; l2 = l2->next ) |
1253 |
|
; |
1254 |
|
l2->next = l; |
1255 |
|
} |
1256 |
|
} |
1257 |
|
for (pos = 0, l2=list; pos < SendMessage (kb, CB_GETCOUNT, 0, 0); |
1258 |
|
pos++, l2=l2->next) |
1259 |
|
SendMessage (kb, CB_SETITEMDATA, pos, (LPARAM)(DWORD)l2->key); |
1260 |
|
SendMessage (kb, CB_SETCURSEL, 0, 0); |
1261 |
|
*ret_list = list; |
1262 |
|
} |
1263 |
|
|
1264 |
|
|
1265 |
|
/* Select a secret key from the combo box with the ID @ctlid. |
1266 |
|
Return the code on success in @ret_key. */ |
1267 |
|
int |
1268 |
|
seclist_select_key (HWND dlg, int ctlid, gpgme_key_t *ret_key) |
1269 |
|
{ |
1270 |
|
int pos; |
1271 |
|
DWORD k = 0; |
1272 |
|
|
1273 |
|
pos = SendDlgItemMessage (dlg, ctlid, CB_GETCURSEL, 0, 0); |
1274 |
|
if (pos == CB_ERR) { |
1275 |
|
msg_box (dlg, _("No key was selected."), _("Secret Key List"), MB_ERR); |
1276 |
|
*ret_key = NULL; |
1277 |
|
} |
1278 |
|
else { |
1279 |
|
k = SendDlgItemMessage (dlg, ctlid, CB_GETITEMDATA, pos, 0); |
1280 |
|
*ret_key = (gpgme_key_t)k; |
1281 |
|
} |
1282 |
|
return k? 0 : -1; |
1283 |
|
} |
1284 |
|
|
1285 |
|
|
1286 |
|
LRESULT |
1287 |
|
keylist_listview_notify (HWND hwnd, gpgme_key_t *keys, |
1288 |
|
int ctlid, LPARAM lparam) |
1289 |
|
{ |
1290 |
|
LPNMHDR lpnmh = (LPNMHDR) lparam; |
1291 |
|
|
1292 |
|
if (!lpnmh) |
1293 |
|
BUG (NULL); |
1294 |
|
|
1295 |
|
/* Make sure the message is for the control and |
1296 |
|
that we have a key list. */ |
1297 |
|
if (lpnmh->idFrom != (DWORD)ctlid || keys == NULL) |
1298 |
|
return 0; |
1299 |
|
|
1300 |
|
switch (lpnmh->code) { |
1301 |
|
case NM_CUSTOMDRAW: |
1302 |
|
LPNMLVCUSTOMDRAW lplvcd; |
1303 |
|
lplvcd = (LPNMLVCUSTOMDRAW)lparam; |
1304 |
|
if (lplvcd->nmcd.dwDrawStage == CDDS_PREPAINT) |
1305 |
|
return CDRF_NOTIFYITEMDRAW; |
1306 |
|
|
1307 |
|
if (lplvcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT) { |
1308 |
|
LRESULT ret = CDRF_DODEFAULT; |
1309 |
|
int pos = lplvcd->nmcd.dwItemSpec; |
1310 |
|
HWND lv = GetDlgItem (hwnd, ctlid); |
1311 |
|
gpgme_key_t key = keys[pos]; |
1312 |
|
|
1313 |
|
if (key != NULL) { |
1314 |
|
HFONT hfont = (HFONT)SendMessage (lv, WM_GETFONT, 0, 0); |
1315 |
|
LOGFONT lf; |
1316 |
|
if (!GetObject (hfont, sizeof (lf), &lf)) |
1317 |
|
BUG (NULL); |
1318 |
|
if (key->revoked) |
1319 |
|
lf.lfStrikeOut = TRUE; |
1320 |
|
else if (key->expired) |
1321 |
|
lf.lfItalic = TRUE; |
1322 |
|
if (find_secret_key (key)) |
1323 |
|
lf.lfWeight = FW_SEMIBOLD; |
1324 |
|
hfont = CreateFontIndirect (&lf); |
1325 |
|
SelectObject (lplvcd->nmcd.hdc, hfont); |
1326 |
|
if (pos & 1) |
1327 |
|
lplvcd->clrTextBk = RGB (0xE5, 0xE5, 0xE5); |
1328 |
|
ret = CDRF_NEWFONT | CDRF_NOTIFYPOSTPAINT; |
1329 |
|
} |
1330 |
|
return ret; |
1331 |
|
} |
1332 |
|
|
1333 |
|
if (lplvcd->nmcd.dwDrawStage == CDDS_ITEMPOSTPAINT) { |
1334 |
|
HFONT hfont = (HFONT)GetStockObject (DEFAULT_GUI_FONT); |
1335 |
|
hfont = (HFONT)SelectObject (lplvcd->nmcd.hdc, hfont); |
1336 |
|
DeleteObject (hfont); |
1337 |
|
return CDRF_DODEFAULT; |
1338 |
|
} |
1339 |
|
return CDRF_DODEFAULT; |
1340 |
|
} |
1341 |
|
|
1342 |
|
return 0; |
1343 |
|
} |