1 |
/* wptKeyManager.cpp - Handy functions for the Key Manager dialog |
/* wptKeyManager.cpp - Handy functions for the Key Manager dialog |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-2006 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
18 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
*/ |
*/ |
21 |
|
|
22 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
23 |
#include <config.h> |
#include <config.h> |
24 |
#endif |
#endif |
47 |
#include "wptKeyEdit.h" |
#include "wptKeyEdit.h" |
48 |
#include "wptImport.h" |
#include "wptImport.h" |
49 |
#include "wptCrypto.h" |
#include "wptCrypto.h" |
50 |
|
#include "wptUTF8.h" |
51 |
|
#include "wptGPGME.h" |
52 |
|
|
53 |
|
|
54 |
|
/* Macros to change the cursor */ |
55 |
|
#define op_begin() SetCursor (LoadCursor (NULL, IDC_WAIT)) |
56 |
|
#define op_end() SetCursor (LoadCursor (NULL, IDC_ARROW)) |
57 |
|
|
58 |
|
|
59 |
/* Return a user friendly key representation in @buf of |
/* Return a user friendly key representation in @buf of |
62 |
key_get_clip_info (const char *keyid, char *buf, size_t buflen) |
key_get_clip_info (const char *keyid, char *buf, size_t buflen) |
63 |
{ |
{ |
64 |
gpgme_key_t pk; |
gpgme_key_t pk; |
65 |
|
char *uid; |
66 |
|
|
67 |
if (get_pubkey (keyid, &pk)) |
if (get_pubkey (keyid, &pk)) |
68 |
BUG (NULL); |
BUG (NULL); |
69 |
|
uid = utf8_to_wincp2 (pk->uids->uid); |
70 |
_snprintf (buf, buflen-1, |
_snprintf (buf, buflen-1, |
71 |
"pub %04d%s/%s %s %s\r\n" |
"pub %04d%s/%s %s %s\r\n" |
72 |
" Primary key fingerprint: %s\r\n", |
" Primary key fingerprint: %s\r\n", |
73 |
pk->subkeys->length, |
pk->subkeys->length, |
74 |
get_key_pubalgo (pk->subkeys->pubkey_algo), |
get_key_pubalgo2 (pk->subkeys->pubkey_algo), |
75 |
pk->subkeys->keyid+8, |
pk->subkeys->keyid+8, |
76 |
get_key_created (pk->subkeys->timestamp), |
get_key_created (pk->subkeys->timestamp), |
77 |
pk->uids->uid, |
uid, |
78 |
get_key_fpr (pk)); |
get_key_fpr (pk)); |
79 |
|
safe_free (uid); |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
/* Return a general description of the key @key. */ |
84 |
|
char* |
85 |
|
km_key_get_info (gpgme_key_t pk, int is_sec) |
86 |
|
{ |
87 |
|
const char *fmt = "%s %04d%s/0x%s %s\n \"%s\""; |
88 |
|
char *p, *uid; |
89 |
|
int n; |
90 |
|
|
91 |
|
n = strlen (fmt) + 8 + 2 + 16 + 12 + strlen (pk->uids->uid) + 32; |
92 |
|
p = new char[n+1]; |
93 |
|
if (!p) |
94 |
|
BUG (NULL); |
95 |
|
uid = utf8_to_wincp2 (pk->uids->uid); |
96 |
|
_snprintf (p, n, fmt, is_sec? "sec" : "pub", |
97 |
|
pk->subkeys->length, |
98 |
|
get_key_pubalgo2 (pk->subkeys->pubkey_algo), |
99 |
|
pk->subkeys->keyid+8, get_key_created (pk->subkeys->timestamp), |
100 |
|
uid); |
101 |
|
safe_free (uid); |
102 |
|
return p; |
103 |
} |
} |
104 |
|
|
105 |
|
|
129 |
int |
int |
130 |
km_check_for_seckey (listview_ctrl_t lv, int pos, int *utrust) |
km_check_for_seckey (listview_ctrl_t lv, int pos, int *utrust) |
131 |
{ |
{ |
132 |
char t[32], t2[64]; |
gpgme_key_t key; |
133 |
|
winpt_key_s sk; |
134 |
int type = 0; |
int type = 0; |
135 |
|
|
136 |
|
key = (gpgme_key_t)listview_get_item2 (lv, pos); |
137 |
|
if (!key) |
138 |
|
BUG (NULL); |
139 |
if (utrust) |
if (utrust) |
140 |
*utrust = 0; |
*utrust = 0; |
141 |
listview_get_item_text (lv, pos, 5, t, DIM (t)-1); |
memset (&sk, 0, sizeof (sk)); |
142 |
listview_get_item_text (lv, pos, 2, t2, DIM (t2)-1); |
if (!winpt_get_seckey (key->subkeys->keyid+8, &sk)) |
|
if (!strcmp (t2, "pub/sec")) |
|
143 |
type = 1; |
type = 1; |
144 |
else if (!strcmp (t2, "pub/crd")) |
if (sk.ext && sk.ext->gloflags.divert_to_card) |
145 |
type = 2; |
type = 2; |
146 |
if ((strstr (t, "Expired") || strstr (t, "Revoked")) && utrust) |
if (utrust && (key->expired || key->revoked)) |
147 |
*utrust = -1; |
*utrust = -1; |
148 |
else if (stristr (t, "Ultimate") && utrust) |
else if (utrust && key->owner_trust == GPGME_VALIDITY_ULTIMATE) |
149 |
*utrust = 1; |
*utrust = 1; |
150 |
return type; |
return type; |
151 |
} |
} |
166 |
} |
} |
167 |
|
|
168 |
|
|
169 |
|
/* Check if the key has a good status. |
170 |
|
Return value: 0 on success. */ |
171 |
int |
int |
172 |
km_check_key_status (listview_ctrl_t lv, int pos) |
km_check_key_status (listview_ctrl_t lv, int pos) |
173 |
{ |
{ |
185 |
} |
} |
186 |
|
|
187 |
return 0; |
return 0; |
188 |
} /* km_check_key_status */ |
} |
189 |
|
|
190 |
|
|
191 |
|
/* Return all key flags ORed. */ |
192 |
int |
int |
193 |
km_get_key_status (listview_ctrl_t lv, int pos) |
km_get_key_status (listview_ctrl_t lv, int pos) |
194 |
{ |
{ |
208 |
if (key->disabled) |
if (key->disabled) |
209 |
flags |= KM_FLAG_DISABLED; |
flags |= KM_FLAG_DISABLED; |
210 |
return flags; |
return flags; |
211 |
} /* km_get_key_status */ |
} |
212 |
|
|
213 |
|
|
214 |
/* Interface to enable or disable a key (@enable = 1 then enable). |
/* Interface to enable or disable a key (@enable = 1 then enable). |
216 |
int |
int |
217 |
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) |
218 |
{ |
{ |
|
GpgKeyEdit *ke; |
|
219 |
gpgme_error_t err; |
gpgme_error_t err; |
220 |
char keyid[32]; |
gpgme_key_t key; |
221 |
|
GpgKeyEdit *ke; |
|
listview_get_item_text (lv, pos, 1, keyid, DIM (keyid)-1); |
|
222 |
|
|
223 |
ke = new GpgKeyEdit (keyid); |
key = (gpgme_key_t)listview_get_item2 (lv, pos); |
224 |
|
if (!key) |
225 |
|
BUG (NULL); |
226 |
|
ke = new GpgKeyEdit (key->subkeys->keyid); |
227 |
if (!ke) |
if (!ke) |
228 |
BUG (NULL); |
BUG (NULL); |
229 |
|
|
230 |
err = enable? ke->enable () : ke->disable (); |
err = enable? ke->enable () : ke->disable (); |
231 |
if (!err) { |
if (!err) |
232 |
show_msg (dlg, 1500, _("Key status changed.")); |
show_msg (dlg, 1500, _("Key status changed.")); |
|
keycache_set_reload (1); /* XXX: set update flag */ |
|
|
} |
|
233 |
else |
else |
234 |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
235 |
delete ke; |
delete ke; |
309 |
|
|
310 |
rset = keylist_enum_recipients (lv, KEYLIST_LIST, &n); |
rset = keylist_enum_recipients (lv, KEYLIST_LIST, &n); |
311 |
if (!n) { |
if (!n) { |
312 |
msg_box (dlg, _("No key was selected for export."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("No key was selected for export."), |
313 |
rc = WPTERR_GENERAL; |
_("Key Manager"), MB_ERR); |
314 |
|
rc = WPTERR_GENERAL; |
315 |
goto leave; |
goto leave; |
316 |
} |
} |
317 |
|
|
331 |
leave: |
leave: |
332 |
free (rset); |
free (rset); |
333 |
return rc; |
return rc; |
334 |
} /* km_clip_export */ |
} |
335 |
|
|
336 |
|
|
337 |
/* Export the selected secret key from @lv into @fname. |
/* Export the selected secret key from @lv into @fname. |
368 |
} |
} |
369 |
|
|
370 |
|
|
371 |
|
/* Export the selected recipients from @lv into the file @fname. */ |
372 |
int |
int |
373 |
km_file_export (HWND dlg, listview_ctrl_t lv, const char * fname) |
km_file_export (HWND dlg, listview_ctrl_t lv, const char *fname) |
374 |
{ |
{ |
375 |
|
GPGME *ctx; |
376 |
gpgme_key_t *rset; |
gpgme_key_t *rset; |
|
gpgme_data_t keydata; |
|
377 |
gpgme_error_t err; |
gpgme_error_t err; |
|
gpgme_ctx_t ctx; |
|
378 |
char *patt; |
char *patt; |
379 |
int n; |
int n; |
380 |
|
|
384 |
_("Key Manager"), MB_ERR); |
_("Key Manager"), MB_ERR); |
385 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
386 |
} |
} |
|
|
|
|
err = gpgme_data_new (&keydata); |
|
|
if (err) |
|
|
BUG (NULL); |
|
|
err = gpgme_new (&ctx); |
|
|
if (err) |
|
|
BUG (NULL); |
|
|
gpgme_set_armor (ctx, 1); |
|
|
|
|
|
/*gpgme_set_comment (ctx, "Generated by WinPT "PGM_VERSION);*/ |
|
387 |
patt = gpg_keylist_to_pattern (rset, n); |
patt = gpg_keylist_to_pattern (rset, n); |
388 |
|
|
389 |
err = gpgme_op_export( ctx, patt, 0, keydata); |
ctx = new GPGME (); |
390 |
if( err ) { |
ctx->setArmor (true); |
391 |
msg_box( dlg, gpgme_strerror( err ), _("Key Manager"), MB_ERR ); |
err = ctx->exportToFile (patt, fname); |
392 |
|
if (err) { |
393 |
|
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
394 |
goto leave; |
goto leave; |
395 |
} |
} |
396 |
|
else |
397 |
log_box( _("Key Manager"), MB_OK, |
log_box (_("Key Manager"), MB_OK, |
398 |
_("Key(s) successfully saved in '%s'."), fname ); |
_("Key(s) successfully saved in '%s'."), fname); |
399 |
|
|
400 |
leave: |
leave: |
401 |
err = gpg_data_release_and_set_file( keydata, fname ); |
delete ctx; |
402 |
if (err) |
safe_free (patt); |
|
log_box (_("Key Manager"), MB_OK, |
|
|
_("Could not save data to '%s'."), fname); |
|
|
gpgme_release (ctx); |
|
|
free (patt); |
|
403 |
return (int)err; |
return (int)err; |
404 |
} /* km_file_export */ |
} |
405 |
|
|
406 |
|
|
407 |
|
/* Read a dash escaped key from the clipboard |
408 |
|
unescape it and write it back. */ |
409 |
static int |
static int |
410 |
extract_dash_escaped_key (void) |
extract_dash_escaped_key (void) |
411 |
{ |
{ |
414 |
|
|
415 |
err = gpg_data_new_from_clipboard (&inp, 0); |
err = gpg_data_new_from_clipboard (&inp, 0); |
416 |
if (err) { |
if (err) { |
417 |
msg_box (NULL, gpgme_strerror( err ), _("Key Manager"), MB_ERR); |
msg_box (NULL, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
418 |
return -1; |
return -1; |
419 |
} |
} |
420 |
gpg_data_extract_plaintext (inp, &plain); |
gpg_data_extract_plaintext (inp, &plain); |
422 |
gpgme_data_release (inp); |
gpgme_data_release (inp); |
423 |
|
|
424 |
return 0; |
return 0; |
425 |
} /* extract_dash_escaped_key */ |
} |
426 |
|
|
427 |
|
|
428 |
/* Import keys from the clipboard. */ |
/* Import keys from the clipboard. */ |
429 |
int |
int |
430 |
km_clip_import (HWND dlg) |
km_clip_import (HWND dlg, int *r_newkeys) |
431 |
{ |
{ |
432 |
gpgme_error_t err; |
gpgme_error_t err; |
433 |
int pgptype; |
int pgptype; |
434 |
int id; |
int id; |
435 |
int has_data = 0; |
int new_keys = 0, has_data = 0; |
436 |
|
|
437 |
if (!gpg_clip_istext_avail (&has_data) && !has_data) { |
if (!gpg_clip_istext_avail (&has_data) && !has_data) { |
438 |
msg_box( dlg, winpt_strerror (WPTERR_CLIP_ISEMPTY), _("Key Manager"), MB_ERR); |
msg_box (dlg, winpt_strerror (WPTERR_CLIP_ISEMPTY), |
439 |
|
_("Key Manager"), MB_ERR); |
440 |
return WPTERR_CLIP_ISEMPTY; |
return WPTERR_CLIP_ISEMPTY; |
441 |
} |
} |
442 |
err = gpg_clip_is_secured (&pgptype, &has_data); |
err = gpg_clip_is_secured (&pgptype, &has_data); |
443 |
if (err) |
if (err) |
444 |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
445 |
if (!has_data) { |
if (!has_data) { |
446 |
msg_box (dlg, _("No valid OpenPGP data found."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("No valid OpenPGP data found."), |
447 |
return WPTERR_GENERAL; |
_("Key Manager"), MB_ERR); |
448 |
|
return WPTERR_NODATA; |
449 |
} |
} |
450 |
if (!(pgptype & PGP_PUBKEY) && !(pgptype & PGP_SECKEY)) { |
if (!(pgptype & PGP_PUBKEY) && !(pgptype & PGP_SECKEY)) { |
451 |
msg_box (dlg, _("No valid OpenPGP keys found."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("No valid OpenPGP keys found."), |
452 |
return WPTERR_GENERAL; |
_("Key Manager"), MB_ERR); |
453 |
|
return WPTERR_NODATA; |
454 |
} |
} |
455 |
if (pgptype & PGP_DASH_ESCAPED) { |
if (pgptype & PGP_DASH_ESCAPED) { |
456 |
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" |
463 |
_("Key Manager"), MB_INFO); |
_("Key Manager"), MB_INFO); |
464 |
} |
} |
465 |
|
|
466 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
new_keys = dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
467 |
clip_import_dlg_proc, NULL, |
clip_import_dlg_proc, 0, |
468 |
_("Key Import"), IDS_WINPT_IMPORT); |
_("Key Import"), IDS_WINPT_IMPORT); |
469 |
|
if (r_newkeys) |
470 |
|
*r_newkeys = new_keys; |
471 |
|
if (!new_keys) |
472 |
|
return WPTERR_NODATA; |
473 |
return 0; |
return 0; |
474 |
} |
} |
475 |
|
|
497 |
fp = fopen (p, "wb"); |
fp = fopen (p, "wb"); |
498 |
if (!fp) { |
if (!fp) { |
499 |
free_if_alloc (p); |
free_if_alloc (p); |
500 |
log_box (_("Key Import HTTP"), MB_ERR, "%s: %s", p, winpt_strerror (WPTERR_FILE_CREAT)); |
log_box (_("Key Import HTTP"), MB_ERR, "%s: %s", p, |
501 |
|
winpt_strerror (WPTERR_FILE_CREAT)); |
502 |
return WPTERR_FILE_CREAT; |
return WPTERR_FILE_CREAT; |
503 |
} |
} |
504 |
|
|
514 |
msg_box (dlg, winpt_strerror (rc), _("Key Import HTTP"), MB_ERR); |
msg_box (dlg, winpt_strerror (rc), _("Key Import HTTP"), MB_ERR); |
515 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
516 |
} |
} |
517 |
km_file_import (dlg, p); |
km_file_import (dlg, p, NULL); |
518 |
remove (p); |
remove (p); |
519 |
free_if_alloc (p); |
free_if_alloc (p); |
520 |
return rc; |
return rc; |
524 |
/* Import a key from the given file @fname. |
/* Import a key from the given file @fname. |
525 |
On success an import statistics dialog is shown. */ |
On success an import statistics dialog is shown. */ |
526 |
int |
int |
527 |
km_file_import (HWND dlg, const char *fname) |
km_file_import (HWND dlg, const char *fname, int *r_newkeys) |
528 |
{ |
{ |
529 |
gpgme_data_t keydata = NULL; |
gpgme_data_t keydata = NULL; |
530 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
531 |
gpgme_error_t err; |
gpgme_error_t err; |
532 |
fm_state_s fm_stat; |
fm_state_s fm_stat; |
533 |
gpgme_import_result_t res; |
gpgme_import_result_t res; |
534 |
|
int no_data = 0; |
535 |
|
|
536 |
memset (&fm_stat, 0, sizeof (fm_stat)); |
memset (&fm_stat, 0, sizeof (fm_stat)); |
537 |
fm_stat.opaque = m_strdup (fname); |
fm_stat.opaque = m_strdup (fname); |
554 |
goto leave; |
goto leave; |
555 |
} |
} |
556 |
|
|
557 |
SetCursor (LoadCursor (NULL, IDC_WAIT)); |
op_begin (); |
558 |
err = gpgme_op_import (ctx, keydata); |
err = gpgme_op_import (ctx, keydata); |
559 |
SetCursor (LoadCursor (NULL, IDC_ARROW)); |
op_end (); |
560 |
if (err) { |
if (err) { |
561 |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
562 |
goto leave; |
goto leave; |
563 |
} |
} |
564 |
|
|
565 |
res = gpgme_op_import_result (ctx); |
res = gpgme_op_import_result (ctx); |
566 |
|
if (res->unchanged == res->considered) |
567 |
|
no_data = 1; |
568 |
|
if (r_newkeys) |
569 |
|
*r_newkeys = res->considered - res->unchanged; |
570 |
if (res->new_revocations == 0 && fm_stat.import.revcert == 1) |
if (res->new_revocations == 0 && fm_stat.import.revcert == 1) |
571 |
res->new_revocations = 1; |
res->new_revocations = 1; |
572 |
if (res->secret_imported == 0 && fm_stat.import.has_seckey == 1) |
if (res->secret_imported == 0 && fm_stat.import.has_seckey == 1) |
573 |
res->secret_imported = 1; |
res->secret_imported = 1; |
574 |
|
|
575 |
|
/* XXX: if we import a key pair but the secret key comes first, |
576 |
|
no_{valid}_user_id is 1 even so the public key, which comes |
577 |
|
later is valid and self-signed. */ |
578 |
print_import_status (res); |
print_import_status (res); |
579 |
if (res->no_user_id > 0) { |
if (res->no_user_id > 0) { |
580 |
msg_box (dlg, _("Key without a self signature was dectected!\n" |
msg_box (dlg, _("Key without a self signature was dectected!\n" |
587 |
gpgme_data_release (keydata); |
gpgme_data_release (keydata); |
588 |
gpgme_release (ctx); |
gpgme_release (ctx); |
589 |
free_if_alloc (fm_stat.opaque); |
free_if_alloc (fm_stat.opaque); |
590 |
|
if (no_data) |
591 |
|
return WPTERR_NODATA; |
592 |
return (int)err; |
return (int)err; |
593 |
} |
} |
594 |
|
|
598 |
delete_keys_from_cache (gpgme_key_t *rset, size_t n) |
delete_keys_from_cache (gpgme_key_t *rset, size_t n) |
599 |
{ |
{ |
600 |
gpg_keycache_t pub = keycache_get_ctx (1); |
gpg_keycache_t pub = keycache_get_ctx (1); |
601 |
|
gpg_keycache_t sec = keycache_get_ctx (0); |
602 |
|
gpgme_key_t sk; |
603 |
int i=0; |
int i=0; |
604 |
|
|
605 |
while (n-- > 0) |
while (n-- > 0) { |
606 |
gpg_keycache_delete_key (pub, rset[i++]->subkeys->keyid); |
if (!get_seckey (rset[i]->subkeys->keyid, &sk)) |
607 |
|
gpg_keycache_delete_key (sec, sk->subkeys->keyid); |
608 |
|
gpg_keycache_delete_key (pub, rset[i]->subkeys->keyid); |
609 |
|
i++; |
610 |
|
} |
611 |
} |
} |
612 |
|
|
613 |
|
|
617 |
{ |
{ |
618 |
gpgme_error_t err; |
gpgme_error_t err; |
619 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
620 |
gpgme_key_t *rset, k; |
gpgme_key_t *rset; |
621 |
char keyid[32], uid[256], date[64], keylen[64]; |
gpgme_key_t key; |
622 |
|
char *p; |
623 |
int with_seckey=0, seckey_type=0, confirm=0; |
int with_seckey=0, seckey_type=0, confirm=0; |
624 |
int i, rc, n, k_pos=0; |
int i, rc, n, k_pos=0; |
625 |
|
|
626 |
if (listview_get_curr_pos (lv) == -1) { |
if (listview_get_curr_pos (lv) == -1) { |
627 |
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
628 |
return WPTERR_GENERAL; |
return -1; |
629 |
} |
} |
630 |
|
|
631 |
if (listview_count_items (lv, 1) > 8) { |
if (listview_count_items (lv, 1) > 8) { |
639 |
else |
else |
640 |
confirm = 1; |
confirm = 1; |
641 |
|
|
642 |
|
/* n = total amount of keys, i is the selected amount. */ |
643 |
n = listview_count_items (lv, 0); |
n = listview_count_items (lv, 0); |
644 |
rset = (gpgme_key_t *)calloc (n+1, sizeof (gpgme_key_t)); |
i = listview_count_items (lv, 1); |
645 |
|
rset = (gpgme_key_t *)calloc (i+1, sizeof (gpgme_key_t)); |
646 |
if (!rset) |
if (!rset) |
647 |
BUG (NULL); |
BUG (NULL); |
648 |
for( i = 0; i < n; i++ ) { |
for (i = 0; i < n; i++) { |
649 |
if( listview_get_item_state( lv, i ) ) { |
if (listview_get_item_state(lv, i)) { |
650 |
listview_get_item_text( lv, i, 0, uid, sizeof uid - 1 ); |
key = (gpgme_key_t)listview_get_item2 (lv, i); |
651 |
listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 ); |
if (!key) |
652 |
listview_get_item_text( lv, i, 3, keylen, sizeof keylen - 1 ); |
BUG (NULL); |
|
listview_get_item_text( lv, i, 7, date, sizeof date - 1 ); |
|
653 |
seckey_type = km_check_for_seckey (lv, i, NULL); |
seckey_type = km_check_for_seckey (lv, i, NULL); |
654 |
if (confirm && !seckey_type) { |
if (confirm && !seckey_type) { |
655 |
rc = log_box( _("Key Manager"), MB_YESNO|MB_ICONWARNING, |
p = km_key_get_info (key, 0); |
656 |
|
rc = log_box (_("Key Manager"), MB_YESNO|MB_ICONWARNING, |
657 |
_("Do you really want to delete this key?\n\n" |
_("Do you really want to delete this key?\n\n" |
658 |
"pub %s %s %s\n" |
"%s"), p); |
659 |
" \"%s\""), keylen, keyid, date, uid ); |
if (rc == IDYES) |
660 |
if (rc == IDYES) { |
rset[k_pos++] = key; |
|
get_pubkey (keyid, &k); |
|
|
rset[k_pos++] = k; |
|
|
} |
|
661 |
with_seckey = 0; |
with_seckey = 0; |
662 |
|
free_if_alloc (p); |
663 |
} |
} |
664 |
else if (confirm) { |
else if (confirm) { |
665 |
rc = log_box( _("Key Manager"), MB_YESNO|MB_ICONWARNING, |
p = km_key_get_info (key, 1); |
666 |
|
rc = log_box (_("Key Manager"), MB_YESNO|MB_ICONWARNING, |
667 |
_("Do you really want to delete this KEY PAIR?\n\n" |
_("Do you really want to delete this KEY PAIR?\n\n" |
668 |
"Please remember that you are not able to decrypt\n" |
"Please remember that you are not able to decrypt\n" |
669 |
"messages you stored with this key any longer.\n" |
"messages you stored with this key any longer.\n" |
670 |
"\n" |
"\n" |
671 |
"pub/sec %s %s %s\n" |
"%s"), p); |
672 |
" \"%s\""), keylen, keyid, date, uid ); |
if (rc == IDYES) { |
|
if( rc == IDYES ) { |
|
673 |
if (seckey_type == 2) |
if (seckey_type == 2) |
674 |
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" |
675 |
"Only the public key and the secret key \n" |
"Only the public key and the secret key \n" |
676 |
"placeholder will be deleted.\n"), _("Key Manager"), MB_OK ); |
"placeholder will be deleted.\n"), |
677 |
get_pubkey (keyid, &k); |
_("Key Manager"), MB_OK); |
678 |
rset[k_pos++] = k; |
rset[k_pos++] = key; |
679 |
} |
} |
680 |
with_seckey = 1; |
with_seckey = 1; |
681 |
|
free_if_alloc (p); |
682 |
} |
} |
683 |
else { |
else { |
684 |
with_seckey = 1; |
with_seckey = 1; |
685 |
get_pubkey (keyid, &k); |
rset[k_pos++] = key; |
|
rset[k_pos++] = k; |
|
686 |
} |
} |
687 |
} |
} |
688 |
} |
} |
695 |
err = gpgme_new (&ctx); |
err = gpgme_new (&ctx); |
696 |
if (err) |
if (err) |
697 |
BUG (NULL); |
BUG (NULL); |
698 |
n=k_pos; |
n = k_pos; |
699 |
|
op_begin (); |
700 |
for (i=0; i < k_pos; i++) { |
for (i=0; i < k_pos; i++) { |
701 |
err = gpgme_op_delete (ctx, rset[i], with_seckey); |
err = gpgme_op_delete (ctx, rset[i], with_seckey); |
702 |
if (err) |
if (err) |
704 |
else |
else |
705 |
n--; |
n--; |
706 |
} |
} |
707 |
|
op_end (); |
708 |
if (n == 0) |
if (n == 0) |
709 |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
710 |
gpgme_release (ctx); |
gpgme_release (ctx); |
711 |
listview_del_items (lv); |
listview_del_sel_items (lv); |
712 |
delete_keys_from_cache (rset, k_pos); |
delete_keys_from_cache (rset, k_pos); |
713 |
free (rset); |
free (rset); |
714 |
|
|
716 |
} |
} |
717 |
|
|
718 |
|
|
719 |
|
/* Send the select key in @lv to the keyserver @host:@port. */ |
720 |
int |
int |
721 |
km_send_to_keyserver (listview_ctrl_t lv, HWND dlg, const char * host, u16 port) |
km_send_to_keyserver (listview_ctrl_t lv, HWND dlg, const char *host, u16 port) |
722 |
{ |
{ |
723 |
char keyid[32]; |
gpgme_key_t key; |
|
const char *t; |
|
724 |
int id; |
int id; |
725 |
|
|
726 |
id = listview_get_curr_pos( lv ); |
id = listview_get_curr_pos (lv); |
727 |
if( id == -1 ) { |
if (id == -1) { |
728 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
729 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
730 |
} |
} |
731 |
|
|
732 |
listview_get_item_text( lv, id, 1, keyid, sizeof keyid - 1 ); |
key = (gpgme_key_t)listview_get_item2 (lv, id); |
733 |
|
if (!key) |
734 |
|
BUG (NULL); |
735 |
id = log_box (_("Key Manager"), MB_YESNO, |
id = log_box (_("Key Manager"), MB_YESNO, |
736 |
_("Do you really want to send '%s' to keyserver %s?"), |
_("Do you really want to send '%s' to keyserver %s?"), |
737 |
keyid, host); |
key->subkeys->keyid+8, host); |
738 |
if (id == IDYES) { |
if (id == IDYES) |
739 |
t = keyid; |
hkp_send_key (dlg, host, port, key->subkeys->keyid+8); |
|
if (!strncmp (keyid, "0x", 2)) |
|
|
t += 2; |
|
|
hkp_send_key (dlg, host, port, t); |
|
|
} |
|
740 |
|
|
741 |
return 0; |
return 0; |
742 |
} /* km_send_to_keyserver */ |
} |
743 |
|
|
744 |
|
|
745 |
|
/* Send the selected key in @lv via MAPI to a mail recipient. */ |
746 |
int |
int |
747 |
km_send_to_mail_recipient( listview_ctrl_t lv, HWND dlg ) |
km_send_to_mail_recipient (listview_ctrl_t lv, HWND dlg) |
748 |
{ |
{ |
|
#if 0 /*FIXME*/ |
|
749 |
gpgme_key_t key; |
gpgme_key_t key; |
750 |
gpgme_ctx_t ctx=NULL; |
gpgme_ctx_t ctx=NULL; |
751 |
gpgme_recipients_t rset=NULL; |
gpgme_data_t out; |
752 |
gpgme_error_t rc; |
gpgme_error_t rc; |
753 |
const char * s; |
char tmp[128]; |
754 |
char keyid[32], tmp[192+256], * p =NULL; |
char *fname; |
755 |
|
char *name; |
756 |
int pos; |
int pos; |
757 |
|
|
758 |
if( listview_count_items( lv, 1 ) > 1 ) { |
if (listview_count_items (lv, 1) > 1) { |
759 |
msg_box( dlg, _("Please only select one key."), _("Key Manager"), MB_INFO|MB_OK ); |
msg_box (dlg, _("Please only select one key."), |
760 |
|
_("Key Manager"), MB_INFO|MB_OK); |
761 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
762 |
} |
} |
763 |
pos = listview_get_curr_pos( lv ); |
pos = listview_get_curr_pos (lv); |
764 |
if( pos == -1 ) { |
if (pos == -1) { |
765 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
766 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
767 |
} |
} |
768 |
listview_get_item_text( lv, pos, 1, keyid, sizeof keyid-1 ); |
key = (gpgme_key_t)listview_get_item2 (lv, pos); |
769 |
if( get_pubkey( keyid, &key ) ) |
if (!key) |
770 |
BUG( NULL ); |
BUG (NULL); |
|
s = key->uids->name; |
|
|
GetTempPath (sizeof tmp-1, tmp); |
|
|
strncat (tmp, s, sizeof tmp-200); |
|
|
strncat (tmp, ".asc", sizeof tmp-200); |
|
|
p = fm_quote_file (tmp); |
|
771 |
|
|
772 |
rc = gpgme_recipients_new (&rset); |
GetTempPath (sizeof (tmp)-1, tmp); |
773 |
if (!rc) |
if (tmp[strlen (tmp)-1] == '\\') |
774 |
rc = gpgme_recipients_add_name (rset, keyid); |
tmp[strlen (tmp)-1] = 0; |
775 |
if (!rc) |
name = utf8_to_wincp2 (key->uids->name); |
776 |
rc = gpgme_new (&ctx); |
fname = make_filename (tmp, name, "asc"); |
777 |
if (!rc) { |
for (pos=0; pos < (int)strlen (fname); pos++) { |
778 |
gpgme_set_armor (ctx, 1); |
if (fname[pos] == ' ') |
779 |
rc = gpgme_op_file_export (ctx, rset, p); |
fname[pos] = '_'; |
780 |
} |
} |
781 |
|
|
782 |
|
rc = gpgme_new (&ctx); |
783 |
|
if (rc) |
784 |
|
BUG (NULL); |
785 |
|
rc = gpgme_data_new (&out); |
786 |
if (rc) |
if (rc) |
787 |
|
BUG (NULL); |
788 |
|
|
789 |
|
gpgme_set_armor (ctx, 1); |
790 |
|
rc = gpgme_op_export (ctx, key->subkeys->keyid, 0, out); |
791 |
|
if (rc) { |
792 |
|
gpgme_data_release (out); |
793 |
msg_box (dlg, gpgme_strerror (rc), _("Key Manager"), MB_ERR); |
msg_box (dlg, gpgme_strerror (rc), _("Key Manager"), MB_ERR); |
794 |
else |
} |
795 |
mapi_send_pubkey (keyid, tmp); |
else { |
796 |
|
gpg_data_release_and_set_file (out, fname); |
797 |
|
mapi_send_pubkey (key->subkeys->keyid+8, fname); |
798 |
|
} |
799 |
|
|
|
free_if_alloc (p); |
|
|
gpgme_recipients_release (rset); |
|
800 |
gpgme_release (ctx); |
gpgme_release (ctx); |
801 |
|
safe_free (name); |
802 |
|
free_if_alloc (fname); |
803 |
return rc; |
return rc; |
|
#endif |
|
|
return 0; |
|
804 |
} |
} |
805 |
|
|
806 |
|
|
807 |
static void |
static void |
808 |
km_refresh_one_key (listview_ctrl_t lv, HWND dlg, int pos) |
km_refresh_one_key (listview_ctrl_t lv, HWND dlg, int pos, int flags) |
809 |
{ |
{ |
810 |
|
gpgme_key_t key; |
811 |
int idx; |
int idx; |
|
char keyid[32]; |
|
|
const char *t; |
|
812 |
|
|
813 |
if (pos != 0) |
if (pos != 0) |
814 |
idx = pos; |
idx = pos; |
815 |
else |
else |
816 |
idx = listview_get_curr_pos (lv); |
idx = listview_get_curr_pos (lv); |
817 |
if (idx != -1) |
if (idx != -1) { |
818 |
{ |
key = (gpgme_key_t)listview_get_item2 (lv, idx); |
819 |
listview_get_item_text (lv, idx, 1, keyid, sizeof keyid - 1); |
if (!key) |
820 |
t = keyid; |
BUG (0); |
821 |
if (!strncmp (keyid, "0x", 2)) |
hkp_recv_key (dlg, default_keyserver, default_keyserver_port, |
822 |
t += 2; |
key->subkeys->keyid+8, 0, flags); |
|
hkp_recv_key (dlg, default_keyserver, default_keyserver_port, t, 0, KM_KS_REFRESH); |
|
823 |
} |
} |
824 |
} |
} |
825 |
|
|
826 |
|
|
827 |
|
/* Refresh the selected keys from the default keyserver. */ |
828 |
void |
void |
829 |
km_refresh_from_keyserver (listview_ctrl_t lv, HWND dlg) |
km_refresh_from_keyserver (listview_ctrl_t lv, HWND dlg) |
830 |
{ |
{ |
831 |
int idx, id, i; |
int cnt, id, i; |
832 |
|
|
833 |
if (kserver_check_inet_connection ()) |
if (kserver_check_inet_connection ()) { |
|
{ |
|
834 |
msg_box (dlg, _("Could not connect to keyserver, abort procedure."), |
msg_box (dlg, _("Could not connect to keyserver, abort procedure."), |
835 |
_("Key Manager"), MB_ERR); |
_("Key Manager"), MB_ERR); |
836 |
return; |
return; |
837 |
} |
} |
838 |
idx = listview_count_items (lv, 0); |
|
839 |
if (listview_count_items (lv, 1) == idx) { |
cnt = listview_count_items (lv, 0); |
840 |
id = msg_box (dlg, _("Do you really want to refresh all keys in the keyring?"), _("Key Manager"), MB_YESNO); |
if (listview_count_items (lv, 1) == cnt) { |
841 |
|
id = msg_box (dlg, _("Do you really want to refresh all keys in the keyring?"), |
842 |
|
_("Key Manager"), MB_YESNO); |
843 |
if (id == IDNO) |
if (id == IDNO) |
844 |
return; |
return; |
|
for (i = 0; i < idx; i++) |
|
|
km_refresh_one_key (lv, dlg, i); |
|
845 |
} |
} |
846 |
else if (idx == 1) |
if (listview_count_items (lv, 1) == 1) |
847 |
km_refresh_one_key (lv, dlg, 0); |
km_refresh_one_key (lv, dlg, listview_get_curr_pos (lv), 0); |
848 |
else { |
else { |
849 |
for (i=0; i < listview_count_items (lv, 0); i++) { |
for (i=0; i < cnt; i++) { |
850 |
if (listview_get_item_state (lv, i)) |
if (listview_get_item_state (lv, i)) |
851 |
km_refresh_one_key (lv, dlg, i); |
km_refresh_one_key (lv, dlg, i, KM_KS_REFRESH); |
852 |
} |
} |
853 |
} |
} |
854 |
} /* km_refresh_from_keyserver */ |
} |
855 |
|
|
856 |
|
|
857 |
void |
void |
859 |
{ |
{ |
860 |
char buf[256]; |
char buf[256]; |
861 |
|
|
862 |
key_get_clip_info (uid, buf, 255); |
key_get_clip_info (uid, buf, sizeof (buf)-1); |
863 |
set_clip_text (NULL, buf, strlen (buf)); |
set_clip_text (NULL, buf, strlen (buf)); |
864 |
} /* km_set_clip_info */ |
} |
865 |
|
|
866 |
|
|
867 |
|
|
871 |
km_key_is_v3 (listview_ctrl_t lv, int pos) |
km_key_is_v3 (listview_ctrl_t lv, int pos) |
872 |
{ |
{ |
873 |
gpgme_key_t pk; |
gpgme_key_t pk; |
|
char keyid[32]; |
|
874 |
|
|
875 |
listview_get_item_text (lv, pos, 1, keyid, sizeof keyid-1); |
pk = (gpgme_key_t)listview_get_item2 (lv, pos); |
876 |
if (get_pubkey (keyid, &pk)) |
if (!pk) |
877 |
BUG (NULL); |
BUG (NULL); |
878 |
if (strlen (pk->subkeys->fpr) == 32 && |
if (strlen (pk->subkeys->fpr) == 32 && |
879 |
pk->subkeys->pubkey_algo == GPGME_PK_RSA) |
pk->subkeys->pubkey_algo == GPGME_PK_RSA) |
882 |
} |
} |
883 |
|
|
884 |
|
|
|
/* Update the default key entry in the status bar for dialog @dlg. */ |
|
|
void |
|
|
km_update_default_key_str (HWND dlg) |
|
|
{ |
|
|
char *keyid, defkeyinf[512]; |
|
|
const char *fmt; |
|
|
|
|
|
/* XXX: also show the name? */ |
|
|
keyid = get_gnupg_default_key (); |
|
|
if (!keyid) |
|
|
BUG (0); |
|
|
if( (keyid[0] >= 'A' && keyid[0] <= 'Z') || (keyid[0] >= 'a' && keyid[0] <= 'z') |
|
|
|| (keyid[0] == '0' && keyid[1] == 'x') ) |
|
|
fmt = _("Default Key: %s"); |
|
|
else |
|
|
fmt = _("Default Key: 0x%s"); |
|
|
_snprintf (defkeyinf, sizeof defkeyinf - 1, fmt, keyid); |
|
|
SendMessage (dlg, SB_SETTEXT, 0, (LPARAM)defkeyinf); |
|
|
free_if_alloc (keyid); |
|
|
} |
|
|
|
|
|
|
|
|
/* Count all keys and show from @lv results in the status bar @sb. */ |
|
|
void |
|
|
km_complete_status_bar (HWND sb, listview_ctrl_t lv) |
|
|
{ |
|
|
char txt_sec[128], txt_pub[128]; |
|
|
int nkeys = 0, nsec = 0, i; |
|
|
|
|
|
nkeys = listview_count_items (lv, 0); |
|
|
for (i = 0; i < nkeys; i++) { |
|
|
if (km_check_for_seckey (lv, i, NULL)) |
|
|
nsec++; |
|
|
} |
|
|
_snprintf (txt_sec, sizeof (txt_sec)-1, _("%d secret keys"), nsec); |
|
|
_snprintf (txt_pub, sizeof (txt_pub)-1, _("%d keys"), nkeys); |
|
|
SendMessage (sb, SB_SETTEXT, 1, (LPARAM)txt_sec); |
|
|
SendMessage (sb, SB_SETTEXT, 2, (LPARAM)txt_pub); |
|
|
} |
|
|
|
|
|
|
|
885 |
/* Set trust of selected key in @lv (at @pos) to ultimate. */ |
/* Set trust of selected key in @lv (at @pos) to ultimate. */ |
886 |
int |
int |
887 |
km_set_implicit_trust (HWND dlg, listview_ctrl_t lv, int pos) |
km_set_implicit_trust (HWND dlg, listview_ctrl_t lv, int pos) |
888 |
{ |
{ |
889 |
|
gpgme_error_t err; |
890 |
|
gpgme_key_t key; |
891 |
GpgKeyEdit *ke; |
GpgKeyEdit *ke; |
|
gpgme_error_t err; |
|
|
char keyid[32]; |
|
|
|
|
|
listview_get_item_text (lv, pos, 1, keyid, 31); |
|
892 |
|
|
893 |
ke = new GpgKeyEdit (keyid); |
key = (gpgme_key_t)listview_get_item2 (lv, pos); |
894 |
|
if (!key) |
895 |
|
BUG (NULL); |
896 |
|
ke = new GpgKeyEdit (key->subkeys->keyid); |
897 |
if (!ke) |
if (!ke) |
898 |
BUG (0); |
BUG (0); |
899 |
|
|
936 |
} |
} |
937 |
|
|
938 |
|
|
939 |
|
/* Return a user-friendly name for a key derrived from |
940 |
void |
name. If @is_secret is 1, a secret key name will be generated. */ |
941 |
km_dump_key (gpgme_key_t key) |
char* |
942 |
{ |
km_gen_export_filename (const char *keyid, int is_secret) |
|
#if _DEBUG |
|
|
log_box ("DEBUG", MB_OK, |
|
|
"%d %d %s %d\n%s", key->subkeys->length, |
|
|
key->subkeys->pubkey_algo, |
|
|
key->subkeys->keyid, |
|
|
key->subkeys->timestamp, |
|
|
key->uids->uid); |
|
|
#endif |
|
|
} |
|
|
|
|
|
#if 0 |
|
|
gpg_optfile_t |
|
|
km_groupdb_open (void) |
|
|
{ |
|
|
gpg_optfile_t opt; |
|
|
char * optfile; |
|
|
int err = 0; |
|
|
|
|
|
optfile = get_gnupg_cfgfile(); |
|
|
if( !optfile ) |
|
|
BUG( NULL ); |
|
|
if( parse_gpg_options( optfile, &opt ) ) |
|
|
err = 1; |
|
|
free_if_alloc( optfile ); |
|
|
return err? NULL : opt; |
|
|
} /* km_groupdb_open */ |
|
|
|
|
|
|
|
|
int |
|
|
km_groupdb_expand_recipients( const char *name, gpgme_recipients_t rset ) |
|
|
{ |
|
|
gpg_keycache_t kc; |
|
|
gpgme_key_t pk; |
|
|
gpg_optfile_t opt; |
|
|
gpg_group_t grp; |
|
|
gpg_member_t mbr; |
|
|
int no_trust = 0, n; |
|
|
|
|
|
kc = keycache_get_ctx( 1 ); |
|
|
if( !kc ) |
|
|
BUG( NULL ); |
|
|
|
|
|
opt = km_groupdb_open( ); |
|
|
if( !opt ) |
|
|
return WPTERR_FILE_OPEN; |
|
|
|
|
|
grp = find_group( opt, name ); |
|
|
if( !grp ) |
|
|
return WPTERR_GENERAL; |
|
|
|
|
|
/* we are paranoid and check that all group members exist in the |
|
|
key cache. there is no need that it is really the real key, but |
|
|
an entry should be available. the rest is up to GPG. */ |
|
|
for( mbr = grp->list; mbr; mbr = mbr->next ) { |
|
|
if( gpgme_keycache_find_key( kc, mbr->name, 0, &pk ) ) |
|
|
BUG( NULL ); |
|
|
n = count_userids (pk); |
|
|
while( n-- ) { |
|
|
gpgme_user_id_t u = get_nth_userid (pk, n); |
|
|
const char * s = u->uid; |
|
|
if( s && stristr( s, mbr->name ) |
|
|
&& u->validity < 3 ) |
|
|
no_trust++; |
|
|
} |
|
|
} |
|
|
|
|
|
gpgme_recipients_add_name( rset, name ); |
|
|
release_gpg_options( opt ); |
|
|
|
|
|
return no_trust; |
|
|
} /* km_groupdb_expand_recipients */ |
|
|
|
|
|
|
|
|
static HTREEITEM |
|
|
km_tv_insert_item( HWND tree, HTREEITEM parent, const char *text ) |
|
|
{ |
|
|
TVINSERTSTRUCT tvis; |
|
|
HTREEITEM node; |
|
|
|
|
|
memset( &tvis, 0, sizeof tvis ); |
|
|
tvis.hParent = parent; |
|
|
tvis.hInsertAfter = TVI_LAST; |
|
|
tvis.item.mask = TVIF_TEXT; |
|
|
tvis.item.pszText = (char *)text; |
|
|
node = TreeView_InsertItem( tree, &tvis ); |
|
|
return node; |
|
|
} /* km_tv_insert_item */ |
|
|
|
|
|
|
|
|
int |
|
|
km_groups_new( km_group_t *r_gc, HWND ctrl ) |
|
|
{ |
|
|
km_group_t gc; |
|
|
|
|
|
gc = new km_group_s; |
|
|
if (!gc) |
|
|
BUG (NULL); |
|
|
gc->tree = ctrl; |
|
|
gc->gh = km_groupdb_open (); |
|
|
*r_gc = gc; |
|
|
return 0; |
|
|
} /* km_groups_new */ |
|
|
|
|
|
|
|
|
void |
|
|
km_groups_sync( km_group_t gc ) |
|
|
{ |
|
|
char * optfile; |
|
|
|
|
|
optfile = get_gnupg_cfgfile (); |
|
|
if( !optfile ) |
|
|
BUG( NULL ); |
|
|
commit_gpg_options( optfile, gc->gh ); |
|
|
free_if_alloc( optfile ); |
|
|
gc->need_sync = 0; |
|
|
} /* km_groups_sync */ |
|
|
|
|
|
|
|
|
void |
|
|
km_groups_release (km_group_t gc) |
|
|
{ |
|
|
if( gc ) { |
|
|
/* xxx: this reset the default key (sync=1) */ |
|
|
gc->need_sync=0; |
|
|
if (gc->need_sync) |
|
|
km_groups_sync (gc); |
|
|
if (gc->gh) |
|
|
release_gpg_options( gc->gh ); |
|
|
gc->gh = NULL; |
|
|
gc->tree = NULL; |
|
|
delete gc; |
|
|
} |
|
|
} /* km_groups_release */ |
|
|
|
|
|
|
|
|
int |
|
|
km_groups_load( km_group_t gc ) |
|
|
{ |
|
|
HTREEITEM n; |
|
|
gpg_group_t grp, g; |
|
|
gpg_member_t mbr; |
|
|
u32 gid = 0; |
|
|
|
|
|
if( !gc->gh ) |
|
|
return 0; |
|
|
grp = gc->gh->grp; |
|
|
if( !grp ) |
|
|
return 0; /* no groups */ |
|
|
|
|
|
for( g = grp; g; g = g->next ) { |
|
|
n = km_tv_insert_item( gc->tree, NULL, g->name ); |
|
|
for( mbr = g->list; mbr; mbr = mbr->next ) { |
|
|
if( mbr->used && mbr->name ) |
|
|
km_tv_insert_item( gc->tree, n, mbr->name ); |
|
|
} |
|
|
} |
|
|
DragAcceptFiles( gc->tree, TRUE ); |
|
|
gc->need_sync = 0; |
|
|
return 0; |
|
|
} /* km_groups_load */ |
|
|
|
|
|
|
|
|
int |
|
|
km_groups_add( km_group_t gc, listview_ctrl_t lv, int km_index ) |
|
|
{ |
|
|
TVITEM tvi; |
|
|
char uid[128], valid[64], text[128]; |
|
|
int i_valid; |
|
|
|
|
|
memset( &tvi, 0, sizeof tvi ); |
|
|
tvi.hItem = TreeView_GetSelection( gc->tree ); |
|
|
tvi.pszText = text; |
|
|
tvi.cchTextMax = sizeof text -1; |
|
|
tvi.mask = TVIF_TEXT; |
|
|
TreeView_GetItem( gc->tree, &tvi ); |
|
|
|
|
|
|
|
|
listview_get_item_text( lv, km_index, 0, uid, sizeof uid -1 ); |
|
|
listview_get_item_text( lv, km_index, 5, valid, sizeof valid -1 ); |
|
|
|
|
|
if( strstr( valid, "Ultimate" ) ) |
|
|
i_valid = 5; |
|
|
else if( !strstr( valid, "Full" ) ) |
|
|
i_valid = 4; |
|
|
else if( !strstr( valid, "Marginal" ) ) |
|
|
i_valid = 3; |
|
|
else |
|
|
i_valid = 0; |
|
|
|
|
|
/* we can't add the full name. one way would be to use the first |
|
|
text until a space appears. |
|
|
group_add_entry(&gc->gh, gid, i_valid, uid); |
|
|
treeview_add_item(gc->tree, tvi.hItem, uid); |
|
|
*/ |
|
|
gc->need_sync = 1; |
|
|
|
|
|
return 0; |
|
|
} /* km_groups_add */ |
|
|
|
|
|
|
|
|
static int |
|
|
km_groups_del_main( km_group_t gc ) |
|
|
{ |
|
|
TVITEM tvi; |
|
|
char text[128]; |
|
|
int id; |
|
|
|
|
|
memset( &tvi, 0, sizeof tvi ); |
|
|
tvi.hItem = TreeView_GetSelection( gc->tree ); |
|
|
tvi.pszText = text; |
|
|
tvi.cchTextMax = sizeof text -1; |
|
|
tvi.mask = TVIF_TEXT; |
|
|
TreeView_GetItem( gc->tree, &tvi ); |
|
|
|
|
|
id = log_box( _("Key Manager"), MB_INFO_ASK, |
|
|
_("Do you really want to delete this group?\n\n%s"), text); |
|
|
if( id == IDNO ) |
|
|
return 0; |
|
|
delete_group( gc->gh, text ); |
|
|
TreeView_DeleteItem( gc->tree, &tvi ); |
|
|
gc->need_sync = 1; |
|
|
|
|
|
return 0; |
|
|
} /* km_groups_del */ |
|
|
|
|
|
|
|
|
static int |
|
|
km_groups_del_entry( km_group_t gc ) |
|
943 |
{ |
{ |
944 |
TVITEM tvi; |
gpgme_key_t key; |
945 |
HTREEITEM root; |
char *p, *uid; |
|
int id; |
|
|
char text[128], info[256]; |
|
|
gpg_group_t grp = NULL; |
|
|
|
|
|
memset( &tvi, 0, sizeof tvi ); |
|
|
tvi.hItem = TreeView_GetSelection( gc->tree ); |
|
|
tvi.pszText = text; |
|
|
tvi.cchTextMax = sizeof text-1; |
|
|
tvi.mask = TVIF_TEXT; |
|
|
TreeView_GetItem( gc->tree, &tvi ); |
|
|
|
|
|
_snprintf( info, sizeof info -1, |
|
|
_("Do you really want to delete this entry?\n\n%s"), text ); |
|
|
|
|
|
id = msg_box( gc->tree, info, _("Key Manager"), MB_INFO_ASK ); |
|
|
if( id == IDNO ) |
|
|
return 0; |
|
946 |
|
|
947 |
root = TreeView_GetParent( gc->tree, tvi.hItem ); |
if (get_pubkey (keyid, &key)) |
948 |
if( root ) { |
return m_strdup (keyid); |
949 |
|
uid = utf8_to_wincp2 (key->uids->name); |
950 |
|
if (!uid) |
951 |
|
return m_strdup (keyid); |
952 |
|
p = new char[strlen (uid) + 8 + 16]; |
953 |
|
if (!p) |
954 |
|
BUG (0); |
955 |
|
sprintf (p, "%s%s.asc", uid, is_secret? "_sec" : ""); |
956 |
|
for (size_t i=0; i < strlen (p); i++) { |
957 |
|
if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|') |
958 |
|
p[i] = '_'; |
959 |
} |
} |
960 |
|
safe_free (uid); |
961 |
delete_member( gc->gh, /*fixme*/NULL, text ); |
return p; |
962 |
TreeView_DeleteItem( gc->tree, &tvi ); |
} |
|
gc->need_sync = 1; |
|
|
return 0; |
|
|
} /* km_groups_del_entry */ |
|
|
|
|
|
|
|
|
int |
|
|
km_groups_del( km_group_t gc ) |
|
|
{ |
|
|
if ( TreeView_GetParent( gc->tree, TreeView_GetSelection( gc->tree ) ) ) |
|
|
return km_groups_del_entry( gc ); |
|
|
else |
|
|
return km_groups_del_main( gc ); |
|
|
} /* km_groups_del */ |
|
|
#endif |
|