1 |
/* wptKeyserver.cpp - W32 Keyserver Access |
/* wptKeyserver.cpp - W32 Keyserver Access |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* Copyright (C) 2001 Marco Cunha |
* Copyright (C) 2001 Marco Cunha |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
6 |
* |
* |
7 |
* WinPT is free software; you can redistribute it and/or |
* WinPT is free software; you can redistribute it and/or |
8 |
* modify it under the terms of the GNU General Public License |
* modify it under the terms of the GNU General Public License |
9 |
* as published by the Free Software Foundation; either version 2 |
* as published by the Free Software Foundation; either version 2 |
10 |
* of the License, or (at your option) any later version. |
* of the License, or (at your option) any later version. |
11 |
* |
* |
12 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
* General Public License for more details. |
* General Public License for more details. |
16 |
* |
* |
17 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
18 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
*/ |
*/ |
21 |
|
|
22 |
#include <windows.h> |
#ifdef HAVE_CONFIG_H |
23 |
#include <stdio.h> |
#include <config.h> |
24 |
#include <sys/stat.h> |
#endif |
25 |
#include <ctype.h> |
|
26 |
|
#include <windows.h> |
27 |
#include "wptKeyserver.h" |
#include <shlobj.h> |
28 |
#include "wptErrors.h" |
#include <stdio.h> |
29 |
#include "wptTypes.h" |
#include <sys/stat.h> |
30 |
#include "wptNLS.h" |
#include <ctype.h> |
31 |
#include "wptW32API.h" |
|
32 |
#include "wptVersion.h" |
#include "wptKeyserver.h" |
33 |
#include "wptGPG.h" |
#include "wptErrors.h" |
34 |
#include "wptRegistry.h" |
#include "wptTypes.h" |
35 |
|
#include "wptNLS.h" |
36 |
static char base64code[] = |
#include "wptW32API.h" |
37 |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
#include "wptGPG.h" |
38 |
|
#include "wptRegistry.h" |
39 |
keyserver server[MAX_KEYSERVERS] = {0}; |
|
40 |
static keyserver_proxy_ctx proxy = {0}; |
/* Map net_errno to a winsock error. */ |
41 |
static const char * server_list[] = { |
#define net_errno ((int)WSAGetLastError ()) |
42 |
"hkp://wwwkeys.nl.pgp.net", |
|
43 |
"hkp://wwwkeys.pl.pgp.net", |
|
44 |
"hkp://wwwkeys.at.pgp.net", |
keyserver server[MAX_KEYSERVERS] = {0}; |
45 |
"hkp://wwwkeys.ch.pgp.net", |
keyserver_proxy_s proxy = {0}; |
46 |
"hkp://wwwkeys.de.pgp.net", |
static const char *server_list[] = { |
47 |
"hkp://wwwkeys.dk.pgp.net", |
"hkp://gnv.us.ks.cryptnet.net", |
48 |
"hkp://wwwkeys.cz.pgp.net", |
"hkp://keyserver.kjsl.com", |
49 |
"hkp://wwwkeys.es.pgp.net", |
"hkp://sks.keyserver.penguin.de", |
50 |
"hkp://wwwkeys.eu.pgp.net", |
"hkp://subkeys.pgp.net", |
51 |
"hkp://wwwkeys.uk.pgp.net", |
"ldap://keyserver.pgp.com", |
52 |
"hkp://wwwkeys.us.pgp.net", |
NULL |
53 |
"hkp://gnv.us.ks.cryptnet.net", |
}; |
54 |
"hkp://subkeys.pgp.net", |
|
55 |
"ldap://keyserver.pgp.com", |
|
56 |
NULL |
static char hkp_errmsg[1024]; /* Holds the error message from the server */ |
57 |
}; |
static int hkp_err = 0; /* != 0 indicates an error occurred. */ |
58 |
static char hkp_errmsg[1024]; |
|
59 |
static int hkp_err = 0; |
/* Default keyserver and port. */ |
60 |
static u32 conf_timestamp = 0; |
char *default_keyserver = NULL; |
61 |
char * default_keyserver = NULL; |
WORD default_keyserver_port = 0; |
62 |
unsigned short default_keyserver_port = 0; |
|
63 |
|
/* Default socket timeout. */ |
64 |
|
static int default_socket_timeout = 6; |
65 |
static void |
|
66 |
base64_encode( const char *inputstr, char *outputstr, int maxlen ) |
|
67 |
{ |
/* Wrapper for safe memory allocation. */ |
68 |
int index = 0, temp = 0, res = 0, i = 0, inputlen = 0, len = 0; |
static char* |
69 |
|
safe_alloc (DWORD n) |
70 |
inputlen = strlen (inputstr); /* fixme: check if len > maxlen */ |
{ |
71 |
for (i = 0; i <inputlen; i++) { |
char *p; |
72 |
res = temp; |
|
73 |
res = (res << 8) | (inputstr[i] & 0xFF); |
p = new char[n+1]; |
74 |
switch (index++) { |
if (!p) |
75 |
case 0: outputstr[len++] = base64code[res >> 2 & 0x3F]; res &= 0x3; break; |
BUG (0); |
76 |
case 1: outputstr[len++] = base64code[res >> 4 & 0x3F]; res &= 0xF; break; |
memset (p, 0, n); |
77 |
case 2: outputstr[len++] = base64code[res >> 6 & 0x3F]; |
return p; |
78 |
outputstr[len++] = base64code[res & 0x3F]; res = index = 0; break; |
} |
79 |
} |
|
80 |
temp = res; |
/* Basic64 encode the input @inbuf to @outbuf. */ |
81 |
} |
static void |
82 |
|
base64_encode (const char *inbuf, char *outbuf) |
83 |
switch( index ) { |
{ |
84 |
case 0: break; |
char base64code[] = |
85 |
case 2: outputstr[len++] = base64code[temp << 2 & 0x3F]; |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
86 |
outputstr[len++] = '='; break; |
int index = 0, temp = 0, res = 0; |
87 |
case 1: outputstr[len++] = base64code[temp << 4 & 0x3F]; |
int i = 0, inputlen = 0, len = 0; |
88 |
outputstr[len++] = '='; |
|
89 |
outputstr[len++] = '='; |
inputlen = strlen (inbuf); |
90 |
} |
for (i = 0; i < inputlen; i++) { |
91 |
|
res = temp; |
92 |
outputstr[len] = '\0'; |
res = (res << 8) | (inbuf[i] & 0xFF); |
93 |
} /* base64_encode */ |
switch (index++) { |
94 |
|
case 0: |
95 |
|
outbuf[len++] = base64code[res >> 2 & 0x3F]; |
96 |
static const char * |
res &= 0x3; |
97 |
skip_type_prefix (const char * hostname) |
break; |
98 |
{ |
case 1: |
99 |
if (hostname && !strncmp (hostname, "http://", 7)) |
outbuf[len++] = base64code[res >> 4 & 0x3F]; |
100 |
hostname += 7; |
res &= 0xF; |
101 |
else if (hostname && !strncmp (hostname, "hkp://", 6)) |
break; |
102 |
hostname += 6; |
case 2: |
103 |
else if (hostname && !strncmp (hostname, "finger://", 9)) |
outbuf[len++] = base64code[res >> 6 & 0x3F]; |
104 |
hostname += 9; |
outbuf[len++] = base64code[res & 0x3F]; |
105 |
else if (hostname && !strncmp (hostname, "ldap://", 7)) |
res = index = 0; |
106 |
hostname += 7; |
break; |
107 |
return hostname; |
} |
108 |
} |
temp = res; |
109 |
|
} |
110 |
|
|
111 |
static int |
if (index == 2) { |
112 |
check_hkp_response (const char *resp, int recv) |
outbuf[len++] = base64code[temp << 2 & 0x3F]; |
113 |
{ |
outbuf[len++] = '='; |
114 |
int ec, len; |
} |
115 |
char *p, * end; |
else if (index == 1) { |
116 |
|
outbuf[len++] = base64code[temp << 4 & 0x3F]; |
117 |
ec = recv ? WPTERR_WINSOCK_RECVKEY : WPTERR_WINSOCK_SENDKEY; |
outbuf[len++] = '='; |
118 |
if (!strstr (resp, "HTTP/1.0 200 OK")) /* http error */ |
outbuf[len++] = '='; |
119 |
return ec; |
} |
120 |
if (strstr (resp, "Public Key Server -- Error") |
|
121 |
|| strstr (resp, "Public Key Server -- Error") |
outbuf[len] = '\0'; |
122 |
|| strstr (resp, "No matching keys in database")) { |
} |
123 |
p = strstr (resp, "<p>"); |
|
124 |
if (p && strlen (p) < sizeof (hkp_errmsg)) { |
|
125 |
end = strstr (p, "</p>"); |
/* Skip the URL schema and return only the host part of it. */ |
126 |
len = end? (end - p + 1) : strlen (p); |
static const char* |
127 |
strncpy (hkp_errmsg, p, len); |
skip_type_prefix (const char *hostname) |
128 |
hkp_err = 1; |
{ |
129 |
} |
if (hostname && !strncmp (hostname, "http://", 7)) |
130 |
return ec; |
hostname += 7; |
131 |
} |
else if (hostname && !strncmp (hostname, "hkp://", 6)) |
132 |
return 0; |
hostname += 6; |
133 |
} /* check_hkp_response */ |
else if (hostname && !strncmp (hostname, "finger://", 9)) |
134 |
|
hostname += 9; |
135 |
|
else if (hostname && !strncmp (hostname, "ldap://", 7)) |
136 |
static int |
hostname += 7; |
137 |
sock_getline (int fd, char *buf, int buflen, int *nbytes) |
return hostname; |
138 |
{ |
} |
139 |
char ch; |
|
140 |
int count = 0; |
|
141 |
|
/* Check that the keyserver response indicates an OK. |
142 |
if (nbytes) |
Return 0 on success. */ |
143 |
*nbytes = 0; |
static int |
144 |
*buf = 0; |
check_hkp_response (const char *resp, int recv) |
145 |
while (recv (fd, &ch, 1, 0) > 0) { |
{ |
146 |
*buf++ = ch; |
char *p, *end; |
147 |
count++; |
int ec, len; |
148 |
if (ch == '\n' || count == (buflen - 1)) { |
|
149 |
*buf = 0; |
log_debug ("check_hkp_response: '%s'\r\n", resp); |
150 |
if (nbytes) |
ec = recv ? WPTERR_WINSOCK_RECVKEY : WPTERR_WINSOCK_SENDKEY; |
151 |
*nbytes = count; |
if (!strstr (resp, "HTTP/1.0 200 OK") && |
152 |
return 0; |
!strstr (resp, "HTTP/1.1 200 OK")) /* http error */ |
153 |
} |
return ec; |
154 |
} |
if (strstr (resp, "Public Key Server -- Error") |
155 |
|
|| strstr (resp, "Public Key Server -- Error") |
156 |
return -1; |
|| strstr (resp, "No matching keys in database")) { |
157 |
} /* sock_getline */ |
p = strstr (resp, "<p>"); |
158 |
|
if (p && strlen (p) < sizeof (hkp_errmsg)) { |
159 |
|
end = strstr (p, "</p>"); |
160 |
static int |
len = end? (end - p + 1) : strlen (p); |
161 |
sock_select( int fd ) |
memset (hkp_errmsg, 0, sizeof (hkp_errmsg)); |
162 |
{ |
strncpy (hkp_errmsg, p, len); |
163 |
FD_SET rfd; |
hkp_err = 1; |
164 |
timeval tv = {1, 0}; |
} |
165 |
|
return ec; |
166 |
FD_ZERO( &rfd ); |
} |
167 |
FD_SET( fd, &rfd ); |
return 0; |
168 |
if( select( fd + 1, &rfd, NULL, NULL, &tv ) == SOCKET_ERROR ) |
} |
169 |
return SOCKET_ERROR; |
|
170 |
if( FD_ISSET( fd, &rfd ) ) |
|
171 |
return 1; |
/* Read a single line (\r\n) from a socket. |
172 |
return 0; |
Return 0 on success. */ |
173 |
} /* sock_select */ |
static int |
174 |
|
sock_getline (int fd, char *buf, int buflen, int *nbytes) |
175 |
|
{ |
176 |
static int |
char ch; |
177 |
sock_read( int fd, char *buf, int buflen, int *nbytes ) |
int nread = 0; |
178 |
{ |
|
179 |
DWORD nread; |
if (nbytes) |
180 |
int nleft = buflen; |
*nbytes = 0; |
181 |
int rc, n = 0; |
*buf = 0; |
182 |
|
while (recv (fd, &ch, 1, 0) > 0) { |
183 |
while (nleft > 0) { |
*buf++ = ch; |
184 |
if (n >= 10) |
nread++; |
185 |
return WPTERR_WINSOCK_TIMEOUT; |
if (ch == '\r') |
186 |
if ( (rc = sock_select( fd )) == SOCKET_ERROR ) |
continue; /* remove this char. */ |
187 |
return SOCKET_ERROR; |
if (ch == '\n' || nread == (buflen - 1)) { |
188 |
else if( !rc ) |
*buf = 0; |
189 |
n++; |
if (nbytes) |
190 |
else { |
*nbytes = nread; |
191 |
nread = recv(fd, buf, nleft, 0); |
return 0; |
192 |
if (nread == SOCKET_ERROR) |
} |
193 |
return SOCKET_ERROR; |
} |
194 |
else if (!nread) |
|
195 |
break; |
return -1; |
196 |
nleft -= nread; |
} |
197 |
buf += nread; |
|
198 |
} |
|
199 |
} |
/* Perform a select() on the given fd to find out |
200 |
if (nbytes) |
is there is data for reading. Wait at least @nsecs seconds. */ |
201 |
*nbytes = buflen - nleft; |
static int |
202 |
|
sock_select (int fd, int nsecs) |
203 |
return 0; |
{ |
204 |
} /* sock_read */ |
FD_SET rfd; |
205 |
|
timeval tv = {nsecs, 0}; |
206 |
|
|
207 |
static int |
FD_ZERO (&rfd); |
208 |
sock_write( int fd, const char *buf, int buflen ) |
FD_SET (fd, &rfd); |
209 |
{ |
if (select (fd + 1, &rfd, NULL, NULL, &tv) == SOCKET_ERROR) { |
210 |
DWORD nwritten; |
log_debug ("sock_select: select() failed ec=%d.\r\n", net_errno); |
211 |
int nleft = buflen; |
return SOCKET_ERROR; |
212 |
|
} |
213 |
while (nleft > 0) { |
if (FD_ISSET (fd, &rfd)) |
214 |
nwritten = send (fd, buf, nleft, 0); |
return 1; |
215 |
if (nwritten == SOCKET_ERROR) |
return 0; |
216 |
return SOCKET_ERROR; |
} |
217 |
nleft -= nwritten; |
|
218 |
buf += nwritten; |
|
219 |
} |
/* Read from a socket @fd to buffer @buf with a fixed timeout |
220 |
|
of 10 seconds. The amount of bytes which were read are |
221 |
return 0; |
returned in @nbytes. |
222 |
} /* sock_write */ |
Return value: 0 on success. */ |
223 |
|
static int |
224 |
|
sock_read (int fd, char *buf, int buflen, int *nbytes) |
225 |
void |
{ |
226 |
set_default_kserver (void) |
DWORD nread; |
227 |
{ |
int nleft = buflen; |
228 |
char * p = get_reg_entry_keyserver ("Default"); |
int rc, n = 0; |
229 |
free_if_alloc (default_keyserver); |
|
230 |
default_keyserver = p && *p != ' ' ? p : m_strdup (DEF_HKP_KEYSERVER); |
if (nbytes) |
231 |
p = get_reg_entry_keyserver ("Default_Port"); |
*nbytes = 0; |
232 |
if (p && *p) { |
while (nleft > 0) { |
233 |
default_keyserver_port = (u16)strtoul (p, NULL, 10); |
if (n >= default_socket_timeout) |
234 |
free_if_alloc (p); |
return WPTERR_WINSOCK_TIMEOUT; |
235 |
} |
rc = sock_select (fd, 1); |
236 |
else |
if (rc == SOCKET_ERROR) |
237 |
default_keyserver_port = HKP_PORT; |
return rc; |
238 |
} /* set_default_kserver */ |
else if (!rc) |
239 |
|
n++; |
240 |
|
else { |
241 |
/* |
nread = recv (fd, buf, nleft, 0); |
242 |
* Initialize the Winsock2 interface. |
if (nread == SOCKET_ERROR) { |
243 |
*/ |
log_debug ("sock_read: recv() failed ec=%d.\r\n", net_errno); |
244 |
int |
return SOCKET_ERROR; |
245 |
wsock_init (void) |
} |
246 |
{ |
else if (!nread) |
247 |
WSADATA wsa; |
break; |
248 |
|
nleft -= nread; |
249 |
if (WSAStartup (0x202, &wsa)) |
buf += nread; |
250 |
return WPTERR_WINSOCK_INIT; |
} |
251 |
set_default_kserver (); |
} |
252 |
return 0; |
if (nbytes) |
253 |
} /* wsock_init */ |
*nbytes = buflen - nleft; |
254 |
|
|
255 |
|
return 0; |
256 |
/* |
} |
257 |
* Should be called after the keyserver access. |
|
258 |
*/ |
|
259 |
void |
/* Helper to create a string from the gpgme data and |
260 |
wsock_end (void) |
then release the gpgme data object. */ |
261 |
{ |
char* |
262 |
int i; |
data_release_and_get_mem (gpgme_data_t in, int *r_bufferlen) |
263 |
|
{ |
264 |
free_if_alloc (default_keyserver); |
size_t n; |
265 |
default_keyserver = NULL; |
char *buffer, *p; |
266 |
for (i=0; i < MAX_KEYSERVERS; i++) { |
|
267 |
if (server[i].used) |
gpg_data_putc (in, '\0'); |
268 |
free_if_alloc (server[i].name); |
p = gpgme_data_release_and_get_mem (in, &n); |
269 |
} |
buffer = m_strdup (p); |
270 |
WSACleanup (); |
if (r_bufferlen) |
271 |
} /* wsock_end */ |
*r_bufferlen = (int)n; |
272 |
|
gpgme_free (p); |
273 |
|
return buffer; |
274 |
const char* |
} |
275 |
wsock_strerror( void ) |
|
276 |
{ |
|
277 |
static char buf[384]; |
/* Read much data as possible from the socket @fd and |
278 |
int ec = WSAGetLastError( ); |
return the data in @buffer. Caller must free data. |
279 |
|
Return value: 0 on success. */ |
280 |
switch ( ec ) { |
int |
281 |
case WSAENETDOWN: return _("The network subsystem has failed"); |
sock_read_ext (int fd, char **buffer, int *r_bufferlen) |
282 |
case WSAHOST_NOT_FOUND: return _("Authoritative Answer Host not found"); |
{ |
283 |
case WSAETIMEDOUT: return _("The connection has been dropped because of a network failure"); |
gpgme_data_t dh; |
284 |
default: _snprintf( buf, sizeof (buf) -1, _("Unknown Winsock error ec=%d"),ec); return buf; |
char buf[1024]; |
285 |
} |
size_t n=0; |
286 |
return NULL; |
int nread, rc; |
287 |
} /* wsock_strerror */ |
|
288 |
|
if (gpgme_data_new (&dh)) |
289 |
|
BUG (0); |
290 |
const char* |
while (n < 10) { |
291 |
kserver_strerror( void ) |
rc = sock_select (fd, 1); |
292 |
{ |
if (rc == SOCKET_ERROR) { |
293 |
if( hkp_err ) |
gpgme_data_release (dh); |
294 |
return hkp_errmsg; |
return rc; |
295 |
return NULL; |
} |
296 |
} /* kserver_strerror */ |
else if (!rc) |
297 |
|
n++; |
298 |
|
else { |
299 |
const char * |
nread = recv (fd, buf, sizeof (buf), 0); |
300 |
kserver_get_hostname (int idx, int type, u16 *port) |
if (nread == SOCKET_ERROR) |
301 |
{ |
return SOCKET_ERROR; |
302 |
if (type == -1) { |
else if (!nread) |
303 |
*port = default_keyserver_port; |
break; |
304 |
return default_keyserver; |
gpgme_data_write (dh, buf, nread); |
305 |
} |
} |
306 |
else if (!type && idx < DIM (server_list)) { |
} |
307 |
*port = HKP_PORT; |
|
308 |
return server_list[idx]; |
*buffer = data_release_and_get_mem (dh, r_bufferlen); |
309 |
} |
return 0; |
310 |
return NULL; |
} |
311 |
} |
|
312 |
|
|
313 |
|
/* Write the buffer @buf with the length @buflen to a socket @fd. */ |
314 |
int |
static int |
315 |
kserver_check_inet_connection (void) |
sock_write (int fd, const char *buf, int buflen) |
316 |
{ |
{ |
317 |
int fd; |
DWORD nwritten; |
318 |
|
int nleft = buflen; |
319 |
if (!kserver_connect (default_keyserver, default_keyserver_port, &fd)) { |
|
320 |
closesocket (fd); |
while (nleft > 0) { |
321 |
return 0; |
nwritten = send (fd, buf, nleft, 0); |
322 |
} |
if (nwritten == SOCKET_ERROR) { |
323 |
return -1; |
log_debug ("sock_write: send() failed ec=%d\r\n", net_errno); |
324 |
} |
return SOCKET_ERROR; |
325 |
|
} |
326 |
|
nleft -= nwritten; |
327 |
/* |
buf += nwritten; |
328 |
* If the request contains the keyid, it have to be |
} |
329 |
* always postfix with '0x'+keyid. This code checks |
|
330 |
* if the keyid is a decimal value and if so if it contains |
return 0; |
331 |
* the '0x'. If not it is inserted. |
} |
332 |
*/ |
|
333 |
const char* |
|
334 |
kserver_check_keyid (const char *keyid) |
/* Initialize the Winsock2 interface.*/ |
335 |
{ |
int |
336 |
static char id[20]; |
wsock_init (void) |
337 |
|
{ |
338 |
if (strstr (keyid, "@")) |
WSADATA wsa; |
339 |
return keyid; /* email address */ |
|
340 |
if (strncmp (keyid, "0x", 2)) { |
if (WSAStartup (0x202, &wsa)) { |
341 |
memset (&id, 0, sizeof (id)); |
log_debug ("wsock_init: WSAStartup failed ec=%d\r\n", net_errno); |
342 |
_snprintf (id, sizeof (id)-1, "0x%s", keyid); |
return WPTERR_WINSOCK_INIT; |
343 |
return id; |
} |
344 |
} |
return 0; |
345 |
return keyid; |
} |
346 |
} /* kserver_check_keyid */ |
|
347 |
|
|
348 |
|
/* Cleanup the Winsock2 interface. */ |
349 |
static void |
void |
350 |
kserver_update_proxyuser (const char *proxy_user, const char *proxy_pass) |
wsock_end (void) |
351 |
{ |
{ |
352 |
char t[257]; /* user:pass = 127+1+127+1 = 257 */ |
char *p; |
353 |
|
int i; |
354 |
free_if_alloc (proxy.base64_user); |
|
355 |
proxy.base64_user = new char[4*strlen( proxy_user ) / 3 + 32]; |
p = make_special_filename (CSIDL_APPDATA, "winpt\\keyserver.conf", NULL); |
356 |
if( !proxy.base64_user ) |
kserver_save_conf (p); |
357 |
BUG (0); |
free_if_alloc (p); |
358 |
_snprintf (t, sizeof (t)-1, "%s:%s", proxy_user, proxy_pass); |
free_if_alloc (default_keyserver); |
359 |
base64_encode (t, proxy.base64_user, 257); |
for (i=0; i < MAX_KEYSERVERS; i++) { |
360 |
free_if_alloc (proxy.user); |
if (server[i].used && server[i].name != NULL) |
361 |
free_if_alloc (proxy.pass); |
free_if_alloc (server[i].name); |
362 |
proxy.user = m_strdup (proxy_user); |
} |
363 |
proxy.pass = m_strdup (proxy_pass); |
kserver_proxy_release (&proxy); |
364 |
} /* kserver_update_proxyuser */ |
WSACleanup (); |
365 |
|
} |
366 |
|
|
367 |
static int |
|
368 |
check_URL (const char * buf) |
/* Return a string representation of a winsock error. */ |
369 |
{ |
const char* |
370 |
if (strlen (buf) < 7) |
wsock_strerror (void) |
371 |
return -1; |
{ |
372 |
if( !strstr (buf, "ldap://") |
int ec = WSAGetLastError (); |
373 |
&& !strstr (buf, "http://") |
|
374 |
&& !strstr (buf, "finger://") |
if (!ec) |
375 |
&& !strstr (buf, "hkp://")) |
return ""; |
376 |
return -1; |
switch (ec) { |
377 |
return 0; |
case WSAENETDOWN: |
378 |
} /* check_URL */ |
return _("Network unreachable"); |
379 |
|
|
380 |
|
case WSAEHOSTUNREACH: |
381 |
static int |
return _("Host unreachable"); |
382 |
proto_from_URL (const char * buf) |
|
383 |
{ |
case WSAHOST_NOT_FOUND: |
384 |
if (strstr( buf, "ldap")) |
return _("Could not resolve host name"); |
385 |
return KSPROTO_LDAP; |
|
386 |
else if (strstr( buf, "finger")) |
case WSAECONNREFUSED: |
387 |
return KSPROTO_FINGER; |
return _("Connection refused"); |
388 |
return KSPROTO_HTTP; |
|
389 |
} /* proto_from_URL */ |
case WSAETIMEDOUT: |
390 |
|
case WSAECONNABORTED: |
391 |
|
return _("Connection timeout"); |
392 |
void |
|
393 |
keyserver_set_default (const char * hostname, u16 port) |
case WSAENETRESET: |
394 |
{ |
case WSAECONNRESET: |
395 |
if (hostname) { |
return _("Connection resetted by peer"); |
396 |
free_if_alloc (default_keyserver); |
|
397 |
default_keyserver = m_strdup (hostname); |
case WSAESHUTDOWN: |
398 |
if (!default_keyserver) |
return _("Socket has been shutdown"); |
399 |
BUG (0); |
|
400 |
default_keyserver_port = port; |
default: |
401 |
} |
break; |
402 |
server[0].name = default_keyserver; |
} |
403 |
server[0].used = 1; |
|
404 |
server[0].port = port; |
return ""; |
405 |
server[0].proto = proto_from_URL (default_keyserver); |
} |
406 |
} /* keyserver_set_default */ |
|
407 |
|
|
408 |
|
/* Set default socket timeout for all reading operations. */ |
409 |
static const char * |
void |
410 |
skip_whitespace (const char * str) |
kserver_set_socket_timeout (int nsec) |
411 |
{ |
{ |
412 |
while (str && *str) |
if (nsec < 0) |
413 |
{ |
nsec = 0; |
414 |
if (*str == ' ' || |
default_socket_timeout = nsec; |
415 |
*str == '\t' || |
} |
416 |
*str == '\n' || |
|
417 |
*str == '\r') |
|
418 |
{ |
/* Return the last keyserver error as a string. */ |
419 |
str++; |
const char* |
420 |
continue; |
kserver_strerror (void) |
421 |
} |
{ |
422 |
break; |
if (hkp_err) |
423 |
} |
return hkp_errmsg; |
424 |
return str; |
return NULL; |
425 |
} |
} |
426 |
|
|
427 |
|
|
428 |
int |
/* Read a keyserver from the list at index @idx. |
429 |
kserver_load_conf (const char * conf) |
Return value: keyserver name at the given position. */ |
430 |
{ |
const char* |
431 |
struct stat statbuf; |
kserver_get_hostname (int idx, int type, WORD *port) |
432 |
FILE *fp; |
{ |
433 |
char buf[1024], * s, * p; |
if (type == -1) { |
434 |
char *user = NULL, *pass = NULL; |
*port = default_keyserver_port; |
435 |
int pos, proxy_auth = 0; |
return default_keyserver; |
436 |
int no_config=0; |
} |
437 |
|
else if (!type && idx < DIM (server_list)) { |
438 |
for (pos = 0; pos < MAX_KEYSERVERS; pos++) { |
*port = HKP_PORT; |
439 |
server[pos].used = 0; |
return server_list[idx]; |
440 |
server[pos].port = HKP_PORT; |
} |
441 |
} |
return NULL; |
442 |
|
} |
443 |
fp = fopen (conf, "rb"); |
|
444 |
if (!fp) { |
|
445 |
for( pos = 0; server_list[pos]; pos++ ) { |
/* Check if the computer is connected to the internet. |
446 |
server[pos].used = 1; |
Return 0 on success -1 otherwise. */ |
447 |
server[pos].name = (char *)server_list[pos]; |
int |
448 |
server[pos].proto = proto_from_URL( server_list[pos] ); |
kserver_check_inet_connection (void) |
449 |
} |
{ |
450 |
no_config=1; |
int fd; |
451 |
} |
|
452 |
get_reg_proxy_prefs( &proxy.host, &proxy.port, &user, &pass ); |
if (!kserver_connect (default_keyserver, default_keyserver_port, &fd)) { |
453 |
if( user && pass ) |
closesocket (fd); |
454 |
kserver_update_proxyuser( user, pass ); |
return 0; |
455 |
else if( user && !pass || !user && pass ) { |
} |
456 |
msg_box( NULL, _("Invalid proxy configuration." |
log_debug ("kserver_check_inet_connection: no inet connection.\r\n"); |
457 |
"You need to set a user and a password" |
return -1; |
458 |
"to use proxy authentication!"), _("Proxy Error"), MB_ERR ); |
} |
459 |
} |
|
460 |
/* check if the host has a http:// prefix and skip it */ |
|
461 |
if( proxy.host && !strncmp( proxy.host, "http://", 7 ) ) { |
/* If the request contains the keyid, it have to be |
462 |
const char *s = proxy.host+7; |
always postfix with '0x'+keyid. This code checks |
463 |
char * p = m_strdup (s); |
if the keyid is a decimal value and if so if it contains |
464 |
if (!p) |
the '0x'. If not it is inserted. */ |
465 |
BUG (0); |
const char* |
466 |
free_if_alloc (proxy.host); |
kserver_check_keyid (const char *keyid) |
467 |
proxy.host = p; |
{ |
468 |
} |
static char id[21]; |
469 |
free_if_alloc (user); |
|
470 |
free_if_alloc (pass); |
if (strstr (keyid, "@")) |
471 |
|
return keyid; /* email address */ |
472 |
pos = 0; |
if (strncmp (keyid, "0x", 2)) { |
473 |
while( fp && !feof( fp ) ) { |
memset (&id, 0, sizeof (id)); |
474 |
s = fgets (buf, sizeof (buf)-1, fp); |
_snprintf (id, sizeof (id)-1, "0x%s", keyid); |
475 |
if (!s) |
return id; |
476 |
break; |
} |
477 |
if (strstr (buf, "\r\n")) |
return keyid; |
478 |
buf[strlen (buf)-2] = '\0'; |
} |
479 |
if (strstr (buf, "\n")) |
|
480 |
buf[strlen (buf)-1] = '\0'; |
|
481 |
s = (char *)skip_whitespace (buf); |
/* Update the keyserver proxy user. */ |
482 |
if (*s == '#' || strlen (s) < 7) |
static void |
483 |
continue; |
update_proxy_user (const char *proxy_user, const char *proxy_pass) |
484 |
if (check_URL (s)) { |
{ |
485 |
msg_box (NULL, _("All entries of this file must have a valid prefix.\n" |
char t[257]; /* user:pass = 127+1+127+1 = 257 */ |
486 |
"Currently HKP/HTTP, LDAP and FINGER are supported.\n"), |
int n = 0; |
487 |
_("Keyserver Error"), MB_ERR); |
|
488 |
continue; |
n = 4*strlen (proxy_user) / 3 + 32 + strlen (proxy_pass) + 2; |
489 |
} |
free_if_alloc (proxy.base64_user); |
490 |
p = strchr (s+6, ':'); |
proxy.base64_user = safe_alloc (n+1); |
491 |
server[pos].used = 1; |
_snprintf (t, sizeof (t)-1, "%s:%s", proxy_user, proxy_pass); |
492 |
server[pos].proto = proto_from_URL (s); |
base64_encode (t, proxy.base64_user); |
493 |
if (!p) |
free_if_alloc (proxy.user); |
494 |
server[pos].name = m_strdup (s); |
free_if_alloc (proxy.pass); |
495 |
else { |
proxy.user = m_strdup (proxy_user); |
496 |
server[pos].port = atol (p+1); |
proxy.pass = m_strdup (proxy_pass); |
497 |
if (server[pos].port < 0 || server[pos].port > 65536) |
} |
498 |
server[pos].port = HKP_PORT; |
|
499 |
server[pos].name = new char [(p-s)+2]; |
|
500 |
if (!server[pos].name) |
/* Check that the given buffer contains a valid keyserver URL. */ |
501 |
BUG (0); |
static int |
502 |
memset (server[pos].name, 0, (p-s)+2); |
check_URL (const char * buf) |
503 |
memcpy (server[pos].name, s, (p-s)); |
{ |
504 |
} |
if (strlen (buf) < 7) |
505 |
pos++; |
return -1; |
506 |
if (pos > MAX_KEYSERVERS) |
if (!strstr (buf, "ldap://") |
507 |
{ |
&& !strstr (buf, "http://") |
508 |
msg_box (NULL, _("The keyserver limit is exceeded"), _("Keyserver Warning"), MB_INFO); |
&& !strstr (buf, "finger://") |
509 |
break; |
&& !strstr (buf, "hkp://")) |
510 |
} |
return -1; |
511 |
} |
return 0; |
512 |
if (fp) |
} |
513 |
fclose (fp); |
|
514 |
if (!pos) |
|
515 |
{ |
/* Get the port number from the given protocol. */ |
516 |
/* only issue an error if the config file exist but it has no valid entries. */ |
static int |
517 |
keyserver_set_default (NULL, HKP_PORT); |
port_from_proto (int proto) |
518 |
if (!no_config) |
{ |
519 |
return WPTERR_CONFIG_FILE; |
switch (proto) { |
520 |
} |
case KSPROTO_LDAP: return 0; |
521 |
|
case KSPROTO_FINGER: return FINGER_PORT; |
522 |
if (!stat (conf, &statbuf)) |
case KSPROTO_HTTP: return HKP_PORT; |
523 |
conf_timestamp = statbuf.st_mtime; |
} |
524 |
return 0; |
return 0; |
525 |
} /* kserver_load_conf */ |
} |
526 |
|
|
527 |
|
|
528 |
const char * |
/* Get the port number from the given URL. */ |
529 |
kserver_get_proxy (int * r_port) |
static int |
530 |
{ |
proto_from_URL (const char *buf) |
531 |
if (proxy.host) |
{ |
532 |
{ |
if (strstr (buf, "ldap")) |
533 |
if (r_port) |
return KSPROTO_LDAP; |
534 |
*r_port = proxy.port; |
else if (strstr( buf, "finger")) |
535 |
return proxy.host; |
return KSPROTO_FINGER; |
536 |
} |
return KSPROTO_HKP; |
537 |
return NULL; |
} |
538 |
} /* kserver_get_proxy */ |
|
539 |
|
|
540 |
|
/* Set the default keyserver. |
541 |
const char * |
If @hostname is NULL, use the predefined keyserver. */ |
542 |
kserver_get_proxy_info( int id ) |
void |
543 |
{ |
keyserver_set_default (const char *hostname, WORD port) |
544 |
switch( id ) { |
{ |
545 |
case PROXY_USER: return proxy.user; |
if (!port) |
546 |
case PROXY_PASS: return proxy.pass; |
port = HKP_PORT; |
547 |
} |
if (hostname != NULL) { |
548 |
return NULL; |
free_if_alloc (default_keyserver); |
549 |
} /* kserver_get_proxy_info */ |
default_keyserver = m_strdup (hostname); |
550 |
|
default_keyserver_port = port; |
551 |
|
} |
552 |
/* |
if (!default_keyserver) { |
553 |
* Connect to the keyserver 'hostname'. |
default_keyserver = m_strdup (DEF_HKP_KEYSERVER); |
554 |
* We always use the HKP port. |
default_keyserver_port = HKP_PORT; |
555 |
*/ |
} |
556 |
int |
server[0].name = m_strdup (default_keyserver); |
557 |
kserver_connect (const char *hostname, u16 port, int *conn_fd) |
server[0].used = 1; |
558 |
{ |
server[0].port = port; |
559 |
int rc, fd; |
server[0].proto = proto_from_URL (default_keyserver); |
560 |
u32 iaddr; |
} |
561 |
char host[128] = {0}; |
|
562 |
struct hostent *hp; |
|
563 |
struct sockaddr_in sock; |
/* Skip all kind of whitespace chars in @str. */ |
564 |
|
static const char* |
565 |
if (debug) |
skip_whitespace (const char *str) |
566 |
log_f ("kserver_connect: %s:%d\r\n", hostname, port); |
{ |
567 |
if (!port) |
while (str && *str) { |
568 |
port = HKP_PORT; |
if (*str == ' ' || |
569 |
if (conn_fd) |
*str == '\t' || |
570 |
*conn_fd = 0; |
*str == '\n' || |
571 |
hostname = skip_type_prefix (hostname); |
*str == '\r') { |
572 |
|
str++; |
573 |
memset (&sock, 0, sizeof (sock)); |
continue; |
574 |
sock.sin_family = AF_INET; |
} |
575 |
sock.sin_port = proxy.host? htons (proxy.port) : htons (port); |
break; |
576 |
if (proxy.host) |
} |
577 |
strncpy (host, proxy.host, 127); |
return str; |
578 |
else |
} |
579 |
strncpy (host, hostname, 127); |
|
580 |
|
|
581 |
if ((iaddr = inet_addr (host)) != INADDR_NONE) |
/* Save the keyserver config file in @conf. */ |
582 |
memcpy (&sock.sin_addr, &iaddr, sizeof (iaddr)); |
int |
583 |
else if ((hp = gethostbyname (host))) { |
kserver_save_conf (const char *conf) |
584 |
if (hp->h_addrtype != AF_INET) |
{ |
585 |
return WPTERR_WINSOCK_RESOLVE; |
FILE *fp; |
586 |
else if (hp->h_length != 4) |
int pos; |
587 |
return WPTERR_WINSOCK_RESOLVE; |
|
588 |
memcpy (&sock.sin_addr, hp->h_addr, hp->h_length); |
fp = fopen (conf, "wb"); |
589 |
} |
if (!fp) { |
590 |
else { |
msg_box (NULL, _("Could not save keyserver.conf file"), |
591 |
if (debug) |
_("Keyserver"), MB_ERR); |
592 |
log_f ("gethostbyname: failed.\r\n"); |
return -1; |
593 |
return WPTERR_WINSOCK_RESOLVE; |
} |
594 |
} |
|
595 |
fd = socket (AF_INET, SOCK_STREAM, 0); |
fprintf (fp, "# do NOT manually modify this file, it will be " |
596 |
if (fd == INVALID_SOCKET) |
"generated automatically!!\r\n"); |
597 |
return WPTERR_WINSOCK_SOCKET; |
for (pos = 0; pos < MAX_KEYSERVERS; pos++) { |
598 |
rc = connect (fd, (struct sockaddr *) &sock, sizeof (sock)); |
if (!server[pos].used) |
599 |
if (rc == SOCKET_ERROR) { |
continue; |
600 |
if (debug) |
fprintf (fp, "%s:%d\r\n", server[pos].name, server[pos].port); |
601 |
log_f ("connect: failed.\r\n"); |
} |
602 |
closesocket(fd); |
fclose (fp); |
603 |
return WPTERR_WINSOCK_CONNECT; |
return 0; |
604 |
} |
} |
605 |
|
|
606 |
if (conn_fd) |
|
607 |
*conn_fd = fd; |
/* Load the keyserver config file @conf. */ |
608 |
WSASetLastError(0); |
int |
609 |
return 0; |
kserver_load_conf (const char *conf) |
610 |
} /* kserver_connect */ |
{ |
611 |
|
FILE *fp; |
612 |
|
char buf[1024], *s, *p; |
613 |
static char* |
char *user = NULL, *pass = NULL; |
614 |
kserver_urlencode (const char *pubkey, int octets, int *newlen) |
int no_config=0, chk_pos=0; |
615 |
{ |
int pos; |
616 |
char *p, numbuf[5]; |
|
617 |
size_t j = 0; |
for (pos = 0; pos < MAX_KEYSERVERS; pos++) { |
618 |
int i, size; |
server[pos].used = 0; |
619 |
|
server[pos].port = HKP_PORT; |
620 |
p = new char [2*octets]; |
} |
621 |
if (!p) |
|
622 |
BUG (0); |
fp = fopen (conf, "rb"); |
623 |
|
if (!fp) { |
624 |
for (size=0, i=0; i<octets; i++) { |
for (pos = 0; server_list[pos]; pos++) { |
625 |
if (isalnum (pubkey[i]) || pubkey[i] == '-') { |
server[pos].used = 1; |
626 |
p[size] = pubkey[i]; |
server[pos].name = m_strdup (server_list[pos]); |
627 |
size++; |
server[pos].proto = proto_from_URL (server_list[pos]); |
628 |
} |
} |
629 |
else if (pubkey[i] == ' ') { |
no_config=1; |
630 |
p[size] = '+'; |
} |
631 |
size++; |
get_reg_proxy_prefs (&proxy); |
632 |
} |
if (user && pass) |
633 |
else { |
update_proxy_user (user, pass); |
634 |
sprintf(numbuf, "%%%02X", pubkey[i]); |
else if (user && !pass || !user && pass) { |
635 |
for (j = 0; j<strlen(numbuf); j++) { |
msg_box (NULL, _("Invalid proxy configuration." |
636 |
p[size] = numbuf[j]; |
"You need to set a user and a password" |
637 |
size++; |
"to use proxy authentication!"), |
638 |
} |
_("Proxy Error"), MB_ERR); |
639 |
} |
} |
640 |
} |
/* check if the host has a http:// prefix and skip it */ |
641 |
p[size] = '\0'; |
if (proxy.host && !strncmp (proxy.host, "http://", 7)) { |
642 |
*newlen = size; |
char *host = m_strdup (proxy.host+7); |
643 |
return p; |
free_if_alloc (proxy.host); |
644 |
} /* kserver_urlencode */ |
proxy.host = host; |
645 |
|
} |
646 |
|
free_if_alloc (user); |
647 |
/* |
free_if_alloc (pass); |
648 |
* Format a request for the given keyid (send). |
|
649 |
*/ |
pos = 0; |
650 |
static char* |
while (fp && !feof (fp)) { |
651 |
kserver_send_request (const char *hostname, u16 port, const char *pubkey, int octets) |
s = fgets (buf, sizeof (buf)-1, fp); |
652 |
{ |
if (!s) |
653 |
char *request = NULL, *enc_pubkey = NULL; |
break; |
654 |
int reqlen, enc_octets; |
if (strstr (buf, "\r\n")) |
655 |
|
buf[strlen (buf)-2] = '\0'; |
656 |
if (debug) |
if (strstr (buf, "\n")) |
657 |
log_f ("kserver_send_request: %s:%d\n", hostname, port); |
buf[strlen (buf)-1] = '\0'; |
658 |
if (!port) |
s = (char *)skip_whitespace (buf); |
659 |
port = HKP_PORT; |
if (*s == '#' || strlen (s) < 7) |
660 |
reqlen = 512 + strlen (hostname) + 2*strlen (pubkey); |
continue; |
661 |
request = new char[reqlen]; |
if (check_URL (s)) { |
662 |
if (!request) |
msg_box (NULL, _("All entries of this file must have a valid prefix.\n" |
663 |
BUG (0); |
"Currently HKP/HTTP, LDAP and FINGER are supported.\n"), |
664 |
enc_pubkey = kserver_urlencode (pubkey, octets, &enc_octets); |
_("Keyserver Error"), MB_ERR); |
665 |
if (!enc_pubkey || !enc_octets) { |
continue; |
666 |
free_if_alloc (request); |
} |
667 |
return NULL; |
chk_pos = 6; |
668 |
} |
if (strstr (s, "finger")) |
669 |
|
chk_pos = 10; |
670 |
if (proxy.user) { |
p = strchr (s+chk_pos, ':'); |
671 |
_snprintf (request, reqlen-1, |
server[pos].used = 1; |
672 |
"POST http://%s:%d/pks/add HTTP/1.0\r\n" |
server[pos].proto = proto_from_URL (s); |
673 |
"Referer: \r\n" |
server[pos].port = port_from_proto (server[pos].proto); |
674 |
"User-Agent: WinPT/W32\r\n" |
if (!p) |
675 |
"Host: %s:%d\r\n" |
server[pos].name = m_strdup (s); |
676 |
"Proxy-Authorization: Basic %s\r\n" |
else { |
677 |
"Content-type: application/x-www-form-urlencoded\r\n" |
server[pos].port = atol (p+1); |
678 |
"Content-length: %d\r\n" |
if (server[pos].port < 0 || server[pos].port > 65536) |
679 |
"\r\n" |
server[pos].port = HKP_PORT; |
680 |
"keytext=%s" |
server[pos].name = safe_alloc ((p-s)+2); |
681 |
"\n", |
memset (server[pos].name, 0, (p-s)+2); |
682 |
skip_type_prefix (hostname), port, hostname, port, |
memcpy (server[pos].name, s, (p-s)); |
683 |
proxy.base64_user, enc_octets+9, enc_pubkey); |
} |
684 |
} |
pos++; |
685 |
else { |
if (pos > MAX_KEYSERVERS) { |
686 |
_snprintf (request, reqlen-1, |
msg_box (NULL, _("The keyserver limit is exceeded"), |
687 |
"POST /pks/add HTTP/1.0\r\n" |
_("Keyserver Warning"), MB_INFO); |
688 |
"Referer: \r\n" |
break; |
689 |
"User-Agent: WinPT/W32\r\n" |
} |
690 |
"Host: %s:%d\r\n" |
} |
691 |
"Content-type: application/x-www-form-urlencoded\r\n" |
if (fp) |
692 |
"Content-length: %d\r\n" |
fclose (fp); |
693 |
"\r\n" |
if (!pos) { |
694 |
"keytext=%s" |
/* only issue an error if the config file exist but |
695 |
"\n", |
it has no valid entries. */ |
696 |
skip_type_prefix (hostname), port, enc_octets+9, enc_pubkey); |
keyserver_set_default (NULL, HKP_PORT); |
697 |
} |
if (!no_config) |
698 |
free_if_alloc (enc_pubkey); |
return WPTERR_CONFIG_FILE; |
699 |
if (debug) |
} |
700 |
log_f("%s\n", request); |
|
701 |
return request; |
return 0; |
702 |
} /* kserver_send_request */ |
} |
703 |
|
|
704 |
|
|
705 |
/* |
/* Connect to the keyserver @hostname (port @port). |
706 |
* Interface receiving a public key. |
Return value: 0 on success */ |
707 |
*/ |
int |
708 |
int |
kserver_connect (const char *hostname, WORD port, int *conn_fd) |
709 |
kserver_recvkey (const char *hostname, u16 port, const char *keyid, char *key, int maxkeylen) |
{ |
710 |
{ |
struct hostent *hp; |
711 |
int rc, n; |
struct sockaddr_in sock; |
712 |
int conn_fd; |
char host[128] = {0}; |
713 |
char *request = NULL; |
DWORD iaddr; |
714 |
|
int rc, fd; |
715 |
if (!port) |
|
716 |
port = HKP_PORT; |
log_debug ("kserver_connect: %s:%d\r\n", hostname, port); |
717 |
hkp_err = 0; /* reset */ |
|
718 |
rc = kserver_connect (hostname, port, &conn_fd); |
if (!port) |
719 |
if (rc) |
port = HKP_PORT; |
720 |
goto leave; |
if (conn_fd) |
721 |
|
*conn_fd = 0; |
722 |
request = new char[300+1]; |
hostname = skip_type_prefix (hostname); |
723 |
if (!request) |
|
724 |
BUG (0); |
if (proxy.host && proxy.proto == PROXY_PROTO_HTTP) |
725 |
|
port = proxy.port; |
726 |
if (proxy.host && proxy.user) { |
memset (&sock, 0, sizeof (sock)); |
727 |
_snprintf (request, 300, |
sock.sin_family = AF_INET; |
728 |
"GET http://%s:%d/pks/lookup?op=get&search=%s HTTP/1.0\r\n" |
sock.sin_port = htons (port); |
729 |
"Proxy-Authorization: Basic %s\r\n\r\n", |
if (proxy.host) |
730 |
skip_type_prefix (hostname), port, keyid, proxy.base64_user); |
strncpy (host, proxy.host, 127); |
731 |
} |
else |
732 |
else if (proxy.host) { |
strncpy (host, hostname, 127); |
733 |
_snprintf (request, 300, |
|
734 |
"GET http://%s:%d/pks/lookup?op=get&search=%s HTTP/1.0\r\n\r\n", |
if ((iaddr = inet_addr (host)) != INADDR_NONE) |
735 |
skip_type_prefix (hostname), port, keyid); |
memcpy (&sock.sin_addr, &iaddr, sizeof (iaddr)); |
736 |
} |
else if ((hp = gethostbyname (host))) { |
737 |
else { |
if (hp->h_addrtype != AF_INET || hp->h_length != 4) { |
738 |
_snprintf (request, 300, |
log_debug ("gethostbyname: unknown address type.\r\n"); |
739 |
"GET /pks/lookup?op=get&search=%s HTTP/1.0\r\n\r\n", keyid); |
return WPTERR_WINSOCK_RESOLVE; |
740 |
} |
} |
741 |
if (debug) |
memcpy (&sock.sin_addr, hp->h_addr, hp->h_length); |
742 |
log_f ("%s\n", request); |
} |
743 |
|
else { |
744 |
rc = sock_write (conn_fd, request, strlen (request)); |
log_debug ("gethostbyname: failed ec=%d.\r\n", net_errno); |
745 |
if (rc == SOCKET_ERROR) { |
return WPTERR_WINSOCK_RESOLVE; |
746 |
rc = WPTERR_WINSOCK_RECVKEY; |
} |
747 |
goto leave; |
fd = socket (AF_INET, SOCK_STREAM, 0); |
748 |
} |
if (fd == INVALID_SOCKET) |
749 |
|
return WPTERR_WINSOCK_SOCKET; |
750 |
rc = sock_read( conn_fd, key, maxkeylen, &n ); |
rc = connect (fd, (struct sockaddr *) &sock, sizeof (sock)); |
751 |
if( rc == SOCKET_ERROR ) { |
if (rc == SOCKET_ERROR) { |
752 |
rc = WPTERR_WINSOCK_RECVKEY; |
log_debug ("connect: failed ec=%d.\r\n", net_errno); |
753 |
goto leave; |
closesocket (fd); |
754 |
} |
return WPTERR_WINSOCK_CONNECT; |
755 |
|
} |
756 |
if( debug ) |
|
757 |
log_f("%s\n", key); |
if (proxy.proto == PROXY_PROTO_SOCKS5) { |
758 |
|
rc = socks_handshake (&proxy, fd, hostname, port); |
759 |
rc = check_hkp_response( key, 1 ); |
if (rc) { |
760 |
if( rc ) |
closesocket (fd); |
761 |
goto leave; |
return WPTERR_GENERAL; /* XXX: use better code. */ |
762 |
|
} |
763 |
WSASetLastError( 0 ); |
} |
764 |
|
|
765 |
leave: |
if (conn_fd) |
766 |
closesocket( conn_fd ); |
*conn_fd = fd; |
767 |
free_if_alloc( request ); |
WSASetLastError (0); |
768 |
return rc; |
return 0; |
769 |
} /* kserver_recvkey */ |
} |
770 |
|
|
771 |
|
|
772 |
/* |
static bool |
773 |
* Interface to send a public key. |
URL_must_encoded (const char *url) |
774 |
*/ |
{ |
775 |
int |
if (strchr (url, '.') || strchr (url, '@') || strchr (url, ' ')) |
776 |
kserver_sendkey (const char *hostname, u16 port, const char *pubkey, int len ) |
return true; |
777 |
{ |
return false; |
778 |
int n, rc; |
} |
779 |
int conn_fd; |
|
780 |
char *request = NULL; |
|
781 |
char log[2048]; |
/* Perform URL encoding of the given data. */ |
782 |
|
static char* |
783 |
hkp_err = 0; /* reset */ |
URL_encode (const char *url, DWORD ulen, DWORD *ret_nlen) |
784 |
rc = kserver_connect (hostname, port, &conn_fd); |
{ |
785 |
if (rc) |
gpgme_data_t hd; |
786 |
goto leave; |
char numbuf[5], *p; |
787 |
|
size_t i; |
788 |
request = kserver_send_request (hostname, port, pubkey, len); |
int nlen; |
789 |
if( request == NULL ) { |
|
790 |
rc = WPTERR_GENERAL; |
if (gpgme_data_new (&hd)) |
791 |
goto leave; |
BUG (0); |
792 |
} |
for (i=0; i < ulen; i++) { |
793 |
|
if (isalnum (url[i]) || url[i] == '-') |
794 |
rc = sock_write( conn_fd, request, lstrlen(request) ); |
gpg_data_putc (hd, url[i]); |
795 |
if( rc == SOCKET_ERROR ) { |
else if (url[i] == ' ') |
796 |
rc = WPTERR_WINSOCK_SENDKEY; |
gpg_data_putc (hd, '+'); |
797 |
goto leave; |
else { |
798 |
} |
sprintf (numbuf, "%%%02X", url[i]); |
799 |
|
gpgme_data_write (hd, numbuf, strlen (numbuf)); |
800 |
rc = sock_read( conn_fd, log, sizeof (log)-1, &n ); |
} |
801 |
if( rc == SOCKET_ERROR ) { |
} |
802 |
rc = WPTERR_WINSOCK_SENDKEY; |
|
803 |
goto leave; |
p = data_release_and_get_mem (hd, &nlen); |
804 |
} |
if (ret_nlen) |
805 |
if (debug) |
*ret_nlen = nlen; |
806 |
log_f("%s\n", log); |
return p; |
807 |
|
} |
808 |
rc = check_hkp_response( log, 0 ); |
|
809 |
if( rc ) |
|
810 |
goto leave; |
/* Format a request for the given keyid (send). */ |
811 |
|
static char* |
812 |
WSASetLastError( 0 ); |
kserver_send_request (const char *hostname, WORD port, |
813 |
|
const char *pubkey, DWORD octets) |
814 |
leave: |
{ |
815 |
closesocket( conn_fd ); |
const char *fmt; |
816 |
free_if_alloc( request ); |
char *request; |
817 |
return rc; |
char *enc_pubkey; |
818 |
} /* kserver_sendkey */ |
DWORD enc_octets; |
819 |
|
int reqlen; |
820 |
|
|
821 |
int |
log_debug ("kserver_send_request: %s:%d\r\n", hostname, port); |
822 |
kserver_search_init (const char * hostname, u16 port, const char * keyid, int * conn_fd) |
|
823 |
{ |
if (!port) |
824 |
int rc, sock_fd; |
port = HKP_PORT; |
825 |
char * request = NULL; |
enc_pubkey = URL_encode (pubkey, octets, &enc_octets); |
826 |
|
reqlen = 2*strlen (hostname) + 2*32/*port*/ + enc_octets + 32 /*len*/ + 1; |
827 |
rc = kserver_connect (hostname, port, &sock_fd); |
|
828 |
if (rc) { |
if (proxy.user && proxy.proto == PROXY_PROTO_HTTP) { |
829 |
*conn_fd = 0; |
fmt = "POST http://%s:%d/pks/add HTTP/1.0\r\n" |
830 |
goto leave; |
"Referer: \r\n" |
831 |
} |
"User-Agent: WinPT/W32\r\n" |
832 |
|
"Host: %s:%d\r\n" |
833 |
request = new char[300+1]; |
"Proxy-Authorization: Basic %s\r\n" |
834 |
if (!request) |
"Content-type: application/x-www-form-urlencoded\r\n" |
835 |
BUG (0); |
"Content-length: %d\r\n" |
836 |
|
"\r\n" |
837 |
if (proxy.host && proxy.user) { |
"keytext=%s" |
838 |
_snprintf (request, 300, |
"\r\n"; |
839 |
"GET http://%s:%d/pks/lookup?op=index&search=%s HTTP/1.0\r\n" |
reqlen += strlen (fmt) + strlen (proxy.base64_user) + 1; |
840 |
"Proxy-Authorization: Basic %s\r\n\r\n", |
request = safe_alloc (reqlen+1); |
841 |
skip_type_prefix (hostname), port, keyid, proxy.base64_user); |
_snprintf (request, reqlen, fmt, |
842 |
} |
skip_type_prefix (hostname), port, hostname, port, |
843 |
else if (proxy.host) { |
proxy.base64_user, enc_octets+9, enc_pubkey); |
844 |
_snprintf (request, 300, |
} |
845 |
"GET http://%s:%d/pks/lookup?op=index&search=%s HTTP/1.0\r\n\r\n", |
else { |
846 |
skip_type_prefix (hostname), port, keyid); |
fmt = "POST /pks/add HTTP/1.0\r\n" |
847 |
} |
"Referer: \r\n" |
848 |
else { |
"User-Agent: WinPT/W32\r\n" |
849 |
_snprintf (request, 300, |
"Host: %s:%d\r\n" |
850 |
"GET /pks/lookup?op=index&search=%s HTTP/1.0\r\n\r\n", keyid); |
"Content-type: application/x-www-form-urlencoded\r\n" |
851 |
} |
"Content-length: %d\r\n" |
852 |
|
"\r\n" |
853 |
if (debug) |
"keytext=%s" |
854 |
log_f("%s\n", request); |
"\r\n"; |
855 |
|
reqlen += strlen (fmt)+1; |
856 |
if (sock_write (sock_fd, request, strlen (request)) == SOCKET_ERROR) { |
request = safe_alloc (reqlen+1); |
857 |
rc = WPTERR_GENERAL; |
_snprintf (request, reqlen, fmt, |
858 |
goto leave; |
skip_type_prefix (hostname), port, |
859 |
} |
enc_octets+9, enc_pubkey); |
860 |
|
} |
861 |
*conn_fd = sock_fd; |
|
862 |
|
free_if_alloc (enc_pubkey); |
863 |
leave: |
log_debug ("request:\r\n%s\r\n", request); |
864 |
free_if_alloc (request); |
return request; |
865 |
return rc; |
} |
866 |
} /* kserver_search_init */ |
|
867 |
|
|
868 |
|
/* Interface for receiving a public key. */ |
869 |
int |
int |
870 |
kserver_search_chkresp (int fd) |
kserver_recvkey (const char *hostname, WORD port, const char *keyid, |
871 |
{ |
char **r_key, int *r_keylen) |
872 |
char buf[128]; |
{ |
873 |
int n=0, i=0; |
const char *fmt; |
874 |
|
char *request = NULL; |
875 |
/* parse response 'HTTP/1.0 500 OK' */ |
int conn_fd; |
876 |
if (sock_getline (fd, buf, 127, &n)) |
int rc, reqlen; |
877 |
return WPTERR_KEYSERVER_NOTFOUND; |
|
878 |
if (strncmp (buf, "HTTP/1.", 7)) |
if (!port) |
879 |
return WPTERR_KEYSERVER_NOTFOUND; |
port = HKP_PORT; |
880 |
i = 8+1; |
hkp_err = 0; /* reset */ |
881 |
if (strncmp (buf+i, "200", 3)) |
rc = kserver_connect (hostname, port, &conn_fd); |
882 |
return WPTERR_KEYSERVER_NOTFOUND; |
if (rc) |
883 |
return 0; |
goto leave; |
884 |
} /* kserver_search_chkresp */ |
|
885 |
|
reqlen = strlen (hostname)+32+strlen (keyid)+1; |
886 |
|
if (proxy.host && proxy.user && proxy.proto == PROXY_PROTO_HTTP) { |
887 |
int |
fmt = "GET http://%s:%d/pks/lookup?op=get&search=%s HTTP/1.0\r\n" |
888 |
kserver_search (int fd, keyserver_key * key) |
"Proxy-Authorization: Basic %s\r\n\r\n"; |
889 |
{ |
reqlen =+ strlen (fmt) + strlen (proxy.base64_user)+1; |
890 |
char buf[1024], *p; |
request = safe_alloc (reqlen+1); |
891 |
int uid_len, nbytes, pos = 0; |
_snprintf (request, reqlen, fmt, skip_type_prefix (hostname), port, |
892 |
|
keyid, proxy.base64_user); |
893 |
if (debug) |
} |
894 |
log_f ("keyserver_search:\n"); |
else if (proxy.host && proxy.proto == PROXY_PROTO_HTTP) { |
895 |
|
fmt = "GET http://%s:%d/pks/lookup?op=get&search=%s HTTP/1.0\r\n\r\n"; |
896 |
if (sock_getline (fd, buf, sizeof (buf), &nbytes)) |
reqlen += strlen (fmt)+1; |
897 |
return WPTERR_GENERAL; |
request = safe_alloc (reqlen+1); |
898 |
|
_snprintf (request, reqlen, fmt, skip_type_prefix (hostname), |
899 |
if (debug) |
port, keyid); |
900 |
log_f ("%s\n", buf); |
} |
901 |
|
else { |
902 |
if (!strncmp (buf, "pub", 3)) { |
fmt = "GET /pks/lookup?op=get&search=%s HTTP/1.0\r\n\r\n"; |
903 |
key->bits = atol (buf+3); |
reqlen += strlen (fmt)+1; |
904 |
p = strchr (buf, '>'); |
request = safe_alloc (reqlen+1); |
905 |
if (p) |
_snprintf (request, reqlen, fmt, keyid); |
906 |
pos = p-buf+1; |
} |
907 |
memcpy (key->keyid, buf+pos, 8); |
|
908 |
key->keyid[8] = '\0'; |
log_debug ("request:\r\n%s\r\n", request); |
909 |
p = strstr (buf, "</a>"); |
|
910 |
if (p) |
rc = sock_write (conn_fd, request, strlen (request)); |
911 |
pos = p-buf+5; |
if (rc == SOCKET_ERROR) { |
912 |
memcpy (key->date, buf+pos, 10); |
rc = WPTERR_WINSOCK_RECVKEY; |
913 |
key->date[10] = '\0'; |
goto leave; |
914 |
pos += 10; |
} |
915 |
p = buf+pos+1; |
|
916 |
while (p && *p != '>') |
rc = sock_read_ext (conn_fd, r_key, r_keylen); |
917 |
p++; |
if (rc == SOCKET_ERROR) { |
918 |
p++; |
rc = WPTERR_WINSOCK_RECVKEY; |
919 |
uid_len = strlen (p) - 10; |
goto leave; |
920 |
memcpy (key->uid, p, uid_len); |
} |
921 |
key->uid[uid_len] = '\0'; |
|
922 |
strcat (key->uid, ">"); |
log_debug ("response:\r\n%s\r\n", *r_key); |
923 |
p = strchr (key->uid, '&'); |
rc = check_hkp_response (*r_key, 1); |
924 |
if (p) { |
if (rc) |
925 |
key->uid[(p-key->uid)] = '<'; |
goto leave; |
926 |
memmove (key->uid+(p-key->uid)+1, key->uid+(p-key->uid)+4, strlen (key->uid)-3); |
|
927 |
} |
WSASetLastError (0); |
928 |
} |
|
929 |
else { |
leave: |
930 |
key->bits = 0; |
closesocket (conn_fd); |
931 |
memset (key, 0, sizeof *key); |
free_if_alloc (request); |
932 |
} |
return rc; |
933 |
|
} |
934 |
return 0; |
|
935 |
} /* kserver_search */ |
|
936 |
|
/* Interface to send a public key. */ |
937 |
|
int |
938 |
static int |
kserver_sendkey (const char *hostname, WORD port, const char *pubkey, int len ) |
939 |
add_node( keyserver_cfgfile *cfg, const char *entry ) |
{ |
940 |
{ |
char *request = NULL; |
941 |
keyserver_node *node; |
char log[2048] = {0}; |
942 |
char *p = NULL; |
int conn_fd, n; |
943 |
|
int rc; |
944 |
p = strchr( entry, '=' ); |
|
945 |
if( p == NULL ) |
hkp_err = 0; /* reset */ |
946 |
return WPTERR_GENERAL; |
rc = kserver_connect (hostname, port, &conn_fd); |
947 |
node = new keyserver_node; |
if (rc) |
948 |
if( !node ) |
goto leave; |
949 |
BUG( NULL ); |
|
950 |
|
request = kserver_send_request (hostname, port, pubkey, len); |
951 |
memset( node, 0, sizeof *node ); |
if (request == NULL) { |
952 |
node->used = 1; |
rc = WPTERR_GENERAL; |
953 |
|
goto leave; |
954 |
node->host.used = 1; |
} |
955 |
node->host.proto = proto_from_URL( entry ); |
|
956 |
memcpy( node->host.name, entry+7, p-entry-7 ); |
rc = sock_write (conn_fd, request, strlen (request)); |
957 |
node->next = cfg->list; |
if (rc == SOCKET_ERROR) { |
958 |
cfg->list = node; |
rc = WPTERR_WINSOCK_SENDKEY; |
959 |
|
goto leave; |
960 |
return 0; |
} |
961 |
} /* add_node */ |
|
962 |
|
rc = sock_read (conn_fd, log, sizeof (log)-1, &n); |
963 |
|
if (rc == SOCKET_ERROR) { |
964 |
void |
rc = WPTERR_WINSOCK_SENDKEY; |
965 |
kserver_change_proxy( keyserver_proxy_ctx *ctx ) |
goto leave; |
966 |
{ |
} |
967 |
proxy.port = ctx->port; |
|
968 |
free_if_alloc (proxy.host); |
log_debug ("kserver_sendkey: read %d bytes\r\n%s\r\n", n, log); |
969 |
proxy.host = ctx->host? m_strdup( ctx->host ) : NULL; |
rc = check_hkp_response (log, 0); |
970 |
free_if_alloc( proxy.pass ); |
if (rc) |
971 |
proxy.pass = ctx->pass? m_strdup( ctx->pass ) : NULL; |
goto leave; |
972 |
free_if_alloc( proxy.user ); |
|
973 |
proxy.user = ctx->user? m_strdup( ctx->user ) : NULL; |
WSASetLastError (0); |
974 |
set_reg_proxy_prefs( proxy.host, proxy.port, proxy.user, proxy.pass ); |
|
975 |
} /* kserver_change_proxy */ |
leave: |
976 |
|
closesocket (conn_fd); |
977 |
|
free_if_alloc (request); |
978 |
int |
return rc; |
979 |
kserver_read_config( const char *fname, keyserver_cfgfile **ret_cfg ) |
} |
980 |
{ |
|
981 |
FILE *fp; |
|
982 |
keyserver_cfgfile *cfg; |
/* Check keyserver response. */ |
983 |
char buf[256]; |
static int |
984 |
int rc = 0; |
kserver_search_chkresp (int fd) |
985 |
|
{ |
986 |
*ret_cfg = NULL; |
char buf[128]; |
987 |
fp = fopen( fname, "rb" ); |
int n=0; |
988 |
if( fp == NULL ) |
|
989 |
return WPTERR_FILE_OPEN; |
/* parse response 'HTTP/1.0 500 OK' */ |
990 |
|
if (sock_getline (fd, buf, sizeof (buf)-1, &n)) |
991 |
cfg = new keyserver_cfgfile; |
return WPTERR_KEYSERVER_NOTFOUND; |
992 |
if ( !cfg ) |
|
993 |
BUG( NULL ); |
log_debug ("kserver_search_chkpresp: %s\r\n", buf); |
994 |
memset( cfg, 0, sizeof *cfg ); |
if (strncmp (buf, "HTTP/1.", 7)) |
995 |
|
return WPTERR_KEYSERVER_NOTFOUND; |
996 |
while ( !feof( fp ) ) { |
if (strncmp (buf+(8+1), "200", 3)) |
997 |
if ( fgets( buf, sizeof(buf)-1, fp ) == NULL ) |
return WPTERR_KEYSERVER_NOTFOUND; |
998 |
break; |
return 0; |
999 |
if ( *buf == '\r' || *buf == '\n' || *buf == '#' ) |
} |
1000 |
continue; |
|
1001 |
buf[strlen(buf) -2] = '\0'; |
|
1002 |
if ( !strncmp( buf, "use_proxy=", 10 ) ) { |
/* End the keyserver search procedure. */ |
1003 |
char *p = strchr(buf, ':'); |
void |
1004 |
if (!p) |
kserver_search_end (int conn_fd) |
1005 |
continue; |
{ |
1006 |
cfg->proxy.port = atol( buf+(p-buf+1) ); |
log_debug ("kserver_search_end: fd=%d\r\n", conn_fd); |
1007 |
buf[p-buf] = '\0'; |
closesocket (conn_fd); |
1008 |
cfg->proxy.host = m_strdup( buf+10 ); |
} |
1009 |
} |
|
1010 |
else if ( !strncmp( buf, "proxy_user=", 11 ) ) |
|
1011 |
cfg->proxy.user = m_strdup( buf+11 ); |
/* Extract the amount of keys from the info record. */ |
1012 |
else if ( !strncmp( buf, "proxy_pass=", 11 ) ) |
static int |
1013 |
cfg->proxy.pass = m_strdup( buf+11 ); |
count_keys_in_response (char *buf) |
1014 |
if ( !strncmp( buf, "http://", 7 ) |
{ |
1015 |
|| !strncmp( buf, "hkp://", 6 ) |
char *p; |
1016 |
|| !strncmp( buf, "ldap://", 7 ) ) { |
int recno = 0; |
1017 |
add_node( cfg, buf ); |
int n = 0; |
1018 |
cfg->nlist++; |
|
1019 |
} |
/* info:1:4 */ |
1020 |
} |
if (strncmp (buf, "info", 4)) |
1021 |
|
return 0; |
1022 |
fclose( fp ); |
p = strtok (buf, ":"); |
1023 |
*ret_cfg = cfg; |
while (p != NULL) { |
1024 |
|
recno++; |
1025 |
return rc; |
if (recno == 3) |
1026 |
} /* kserver_read_config */ |
n = atoi (p); |
1027 |
|
p = strtok (NULL, ":"); |
1028 |
|
} |
1029 |
int |
return n; |
1030 |
kserver_write_config( const char * fname, keyserver_cfgfile * cfg ) |
} |
1031 |
{ |
|
1032 |
|
|
1033 |
return 0; |
/* Start the keyserver search. |
1034 |
} |
Connect to host @hostname and port @port. |
1035 |
|
The pattern are given in @pattern. |
1036 |
|
The socket is returned in @conn_fd and @nkeys contains |
1037 |
void |
the amount of keys which were found. */ |
1038 |
kserver_cfgfile_release( keyserver_cfgfile *cfg ) |
int |
1039 |
{ |
kserver_search_begin (const char *hostname, WORD port, |
1040 |
keyserver_node *k, *k2; |
const char *pattern, int *conn_fd, int *nkeys) |
1041 |
|
{ |
1042 |
proxy_release( &cfg->proxy ); |
const char *fmt; |
1043 |
for( k = cfg->list; cfg->nlist--; k = k2 ) { |
char *request = NULL; |
1044 |
k2 = k->next; |
char *enc_patt = NULL; |
1045 |
free_if_alloc( k ); |
char status[128]; |
1046 |
} |
int rc, sock_fd; |
1047 |
free_if_alloc( cfg ); |
int reqlen; |
1048 |
} /* kserver_cfgfile_release */ |
|
1049 |
|
*conn_fd = 0; |
1050 |
|
|
1051 |
void |
rc = kserver_connect (hostname, port, &sock_fd); |
1052 |
proxy_release( keyserver_proxy_ctx *ctx ) |
if (rc) |
1053 |
{ |
goto leave; |
1054 |
free_if_alloc( ctx->host ); |
|
1055 |
free_if_alloc( ctx->pass ); |
enc_patt = URL_encode (pattern, strlen (pattern), NULL); |
1056 |
free_if_alloc( ctx->user ); |
reqlen = strlen (enc_patt) + strlen (hostname) + 32 + 1; |
1057 |
} /* proxy_release */ |
|
1058 |
|
if (proxy.host && proxy.user && proxy.proto == PROXY_PROTO_HTTP) { |
1059 |
|
fmt = "GET http://%s:%d/pks/lookup?options=mr&op=index&search=%s HTTP/1.0\r\n" |
1060 |
int |
"Proxy-Authorization: Basic %s\r\n\r\n"; |
1061 |
ldap_recvkey (const char * host, const char * keyid, char * key, int maxkeylen) |
reqlen += strlen (proxy.base64_user) + strlen (fmt) + 1; |
1062 |
{ |
request = safe_alloc (reqlen+1); |
1063 |
const char *s; |
_snprintf (request, reqlen, fmt, skip_type_prefix (hostname), port, |
1064 |
char *ksprg = NULL, *p = NULL; |
enc_patt, proxy.base64_user); |
1065 |
char temp[512], outf[512]; |
} |
1066 |
FILE * inp; |
else if (proxy.host && proxy.proto == PROXY_PROTO_HTTP) { |
1067 |
int rc, start_key = 0; |
fmt = "GET http://%s:%d/pks/lookup?options=mr&op=index&search=%s HTTP/1.0\r\n\r\n"; |
1068 |
STARTUPINFO si; |
reqlen += strlen (fmt)+1; |
1069 |
PROCESS_INFORMATION pi; |
request = safe_alloc (reqlen+1); |
1070 |
|
_snprintf (request, reqlen, skip_type_prefix (hostname), port, |
1071 |
p = get_gnupg_path (); |
enc_patt); |
1072 |
ksprg = new char[strlen (p) + 1 + 128]; |
} |
1073 |
if (!ksprg) |
else { |
1074 |
BUG (0); |
fmt = "GET /pks/lookup?options=mr&op=index&search=%s HTTP/1.0\r\n\r\n"; |
1075 |
strcpy (ksprg, p); |
reqlen += strlen (fmt)+1; |
1076 |
strcat (ksprg, "\\"); |
request = safe_alloc (reqlen+1); |
1077 |
strcat (ksprg, "gpgkeys_ldap.exe"); |
_snprintf (request, reqlen, fmt, enc_patt); |
1078 |
free_if_alloc (p); |
} |
1079 |
if (file_exist_check (ksprg)) { |
|
1080 |
log_box ( "LDAP Keyserver Plugin", MB_ERR, "Could not find LDAP keyserver module!"); |
log_debug ("kserver_search_begin:\r\n%s\r\n", request); |
1081 |
rc = -1; |
if (sock_write (sock_fd, request, strlen (request)) == SOCKET_ERROR) { |
1082 |
goto leave; |
rc = WPTERR_GENERAL; |
1083 |
} |
goto leave; |
1084 |
GetTempPath (sizeof (temp)-1, temp); |
} |
1085 |
strcpy (outf, temp); |
|
1086 |
strcat (outf, keyid); |
rc = kserver_search_chkresp (sock_fd); |
1087 |
strcat (outf, ".out"); |
if (rc) { |
1088 |
strcat (temp, keyid); |
closesocket (sock_fd); |
1089 |
inp = fopen (temp, "w+b"); |
sock_fd = 0; |
1090 |
if( !inp ) { |
goto leave; |
1091 |
log_box ("LDAP Keyserver Plugin", MB_ERR, "%s: %s", temp, |
} |
1092 |
winpt_strerror (WPTERR_FILE_OPEN)); |
|
1093 |
rc = -1; |
/* Skip all lines until we reach the "info:" record. */ |
1094 |
goto leave; |
for (;;) { |
1095 |
} |
if (sock_getline (sock_fd, status, sizeof (status)-1, &reqlen)) { |
1096 |
fprintf (inp, |
log_debug ("kserver_search_begin: retrieving status line failed.\r\n"); |
1097 |
"VERSION 0\n" |
closesocket (sock_fd); |
1098 |
"HOST %s\n" |
sock_fd = 0; |
1099 |
"OPTION verbose\n" |
rc = WPTERR_GENERAL; |
1100 |
"COMMAND GET\n" |
break; |
1101 |
"\n" |
} |
1102 |
"%s\n", host? skip_type_prefix (host): "64.94.85.200", keyid); |
if (!strncmp (status, "info:", 5)) |
1103 |
fclose (inp); |
break; |
1104 |
|
} |
1105 |
memset (&si, 0, sizeof (si)); |
|
1106 |
si.cb = sizeof (si); |
if (!rc) |
1107 |
si.dwFlags = STARTF_USESHOWWINDOW; |
*nkeys = count_keys_in_response (status); |
1108 |
si.wShowWindow = SW_HIDE; |
*conn_fd = sock_fd; |
1109 |
memset (&pi, 0, sizeof (pi)); |
|
1110 |
p = new char[strlen (ksprg) + strlen (temp) + strlen (outf) + 32]; |
leave: |
1111 |
sprintf (p, "%s -o %s %s", ksprg, outf, temp); |
free_if_alloc (request); |
1112 |
rc = CreateProcess (NULL, p, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); |
free_if_alloc (enc_patt); |
1113 |
if (!rc) { |
return rc; |
1114 |
log_box ("LDAP Keyserver Plugin", MB_ERR, "Could not spawn process"); |
} |
1115 |
rc = -1; |
|
1116 |
goto leave; |
|
1117 |
} |
/* Parse a single pub record returned by the keyserver. */ |
1118 |
CloseHandle (pi.hThread); |
static void |
1119 |
WaitForSingleObject (pi.hProcess, INFINITE); |
parse_pub_record (keyserver_key_s *key, char *buf) |
1120 |
CloseHandle (pi.hProcess); |
{ |
1121 |
|
enum pub_rec_t {ID=1, KEYID, ALGO, SIZE, CREATE, EXPIRE}; |
1122 |
inp = fopen (outf, "rb"); |
char *p; |
1123 |
if (!inp) { |
int recno = 0; |
1124 |
log_box ("LDAP Keyserver Plugin", MB_ERR, "%s: %s", outf, |
|
1125 |
winpt_strerror (WPTERR_FILE_OPEN)); |
/* pub:BF3DF9B4:17:1024:925411133:: */ |
1126 |
rc = -1; |
p = strtok (buf, ":"); |
1127 |
goto leave; |
while (p != NULL) { |
1128 |
} |
recno++; |
1129 |
memset (key, 0, maxkeylen); |
switch (recno) { |
1130 |
while( !feof( inp ) ) { |
case ID: |
1131 |
s = fgets( temp, sizeof (temp)-1, inp ); |
break; |
1132 |
if( !s ) |
|
1133 |
break; |
case KEYID: |
1134 |
if( !start_key && strstr( s, "KEY" ) && strstr( s, "BEGIN" ) ) { |
free_if_alloc (key->keyid); |
1135 |
start_key = 1; |
key->keyid = m_strdup (p); |
1136 |
continue; |
break; |
1137 |
} |
|
1138 |
if( !start_key ) |
case ALGO: |
1139 |
continue; |
key->algo = atoi (p); |
1140 |
strcat( key, temp ); |
break; |
1141 |
maxkeylen -= strlen( temp ); |
|
1142 |
if( maxkeylen < 0 || (strstr( s, "KEY" ) && strstr( s, "END" )) ) |
case SIZE: |
1143 |
break; |
key->bits = atoi (p); |
1144 |
} |
break; |
1145 |
fclose( inp ); |
|
1146 |
|
case CREATE: |
1147 |
leave: |
key->creation = strtoul (p, NULL, 10); |
1148 |
if( !strlen( key ) ) |
break; |
1149 |
rc = WPTERR_WINSOCK_RECVKEY; |
|
1150 |
free_if_alloc( p ); |
case EXPIRE: |
1151 |
free_if_alloc( ksprg ); |
key->expires = strtoul (p, NULL, 10); |
1152 |
return rc; |
break; |
1153 |
} /* ldap_recvkey */ |
} |
1154 |
|
p = strtok (NULL, ":"); |
1155 |
|
} |
1156 |
static int |
|
1157 |
finger_readline (int fd, char * buf, int nbytes) |
} |
1158 |
{ |
|
1159 |
char c = 0; |
|
1160 |
int n, pos = 0; |
/* Parse a single user id returned by the keyserver. */ |
1161 |
|
static void |
1162 |
while (nbytes > 0) { |
parse_uid_record (keyserver_key_s *key, char *buf) |
1163 |
n = recv (fd, &c, 1, 0); |
{ |
1164 |
if (n <= 0) |
enum uid_rec_t {ID=1, UID, CREATE, EXPIRE}; |
1165 |
break; |
keyserver_uid_s *u, *n; |
1166 |
if (c == '\n') |
char *p; |
1167 |
break; |
int recno = 0; |
1168 |
buf[pos++] = c; |
|
1169 |
nbytes--; |
/* uid:Timo Schulz <[email protected]>:1138440360:: */ |
1170 |
} |
u = new keyserver_uid_s; |
1171 |
if (nbytes > 0) |
memset (u, 0, sizeof *u); |
1172 |
buf[pos++] = '\0'; |
|
1173 |
if (n <= 0) |
p = strtok (buf, ":"); |
1174 |
pos = n; |
while (p != NULL) { |
1175 |
return pos; |
recno++; |
1176 |
} |
|
1177 |
|
switch (recno) { |
1178 |
|
case ID: |
1179 |
int |
break; |
1180 |
finger_recvkey (const char * host, const char * user, char * key, int maxkeylen) |
|
1181 |
{ |
case UID: |
1182 |
struct hostent * hp; |
unhexify_buffer (p, &u->uid); |
1183 |
struct sockaddr_in saddr; |
break; |
1184 |
char buf[128]; |
|
1185 |
int fd, nread; |
case CREATE: |
1186 |
int start_key = 0; |
u->creation = strtoul (p, NULL, 10); |
1187 |
int rc=0; |
break; |
1188 |
|
|
1189 |
fd = socket (PF_INET, SOCK_STREAM, 0); |
case EXPIRE: |
1190 |
if (fd == -1) |
u->expires = strtoul (p, NULL, 10); |
1191 |
return WPTERR_WINSOCK_SOCKET; |
break; |
1192 |
hp = gethostbyname (skip_type_prefix (host)); |
} |
1193 |
if (!hp) { |
|
1194 |
closesocket (fd); |
p = strtok (NULL, ":"); |
1195 |
return WPTERR_WINSOCK_RESOLVE; |
} |
1196 |
} |
if (!key->uids) |
1197 |
|
key->uids = u; |
1198 |
memset (&saddr, 0, sizeof (saddr)); |
else { |
1199 |
saddr.sin_family = AF_INET; |
for (n = key->uids; n->next; n=n->next) |
1200 |
saddr.sin_port = htons (FINGER_PORT); |
; |
1201 |
saddr.sin_addr = *(struct in_addr *)hp->h_addr; |
n->next = u; |
1202 |
if (connect (fd, (struct sockaddr *)&saddr, sizeof (saddr))) { |
} |
1203 |
closesocket (fd); |
} |
1204 |
return WPTERR_WINSOCK_CONNECT; |
|
1205 |
} |
|
1206 |
send (fd, user, strlen (user), 0); |
/* Peek the next 3 bytes to check if the next line |
1207 |
send (fd, "\r\n", 2, 0); |
would be a new "pub" record. In this case, return |
1208 |
|
-1 as an EOF indication, 0 otherwise. */ |
1209 |
memset (key, 0, maxkeylen); |
static int |
1210 |
while (maxkeylen > 0) { |
is_key_eof (int fd) |
1211 |
nread = finger_readline (fd, buf, sizeof (buf)-1); |
{ |
1212 |
if (nread <= 0) |
char buf[64]; |
1213 |
break; |
int n; |
1214 |
strcat (buf, "\n"); |
|
1215 |
if (strstr (buf, "BEGIN PGP PUBLIC KEY BLOCK")) { |
n = recv (fd, buf, 3, MSG_PEEK); |
1216 |
strcat (key, buf); |
if (n < 3 || strncmp (buf, "pub", 3)) |
1217 |
start_key = 1; |
return 0; |
1218 |
maxkeylen -= nread; |
return -1; |
1219 |
} |
} |
1220 |
else if (strstr (buf, "END PGP PUBLIC KEY BLOCK" ) && start_key) { |
|
1221 |
strcat (key, buf); |
|
1222 |
start_key--; |
/* Return the next key from the search response. */ |
1223 |
maxkeylen -= nread; |
int |
1224 |
break; |
kserver_search_next (int fd, keyserver_key_s **r_key) |
1225 |
} |
{ |
1226 |
else if (start_key) { |
keyserver_uid_s *uid, *u = NULL; |
1227 |
strcat (key, buf); |
keyserver_key_s *key; |
1228 |
maxkeylen -= nread; |
char buf[512]; |
1229 |
} |
int n = 0; |
1230 |
} |
long max = 0; |
1231 |
closesocket (fd); |
|
1232 |
if (start_key != 0) |
log_debug ("keyserver_search_next:\r\n"); |
1233 |
rc = WPTERR_WINSOCK_RECVKEY; |
*r_key = NULL; |
1234 |
return rc; |
|
1235 |
} |
key = new keyserver_key_s; |
1236 |
|
memset (key, 0, sizeof *key); |
1237 |
|
for (;;) { |
1238 |
|
if (sock_getline (fd, buf, sizeof (buf)-1, &n)) |
1239 |
|
break; |
1240 |
|
/*log_debug ("record: '%s'\r\n", buf); */ |
1241 |
|
if (!strncmp (buf, "pub", 3)) |
1242 |
|
parse_pub_record (key, buf); |
1243 |
|
else |
1244 |
|
parse_uid_record (key, buf); |
1245 |
|
if (is_key_eof (fd)) |
1246 |
|
break; |
1247 |
|
} |
1248 |
|
|
1249 |
|
/* the uid with the newest self sig is used as the |
1250 |
|
primary user id. */ |
1251 |
|
for (uid = key->uids; uid; uid = uid->next) { |
1252 |
|
if (uid->creation > max) { |
1253 |
|
max = uid->creation; |
1254 |
|
u = uid; |
1255 |
|
} |
1256 |
|
} |
1257 |
|
|
1258 |
|
key->main_uid = u? u : key->uids; |
1259 |
|
*r_key = key; |
1260 |
|
return 0; |
1261 |
|
} |
1262 |
|
|
1263 |
|
|
1264 |
|
/* Release the keyserver key @key and all its elements. */ |
1265 |
|
void |
1266 |
|
kserver_release_key (keyserver_key_s *key) |
1267 |
|
{ |
1268 |
|
keyserver_uid_s *u; |
1269 |
|
|
1270 |
|
while (key->uids) { |
1271 |
|
u = key->uids->next; |
1272 |
|
free_if_alloc (key->uids->uid); |
1273 |
|
free_if_alloc (key->uids); |
1274 |
|
key->uids = u; |
1275 |
|
} |
1276 |
|
free_if_alloc (key->keyid); |
1277 |
|
free_if_alloc (key); |
1278 |
|
} |
1279 |
|
|
1280 |
|
|
1281 |
|
/* Release mbmers in the proxy context @ctx. */ |
1282 |
|
void |
1283 |
|
kserver_proxy_release (keyserver_proxy_t ctx) |
1284 |
|
{ |
1285 |
|
free_if_alloc (ctx->host); |
1286 |
|
free_if_alloc (ctx->pass); |
1287 |
|
free_if_alloc (ctx->user); |
1288 |
|
ctx->port = ctx->proto = 0; |
1289 |
|
} |
1290 |
|
|
1291 |
|
|
1292 |
|
/* Spawn a process given by @cmdl. */ |
1293 |
|
static int |
1294 |
|
spawn_application (char *cmdl) |
1295 |
|
{ |
1296 |
|
STARTUPINFO si; |
1297 |
|
PROCESS_INFORMATION pi; |
1298 |
|
int rc = 0; |
1299 |
|
|
1300 |
|
memset (&si, 0, sizeof (si)); |
1301 |
|
si.cb = sizeof (si); |
1302 |
|
si.dwFlags = STARTF_USESHOWWINDOW; |
1303 |
|
si.wShowWindow = SW_HIDE; |
1304 |
|
memset (&pi, 0, sizeof (pi)); |
1305 |
|
|
1306 |
|
if (!CreateProcess (NULL, cmdl, NULL, NULL, FALSE, 0, |
1307 |
|
NULL, NULL, &si, &pi)) { |
1308 |
|
log_box ("Keyserver Plugin", MB_ERR, "Could not spawn helper process"); |
1309 |
|
rc = -1; |
1310 |
|
} |
1311 |
|
|
1312 |
|
CloseHandle (pi.hThread); |
1313 |
|
WaitForSingleObject (pi.hProcess, INFINITE); |
1314 |
|
CloseHandle (pi.hProcess); |
1315 |
|
return rc; |
1316 |
|
} |
1317 |
|
|
1318 |
|
|
1319 |
|
static FILE* |
1320 |
|
do_spawn_ldap_helper (const char *host, const char *keyid) |
1321 |
|
{ |
1322 |
|
FILE *fp = NULL; |
1323 |
|
char *p, *sep; |
1324 |
|
char *ksprg; |
1325 |
|
char outf[256], inf[256]; |
1326 |
|
size_t n; |
1327 |
|
|
1328 |
|
p = get_gnupg_prog (); |
1329 |
|
n = strlen (p) + 1 + 128; |
1330 |
|
ksprg = safe_alloc (n+1); |
1331 |
|
if (!ksprg) |
1332 |
|
BUG (0); |
1333 |
|
sep = strrchr (p, '\\'); |
1334 |
|
if (sep != NULL) |
1335 |
|
p[(sep-p)] = 0; |
1336 |
|
|
1337 |
|
_snprintf (ksprg, n, "%s\\gpgkeys_ldap.exe", p); |
1338 |
|
free_if_alloc (p); |
1339 |
|
if (file_exist_check (ksprg)) { |
1340 |
|
log_box ("LDAP Keyserver Plugin", MB_ERR, |
1341 |
|
"%s: could not find LDAP keyserver module!", ksprg); |
1342 |
|
fp = NULL; |
1343 |
|
goto leave; |
1344 |
|
} |
1345 |
|
get_temp_name (outf, sizeof (outf)-1, keyid); |
1346 |
|
get_temp_name (inf, sizeof (inf)-1, NULL); |
1347 |
|
fp = fopen (inf, "w+b"); |
1348 |
|
if (!fp) { |
1349 |
|
log_box ("LDAP Keyserver Plugin", MB_ERR, "%s: %s", inf, |
1350 |
|
winpt_strerror (WPTERR_FILE_OPEN)); |
1351 |
|
goto leave; |
1352 |
|
} |
1353 |
|
fprintf (fp, |
1354 |
|
"VERSION 1\n" |
1355 |
|
"PROGRAM 1.4.3-cvs\n" |
1356 |
|
"SCHEME ldap\n" |
1357 |
|
"HOST %s\n" |
1358 |
|
"COMMAND GET\n" |
1359 |
|
"\n" |
1360 |
|
"%s\n", |
1361 |
|
host? skip_type_prefix (host): "64.94.85.200", keyid); |
1362 |
|
fclose (fp); |
1363 |
|
|
1364 |
|
p = safe_alloc (strlen (ksprg) + strlen (inf) + strlen (outf) + 32); |
1365 |
|
sprintf (p, "%s -o %s %s", ksprg, outf, inf); |
1366 |
|
if (spawn_application (p)) { |
1367 |
|
fp = NULL; |
1368 |
|
goto leave; |
1369 |
|
} |
1370 |
|
fp = fopen (outf, "rb"); |
1371 |
|
if (!fp) |
1372 |
|
log_box ("LDAP Keyserver Plugin", MB_ERR, "%s: %s", outf, |
1373 |
|
winpt_strerror (WPTERR_FILE_OPEN)); |
1374 |
|
|
1375 |
|
leave: |
1376 |
|
DeleteFile (inf); |
1377 |
|
DeleteFile (outf); |
1378 |
|
free_if_alloc (p); |
1379 |
|
free_if_alloc (ksprg); |
1380 |
|
return fp; |
1381 |
|
} |
1382 |
|
|
1383 |
|
/* Receive an key via LDAP from host @host with the keyid @keyid. |
1384 |
|
@key contains the key on success. */ |
1385 |
|
int |
1386 |
|
ldap_recvkey (const char *host, const char *keyid, |
1387 |
|
char **r_key, int *r_keylen) |
1388 |
|
{ |
1389 |
|
gpgme_data_t raw; |
1390 |
|
FILE *fp; |
1391 |
|
const char *s; |
1392 |
|
char buf[512]; |
1393 |
|
int start_key = 0, failed = 0; |
1394 |
|
int rc = 0; |
1395 |
|
|
1396 |
|
fp = do_spawn_ldap_helper (host, keyid); |
1397 |
|
if (!fp) |
1398 |
|
return WPTERR_GENERAL; |
1399 |
|
|
1400 |
|
if (gpgme_data_new (&raw)) |
1401 |
|
BUG (0); |
1402 |
|
while (!feof (fp)) { |
1403 |
|
s = fgets (buf, sizeof (buf)-1, fp); |
1404 |
|
if (!s) |
1405 |
|
break; |
1406 |
|
if (strstr (s, "KEY") && strstr (s, "FAILED")) { |
1407 |
|
failed = 1; |
1408 |
|
break; |
1409 |
|
} |
1410 |
|
if (!start_key && strstr (s, "KEY") && strstr (s, "BEGIN")) { |
1411 |
|
start_key = 1; |
1412 |
|
continue; |
1413 |
|
} |
1414 |
|
if (!start_key) |
1415 |
|
continue; |
1416 |
|
gpgme_data_write (raw, buf, strlen (buf)); |
1417 |
|
if (strstr (s, "KEY") && strstr (s, "END")) |
1418 |
|
break; |
1419 |
|
} |
1420 |
|
fclose (fp); |
1421 |
|
|
1422 |
|
if (failed) |
1423 |
|
rc = WPTERR_WINSOCK_RECVKEY; |
1424 |
|
*r_key = data_release_and_get_mem (raw, r_keylen); |
1425 |
|
return rc; |
1426 |
|
} |
1427 |
|
|
1428 |
|
|
1429 |
|
/* Receive an key via FINGER from host @host with the user @user. |
1430 |
|
On success @key contains the key. */ |
1431 |
|
int |
1432 |
|
finger_recvkey (const char *host, const char *user, |
1433 |
|
char **r_key, int *r_keylen) |
1434 |
|
{ |
1435 |
|
gpgme_data_t raw; |
1436 |
|
char buf[256]; |
1437 |
|
int fd, nread; |
1438 |
|
int start_key = 0; |
1439 |
|
int rc=0; |
1440 |
|
|
1441 |
|
rc = kserver_connect (host, FINGER_PORT, &fd); |
1442 |
|
if (rc) |
1443 |
|
return rc; |
1444 |
|
|
1445 |
|
sock_write (fd, user, strlen (user)); |
1446 |
|
sock_write (fd, "\r\n", 2); |
1447 |
|
|
1448 |
|
if (gpgme_data_new (&raw)) |
1449 |
|
BUG (0); |
1450 |
|
|
1451 |
|
for (;;) { |
1452 |
|
if (sock_getline (fd, buf, sizeof (buf), &nread)) |
1453 |
|
break; |
1454 |
|
strcat (buf, "\n"); |
1455 |
|
if (strstr (buf, "BEGIN PGP PUBLIC KEY BLOCK")) { |
1456 |
|
gpgme_data_write (raw, buf, nread); |
1457 |
|
start_key = 1; |
1458 |
|
} |
1459 |
|
else if (strstr (buf, "END PGP PUBLIC KEY BLOCK" ) && start_key) { |
1460 |
|
gpgme_data_write (raw, buf, nread); |
1461 |
|
start_key--; |
1462 |
|
break; |
1463 |
|
} |
1464 |
|
else if (start_key) |
1465 |
|
gpgme_data_write (raw, buf, nread); |
1466 |
|
} |
1467 |
|
|
1468 |
|
closesocket (fd); |
1469 |
|
if (start_key != 0) |
1470 |
|
rc = WPTERR_WINSOCK_RECVKEY; |
1471 |
|
*r_key = data_release_and_get_mem (raw, r_keylen); |
1472 |
|
return rc; |
1473 |
|
} |
1474 |
|
|
1475 |
|
|
1476 |
|
/* Check if the given name @name is a valid hostname. */ |
1477 |
|
int |
1478 |
|
check_IP_or_hostname (const char *name) |
1479 |
|
{ |
1480 |
|
const char *not_allowed = "=!�$%&@#*~\\/}][{<>|,;:'"; |
1481 |
|
size_t i, j; |
1482 |
|
|
1483 |
|
for (i=0; i < strlen (name); i++) { |
1484 |
|
for (j =0; j < strlen (not_allowed); j++) { |
1485 |
|
if (name[i] == not_allowed[j]) |
1486 |
|
return -1; |
1487 |
|
} |
1488 |
|
} |
1489 |
|
return 0; |
1490 |
|
} |
1491 |
|
|
1492 |
|
|
1493 |
|
/* Split the URL @r_keyserver into the host and the port |
1494 |
|
part if possible. */ |
1495 |
|
gpgme_error_t |
1496 |
|
parse_keyserver_url (char **r_keyserver, unsigned short *r_port) |
1497 |
|
{ |
1498 |
|
char *p; |
1499 |
|
char *url = *r_keyserver; |
1500 |
|
|
1501 |
|
/* no port is given so use the default port. */ |
1502 |
|
p = strrchr (url, ':'); |
1503 |
|
if (p == strchr (url, ':')) { |
1504 |
|
int port = port_from_proto (proto_from_URL (url)); |
1505 |
|
if (!port) |
1506 |
|
port = HKP_PORT; |
1507 |
|
*r_port = port; |
1508 |
|
return 0; |
1509 |
|
} |
1510 |
|
/* XXX: remove / in .de/:11371 */ |
1511 |
|
*r_keyserver = substr (url, 0, (p-url)); |
1512 |
|
*r_port = atoi (url+(p-url)+1); |
1513 |
|
free_if_alloc (url); |
1514 |
|
return 0; |
1515 |
|
} |