1 |
/* wptKeyManager.cpp - Handy functions for the Key Manager dialog |
/* wptKeyManager.cpp - Handy functions for the Key Manager dialog |
2 |
* Copyright (C) 2001-2004 Timo Schulz |
* Copyright (C) 2001-2005 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
*/ |
|
/* x-todo-status: OK */ |
|
|
|
|
20 |
#include <windows.h> |
#include <windows.h> |
21 |
#include <commctrl.h> |
#include <commctrl.h> |
22 |
#include <stdio.h> |
#include <stdio.h> |
77 |
int |
int |
78 |
km_check_for_seckey (listview_ctrl_t lv, int pos, int * utrust) |
km_check_for_seckey (listview_ctrl_t lv, int pos, int * utrust) |
79 |
{ |
{ |
80 |
char t[128], t2[128]; |
char t[32], t2[64]; |
81 |
int type=0; |
int type = 0; |
82 |
|
|
83 |
listview_get_item_text (lv, pos, 5, t, sizeof t -1); |
listview_get_item_text (lv, pos, 5, t, sizeof (t) - 1); |
84 |
listview_get_item_text (lv, pos, 2, t2, sizeof t2 -1); |
listview_get_item_text (lv, pos, 2, t2, sizeof (t2) - 1); |
85 |
if (!strcmp (t2, "pub/sec")) |
if (!strcmp (t2, "pub/sec")) |
86 |
type = 1; |
type = 1; |
87 |
else if (!strcmp (t2, "pub/crd")) |
else if (!strcmp (t2, "pub/crd")) |
149 |
|
|
150 |
|
|
151 |
int |
int |
152 |
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) |
153 |
{ |
{ |
154 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
155 |
gpgme_editkey_t ek; |
gpgme_editkey_t ek; |
157 |
int edit_id; |
int edit_id; |
158 |
char keyid[32]; |
char keyid[32]; |
159 |
|
|
160 |
listview_get_item_text( lv, pos, 1, keyid, sizeof keyid-1 ); |
listview_get_item_text( lv, pos, 1, keyid, DIM (keyid)-1 ); |
161 |
err = gpgme_editkey_new( &ek ); |
err = gpgme_editkey_new( &ek ); |
162 |
if( err ) |
if( err ) |
163 |
BUG( NULL ); |
BUG( NULL ); |
164 |
if( enable ) { |
if( enable ) { |
165 |
gpgme_editkey_enable_set( ek ); |
gpgme_editkey_enable_set (ek); |
166 |
edit_id = GPGME_EDITKEY_ENABLE; |
edit_id = GPGME_EDITKEY_ENABLE; |
167 |
} |
} |
168 |
else { |
else { |
169 |
gpgme_editkey_disable_set( ek ); |
gpgme_editkey_disable_set (ek); |
170 |
edit_id = GPGME_EDITKEY_DISABLE; |
edit_id = GPGME_EDITKEY_DISABLE; |
171 |
} |
} |
172 |
err = gpgme_new( &ctx ); |
err = gpgme_new (&ctx); |
173 |
if( err ) |
if( err ) |
174 |
BUG( NULL ); |
BUG( NULL ); |
175 |
gpgme_set_edit_ctx( ctx, ek, edit_id ); |
gpgme_set_edit_ctx (ctx, ek, edit_id); |
176 |
err = gpgme_op_editkey( ctx, keyid ); |
err = gpgme_op_editkey (ctx, keyid); |
177 |
if( !err ) { |
if( !err ) { |
178 |
show_msg( dlg, 1500, _("Key status changed.") ); |
show_msg( dlg, 1500, _("Key status changed.") ); |
179 |
keycache_set_reload( 1 ); |
keycache_set_reload( 1 ); |
181 |
else |
else |
182 |
msg_box( dlg, gpgme_strerror( err ), _("Key Manager"), MB_ERR ); |
msg_box( dlg, gpgme_strerror( err ), _("Key Manager"), MB_ERR ); |
183 |
|
|
184 |
gpgme_release( ctx ); |
gpgme_release (ctx); |
185 |
gpgme_editkey_release( ek ); |
gpgme_editkey_release (ek); |
186 |
return err? WPTERR_GENERAL : 0; |
return err? WPTERR_GENERAL : 0; |
187 |
} /* km_enable_disable_key */ |
} /* km_enable_disable_key */ |
188 |
|
|
316 |
|
|
317 |
|
|
318 |
static int |
static int |
319 |
extract_dash_escaped_key( void ) |
extract_dash_escaped_key (void) |
320 |
{ |
{ |
321 |
gpgme_data_t inp, plain; |
gpgme_data_t inp, plain; |
322 |
gpgme_error_t err; |
gpgme_error_t err; |
323 |
|
|
324 |
err = gpgme_data_new_from_clipboard (&inp); |
err = gpgme_data_new_from_clipboard (&inp); |
325 |
if( err ) { |
if (err) { |
326 |
msg_box( NULL, gpgme_strerror( err ), _("Key Manager"), MB_ERR ); |
msg_box (NULL, gpgme_strerror( err ), _("Key Manager"), MB_ERR); |
327 |
return -1; |
return -1; |
328 |
} |
} |
329 |
gpgme_data_extract_plaintext( inp, &plain ); |
gpgme_data_extract_plaintext (inp, &plain); |
330 |
gpgme_data_release( inp ); |
gpgme_data_release (inp); |
331 |
gpgme_data_release_and_set_clipboard( plain ); |
gpgme_data_release_and_set_clipboard (plain); |
332 |
|
|
333 |
return 0; |
return 0; |
334 |
} /* extract_dash_escaped_key */ |
} /* extract_dash_escaped_key */ |
338 |
km_clip_import( HWND dlg ) |
km_clip_import( HWND dlg ) |
339 |
{ |
{ |
340 |
gpgme_error_t err; |
gpgme_error_t err; |
341 |
gpgme_cliptype_t pgptype; |
gpgme_pgptype_t pgptype; |
342 |
int id; |
int id; |
343 |
int has_data = 0; |
int has_data = 0; |
344 |
|
|
353 |
msg_box( dlg, _("No valid OpenPGP data found."), _("Key Manager"), MB_ERR ); |
msg_box( dlg, _("No valid OpenPGP data found."), _("Key Manager"), MB_ERR ); |
354 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
355 |
} |
} |
356 |
if( !(pgptype & GPGME_CLIP_PUBKEY) && !(pgptype & GPGME_CLIP_SECKEY) ) { |
if( !(pgptype & GPGME_PGP_PUBKEY) && !(pgptype & GPGME_PGP_SECKEY) ) { |
357 |
msg_box( dlg, _("No valid OpenPGP keys found."), _("Key Manager"), MB_ERR ); |
msg_box( dlg, _("No valid OpenPGP keys found."), _("Key Manager"), MB_ERR ); |
358 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
359 |
} |
} |
360 |
if( pgptype & GPGME_CLIP_DASH_ESCAPED ) { |
if( pgptype & GPGME_PGP_DASH_ESCAPED ) { |
361 |
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" |
362 |
"Do you want to extract the key?"), |
"Do you want to extract the key?"), |
363 |
_("Key Manager"), MB_YESNO ); |
_("Key Manager"), MB_YESNO ); |
490 |
gpgme_recipients_t rset; |
gpgme_recipients_t rset; |
491 |
char keyid[32], uid[256], date[64], keylen[64]; |
char keyid[32], uid[256], date[64], keylen[64]; |
492 |
int with_seckey, seckey_type=0; |
int with_seckey, seckey_type=0; |
493 |
int i, rc; |
int i, rc, n; |
494 |
|
|
495 |
if( listview_get_curr_pos( lv ) == -1 ) { |
if( listview_get_curr_pos( lv ) == -1 ) { |
496 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
500 |
err = gpgme_recipients_new (&rset); |
err = gpgme_recipients_new (&rset); |
501 |
if (err) |
if (err) |
502 |
BUG (0); |
BUG (0); |
503 |
|
n = listview_count_items (lv, 0); |
504 |
for( i = 0; i < listview_count_items( lv, 0 ); i++ ) { |
for( i = 0; i < n; i++ ) { |
505 |
if( listview_get_item_state( lv, i ) ) { |
if( listview_get_item_state( lv, i ) ) { |
506 |
listview_get_item_text( lv, i, 0, uid, sizeof uid - 1 ); |
listview_get_item_text( lv, i, 0, uid, sizeof uid - 1 ); |
507 |
listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 ); |
listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 ); |
704 |
|
|
705 |
|
|
706 |
int |
int |
707 |
km_key_is_v3( listview_ctrl_t lv, int pos ) |
km_key_is_v3 (listview_ctrl_t lv, int pos) |
708 |
{ |
{ |
709 |
gpgme_key_t pk; |
gpgme_key_t pk; |
|
const char * fpr; |
|
|
unsigned long algo; |
|
710 |
char keyid[32]; |
char keyid[32]; |
711 |
|
|
712 |
listview_get_item_text( lv, pos, 1, keyid, sizeof keyid-1 ); |
listview_get_item_text (lv, pos, 1, keyid, sizeof keyid-1); |
713 |
if( get_pubkey( keyid, &pk ) ) |
if (get_pubkey (keyid, &pk)) |
714 |
BUG( NULL ); |
BUG (NULL); |
715 |
algo = gpgme_key_get_ulong_attr( pk, GPGME_ATTR_ALGO, NULL, 0 ); |
return gpgme_key_get_ulong_attr (pk, GPGME_ATTR_VERSION, NULL, 0); |
|
fpr = gpgme_key_get_string_attr( pk, GPGME_ATTR_FPR, NULL, 0 ); |
|
|
return strlen( fpr ) == 32 && algo == GPGME_PK_RSA? 1 : 0; |
|
716 |
} /* km_key_is_v3 */ |
} /* km_key_is_v3 */ |
717 |
|
|
718 |
|
|