425 |
} |
} |
426 |
|
|
427 |
|
|
428 |
|
/* Import the PGP key data from the clipboard. |
429 |
|
Return value: 0 on success. */ |
430 |
|
static gpgme_error_t |
431 |
|
gpg_op_clip_import (gpgme_ctx_t ctx) |
432 |
|
{ |
433 |
|
gpgme_error_t err = 0; |
434 |
|
gpgme_data_t keydata = NULL; |
435 |
|
|
436 |
|
err = gpg_data_new_from_clipboard (&keydata, 0); |
437 |
|
if (!err) |
438 |
|
err = gpgme_op_import (ctx, keydata); |
439 |
|
|
440 |
|
gpgme_data_release (keydata); |
441 |
|
return err; |
442 |
|
} |
443 |
|
|
444 |
/* Import keys from the clipboard. */ |
/* Import keys from the clipboard. */ |
445 |
int |
int |
446 |
km_clip_import (HWND dlg, int *r_newkeys) |
km_clip_import (HWND dlg, int *r_newkeys, int *r_newsks) |
447 |
{ |
{ |
448 |
gpgme_error_t err; |
gpgme_error_t err; |
449 |
|
gpgme_ctx_t ctx = NULL; |
450 |
|
gpgme_import_result_t res; |
451 |
|
fm_state_s fm_stat; |
452 |
int pgptype; |
int pgptype; |
453 |
int id; |
int id, has_data = 0; |
454 |
int new_keys = 0, has_data = 0; |
int new_keys = 0, new_sks = 0; |
455 |
|
|
456 |
if (!gpg_clip_istext_avail (&has_data) && !has_data) { |
if (!gpg_clip_istext_avail (&has_data) && !has_data) { |
457 |
msg_box (dlg, winpt_strerror (WPTERR_CLIP_ISEMPTY), |
msg_box (dlg, winpt_strerror (WPTERR_CLIP_ISEMPTY), |
458 |
_("Key Manager"), MB_ERR); |
_("Key Manager"), MB_ERR); |
482 |
_("Key Manager"), MB_INFO); |
_("Key Manager"), MB_INFO); |
483 |
} |
} |
484 |
|
|
485 |
new_keys = dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
memset (&fm_stat, 0, sizeof (fm_stat)); |
486 |
clip_import_dlg_proc, 0, |
fm_stat.opaque = m_strdup ("Clipboard"); |
487 |
|
fm_stat.import.is_clip = 1; |
488 |
|
has_data = dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
489 |
|
file_import_dlg_proc, (LPARAM)&fm_stat, |
490 |
_("Key Import"), IDS_WINPT_IMPORT); |
_("Key Import"), IDS_WINPT_IMPORT); |
491 |
|
if (!has_data) |
492 |
|
goto leave; |
493 |
|
|
494 |
|
err = gpgme_new (&ctx); |
495 |
|
if (err) |
496 |
|
BUG (NULL); |
497 |
|
op_begin (); |
498 |
|
err = gpg_op_clip_import (ctx); |
499 |
|
op_end (); |
500 |
|
if (err) { |
501 |
|
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
502 |
|
goto leave; |
503 |
|
} |
504 |
|
|
505 |
|
res = gpgme_op_import_result (ctx); |
506 |
|
print_import_status (res); |
507 |
|
new_keys = res->considered - res->unchanged; |
508 |
|
new_sks = res->secret_imported - res->secret_unchanged; |
509 |
|
if (res->no_user_id > 0) { |
510 |
|
msg_box (dlg, _("Key without a self signature was dectected!\n" |
511 |
|
"(This key is NOT usable for encryption, etc)\n"), |
512 |
|
_("Import"), MB_WARN); |
513 |
|
} |
514 |
|
|
515 |
|
leave: |
516 |
|
if (ctx) |
517 |
|
gpgme_release (ctx); |
518 |
|
free_if_alloc (fm_stat.opaque); |
519 |
if (r_newkeys) |
if (r_newkeys) |
520 |
*r_newkeys = new_keys; |
*r_newkeys = new_keys; |
521 |
if (!new_keys) |
if (r_newsks) |
522 |
|
*r_newsks = new_sks; |
523 |
|
if (!new_keys || !has_data) |
524 |
return WPTERR_NODATA; |
return WPTERR_NODATA; |
525 |
return 0; |
return (int)err; |
526 |
} |
} |
527 |
|
|
528 |
|
|
566 |
msg_box (dlg, winpt_strerror (rc), _("Key Import HTTP"), MB_ERR); |
msg_box (dlg, winpt_strerror (rc), _("Key Import HTTP"), MB_ERR); |
567 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
568 |
} |
} |
569 |
km_file_import (dlg, p, NULL); |
km_file_import (dlg, p, NULL, NULL); |
570 |
remove (p); |
remove (p); |
571 |
free_if_alloc (p); |
free_if_alloc (p); |
572 |
return rc; |
return rc; |
573 |
} |
} |
574 |
|
|
575 |
|
|
576 |
/* Import a key from the given file @fname. |
/* Import a key from the given file @fname, if @fname is |
577 |
|
NULL use the common 'file open' dialog. |
578 |
On success an import statistics dialog is shown. */ |
On success an import statistics dialog is shown. */ |
579 |
int |
int |
580 |
km_file_import (HWND dlg, const char *fname, int *r_newkeys) |
km_file_import (HWND dlg, const char *fname, int *r_newkeys, int *r_newsks) |
581 |
{ |
{ |
582 |
gpgme_data_t keydata = NULL; |
gpgme_data_t keydata = NULL; |
583 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
584 |
gpgme_error_t err; |
gpgme_error_t err; |
585 |
fm_state_s fm_stat; |
fm_state_s fm_stat; |
586 |
gpgme_import_result_t res; |
gpgme_import_result_t res; |
587 |
|
const char *name; |
588 |
int no_data = 0; |
int no_data = 0; |
589 |
|
int new_keys = 0, new_sks = 0; |
590 |
|
|
591 |
|
if (!fname) { |
592 |
|
name = get_fileopen_dlg (dlg, _("Choose Name of the Key File"), |
593 |
|
NULL, NULL); |
594 |
|
if (!name) |
595 |
|
return WPTERR_GENERAL; |
596 |
|
} |
597 |
|
else |
598 |
|
name = fname; |
599 |
|
|
600 |
memset (&fm_stat, 0, sizeof (fm_stat)); |
memset (&fm_stat, 0, sizeof (fm_stat)); |
601 |
fm_stat.opaque = m_strdup (fname); |
fm_stat.opaque = m_strdup (name); |
602 |
|
|
603 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
604 |
file_import_dlg_proc, (LPARAM)&fm_stat, |
file_import_dlg_proc, (LPARAM)&fm_stat, |
611 |
err = gpgme_new (&ctx); |
err = gpgme_new (&ctx); |
612 |
if (err) |
if (err) |
613 |
BUG (NULL); |
BUG (NULL); |
614 |
err = gpgme_data_new_from_file (&keydata, fname, 1); |
err = gpgme_data_new_from_file (&keydata, name, 1); |
615 |
if (err) { |
if (err) { |
616 |
msg_box (dlg, _("Could not read key-data from file."), |
msg_box (dlg, _("Could not read key-data from file."), |
617 |
_("Key Manager"), MB_ERR); |
_("Key Manager"), MB_ERR); |
627 |
} |
} |
628 |
|
|
629 |
res = gpgme_op_import_result (ctx); |
res = gpgme_op_import_result (ctx); |
630 |
if (res->unchanged == res->considered) |
if (res->unchanged == res->considered && |
631 |
|
res->secret_unchanged == res->secret_imported) |
632 |
no_data = 1; |
no_data = 1; |
633 |
if (r_newkeys) |
new_keys = res->considered - res->unchanged; |
634 |
*r_newkeys = res->considered - res->unchanged; |
new_sks = res->secret_imported - res->secret_unchanged; |
635 |
if (res->new_revocations == 0 && fm_stat.import.revcert == 1) |
if (res->new_revocations == 0 && fm_stat.import.revcert == 1) |
636 |
res->new_revocations = 1; |
res->new_revocations = 1; |
637 |
if (res->secret_imported == 0 && fm_stat.import.has_seckey == 1) |
if (res->secret_imported == 0 && fm_stat.import.has_seckey == 1) |
643 |
print_import_status (res); |
print_import_status (res); |
644 |
if (res->no_user_id > 0) { |
if (res->no_user_id > 0) { |
645 |
msg_box (dlg, _("Key without a self signature was dectected!\n" |
msg_box (dlg, _("Key without a self signature was dectected!\n" |
646 |
"(This key is NOT usable for encryption, etc)\n" |
"(This key is NOT usable for encryption, etc)\n"), |
647 |
"\n" |
_("Import"), MB_WARN); |
|
"Cannot import these key(s)!"), _("Import"), MB_INFO); |
|
648 |
} |
} |
649 |
|
|
650 |
leave: |
leave: |
651 |
gpgme_data_release (keydata); |
gpgme_data_release (keydata); |
652 |
gpgme_release (ctx); |
gpgme_release (ctx); |
653 |
free_if_alloc (fm_stat.opaque); |
free_if_alloc (fm_stat.opaque); |
654 |
|
if (r_newkeys) |
655 |
|
*r_newkeys = new_keys; |
656 |
|
if (r_newsks) |
657 |
|
*r_newsks = new_sks; |
658 |
if (no_data) |
if (no_data) |
659 |
return WPTERR_NODATA; |
return WPTERR_NODATA; |
660 |
return (int)err; |
return (int)err; |
876 |
km_refresh_one_key (listview_ctrl_t lv, HWND dlg, int pos, int flags) |
km_refresh_one_key (listview_ctrl_t lv, HWND dlg, int pos, int flags) |
877 |
{ |
{ |
878 |
gpgme_key_t key; |
gpgme_key_t key; |
879 |
int idx; |
char keyid[16+1]; |
880 |
|
int idx, err = 0; |
881 |
|
|
882 |
if (pos != 0) |
if (pos != 0) |
883 |
idx = pos; |
idx = pos; |
887 |
key = (gpgme_key_t)listview_get_item2 (lv, idx); |
key = (gpgme_key_t)listview_get_item2 (lv, idx); |
888 |
if (!key) |
if (!key) |
889 |
BUG (0); |
BUG (0); |
890 |
hkp_recv_key (dlg, default_keyserver, default_keyserver_port, |
_snprintf (keyid, sizeof (keyid)-1, "%s", key->subkeys->keyid+8); |
891 |
key->subkeys->keyid+8, 0, flags); |
err = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, |
892 |
|
keyid, 0, flags); |
893 |
|
/* if we receive just a single key (no refresh mode), update it. */ |
894 |
|
if (!flags && !err) |
895 |
|
keycache_update (0, keyid); |
896 |
} |
} |
897 |
} |
} |
898 |
|
|