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 |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
6 |
* |
* |
35 |
#include "wptW32API.h" |
#include "wptW32API.h" |
36 |
#include "wptVersion.h" |
#include "wptVersion.h" |
37 |
#include "wptGPG.h" |
#include "wptGPG.h" |
38 |
|
#include "wptGPGME.h" |
39 |
#include "wptKeyManager.h" |
#include "wptKeyManager.h" |
40 |
#include "wptContext.h" /* for passphrase_s */ |
#include "wptContext.h" /* for passphrase_s */ |
41 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
42 |
|
#include "wptUTF8.h" |
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 |
|
enum { KS_COL_NAME = 0, KS_COL_PORT }; |
50 |
|
|
51 |
|
/* Callback context to modify (add, edit) keyserver items. */ |
52 |
|
struct keyserver_rec_s { |
53 |
|
char name[200]; /* hostname */ |
54 |
|
int proto; /* protocol */ |
55 |
|
int port; /* used port */ |
56 |
|
bool mode; /* true = edit */ |
57 |
|
bool cancel; |
58 |
|
}; |
59 |
|
typedef struct keyserver_rec_s *keyserver_rec_t; |
60 |
|
|
61 |
/* Print out keyserver error and a possible Winsock error. */ |
/* Print out keyserver error and a possible Winsock error. */ |
62 |
static void |
static void |
77 |
int |
int |
78 |
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) |
79 |
{ |
{ |
80 |
gpgme_ctx_t ctx; |
GPGME *gpg; |
|
gpgme_data_t keydata; |
|
81 |
gpgme_error_t ec; |
gpgme_error_t ec; |
82 |
char *rawkey = NULL; |
char *rawkey = NULL; |
83 |
char msg[384]; |
char msg[384]; |
|
size_t n; |
|
84 |
|
|
85 |
ec = gpgme_new (&ctx); |
gpg = new GPGME (); |
86 |
if (ec) |
gpg->setArmor (true); |
87 |
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); |
|
88 |
if (ec) { |
if (ec) { |
89 |
msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR); |
msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR); |
90 |
goto leave; |
goto leave; |
91 |
} |
} |
92 |
rawkey = gpgme_data_release_and_get_mem (keydata, &n); |
ec = kserver_sendkey (kserver, port, rawkey, strlen (rawkey)); |
|
ec = kserver_sendkey (kserver, port, rawkey, n); |
|
93 |
if (ec) { |
if (ec) { |
94 |
hkp_err_box (dlg, kserver, port, ec); |
hkp_err_box (dlg, kserver, port, ec); |
95 |
goto leave; |
goto leave; |
99 |
status_box (dlg, msg, _("GnuPG status")); |
status_box (dlg, msg, _("GnuPG status")); |
100 |
|
|
101 |
leave: |
leave: |
102 |
gpgme_release (ctx); |
delete gpg; |
103 |
if (rawkey) |
free_if_alloc (rawkey); |
|
gpgme_free (rawkey); |
|
104 |
return ec? -1 : 0; |
return ec? -1 : 0; |
105 |
} |
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
/* Show all received keys from the keyserver. */ |
110 |
|
static void |
111 |
|
show_imported_keys (gpgme_import_result_t res) |
112 |
|
{ |
113 |
|
gpgme_import_status_t t; |
114 |
|
gpgme_key_t key; |
115 |
|
gpgme_data_t msg; |
116 |
|
gpgme_ctx_t ctx; |
117 |
|
gpgme_error_t err; |
118 |
|
const char *s; |
119 |
|
char *p, *uid; |
120 |
|
size_t n=0; |
121 |
|
|
122 |
|
if (!res) |
123 |
|
return; |
124 |
|
|
125 |
|
err = gpgme_data_new (&msg); |
126 |
|
if (err) |
127 |
|
BUG (NULL); |
128 |
|
err = gpgme_new (&ctx); |
129 |
|
if (err) |
130 |
|
BUG (NULL); |
131 |
|
if (res->considered > 1) { |
132 |
|
s = _("WARNING: multiple keys matched request.\n\n"); |
133 |
|
gpgme_data_write (msg, s, strlen (s)); |
134 |
|
} |
135 |
|
|
136 |
|
if (res->unchanged == res->considered) |
137 |
|
s = _("Key(s) successfully received but nothing was changed."); |
138 |
|
else |
139 |
|
s = _("Key(s) sucessfully received and imported."); |
140 |
|
gpgme_data_write (msg, s, strlen (s)); |
141 |
|
gpgme_data_write (msg, "\n\n", 2); |
142 |
|
|
143 |
|
for (t=res->imports; t; t = t->next) { |
144 |
|
if (!gpgme_get_key (ctx, t->fpr, &key, 0)) { |
145 |
|
s = uid = utf8_to_native (key->uids->uid); |
146 |
|
gpgme_data_write (msg, s, strlen (s)); |
147 |
|
gpgme_data_write (msg, "\n", 1); |
148 |
|
gpgme_key_release (key); |
149 |
|
free (uid); |
150 |
|
} |
151 |
|
} |
152 |
|
gpgme_data_write (msg, "\0", 1); |
153 |
|
p = gpgme_data_release_and_get_mem (msg, &n); |
154 |
|
if (p != NULL) { |
155 |
|
msg_box (NULL, p, _("Imported Keys"), MB_INFO); |
156 |
|
gpgme_free (p); |
157 |
|
} |
158 |
|
gpgme_release (ctx); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
/* Receive a key from the keyserver @kserver (port @port) |
/* Receive a key from the keyserver @kserver (port @port) |
163 |
with the pattern @pattern. |
with the pattern @pattern. |
164 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
165 |
int |
static int |
166 |
hkp_recv_key (HWND dlg, const char *kserver, WORD port, |
keyserver_recv_key (HWND dlg, const char *kserver, WORD port, |
167 |
const char *pattern, int proto, int flags) |
const char *pattern, int proto, int flags, |
168 |
|
char **r_fpr) |
169 |
{ |
{ |
170 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
171 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
172 |
gpgme_error_t ec; |
gpgme_error_t ec; |
173 |
gpgme_import_result_t import_res = NULL; |
gpgme_import_result_t import_res = NULL; |
|
int rc; |
|
174 |
char *rawkey = NULL; |
char *rawkey = NULL; |
175 |
char msg[384]; |
int rc; |
176 |
|
|
177 |
|
/* XXX: implement dynamic buffers. */ |
178 |
rawkey = new char[MAX_KEYSIZE]; |
rawkey = new char[MAX_KEYSIZE]; |
179 |
if (!rawkey) |
if (!rawkey) |
180 |
BUG (0); |
BUG (0); |
222 |
goto leave; |
goto leave; |
223 |
} |
} |
224 |
import_res = gpgme_op_import_result (ctx); |
import_res = gpgme_op_import_result (ctx); |
225 |
|
if (import_res && r_fpr) |
226 |
|
*r_fpr = m_strdup (import_res->imports->fpr); |
227 |
} |
} |
228 |
|
|
229 |
/* 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 |
230 |
a summarize at the end is presented and not for each key. */ |
a summarize at the end is presented and not for each key. */ |
231 |
if (!(flags & KM_KS_REFRESH)) { |
if (!(flags & KM_KS_REFRESH)) { |
232 |
if (import_res && import_res->unchanged == 1) { |
show_imported_keys (import_res); |
233 |
_snprintf (msg, DIM (msg)-1, |
if (import_res && import_res->unchanged == import_res->considered) { |
234 |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
rc = WPTERR_GENERAL; /* no keys updated. */ |
|
status_box (dlg, msg, _("GnuPG Status")); |
|
|
rc = WPTERR_GENERAL; |
|
235 |
goto leave; |
goto leave; |
236 |
} |
} |
|
_snprintf (msg, DIM (msg)-1, _("Key '%s' sucessfully received and imported."), pattern); |
|
|
status_box (dlg, msg, _("GnuPG Status")); |
|
237 |
} |
} |
238 |
|
|
239 |
leave: |
leave: |
240 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
241 |
gpgme_release (ctx); |
gpgme_release (ctx); |
245 |
} |
} |
246 |
|
|
247 |
|
|
248 |
|
/* Alias for keyserver_recv_key but without the ability to return |
249 |
|
the fingerprint of the key. */ |
250 |
|
int |
251 |
|
hkp_recv_key (HWND dlg, const char *kserver, WORD port, |
252 |
|
const char *pattern, int proto, int flags) |
253 |
|
{ |
254 |
|
return keyserver_recv_key (dlg, kserver, port, pattern, |
255 |
|
proto, flags, NULL); |
256 |
|
} |
257 |
|
|
258 |
|
int |
259 |
|
hkp_recv_key2 (HWND dlg, const char *kserver, WORD port, |
260 |
|
const char *pattern, int proto, char **r_fpr) |
261 |
|
{ |
262 |
|
return keyserver_recv_key (dlg, kserver, port, pattern, proto, 0, |
263 |
|
r_fpr); |
264 |
|
} |
265 |
|
|
266 |
|
|
267 |
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
268 |
|
|
269 |
static int |
static int |
272 |
int rc = 1; |
int rc = 1; |
273 |
|
|
274 |
/* Whitespace are not allowed! */ |
/* Whitespace are not allowed! */ |
275 |
if (strchr( pattern, ' ')) { |
if (strchr (pattern, ' ')) { |
276 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
277 |
goto leave; |
goto leave; |
278 |
} |
} |
289 |
goto leave; |
goto leave; |
290 |
} |
} |
291 |
|
|
292 |
if( ( strchr( pattern, '@' ) ) && ( strlen( pattern ) >= 3 ) ) { |
if ((strchr (pattern, '@')) && |
293 |
|
(strlen (pattern) >= 3)) { |
294 |
rc = 0; |
rc = 0; |
295 |
goto leave; |
goto leave; |
296 |
} |
} |
297 |
|
|
298 |
leave: |
leave: |
299 |
return rc; |
return rc; |
300 |
} /* check_pattern */ |
} |
301 |
|
|
302 |
|
|
303 |
static void |
/* Return human readable name for the proxy protocol. */ |
304 |
set_proxy (HWND dlg) |
static const char* |
305 |
{ |
name_from_proto (int proto) |
306 |
char proxy[256]; |
{ |
307 |
int port = 0; |
const char *s; |
308 |
|
|
309 |
strcpy (proxy, "HTTP proxy: "); |
switch (proto) { |
310 |
if (kserver_get_proxy (&port)) { |
case PROXY_PROTO_NONE: s = ""; break; |
311 |
char t[128]; |
case PROXY_PROTO_HTTP: s = "HTTP"; break; |
312 |
const char *http = kserver_get_proxy (&port); |
case PROXY_PROTO_SOCKS5: s = "SOCKS5"; break; |
313 |
_snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port); |
default: s= "HTTP"; break; |
|
strcat (proxy, t); |
|
314 |
} |
} |
315 |
else |
return s; |
316 |
strcat (proxy, "none"); |
} |
|
SetDlgItemText (dlg, IDC_KEYSERVER_PROXY, proxy); |
|
|
} /* set_proxy */ |
|
317 |
|
|
318 |
|
|
319 |
static int inline |
static int inline |
325 |
} |
} |
326 |
|
|
327 |
|
|
328 |
static u16 inline |
static WORD inline |
329 |
kserver_get_port (listview_ctrl_t lv) |
kserver_get_port (listview_ctrl_t lv) |
330 |
{ |
{ |
331 |
char buf[16]; |
char buf[16]; |
332 |
|
|
333 |
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); |
334 |
return (u16)strtoul (buf, NULL, 10); |
return (WORD)strtoul (buf, NULL, 10); |
335 |
} |
} |
336 |
|
|
337 |
|
|
338 |
static void |
static void |
339 |
load_default_ks (listview_ctrl_t lv) |
set_default_ks (listview_ctrl_t lv) |
340 |
{ |
{ |
341 |
char * p, buf[192]; |
char *p, buf[200]; |
342 |
int i; |
int i; |
343 |
|
|
344 |
p = get_reg_entry_keyserver ("Default"); |
p = get_reg_entry_keyserver ("Default"); |
345 |
if (!p) |
if (!p) |
346 |
return; |
return; |
347 |
for( i = 0; i < listview_count_items( lv, 0 ); i++ ) { |
for (i=0; i < listview_count_items (lv, 0); i++) { |
348 |
listview_get_item_text( lv, i, 0, buf, sizeof (buf)-1 ); |
listview_get_item_text (lv, i, KS_COL_NAME, buf, sizeof (buf)-1); |
349 |
if( !strncmp( p, buf, strlen( p ) ) ) { |
if (!strcmp (buf, p)) { |
350 |
listview_add_sub_item( lv, i, 2, "x" ); |
listview_select_one (lv, i); |
351 |
break; |
break; |
352 |
} |
} |
353 |
} |
} |
354 |
free_if_alloc (p); |
free_if_alloc (p); |
355 |
} /* load_default_ks */ |
} |
|
|
|
356 |
|
|
357 |
|
/* Save the selected keyserver from @lv as the default server. */ |
358 |
static int |
static int |
359 |
save_default_ks (listview_ctrl_t lv) |
save_default_ks (listview_ctrl_t lv) |
360 |
{ |
{ |
361 |
char buf[192], port[32]; |
char buf[192], port[32]; |
362 |
int idx, i; |
int idx, i; |
363 |
|
|
364 |
idx = listview_get_curr_pos( lv ); |
idx = listview_get_curr_pos (lv); |
365 |
if( idx == -1 ) { |
if (idx == -1) { |
366 |
msg_box( NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR ); |
msg_box (NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR); |
367 |
return -1; |
return -1; |
368 |
} |
} |
369 |
listview_get_item_text( lv, idx, 1, buf, sizeof (buf)-1 ); |
listview_get_item_text (lv, idx, KS_COL_NAME, buf, sizeof (buf)-1); |
370 |
if( *buf != 'H' ) { |
if (strncmp (buf, "http", 4) && strncmp (buf, "hkp", 3)) { |
371 |
msg_box( NULL, _("Only HTTP keyserver can be used."), _("Keyserver"), MB_ERR ); |
msg_box (NULL, _("Only HTTP keyserver can be used."), |
372 |
|
_("Keyserver"), MB_ERR); |
373 |
return -1; |
return -1; |
374 |
} |
} |
|
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); |
|
375 |
set_reg_entry_keyserver ("Default", buf); |
set_reg_entry_keyserver ("Default", buf); |
376 |
i = kserver_get_port (lv); |
i = kserver_get_port (lv); |
377 |
sprintf (port, "%d", i); |
sprintf (port, "%d", i); |
378 |
set_reg_entry_keyserver ("Default_Port", port); |
set_reg_entry_keyserver ("Default_Port", port); |
379 |
keyserver_set_default (buf, (u16)i); |
keyserver_set_default (buf, (WORD)i); |
380 |
return 0; |
return 0; |
381 |
} /* save_default_ks */ |
} |
382 |
|
|
383 |
|
|
384 |
int |
int |
385 |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
386 |
{ |
{ |
387 |
struct listview_column_s keyserver[] = { |
struct listview_column_s keyserver[] = { |
388 |
{0, 160, (char *)_("DNS Name")}, |
{0, 180, (char *)_("DNS Name")}, |
389 |
{1, 52, (char *)_("Protocol")}, |
{1, 55, (char *)_("Port")}, |
|
{2, 46, (char *)_("Default")}, |
|
|
{3, 46, (char *)_("Port")}, |
|
390 |
{0, 0, NULL} |
{0, 0, NULL} |
391 |
}; |
}; |
392 |
|
HICON ico[1]; |
393 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
394 |
char buf[32]; |
char buf[32]; |
395 |
int j; |
int j; |
396 |
|
|
397 |
|
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_COMPUTER); |
398 |
listview_new (&lv); |
listview_new (&lv); |
399 |
lv->ctrl = hwnd; |
lv->ctrl = hwnd; |
400 |
for (j=0; keyserver[j].fieldname; j++) |
for (j=0; keyserver[j].fieldname; j++) |
401 |
listview_add_column (lv, &keyserver[j]); |
listview_add_column (lv, &keyserver[j]); |
402 |
|
listview_set_image_list (lv, 16, 16, ico, 1); |
403 |
for (j = 0; j<MAX_KEYSERVERS; j++) { |
for (j = 0; j<MAX_KEYSERVERS; j++) { |
404 |
if (!server[j].used) |
if (!server[j].used) |
405 |
continue; |
continue; |
406 |
listview_add_item (lv, " "); |
listview_add_item_image (lv, " ", 0); |
407 |
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; |
|
|
} |
|
408 |
sprintf (buf, "%d", server[j].port); |
sprintf (buf, "%d", server[j].port); |
409 |
listview_add_sub_item (lv, 0, 3, buf); |
listview_add_sub_item (lv, 0, KS_COL_PORT, buf); |
410 |
} |
} |
|
load_default_ks (lv); |
|
411 |
if (listview_count_items (lv, 0) == 0) { |
if (listview_count_items (lv, 0) == 0) { |
412 |
listview_add_item (lv, ""); |
listview_add_item (lv, ""); |
413 |
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"); |
|
414 |
} |
} |
415 |
listview_set_ext_style (lv); |
listview_set_ext_style (lv); |
416 |
*r_lv = lv; |
*r_lv = lv; |
418 |
} |
} |
419 |
|
|
420 |
|
|
421 |
|
static void |
422 |
|
keyserver_remove (listview_ctrl_t lv) |
423 |
|
{ |
424 |
|
char name[100]; |
425 |
|
int pos = listview_get_curr_pos (lv); |
426 |
|
int i; |
427 |
|
|
428 |
|
listview_get_item_text (lv, pos, KS_COL_NAME, name, sizeof (name)-1); |
429 |
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
430 |
|
if (server[i].name && strcmp (server[i].name, name) == 0) |
431 |
|
server[i].used = 0; |
432 |
|
} |
433 |
|
listview_del_item (lv, pos); |
434 |
|
} |
435 |
|
|
436 |
|
|
437 |
|
static void |
438 |
|
keyserver_edit (listview_ctrl_t lv, keyserver_rec_t ctx) |
439 |
|
{ |
440 |
|
char buf[16]; |
441 |
|
bool fnd = false; |
442 |
|
int i; |
443 |
|
|
444 |
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
445 |
|
if (server[i].name && strcmp (server[i].name, ctx->name) == 0) { |
446 |
|
fnd = true; |
447 |
|
break; |
448 |
|
} |
449 |
|
} |
450 |
|
if (!fnd) |
451 |
|
return; |
452 |
|
server[i].port = ctx->port; |
453 |
|
|
454 |
|
i = listview_get_curr_pos (lv); |
455 |
|
sprintf (buf, "%d", ctx->port); |
456 |
|
listview_add_sub_item (lv, i, KS_COL_NAME, ctx->name); |
457 |
|
listview_add_sub_item (lv, i, KS_COL_PORT, buf); |
458 |
|
} |
459 |
|
|
460 |
|
static void |
461 |
|
keyserver_add (listview_ctrl_t lv, keyserver_rec_t ctx) |
462 |
|
{ |
463 |
|
char buf[16]; |
464 |
|
bool fnd = false; |
465 |
|
int i; |
466 |
|
|
467 |
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
468 |
|
if (server[i].used == 0) { |
469 |
|
fnd = true; |
470 |
|
break; |
471 |
|
} |
472 |
|
} |
473 |
|
if (!fnd) { |
474 |
|
msg_box (NULL, _("No space for new keyserver entry"), |
475 |
|
_("Keyserver"), MB_ERR); |
476 |
|
return; |
477 |
|
} |
478 |
|
free_if_alloc (server[i].name); |
479 |
|
server[i].name = m_strdup (ctx->name); |
480 |
|
server[i].port = ctx->port; |
481 |
|
server[i].proto = ctx->proto; |
482 |
|
server[i].used = 1; |
483 |
|
|
484 |
|
sprintf (buf, "%d", ctx->port); |
485 |
|
listview_add_item (lv, " "); |
486 |
|
listview_add_sub_item (lv, 0, KS_COL_NAME, ctx->name); |
487 |
|
listview_add_sub_item (lv, 0, KS_COL_PORT, buf); |
488 |
|
} |
489 |
|
|
490 |
|
|
491 |
|
static void |
492 |
|
fill_keyserv_types (HWND dlg) |
493 |
|
{ |
494 |
|
HWND h = GetDlgItem (dlg, IDC_KSERVADD_TYPES); |
495 |
|
combox_add_string (h, _("HKP Keyserver")); |
496 |
|
combox_add_string (h, _("LDAP Keyserver")); |
497 |
|
combox_add_string (h, _("Finger Keyserver")); |
498 |
|
SendMessage (h, CB_SETCURSEL, 0, 0); |
499 |
|
} |
500 |
|
|
501 |
|
|
502 |
|
/* Dialog box procedure for modify keyservers. */ |
503 |
|
BOOL CALLBACK |
504 |
|
keyserver_modify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
505 |
|
{ |
506 |
|
static keyserver_rec_t ctx; |
507 |
|
char tmp[128]; |
508 |
|
|
509 |
|
switch (msg) { |
510 |
|
case WM_INITDIALOG: |
511 |
|
fill_keyserv_types (dlg); |
512 |
|
ctx = (keyserver_rec_t)lparam; |
513 |
|
if (ctx->mode) { |
514 |
|
SendDlgItemMessage (dlg, IDC_KSERVADD_TYPES, CB_SETCURSEL, ctx->proto, 0); |
515 |
|
SetDlgItemText (dlg, IDC_KSERVADD_HOST, ctx->name); |
516 |
|
SetDlgItemInt (dlg, IDC_KSERVADD_PORT, ctx->port, FALSE); |
517 |
|
EnableWindow (GetDlgItem (dlg, IDC_KSERVADD_HOST), FALSE); |
518 |
|
EnableWindow (GetDlgItem (dlg, IDC_KSERVADD_TYPES), FALSE); |
519 |
|
} |
520 |
|
else |
521 |
|
SetDlgItemInt (dlg, IDC_KSERVADD_PORT, 11371, FALSE); |
522 |
|
SetWindowText (dlg, _("Edit Keyserver")); |
523 |
|
SetDlgItemText (dlg, IDOK, _("&Add")); |
524 |
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
525 |
|
SetDlgItemText (dlg, IDC_KSERVADD_TYPEINF, _("Type:")); |
526 |
|
SetDlgItemText (dlg, IDC_KSERVADD_PORTINF, _("Port:")); |
527 |
|
SetDlgItemText (dlg, IDC_KSERVADD_HOSTINF, _("Host name:")); |
528 |
|
SetForegroundWindow (dlg); |
529 |
|
break; |
530 |
|
|
531 |
|
case WM_COMMAND: |
532 |
|
switch (LOWORD (wparam)) { |
533 |
|
case IDOK: |
534 |
|
if (!GetDlgItemText (dlg, IDC_KSERVADD_HOST, tmp, sizeof (tmp)-1)) { |
535 |
|
msg_box (dlg, _("Please enter a host name"), _("Keyserver"), MB_ERR); |
536 |
|
return FALSE; |
537 |
|
} |
538 |
|
ctx->port = GetDlgItemInt (dlg, IDC_KSERVADD_PORT, NULL, FALSE); |
539 |
|
if (ctx->port > 65535) { |
540 |
|
msg_box (dlg, _("Invalid port, valid numbers are < 65535"), _("Keyserver"), MB_ERR); |
541 |
|
return FALSE; |
542 |
|
} |
543 |
|
ctx->proto = SendDlgItemMessage (dlg, IDC_KSERVADD_TYPES, CB_GETCURSEL, 0, 0); |
544 |
|
ctx->cancel = false; |
545 |
|
ctx->name[0] = '\0'; |
546 |
|
if (!strstr (tmp, "://")) { |
547 |
|
switch (ctx->proto) { |
548 |
|
case KSPROTO_HTTP: strcpy (ctx->name, "http://"); break; |
549 |
|
case KSPROTO_LDAP: strcpy (ctx->name, "ldap://"); break; |
550 |
|
case KSPROTO_FINGER:strcpy (ctx->name, "finger://"); break; |
551 |
|
} |
552 |
|
} |
553 |
|
strcat (ctx->name, tmp); |
554 |
|
ctx->cancel = false; |
555 |
|
EndDialog (dlg, TRUE); |
556 |
|
break; |
557 |
|
|
558 |
|
case IDCANCEL: |
559 |
|
ctx->cancel = true; |
560 |
|
EndDialog (dlg, FALSE); |
561 |
|
break; |
562 |
|
} |
563 |
|
break; |
564 |
|
} |
565 |
|
|
566 |
|
return FALSE; |
567 |
|
} |
568 |
|
|
569 |
/* Dialog box procedure to access keyservers. */ |
/* Dialog box procedure to access keyservers. */ |
570 |
BOOL CALLBACK |
BOOL CALLBACK |
571 |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
572 |
{ |
{ |
573 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
574 |
static int lv_idx = 0; |
static int lv_idx = 0; |
|
int rc, proto_nr = 0; |
|
|
char kserver[128], pattern[128]; |
|
|
char proto[16]; |
|
575 |
keyserver_ctx ksc; |
keyserver_ctx ksc; |
576 |
|
struct keyserver_rec_s edit; |
577 |
|
char kserver[128], pattern[128]; |
578 |
|
char proto[16], *fpr = NULL; |
579 |
|
int rc, proto_nr = 0; |
580 |
|
|
581 |
switch ( msg ) { |
switch (msg) { |
582 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
583 |
SetWindowText (dlg, _("Keyserver Access")); |
SetWindowText (dlg, _("Keyserver Access")); |
584 |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
587 |
SetDlgItemText (dlg, IDC_KEYSERVER_INFO, |
SetDlgItemText (dlg, IDC_KEYSERVER_INFO, |
588 |
_("Please enter the key ID or email address you search for")); |
_("Please enter the key ID or email address you search for")); |
589 |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
590 |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange proxy")); |
591 |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
592 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
593 |
|
|
|
set_proxy (dlg); |
|
594 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
595 |
|
set_default_ks (lv); |
596 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
597 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
598 |
return TRUE; |
return TRUE; |
600 |
case WM_NOTIFY: |
case WM_NOTIFY: |
601 |
NMHDR *notify; |
NMHDR *notify; |
602 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
603 |
if( notify && notify->code == NM_CLICK |
if (!notify) |
604 |
&& notify->idFrom == IDC_KEYSERVER_LIST ) |
break; |
605 |
lv_idx = listview_get_curr_pos( lv ); |
if (notify->code == NM_CLICK |
606 |
|
&& notify->idFrom == IDC_KEYSERVER_LIST) |
607 |
|
lv_idx = listview_get_curr_pos (lv); |
608 |
|
else if (notify->code == NM_RCLICK && |
609 |
|
notify->idFrom == IDC_KEYSERVER_LIST) { |
610 |
|
POINT p; |
611 |
|
GetCursorPos (&p); |
612 |
|
HMENU hm, pop; |
613 |
|
hm = LoadMenu (glob_hinst, (LPCTSTR)IDR_WINPT_KEYSERVER_CTX); |
614 |
|
pop = GetSubMenu (hm, 0); |
615 |
|
set_menu_text (pop, ID_KSERVCTX_ADD, _("&Add")); |
616 |
|
set_menu_text (pop, ID_KSERVCTX_DEL, _("&Remove")); |
617 |
|
set_menu_text (pop, ID_KSERVCTX_EDIT, _("&Edit")); |
618 |
|
TrackPopupMenu (pop, 0, p.x, p.y, 0, dlg, NULL); |
619 |
|
DestroyMenu (hm); |
620 |
|
DestroyMenu (pop); |
621 |
|
} |
622 |
|
|
623 |
return TRUE; |
return TRUE; |
624 |
|
|
625 |
case WM_DESTROY: |
case WM_DESTROY: |
626 |
if( lv ) { |
if (lv) { |
627 |
listview_release( lv ); |
listview_release (lv); |
628 |
lv = NULL; |
lv = NULL; |
629 |
} |
} |
630 |
lv_idx = 0; |
lv_idx = 0; |
631 |
return FALSE; |
return FALSE; |
632 |
|
|
633 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
634 |
if( LOWORD( wparam ) == SC_CLOSE ) |
if (LOWORD (wparam) == SC_CLOSE) |
635 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
636 |
return FALSE; |
return FALSE; |
637 |
|
|
638 |
case WM_COMMAND: |
case WM_COMMAND: |
639 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
640 |
case IDC_KEYSERVER_PROXSETT: |
case IDC_KEYSERVER_PROXSETT: |
641 |
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, glob_hwnd, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, |
642 |
keyserver_proxy_dlg_proc, NULL, |
dlg, keyserver_proxy_dlg_proc, NULL, |
643 |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY ); |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY); |
|
set_proxy( dlg ); |
|
644 |
return TRUE; |
return TRUE; |
645 |
|
|
646 |
case IDC_KEYSERVER_INDEX: |
case IDC_KEYSERVER_INDEX: |
652 |
return FALSE; |
return FALSE; |
653 |
} |
} |
654 |
} |
} |
655 |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
656 |
if (*proto == 'L') { |
proto, sizeof (proto)-1); |
657 |
msg_box( dlg, _("This is not implemented yet!"), _("Keyserver"), MB_ERR ); |
if (!strncmp (proto, "ldap", 4)) { |
658 |
|
msg_box (dlg, _("This is not implemented yet!"), |
659 |
|
_("Keyserver"), MB_ERR); |
660 |
return FALSE; |
return FALSE; |
661 |
} |
} |
662 |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
663 |
|
kserver, sizeof (kserver)-1); |
664 |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
665 |
msg_box (dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO); |
msg_box (dlg, _("Please enter the search pattern."), |
666 |
|
_("Keyserver"), MB_INFO); |
667 |
return FALSE; |
return FALSE; |
668 |
} |
} |
669 |
ksc.name = kserver; |
ksc.name = kserver; |
670 |
ksc.pattern = pattern; |
ksc.pattern = pattern; |
671 |
ksc.port = kserver_get_port (lv); |
ksc.port = kserver_get_port (lv); |
672 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
673 |
hkpsearch_dlg_proc, (LPARAM) &ksc ); |
hkpsearch_dlg_proc, (LPARAM) &ksc); |
674 |
return TRUE; |
return TRUE; |
675 |
|
|
676 |
case IDC_KEYSERVER_RECV: |
case IDC_KEYSERVER_RECV: |
683 |
return FALSE; |
return FALSE; |
684 |
} |
} |
685 |
} |
} |
686 |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
687 |
|
proto, sizeof (proto)-1); |
688 |
proto_nr = KSPROTO_HTTP; |
proto_nr = KSPROTO_HTTP; |
689 |
if( *proto == 'L' ) |
if (!strncmp (proto, "ldap", 4)) |
690 |
proto_nr = KSPROTO_LDAP; |
proto_nr = KSPROTO_LDAP; |
691 |
else if( *proto == 'F' ) |
else if (!strncmp (proto, "finger", 6)) |
692 |
proto_nr = KSPROTO_FINGER; |
proto_nr = KSPROTO_FINGER; |
693 |
listview_get_item_text( lv, lv_idx, 0, kserver, sizeof (kserver)-1 ); |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
694 |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1 ) ) { |
kserver, sizeof (kserver)-1); |
695 |
msg_box( dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO ); |
if (!GetDlgItemText(dlg, IDC_KEYSERVER_SEARCH, |
696 |
|
pattern, sizeof (pattern)-1)) { |
697 |
|
msg_box (dlg, _("Please enter the search pattern."), |
698 |
|
_("Keyserver"), MB_INFO); |
699 |
return FALSE; |
return FALSE; |
700 |
} |
} |
701 |
if( proto_nr == KSPROTO_LDAP && strchr( pattern, '@' ) ) { |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
702 |
msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO ); |
msg_box (dlg, _("Only keyids are allowed."), |
703 |
|
_("Keyserver"), MB_INFO); |
704 |
return FALSE; |
return FALSE; |
705 |
} |
} |
706 |
else if (proto_nr == KSPROTO_FINGER) { |
else if (proto_nr == KSPROTO_FINGER) { |
707 |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
708 |
msg_box (dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO); |
msg_box (dlg, _("Only enter the name of the user."), |
709 |
|
_("Keyserver"), MB_INFO); |
710 |
return FALSE; |
return FALSE; |
711 |
} |
} |
712 |
} |
} |
713 |
else if( check_pattern( pattern ) ) { |
else if (check_pattern (pattern)) { |
714 |
msg_box( dlg, _("Only email addresses or keyids are allowed."), _("HKP Keyserver"), MB_INFO ); |
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
715 |
|
_("Keyserver"), MB_INFO); |
716 |
return FALSE; |
return FALSE; |
717 |
} |
} |
718 |
rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0); |
rc = keyserver_recv_key (dlg, kserver, kserver_get_port (lv), |
719 |
if (!rc) |
pattern, proto_nr, 0, |
720 |
keycache_set_reload (1); |
&fpr); |
721 |
|
if (!rc && fpr != NULL) { |
722 |
|
keycache_update (0, fpr); |
723 |
|
free_if_alloc (fpr); |
724 |
|
} |
725 |
return TRUE; |
return TRUE; |
726 |
|
|
727 |
case IDC_KEYSERVER_DEFAULT: |
case IDC_KEYSERVER_DEFAULT: |
728 |
save_default_ks (lv); |
save_default_ks (lv); |
729 |
break; |
break; |
730 |
|
|
731 |
|
case ID_KSERVCTX_ADD: |
732 |
|
memset (&edit, 0, sizeof (edit)); |
733 |
|
edit.mode = false; |
734 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_ADD, dlg, |
735 |
|
keyserver_modify_dlg_proc, |
736 |
|
(LPARAM)&edit, _("Edit Keyserver"), 0); |
737 |
|
if (!edit.cancel) |
738 |
|
keyserver_add (lv, &edit); |
739 |
|
return TRUE; |
740 |
|
|
741 |
|
case ID_KSERVCTX_EDIT: |
742 |
|
memset (&edit, 0, sizeof (edit)); |
743 |
|
edit.mode = true; |
744 |
|
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
745 |
|
edit.name, sizeof (edit.name)-1); |
746 |
|
listview_get_item_text (lv, lv_idx, KS_COL_PORT, pattern, 32); |
747 |
|
edit.port = atoi (pattern); |
748 |
|
if (!strncmp (edit.name, "hkp", 3) || !strncmp (edit.name, "http", 4)) |
749 |
|
edit.proto = KSPROTO_HTTP; |
750 |
|
else if (!strncmp (edit.name, "ldap", 4)) |
751 |
|
edit.proto = KSPROTO_LDAP; |
752 |
|
else |
753 |
|
edit.proto = KSPROTO_FINGER; |
754 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_ADD, dlg, |
755 |
|
keyserver_modify_dlg_proc, |
756 |
|
(LPARAM)&edit, _("Edit Keyserver"), 0); |
757 |
|
if (!edit.cancel) |
758 |
|
keyserver_edit (lv, &edit); |
759 |
|
break; |
760 |
|
|
761 |
|
case ID_KSERVCTX_DEL: |
762 |
|
keyserver_remove (lv); |
763 |
|
return TRUE; |
764 |
|
|
765 |
case IDCANCEL: |
case IDCANCEL: |
766 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
771 |
|
|
772 |
return FALSE; |
return FALSE; |
773 |
} |
} |
|
|
|