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; |
61 |
WORD default_keyserver_port = 0; |
WORD default_keyserver_port = 0; |
62 |
|
|
63 |
/* Default socket timeout. */ |
/* Default socket timeout. */ |
64 |
static int default_socket_timeout = 10; |
static int default_socket_timeout = 6; |
65 |
|
|
66 |
/* Basic64 encode the input @inbuf to @outbuf. */ |
/* Basic64 encode the input @inbuf to @outbuf. */ |
67 |
static void |
static void |
211 |
DWORD nread; |
DWORD nread; |
212 |
int nleft = buflen; |
int nleft = buflen; |
213 |
int rc, n = 0; |
int rc, n = 0; |
214 |
|
|
215 |
|
if (nbytes) |
216 |
|
*nbytes = 0; |
217 |
while (nleft > 0) { |
while (nleft > 0) { |
218 |
if (n >= default_socket_timeout) |
if (n >= default_socket_timeout) |
219 |
return WPTERR_WINSOCK_TIMEOUT; |
return WPTERR_WINSOCK_TIMEOUT; |
557 |
/* Load the keyserver config file @conf. */ |
/* Load the keyserver config file @conf. */ |
558 |
int |
int |
559 |
kserver_load_conf (const char *conf) |
kserver_load_conf (const char *conf) |
560 |
{ |
{ |
|
struct stat statbuf; |
|
561 |
FILE *fp; |
FILE *fp; |
562 |
char buf[1024], *s, *p; |
char buf[1024], *s, *p; |
563 |
char *user = NULL, *pass = NULL; |
char *user = NULL, *pass = NULL; |
652 |
return WPTERR_CONFIG_FILE; |
return WPTERR_CONFIG_FILE; |
653 |
} |
} |
654 |
|
|
|
if (!stat (conf, &statbuf)) |
|
|
conf_timestamp = statbuf.st_mtime; |
|
655 |
return 0; |
return 0; |
656 |
} |
} |
657 |
|
|
660 |
Return value: 0 on success */ |
Return value: 0 on success */ |
661 |
int |
int |
662 |
kserver_connect (const char *hostname, WORD port, int *conn_fd) |
kserver_connect (const char *hostname, WORD port, int *conn_fd) |
663 |
{ |
{ |
|
int rc, fd; |
|
|
DWORD iaddr; |
|
|
char host[128] = {0}; |
|
664 |
struct hostent *hp; |
struct hostent *hp; |
665 |
struct sockaddr_in sock; |
struct sockaddr_in sock; |
666 |
|
char host[128] = {0}; |
667 |
|
DWORD iaddr; |
668 |
|
int rc, fd; |
669 |
|
|
670 |
log_debug ("kserver_connect: %s:%d\r\n", hostname, port); |
log_debug ("kserver_connect: %s:%d\r\n", hostname, port); |
671 |
|
|
675 |
*conn_fd = 0; |
*conn_fd = 0; |
676 |
hostname = skip_type_prefix (hostname); |
hostname = skip_type_prefix (hostname); |
677 |
|
|
678 |
|
if (proxy.host && proxy.proto == PROXY_PROTO_HTTP) |
679 |
|
port = proxy.port; |
680 |
memset (&sock, 0, sizeof (sock)); |
memset (&sock, 0, sizeof (sock)); |
681 |
sock.sin_family = AF_INET; |
sock.sin_family = AF_INET; |
682 |
sock.sin_port = proxy.host? htons (proxy.port) : htons (port); |
sock.sin_port = htons (port); |
683 |
if (proxy.host) |
if (proxy.host) |
684 |
strncpy (host, proxy.host, 127); |
strncpy (host, proxy.host, 127); |
685 |
else |
else |
686 |
strncpy (host, hostname, 127); |
strncpy (host, hostname, 127); |
687 |
|
|
688 |
if ((iaddr = inet_addr (host)) != INADDR_NONE) |
if ((iaddr = inet_addr (host)) != INADDR_NONE) |
689 |
memcpy (&sock.sin_addr, &iaddr, sizeof (iaddr)); |
memcpy (&sock.sin_addr, &iaddr, sizeof (iaddr)); |
690 |
else if ((hp = gethostbyname (host))) { |
else if ((hp = gethostbyname (host))) { |
778 |
if (!port) |
if (!port) |
779 |
port = HKP_PORT; |
port = HKP_PORT; |
780 |
reqlen = 512 + strlen (hostname) + 2*strlen (pubkey); |
reqlen = 512 + strlen (hostname) + 2*strlen (pubkey); |
781 |
|
if (proxy.proto == PROXY_PROTO_HTTP && proxy.base64_user) |
782 |
|
reqlen += strlen (proxy.base64_user) + 1; |
783 |
request = new char[reqlen]; |
request = new char[reqlen]; |
784 |
if (!request) |
if (!request) |
785 |
BUG (0); |
BUG (0); |
800 |
"Content-length: %d\r\n" |
"Content-length: %d\r\n" |
801 |
"\r\n" |
"\r\n" |
802 |
"keytext=%s" |
"keytext=%s" |
803 |
"\n", |
"\r\n", |
804 |
skip_type_prefix (hostname), port, hostname, port, |
skip_type_prefix (hostname), port, hostname, port, |
805 |
proxy.base64_user, enc_octets+9, enc_pubkey); |
proxy.base64_user, enc_octets+9, enc_pubkey); |
806 |
} |
} |
814 |
"Content-length: %d\r\n" |
"Content-length: %d\r\n" |
815 |
"\r\n" |
"\r\n" |
816 |
"keytext=%s" |
"keytext=%s" |
817 |
"\n", |
"\r\n", |
818 |
skip_type_prefix (hostname), port, |
skip_type_prefix (hostname), port, |
819 |
enc_octets+9, enc_pubkey); |
enc_octets+9, enc_pubkey); |
820 |
} |
} |
918 |
kserver_sendkey (const char *hostname, WORD port, const char *pubkey, int len ) |
kserver_sendkey (const char *hostname, WORD port, const char *pubkey, int len ) |
919 |
{ |
{ |
920 |
char *request = NULL; |
char *request = NULL; |
921 |
char log[2048]; |
char log[2048] = {0}; |
922 |
int conn_fd, n; |
int conn_fd, n; |
923 |
int rc; |
int rc; |
924 |
|
|
945 |
goto leave; |
goto leave; |
946 |
} |
} |
947 |
|
|
948 |
log_debug ("kserver_sendkey:\r\n%s\r\n", log); |
log_debug ("kserver_sendkey: read %d bytes\r\n%s\r\n", n, log); |
949 |
rc = check_hkp_response (log, 0); |
rc = check_hkp_response (log, 0); |
950 |
if (rc) |
if (rc) |
951 |
goto leave; |
goto leave; |