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