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 |
* This file is part of WinPT. |
* |
5 |
* |
* This file is part of WinPT. |
6 |
* WinPT is free software; you can redistribute it and/or modify |
* |
7 |
* it under the terms of the GNU General Public License as published by |
* WinPT is free software; you can redistribute it and/or modify |
8 |
* the Free Software Foundation; either version 2 of the License, or |
* it under the terms of the GNU General Public License as published by |
9 |
* (at your option) any later version. |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* |
* (at your option) any later version. |
11 |
* WinPT is distributed in the hope that it will be useful, |
* |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* WinPT is distributed in the hope that it will be useful, |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* GNU General Public License for more details. |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* |
* GNU General Public License for more details. |
16 |
* You should have received a copy of the GNU General Public License |
* |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* You should have received a copy of the GNU General Public License |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
*/ |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
20 |
|
*/ |
21 |
#include <windows.h> |
#ifdef HAVE_CONFIG_H |
22 |
#include <commctrl.h> |
#include <config.h> |
23 |
#include <malloc.h> |
#endif |
24 |
|
|
25 |
#include "../resource.h" |
#include <windows.h> |
26 |
#include "wptKeyserver.h" |
#include <commctrl.h> |
27 |
#include "wptErrors.h" |
#include <malloc.h> |
28 |
#include "wptTypes.h" |
|
29 |
#include "wptCommonCtl.h" |
#include "resource.h" |
30 |
#include "wptNLS.h" |
#include "wptKeyserver.h" |
31 |
#include "wptW32API.h" |
#include "wptErrors.h" |
32 |
#include "wptVersion.h" |
#include "wptTypes.h" |
33 |
#include "wptGPG.h" |
#include "wptCommonCtl.h" |
34 |
#include "wptKeyManager.h" |
#include "wptNLS.h" |
35 |
#include "wptContext.h" /* for passphrase_s */ |
#include "wptW32API.h" |
36 |
#include "wptDlgs.h" |
#include "wptVersion.h" |
37 |
|
#include "wptGPG.h" |
38 |
|
#include "wptKeyManager.h" |
39 |
#define MAX_KEYSIZE 70000 |
#include "wptContext.h" /* for passphrase_s */ |
40 |
|
#include "wptDlgs.h" |
41 |
char * get_reg_entry_keyserver (const char *); |
|
42 |
int set_reg_entry_keyserver (const char *, const char *); |
|
43 |
|
#define MAX_KEYSIZE 70000 |
44 |
|
|
45 |
static void |
char* get_reg_entry_keyserver (const char *); |
46 |
hkp_err_box (HWND dlg, const char * host, u16 port, int rc) |
int set_reg_entry_keyserver (const char *, const char *); |
47 |
{ |
|
48 |
const char *err = kserver_strerror(); |
|
49 |
|
/* Print out keyserver error and a possible Winsock error. */ |
50 |
log_box( _("Keyserver"), MB_ERR, "%s:%d: %s", host, port, winpt_strerror (rc)); |
static void |
51 |
if (err) |
hkp_err_box (HWND dlg, const char *host, WORD port, int rc) |
52 |
msg_box (dlg, err, wsock_strerror (), MB_ERR); |
{ |
53 |
} /* hkp_err_box */ |
const char *err = kserver_strerror (); |
54 |
|
|
55 |
|
log_box (_("Keyserver"), MB_ERR, "%s:%d: %s", |
56 |
int |
host, port, winpt_strerror (rc)); |
57 |
hkp_send_key (HWND dlg, const char *kserver, u16 port, const char *pattern) |
if (err) |
58 |
{ |
msg_box (dlg, err, wsock_strerror (), MB_ERR); |
59 |
gpgme_ctx_t c; |
} |
60 |
gpgme_data_t keydata; |
|
61 |
gpgme_error_t ec; |
|
62 |
char *rawkey = NULL, msg[1024]; |
/* Send the extracted key with keyid @pattern to the |
63 |
size_t n; |
keyserver @kserver (port @port). |
64 |
int rc; |
Return value: 0 on success. */ |
65 |
|
int |
66 |
ec = gpgme_new( &c ); |
hkp_send_key (HWND dlg, const char *kserver, WORD port, const char *pattern) |
67 |
if( ec ) |
{ |
68 |
BUG( NULL ); |
gpgme_ctx_t ctx; |
69 |
gpgme_set_armor (c, 1); |
gpgme_data_t keydata; |
70 |
ec = gpgme_data_new( &keydata ); |
gpgme_error_t ec; |
71 |
if( ec ) |
char *rawkey = NULL; |
72 |
BUG( NULL ); |
char msg[384]; |
73 |
rc = (int) gpgme_op_export( c, pattern, 0, keydata ); |
size_t n; |
74 |
if( rc ) { |
|
75 |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Export"), MB_ERR ); |
ec = gpgme_new (&ctx); |
76 |
goto leave; |
if (ec) |
77 |
} |
BUG (NULL); |
78 |
rawkey = gpgme_data_release_and_get_mem (keydata, &n); |
gpgme_set_armor (ctx, 1); |
79 |
rc = kserver_sendkey (kserver, port, rawkey, n); |
ec = gpgme_data_new (&keydata); |
80 |
if (rc) { |
if (ec) |
81 |
hkp_err_box (dlg, kserver, port, rc); |
BUG (NULL); |
82 |
goto leave; |
ec = gpgme_op_export (ctx, pattern, 0, keydata); |
83 |
} |
if (ec) { |
84 |
|
msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR); |
85 |
_snprintf (msg, sizeof (msg) -1, _("Key '%s' successfully sent"), pattern); |
goto leave; |
86 |
status_box (dlg, msg, _("GnuPG status")); |
} |
87 |
|
rawkey = gpgme_data_release_and_get_mem (keydata, &n); |
88 |
leave: |
ec = kserver_sendkey (kserver, port, rawkey, n); |
89 |
gpgme_release (c); |
if (ec) { |
90 |
if (rawkey) |
hkp_err_box (dlg, kserver, port, ec); |
91 |
gpgme_free (rawkey); |
goto leave; |
92 |
return rc; |
} |
93 |
} /* hkp_send_key */ |
|
94 |
|
_snprintf (msg, sizeof (msg) -1, _("Key '%s' successfully sent"), pattern); |
95 |
|
status_box (dlg, msg, _("GnuPG status")); |
96 |
int |
|
97 |
hkp_recv_key (HWND dlg, const char *kserver, u16 port, |
leave: |
98 |
const char *pattern, int proto, int flags) |
gpgme_release (ctx); |
99 |
{ |
if (rawkey) |
100 |
gpgme_ctx_t ctx; |
gpgme_free (rawkey); |
101 |
gpgme_data_t keydata; |
return ec? -1 : 0; |
102 |
gpgme_error_t ec; |
} |
103 |
gpgme_import_result_t import_res; |
|
104 |
int rc; |
|
105 |
char *rawkey = NULL, msg[384]; |
|
106 |
|
/* Show all received keys from the keyserver. */ |
107 |
rawkey = new char[MAX_KEYSIZE]; |
static void |
108 |
if (!rawkey) |
show_imported_keys (gpgme_import_result_t res) |
109 |
BUG (0); |
{ |
110 |
memset (rawkey, 0, MAX_KEYSIZE); |
gpgme_import_status_t t; |
111 |
if( proto == KSPROTO_LDAP ) { |
gpgme_key_t key; |
112 |
rc = ldap_recvkey( kserver, pattern, rawkey, MAX_KEYSIZE-1 ); |
gpgme_data_t msg; |
113 |
if( rc ) { |
gpgme_ctx_t ctx; |
114 |
msg_box( dlg, _("LDAP key import failed.\n" |
gpgme_error_t err; |
115 |
"Please make sure you have an online connection" |
const char *s; |
116 |
" and gpgkeys_ldap.exe is installed"), |
char *p; |
117 |
_("Keyserver"), MB_ERR ); |
size_t n=0; |
118 |
free_if_alloc( rawkey ); |
|
119 |
return rc; |
if (!res) |
120 |
} |
return; |
121 |
} |
|
122 |
else if (proto == KSPROTO_FINGER) { |
err = gpgme_data_new (&msg); |
123 |
rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
if (err) |
124 |
if (rc) { |
BUG (NULL); |
125 |
log_box (_("Keyserver"), MB_ERR, _("Finger key import failed: %s\n"), |
err = gpgme_new (&ctx); |
126 |
winpt_strerror (rc)); |
if (err) |
127 |
free_if_alloc (rawkey); |
BUG (NULL); |
128 |
return rc; |
if (res->considered > 1) { |
129 |
} |
s = _("WARNING: multiple keys matched request.\n\n"); |
130 |
} |
gpgme_data_write (msg, s, strlen (s)); |
131 |
else if( ( rc = kserver_recvkey( kserver, port, kserver_check_keyid( pattern ), |
} |
132 |
rawkey, MAX_KEYSIZE-1 ) ) ) { |
|
133 |
hkp_err_box (dlg, kserver, port, rc); |
if (res->unchanged == res->considered) |
134 |
free_if_alloc (rawkey); |
s = _("Key(s) successfully received but nothing was changed."); |
135 |
return rc; |
else |
136 |
} |
s = _("Key(s) sucessfully received and imported."); |
137 |
else { |
gpgme_data_write (msg, s, strlen (s)); |
138 |
if( !strstr( rawkey, "BEGIN PGP PUBLIC KEY BLOCK" ) ) { |
gpgme_data_write (msg, "\n\n", 2); |
139 |
msg_box( dlg, _("This is not a valid OpenPGP key."), _("Keyserver"), MB_ERR ); |
|
140 |
goto leave; |
for (t=res->imports; t; t = t->next) { |
141 |
} |
if (!gpgme_get_key (ctx, t->fpr, &key, 0)) { |
142 |
ec = gpgme_new( &ctx ); |
s = key->uids->uid; |
143 |
if( ec ) |
gpgme_data_write (msg, s, strlen (s)); |
144 |
BUG( NULL ); |
gpgme_data_write (msg, "\n", 1); |
145 |
gpgme_data_new_from_mem( &keydata, rawkey, strlen( rawkey ), 1 ); |
gpgme_key_release (key); |
146 |
rc = gpgme_op_import( ctx, keydata ); |
} |
147 |
if( rc ) { |
} |
148 |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Import"), MB_ERR ); |
gpgme_data_write (msg, "\0", 1); |
149 |
goto leave; |
p = gpgme_data_release_and_get_mem (msg, &n); |
150 |
} |
if (p != NULL) { |
151 |
import_res = gpgme_op_import_result (ctx); |
msg_box (NULL, p, _("Imported Keys"), MB_INFO); |
152 |
} |
gpgme_free (p); |
153 |
|
} |
154 |
/* if we use the refresh mode, a lot of keys will be fetched and thus only |
gpgme_release (ctx); |
155 |
a summarize at the end is presented and not for each key. */ |
} |
156 |
if (!(flags & KM_KS_REFRESH)) { |
|
157 |
if (import_res->new_user_ids == 0) { |
|
158 |
_snprintf (msg, DIM (msg)-1, |
/* Receive a key from the keyserver @kserver (port @port) |
159 |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
with the pattern @pattern. |
160 |
status_box (dlg, msg, _("GnuPG Status")); |
Return value: 0 on success. */ |
161 |
rc = WPTERR_GENERAL; |
int |
162 |
goto leave; |
hkp_recv_key2 (HWND dlg, const char *kserver, WORD port, |
163 |
} |
const char *pattern, int proto, int flags, |
164 |
_snprintf (msg, DIM (msg)-1, _("Key '%s' sucessfully received and imported."), pattern); |
char **r_fpr) |
165 |
status_box (dlg, msg, _("GnuPG Status")); |
{ |
166 |
} |
gpgme_ctx_t ctx; |
167 |
|
gpgme_data_t keydata; |
168 |
leave: |
gpgme_error_t ec; |
169 |
free_if_alloc (rawkey); |
gpgme_import_result_t import_res = NULL; |
170 |
gpgme_release (ctx); |
char *rawkey = NULL; |
171 |
gpgme_data_release (keydata); |
int rc; |
172 |
|
|
173 |
return rc; |
/* XXX: implement dynamic buffers. */ |
174 |
} /* hkp_recv_key */ |
rawkey = new char[MAX_KEYSIZE]; |
175 |
|
if (!rawkey) |
176 |
|
BUG (0); |
177 |
#define my_iskeychar(a) ( ( (a) >='0' && (a) <= '9' ) || ( (a) >= 'A' && (a) <= 'F' ) ) |
memset (rawkey, 0, MAX_KEYSIZE); |
178 |
|
if (proto == KSPROTO_LDAP) { |
179 |
static int |
rc = ldap_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
180 |
check_pattern( const char *pattern ) |
if (rc) { |
181 |
{ |
msg_box (dlg, _("LDAP key import failed.\n" |
182 |
int rc = 1; |
"Please make sure you have an online connection" |
183 |
|
" and gpgkeys_ldap.exe is installed"), |
184 |
/* Whitespace are not allowed! */ |
_("Keyserver"), MB_ERR); |
185 |
if( strchr( pattern, ' ') ) { |
free_if_alloc (rawkey); |
186 |
rc = WPTERR_GENERAL; |
return rc; |
187 |
goto leave; |
} |
188 |
} |
} |
189 |
|
else if (proto == KSPROTO_FINGER) { |
190 |
if( (( strstr( pattern, "0x" ) ) && ( strlen( pattern ) == 10 ) ) |
rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
191 |
|| (strstr(pattern, "0x")) && ( strlen( pattern ) == 18 ) ) { |
if (rc) { |
192 |
rc = 0; |
log_box (_("Keyserver"), MB_ERR, |
193 |
goto leave; |
_("Finger key import failed: %s\n"), winpt_strerror (rc)); |
194 |
} |
free_if_alloc (rawkey); |
195 |
|
return rc; |
196 |
if( (( my_iskeychar( pattern[0] )) && ( strlen( pattern ) == 8 ) ) |
} |
197 |
|| (my_iskeychar(pattern[0])) && ( strlen( pattern ) == 16) ) { |
} |
198 |
rc = 0; |
else if ((rc = kserver_recvkey (kserver, port, |
199 |
goto leave; |
kserver_check_keyid (pattern), |
200 |
} |
rawkey, MAX_KEYSIZE-1))) { |
201 |
|
hkp_err_box (dlg, kserver, port, rc); |
202 |
if( ( strchr( pattern, '@' ) ) && ( strlen( pattern ) >= 3 ) ) { |
free_if_alloc (rawkey); |
203 |
rc = 0; |
return rc; |
204 |
goto leave; |
} |
205 |
} |
else { |
206 |
|
if (!strstr (rawkey, "BEGIN PGP PUBLIC KEY BLOCK")) { |
207 |
leave: |
msg_box (dlg, _("This is not a valid OpenPGP key."), |
208 |
return rc; |
_("Keyserver"), MB_ERR); |
209 |
} /* check_pattern */ |
goto leave; |
210 |
|
} |
211 |
|
ec = gpgme_new (&ctx); |
212 |
static void |
if (ec) |
213 |
set_proxy (HWND dlg) |
BUG (NULL); |
214 |
{ |
gpgme_data_new_from_mem (&keydata, rawkey, strlen (rawkey), 1); |
215 |
char proxy[384]; |
rc = gpgme_op_import (ctx, keydata); |
216 |
int port = 0; |
if (rc) { |
217 |
|
msg_box (dlg, gpgme_strerror ((gpgme_error_t)rc), _("Import"), MB_ERR); |
218 |
strcpy (proxy, "HTTP proxy: "); |
goto leave; |
219 |
if (kserver_get_proxy (&port)) { |
} |
220 |
char t[256]; |
import_res = gpgme_op_import_result (ctx); |
221 |
const char *http = kserver_get_proxy (&port); |
if (import_res && r_fpr) |
222 |
_snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port); |
*r_fpr = m_strdup (import_res->imports->fpr); |
223 |
strcat (proxy, t); |
} |
224 |
} |
|
225 |
else |
/* if we use the refresh mode, a lot of keys will be fetched and thus only |
226 |
strcat( proxy, "none" ); |
a summarize at the end is presented and not for each key. */ |
227 |
SetDlgItemText( dlg, IDC_KEYSERVER_PROXY, proxy ); |
if (!(flags & KM_KS_REFRESH)) { |
228 |
} /* set_proxy */ |
show_imported_keys (import_res); |
229 |
|
if (import_res && import_res->unchanged == import_res->considered) { |
230 |
|
rc = WPTERR_GENERAL; /* no keys updated. */ |
231 |
static int inline |
goto leave; |
232 |
kserver_get_pos (listview_ctrl_t lv) |
} |
233 |
{ |
} |
234 |
if (listview_count_items (lv, 0) == 1) |
|
235 |
return 0; |
leave: |
236 |
return listview_get_curr_pos (lv); |
free_if_alloc (rawkey); |
237 |
} |
gpgme_release (ctx); |
238 |
|
gpgme_data_release (keydata); |
239 |
|
|
240 |
static u16 inline |
return rc; |
241 |
kserver_get_port (listview_ctrl_t lv) |
} |
242 |
{ |
|
243 |
char buf[16]; |
|
244 |
|
/* Alias for hkp_recv_key2 but without the ability to return |
245 |
listview_get_item_text (lv, kserver_get_pos (lv), 3, buf, 15); |
the fingerprint of the key. */ |
246 |
return (u16)strtoul (buf, NULL, 10); |
int |
247 |
} |
hkp_recv_key (HWND dlg, const char *kserver, WORD port, |
248 |
|
const char *pattern, int proto, int flags) |
249 |
static void |
{ |
250 |
load_default_ks (listview_ctrl_t lv) |
return hkp_recv_key2 (dlg, kserver, port, pattern, proto, flags, NULL); |
251 |
{ |
} |
252 |
char * p, buf[192]; |
|
253 |
int i; |
|
254 |
|
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
255 |
p = get_reg_entry_keyserver ("Default"); |
|
256 |
if (!p) |
static int |
257 |
return; |
check_pattern (const char *pattern) |
258 |
for( i = 0; i < listview_count_items( lv, 0 ); i++ ) { |
{ |
259 |
listview_get_item_text( lv, i, 0, buf, sizeof (buf)-1 ); |
int rc = 1; |
260 |
if( !strncmp( p, buf, strlen( p ) ) ) { |
|
261 |
listview_add_sub_item( lv, i, 2, "x" ); |
/* Whitespace are not allowed! */ |
262 |
break; |
if (strchr( pattern, ' ')) { |
263 |
} |
rc = WPTERR_GENERAL; |
264 |
} |
goto leave; |
265 |
free_if_alloc (p); |
} |
266 |
} /* load_default_ks */ |
|
267 |
|
if (((strstr (pattern, "0x")) && (strlen (pattern) == 10)) || |
268 |
|
(strstr(pattern, "0x")) && (strlen (pattern) == 18)) { |
269 |
static int |
rc = 0; /* Either long or short keyid */ |
270 |
save_default_ks (listview_ctrl_t lv) |
goto leave; |
271 |
{ |
} |
272 |
char buf[192], port[32]; |
|
273 |
int idx, i; |
if( (( my_iskeychar( pattern[0] )) && ( strlen( pattern ) == 8 ) ) |
274 |
|
|| (my_iskeychar(pattern[0])) && ( strlen( pattern ) == 16) ) { |
275 |
idx = listview_get_curr_pos( lv ); |
rc = 0; |
276 |
if( idx == -1 ) { |
goto leave; |
277 |
msg_box( NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR ); |
} |
278 |
return -1; |
|
279 |
} |
if( ( strchr( pattern, '@' ) ) && ( strlen( pattern ) >= 3 ) ) { |
280 |
listview_get_item_text( lv, idx, 1, buf, sizeof (buf)-1 ); |
rc = 0; |
281 |
if( *buf != 'H' ) { |
goto leave; |
282 |
msg_box( NULL, _("Only HTTP keyserver can be used."), _("Keyserver"), MB_ERR ); |
} |
283 |
return -1; |
|
284 |
} |
leave: |
285 |
for (i = 0; i < listview_count_items( lv, 0 ); i++) |
return rc; |
286 |
listview_add_sub_item (lv, i, 2, ""); |
} /* check_pattern */ |
287 |
listview_add_sub_item (lv, idx, 2, "x"); |
|
288 |
listview_get_item_text (lv, idx, 0, buf, sizeof (buf)-1); |
|
289 |
set_reg_entry_keyserver ("Default", buf); |
static void |
290 |
i = kserver_get_port (lv); |
set_proxy (HWND dlg) |
291 |
sprintf (port, "%d", i); |
{ |
292 |
set_reg_entry_keyserver ("Default_Port", port); |
char proxy[256]; |
293 |
keyserver_set_default (buf, (u16)i); |
int port = 0; |
294 |
return 0; |
|
295 |
} /* save_default_ks */ |
strcpy (proxy, "HTTP proxy: "); |
296 |
|
if (kserver_get_proxy (&port)) { |
297 |
|
char t[128]; |
298 |
int |
const char *http = kserver_get_proxy (&port); |
299 |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
_snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port); |
300 |
{ |
strcat (proxy, t); |
301 |
struct listview_column_s keyserver[] = { |
} |
302 |
{0, 160, (char *)_("DNS Name")}, |
else |
303 |
{1, 52, (char *)_("Protocol")}, |
strcat (proxy, "none"); |
304 |
{2, 46, (char *)_("Default")}, |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXY, proxy); |
305 |
{3, 46, (char *)_("Port")}, |
} /* set_proxy */ |
306 |
{0, 0, NULL} |
|
307 |
}; |
|
308 |
listview_ctrl_t lv; |
static int inline |
309 |
char buf[32]; |
kserver_get_pos (listview_ctrl_t lv) |
310 |
int j; |
{ |
311 |
|
if (listview_count_items (lv, 0) == 1) |
312 |
listview_new (&lv); |
return 0; |
313 |
lv->ctrl = hwnd; |
return listview_get_curr_pos (lv); |
314 |
for (j=0; keyserver[j].fieldname; j++) |
} |
315 |
listview_add_column (lv, &keyserver[j]); |
|
316 |
for (j = 0; j<MAX_KEYSERVERS; j++) { |
|
317 |
if (!server[j].used) |
static u16 inline |
318 |
continue; |
kserver_get_port (listview_ctrl_t lv) |
319 |
listview_add_item (lv, " "); |
{ |
320 |
listview_add_sub_item (lv, 0, 0, server[j].name); |
char buf[16]; |
321 |
switch (server[j].proto) { |
|
322 |
case KSPROTO_HTTP: |
listview_get_item_text (lv, kserver_get_pos (lv), 3, buf, 15); |
323 |
listview_add_sub_item( lv, 0, 1, "H" ); break; |
return (u16)strtoul (buf, NULL, 10); |
324 |
case KSPROTO_LDAP: |
} |
325 |
listview_add_sub_item( lv, 0, 1, "L" ); break; |
|
326 |
case KSPROTO_FINGER: |
static void |
327 |
listview_add_sub_item( lv, 0, 1, "F" ); break; |
load_default_ks (listview_ctrl_t lv) |
328 |
} |
{ |
329 |
sprintf (buf, "%d", server[j].port); |
char * p, buf[192]; |
330 |
listview_add_sub_item (lv, 0, 3, buf); |
int i; |
331 |
} |
|
332 |
load_default_ks (lv); |
p = get_reg_entry_keyserver ("Default"); |
333 |
if (listview_count_items (lv, 0) == 0) { |
if (!p) |
334 |
listview_add_item (lv, ""); |
return; |
335 |
listview_add_sub_item (lv, 0, 0, DEF_HKP_KEYSERVER); |
for( i = 0; i < listview_count_items( lv, 0 ); i++ ) { |
336 |
listview_add_sub_item (lv, 0, 1, "H"); |
listview_get_item_text( lv, i, 0, buf, sizeof (buf)-1 ); |
337 |
} |
if( !strncmp( p, buf, strlen( p ) ) ) { |
338 |
listview_set_ext_style (lv); |
listview_add_sub_item( lv, i, 2, "x" ); |
339 |
*r_lv = lv; |
break; |
340 |
return 0; |
} |
341 |
} |
} |
342 |
|
free_if_alloc (p); |
343 |
|
} /* load_default_ks */ |
344 |
BOOL CALLBACK |
|
345 |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
|
346 |
{ |
static int |
347 |
static listview_ctrl_t lv = NULL; |
save_default_ks (listview_ctrl_t lv) |
348 |
static int lv_idx = 0; |
{ |
349 |
int rc, proto_nr = 0; |
char buf[192], port[32]; |
350 |
char kserver[128], pattern[128]; |
int idx, i; |
351 |
char proto[16]; |
|
352 |
keyserver_ctx ksc; |
idx = listview_get_curr_pos( lv ); |
353 |
|
if( idx == -1 ) { |
354 |
switch ( msg ) { |
msg_box( NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR ); |
355 |
case WM_INITDIALOG: |
return -1; |
356 |
#ifndef LANG_DE |
} |
357 |
SetWindowText (dlg, _("Keyserver Access")); |
listview_get_item_text( lv, idx, 1, buf, sizeof (buf)-1 ); |
358 |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
if( *buf != 'H' ) { |
359 |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
msg_box( NULL, _("Only HTTP keyserver can be used."), _("Keyserver"), MB_ERR ); |
360 |
_("Send key (default is receiving)")); |
return -1; |
361 |
SetDlgItemText (dlg, IDC_KEYSERVER_INFO, |
} |
362 |
_("Please enter the key ID or email address you search for")); |
for (i = 0; i < listview_count_items( lv, 0 ); i++) |
363 |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
listview_add_sub_item (lv, i, 2, ""); |
364 |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
listview_add_sub_item (lv, idx, 2, "x"); |
365 |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
listview_get_item_text (lv, idx, 0, buf, sizeof (buf)-1); |
366 |
#endif |
set_reg_entry_keyserver ("Default", buf); |
367 |
set_proxy (dlg); |
i = kserver_get_port (lv); |
368 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
sprintf (port, "%d", i); |
369 |
center_window (dlg, NULL); |
set_reg_entry_keyserver ("Default_Port", port); |
370 |
SetForegroundWindow (dlg); |
keyserver_set_default (buf, (u16)i); |
371 |
return TRUE; |
return 0; |
372 |
|
} /* save_default_ks */ |
373 |
case WM_NOTIFY: |
|
374 |
NMHDR *notify; |
|
375 |
notify = (NMHDR *)lparam; |
int |
376 |
if( notify && notify->code == NM_CLICK |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
377 |
&& notify->idFrom == IDC_KEYSERVER_LIST ) |
{ |
378 |
lv_idx = listview_get_curr_pos( lv ); |
struct listview_column_s keyserver[] = { |
379 |
return TRUE; |
{0, 160, (char *)_("DNS Name")}, |
380 |
|
{1, 52, (char *)_("Protocol")}, |
381 |
case WM_DESTROY: |
{2, 46, (char *)_("Default")}, |
382 |
if( lv ) { |
{3, 46, (char *)_("Port")}, |
383 |
listview_release( lv ); |
{0, 0, NULL} |
384 |
lv = NULL; |
}; |
385 |
} |
listview_ctrl_t lv; |
386 |
lv_idx = 0; |
char buf[32]; |
387 |
return FALSE; |
int j; |
388 |
|
|
389 |
case WM_SYSCOMMAND: |
listview_new (&lv); |
390 |
if( LOWORD( wparam ) == SC_CLOSE ) |
lv->ctrl = hwnd; |
391 |
EndDialog( dlg, TRUE ); |
for (j=0; keyserver[j].fieldname; j++) |
392 |
return FALSE; |
listview_add_column (lv, &keyserver[j]); |
393 |
|
for (j = 0; j<MAX_KEYSERVERS; j++) { |
394 |
case WM_COMMAND: |
if (!server[j].used) |
395 |
switch( LOWORD( wparam ) ) { |
continue; |
396 |
case IDC_KEYSERVER_PROXSETT: |
listview_add_item (lv, " "); |
397 |
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, glob_hwnd, |
listview_add_sub_item (lv, 0, 0, server[j].name); |
398 |
keyserver_proxy_dlg_proc, NULL, |
switch (server[j].proto) { |
399 |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY ); |
case KSPROTO_HTTP: |
400 |
set_proxy( dlg ); |
listview_add_sub_item( lv, 0, 1, "H" ); break; |
401 |
return TRUE; |
case KSPROTO_LDAP: |
402 |
|
listview_add_sub_item( lv, 0, 1, "L" ); break; |
403 |
case IDC_KEYSERVER_INDEX: |
case KSPROTO_FINGER: |
404 |
if (!lv_idx) { |
listview_add_sub_item( lv, 0, 1, "F" ); break; |
405 |
lv_idx = kserver_get_pos (lv); |
} |
406 |
if (lv_idx == -1) { |
sprintf (buf, "%d", server[j].port); |
407 |
msg_box (dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO); |
listview_add_sub_item (lv, 0, 3, buf); |
408 |
return FALSE; |
} |
409 |
} |
load_default_ks (lv); |
410 |
} |
if (listview_count_items (lv, 0) == 0) { |
411 |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
listview_add_item (lv, ""); |
412 |
if (*proto == 'L') { |
listview_add_sub_item (lv, 0, 0, DEF_HKP_KEYSERVER); |
413 |
msg_box( dlg, _("This is not implemented yet!"), _("Keyserver"), MB_ERR ); |
listview_add_sub_item (lv, 0, 1, "H"); |
414 |
return FALSE; |
} |
415 |
} |
listview_set_ext_style (lv); |
416 |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
*r_lv = lv; |
417 |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
return 0; |
418 |
msg_box (dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO); |
} |
419 |
return FALSE; |
|
420 |
} |
|
421 |
ksc.name = kserver; |
/* Dialog box procedure to access keyservers. */ |
422 |
ksc.pattern = pattern; |
BOOL CALLBACK |
423 |
ksc.port = kserver_get_port (lv); |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
424 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
{ |
425 |
hkpsearch_dlg_proc, (LPARAM) &ksc ); |
static listview_ctrl_t lv = NULL; |
426 |
return TRUE; |
static int lv_idx = 0; |
427 |
|
static struct genkey_s *key; |
428 |
case IDC_KEYSERVER_RECV: |
keyserver_ctx ksc; |
429 |
memset (&kserver, 0, sizeof (kserver)); |
char kserver[128], pattern[128]; |
430 |
if (!lv_idx) { |
char proto[16]; |
431 |
lv_idx = kserver_get_pos (lv); |
int rc, proto_nr = 0; |
432 |
if (lv_idx == -1) { |
|
433 |
msg_box( dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO ); |
switch (msg) { |
434 |
return FALSE; |
case WM_INITDIALOG: |
435 |
} |
if (lparam != 0) |
436 |
} |
key = (struct genkey_s*)lparam; |
437 |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
SetWindowText (dlg, _("Keyserver Access")); |
438 |
proto_nr = KSPROTO_HTTP; |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
439 |
if( *proto == 'L' ) |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
440 |
proto_nr = KSPROTO_LDAP; |
_("Send key (default is receiving)")); |
441 |
else if( *proto == 'F' ) |
SetDlgItemText (dlg, IDC_KEYSERVER_INFO, |
442 |
proto_nr = KSPROTO_FINGER; |
_("Please enter the key ID or email address you search for")); |
443 |
listview_get_item_text( lv, lv_idx, 0, kserver, sizeof (kserver)-1 ); |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
444 |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1 ) ) { |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
445 |
msg_box( dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO ); |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
446 |
return FALSE; |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
447 |
} |
|
448 |
if( proto_nr == KSPROTO_LDAP && strchr( pattern, '@' ) ) { |
set_proxy (dlg); |
449 |
msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO ); |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
450 |
return FALSE; |
center_window (dlg, NULL); |
451 |
} |
SetForegroundWindow (dlg); |
452 |
else if (proto_nr == KSPROTO_FINGER) { |
return TRUE; |
453 |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
|
454 |
msg_box (dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO); |
case WM_NOTIFY: |
455 |
return FALSE; |
NMHDR *notify; |
456 |
} |
notify = (NMHDR *)lparam; |
457 |
} |
if (notify && notify->code == NM_CLICK |
458 |
else if( check_pattern( pattern ) ) { |
&& notify->idFrom == IDC_KEYSERVER_LIST) |
459 |
msg_box( dlg, _("Only email addresses or keyids are allowed."), _("HKP Keyserver"), MB_INFO ); |
lv_idx = listview_get_curr_pos (lv); |
460 |
return FALSE; |
return TRUE; |
461 |
} |
|
462 |
rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0); |
case WM_DESTROY: |
463 |
if (!rc) |
if (lv) { |
464 |
keycache_set_reload (1); |
listview_release (lv); |
465 |
return TRUE; |
lv = NULL; |
466 |
|
} |
467 |
case IDC_KEYSERVER_DEFAULT: |
lv_idx = 0; |
468 |
save_default_ks( lv ); |
return FALSE; |
469 |
break; |
|
470 |
|
case WM_SYSCOMMAND: |
471 |
case IDCANCEL: |
if (LOWORD (wparam) == SC_CLOSE) |
472 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, TRUE); |
473 |
return FALSE; |
return FALSE; |
474 |
} |
|
475 |
break; |
case WM_COMMAND: |
476 |
} |
switch (LOWORD (wparam)) { |
477 |
|
case IDC_KEYSERVER_PROXSETT: |
478 |
return FALSE; |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, |
479 |
} /* keyserver_dlg_proc */ |
dlg, keyserver_proxy_dlg_proc, NULL, |
480 |
|
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY); |
481 |
|
set_proxy (dlg); |
482 |
|
return TRUE; |
483 |
|
|
484 |
|
case IDC_KEYSERVER_INDEX: |
485 |
|
if (!lv_idx) { |
486 |
|
lv_idx = kserver_get_pos (lv); |
487 |
|
if (lv_idx == -1) { |
488 |
|
msg_box (dlg, _("Please select one of the keyservers."), |
489 |
|
_("Keyserver"), MB_INFO); |
490 |
|
return FALSE; |
491 |
|
} |
492 |
|
} |
493 |
|
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
494 |
|
if (*proto == 'L') { |
495 |
|
msg_box (dlg, _("This is not implemented yet!"), |
496 |
|
_("Keyserver"), MB_ERR); |
497 |
|
return FALSE; |
498 |
|
} |
499 |
|
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
500 |
|
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
501 |
|
msg_box (dlg, _("Please enter the search pattern."), |
502 |
|
_("Keyserver"), MB_INFO); |
503 |
|
return FALSE; |
504 |
|
} |
505 |
|
ksc.name = kserver; |
506 |
|
ksc.pattern = pattern; |
507 |
|
ksc.port = kserver_get_port (lv); |
508 |
|
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
509 |
|
hkpsearch_dlg_proc, (LPARAM) &ksc); |
510 |
|
return TRUE; |
511 |
|
|
512 |
|
case IDC_KEYSERVER_RECV: |
513 |
|
memset (&kserver, 0, sizeof (kserver)); |
514 |
|
if (!lv_idx) { |
515 |
|
lv_idx = kserver_get_pos (lv); |
516 |
|
if (lv_idx == -1) { |
517 |
|
msg_box (dlg, _("Please select one of the keyservers."), |
518 |
|
_("Keyserver"), MB_INFO); |
519 |
|
return FALSE; |
520 |
|
} |
521 |
|
} |
522 |
|
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
523 |
|
proto_nr = KSPROTO_HTTP; |
524 |
|
if (*proto == 'L') |
525 |
|
proto_nr = KSPROTO_LDAP; |
526 |
|
else if (*proto == 'F') |
527 |
|
proto_nr = KSPROTO_FINGER; |
528 |
|
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
529 |
|
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
530 |
|
msg_box (dlg, _("Please enter the search pattern."), |
531 |
|
_("Keyserver"), MB_INFO); |
532 |
|
return FALSE; |
533 |
|
} |
534 |
|
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
535 |
|
msg_box (dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO); |
536 |
|
return FALSE; |
537 |
|
} |
538 |
|
else if (proto_nr == KSPROTO_FINGER) { |
539 |
|
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
540 |
|
msg_box (dlg, _("Only enter the name of the user."), |
541 |
|
_("FINGER Keyserver"), MB_INFO); |
542 |
|
return FALSE; |
543 |
|
} |
544 |
|
} |
545 |
|
else if (check_pattern (pattern)) { |
546 |
|
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
547 |
|
_("HKP Keyserver"), MB_INFO); |
548 |
|
return FALSE; |
549 |
|
} |
550 |
|
rc = hkp_recv_key2 (dlg, kserver, kserver_get_port (lv), |
551 |
|
pattern, proto_nr, 0, key? &key->fpr : NULL); |
552 |
|
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; |
559 |
|
|
560 |
|
case IDC_KEYSERVER_DEFAULT: |
561 |
|
save_default_ks (lv); |
562 |
|
break; |
563 |
|
|
564 |
|
case IDCANCEL: |
565 |
|
EndDialog (dlg, FALSE); |
566 |
|
return FALSE; |
567 |
|
} |
568 |
|
break; |
569 |
|
} |
570 |
|
|
571 |
|
return FALSE; |
572 |
|
} |