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[] = { |
47 |
"hkp://wwwkeys.nl.pgp.net", |
"hkp://gnv.us.ks.cryptnet.net", |
48 |
"hkp://wwwkeys.pl.pgp.net", |
"hkp://keyserver.kjsl.com", |
49 |
"hkp://wwwkeys.at.pgp.net", |
"hkp://sks.keyserver.penguin.de", |
|
"hkp://wwwkeys.ch.pgp.net", |
|
|
"hkp://wwwkeys.de.pgp.net", |
|
|
"hkp://wwwkeys.dk.pgp.net", |
|
|
"hkp://wwwkeys.cz.pgp.net", |
|
|
"hkp://wwwkeys.es.pgp.net", |
|
|
"hkp://wwwkeys.eu.pgp.net", |
|
|
"hkp://wwwkeys.uk.pgp.net", |
|
|
"hkp://wwwkeys.us.pgp.net", |
|
50 |
"hkp://subkeys.pgp.net", |
"hkp://subkeys.pgp.net", |
51 |
"ldap://keyserver.pgp.com", |
"ldap://keyserver.pgp.com", |
52 |
NULL |
NULL |
55 |
|
|
56 |
static char hkp_errmsg[1024]; /* Holds the error message from the server */ |
static char hkp_errmsg[1024]; /* Holds the error message from the server */ |
57 |
static int hkp_err = 0; /* != 0 indicates an error occurred. */ |
static int hkp_err = 0; /* != 0 indicates an error occurred. */ |
|
static DWORD conf_timestamp = 0;/* timestamp of the configuration fiele. */ |
|
58 |
|
|
59 |
/* Default keyserver and port. */ |
/* Default keyserver and port. */ |
60 |
char *default_keyserver = NULL; |
char *default_keyserver = NULL; |
555 |
/* Load the keyserver config file @conf. */ |
/* Load the keyserver config file @conf. */ |
556 |
int |
int |
557 |
kserver_load_conf (const char *conf) |
kserver_load_conf (const char *conf) |
558 |
{ |
{ |
|
struct stat statbuf; |
|
559 |
FILE *fp; |
FILE *fp; |
560 |
char buf[1024], *s, *p; |
char buf[1024], *s, *p; |
561 |
char *user = NULL, *pass = NULL; |
char *user = NULL, *pass = NULL; |
650 |
return WPTERR_CONFIG_FILE; |
return WPTERR_CONFIG_FILE; |
651 |
} |
} |
652 |
|
|
|
if (!stat (conf, &statbuf)) |
|
|
conf_timestamp = statbuf.st_mtime; |
|
653 |
return 0; |
return 0; |
654 |
} |
} |
655 |
|
|
704 |
return WPTERR_WINSOCK_CONNECT; |
return WPTERR_WINSOCK_CONNECT; |
705 |
} |
} |
706 |
|
|
707 |
if (proxy.proto != PROXY_PROTO_HTTP) { |
if (proxy.proto == PROXY_PROTO_SOCKS5) { |
708 |
rc = socks_handshake (&proxy, fd, hostname, port); |
rc = socks_handshake (&proxy, fd, hostname, port); |
709 |
if (rc) { |
if (rc) { |
710 |
closesocket (fd); |
closesocket (fd); |
870 |
|
|
871 |
if (r_keylen) |
if (r_keylen) |
872 |
*r_keylen = n; |
*r_keylen = n; |
873 |
log_debug("%s\r\n", *r_key); |
log_debug ("%s\r\n", *r_key); |
874 |
rc = check_hkp_response (*r_key, 1); |
rc = check_hkp_response (*r_key, 1); |
875 |
if (rc) |
if (rc) |
876 |
goto leave; |
goto leave; |
953 |
} |
} |
954 |
|
|
955 |
|
|
956 |
|
/* Check keyserver response. */ |
957 |
|
static int |
958 |
|
kserver_search_chkresp (int fd) |
959 |
|
{ |
960 |
|
char buf[128]; |
961 |
|
int n=0; |
962 |
|
|
963 |
|
/* parse response 'HTTP/1.0 500 OK' */ |
964 |
|
if (sock_getline (fd, buf, 127, &n)) |
965 |
|
return WPTERR_KEYSERVER_NOTFOUND; |
966 |
|
|
967 |
|
log_debug ("kserver_search_chkpresp: %s\r\n", buf); |
968 |
|
if (strncmp (buf, "HTTP/1.", 7)) |
969 |
|
return WPTERR_KEYSERVER_NOTFOUND; |
970 |
|
if (strncmp (buf+(8+1), "200", 3)) |
971 |
|
return WPTERR_KEYSERVER_NOTFOUND; |
972 |
|
return 0; |
973 |
|
} |
974 |
|
|
975 |
|
|
976 |
|
/* End the keyserver search procedure. */ |
977 |
|
void |
978 |
|
kserver_search_end (int conn_fd) |
979 |
|
{ |
980 |
|
log_debug ("kserver_search_end: fd=%d\r\n", conn_fd); |
981 |
|
closesocket (conn_fd); |
982 |
|
} |
983 |
|
|
984 |
|
|
985 |
|
/* Begin keyserver search procedure. */ |
986 |
int |
int |
987 |
kserver_search_init (const char *hostname, WORD port, |
kserver_search_begin (const char *hostname, WORD port, |
988 |
const char *keyid, int *conn_fd) |
const char *pattern, int *conn_fd) |
989 |
{ |
{ |
990 |
char *request = NULL; |
char *request = NULL; |
991 |
char *enc_keyid = NULL; |
char *enc_patt = NULL; |
992 |
int n = 0; |
int n; |
993 |
int rc, sock_fd; |
int rc, sock_fd; |
994 |
|
|
995 |
rc = kserver_connect (hostname, port, &sock_fd); |
rc = kserver_connect (hostname, port, &sock_fd); |
998 |
goto leave; |
goto leave; |
999 |
} |
} |
1000 |
|
|
1001 |
enc_keyid = URL_encode (keyid, strlen (keyid), NULL); |
enc_patt = URL_encode (pattern, strlen (pattern), NULL); |
1002 |
n=300; |
n = 140 + strlen (enc_patt) + strlen (hostname) + 32 + 2; |
1003 |
|
if (proxy.base64_user) |
1004 |
|
n += strlen (proxy.base64_user) + 1; |
1005 |
request = new char[n+1]; |
request = new char[n+1]; |
1006 |
if (!request) |
if (!request) |
1007 |
BUG (0); |
BUG (0); |
1010 |
_snprintf (request, n, |
_snprintf (request, n, |
1011 |
"GET http://%s:%d/pks/lookup?op=index&search=%s HTTP/1.0\r\n" |
"GET http://%s:%d/pks/lookup?op=index&search=%s HTTP/1.0\r\n" |
1012 |
"Proxy-Authorization: Basic %s\r\n\r\n", |
"Proxy-Authorization: Basic %s\r\n\r\n", |
1013 |
skip_type_prefix (hostname), port, enc_keyid, proxy.base64_user); |
skip_type_prefix (hostname), port, enc_patt, proxy.base64_user); |
1014 |
} |
} |
1015 |
else if (proxy.host && proxy.proto == PROXY_PROTO_HTTP) { |
else if (proxy.host && proxy.proto == PROXY_PROTO_HTTP) { |
1016 |
_snprintf (request, n, |
_snprintf (request, n, |
1017 |
"GET http://%s:%d/pks/lookup?op=index&search=%s HTTP/1.0\r\n\r\n", |
"GET http://%s:%d/pks/lookup?op=index&search=%s HTTP/1.0\r\n\r\n", |
1018 |
skip_type_prefix (hostname), port, enc_keyid); |
skip_type_prefix (hostname), port, enc_patt); |
1019 |
} |
} |
1020 |
else { |
else { |
1021 |
_snprintf (request, n, |
_snprintf (request, n, |
1022 |
"GET /pks/lookup?op=index&search=%s HTTP/1.0\r\n\r\n", |
"GET /pks/lookup?op=index&search=%s HTTP/1.0\r\n\r\n", |
1023 |
enc_keyid); |
enc_patt); |
1024 |
} |
} |
1025 |
|
|
1026 |
log_debug ("kserver_search_init:\r\n%s\r\n", request); |
log_debug ("kserver_search_begin:\r\n%s\r\n", request); |
1027 |
|
|
1028 |
if (sock_write (sock_fd, request, strlen (request)) == SOCKET_ERROR) { |
if (sock_write (sock_fd, request, strlen (request)) == SOCKET_ERROR) { |
1029 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1030 |
goto leave; |
goto leave; |
1031 |
} |
} |
1032 |
|
|
1033 |
|
rc = kserver_search_chkresp (sock_fd); |
1034 |
|
if (rc) { |
1035 |
|
closesocket (sock_fd); |
1036 |
|
sock_fd = 0; |
1037 |
|
} |
1038 |
|
|
1039 |
*conn_fd = sock_fd; |
*conn_fd = sock_fd; |
1040 |
|
|
1041 |
leave: |
leave: |
1042 |
free_if_alloc (request); |
free_if_alloc (request); |
1043 |
free_if_alloc (enc_keyid); |
free_if_alloc (enc_patt); |
1044 |
return rc; |
return rc; |
1045 |
} |
} |
1046 |
|
|
1047 |
|
|
|
/* Check keyserver response. */ |
|
|
int |
|
|
kserver_search_chkresp (int fd) |
|
|
{ |
|
|
char buf[128]; |
|
|
int n=0; |
|
|
|
|
|
/* parse response 'HTTP/1.0 500 OK' */ |
|
|
if (sock_getline (fd, buf, 127, &n)) |
|
|
return WPTERR_KEYSERVER_NOTFOUND; |
|
|
|
|
|
log_debug ("kserver_search_chkpresp: %s\r\n", buf); |
|
|
if (strncmp (buf, "HTTP/1.", 7)) |
|
|
return WPTERR_KEYSERVER_NOTFOUND; |
|
|
if (strncmp (buf+(8+1), "200", 3)) |
|
|
return WPTERR_KEYSERVER_NOTFOUND; |
|
|
return 0; |
|
|
} |
|
1048 |
|
|
1049 |
|
|
1050 |
/* Convert an iso date @iso_date (YYYY-MM-DD) into the locale |
/* Convert an iso date @iso_date (YYYY-MM-DD) into the locale |
1079 |
|
|
1080 |
|
|
1081 |
int |
int |
1082 |
kserver_search (int fd, keyserver_key *key) |
kserver_search_next (int fd, keyserver_key *key) |
1083 |
{ |
{ |
1084 |
char buf[1024], *p; |
char buf[1024], *p; |
1085 |
int uidlen, nbytes, pos = 0; |
int uidlen, nbytes, pos = 0; |
1086 |
|
|
1087 |
log_debug ("keyserver_search:\r\n"); |
log_debug ("keyserver_search_next:\r\n"); |
1088 |
|
|
1089 |
if (sock_getline (fd, buf, sizeof (buf) - 1, &nbytes)) |
if (sock_getline (fd, buf, sizeof (buf) - 1, &nbytes)) |
1090 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
1091 |
|
|
1092 |
|
/* XXX: use maschine readable option. */ |
1093 |
log_debug ("%s\r\n", buf); |
log_debug ("%s\r\n", buf); |
1094 |
|
|
1095 |
if (!strncmp (buf, "pub", 3)) { |
if (!strncmp (buf, "pub", 3)) { |
1157 |
free_if_alloc (ctx->host); |
free_if_alloc (ctx->host); |
1158 |
free_if_alloc (ctx->pass); |
free_if_alloc (ctx->pass); |
1159 |
free_if_alloc (ctx->user); |
free_if_alloc (ctx->user); |
1160 |
|
ctx->port = ctx->proto = 0; |
1161 |
} |
} |
1162 |
|
|
1163 |
|
|