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 |
24 |
|
|
25 |
#include <windows.h> |
#include <windows.h> |
|
#include <windows.h> |
|
26 |
#include <commctrl.h> |
#include <commctrl.h> |
27 |
#include <malloc.h> |
#include <malloc.h> |
28 |
|
|
29 |
#include "../resource.h" |
#include "resource.h" |
30 |
#include "wptKeyserver.h" |
#include "wptKeyserver.h" |
31 |
#include "wptErrors.h" |
#include "wptErrors.h" |
32 |
#include "wptTypes.h" |
#include "wptTypes.h" |
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 |
|
/* Show all received keys from the keyserver. */ |
107 |
|
static void |
108 |
|
show_imported_keys (gpgme_import_result_t res) |
109 |
|
{ |
110 |
|
gpgme_import_status_t t; |
111 |
|
gpgme_key_t key; |
112 |
|
gpgme_data_t msg; |
113 |
|
gpgme_ctx_t ctx; |
114 |
|
gpgme_error_t err; |
115 |
|
const char *s; |
116 |
|
char *p; |
117 |
|
size_t n=0; |
118 |
|
|
119 |
|
if (!res) |
120 |
|
return; |
121 |
|
|
122 |
|
err = gpgme_data_new (&msg); |
123 |
|
if (err) |
124 |
|
BUG (NULL); |
125 |
|
err = gpgme_new (&ctx); |
126 |
|
if (err) |
127 |
|
BUG (NULL); |
128 |
|
if (res->considered > 1) { |
129 |
|
s = _("WARNING: multiple keys matched request.\n\n"); |
130 |
|
gpgme_data_write (msg, s, strlen (s)); |
131 |
|
} |
132 |
|
|
133 |
|
if (res->unchanged == res->considered) |
134 |
|
s = _("Key(s) successfully received but nothing was changed."); |
135 |
|
else |
136 |
|
s = _("Key(s) sucessfully received and imported."); |
137 |
|
gpgme_data_write (msg, s, strlen (s)); |
138 |
|
gpgme_data_write (msg, "\n\n", 2); |
139 |
|
|
140 |
|
for (t=res->imports; t; t = t->next) { |
141 |
|
if (!gpgme_get_key (ctx, t->fpr, &key, 0)) { |
142 |
|
s = key->uids->uid; |
143 |
|
gpgme_data_write (msg, s, strlen (s)); |
144 |
|
gpgme_data_write (msg, "\n", 1); |
145 |
|
gpgme_key_release (key); |
146 |
|
} |
147 |
|
} |
148 |
|
gpgme_data_write (msg, "\0", 1); |
149 |
|
p = gpgme_data_release_and_get_mem (msg, &n); |
150 |
|
if (p != NULL) { |
151 |
|
msg_box (NULL, p, _("Imported Keys"), MB_INFO); |
152 |
|
gpgme_free (p); |
153 |
|
} |
154 |
|
gpgme_release (ctx); |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
|
/* Receive a key from the keyserver @kserver (port @port) |
159 |
|
with the pattern @pattern. |
160 |
|
Return value: 0 on success. */ |
161 |
int |
int |
162 |
hkp_recv_key (HWND dlg, const char *kserver, u16 port, |
hkp_recv_key2 (HWND dlg, const char *kserver, WORD port, |
163 |
const char *pattern, int proto, int flags) |
const char *pattern, int proto, int flags, |
164 |
|
char **r_fpr) |
165 |
{ |
{ |
166 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
167 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
168 |
gpgme_error_t ec; |
gpgme_error_t ec; |
169 |
gpgme_import_result_t import_res; |
gpgme_import_result_t import_res = NULL; |
170 |
|
char *rawkey = NULL; |
171 |
int rc; |
int rc; |
|
char *rawkey = NULL, msg[384]; |
|
172 |
|
|
173 |
|
/* XXX: implement dynamic buffers. */ |
174 |
rawkey = new char[MAX_KEYSIZE]; |
rawkey = new char[MAX_KEYSIZE]; |
175 |
if (!rawkey) |
if (!rawkey) |
176 |
BUG (0); |
BUG (0); |
177 |
memset (rawkey, 0, MAX_KEYSIZE); |
memset (rawkey, 0, MAX_KEYSIZE); |
178 |
if( proto == KSPROTO_LDAP ) { |
if (proto == KSPROTO_LDAP) { |
179 |
rc = ldap_recvkey( kserver, pattern, rawkey, MAX_KEYSIZE-1 ); |
rc = ldap_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
180 |
if( rc ) { |
if (rc) { |
181 |
msg_box( dlg, _("LDAP key import failed.\n" |
msg_box (dlg, _("LDAP key import failed.\n" |
182 |
"Please make sure you have an online connection" |
"Please make sure you have an online connection" |
183 |
" and gpgkeys_ldap.exe is installed"), |
" and gpgkeys_ldap.exe is installed"), |
184 |
_("Keyserver"), MB_ERR ); |
_("Keyserver"), MB_ERR); |
185 |
free_if_alloc( rawkey ); |
free_if_alloc (rawkey); |
186 |
return rc; |
return rc; |
187 |
} |
} |
188 |
} |
} |
189 |
else if (proto == KSPROTO_FINGER) { |
else if (proto == KSPROTO_FINGER) { |
190 |
rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
191 |
if (rc) { |
if (rc) { |
192 |
log_box (_("Keyserver"), MB_ERR, _("Finger key import failed: %s\n"), |
log_box (_("Keyserver"), MB_ERR, |
193 |
winpt_strerror (rc)); |
_("Finger key import failed: %s\n"), winpt_strerror (rc)); |
194 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
195 |
return rc; |
return rc; |
196 |
} |
} |
197 |
} |
} |
198 |
else if( ( rc = kserver_recvkey( kserver, port, kserver_check_keyid( pattern ), |
else if ((rc = kserver_recvkey (kserver, port, |
199 |
rawkey, MAX_KEYSIZE-1 ) ) ) { |
kserver_check_keyid (pattern), |
200 |
|
rawkey, MAX_KEYSIZE-1))) { |
201 |
hkp_err_box (dlg, kserver, port, rc); |
hkp_err_box (dlg, kserver, port, rc); |
202 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
203 |
return rc; |
return rc; |
204 |
} |
} |
205 |
else { |
else { |
206 |
if( !strstr( rawkey, "BEGIN PGP PUBLIC KEY BLOCK" ) ) { |
if (!strstr (rawkey, "BEGIN PGP PUBLIC KEY BLOCK")) { |
207 |
msg_box( dlg, _("This is not a valid OpenPGP key."), _("Keyserver"), MB_ERR ); |
msg_box (dlg, _("This is not a valid OpenPGP key."), |
208 |
|
_("Keyserver"), MB_ERR); |
209 |
goto leave; |
goto leave; |
210 |
} |
} |
211 |
ec = gpgme_new( &ctx ); |
ec = gpgme_new (&ctx); |
212 |
if( ec ) |
if (ec) |
213 |
BUG( NULL ); |
BUG (NULL); |
214 |
gpgme_data_new_from_mem( &keydata, rawkey, strlen( rawkey ), 1 ); |
gpgme_data_new_from_mem (&keydata, rawkey, strlen (rawkey), 1); |
215 |
rc = gpgme_op_import( ctx, keydata ); |
rc = gpgme_op_import (ctx, keydata); |
216 |
if( rc ) { |
if (rc) { |
217 |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Import"), MB_ERR ); |
msg_box (dlg, gpgme_strerror ((gpgme_error_t)rc), _("Import"), MB_ERR); |
218 |
goto leave; |
goto leave; |
219 |
} |
} |
220 |
import_res = gpgme_op_import_result (ctx); |
import_res = gpgme_op_import_result (ctx); |
221 |
|
if (import_res && r_fpr) |
222 |
|
*r_fpr = m_strdup (import_res->imports->fpr); |
223 |
} |
} |
224 |
|
|
225 |
/* 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 |
226 |
a summarize at the end is presented and not for each key. */ |
a summarize at the end is presented and not for each key. */ |
227 |
if (!(flags & KM_KS_REFRESH)) { |
if (!(flags & KM_KS_REFRESH)) { |
228 |
if (import_res->new_user_ids == 0) { |
show_imported_keys (import_res); |
229 |
_snprintf (msg, DIM (msg)-1, |
if (import_res && import_res->unchanged == import_res->considered) { |
230 |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
rc = WPTERR_GENERAL; /* no keys updated. */ |
|
status_box (dlg, msg, _("GnuPG Status")); |
|
|
rc = WPTERR_GENERAL; |
|
231 |
goto leave; |
goto leave; |
232 |
} |
} |
|
_snprintf (msg, DIM (msg)-1, _("Key '%s' sucessfully received and imported."), pattern); |
|
|
status_box (dlg, msg, _("GnuPG Status")); |
|
233 |
} |
} |
234 |
|
|
235 |
leave: |
leave: |
236 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
237 |
gpgme_release (ctx); |
gpgme_release (ctx); |
238 |
gpgme_data_release (keydata); |
gpgme_data_release (keydata); |
239 |
|
|
240 |
return rc; |
return rc; |
241 |
} /* hkp_recv_key */ |
} |
242 |
|
|
243 |
|
|
244 |
|
/* Alias for hkp_recv_key2 but without the ability to return |
245 |
|
the fingerprint of the key. */ |
246 |
|
int |
247 |
|
hkp_recv_key (HWND dlg, const char *kserver, WORD port, |
248 |
|
const char *pattern, int proto, int flags) |
249 |
|
{ |
250 |
|
return hkp_recv_key2 (dlg, kserver, port, pattern, proto, flags, NULL); |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
#define my_iskeychar(a) ( ( (a) >='0' && (a) <= '9' ) || ( (a) >= 'A' && (a) <= 'F' ) ) |
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
255 |
|
|
256 |
static int |
static int |
257 |
check_pattern( const char *pattern ) |
check_pattern (const char *pattern) |
258 |
{ |
{ |
259 |
int rc = 1; |
int rc = 1; |
260 |
|
|
261 |
/* Whitespace are not allowed! */ |
/* Whitespace are not allowed! */ |
262 |
if( strchr( pattern, ' ') ) { |
if (strchr( pattern, ' ')) { |
263 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
264 |
goto leave; |
goto leave; |
265 |
} |
} |
266 |
|
|
267 |
if( (( strstr( pattern, "0x" ) ) && ( strlen( pattern ) == 10 ) ) |
if (((strstr (pattern, "0x")) && (strlen (pattern) == 10)) || |
268 |
|| (strstr(pattern, "0x")) && ( strlen( pattern ) == 18 ) ) { |
(strstr(pattern, "0x")) && (strlen (pattern) == 18)) { |
269 |
rc = 0; |
rc = 0; /* Either long or short keyid */ |
270 |
goto leave; |
goto leave; |
271 |
} |
} |
272 |
|
|
289 |
static void |
static void |
290 |
set_proxy (HWND dlg) |
set_proxy (HWND dlg) |
291 |
{ |
{ |
292 |
char proxy[384]; |
char proxy[256]; |
293 |
int port = 0; |
int port = 0; |
294 |
|
|
295 |
strcpy (proxy, "HTTP proxy: "); |
strcpy (proxy, "HTTP proxy: "); |
296 |
if (kserver_get_proxy (&port)) { |
if (kserver_get_proxy (&port)) { |
297 |
char t[256]; |
char t[128]; |
298 |
const char *http = kserver_get_proxy (&port); |
const char *http = kserver_get_proxy (&port); |
299 |
_snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port); |
_snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port); |
300 |
strcat (proxy, t); |
strcat (proxy, t); |
301 |
} |
} |
302 |
else |
else |
303 |
strcat( proxy, "none" ); |
strcat (proxy, "none"); |
304 |
SetDlgItemText( dlg, IDC_KEYSERVER_PROXY, proxy ); |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXY, proxy); |
305 |
} /* set_proxy */ |
} /* set_proxy */ |
306 |
|
|
307 |
|
|
418 |
} |
} |
419 |
|
|
420 |
|
|
421 |
|
/* Dialog box procedure to access keyservers. */ |
422 |
BOOL CALLBACK |
BOOL CALLBACK |
423 |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
424 |
{ |
{ |
425 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
426 |
static int lv_idx = 0; |
static int lv_idx = 0; |
427 |
int rc, proto_nr = 0; |
static struct genkey_s *key; |
|
char kserver[128], pattern[128]; |
|
|
char proto[16]; |
|
428 |
keyserver_ctx ksc; |
keyserver_ctx ksc; |
429 |
|
char kserver[128], pattern[128]; |
430 |
|
char proto[16]; |
431 |
|
int rc, proto_nr = 0; |
432 |
|
|
433 |
switch ( msg ) { |
switch (msg) { |
434 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
435 |
#ifndef LANG_DE |
if (lparam != 0) |
436 |
|
key = (struct genkey_s*)lparam; |
437 |
SetWindowText (dlg, _("Keyserver Access")); |
SetWindowText (dlg, _("Keyserver Access")); |
438 |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
439 |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
443 |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
444 |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
445 |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
446 |
#endif |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
447 |
|
|
448 |
set_proxy (dlg); |
set_proxy (dlg); |
449 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
450 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
454 |
case WM_NOTIFY: |
case WM_NOTIFY: |
455 |
NMHDR *notify; |
NMHDR *notify; |
456 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
457 |
if( notify && notify->code == NM_CLICK |
if (notify && notify->code == NM_CLICK |
458 |
&& notify->idFrom == IDC_KEYSERVER_LIST ) |
&& notify->idFrom == IDC_KEYSERVER_LIST) |
459 |
lv_idx = listview_get_curr_pos( lv ); |
lv_idx = listview_get_curr_pos (lv); |
460 |
return TRUE; |
return TRUE; |
461 |
|
|
462 |
case WM_DESTROY: |
case WM_DESTROY: |
463 |
if( lv ) { |
if (lv) { |
464 |
listview_release( lv ); |
listview_release (lv); |
465 |
lv = NULL; |
lv = NULL; |
466 |
} |
} |
467 |
lv_idx = 0; |
lv_idx = 0; |
468 |
return FALSE; |
return FALSE; |
469 |
|
|
470 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
471 |
if( LOWORD( wparam ) == SC_CLOSE ) |
if (LOWORD (wparam) == SC_CLOSE) |
472 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
473 |
return FALSE; |
return FALSE; |
474 |
|
|
475 |
case WM_COMMAND: |
case WM_COMMAND: |
476 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
477 |
case IDC_KEYSERVER_PROXSETT: |
case IDC_KEYSERVER_PROXSETT: |
478 |
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, glob_hwnd, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, |
479 |
keyserver_proxy_dlg_proc, NULL, |
dlg, keyserver_proxy_dlg_proc, NULL, |
480 |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY ); |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY); |
481 |
set_proxy( dlg ); |
set_proxy (dlg); |
482 |
return TRUE; |
return TRUE; |
483 |
|
|
484 |
case IDC_KEYSERVER_INDEX: |
case IDC_KEYSERVER_INDEX: |
485 |
if (!lv_idx) { |
if (!lv_idx) { |
486 |
lv_idx = kserver_get_pos (lv); |
lv_idx = kserver_get_pos (lv); |
487 |
if (lv_idx == -1) { |
if (lv_idx == -1) { |
488 |
msg_box (dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO); |
msg_box (dlg, _("Please select one of the keyservers."), |
489 |
|
_("Keyserver"), MB_INFO); |
490 |
return FALSE; |
return FALSE; |
491 |
} |
} |
492 |
} |
} |
493 |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
494 |
if (*proto == 'L') { |
if (*proto == 'L') { |
495 |
msg_box( dlg, _("This is not implemented yet!"), _("Keyserver"), MB_ERR ); |
msg_box (dlg, _("This is not implemented yet!"), |
496 |
|
_("Keyserver"), MB_ERR); |
497 |
return FALSE; |
return FALSE; |
498 |
} |
} |
499 |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
500 |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
501 |
msg_box (dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO); |
msg_box (dlg, _("Please enter the search pattern."), |
502 |
|
_("Keyserver"), MB_INFO); |
503 |
return FALSE; |
return FALSE; |
504 |
} |
} |
505 |
ksc.name = kserver; |
ksc.name = kserver; |
506 |
ksc.pattern = pattern; |
ksc.pattern = pattern; |
507 |
ksc.port = kserver_get_port (lv); |
ksc.port = kserver_get_port (lv); |
508 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
509 |
hkpsearch_dlg_proc, (LPARAM) &ksc ); |
hkpsearch_dlg_proc, (LPARAM) &ksc); |
510 |
return TRUE; |
return TRUE; |
511 |
|
|
512 |
case IDC_KEYSERVER_RECV: |
case IDC_KEYSERVER_RECV: |
514 |
if (!lv_idx) { |
if (!lv_idx) { |
515 |
lv_idx = kserver_get_pos (lv); |
lv_idx = kserver_get_pos (lv); |
516 |
if (lv_idx == -1) { |
if (lv_idx == -1) { |
517 |
msg_box( dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO ); |
msg_box (dlg, _("Please select one of the keyservers."), |
518 |
|
_("Keyserver"), MB_INFO); |
519 |
return FALSE; |
return FALSE; |
520 |
} |
} |
521 |
} |
} |
522 |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
523 |
proto_nr = KSPROTO_HTTP; |
proto_nr = KSPROTO_HTTP; |
524 |
if( *proto == 'L' ) |
if (*proto == 'L') |
525 |
proto_nr = KSPROTO_LDAP; |
proto_nr = KSPROTO_LDAP; |
526 |
else if( *proto == 'F' ) |
else if (*proto == 'F') |
527 |
proto_nr = KSPROTO_FINGER; |
proto_nr = KSPROTO_FINGER; |
528 |
listview_get_item_text( lv, lv_idx, 0, kserver, sizeof (kserver)-1 ); |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
529 |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1 ) ) { |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
530 |
msg_box( dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO ); |
msg_box (dlg, _("Please enter the search pattern."), |
531 |
|
_("Keyserver"), MB_INFO); |
532 |
return FALSE; |
return FALSE; |
533 |
} |
} |
534 |
if( proto_nr == KSPROTO_LDAP && strchr( pattern, '@' ) ) { |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
535 |
msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO ); |
msg_box (dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO); |
536 |
return FALSE; |
return FALSE; |
537 |
} |
} |
538 |
else if (proto_nr == KSPROTO_FINGER) { |
else if (proto_nr == KSPROTO_FINGER) { |
539 |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
540 |
msg_box (dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO); |
msg_box (dlg, _("Only enter the name of the user."), |
541 |
|
_("FINGER Keyserver"), MB_INFO); |
542 |
return FALSE; |
return FALSE; |
543 |
} |
} |
544 |
} |
} |
545 |
else if( check_pattern( pattern ) ) { |
else if (check_pattern (pattern)) { |
546 |
msg_box( dlg, _("Only email addresses or keyids are allowed."), _("HKP Keyserver"), MB_INFO ); |
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
547 |
|
_("HKP Keyserver"), MB_INFO); |
548 |
return FALSE; |
return FALSE; |
549 |
} |
} |
550 |
rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0); |
rc = hkp_recv_key2 (dlg, kserver, kserver_get_port (lv), |
551 |
if (!rc) |
pattern, proto_nr, 0, key? &key->fpr : NULL); |
552 |
keycache_set_reload (1); |
if (!rc && key->fpr != NULL) { |
553 |
|
keycache_update (0, key->fpr); |
554 |
|
get_pubkey (key->fpr, &key->newkey); |
555 |
|
/* we do not need the fingerprint any longer. */ |
556 |
|
free_if_alloc (key->fpr); |
557 |
|
} |
558 |
return TRUE; |
return TRUE; |
559 |
|
|
560 |
case IDC_KEYSERVER_DEFAULT: |
case IDC_KEYSERVER_DEFAULT: |
561 |
save_default_ks( lv ); |
save_default_ks (lv); |
562 |
break; |
break; |
563 |
|
|
564 |
case IDCANCEL: |
case IDCANCEL: |
565 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
566 |
return FALSE; |
return FALSE; |
567 |
} |
} |
568 |
break; |
break; |
569 |
} |
} |
570 |
|
|
571 |
return FALSE; |
return FALSE; |
572 |
} /* keyserver_dlg_proc */ |
} |