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