40 |
#include "wptKeyManager.h" |
#include "wptKeyManager.h" |
41 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
42 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
43 |
|
#include "wptRegistry.h" |
44 |
|
|
45 |
|
|
46 |
char* get_reg_entry_keyserver (const char *); |
char* get_reg_entry_keyserver (const char *); |
173 |
keyserver_recv_key (HWND dlg, const char *kserver, WORD port, |
keyserver_recv_key (HWND dlg, const char *kserver, WORD port, |
174 |
const char *pattern, int proto, int flags, |
const char *pattern, int proto, int flags, |
175 |
char **r_fpr) |
char **r_fpr) |
176 |
{ |
{ |
|
gpgme_ctx_t ctx = NULL; |
|
|
gpgme_data_t keydata = NULL; |
|
177 |
gpgme_import_result_t import_res = NULL; |
gpgme_import_result_t import_res = NULL; |
178 |
gpgme_error_t err; |
gpgme_error_t err; |
179 |
|
GPGME *gpg = NULL; |
180 |
char *rawkey = NULL; |
char *rawkey = NULL; |
181 |
int keylen = 0; |
int keylen = 0; |
182 |
int rc; |
int rc; |
214 |
_("Keyserver"), MB_ERR); |
_("Keyserver"), MB_ERR); |
215 |
goto leave; |
goto leave; |
216 |
} |
} |
217 |
if (gpgme_new (&ctx)) |
gpg = new GPGME (); |
218 |
BUG (NULL); |
err = gpg->importFromBuffer (rawkey); |
|
gpgme_data_new_from_mem (&keydata, rawkey, strlen (rawkey), 1); |
|
|
err = gpgme_op_import (ctx, keydata); |
|
219 |
if (err) { |
if (err) { |
220 |
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
221 |
goto leave; |
goto leave; |
222 |
} |
} |
223 |
import_res = gpgme_op_import_result (ctx); |
import_res = gpg->importGetResult (); |
224 |
if (import_res && r_fpr) |
if (import_res && r_fpr) |
225 |
*r_fpr = m_strdup (import_res->imports->fpr); |
*r_fpr = m_strdup (import_res->imports->fpr); |
226 |
|
|
227 |
/* if we use the refresh mode, a lot of keys will be fetched and thus only |
/* if we use the refresh mode, a lot of keys will be fetched and thus only |
228 |
a summarize at the end is presented and not for each key. */ |
a summarize at the end is presented and not for each key. */ |
229 |
if (!(flags & KM_KS_REFRESH)) { |
if (import_res && !(flags & KM_KS_REFRESH)) { |
230 |
show_imported_keys (import_res); |
show_imported_keys (import_res); |
231 |
if (import_res && import_res->unchanged == import_res->considered) { |
if (import_res->unchanged == import_res->considered) { |
232 |
rc = WPTERR_GENERAL; /* no keys updated. */ |
rc = WPTERR_GENERAL; /* no keys updated. */ |
233 |
goto leave; |
goto leave; |
234 |
} |
} |
236 |
|
|
237 |
leave: |
leave: |
238 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
239 |
if (ctx != NULL) |
if (gpg != NULL) |
240 |
gpgme_release (ctx); |
delete gpg; |
|
if (keydata != NULL) |
|
|
gpgme_data_release (keydata); |
|
241 |
return rc; |
return rc; |
242 |
} |
} |
243 |
|
|
559 |
return FALSE; |
return FALSE; |
560 |
} |
} |
561 |
|
|
562 |
|
|
563 |
|
/* Add search pattern @patt to the combo box if it is |
564 |
|
not already available in the list. */ |
565 |
|
static void |
566 |
|
add_pattern_to_combox (HWND dlg, int ctlid, const char *patt) |
567 |
|
{ |
568 |
|
int err; |
569 |
|
|
570 |
|
err = SendDlgItemMessage (dlg, ctlid, CB_FINDSTRINGEXACT, |
571 |
|
0, (LPARAM)(LPCSTR)patt); |
572 |
|
if (err != CB_ERR) |
573 |
|
return; |
574 |
|
SendDlgItemMessage (dlg, IDC_KEYSERVER_SEARCH, CB_ADDSTRING, |
575 |
|
0, (LPARAM)(LPCSTR)patt); |
576 |
|
} |
577 |
|
|
578 |
|
static void |
579 |
|
load_pattern_to_combox (HWND dlg, int ctlid, const char *rkey_name) |
580 |
|
{ |
581 |
|
} |
582 |
|
|
583 |
|
static void |
584 |
|
save_pattern_from_combox (HWND dlg, int ctlid, const char *rkey_name) |
585 |
|
{ |
586 |
|
char *p, tmp[64]; |
587 |
|
int i; |
588 |
|
int n, len=0; |
589 |
|
|
590 |
|
n = SendDlgItemMessage (dlg, ctlid, CB_GETCOUNT, 0, 0); |
591 |
|
if (n == 0 || n == CB_ERR) |
592 |
|
return; |
593 |
|
/* it is very unlikely that the combox contain hundred of pattern |
594 |
|
but even so we limit the value to 16 which should be sufficient. */ |
595 |
|
if (n > 16) n = 16; |
596 |
|
for (i=0; i < n; i++) |
597 |
|
len += SendDlgItemMessage (dlg, ctlid, CB_GETLBTEXTLEN, |
598 |
|
(WPARAM)i, 0) + 1 + 1; |
599 |
|
p = new char[len+1]; |
600 |
|
memset (p, 0, len+1); |
601 |
|
for (i=0; i < n; i++) { |
602 |
|
memset (tmp, 0, sizeof (tmp)); |
603 |
|
SendDlgItemMessage (dlg, ctlid, CB_GETLBTEXT, |
604 |
|
(WPARAM)i, (LPARAM)tmp); |
605 |
|
strcat (p, tmp); |
606 |
|
strcat (p, "$"); |
607 |
|
} |
608 |
|
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", rkey_name, p); |
609 |
|
free_if_alloc (p); |
610 |
|
} |
611 |
|
|
612 |
|
|
613 |
/* Dialog box procedure to access keyservers. */ |
/* Dialog box procedure to access keyservers. */ |
614 |
BOOL CALLBACK |
BOOL CALLBACK |
615 |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
680 |
lv = NULL; |
lv = NULL; |
681 |
} |
} |
682 |
lv_idx = 0; |
lv_idx = 0; |
683 |
|
save_pattern_from_combox (dlg, IDC_KEYSERVER_SEARCH, "KSsearch"); |
684 |
return FALSE; |
return FALSE; |
685 |
|
|
686 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
703 |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
704 |
msg_box (dlg, _("Please enter the search pattern."), |
msg_box (dlg, _("Please enter the search pattern."), |
705 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
706 |
return FALSE; |
return TRUE; |
707 |
} |
} |
708 |
|
|
709 |
if (lv_idx != -1) { |
if (lv_idx != -1) { |
721 |
hkpsearch_dlg_proc, (LPARAM) &ksc); |
hkpsearch_dlg_proc, (LPARAM) &ksc); |
722 |
return TRUE; |
return TRUE; |
723 |
|
|
724 |
case IDC_KEYSERVER_RECV: |
case IDC_KEYSERVER_RECV: |
725 |
memset (&kserver, 0, sizeof (kserver)); |
memset (&kserver, 0, sizeof (kserver)); |
726 |
if (!lv_idx) { |
if (!lv_idx) { |
727 |
lv_idx = kserver_get_pos (lv); |
lv_idx = kserver_get_pos (lv); |
728 |
if (lv_idx == -1) { |
if (lv_idx == -1) { |
729 |
msg_box (dlg, _("Please select one of the keyservers."), |
msg_box (dlg, _("Please select one of the keyservers."), |
730 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
731 |
return FALSE; |
return TRUE; |
732 |
} |
} |
733 |
} |
} |
734 |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
746 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
747 |
return FALSE; |
return FALSE; |
748 |
} |
} |
749 |
|
add_pattern_to_combox (dlg, IDC_KEYSERVER_SEARCH, pattern); |
750 |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
751 |
msg_box (dlg, _("Only keyids are allowed."), |
msg_box (dlg, _("Only keyids are allowed."), |
752 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
756 |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
757 |
msg_box (dlg, _("Only enter the name of the user."), |
msg_box (dlg, _("Only enter the name of the user."), |
758 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
759 |
return FALSE; |
return TRUE; |
760 |
} |
} |
761 |
} |
} |
762 |
else if (check_pattern (pattern)) { |
else if (check_pattern (pattern)) { |
763 |
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
764 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
765 |
return FALSE; |
return TRUE; |
766 |
} |
} |
767 |
rc = keyserver_recv_key (dlg, kserver, kserver_get_port (lv), |
rc = keyserver_recv_key (dlg, kserver, kserver_get_port (lv), |
768 |
pattern, proto_nr, 0, |
pattern, proto_nr, 0, |