1 |
/* wptKeyserverDlg.cpp - Keyserver dialog |
/* wptKeyserverDlg.cpp - Keyserver dialog |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2005 Timo Schulz |
3 |
|
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
6 |
* |
* |
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 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
22 |
#include <config.h> |
#include <config.h> |
23 |
#endif |
#endif |
42 |
|
|
43 |
#define MAX_KEYSIZE 70000 |
#define MAX_KEYSIZE 70000 |
44 |
|
|
45 |
char * get_reg_entry_keyserver (const char *); |
char* get_reg_entry_keyserver (const char *); |
46 |
int set_reg_entry_keyserver (const char *, const char *); |
int set_reg_entry_keyserver (const char *, const char *); |
47 |
|
|
48 |
|
|
49 |
|
/* Print out keyserver error and a possible Winsock error. */ |
50 |
static void |
static void |
51 |
hkp_err_box (HWND dlg, const char * host, u16 port, int rc) |
hkp_err_box (HWND dlg, const char *host, WORD port, int rc) |
52 |
{ |
{ |
53 |
const char *err = kserver_strerror(); |
const char *err = kserver_strerror (); |
54 |
|
|
55 |
log_box( _("Keyserver"), MB_ERR, "%s:%d: %s", host, port, winpt_strerror (rc)); |
log_box (_("Keyserver"), MB_ERR, "%s:%d: %s", |
56 |
|
host, port, winpt_strerror (rc)); |
57 |
if (err) |
if (err) |
58 |
msg_box (dlg, err, wsock_strerror (), MB_ERR); |
msg_box (dlg, err, wsock_strerror (), MB_ERR); |
59 |
} /* hkp_err_box */ |
} |
60 |
|
|
61 |
|
|
62 |
|
/* Send the extracted key with keyid @pattern to the |
63 |
|
keyserver @kserver (port @port). |
64 |
|
Return value: 0 on success. */ |
65 |
int |
int |
66 |
hkp_send_key (HWND dlg, const char *kserver, u16 port, const char *pattern) |
hkp_send_key (HWND dlg, const char *kserver, WORD port, const char *pattern) |
67 |
{ |
{ |
68 |
gpgme_ctx_t c; |
gpgme_ctx_t ctx; |
69 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
70 |
gpgme_error_t ec; |
gpgme_error_t ec; |
71 |
char *rawkey = NULL, msg[1024]; |
char *rawkey = NULL; |
72 |
|
char msg[384]; |
73 |
size_t n; |
size_t n; |
|
int rc; |
|
74 |
|
|
75 |
ec = gpgme_new( &c ); |
ec = gpgme_new (&ctx); |
76 |
if( ec ) |
if (ec) |
77 |
BUG( NULL ); |
BUG (NULL); |
78 |
gpgme_set_armor (c, 1); |
gpgme_set_armor (ctx, 1); |
79 |
ec = gpgme_data_new( &keydata ); |
ec = gpgme_data_new (&keydata); |
80 |
if( ec ) |
if (ec) |
81 |
BUG( NULL ); |
BUG (NULL); |
82 |
rc = (int) gpgme_op_export( c, pattern, 0, keydata ); |
ec = gpgme_op_export (ctx, pattern, 0, keydata); |
83 |
if( rc ) { |
if (ec) { |
84 |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Export"), MB_ERR ); |
msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR); |
85 |
goto leave; |
goto leave; |
86 |
} |
} |
87 |
rawkey = gpgme_data_release_and_get_mem (keydata, &n); |
rawkey = gpgme_data_release_and_get_mem (keydata, &n); |
88 |
rc = kserver_sendkey (kserver, port, rawkey, n); |
ec = kserver_sendkey (kserver, port, rawkey, n); |
89 |
if (rc) { |
if (ec) { |
90 |
hkp_err_box (dlg, kserver, port, rc); |
hkp_err_box (dlg, kserver, port, ec); |
91 |
goto leave; |
goto leave; |
92 |
} |
} |
93 |
|
|
95 |
status_box (dlg, msg, _("GnuPG status")); |
status_box (dlg, msg, _("GnuPG status")); |
96 |
|
|
97 |
leave: |
leave: |
98 |
gpgme_release (c); |
gpgme_release (ctx); |
99 |
if (rawkey) |
if (rawkey) |
100 |
gpgme_free (rawkey); |
gpgme_free (rawkey); |
101 |
return rc; |
return ec? -1 : 0; |
102 |
} /* hkp_send_key */ |
} |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
/* If the keyserver returned one than more key in a |
107 |
|
keyblob, show the names of all imported keys. */ |
108 |
|
static void |
109 |
|
show_imported_keys (gpgme_import_result_t res) |
110 |
|
{ |
111 |
|
gpgme_import_status_t t; |
112 |
|
gpgme_key_t key; |
113 |
|
gpgme_data_t msg; |
114 |
|
gpgme_ctx_t ctx; |
115 |
|
gpgme_error_t err; |
116 |
|
const char *s; |
117 |
|
char *p; |
118 |
|
size_t n=0; |
119 |
|
|
120 |
|
err = gpgme_data_new (&msg); |
121 |
|
if (err) |
122 |
|
BUG (NULL); |
123 |
|
err = gpgme_new (&ctx); |
124 |
|
if (err) |
125 |
|
BUG (NULL); |
126 |
|
s = _("WARNING: multiple keys matched request.\n\n"); |
127 |
|
gpgme_data_write (msg, s, strlen (s)); |
128 |
|
for (t=res->imports; t; t = t->next) { |
129 |
|
if (!gpgme_get_key (ctx, t->fpr, &key, 0)) { |
130 |
|
s = key->uids->uid; |
131 |
|
gpgme_data_write (msg, s, strlen (s)); |
132 |
|
gpgme_data_write (msg, "\n", 1); |
133 |
|
gpgme_key_release (key); |
134 |
|
} |
135 |
|
} |
136 |
|
gpgme_data_write (msg, "\0", 1); |
137 |
|
p = gpgme_data_release_and_get_mem (msg, &n); |
138 |
|
if (p != NULL) { |
139 |
|
msg_box (NULL, p, _("Imported Keys"), MB_INFO); |
140 |
|
gpgme_free (p); |
141 |
|
} |
142 |
|
gpgme_release (ctx); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
/* Receive a key from the keyserver @kserver (port @port) |
147 |
|
with the pattern @pattern. |
148 |
|
Return value: 0 on success. */ |
149 |
int |
int |
150 |
hkp_recv_key (HWND dlg, const char *kserver, u16 port, |
hkp_recv_key2 (HWND dlg, const char *kserver, WORD port, |
151 |
const char *pattern, int proto, int flags) |
const char *pattern, int proto, int flags, |
152 |
|
char **r_fpr) |
153 |
{ |
{ |
154 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
155 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
156 |
gpgme_error_t ec; |
gpgme_error_t ec; |
157 |
gpgme_import_result_t import_res = NULL; |
gpgme_import_result_t import_res = NULL; |
158 |
|
char *rawkey = NULL; |
159 |
|
char msg[384]; |
160 |
int rc; |
int rc; |
|
char *rawkey = NULL, msg[384]; |
|
161 |
|
|
162 |
|
/* XXX: implement dynamic buffers. */ |
163 |
rawkey = new char[MAX_KEYSIZE]; |
rawkey = new char[MAX_KEYSIZE]; |
164 |
if (!rawkey) |
if (!rawkey) |
165 |
BUG (0); |
BUG (0); |
166 |
memset (rawkey, 0, MAX_KEYSIZE); |
memset (rawkey, 0, MAX_KEYSIZE); |
167 |
if( proto == KSPROTO_LDAP ) { |
if (proto == KSPROTO_LDAP) { |
168 |
rc = ldap_recvkey( kserver, pattern, rawkey, MAX_KEYSIZE-1 ); |
rc = ldap_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
169 |
if( rc ) { |
if (rc) { |
170 |
msg_box( dlg, _("LDAP key import failed.\n" |
msg_box (dlg, _("LDAP key import failed.\n" |
171 |
"Please make sure you have an online connection" |
"Please make sure you have an online connection" |
172 |
" and gpgkeys_ldap.exe is installed"), |
" and gpgkeys_ldap.exe is installed"), |
173 |
_("Keyserver"), MB_ERR ); |
_("Keyserver"), MB_ERR); |
174 |
free_if_alloc( rawkey ); |
free_if_alloc (rawkey); |
175 |
return rc; |
return rc; |
176 |
} |
} |
177 |
} |
} |
178 |
else if (proto == KSPROTO_FINGER) { |
else if (proto == KSPROTO_FINGER) { |
179 |
rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
180 |
if (rc) { |
if (rc) { |
181 |
log_box (_("Keyserver"), MB_ERR, _("Finger key import failed: %s\n"), |
log_box (_("Keyserver"), MB_ERR, |
182 |
winpt_strerror (rc)); |
_("Finger key import failed: %s\n"), winpt_strerror (rc)); |
183 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
184 |
return rc; |
return rc; |
185 |
} |
} |
186 |
} |
} |
187 |
else if( ( rc = kserver_recvkey( kserver, port, kserver_check_keyid( pattern ), |
else if ((rc = kserver_recvkey (kserver, port, |
188 |
rawkey, MAX_KEYSIZE-1 ) ) ) { |
kserver_check_keyid (pattern), |
189 |
|
rawkey, MAX_KEYSIZE-1))) { |
190 |
hkp_err_box (dlg, kserver, port, rc); |
hkp_err_box (dlg, kserver, port, rc); |
191 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
192 |
return rc; |
return rc; |
193 |
} |
} |
194 |
else { |
else { |
195 |
if( !strstr( rawkey, "BEGIN PGP PUBLIC KEY BLOCK" ) ) { |
if (!strstr (rawkey, "BEGIN PGP PUBLIC KEY BLOCK")) { |
196 |
msg_box( dlg, _("This is not a valid OpenPGP key."), _("Keyserver"), MB_ERR ); |
msg_box (dlg, _("This is not a valid OpenPGP key."), |
197 |
|
_("Keyserver"), MB_ERR); |
198 |
goto leave; |
goto leave; |
199 |
} |
} |
200 |
ec = gpgme_new( &ctx ); |
ec = gpgme_new (&ctx); |
201 |
if( ec ) |
if (ec) |
202 |
BUG( NULL ); |
BUG (NULL); |
203 |
gpgme_data_new_from_mem( &keydata, rawkey, strlen( rawkey ), 1 ); |
gpgme_data_new_from_mem (&keydata, rawkey, strlen (rawkey), 1); |
204 |
rc = gpgme_op_import( ctx, keydata ); |
rc = gpgme_op_import (ctx, keydata); |
205 |
if( rc ) { |
if (rc) { |
206 |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Import"), MB_ERR ); |
msg_box (dlg, gpgme_strerror ((gpgme_error_t)rc), _("Import"), MB_ERR); |
207 |
goto leave; |
goto leave; |
208 |
} |
} |
209 |
import_res = gpgme_op_import_result (ctx); |
import_res = gpgme_op_import_result (ctx); |
210 |
|
if (import_res && r_fpr) |
211 |
|
*r_fpr = m_strdup (import_res->imports->fpr); |
212 |
} |
} |
213 |
|
|
214 |
/* 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 |
215 |
a summarize at the end is presented and not for each key. */ |
a summarize at the end is presented and not for each key. */ |
216 |
if (!(flags & KM_KS_REFRESH)) { |
if (!(flags & KM_KS_REFRESH)) { |
217 |
if (import_res && import_res->new_user_ids == 0) { |
if (import_res && import_res->considered > 1) |
218 |
|
show_imported_keys (import_res); |
219 |
|
if (import_res && import_res->unchanged == import_res->considered) { |
220 |
_snprintf (msg, DIM (msg)-1, |
_snprintf (msg, DIM (msg)-1, |
221 |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
222 |
status_box (dlg, msg, _("GnuPG Status")); |
status_box (dlg, msg, _("GnuPG Status")); |
233 |
gpgme_data_release (keydata); |
gpgme_data_release (keydata); |
234 |
|
|
235 |
return rc; |
return rc; |
236 |
} /* hkp_recv_key */ |
} |
237 |
|
|
238 |
|
|
239 |
#define my_iskeychar(a) ( ( (a) >='0' && (a) <= '9' ) || ( (a) >= 'A' && (a) <= 'F' ) ) |
/* Alias for hkp_recv_key2 but without the ability to return |
240 |
|
the fingerprint of the key. */ |
241 |
|
int |
242 |
|
hkp_recv_key (HWND dlg, const char *kserver, WORD port, |
243 |
|
const char *pattern, int proto, int flags) |
244 |
|
{ |
245 |
|
return hkp_recv_key2 (dlg, kserver, port, pattern, proto, flags, NULL); |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
|
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
250 |
|
|
251 |
static int |
static int |
252 |
check_pattern( const char *pattern ) |
check_pattern (const char *pattern) |
253 |
{ |
{ |
254 |
int rc = 1; |
int rc = 1; |
255 |
|
|
256 |
/* Whitespace are not allowed! */ |
/* Whitespace are not allowed! */ |
257 |
if( strchr( pattern, ' ') ) { |
if (strchr( pattern, ' ')) { |
258 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
259 |
goto leave; |
goto leave; |
260 |
} |
} |
261 |
|
|
262 |
if( (( strstr( pattern, "0x" ) ) && ( strlen( pattern ) == 10 ) ) |
if (((strstr (pattern, "0x")) && (strlen (pattern) == 10)) || |
263 |
|| (strstr(pattern, "0x")) && ( strlen( pattern ) == 18 ) ) { |
(strstr(pattern, "0x")) && (strlen (pattern) == 18)) { |
264 |
rc = 0; |
rc = 0; /* Either long or short keyid */ |
265 |
goto leave; |
goto leave; |
266 |
} |
} |
267 |
|
|
284 |
static void |
static void |
285 |
set_proxy (HWND dlg) |
set_proxy (HWND dlg) |
286 |
{ |
{ |
287 |
char proxy[384]; |
char proxy[256]; |
288 |
int port = 0; |
int port = 0; |
289 |
|
|
290 |
strcpy (proxy, "HTTP proxy: "); |
strcpy (proxy, "HTTP proxy: "); |
291 |
if (kserver_get_proxy (&port)) { |
if (kserver_get_proxy (&port)) { |
292 |
char t[256]; |
char t[128]; |
293 |
const char *http = kserver_get_proxy (&port); |
const char *http = kserver_get_proxy (&port); |
294 |
_snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port); |
_snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port); |
295 |
strcat (proxy, t); |
strcat (proxy, t); |
296 |
} |
} |
297 |
else |
else |
298 |
strcat( proxy, "none" ); |
strcat (proxy, "none"); |
299 |
SetDlgItemText( dlg, IDC_KEYSERVER_PROXY, proxy ); |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXY, proxy); |
300 |
} /* set_proxy */ |
} /* set_proxy */ |
301 |
|
|
302 |
|
|
413 |
} |
} |
414 |
|
|
415 |
|
|
416 |
|
/* Dialog box procedure to access keyservers. */ |
417 |
BOOL CALLBACK |
BOOL CALLBACK |
418 |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
419 |
{ |
{ |
420 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
421 |
static int lv_idx = 0; |
static int lv_idx = 0; |
422 |
int rc, proto_nr = 0; |
static struct genkey_s *key; |
|
char kserver[128], pattern[128]; |
|
|
char proto[16]; |
|
423 |
keyserver_ctx ksc; |
keyserver_ctx ksc; |
424 |
|
char kserver[128], pattern[128]; |
425 |
|
char proto[16]; |
426 |
|
int rc, proto_nr = 0; |
427 |
|
|
428 |
switch ( msg ) { |
switch (msg) { |
429 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
430 |
|
if (lparam != 0) |
431 |
|
key = (struct genkey_s*)lparam; |
432 |
SetWindowText (dlg, _("Keyserver Access")); |
SetWindowText (dlg, _("Keyserver Access")); |
433 |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
434 |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
438 |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
439 |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
440 |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
441 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
442 |
|
|
443 |
set_proxy (dlg); |
set_proxy (dlg); |
444 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
449 |
case WM_NOTIFY: |
case WM_NOTIFY: |
450 |
NMHDR *notify; |
NMHDR *notify; |
451 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
452 |
if( notify && notify->code == NM_CLICK |
if (notify && notify->code == NM_CLICK |
453 |
&& notify->idFrom == IDC_KEYSERVER_LIST ) |
&& notify->idFrom == IDC_KEYSERVER_LIST) |
454 |
lv_idx = listview_get_curr_pos( lv ); |
lv_idx = listview_get_curr_pos (lv); |
455 |
return TRUE; |
return TRUE; |
456 |
|
|
457 |
case WM_DESTROY: |
case WM_DESTROY: |
458 |
if( lv ) { |
if (lv) { |
459 |
listview_release( lv ); |
listview_release (lv); |
460 |
lv = NULL; |
lv = NULL; |
461 |
} |
} |
462 |
lv_idx = 0; |
lv_idx = 0; |
463 |
return FALSE; |
return FALSE; |
464 |
|
|
465 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
466 |
if( LOWORD( wparam ) == SC_CLOSE ) |
if (LOWORD (wparam) == SC_CLOSE) |
467 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
468 |
return FALSE; |
return FALSE; |
469 |
|
|
470 |
case WM_COMMAND: |
case WM_COMMAND: |
471 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
472 |
case IDC_KEYSERVER_PROXSETT: |
case IDC_KEYSERVER_PROXSETT: |
473 |
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, glob_hwnd, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, |
474 |
keyserver_proxy_dlg_proc, 0, |
dlg, keyserver_proxy_dlg_proc, NULL, |
475 |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY ); |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY); |
476 |
set_proxy( dlg ); |
set_proxy (dlg); |
477 |
return TRUE; |
return TRUE; |
478 |
|
|
479 |
case IDC_KEYSERVER_INDEX: |
case IDC_KEYSERVER_INDEX: |
480 |
if (!lv_idx) { |
if (!lv_idx) { |
481 |
lv_idx = kserver_get_pos (lv); |
lv_idx = kserver_get_pos (lv); |
482 |
if (lv_idx == -1) { |
if (lv_idx == -1) { |
483 |
msg_box (dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO); |
msg_box (dlg, _("Please select one of the keyservers."), |
484 |
|
_("Keyserver"), MB_INFO); |
485 |
return FALSE; |
return FALSE; |
486 |
} |
} |
487 |
} |
} |
488 |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
489 |
if (*proto == 'L') { |
if (*proto == 'L') { |
490 |
msg_box( dlg, _("This is not implemented yet!"), _("Keyserver"), MB_ERR ); |
msg_box (dlg, _("This is not implemented yet!"), |
491 |
|
_("Keyserver"), MB_ERR); |
492 |
return FALSE; |
return FALSE; |
493 |
} |
} |
494 |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
495 |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
496 |
msg_box (dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO); |
msg_box (dlg, _("Please enter the search pattern."), |
497 |
|
_("Keyserver"), MB_INFO); |
498 |
return FALSE; |
return FALSE; |
499 |
} |
} |
500 |
ksc.name = kserver; |
ksc.name = kserver; |
501 |
ksc.pattern = pattern; |
ksc.pattern = pattern; |
502 |
ksc.port = kserver_get_port (lv); |
ksc.port = kserver_get_port (lv); |
503 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
504 |
hkpsearch_dlg_proc, (LPARAM) &ksc ); |
hkpsearch_dlg_proc, (LPARAM) &ksc); |
505 |
return TRUE; |
return TRUE; |
506 |
|
|
507 |
case IDC_KEYSERVER_RECV: |
case IDC_KEYSERVER_RECV: |
509 |
if (!lv_idx) { |
if (!lv_idx) { |
510 |
lv_idx = kserver_get_pos (lv); |
lv_idx = kserver_get_pos (lv); |
511 |
if (lv_idx == -1) { |
if (lv_idx == -1) { |
512 |
msg_box( dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO ); |
msg_box (dlg, _("Please select one of the keyservers."), |
513 |
|
_("Keyserver"), MB_INFO); |
514 |
return FALSE; |
return FALSE; |
515 |
} |
} |
516 |
} |
} |
517 |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
518 |
proto_nr = KSPROTO_HTTP; |
proto_nr = KSPROTO_HTTP; |
519 |
if( *proto == 'L' ) |
if (*proto == 'L') |
520 |
proto_nr = KSPROTO_LDAP; |
proto_nr = KSPROTO_LDAP; |
521 |
else if( *proto == 'F' ) |
else if (*proto == 'F') |
522 |
proto_nr = KSPROTO_FINGER; |
proto_nr = KSPROTO_FINGER; |
523 |
listview_get_item_text( lv, lv_idx, 0, kserver, sizeof (kserver)-1 ); |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
524 |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1 ) ) { |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
525 |
msg_box( dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO ); |
msg_box (dlg, _("Please enter the search pattern."), |
526 |
|
_("Keyserver"), MB_INFO); |
527 |
return FALSE; |
return FALSE; |
528 |
} |
} |
529 |
if( proto_nr == KSPROTO_LDAP && strchr( pattern, '@' ) ) { |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
530 |
msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO ); |
msg_box (dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO); |
531 |
return FALSE; |
return FALSE; |
532 |
} |
} |
533 |
else if (proto_nr == KSPROTO_FINGER) { |
else if (proto_nr == KSPROTO_FINGER) { |
534 |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
535 |
msg_box (dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO); |
msg_box (dlg, _("Only enter the name of the user."), |
536 |
|
_("FINGER Keyserver"), MB_INFO); |
537 |
return FALSE; |
return FALSE; |
538 |
} |
} |
539 |
} |
} |
540 |
else if( check_pattern( pattern ) ) { |
else if (check_pattern (pattern)) { |
541 |
msg_box( dlg, _("Only email addresses or keyids are allowed."), _("HKP Keyserver"), MB_INFO ); |
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
542 |
|
_("HKP Keyserver"), MB_INFO); |
543 |
return FALSE; |
return FALSE; |
544 |
} |
} |
545 |
rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0); |
rc = hkp_recv_key2 (dlg, kserver, kserver_get_port (lv), |
546 |
if (!rc) |
pattern, proto_nr, 0, key? &key->fpr : NULL); |
547 |
keycache_set_reload (1); |
if (!rc && key->fpr != NULL) { |
548 |
|
keycache_update (0, key->fpr); |
549 |
|
get_pubkey (key->fpr, &key->newkey); |
550 |
|
/* we do not need the fingerprint any longer. */ |
551 |
|
free_if_alloc (key->fpr); |
552 |
|
} |
553 |
return TRUE; |
return TRUE; |
554 |
|
|
555 |
case IDC_KEYSERVER_DEFAULT: |
case IDC_KEYSERVER_DEFAULT: |
556 |
save_default_ks( lv ); |
save_default_ks (lv); |
557 |
break; |
break; |
558 |
|
|
559 |
case IDCANCEL: |
case IDCANCEL: |
560 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
561 |
return FALSE; |
return FALSE; |
562 |
} |
} |
563 |
break; |
break; |
564 |
} |
} |
565 |
|
|
566 |
return FALSE; |
return FALSE; |
567 |
} /* keyserver_dlg_proc */ |
} |