1 |
/* wptKeyserverDlg.cpp - Keyserver dialog |
/* wptKeyserverDlg.cpp - Keyserver dialog |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
35 |
#include "wptW32API.h" |
#include "wptW32API.h" |
36 |
#include "wptVersion.h" |
#include "wptVersion.h" |
37 |
#include "wptGPG.h" |
#include "wptGPG.h" |
38 |
#include "wptKeyManager.h" |
#include "wptGPGME.h" |
39 |
#include "wptContext.h" /* for passphrase_s */ |
#include "wptContext.h" /* for passphrase_s */ |
40 |
|
#include "wptKeyManager.h" |
41 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
42 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
43 |
|
|
44 |
|
|
|
#define MAX_KEYSIZE 70000 |
|
|
|
|
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 |
|
enum { KS_COL_NAME = 0, KS_COL_PORT }; |
49 |
|
|
50 |
|
/* Callback context to modify (add, edit) keyserver items. */ |
51 |
|
struct keyserver_rec_s { |
52 |
|
char name[200]; /* hostname */ |
53 |
|
int proto; /* protocol */ |
54 |
|
int port; /* used port */ |
55 |
|
bool mode; /* true = edit */ |
56 |
|
bool cancel; |
57 |
|
}; |
58 |
|
typedef struct keyserver_rec_s *keyserver_rec_t; |
59 |
|
|
60 |
/* Print out keyserver error and a possible Winsock error. */ |
/* Print out keyserver error and a possible Winsock error. */ |
61 |
static void |
static void |
62 |
hkp_err_box (HWND dlg, const char *host, WORD port, int rc) |
hkp_err_box (HWND dlg, const char *host, WORD port, int rc) |
63 |
{ |
{ |
64 |
const char *err = kserver_strerror (); |
const char *err = kserver_strerror (); |
65 |
|
const char *ws_err = wsock_strerror (); |
66 |
log_box (_("Keyserver"), MB_ERR, "%s:%d: %s", |
|
67 |
host, port, winpt_strerror (rc)); |
if (ws_err && strlen (ws_err) > 0) |
68 |
if (err) |
log_box (_("Keyserver"), MB_ERR, "%s:%d: %s", host, port, ws_err); |
69 |
msg_box (dlg, err, wsock_strerror (), MB_ERR); |
else |
70 |
|
log_box (_("Keyserver"), MB_ERR, "%s:%d: %s\n%s", |
71 |
|
host, port, winpt_strerror (rc), err? err : ""); |
72 |
} |
} |
73 |
|
|
74 |
|
|
78 |
int |
int |
79 |
hkp_send_key (HWND dlg, const char *kserver, WORD port, const char *pattern) |
hkp_send_key (HWND dlg, const char *kserver, WORD port, const char *pattern) |
80 |
{ |
{ |
81 |
gpgme_ctx_t ctx; |
GPGME *gpg; |
|
gpgme_data_t keydata; |
|
82 |
gpgme_error_t ec; |
gpgme_error_t ec; |
83 |
char *rawkey = NULL; |
char *rawkey = NULL; |
84 |
char msg[384]; |
char msg[384]; |
|
size_t n; |
|
85 |
|
|
86 |
ec = gpgme_new (&ctx); |
gpg = new GPGME (); |
87 |
if (ec) |
gpg->setArmor (true); |
88 |
BUG (NULL); |
ec = gpg->exportToBuffer (pattern, &rawkey); |
|
gpgme_set_armor (ctx, 1); |
|
|
ec = gpgme_data_new (&keydata); |
|
|
if (ec) |
|
|
BUG (NULL); |
|
|
ec = gpgme_op_export (ctx, pattern, 0, keydata); |
|
89 |
if (ec) { |
if (ec) { |
90 |
msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR); |
msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR); |
91 |
goto leave; |
goto leave; |
92 |
} |
} |
93 |
rawkey = gpgme_data_release_and_get_mem (keydata, &n); |
op_begin (); |
94 |
ec = kserver_sendkey (kserver, port, rawkey, n); |
ec = kserver_sendkey (kserver, port, rawkey, strlen (rawkey)); |
95 |
|
op_end (); |
96 |
if (ec) { |
if (ec) { |
97 |
hkp_err_box (dlg, kserver, port, ec); |
hkp_err_box (dlg, kserver, port, ec); |
98 |
goto leave; |
goto leave; |
102 |
status_box (dlg, msg, _("GnuPG status")); |
status_box (dlg, msg, _("GnuPG status")); |
103 |
|
|
104 |
leave: |
leave: |
105 |
gpgme_release (ctx); |
delete gpg; |
106 |
if (rawkey) |
free_if_alloc (rawkey); |
|
gpgme_free (rawkey); |
|
107 |
return ec? -1 : 0; |
return ec? -1 : 0; |
108 |
} |
} |
109 |
|
|
145 |
|
|
146 |
for (t=res->imports; t; t = t->next) { |
for (t=res->imports; t; t = t->next) { |
147 |
if (!gpgme_get_key (ctx, t->fpr, &key, 0)) { |
if (!gpgme_get_key (ctx, t->fpr, &key, 0)) { |
148 |
s = uid = utf8_to_wincp2 (key->uids->uid); |
s = uid = utf8_to_native (key->uids->uid); |
149 |
gpgme_data_write (msg, s, strlen (s)); |
gpgme_data_write (msg, s, strlen (s)); |
150 |
gpgme_data_write (msg, "\n", 1); |
gpgme_data_write (msg, "\n", 1); |
151 |
gpgme_key_release (key); |
gpgme_key_release (key); |
172 |
{ |
{ |
173 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
174 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
175 |
gpgme_error_t ec; |
gpgme_import_result_t import_res = NULL; |
176 |
gpgme_import_result_t import_res = NULL; |
gpgme_error_t err; |
177 |
char *rawkey = NULL; |
char *rawkey = NULL; |
178 |
|
int keylen = 0; |
179 |
int rc; |
int rc; |
180 |
|
|
|
/* XXX: implement dynamic buffers. */ |
|
|
rawkey = new char[MAX_KEYSIZE]; |
|
|
if (!rawkey) |
|
|
BUG (0); |
|
|
memset (rawkey, 0, MAX_KEYSIZE); |
|
181 |
if (proto == KSPROTO_LDAP) { |
if (proto == KSPROTO_LDAP) { |
182 |
rc = ldap_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
rc = ldap_recvkey (kserver, pattern, &rawkey, &keylen); |
183 |
if (rc) { |
if (rc) { |
184 |
msg_box (dlg, _("LDAP key import failed.\n" |
msg_box (dlg, _("LDAP key import failed.\n" |
185 |
"Please make sure you have an online connection" |
"Please make sure you have an online connection" |
190 |
} |
} |
191 |
} |
} |
192 |
else if (proto == KSPROTO_FINGER) { |
else if (proto == KSPROTO_FINGER) { |
193 |
rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
rc = finger_recvkey (kserver, pattern, &rawkey, &keylen); |
194 |
if (rc) { |
if (rc) { |
195 |
log_box (_("Keyserver"), MB_ERR, |
log_box (_("Keyserver"), MB_ERR, |
196 |
_("Finger key import failed: %s\n"), winpt_strerror (rc)); |
_("Finger key import failed: %s\n"), winpt_strerror (rc)); |
200 |
} |
} |
201 |
else if ((rc = kserver_recvkey (kserver, port, |
else if ((rc = kserver_recvkey (kserver, port, |
202 |
kserver_check_keyid (pattern), |
kserver_check_keyid (pattern), |
203 |
rawkey, MAX_KEYSIZE-1))) { |
&rawkey, &keylen))) { |
204 |
hkp_err_box (dlg, kserver, port, rc); |
hkp_err_box (dlg, kserver, port, rc); |
205 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
206 |
return rc; |
return rc; |
207 |
} |
} |
208 |
else { |
|
209 |
if (!strstr (rawkey, "BEGIN PGP PUBLIC KEY BLOCK")) { |
if (!strstr (rawkey, "BEGIN PGP PUBLIC KEY BLOCK")) { |
210 |
msg_box (dlg, _("This is not a valid OpenPGP key."), |
msg_box (dlg, _("This is not a valid OpenPGP key."), |
211 |
_("Keyserver"), MB_ERR); |
_("Keyserver"), MB_ERR); |
212 |
goto leave; |
goto leave; |
|
} |
|
|
ec = gpgme_new (&ctx); |
|
|
if (ec) |
|
|
BUG (NULL); |
|
|
gpgme_data_new_from_mem (&keydata, rawkey, strlen (rawkey), 1); |
|
|
rc = gpgme_op_import (ctx, keydata); |
|
|
if (rc) { |
|
|
msg_box (dlg, gpgme_strerror ((gpgme_error_t)rc), _("Import"), MB_ERR); |
|
|
goto leave; |
|
|
} |
|
|
import_res = gpgme_op_import_result (ctx); |
|
|
if (import_res && r_fpr) |
|
|
*r_fpr = m_strdup (import_res->imports->fpr); |
|
213 |
} |
} |
214 |
|
if (gpgme_new (&ctx)) |
215 |
|
BUG (NULL); |
216 |
|
gpgme_data_new_from_mem (&keydata, rawkey, strlen (rawkey), 1); |
217 |
|
err = gpgme_op_import (ctx, keydata); |
218 |
|
if (err) { |
219 |
|
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
220 |
|
goto leave; |
221 |
|
} |
222 |
|
import_res = gpgme_op_import_result (ctx); |
223 |
|
if (import_res && r_fpr) |
224 |
|
*r_fpr = m_strdup (import_res->imports->fpr); |
225 |
|
|
226 |
/* 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 |
227 |
a summarize at the end is presented and not for each key. */ |
a summarize at the end is presented and not for each key. */ |
252 |
proto, flags, NULL); |
proto, flags, NULL); |
253 |
} |
} |
254 |
|
|
255 |
|
int |
256 |
|
hkp_recv_key2 (HWND dlg, const char *kserver, WORD port, |
257 |
|
const char *pattern, int proto, char **r_fpr) |
258 |
|
{ |
259 |
|
return keyserver_recv_key (dlg, kserver, port, pattern, proto, 0, |
260 |
|
r_fpr); |
261 |
|
} |
262 |
|
|
263 |
|
|
264 |
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
265 |
|
|
266 |
static int |
static int |
267 |
check_pattern (const char *pattern) |
check_pattern (const char *pattern) |
268 |
{ |
{ |
269 |
int rc = 1; |
int rc = WPTERR_GENERAL; |
270 |
|
|
271 |
/* Whitespace are not allowed! */ |
/* do not allow white spaces. */ |
272 |
if (strchr( pattern, ' ')) { |
if (strchr (pattern, ' ')) |
273 |
rc = WPTERR_GENERAL; |
return rc; |
274 |
goto leave; |
|
275 |
} |
if (strstr (pattern, "0x")) |
276 |
|
pattern += 2; |
277 |
if (((strstr (pattern, "0x")) && (strlen (pattern) == 10)) || |
|
278 |
(strstr(pattern, "0x")) && (strlen (pattern) == 18)) { |
if (((my_iskeychar (pattern[0])) && (strlen (pattern) == 8)) || |
279 |
rc = 0; /* Either long or short keyid */ |
(my_iskeychar (pattern[0])) && (strlen (pattern) == 16)) |
280 |
goto leave; |
rc = 0; /* assume long or short key ID. */ |
281 |
} |
else if (strchr (pattern, '@') && strlen (pattern) >= 3) |
282 |
|
rc = 0; /* assume email address. */ |
283 |
if( (( my_iskeychar( pattern[0] )) && ( strlen( pattern ) == 8 ) ) |
|
|
|| (my_iskeychar(pattern[0])) && ( strlen( pattern ) == 16) ) { |
|
|
rc = 0; |
|
|
goto leave; |
|
|
} |
|
|
|
|
|
if( ( strchr( pattern, '@' ) ) && ( strlen( pattern ) >= 3 ) ) { |
|
|
rc = 0; |
|
|
goto leave; |
|
|
} |
|
|
|
|
|
leave: |
|
284 |
return rc; |
return rc; |
285 |
} /* check_pattern */ |
} |
286 |
|
|
287 |
|
|
288 |
static void |
/* Return human readable name for the proxy protocol. */ |
289 |
set_proxy (HWND dlg) |
static const char* |
290 |
|
name_from_proto (int proto) |
291 |
{ |
{ |
292 |
char proxy[256]; |
const char *s; |
293 |
int port = 0; |
|
294 |
|
switch (proto) { |
295 |
strcpy (proxy, "HTTP proxy: "); |
case PROXY_PROTO_NONE: s = ""; break; |
296 |
if (kserver_get_proxy (&port)) { |
case PROXY_PROTO_HTTP: s = "HTTP"; break; |
297 |
char t[128]; |
case PROXY_PROTO_SOCKS5: s = "SOCKS5"; break; |
298 |
const char *http = kserver_get_proxy (&port); |
default: s= "HTTP"; break; |
|
_snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port); |
|
|
strcat (proxy, t); |
|
299 |
} |
} |
300 |
else |
return s; |
301 |
strcat (proxy, "none"); |
} |
|
SetDlgItemText (dlg, IDC_KEYSERVER_PROXY, proxy); |
|
|
} /* set_proxy */ |
|
302 |
|
|
303 |
|
|
304 |
static int inline |
static int inline |
310 |
} |
} |
311 |
|
|
312 |
|
|
313 |
static u16 inline |
static WORD inline |
314 |
kserver_get_port (listview_ctrl_t lv) |
kserver_get_port (listview_ctrl_t lv) |
315 |
{ |
{ |
316 |
char buf[16]; |
char buf[16]; |
317 |
|
|
318 |
listview_get_item_text (lv, kserver_get_pos (lv), 3, buf, 15); |
listview_get_item_text (lv, kserver_get_pos (lv), KS_COL_PORT, buf, 15); |
319 |
return (u16)strtoul (buf, NULL, 10); |
return (WORD)strtoul (buf, NULL, 10); |
320 |
} |
} |
321 |
|
|
322 |
|
|
323 |
static void |
static void |
324 |
load_default_ks (listview_ctrl_t lv) |
set_default_ks (listview_ctrl_t lv) |
325 |
{ |
{ |
326 |
char * p, buf[192]; |
char *p, buf[200]; |
327 |
int i; |
int i; |
328 |
|
|
329 |
p = get_reg_entry_keyserver ("Default"); |
p = get_reg_entry_keyserver ("Default"); |
330 |
if (!p) |
if (!p) |
331 |
return; |
return; |
332 |
for( i = 0; i < listview_count_items( lv, 0 ); i++ ) { |
for (i=0; i < listview_count_items (lv, 0); i++) { |
333 |
listview_get_item_text( lv, i, 0, buf, sizeof (buf)-1 ); |
listview_get_item_text (lv, i, KS_COL_NAME, buf, sizeof (buf)-1); |
334 |
if( !strncmp( p, buf, strlen( p ) ) ) { |
if (!strcmp (buf, p)) { |
335 |
listview_add_sub_item( lv, i, 2, "x" ); |
listview_select_one (lv, i); |
336 |
break; |
break; |
337 |
} |
} |
338 |
} |
} |
339 |
free_if_alloc (p); |
free_if_alloc (p); |
340 |
} /* load_default_ks */ |
} |
341 |
|
|
342 |
|
|
343 |
|
/* Save the selected keyserver from @lv as the default server. */ |
344 |
static int |
static int |
345 |
save_default_ks (listview_ctrl_t lv) |
save_default_ks (listview_ctrl_t lv) |
346 |
{ |
{ |
347 |
char buf[192], port[32]; |
char buf[192], port[32]; |
348 |
int idx, i; |
int idx, i; |
349 |
|
|
350 |
idx = listview_get_curr_pos( lv ); |
idx = listview_get_curr_pos (lv); |
351 |
if( idx == -1 ) { |
if (idx == -1) { |
352 |
msg_box( NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR ); |
msg_box (NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR); |
353 |
return -1; |
return -1; |
354 |
} |
} |
355 |
listview_get_item_text( lv, idx, 1, buf, sizeof (buf)-1 ); |
listview_get_item_text (lv, idx, KS_COL_NAME, buf, sizeof (buf)-1); |
356 |
if( *buf != 'H' ) { |
if (strncmp (buf, "http", 4) && strncmp (buf, "hkp", 3)) { |
357 |
msg_box( NULL, _("Only HTTP keyserver can be used."), _("Keyserver"), MB_ERR ); |
msg_box (NULL, _("Only HTTP keyserver can be used."), |
358 |
|
_("Keyserver"), MB_ERR); |
359 |
return -1; |
return -1; |
360 |
} |
} |
|
for (i = 0; i < listview_count_items( lv, 0 ); i++) |
|
|
listview_add_sub_item (lv, i, 2, ""); |
|
|
listview_add_sub_item (lv, idx, 2, "x"); |
|
|
listview_get_item_text (lv, idx, 0, buf, sizeof (buf)-1); |
|
361 |
set_reg_entry_keyserver ("Default", buf); |
set_reg_entry_keyserver ("Default", buf); |
362 |
i = kserver_get_port (lv); |
i = kserver_get_port (lv); |
363 |
sprintf (port, "%d", i); |
sprintf (port, "%d", i); |
364 |
set_reg_entry_keyserver ("Default_Port", port); |
set_reg_entry_keyserver ("Default_Port", port); |
365 |
keyserver_set_default (buf, (u16)i); |
keyserver_set_default (buf, (WORD)i); |
366 |
return 0; |
return 0; |
367 |
} /* save_default_ks */ |
} |
368 |
|
|
369 |
|
|
370 |
int |
int |
371 |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
372 |
{ |
{ |
373 |
struct listview_column_s keyserver[] = { |
struct listview_column_s keyserver[] = { |
374 |
{0, 160, (char *)_("DNS Name")}, |
{0, 180, (char *)_("DNS Name")}, |
375 |
{1, 52, (char *)_("Protocol")}, |
{1, 55, (char *)_("Port")}, |
|
{2, 46, (char *)_("Default")}, |
|
|
{3, 46, (char *)_("Port")}, |
|
376 |
{0, 0, NULL} |
{0, 0, NULL} |
377 |
}; |
}; |
378 |
|
HICON ico[1]; |
379 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
380 |
char buf[32]; |
char buf[32]; |
381 |
int j; |
int j; |
382 |
|
|
383 |
listview_new (&lv); |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_COMPUTER); |
384 |
lv->ctrl = hwnd; |
listview_new (&lv, hwnd); |
385 |
for (j=0; keyserver[j].fieldname; j++) |
for (j=0; keyserver[j].fieldname; j++) |
386 |
listview_add_column (lv, &keyserver[j]); |
listview_add_column (lv, &keyserver[j]); |
387 |
|
listview_set_image_list (lv, 16, 16, ico, 1); |
388 |
for (j = 0; j<MAX_KEYSERVERS; j++) { |
for (j = 0; j<MAX_KEYSERVERS; j++) { |
389 |
if (!server[j].used) |
if (!server[j].used) |
390 |
continue; |
continue; |
391 |
listview_add_item (lv, " "); |
listview_add_item_image (lv, " ", 0); |
392 |
listview_add_sub_item (lv, 0, 0, server[j].name); |
listview_add_sub_item (lv, 0, KS_COL_NAME, server[j].name); |
|
switch (server[j].proto) { |
|
|
case KSPROTO_HTTP: |
|
|
listview_add_sub_item( lv, 0, 1, "H" ); break; |
|
|
case KSPROTO_LDAP: |
|
|
listview_add_sub_item( lv, 0, 1, "L" ); break; |
|
|
case KSPROTO_FINGER: |
|
|
listview_add_sub_item( lv, 0, 1, "F" ); break; |
|
|
} |
|
393 |
sprintf (buf, "%d", server[j].port); |
sprintf (buf, "%d", server[j].port); |
394 |
listview_add_sub_item (lv, 0, 3, buf); |
listview_add_sub_item (lv, 0, KS_COL_PORT, buf); |
395 |
} |
} |
|
load_default_ks (lv); |
|
396 |
if (listview_count_items (lv, 0) == 0) { |
if (listview_count_items (lv, 0) == 0) { |
397 |
listview_add_item (lv, ""); |
listview_add_item (lv, ""); |
398 |
listview_add_sub_item (lv, 0, 0, DEF_HKP_KEYSERVER); |
listview_add_sub_item (lv, 0, KS_COL_NAME, DEF_HKP_KEYSERVER); |
|
listview_add_sub_item (lv, 0, 1, "H"); |
|
399 |
} |
} |
400 |
listview_set_ext_style (lv); |
listview_set_ext_style (lv); |
401 |
*r_lv = lv; |
*r_lv = lv; |
403 |
} |
} |
404 |
|
|
405 |
|
|
406 |
|
static void |
407 |
|
keyserver_remove (listview_ctrl_t lv) |
408 |
|
{ |
409 |
|
char name[100]; |
410 |
|
int pos = listview_get_curr_pos (lv); |
411 |
|
int i; |
412 |
|
|
413 |
|
listview_get_item_text (lv, pos, KS_COL_NAME, name, sizeof (name)-1); |
414 |
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
415 |
|
if (server[i].name && strcmp (server[i].name, name) == 0) |
416 |
|
server[i].used = 0; |
417 |
|
} |
418 |
|
listview_del_item (lv, pos); |
419 |
|
} |
420 |
|
|
421 |
|
|
422 |
|
static void |
423 |
|
keyserver_edit (listview_ctrl_t lv, keyserver_rec_t ctx) |
424 |
|
{ |
425 |
|
char buf[16]; |
426 |
|
bool fnd = false; |
427 |
|
int i; |
428 |
|
|
429 |
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
430 |
|
if (server[i].name && strcmp (server[i].name, ctx->name) == 0) { |
431 |
|
fnd = true; |
432 |
|
break; |
433 |
|
} |
434 |
|
} |
435 |
|
if (!fnd) |
436 |
|
return; |
437 |
|
server[i].port = ctx->port; |
438 |
|
|
439 |
|
i = listview_get_curr_pos (lv); |
440 |
|
sprintf (buf, "%d", ctx->port); |
441 |
|
listview_add_sub_item (lv, i, KS_COL_NAME, ctx->name); |
442 |
|
listview_add_sub_item (lv, i, KS_COL_PORT, buf); |
443 |
|
} |
444 |
|
|
445 |
|
static void |
446 |
|
keyserver_add (listview_ctrl_t lv, keyserver_rec_t ctx) |
447 |
|
{ |
448 |
|
char buf[16]; |
449 |
|
bool fnd = false; |
450 |
|
int i; |
451 |
|
|
452 |
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
453 |
|
if (server[i].used == 0) { |
454 |
|
fnd = true; |
455 |
|
break; |
456 |
|
} |
457 |
|
} |
458 |
|
if (!fnd) { |
459 |
|
msg_box (NULL, _("No space for new keyserver entry"), |
460 |
|
_("Keyserver"), MB_ERR); |
461 |
|
return; |
462 |
|
} |
463 |
|
free_if_alloc (server[i].name); |
464 |
|
server[i].name = m_strdup (ctx->name); |
465 |
|
server[i].port = ctx->port; |
466 |
|
server[i].proto = ctx->proto; |
467 |
|
server[i].used = 1; |
468 |
|
|
469 |
|
sprintf (buf, "%d", ctx->port); |
470 |
|
listview_add_item (lv, " "); |
471 |
|
listview_add_sub_item (lv, 0, KS_COL_NAME, ctx->name); |
472 |
|
listview_add_sub_item (lv, 0, KS_COL_PORT, buf); |
473 |
|
} |
474 |
|
|
475 |
|
|
476 |
|
static void |
477 |
|
fill_keyserv_types (HWND dlg) |
478 |
|
{ |
479 |
|
HWND h = GetDlgItem (dlg, IDC_KSERVADD_TYPES); |
480 |
|
combox_add_string (h, _("HKP Keyserver")); |
481 |
|
combox_add_string (h, _("LDAP Keyserver")); |
482 |
|
combox_add_string (h, _("Finger Keyserver")); |
483 |
|
SendMessage (h, CB_SETCURSEL, 0, 0); |
484 |
|
} |
485 |
|
|
486 |
|
|
487 |
|
/* Dialog box procedure for modify keyservers. */ |
488 |
|
BOOL CALLBACK |
489 |
|
keyserver_modify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
490 |
|
{ |
491 |
|
static keyserver_rec_t ctx; |
492 |
|
char tmp[128]; |
493 |
|
|
494 |
|
switch (msg) { |
495 |
|
case WM_INITDIALOG: |
496 |
|
fill_keyserv_types (dlg); |
497 |
|
ctx = (keyserver_rec_t)lparam; |
498 |
|
if (ctx->mode) { |
499 |
|
SendDlgItemMessage (dlg, IDC_KSERVADD_TYPES, CB_SETCURSEL, ctx->proto, 0); |
500 |
|
SetDlgItemText (dlg, IDC_KSERVADD_HOST, ctx->name); |
501 |
|
SetDlgItemInt (dlg, IDC_KSERVADD_PORT, ctx->port, FALSE); |
502 |
|
EnableWindow (GetDlgItem (dlg, IDC_KSERVADD_HOST), FALSE); |
503 |
|
EnableWindow (GetDlgItem (dlg, IDC_KSERVADD_TYPES), FALSE); |
504 |
|
} |
505 |
|
else |
506 |
|
SetDlgItemInt (dlg, IDC_KSERVADD_PORT, 11371, FALSE); |
507 |
|
SetWindowText (dlg, _("Edit Keyserver")); |
508 |
|
SetDlgItemText (dlg, IDOK, _("&Add")); |
509 |
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
510 |
|
SetDlgItemText (dlg, IDC_KSERVADD_TYPEINF, _("Type:")); |
511 |
|
SetDlgItemText (dlg, IDC_KSERVADD_PORTINF, _("Port:")); |
512 |
|
SetDlgItemText (dlg, IDC_KSERVADD_HOSTINF, _("Host name:")); |
513 |
|
SetForegroundWindow (dlg); |
514 |
|
break; |
515 |
|
|
516 |
|
case WM_COMMAND: |
517 |
|
switch (LOWORD (wparam)) { |
518 |
|
case IDOK: |
519 |
|
if (!GetDlgItemText (dlg, IDC_KSERVADD_HOST, tmp, sizeof (tmp)-1)) { |
520 |
|
msg_box (dlg, _("Please enter a host name"), _("Keyserver"), MB_ERR); |
521 |
|
return FALSE; |
522 |
|
} |
523 |
|
ctx->port = GetDlgItemInt (dlg, IDC_KSERVADD_PORT, NULL, FALSE); |
524 |
|
if (ctx->port > 65535) { |
525 |
|
msg_box (dlg, _("Invalid port, valid numbers are < 65535"), _("Keyserver"), MB_ERR); |
526 |
|
return FALSE; |
527 |
|
} |
528 |
|
ctx->proto = SendDlgItemMessage (dlg, IDC_KSERVADD_TYPES, CB_GETCURSEL, 0, 0); |
529 |
|
ctx->cancel = false; |
530 |
|
ctx->name[0] = '\0'; |
531 |
|
if (!strstr (tmp, "://")) { |
532 |
|
switch (ctx->proto) { |
533 |
|
case KSPROTO_HTTP: strcpy (ctx->name, "http://"); break; |
534 |
|
case KSPROTO_LDAP: strcpy (ctx->name, "ldap://"); break; |
535 |
|
case KSPROTO_FINGER:strcpy (ctx->name, "finger://"); break; |
536 |
|
} |
537 |
|
} |
538 |
|
strcat (ctx->name, tmp); |
539 |
|
ctx->cancel = false; |
540 |
|
EndDialog (dlg, TRUE); |
541 |
|
break; |
542 |
|
|
543 |
|
case IDCANCEL: |
544 |
|
ctx->cancel = true; |
545 |
|
EndDialog (dlg, FALSE); |
546 |
|
break; |
547 |
|
} |
548 |
|
break; |
549 |
|
} |
550 |
|
|
551 |
|
return FALSE; |
552 |
|
} |
553 |
|
|
554 |
/* Dialog box procedure to access keyservers. */ |
/* Dialog box procedure to access keyservers. */ |
555 |
BOOL CALLBACK |
BOOL CALLBACK |
556 |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
557 |
{ |
{ |
558 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
559 |
static int lv_idx = 0; |
static int lv_idx = 0; |
|
static struct genkey_s *key; |
|
560 |
keyserver_ctx ksc; |
keyserver_ctx ksc; |
561 |
|
struct keyserver_rec_s edit; |
562 |
char kserver[128], pattern[128]; |
char kserver[128], pattern[128]; |
563 |
char proto[16]; |
char proto[16], *fpr = NULL; |
564 |
int rc, proto_nr = 0; |
int rc, proto_nr = 0; |
565 |
|
|
566 |
switch (msg) { |
switch (msg) { |
567 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
|
if (lparam != 0) |
|
|
key = (struct genkey_s*)lparam; |
|
568 |
SetWindowText (dlg, _("Keyserver Access")); |
SetWindowText (dlg, _("Keyserver Access")); |
569 |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
570 |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
572 |
SetDlgItemText (dlg, IDC_KEYSERVER_INFO, |
SetDlgItemText (dlg, IDC_KEYSERVER_INFO, |
573 |
_("Please enter the key ID or email address you search for")); |
_("Please enter the key ID or email address you search for")); |
574 |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
575 |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange proxy")); |
576 |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
577 |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
578 |
|
|
|
set_proxy (dlg); |
|
579 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
580 |
|
set_default_ks (lv); |
581 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
582 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
583 |
return TRUE; |
return TRUE; |
585 |
case WM_NOTIFY: |
case WM_NOTIFY: |
586 |
NMHDR *notify; |
NMHDR *notify; |
587 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
588 |
if (notify && notify->code == NM_CLICK |
if (!notify) |
589 |
|
break; |
590 |
|
if (notify->code == NM_CLICK |
591 |
&& notify->idFrom == IDC_KEYSERVER_LIST) |
&& notify->idFrom == IDC_KEYSERVER_LIST) |
592 |
lv_idx = listview_get_curr_pos (lv); |
lv_idx = listview_get_curr_pos (lv); |
593 |
|
else if (notify->code == NM_RCLICK && |
594 |
|
notify->idFrom == IDC_KEYSERVER_LIST) { |
595 |
|
POINT p; |
596 |
|
GetCursorPos (&p); |
597 |
|
HMENU hm, pop; |
598 |
|
hm = LoadMenu (glob_hinst, (LPCTSTR)IDR_WINPT_KEYSERVER_CTX); |
599 |
|
pop = GetSubMenu (hm, 0); |
600 |
|
set_menu_text (pop, ID_KSERVCTX_ADD, _("&Add")); |
601 |
|
set_menu_text (pop, ID_KSERVCTX_DEL, _("&Remove")); |
602 |
|
set_menu_text (pop, ID_KSERVCTX_EDIT, _("&Edit")); |
603 |
|
TrackPopupMenu (pop, 0, p.x, p.y, 0, dlg, NULL); |
604 |
|
DestroyMenu (hm); |
605 |
|
DestroyMenu (pop); |
606 |
|
} |
607 |
|
else if (notify->code == LVN_ITEMCHANGED && |
608 |
|
((LPNMLISTVIEW)lparam)->uNewState) { |
609 |
|
/* XXX: disable search for ldap servers. */ |
610 |
|
} |
611 |
return TRUE; |
return TRUE; |
612 |
|
|
613 |
case WM_DESTROY: |
case WM_DESTROY: |
621 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
622 |
if (LOWORD (wparam) == SC_CLOSE) |
if (LOWORD (wparam) == SC_CLOSE) |
623 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
624 |
return FALSE; |
return FALSE; |
625 |
|
|
626 |
case WM_COMMAND: |
case WM_COMMAND: |
627 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
628 |
case IDC_KEYSERVER_PROXSETT: |
case IDC_KEYSERVER_PROXSETT: |
629 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, |
630 |
dlg, keyserver_proxy_dlg_proc, NULL, |
dlg, keyserver_proxy_dlg_proc, 0, |
631 |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY); |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY); |
|
set_proxy (dlg); |
|
632 |
return TRUE; |
return TRUE; |
633 |
|
|
634 |
case IDC_KEYSERVER_INDEX: |
case IDC_KEYSERVER_INDEX: |
640 |
return FALSE; |
return FALSE; |
641 |
} |
} |
642 |
} |
} |
643 |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
644 |
if (*proto == 'L') { |
proto, sizeof (proto)-1); |
645 |
|
if (!strncmp (proto, "ldap", 4)) { |
646 |
msg_box (dlg, _("This is not implemented yet!"), |
msg_box (dlg, _("This is not implemented yet!"), |
647 |
_("Keyserver"), MB_ERR); |
_("Keyserver"), MB_ERR); |
648 |
return FALSE; |
return FALSE; |
649 |
} |
} |
650 |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
651 |
|
kserver, sizeof (kserver)-1); |
652 |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
653 |
msg_box (dlg, _("Please enter the search pattern."), |
msg_box (dlg, _("Please enter the search pattern."), |
654 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
671 |
return FALSE; |
return FALSE; |
672 |
} |
} |
673 |
} |
} |
674 |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
675 |
|
proto, sizeof (proto)-1); |
676 |
proto_nr = KSPROTO_HTTP; |
proto_nr = KSPROTO_HTTP; |
677 |
if (*proto == 'L') |
if (!strncmp (proto, "ldap", 4)) |
678 |
proto_nr = KSPROTO_LDAP; |
proto_nr = KSPROTO_LDAP; |
679 |
else if (*proto == 'F') |
else if (!strncmp (proto, "finger", 6)) |
680 |
proto_nr = KSPROTO_FINGER; |
proto_nr = KSPROTO_FINGER; |
681 |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
682 |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
kserver, sizeof (kserver)-1); |
683 |
|
if (!GetDlgItemText(dlg, IDC_KEYSERVER_SEARCH, |
684 |
|
pattern, sizeof (pattern)-1)) { |
685 |
msg_box (dlg, _("Please enter the search pattern."), |
msg_box (dlg, _("Please enter the search pattern."), |
686 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
687 |
return FALSE; |
return FALSE; |
688 |
} |
} |
689 |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
690 |
msg_box (dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO); |
msg_box (dlg, _("Only keyids are allowed."), |
691 |
|
_("Keyserver"), MB_INFO); |
692 |
return FALSE; |
return FALSE; |
693 |
} |
} |
694 |
else if (proto_nr == KSPROTO_FINGER) { |
else if (proto_nr == KSPROTO_FINGER) { |
695 |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
696 |
msg_box (dlg, _("Only enter the name of the user."), |
msg_box (dlg, _("Only enter the name of the user."), |
697 |
_("FINGER Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
698 |
return FALSE; |
return FALSE; |
699 |
} |
} |
700 |
} |
} |
701 |
else if (check_pattern (pattern)) { |
else if (check_pattern (pattern)) { |
702 |
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
703 |
_("HKP Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
704 |
return FALSE; |
return FALSE; |
705 |
} |
} |
706 |
rc = keyserver_recv_key (dlg, kserver, kserver_get_port (lv), |
rc = keyserver_recv_key (dlg, kserver, kserver_get_port (lv), |
707 |
pattern, proto_nr, 0, |
pattern, proto_nr, 0, |
708 |
key? &key->fpr : NULL); |
&fpr); |
709 |
if (!rc && key->fpr != NULL) { |
if (!rc && fpr != NULL) { |
710 |
keycache_update (0, key->fpr); |
keycache_update (0, fpr); |
711 |
get_pubkey (key->fpr, &key->newkey); |
free_if_alloc (fpr); |
|
/* we do not need the fingerprint any longer. */ |
|
|
free_if_alloc (key->fpr); |
|
712 |
} |
} |
713 |
return TRUE; |
return TRUE; |
714 |
|
|
715 |
case IDC_KEYSERVER_DEFAULT: |
case IDC_KEYSERVER_DEFAULT: |
716 |
save_default_ks (lv); |
save_default_ks (lv); |
717 |
break; |
break; |
718 |
|
|
719 |
|
case ID_KSERVCTX_ADD: |
720 |
|
memset (&edit, 0, sizeof (edit)); |
721 |
|
edit.mode = false; |
722 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_ADD, dlg, |
723 |
|
keyserver_modify_dlg_proc, |
724 |
|
(LPARAM)&edit, _("Edit Keyserver"), 0); |
725 |
|
if (!edit.cancel) |
726 |
|
keyserver_add (lv, &edit); |
727 |
|
return TRUE; |
728 |
|
|
729 |
|
case ID_KSERVCTX_EDIT: |
730 |
|
memset (&edit, 0, sizeof (edit)); |
731 |
|
edit.mode = true; |
732 |
|
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
733 |
|
edit.name, sizeof (edit.name)-1); |
734 |
|
listview_get_item_text (lv, lv_idx, KS_COL_PORT, pattern, 32); |
735 |
|
edit.port = atoi (pattern); |
736 |
|
if (!strncmp (edit.name, "hkp", 3) || !strncmp (edit.name, "http", 4)) |
737 |
|
edit.proto = KSPROTO_HTTP; |
738 |
|
else if (!strncmp (edit.name, "ldap", 4)) |
739 |
|
edit.proto = KSPROTO_LDAP; |
740 |
|
else |
741 |
|
edit.proto = KSPROTO_FINGER; |
742 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_ADD, dlg, |
743 |
|
keyserver_modify_dlg_proc, |
744 |
|
(LPARAM)&edit, _("Edit Keyserver"), 0); |
745 |
|
if (!edit.cancel) |
746 |
|
keyserver_edit (lv, &edit); |
747 |
|
break; |
748 |
|
|
749 |
|
case ID_KSERVCTX_DEL: |
750 |
|
keyserver_remove (lv); |
751 |
|
return TRUE; |
752 |
|
|
753 |
case IDCANCEL: |
case IDCANCEL: |
754 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |