44 |
keyserver server[MAX_KEYSERVERS] = {0}; |
keyserver server[MAX_KEYSERVERS] = {0}; |
45 |
keyserver_proxy_s proxy = {0}; |
keyserver_proxy_s proxy = {0}; |
46 |
static const char *server_list[] = { |
static const char *server_list[] = { |
|
"hkp://gnv.us.ks.cryptnet.net", |
|
|
"hkp://keyserver.kjsl.com", |
|
47 |
"hkp://sks.keyserver.penguin.de", |
"hkp://sks.keyserver.penguin.de", |
48 |
"hkp://subkeys.pgp.net", |
"hkp://subkeys.pgp.net", |
49 |
"ldap://keyserver.pgp.com", |
"ldap://keyserver.pgp.com", |
120 |
} |
} |
121 |
|
|
122 |
|
|
123 |
|
/* Check that the given buffer contains a valid keyserver URL |
124 |
|
and return the prefix length, 0 in case of an error. */ |
125 |
|
static int |
126 |
|
check_URL (const char *buf) |
127 |
|
{ |
128 |
|
const char *proto[] = { |
129 |
|
"ldap://", |
130 |
|
"http://", |
131 |
|
"finger://", |
132 |
|
"hkp://", |
133 |
|
NULL}; |
134 |
|
int i; |
135 |
|
|
136 |
|
if (strlen (buf) < 7) |
137 |
|
return 0; |
138 |
|
|
139 |
|
for (i=0; proto[i] != NULL; i++) { |
140 |
|
if (strstr (buf, proto[i])) |
141 |
|
return strlen (proto[i]); |
142 |
|
} |
143 |
|
return 0; |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
/* Skip the URL schema and return only the host part of it. */ |
/* Skip the URL schema and return only the host part of it. */ |
148 |
static const char* |
static const char* |
149 |
skip_type_prefix (const char *hostname) |
skip_type_prefix (const char *hostname) |
150 |
{ |
{ |
151 |
if (hostname && !strncmp (hostname, "http://", 7)) |
int pos; |
152 |
hostname += 7; |
|
153 |
else if (hostname && !strncmp (hostname, "hkp://", 6)) |
if (!hostname) |
154 |
hostname += 6; |
return hostname; |
155 |
else if (hostname && !strncmp (hostname, "finger://", 9)) |
|
156 |
hostname += 9; |
pos = check_URL (hostname); |
157 |
else if (hostname && !strncmp (hostname, "ldap://", 7)) |
if (pos > 0) |
158 |
hostname += 7; |
hostname += pos; |
159 |
return hostname; |
return hostname; |
160 |
} |
} |
161 |
|
|
177 |
|| strstr (resp, "Public Key Server -- Error") |
|| strstr (resp, "Public Key Server -- Error") |
178 |
|| strstr (resp, "No matching keys in database")) { |
|| strstr (resp, "No matching keys in database")) { |
179 |
p = strstr (resp, "<p>"); |
p = strstr (resp, "<p>"); |
180 |
if (p && strlen (p) < sizeof (hkp_errmsg)) { |
if (p && strlen (p) < sizeof (hkp_errmsg)-1) { |
181 |
end = strstr (p, "</p>"); |
end = strstr (p, "</p>"); |
182 |
len = end? (end - p + 1) : strlen (p); |
len = end? (end - p + 1) : strlen (p); |
183 |
memset (hkp_errmsg, 0, sizeof (hkp_errmsg)); |
memset (hkp_errmsg, 0, sizeof (hkp_errmsg)); |
384 |
} |
} |
385 |
kserver_proxy_release (&proxy); |
kserver_proxy_release (&proxy); |
386 |
WSACleanup (); |
WSACleanup (); |
387 |
|
log_debug ("wsock_end: cleanup finished.\r\n"); |
388 |
} |
} |
389 |
|
|
390 |
|
|
432 |
void |
void |
433 |
kserver_set_socket_timeout (int nsec) |
kserver_set_socket_timeout (int nsec) |
434 |
{ |
{ |
435 |
if (nsec < 0) |
if (nsec < 0 || nsec > 3600) |
436 |
nsec = 0; |
nsec = 0; |
437 |
default_socket_timeout = nsec; |
default_socket_timeout = nsec; |
438 |
} |
} |
458 |
return default_keyserver; |
return default_keyserver; |
459 |
} |
} |
460 |
else if (!type && idx < DIM (server_list)) { |
else if (!type && idx < DIM (server_list)) { |
461 |
|
/* XXX: handle non HKP servers. */ |
462 |
*port = HKP_PORT; |
*port = HKP_PORT; |
463 |
return server_list[idx]; |
return server_list[idx]; |
464 |
} |
} |
489 |
const char* |
const char* |
490 |
kserver_check_keyid (const char *keyid) |
kserver_check_keyid (const char *keyid) |
491 |
{ |
{ |
492 |
static char id[21]; |
static char id[22]; |
493 |
|
|
494 |
if (strstr (keyid, "@")) |
if (strstr (keyid, "@")) |
495 |
return keyid; /* email address */ |
return keyid; /* email address */ |
519 |
proxy.user = m_strdup (proxy_user); |
proxy.user = m_strdup (proxy_user); |
520 |
proxy.pass = m_strdup (proxy_pass); |
proxy.pass = m_strdup (proxy_pass); |
521 |
} |
} |
|
|
|
|
|
|
|
/* Check that the given buffer contains a valid keyserver URL. */ |
|
|
static int |
|
|
check_URL (const char * buf) |
|
|
{ |
|
|
if (strlen (buf) < 7) |
|
|
return -1; |
|
|
if (!strstr (buf, "ldap://") |
|
|
&& !strstr (buf, "http://") |
|
|
&& !strstr (buf, "finger://") |
|
|
&& !strstr (buf, "hkp://")) |
|
|
return -1; |
|
|
return 0; |
|
|
} |
|
522 |
|
|
523 |
|
|
524 |
/* Get the port number from the given protocol. */ |
/* Get the port number from the given protocol. */ |
667 |
s = (char *)skip_whitespace (buf); |
s = (char *)skip_whitespace (buf); |
668 |
if (*s == '#' || strlen (s) < 7) |
if (*s == '#' || strlen (s) < 7) |
669 |
continue; |
continue; |
670 |
if (check_URL (s)) { |
chk_pos = check_URL (s); |
671 |
|
if (!chk_pos) { |
672 |
msg_box (NULL, _("All entries of this file must have a valid prefix.\n" |
msg_box (NULL, _("All entries of this file must have a valid prefix.\n" |
673 |
"Currently HKP/HTTP, LDAP and FINGER are supported.\n"), |
"Currently HKP/HTTP, LDAP and FINGER are supported.\n"), |
674 |
_("Keyserver Error"), MB_ERR); |
_("Keyserver Error"), MB_ERR); |
675 |
continue; |
continue; |
676 |
} |
} |
|
chk_pos = 6; |
|
|
if (strstr (s, "finger")) |
|
|
chk_pos = 10; |
|
677 |
p = strchr (s+chk_pos, ':'); |
p = strchr (s+chk_pos, ':'); |
678 |
server[pos].used = 1; |
server[pos].used = 1; |
679 |
server[pos].proto = proto_from_URL (s); |
server[pos].proto = proto_from_URL (s); |
776 |
} |
} |
777 |
|
|
778 |
|
|
779 |
|
/* Check if the URL needs to be encoded or not. */ |
780 |
static bool |
static bool |
781 |
URL_must_encoded (const char *url) |
URL_must_encoded (const char *url) |
782 |
{ |
{ |