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