716 |
return WPTERR_WINSOCK_CONNECT; |
return WPTERR_WINSOCK_CONNECT; |
717 |
} |
} |
718 |
|
|
719 |
if (proxy.proto != PROXY_PROTO_HTTP) { |
if (proxy.proto == PROXY_PROTO_SOCKS5) { |
720 |
rc = socks_handshake (&proxy, fd, hostname, port); |
rc = socks_handshake (&proxy, fd, hostname, port); |
721 |
if (rc) { |
if (rc) { |
722 |
closesocket (fd); |
closesocket (fd); |
882 |
|
|
883 |
if (r_keylen) |
if (r_keylen) |
884 |
*r_keylen = n; |
*r_keylen = n; |
885 |
log_debug("%s\r\n", *r_key); |
log_debug ("%s\r\n", *r_key); |
886 |
rc = check_hkp_response (*r_key, 1); |
rc = check_hkp_response (*r_key, 1); |
887 |
if (rc) |
if (rc) |
888 |
goto leave; |
goto leave; |
965 |
} |
} |
966 |
|
|
967 |
|
|
968 |
|
/* Check keyserver response. */ |
969 |
|
static int |
970 |
|
kserver_search_chkresp (int fd) |
971 |
|
{ |
972 |
|
char buf[128]; |
973 |
|
int n=0; |
974 |
|
|
975 |
|
/* parse response 'HTTP/1.0 500 OK' */ |
976 |
|
if (sock_getline (fd, buf, 127, &n)) |
977 |
|
return WPTERR_KEYSERVER_NOTFOUND; |
978 |
|
|
979 |
|
log_debug ("kserver_search_chkpresp: %s\r\n", buf); |
980 |
|
if (strncmp (buf, "HTTP/1.", 7)) |
981 |
|
return WPTERR_KEYSERVER_NOTFOUND; |
982 |
|
if (strncmp (buf+(8+1), "200", 3)) |
983 |
|
return WPTERR_KEYSERVER_NOTFOUND; |
984 |
|
return 0; |
985 |
|
} |
986 |
|
|
987 |
|
|
988 |
|
/* End the keyserver search procedure. */ |
989 |
|
void |
990 |
|
kserver_search_end (int conn_fd) |
991 |
|
{ |
992 |
|
log_debug ("kserver_search_end: fd=%d\r\n", conn_fd); |
993 |
|
closesocket (conn_fd); |
994 |
|
} |
995 |
|
|
996 |
|
|
997 |
|
/* Begin keyserver search procedure. */ |
998 |
int |
int |
999 |
kserver_search_init (const char *hostname, WORD port, |
kserver_search_begin (const char *hostname, WORD port, |
1000 |
const char *keyid, int *conn_fd) |
const char *pattern, int *conn_fd) |
1001 |
{ |
{ |
1002 |
char *request = NULL; |
char *request = NULL; |
1003 |
char *enc_keyid = NULL; |
char *enc_patt = NULL; |
1004 |
int n = 0; |
int n; |
1005 |
int rc, sock_fd; |
int rc, sock_fd; |
1006 |
|
|
1007 |
rc = kserver_connect (hostname, port, &sock_fd); |
rc = kserver_connect (hostname, port, &sock_fd); |
1010 |
goto leave; |
goto leave; |
1011 |
} |
} |
1012 |
|
|
1013 |
enc_keyid = URL_encode (keyid, strlen (keyid), NULL); |
enc_patt = URL_encode (pattern, strlen (pattern), NULL); |
1014 |
n=300; |
n = 140 + strlen (enc_patt) + strlen (hostname) + 32 + 2; |
1015 |
|
if (proxy.base64_user) |
1016 |
|
n += strlen (proxy.base64_user) + 1; |
1017 |
request = new char[n+1]; |
request = new char[n+1]; |
1018 |
if (!request) |
if (!request) |
1019 |
BUG (0); |
BUG (0); |
1022 |
_snprintf (request, n, |
_snprintf (request, n, |
1023 |
"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" |
1024 |
"Proxy-Authorization: Basic %s\r\n\r\n", |
"Proxy-Authorization: Basic %s\r\n\r\n", |
1025 |
skip_type_prefix (hostname), port, enc_keyid, proxy.base64_user); |
skip_type_prefix (hostname), port, enc_patt, proxy.base64_user); |
1026 |
} |
} |
1027 |
else if (proxy.host && proxy.proto == PROXY_PROTO_HTTP) { |
else if (proxy.host && proxy.proto == PROXY_PROTO_HTTP) { |
1028 |
_snprintf (request, n, |
_snprintf (request, n, |
1029 |
"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", |
1030 |
skip_type_prefix (hostname), port, enc_keyid); |
skip_type_prefix (hostname), port, enc_patt); |
1031 |
} |
} |
1032 |
else { |
else { |
1033 |
_snprintf (request, n, |
_snprintf (request, n, |
1034 |
"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", |
1035 |
enc_keyid); |
enc_patt); |
1036 |
} |
} |
1037 |
|
|
1038 |
log_debug ("kserver_search_init:\r\n%s\r\n", request); |
log_debug ("kserver_search_begin:\r\n%s\r\n", request); |
1039 |
|
|
1040 |
if (sock_write (sock_fd, request, strlen (request)) == SOCKET_ERROR) { |
if (sock_write (sock_fd, request, strlen (request)) == SOCKET_ERROR) { |
1041 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1042 |
goto leave; |
goto leave; |
1043 |
} |
} |
1044 |
|
|
1045 |
|
rc = kserver_search_chkresp (sock_fd); |
1046 |
|
if (rc) { |
1047 |
|
closesocket (sock_fd); |
1048 |
|
sock_fd = 0; |
1049 |
|
} |
1050 |
|
|
1051 |
*conn_fd = sock_fd; |
*conn_fd = sock_fd; |
1052 |
|
|
1053 |
leave: |
leave: |
1054 |
free_if_alloc (request); |
free_if_alloc (request); |
1055 |
free_if_alloc (enc_keyid); |
free_if_alloc (enc_patt); |
1056 |
return rc; |
return rc; |
1057 |
} |
} |
1058 |
|
|
1059 |
|
|
|
/* 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; |
|
|
} |
|
1060 |
|
|
1061 |
|
|
1062 |
/* Convert an iso date @iso_date (YYYY-MM-DD) into the locale |
/* Convert an iso date @iso_date (YYYY-MM-DD) into the locale |
1091 |
|
|
1092 |
|
|
1093 |
int |
int |
1094 |
kserver_search (int fd, keyserver_key *key) |
kserver_search_next (int fd, keyserver_key *key) |
1095 |
{ |
{ |
1096 |
char buf[1024], *p; |
char buf[1024], *p; |
1097 |
int uidlen, nbytes, pos = 0; |
int uidlen, nbytes, pos = 0; |
1098 |
|
|
1099 |
log_debug ("keyserver_search:\r\n"); |
log_debug ("keyserver_search_next:\r\n"); |
1100 |
|
|
1101 |
if (sock_getline (fd, buf, sizeof (buf) - 1, &nbytes)) |
if (sock_getline (fd, buf, sizeof (buf) - 1, &nbytes)) |
1102 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
1103 |
|
|
1104 |
|
/* XXX: use maschine readable option. */ |
1105 |
log_debug ("%s\r\n", buf); |
log_debug ("%s\r\n", buf); |
1106 |
|
|
1107 |
if (!strncmp (buf, "pub", 3)) { |
if (!strncmp (buf, "pub", 3)) { |
1169 |
free_if_alloc (ctx->host); |
free_if_alloc (ctx->host); |
1170 |
free_if_alloc (ctx->pass); |
free_if_alloc (ctx->pass); |
1171 |
free_if_alloc (ctx->user); |
free_if_alloc (ctx->user); |
1172 |
|
ctx->port = ctx->proto = 0; |
1173 |
} |
} |
1174 |
|
|
1175 |
|
|