23 |
#include <io.h> |
#include <io.h> |
24 |
|
|
25 |
#include "../resource.h" |
#include "../resource.h" |
26 |
|
#include "w32gpgme.h" |
27 |
#include "wptTypes.h" |
#include "wptTypes.h" |
28 |
#include "wptW32API.h" |
#include "wptW32API.h" |
29 |
#include "wptVersion.h" |
#include "wptVersion.h" |
30 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
31 |
#include "wptNLS.h" |
#include "wptNLS.h" |
32 |
#include "wptErrors.h" |
#include "wptErrors.h" |
|
#include "wptGPG.h" |
|
33 |
#include "wptContext.h" |
#include "wptContext.h" |
34 |
|
#include "wptGPG.h" |
35 |
#include "wptKeylist.h" |
#include "wptKeylist.h" |
36 |
#include "wptFileManager.h" |
#include "wptFileManager.h" |
37 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
39 |
#include "wptKeyManager.h" |
#include "wptKeyManager.h" |
40 |
#include "wptKeylist.h" |
#include "wptKeylist.h" |
41 |
#include "wptHTTP.h" |
#include "wptHTTP.h" |
42 |
|
#include "wptKeyEdit.h" |
43 |
|
#include "wptImport.h" |
44 |
|
|
45 |
|
|
46 |
|
/* Return a user friendly key representation in @buf from |
47 |
|
the key given by @keyid. */ |
48 |
static void |
static void |
49 |
km_get_clip_info (const char *uid, char *buf, size_t buflen) |
key_get_clip_info (const char *keyid, char *buf, size_t buflen) |
50 |
{ |
{ |
51 |
gpgme_key_t pk; |
gpgme_key_t pk; |
|
unsigned long a, algo; |
|
52 |
|
|
53 |
if (get_pubkey (uid, &pk)) |
if (get_pubkey (keyid, &pk)) |
54 |
BUG (0); |
BUG (0); |
|
|
|
|
a = gpgme_key_get_ulong_attr (pk, GPGME_ATTR_CREATED, NULL, 0); |
|
|
algo = gpgme_key_get_ulong_attr (pk, GPGME_ATTR_ALGO, NULL, 0); |
|
55 |
_snprintf (buf, buflen-1, |
_snprintf (buf, buflen-1, |
56 |
"pub %04d%s/%s %s %s\r\n" |
"pub %04d%s/%s %s %s\r\n" |
57 |
" Primary key fingerprint: %s\r\n", |
" Primary key fingerprint: %s\r\n", |
58 |
gpgme_key_get_ulong_attr (pk, GPGME_ATTR_LEN, NULL, 0), |
pk->subkeys->length, |
59 |
gpgme_key_expand_attr (GPGME_ATTR_ALGO_SHORT, algo), |
get_key_pubalgo (pk->subkeys->pubkey_algo), |
60 |
gpgme_key_get_string_attr (pk, GPGME_ATTR_KEYID, NULL, 0) + 8, |
pk->subkeys->keyid+8, |
61 |
gpgme_key_expand_attr (GPGME_ATTR_CREATED, a ), |
get_key_created (pk->subkeys->timestamp), |
62 |
gpgme_key_get_string_attr (pk, GPGME_ATTR_USERID, NULL, 0), |
pk->uids->uid, |
63 |
get_key_fpr (pk)); |
get_key_fpr (pk)); |
64 |
} |
} |
65 |
|
|
66 |
|
|
67 |
|
/* Quoted the user-id given by @uid. If @uid is already |
68 |
|
quoted @uid is returned without any modifications. |
69 |
|
Return value: quoted @uid. */ |
70 |
char* |
char* |
71 |
km_quote_uid (const char * uid) |
km_quote_uid (const char *uid) |
72 |
{ |
{ |
73 |
char * q = new char[strlen (uid) + 4]; |
char *q; |
74 |
|
|
75 |
|
if (*uid == '"' && uid[strlen (uid)-1] == '"') |
76 |
|
return m_strdup (uid); |
77 |
|
q = new char[strlen (uid) + 4]; |
78 |
if (!q) |
if (!q) |
79 |
BUG (NULL); |
BUG (NULL); |
80 |
_snprintf (q, strlen (uid) + 3, "\"%s\"", uid); |
_snprintf (q, strlen (uid) + 3, "\"%s\"", uid); |
81 |
return q; |
return q; |
82 |
} /* km_quote_uid */ |
} |
83 |
|
|
84 |
|
|
85 |
int |
int |
86 |
km_check_for_seckey (listview_ctrl_t lv, int pos, int * utrust) |
km_check_for_seckey (listview_ctrl_t lv, int pos, int *utrust) |
87 |
{ |
{ |
88 |
char t[32], t2[64]; |
char t[32], t2[64]; |
89 |
int type = 0; |
int type = 0; |
90 |
|
|
91 |
listview_get_item_text (lv, pos, 5, t, sizeof (t) - 1); |
if (utrust) |
92 |
listview_get_item_text (lv, pos, 2, t2, sizeof (t2) - 1); |
*utrust = 0; |
93 |
|
listview_get_item_text (lv, pos, 5, t, DIM (t)-1); |
94 |
|
listview_get_item_text (lv, pos, 2, t2, DIM (t2)-1); |
95 |
if (!strcmp (t2, "pub/sec")) |
if (!strcmp (t2, "pub/sec")) |
96 |
type = 1; |
type = 1; |
97 |
else if (!strcmp (t2, "pub/crd")) |
else if (!strcmp (t2, "pub/crd")) |
98 |
type = 2; |
type = 2; |
99 |
if (stristr (t, "ultimate") && utrust) |
if ((strstr (t, "Expired") || strstr (t, "Revoked")) && utrust) |
100 |
|
*utrust = -1; |
101 |
|
else if (stristr (t, "Ultimate") && utrust) |
102 |
*utrust = 1; |
*utrust = 1; |
103 |
return type; |
return type; |
104 |
} /* km_check_for_seckey */ |
} /* km_check_for_seckey */ |
105 |
|
|
106 |
|
|
107 |
int |
int |
108 |
km_check_if_protected( listview_ctrl_t lv, int pos ) |
km_check_if_protected (listview_ctrl_t lv, int pos) |
109 |
{ |
{ |
110 |
gpgme_key_t key; |
gpgme_key_t key; |
111 |
char keyid[32]; |
winpt_key_s k; |
112 |
|
|
113 |
listview_get_item_text( lv, pos, 1, keyid, sizeof keyid-1 ); |
key = (gpgme_key_t)listview_get_item2 (lv, pos); |
114 |
if( get_pubkey( keyid, &key ) ) |
if (!key) |
115 |
BUG( NULL ); |
return 1; /* assume yes */ |
116 |
return gpgme_key_get_ulong_attr( key, GPGME_ATTR_IS_PROTECTED, NULL, 0 ); |
winpt_get_pubkey (key->subkeys->keyid, &k); |
117 |
|
return k.is_protected; |
118 |
} /* km_check_if_protected */ |
} /* km_check_if_protected */ |
119 |
|
|
120 |
|
|
121 |
int |
int |
122 |
km_check_key_status (listview_ctrl_t lv, int pos) |
km_check_key_status (listview_ctrl_t lv, int pos) |
123 |
{ |
{ |
124 |
char t[128]; |
int flags = km_get_key_status (lv, pos); |
|
int i = 1; |
|
125 |
|
|
126 |
listview_get_item_text( lv, pos, 5, t, sizeof t - 1 ); |
if (flags & KM_FLAG_EXPIRED) { |
127 |
if( t[0] == '[' && t[1] == ']' ) |
msg_box (lv->ctrl, _("This key has expired!\n" |
128 |
return 1; |
"Key check failed."), _("Key Manager"), MB_ERR); |
129 |
for( i = 0; t[i] != ']'; i++ ) { |
return -1; |
130 |
if( t[i] == 'E' ) |
} |
131 |
msg_box(lv->ctrl, _("This key has expired!\n" |
else if (flags & KM_FLAG_REVOKED) { |
132 |
"Key check failed."), _("Key Manager"), MB_ERR ); |
msg_box (lv->ctrl, _("This key has been revoked by its owner!\n" |
133 |
else if( t[i] == 'R' ) |
"Key check failed."), _("Key Manager"), MB_ERR); |
134 |
msg_box(lv->ctrl, _("This key has been revoked by its owner!\n" |
return -1; |
|
"Key check failed."), _("Key Manager"), MB_ERR ); |
|
135 |
} |
} |
136 |
|
|
137 |
return 0; |
return 0; |
139 |
|
|
140 |
|
|
141 |
int |
int |
142 |
km_get_key_status( listview_ctrl_t lv, int pos ) |
km_get_key_status (listview_ctrl_t lv, int pos) |
143 |
{ |
{ |
144 |
char t[128]; |
gpgme_key_t key; |
145 |
int i, flags = 0; |
int flags = 0; |
146 |
|
|
147 |
if( pos == -1 ) |
if (pos == -1) |
148 |
return 0; |
return 0; |
149 |
listview_get_item_text( lv, pos, 5, t, sizeof t-1 ); |
key = (gpgme_key_t)listview_get_item2 (lv, pos); |
150 |
for( i = 0; t[i] != ']'; i++ ) { |
if (key == NULL) |
151 |
if( t[i] == 'E' ) |
return 0; |
152 |
flags |= KM_FLAG_EXPIRED; |
|
153 |
if( t[i] == 'R' ) |
if (key->expired) |
154 |
flags |= KM_FLAG_REVOKED; |
flags |= KM_FLAG_EXPIRED; |
155 |
if( t[i] == 'D' ) |
if (key->revoked) |
156 |
flags |= KM_FLAG_DISABLED; |
flags |= KM_FLAG_REVOKED; |
157 |
} |
if (key->disabled) |
158 |
|
flags |= KM_FLAG_DISABLED; |
159 |
return flags; |
return flags; |
160 |
} /* km_get_key_status */ |
} /* km_get_key_status */ |
161 |
|
|
162 |
|
|
163 |
|
/* Interface to enable or disable a key (@enable = 1 then enable). |
164 |
|
The key is retrieved from a list control @lv at the pos @pos. */ |
165 |
int |
int |
166 |
km_enable_disable_key (listview_ctrl_t lv, HWND dlg, int pos, int enable) |
km_enable_disable_key (listview_ctrl_t lv, HWND dlg, int pos, int enable) |
167 |
{ |
{ |
168 |
gpgme_ctx_t ctx; |
GpgKeyEdit *ke; |
|
gpgme_editkey_t ek; |
|
169 |
gpgme_error_t err; |
gpgme_error_t err; |
|
int edit_id; |
|
170 |
char keyid[32]; |
char keyid[32]; |
171 |
|
|
172 |
listview_get_item_text( lv, pos, 1, keyid, DIM (keyid)-1 ); |
listview_get_item_text (lv, pos, 1, keyid, DIM (keyid)-1); |
173 |
err = gpgme_editkey_new( &ek ); |
|
174 |
if( err ) |
ke = new GpgKeyEdit (keyid); |
175 |
BUG( NULL ); |
if (!ke) |
176 |
if( enable ) { |
BUG (NULL); |
177 |
gpgme_editkey_enable_set (ek); |
|
178 |
edit_id = GPGME_EDITKEY_ENABLE; |
if (enable) |
179 |
|
err = ke->enable (); |
180 |
|
else |
181 |
|
err = ke->disable (); |
182 |
|
if (!err) { |
183 |
|
show_msg (dlg, 1500, _("Key status changed.")); |
184 |
|
keycache_set_reload (1); /* XXX: set update flag */ |
185 |
} |
} |
186 |
else { |
else |
187 |
gpgme_editkey_disable_set (ek); |
msg_box (dlg, gpgme_strerror( err ), _("Key Manager"), MB_ERR); |
188 |
edit_id = GPGME_EDITKEY_DISABLE; |
delete ke; |
189 |
|
return err? WPTERR_GENERAL : 0; |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
/* Create a string that contain all keyids from |
195 |
|
the key list @rset separated by a space. */ |
196 |
|
char* |
197 |
|
gpg_keylist_to_pattern (gpgme_key_t *rset) |
198 |
|
{ |
199 |
|
int i, n=0; |
200 |
|
char *p; |
201 |
|
|
202 |
|
for (i=0; rset[i] != NULL; i++) |
203 |
|
n++; |
204 |
|
p = (char *)calloc (1, n*(8+1)+n); |
205 |
|
if (!p) |
206 |
|
return NULL; |
207 |
|
for (i=0; rset[i] != NULL; i++) { |
208 |
|
strcat (p, rset[i]->subkeys->keyid); |
209 |
|
strcat (p, " "); |
210 |
} |
} |
211 |
|
return p; |
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
|
/* Export the keys given in @rset to the clipboard. |
216 |
|
Return value: 0 on success. */ |
217 |
|
gpgme_error_t |
218 |
|
gpg_clip_export (gpgme_key_t *rset) |
219 |
|
{ |
220 |
|
gpgme_error_t err = 0; |
221 |
|
gpgme_ctx_t ctx = NULL; |
222 |
|
gpgme_data_t keydata = NULL; |
223 |
|
char *patt=NULL; |
224 |
|
|
225 |
err = gpgme_new (&ctx); |
err = gpgme_new (&ctx); |
226 |
if( err ) |
if (err) |
227 |
BUG( NULL ); |
return err; |
228 |
gpgme_set_edit_ctx (ctx, ek, edit_id); |
gpgme_set_armor (ctx, 1); |
229 |
err = gpgme_op_editkey (ctx, keyid); |
err = gpgme_data_new (&keydata); |
230 |
if( !err ) { |
if (err) |
231 |
show_msg( dlg, 1500, _("Key status changed.") ); |
goto leave; |
232 |
keycache_set_reload( 1 ); |
|
233 |
|
patt = gpg_keylist_to_pattern (rset); |
234 |
|
if (!patt) { |
235 |
|
err = gpg_error (GPG_ERR_ENOMEM); |
236 |
|
goto leave; |
237 |
} |
} |
|
else |
|
|
msg_box( dlg, gpgme_strerror( err ), _("Key Manager"), MB_ERR ); |
|
238 |
|
|
239 |
|
err = gpgme_op_export (ctx, patt, 0, keydata); |
240 |
|
if (err) |
241 |
|
goto leave; |
242 |
|
|
243 |
|
gpg_data_release_and_set_clipboard (keydata, 1); |
244 |
|
|
245 |
|
leave: |
246 |
|
if (patt) |
247 |
|
free (patt); |
248 |
gpgme_release (ctx); |
gpgme_release (ctx); |
249 |
gpgme_editkey_release (ek); |
return err; |
250 |
return err? WPTERR_GENERAL : 0; |
} |
|
} /* km_enable_disable_key */ |
|
251 |
|
|
252 |
|
|
253 |
|
/* Export the selected keys in @lv to the clipboard. */ |
254 |
int |
int |
255 |
km_clip_export (HWND dlg, listview_ctrl_t lv) |
km_clip_export (HWND dlg, listview_ctrl_t lv) |
256 |
{ |
{ |
257 |
gpgme_error_t err; |
gpgme_error_t err; |
258 |
gpgme_recipients_t rset; |
gpgme_key_t *rset; |
259 |
int rc, id = 0, n = 0; |
int rc, id = 0, n = 0; |
260 |
|
|
261 |
rset = keylist_enum_recipients (lv, KEYLIST_LIST); |
rset = keylist_enum_recipients (lv, KEYLIST_LIST, &n); |
|
n = gpgme_recipients_count (rset); |
|
262 |
if (!n) { |
if (!n) { |
263 |
msg_box (dlg, _("No key was selected for export."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("No key was selected for export."), _("Key Manager"), MB_ERR); |
264 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
265 |
goto leave; |
goto leave; |
266 |
} |
} |
267 |
|
|
268 |
err = gpgme_op_clip_export (rset); |
err = gpg_clip_export (rset); |
269 |
if (err) { |
if (err) { |
270 |
msg_box( dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
msg_box( dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
271 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
272 |
goto leave; |
goto leave; |
273 |
} |
} |
274 |
if (n == 1) { |
if (n == 1) { |
|
const char *s; |
|
275 |
char buf[256]; |
char buf[256]; |
276 |
s = gpgme_recipients_get_name (rset, 0); |
key_get_clip_info (rset[0]->subkeys->keyid, buf, 255); |
|
km_get_clip_info (s, buf, 255); |
|
277 |
set_clip_text2 (NULL, buf, strlen (buf), 0); |
set_clip_text2 (NULL, buf, strlen (buf), 0); |
278 |
} |
} |
279 |
|
|
280 |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
281 |
|
|
282 |
leave: |
leave: |
283 |
gpgme_recipients_release (rset); |
free (rset); |
284 |
return rc; |
return rc; |
285 |
} /* km_clip_export */ |
} /* km_clip_export */ |
286 |
|
|
287 |
|
|
288 |
|
/* Export the selected secret key from @lv into @fname. |
289 |
|
It is only allowed to export a single secret key. */ |
290 |
int |
int |
291 |
km_privkey_export( HWND dlg, listview_ctrl_t lv, const char *fname ) |
km_privkey_export (HWND dlg, listview_ctrl_t lv, const char *fname) |
292 |
{ |
{ |
293 |
gpgme_recipients_t rset; |
gpgme_key_t *rset; |
|
gpgme_data_t keydata; |
|
294 |
gpgme_error_t err; |
gpgme_error_t err; |
295 |
gpgme_ctx_t ctx; |
int n = 0; |
|
size_t n = 0; |
|
296 |
|
|
297 |
rset = keylist_enum_recipients( lv, KEYLIST_LIST ); |
rset = keylist_enum_recipients (lv, KEYLIST_LIST, &n); |
298 |
n = gpgme_recipients_count( rset ); |
if (!n) { |
|
if( !n ) { |
|
299 |
msg_box( dlg, _("No key was selected for export."), _("Key Manager"), MB_ERR ); |
msg_box( dlg, _("No key was selected for export."), _("Key Manager"), MB_ERR ); |
300 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
301 |
} |
} |
302 |
if( n > 1 ) { |
if (n > 1) { |
303 |
msg_box( dlg, _("Only one secret key can be exported."), _("Key Manager"), MB_ERR ); |
msg_box (dlg, _("Only one secret key can be exported."), _("Key Manager"), MB_ERR); |
304 |
|
free (rset); |
305 |
return 0; /* we checked this before, so we just quit */ |
return 0; /* we checked this before, so we just quit */ |
306 |
} |
} |
|
err = gpgme_data_new( &keydata ); |
|
|
if( err ) |
|
|
BUG( dlg ); |
|
|
err = gpgme_new( &ctx ); |
|
|
if( err ) |
|
|
BUG( dlg ); |
|
|
gpgme_control( ctx, GPGME_CTRL_ARMOR, 1 ); |
|
|
gpgme_control( ctx, GPGME_CTRL_WITH_SECRET_KEY, 1 ); |
|
307 |
|
|
308 |
err = gpgme_op_export( ctx, rset, keydata ); |
err = gpg_export_seckey (rset[0]->subkeys->keyid, fname); |
309 |
if( err ) { |
if (err) |
310 |
msg_box( dlg, gpgme_strerror( err ), _("Key Manager"), MB_ERR ); |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
311 |
goto leave; |
else |
312 |
} |
log_box (_("Key Manager"), MB_OK, |
313 |
|
_("Secret key successfully saved in '%s'."), fname); |
314 |
|
|
|
log_box( _("Key Manager"), MB_OK, |
|
|
_("Secret key successfully saved in '%s'."), fname ); |
|
|
|
|
|
leave: |
|
|
err = gpgme_data_release_and_set_file( keydata, fname ); |
|
|
if( err ) |
|
|
log_box( _("Key Manager"), MB_OK, |
|
|
_("Could not save data to '%s'."), fname ); |
|
|
gpgme_release( ctx ); |
|
315 |
|
|
316 |
return (int)err; |
free (rset); |
317 |
} /* km_privkey_export */ |
return err? WPTERR_GENERAL : 0; |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
int |
int |
322 |
km_file_export (HWND dlg, listview_ctrl_t lv, const char * fname) |
km_file_export (HWND dlg, listview_ctrl_t lv, const char * fname) |
323 |
{ |
{ |
324 |
gpgme_recipients_t rset; |
gpgme_key_t *rset; |
325 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
326 |
gpgme_error_t err; |
gpgme_error_t err; |
327 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
328 |
|
char *patt; |
329 |
|
int n; |
330 |
|
|
331 |
rset = keylist_enum_recipients( lv, KEYLIST_LIST ); |
rset = keylist_enum_recipients( lv, KEYLIST_LIST, &n ); |
332 |
if( !gpgme_recipients_count( rset ) ) { |
if (!n) { |
333 |
msg_box( dlg, _("No key was selected for export."), _("Key Manager"), MB_ERR ); |
msg_box( dlg, _("No key was selected for export."), _("Key Manager"), MB_ERR ); |
334 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
335 |
} |
} |
336 |
|
|
337 |
err = gpgme_data_new( &keydata ); |
err = gpgme_data_new (&keydata); |
338 |
if( err ) |
if( err ) |
339 |
BUG( dlg ); |
BUG( dlg ); |
340 |
err = gpgme_new( &ctx ); |
err = gpgme_new (&ctx); |
341 |
if( err ) |
if( err ) |
342 |
BUG( dlg ); |
BUG( dlg ); |
343 |
gpgme_control( ctx, GPGME_CTRL_ARMOR, 1 ); |
gpgme_set_armor (ctx, 1); |
344 |
gpgme_set_comment (ctx, "Generated by WinPT "PGM_VERSION); |
|
345 |
|
/*gpgme_set_comment (ctx, "Generated by WinPT "PGM_VERSION);*/ |
346 |
|
patt = gpg_keylist_to_pattern (rset); |
347 |
|
|
348 |
err = gpgme_op_export( ctx, rset, keydata ); |
err = gpgme_op_export( ctx, patt, 0, keydata); |
349 |
if( err ) { |
if( err ) { |
350 |
msg_box( dlg, gpgme_strerror( err ), _("Key Manager"), MB_ERR ); |
msg_box( dlg, gpgme_strerror( err ), _("Key Manager"), MB_ERR ); |
351 |
goto leave; |
goto leave; |
355 |
_("Key(s) successfully saved in '%s'."), fname ); |
_("Key(s) successfully saved in '%s'."), fname ); |
356 |
|
|
357 |
leave: |
leave: |
358 |
err = gpgme_data_release_and_set_file( keydata, fname ); |
err = gpg_data_release_and_set_file( keydata, fname ); |
359 |
if( err ) |
if (err) |
360 |
log_box( _("Key Manager"), MB_OK, |
log_box (_("Key Manager"), MB_OK, |
361 |
_("Could not save data to '%s'."), fname ); |
_("Could not save data to '%s'."), fname); |
362 |
gpgme_release( ctx ); |
gpgme_release (ctx); |
363 |
|
free (patt); |
364 |
return (int)err; |
return (int)err; |
365 |
} /* km_file_export */ |
} /* km_file_export */ |
366 |
|
|
371 |
gpgme_data_t inp, plain; |
gpgme_data_t inp, plain; |
372 |
gpgme_error_t err; |
gpgme_error_t err; |
373 |
|
|
374 |
err = gpgme_data_new_from_clipboard (&inp); |
err = gpg_data_new_from_clipboard (&inp, 0); |
375 |
if (err) { |
if (err) { |
376 |
msg_box (NULL, gpgme_strerror( err ), _("Key Manager"), MB_ERR); |
msg_box (NULL, gpgme_strerror( err ), _("Key Manager"), MB_ERR); |
377 |
return -1; |
return -1; |
378 |
} |
} |
379 |
gpgme_data_extract_plaintext (inp, &plain); |
gpg_data_extract_plaintext (inp, &plain); |
380 |
|
gpg_data_release_and_set_clipboard (plain, 0); |
381 |
gpgme_data_release (inp); |
gpgme_data_release (inp); |
|
gpgme_data_release_and_set_clipboard (plain); |
|
382 |
|
|
383 |
return 0; |
return 0; |
384 |
} /* extract_dash_escaped_key */ |
} /* extract_dash_escaped_key */ |
403 |
msg_box( dlg, _("No valid OpenPGP data found."), _("Key Manager"), MB_ERR ); |
msg_box( dlg, _("No valid OpenPGP data found."), _("Key Manager"), MB_ERR ); |
404 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
405 |
} |
} |
406 |
if( !(pgptype & GPGME_PGP_PUBKEY) && !(pgptype & GPGME_PGP_SECKEY) ) { |
if( !(pgptype & PGP_PUBKEY) && !(pgptype & PGP_SECKEY) ) { |
407 |
msg_box( dlg, _("No valid OpenPGP keys found."), _("Key Manager"), MB_ERR ); |
msg_box( dlg, _("No valid OpenPGP keys found."), _("Key Manager"), MB_ERR ); |
408 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
409 |
} |
} |
410 |
if( pgptype & GPGME_PGP_DASH_ESCAPED ) { |
if( pgptype & PGP_DASH_ESCAPED ) { |
411 |
id = msg_box( dlg, _("The key you want to import is dash escacped.\n" |
id = msg_box( dlg, _("The key you want to import is dash escacped.\n" |
412 |
"Do you want to extract the key?"), |
"Do you want to extract the key?"), |
413 |
_("Key Manager"), MB_YESNO ); |
_("Key Manager"), MB_YESNO ); |
414 |
if( id == IDYES ) |
if (id == IDYES) |
415 |
extract_dash_escaped_key( ); |
extract_dash_escaped_key (); |
416 |
else |
else |
417 |
msg_box( dlg, _("Cannot import dash escaped OpenPGP keys."), _("Key Manager"), MB_INFO ); |
msg_box( dlg, _("Cannot import dash escaped OpenPGP keys."), _("Key Manager"), MB_INFO ); |
418 |
} |
} |
440 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
441 |
} |
} |
442 |
|
|
443 |
GetTempPath (499, tmpdir); |
GetTempPath (sizeof (tmpdir)-1, tmpdir); |
444 |
p = make_filename (tmpdir, "file_http", "tmp"); |
p = make_filename (tmpdir, "winpt_file_http", "tmp"); |
445 |
if (!p) |
if (!p) |
446 |
BUG (0); |
BUG (0); |
447 |
fp = fopen (p, "wb"); |
fp = fopen (p, "wb"); |
460 |
fclose (fp); |
fclose (fp); |
461 |
if (rc) { |
if (rc) { |
462 |
free_if_alloc (p); |
free_if_alloc (p); |
463 |
msg_box (dlg, http_strerror (rc), _("Key Import HTTP"), MB_ERR); |
msg_box (dlg, winpt_strerror (rc), _("Key Import HTTP"), MB_ERR); |
464 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
465 |
} |
} |
466 |
km_file_import (dlg, p); |
km_file_import (dlg, p); |
467 |
|
// XXX: delete file |
468 |
free_if_alloc (p); |
free_if_alloc (p); |
469 |
return 0; |
return 0; |
470 |
} |
} |
471 |
|
|
472 |
|
|
473 |
|
/* Import a key from the given file @fname. |
474 |
|
On success an import statistics dialog is shown. */ |
475 |
int |
int |
476 |
km_file_import( HWND dlg, const char * fname ) |
km_file_import (HWND dlg, const char *fname) |
477 |
{ |
{ |
478 |
gpgme_data_t keydata = NULL; |
gpgme_data_t keydata = NULL; |
479 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
480 |
gpgme_error_t err; |
gpgme_error_t err; |
481 |
|
gpgme_key_t *keys = NULL; |
482 |
fm_state_s fm_stat; |
fm_state_s fm_stat; |
483 |
int import_res[14]; |
gpgme_import_result_t res; |
484 |
|
|
485 |
memset( &fm_stat, 0, sizeof fm_stat ); |
memset (&fm_stat, 0, sizeof (fm_stat)); |
486 |
fm_stat.opaque = m_strdup( fname ); |
fm_stat.opaque = m_strdup (fname); |
487 |
|
|
488 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
489 |
file_import_dlg_proc, (LPARAM)&fm_stat, |
file_import_dlg_proc, (LPARAM)&fm_stat, |
490 |
_("File Import"), IDS_WINPT_IMPORT ); |
_("File Import"), IDS_WINPT_IMPORT); |
491 |
if( fm_stat.cancel == 1 ) |
if (fm_stat.cancel == 1 ) { |
492 |
|
free_if_alloc (fm_stat.opaque); |
493 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
494 |
|
} |
495 |
|
|
496 |
err = gpgme_new( &ctx ); |
err = gpgme_new( &ctx ); |
497 |
if( err ) |
if( err ) |
498 |
BUG( dlg ); |
BUG( dlg ); |
499 |
gpgme_control( ctx, GPGME_CTRL_FORCETRUST, 1 ); |
/*XXX gpgme_control( ctx, GPGME_CTRL_FORCETRUST, 1 );*/ |
500 |
err = gpgme_data_new_from_file (&keydata, fname); |
err = gpgme_data_new_from_file (&keydata, fname, 1); |
501 |
if( err ) { |
if( err ) { |
502 |
msg_box( dlg, _("Could not read key-data from file."), _("Key Manager"), MB_ERR ); |
msg_box( dlg, _("Could not read key-data from file."), _("Key Manager"), MB_ERR ); |
503 |
goto leave; |
goto leave; |
504 |
} |
} |
505 |
|
|
506 |
err = gpgme_op_import( ctx, NULL, keydata ); |
err = gpgme_op_import (ctx, keydata); |
507 |
if( err ) { |
if (err) { |
508 |
msg_box( dlg, gpgme_strerror( err ), _("Key Manager"), MB_ERR ); |
msg_box( dlg, gpgme_strerror( err ), _("Key Manager"), MB_ERR ); |
509 |
goto leave; |
goto leave; |
510 |
} |
} |
511 |
|
|
512 |
|
res = gpgme_op_import_result (ctx); |
513 |
|
|
514 |
gpgme_get_import_status( ctx, import_res, NULL ); |
print_import_status (res); |
515 |
print_import_status( import_res, fm_stat.implist_revcert ); |
if (res->no_user_id > 0) { |
516 |
if( import_res[GPGME_IMPSTAT_NOSELFSIG] > 0 ) { |
msg_box (dlg, _("Key without a self signature was dectected!\n" |
|
msg_box( dlg, _("Key without a self signature was dectected!\n" |
|
517 |
"(This key is NOT usable for encryption, etc)\n" |
"(This key is NOT usable for encryption, etc)\n" |
518 |
"\n" |
"\n" |
519 |
"Cannot import these key(s)!"), _("Import"), MB_INFO ); |
"Cannot import these key(s)!"), _("Import"), MB_INFO); |
520 |
} |
} |
521 |
|
|
522 |
leave: |
leave: |
523 |
gpgme_data_release( keydata ); |
free (keys); |
524 |
gpgme_release( ctx ); |
gpgme_data_release (keydata); |
525 |
free_if_alloc( fm_stat.opaque ); |
gpgme_release (ctx); |
526 |
|
free_if_alloc (fm_stat.opaque); |
527 |
return (int)err; |
return (int)err; |
528 |
} /* km_file_import */ |
} |
529 |
|
|
530 |
|
|
531 |
|
/* Mark the keys in @rset as deleted in the keycache. */ |
532 |
static void |
static void |
533 |
delete_keys_from_cache (gpgme_recipients_t rset) |
delete_keys_from_cache (gpgme_key_t *rset) |
534 |
{ |
{ |
535 |
gpgme_keycache_t pub = keycache_get_ctx (1); |
gpgme_keycache_t pub = keycache_get_ctx (1); |
536 |
void * ctx =NULL; |
int i=0; |
|
const char * s; |
|
537 |
|
|
538 |
gpgme_recipients_enum_open (rset, &ctx); |
while (rset[i++] != NULL) |
539 |
while ((s = gpgme_recipients_enum_read (rset, &ctx))) |
gpgme_keycache_delete_key (pub, rset[i]->subkeys->keyid); |
540 |
gpgme_keycache_delete_key (pub, s); |
} |
|
gpgme_recipients_enum_close (rset, &ctx); |
|
|
} /* delete_keys_from_cache */ |
|
541 |
|
|
542 |
|
|
543 |
int |
int |
544 |
km_delete_keys (listview_ctrl_t lv, HWND dlg) |
km_delete_keys (listview_ctrl_t lv, HWND dlg) |
545 |
{ |
{ |
546 |
gpgme_error_t err; |
gpgme_error_t err; |
547 |
gpgme_recipients_t rset; |
gpgme_ctx_t ctx; |
548 |
|
gpgme_key_t *rset, k; |
549 |
char keyid[32], uid[256], date[64], keylen[64]; |
char keyid[32], uid[256], date[64], keylen[64]; |
550 |
int with_seckey, seckey_type=0; |
int with_seckey=0, seckey_type=0, confirm=0; |
551 |
int i, rc, n; |
int i, rc, n, k_pos=0; |
552 |
|
|
553 |
if( listview_get_curr_pos( lv ) == -1 ) { |
if (listview_get_curr_pos (lv) == -1) { |
554 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
555 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
556 |
} |
} |
557 |
|
|
558 |
err = gpgme_recipients_new (&rset); |
if (listview_count_items (lv, 1) > 8) { |
559 |
if (err) |
i = msg_box (NULL, _("Do you really want to confirm each key?"), _("Delete Confirmation"), MB_YESNOCANCEL|MB_ICONQUESTION); |
560 |
BUG (0); |
if (i == IDCANCEL) |
561 |
|
return 0; |
562 |
|
if (i != IDNO) |
563 |
|
confirm = 1; |
564 |
|
} |
565 |
|
else |
566 |
|
confirm = 1; |
567 |
|
|
568 |
n = listview_count_items (lv, 0); |
n = listview_count_items (lv, 0); |
569 |
|
rset = (gpgme_key_t *)calloc (n+1, sizeof (gpgme_key_t)); |
570 |
|
if (!rset) |
571 |
|
BUG (NULL); |
572 |
for( i = 0; i < n; i++ ) { |
for( i = 0; i < n; i++ ) { |
573 |
if( listview_get_item_state( lv, i ) ) { |
if( listview_get_item_state( lv, i ) ) { |
574 |
listview_get_item_text( lv, i, 0, uid, sizeof uid - 1 ); |
listview_get_item_text( lv, i, 0, uid, sizeof uid - 1 ); |
575 |
listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 ); |
listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 ); |
576 |
listview_get_item_text( lv, i, 3, keylen, sizeof keylen - 1 ); |
listview_get_item_text( lv, i, 3, keylen, sizeof keylen - 1 ); |
577 |
listview_get_item_text( lv, i, 7, date, sizeof date - 1 ); |
listview_get_item_text( lv, i, 7, date, sizeof date - 1 ); |
578 |
seckey_type = km_check_for_seckey( lv, i, NULL ); |
seckey_type = km_check_for_seckey (lv, i, NULL); |
579 |
if( !seckey_type ) { |
if (confirm && !seckey_type) { |
580 |
rc = log_box( _("Key Manager"), MB_YESNO|MB_ICONWARNING, |
rc = log_box( _("Key Manager"), MB_YESNO|MB_ICONWARNING, |
581 |
_("Do you really want to delete this key?\n\n" |
_("Do you really want to delete this key?\n\n" |
582 |
"pub %s %s %s\n" |
"pub %s %s %s\n" |
583 |
" \"%s\""), keylen, keyid, date, uid ); |
" \"%s\""), keylen, keyid, date, uid ); |
584 |
if( rc == IDYES ) |
if (rc == IDYES) { |
585 |
gpgme_recipients_add_name( rset, keyid ); |
get_pubkey (keyid, &k); |
586 |
|
rset[k_pos++] = k; |
587 |
|
} |
588 |
with_seckey = 0; |
with_seckey = 0; |
589 |
} |
} |
590 |
else { |
else if (confirm) { |
591 |
rc = log_box( _("Key Manager"), MB_YESNO|MB_ICONWARNING, |
rc = log_box( _("Key Manager"), MB_YESNO|MB_ICONWARNING, |
592 |
_("Do you really want to delete this KEY PAIR?\n\n" |
_("Do you really want to delete this KEY PAIR?\n\n" |
593 |
"Please remember that you are not able to decrypt\n" |
"Please remember that you are not able to decrypt\n" |
600 |
msg_box( dlg, _("The actual secret key is stored on a smartcard.\n" |
msg_box( dlg, _("The actual secret key is stored on a smartcard.\n" |
601 |
"Only the public key and the secret key \n" |
"Only the public key and the secret key \n" |
602 |
"placeholder will be deleted.\n"), _("Key Manager"), MB_OK ); |
"placeholder will be deleted.\n"), _("Key Manager"), MB_OK ); |
603 |
gpgme_recipients_add_name( rset, keyid ); |
get_pubkey (keyid, &k); |
604 |
|
rset[k_pos++] = k; |
605 |
} |
} |
606 |
with_seckey = 1; |
with_seckey = 1; |
607 |
} |
} |
608 |
|
else { |
609 |
|
with_seckey = 1; |
610 |
|
get_pubkey (keyid, &k); |
611 |
|
rset[k_pos++] = k; |
612 |
|
} |
613 |
} |
} |
614 |
} |
} |
615 |
|
|
616 |
if (!gpgme_recipients_count (rset)) { |
if (k_pos == 0) { |
617 |
gpgme_recipients_release (rset); |
free (rset); |
618 |
return 0; |
return 0; |
619 |
} |
} |
620 |
|
|
621 |
err = gpgme_op_delete_keys (rset, with_seckey); |
err = gpgme_new (&ctx); |
622 |
if (err) { |
if (err) |
623 |
if (err == GPGME_Invalid_Key) |
BUG (NULL); |
624 |
msg_box (dlg, _("No such key."), _("Key Manager"), MB_INFO); |
for (i=0; i < n; i++) { |
625 |
else if (err == GPGME_Conflict) |
err = gpgme_op_delete (ctx, rset[i], with_seckey); |
626 |
msg_box (dlg, _("Must delete secret key first."), _("Key Manager"), MB_INFO); |
if (err) |
627 |
else |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
628 |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
else |
629 |
return FALSE; |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
630 |
} |
} |
631 |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
gpgme_release (ctx); |
632 |
listview_del_items (lv); |
listview_del_items (lv); |
|
if (keyring_check_last_access ()) |
|
|
keycache_set_reload (1); |
|
633 |
delete_keys_from_cache (rset); |
delete_keys_from_cache (rset); |
634 |
gpgme_recipients_release (rset); |
free (rset); |
635 |
|
|
636 |
return (int)err; |
return (int)err; |
637 |
} /* km_delete_keys */ |
} /* km_delete_keys */ |
668 |
int |
int |
669 |
km_send_to_mail_recipient( listview_ctrl_t lv, HWND dlg ) |
km_send_to_mail_recipient( listview_ctrl_t lv, HWND dlg ) |
670 |
{ |
{ |
671 |
|
#if 0 /*FIXME*/ |
672 |
gpgme_key_t key; |
gpgme_key_t key; |
673 |
gpgme_ctx_t ctx=NULL; |
gpgme_ctx_t ctx=NULL; |
674 |
gpgme_recipients_t rset=NULL; |
gpgme_recipients_t rset=NULL; |
689 |
listview_get_item_text( lv, pos, 1, keyid, sizeof keyid-1 ); |
listview_get_item_text( lv, pos, 1, keyid, sizeof keyid-1 ); |
690 |
if( get_pubkey( keyid, &key ) ) |
if( get_pubkey( keyid, &key ) ) |
691 |
BUG( NULL ); |
BUG( NULL ); |
692 |
s = gpgme_key_get_string_attr( key, GPGME_ATTR_NAME, NULL, 0 ); |
s = key->uids->name; |
693 |
GetTempPath (sizeof tmp-1, tmp); |
GetTempPath (sizeof tmp-1, tmp); |
694 |
strncat (tmp, s, sizeof tmp-200); |
strncat (tmp, s, sizeof tmp-200); |
695 |
strncat (tmp, ".asc", sizeof tmp-200); |
strncat (tmp, ".asc", sizeof tmp-200); |
701 |
if( !rc ) |
if( !rc ) |
702 |
rc = gpgme_new( &ctx ); |
rc = gpgme_new( &ctx ); |
703 |
if( !rc ) { |
if( !rc ) { |
704 |
gpgme_control( ctx, GPGME_CTRL_ARMOR, 1 ); |
gpgme_set_armor (ctx, 1); |
705 |
rc = gpgme_op_file_export( ctx, rset, p ); |
rc = gpgme_op_file_export( ctx, rset, p ); |
706 |
} |
} |
707 |
if( rc ) |
if( rc ) |
712 |
gpgme_recipients_release( rset ); |
gpgme_recipients_release( rset ); |
713 |
gpgme_release( ctx ); |
gpgme_release( ctx ); |
714 |
return rc; |
return rc; |
715 |
|
#endif |
716 |
|
return 0; |
717 |
} |
} |
718 |
|
|
719 |
|
|
770 |
|
|
771 |
|
|
772 |
void |
void |
773 |
km_set_clip_info( const char *uid ) |
km_set_clip_info (const char *uid) |
774 |
{ |
{ |
775 |
char buf[256]; |
char buf[256]; |
776 |
|
|
777 |
km_get_clip_info (uid, buf, 255); |
key_get_clip_info (uid, buf, 255); |
778 |
set_clip_text( NULL, buf, strlen( buf ) ); |
set_clip_text (NULL, buf, strlen (buf)); |
779 |
} /* km_set_clip_info */ |
} /* km_set_clip_info */ |
780 |
|
|
781 |
|
|
782 |
|
|
783 |
|
/* Return TRUE if the key in the list @lv at pos @pos is an |
784 |
|
old version 3 key. */ |
785 |
int |
int |
786 |
km_key_is_v3 (listview_ctrl_t lv, int pos) |
km_key_is_v3 (listview_ctrl_t lv, int pos) |
787 |
{ |
{ |
791 |
listview_get_item_text (lv, pos, 1, keyid, sizeof keyid-1); |
listview_get_item_text (lv, pos, 1, keyid, sizeof keyid-1); |
792 |
if (get_pubkey (keyid, &pk)) |
if (get_pubkey (keyid, &pk)) |
793 |
BUG (NULL); |
BUG (NULL); |
794 |
return gpgme_key_get_ulong_attr (pk, GPGME_ATTR_VERSION, NULL, 0); |
if (strlen (pk->subkeys->fpr) == 32 && |
795 |
} /* km_key_is_v3 */ |
pk->subkeys->pubkey_algo == GPGME_PK_RSA) |
796 |
|
return -1; |
797 |
|
return 0; |
798 |
|
} |
799 |
|
|
800 |
|
|
801 |
void |
void |
802 |
km_update_default_key_str (HWND dlg, int * ret_len) |
km_update_default_key_str (HWND dlg) |
803 |
{ |
{ |
804 |
char * keyid, defkeyinf[512]; |
char * keyid, defkeyinf[512]; |
805 |
const char * fmt; |
const char * fmt; |
812 |
fmt = _("Default Key: %s"); |
fmt = _("Default Key: %s"); |
813 |
else |
else |
814 |
fmt = _("Default Key: 0x%s"); |
fmt = _("Default Key: 0x%s"); |
815 |
_snprintf( defkeyinf, sizeof defkeyinf - 1, fmt, keyid ); |
_snprintf (defkeyinf, sizeof defkeyinf - 1, fmt, keyid); |
816 |
SetWindowText( dlg, defkeyinf ); |
SendMessage (dlg, SB_SETTEXT, 0, (LPARAM)defkeyinf); |
817 |
*ret_len = strlen( defkeyinf ); |
free_if_alloc (keyid); |
|
free_if_alloc( keyid ); |
|
818 |
} /* km_return_default_key_str */ |
} /* km_return_default_key_str */ |
819 |
|
|
820 |
|
|
821 |
void |
void |
822 |
km_complete_status_bar( HWND sb, listview_ctrl_t lv, int startpos ) |
km_complete_status_bar (HWND sb, listview_ctrl_t lv) |
823 |
{ |
{ |
824 |
char text[384]; |
char txt_sec[128], txt_pub[128]; |
825 |
int nkeys = 0, nsec = 0, i; |
int nkeys = 0, nsec = 0, i; |
826 |
|
|
827 |
GetWindowText( sb, text, sizeof text -1 ); |
nkeys = listview_count_items (lv, 0); |
828 |
nkeys = listview_count_items( lv, 0 ); |
for (i = 0; i < nkeys; i++) { |
829 |
for( i = 0; i < nkeys; i++ ) { |
if (km_check_for_seckey (lv, i, NULL)) |
|
if( km_check_for_seckey( lv, i, NULL ) ) |
|
830 |
nsec++; |
nsec++; |
831 |
} |
} |
832 |
_snprintf( text+startpos, sizeof text-1, " %d keys (%d secret keys)", nkeys, nsec ); |
_snprintf (txt_sec, sizeof (txt_sec)-1, "%d secret keys", nsec); |
833 |
SetWindowText( sb, text ); |
_snprintf (txt_pub, sizeof (txt_pub)-1, "%d keys", nkeys); |
834 |
|
SendMessage (sb, SB_SETTEXT, 1, (LPARAM)txt_sec); |
835 |
|
SendMessage (sb, SB_SETTEXT, 2, (LPARAM)txt_pub); |
836 |
} /* km_complete_status_bar */ |
} /* km_complete_status_bar */ |
837 |
|
|
838 |
|
|
839 |
void |
|
840 |
|
int |
841 |
km_set_implicit_trust (HWND dlg, listview_ctrl_t lv, int pos) |
km_set_implicit_trust (HWND dlg, listview_ctrl_t lv, int pos) |
842 |
{ |
{ |
843 |
gpgme_error_t err; |
GpgKeyEdit *ke; |
844 |
gpgme_ctx_t ctx; |
gpgme_error_t err; |
|
gpgme_editkey_t ek; |
|
845 |
char keyid[32]; |
char keyid[32]; |
846 |
|
|
847 |
listview_get_item_text (lv, pos, 1, keyid, 31); |
listview_get_item_text (lv, pos, 1, keyid, 31); |
848 |
err = gpgme_new (&ctx); |
|
849 |
if (err) |
ke = new GpgKeyEdit (keyid); |
850 |
BUG (0); |
if (!ke) |
|
err = gpgme_editkey_new (&ek); |
|
|
if (err) |
|
851 |
BUG (0); |
BUG (0); |
|
gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_TRUST); |
|
|
gpgme_editkey_trust_set (ek, 5); |
|
852 |
|
|
853 |
err = gpgme_op_editkey (ctx, keyid); |
err = ke->setTrust (GPGME_VALIDITY_ULTIMATE); |
854 |
if (err) |
if (err) |
855 |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
856 |
else { |
else |
857 |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
|
keycache_set_reload (1); |
|
|
} |
|
858 |
|
|
859 |
gpgme_release (ctx); |
delete ke; |
860 |
gpgme_editkey_release (ek); |
return (int)err; |
861 |
} |
} |
862 |
|
|
863 |
|
|
864 |
|
void |
865 |
|
km_find_key (HWND dlg, listview_ctrl_t lv) |
866 |
|
{ |
867 |
|
int oldpos = listview_get_curr_pos (lv); |
868 |
|
int n; |
869 |
|
char *name = get_input_dialog (dlg, "Search", "Search for:"); |
870 |
|
if (name == NULL) |
871 |
|
return; |
872 |
|
if (oldpos < 0) |
873 |
|
oldpos = 0; |
874 |
|
n = listview_find (lv, name); |
875 |
|
if (n != -1) { |
876 |
|
listview_select_one (lv, n); |
877 |
|
listview_scroll (lv, oldpos, n); |
878 |
|
} |
879 |
|
else { |
880 |
|
const char *s = _("String pattern \"%s\" not found."); |
881 |
|
char *p = new char[strlen (s) + strlen (name) + 2]; |
882 |
|
if (!p) |
883 |
|
BUG (0); |
884 |
|
sprintf (p, s, name); |
885 |
|
msg_box (dlg, p, _("Key Manager"), MB_INFO); |
886 |
|
free_if_alloc (p); |
887 |
|
} |
888 |
|
free_if_alloc (name); |
889 |
|
} |
890 |
|
|
891 |
|
|
892 |
|
|
893 |
|
void |
894 |
|
km_dump_key (gpgme_key_t key) |
895 |
|
{ |
896 |
|
#if _DEBUG |
897 |
|
log_box ("DEBUG", MB_OK, |
898 |
|
"%d %d %s %d\n%s", key->subkeys->length, |
899 |
|
key->subkeys->pubkey_algo, |
900 |
|
key->subkeys->keyid, |
901 |
|
key->subkeys->timestamp, |
902 |
|
key->uids->uid); |
903 |
|
#endif |
904 |
|
} |
905 |
|
|
906 |
|
#if 0 |
907 |
gpg_optfile_t |
gpg_optfile_t |
908 |
km_groupdb_open( void ) |
km_groupdb_open( void ) |
909 |
{ |
{ |
949 |
for( mbr = grp->list; mbr; mbr = mbr->next ) { |
for( mbr = grp->list; mbr; mbr = mbr->next ) { |
950 |
if( gpgme_keycache_find_key( kc, mbr->name, 0, &pk ) ) |
if( gpgme_keycache_find_key( kc, mbr->name, 0, &pk ) ) |
951 |
BUG( NULL ); |
BUG( NULL ); |
952 |
n = gpgme_key_count_items( pk, GPGME_ATTR_USERID ); |
n = count_userids (pk); |
953 |
while( n-- ) { |
while( n-- ) { |
954 |
const char * s = gpgme_key_get_string_attr( pk, GPGME_ATTR_USERID, NULL, n ); |
gpgme_user_id_t u = get_nth_userid (pk, n); |
955 |
|
const char * s = u->uid; |
956 |
if( s && stristr( s, mbr->name ) |
if( s && stristr( s, mbr->name ) |
957 |
&& gpgme_key_get_ulong_attr( pk, GPGME_ATTR_VALIDITY, NULL, n ) < 3 ) |
&& u->validity < 3 ) |
958 |
no_trust++; |
no_trust++; |
959 |
} |
} |
960 |
} |
} |
1161 |
else |
else |
1162 |
return km_groups_del_main( gc ); |
return km_groups_del_main( gc ); |
1163 |
} /* km_groups_del */ |
} /* km_groups_del */ |
1164 |
|
#endif |