* gpgkeys_hkp.c, gpgkeys_oldhkp.c: Add support for HKP servers that

aren't at the root path.  Suggested by Jack Bates.
This commit is contained in:
David Shaw 2005-06-04 23:09:27 +00:00
parent 7bf9354bf6
commit c347404bfd
3 changed files with 40 additions and 17 deletions

View File

@ -1,3 +1,8 @@
2005-06-04 David Shaw <dshaw@jabberwocky.com>
* gpgkeys_hkp.c, gpgkeys_oldhkp.c: Add support for HKP servers
that aren't at the root path. Suggested by Jack Bates.
2005-06-01 David Shaw <dshaw@jabberwocky.com>
* ksutil.c [HAVE_DOSISH_SYSTEM]: Fix warnings on mingw32. Noted

View File

@ -73,7 +73,7 @@ int
send_key(int *eof)
{
CURLcode res;
char request[MAX_URL];
char request[MAX_URL+15];
int begin=0,end=0,ret=KEYSERVER_INTERNAL_ERROR;
char keyid[17];
char line[MAX_LINE];
@ -162,6 +162,10 @@ send_key(int *eof)
strcat(request,opt->port);
else
strcat(request,"11371");
if(opt->path)
strcat(request,opt->path);
/* request is MAX_URL+15 bytes long - MAX_URL covers the whole URL,
including any supplied path. The 15 covers /pks/add. */
strcat(request,"/pks/add");
if(opt->verbose>2)
@ -197,7 +201,7 @@ static int
get_key(char *getkey)
{
CURLcode res;
char request[MAX_URL+100];
char request[MAX_URL+60];
char *offset;
struct curl_writer_ctx ctx;
@ -218,9 +222,6 @@ get_key(char *getkey)
return KEYSERVER_NOT_SUPPORTED;
}
/* Note that the size of request is MAX_URL which already implies a
1024 byte PATH. MAX_URL+100 is absurdly safe. */
strcpy(request,"http://");
strcat(request,opt->host);
strcat(request,":");
@ -228,6 +229,11 @@ get_key(char *getkey)
strcat(request,opt->port);
else
strcat(request,"11371");
if(opt->path)
strcat(request,opt->path);
/* request is MAX_URL+55 bytes long - MAX_URL covers the whole URL,
including any supplied path. The 60 overcovers this /pks/... etc
string plus the 8 bytes of key id */
strcat(request,"/pks/lookup?op=get&options=mr&search=0x");
/* fingerprint or long key id. Take the last 8 characters and treat
@ -278,9 +284,7 @@ search_key(char *searchkey)
searchkey_encoded=curl_escape(searchkey,0);
/* Note that MAX_URL already implies a 1024 byte PATH, so this is
safe. */
request=malloc(MAX_URL+strlen(searchkey_encoded));
request=malloc(MAX_URL+50+strlen(searchkey_encoded));
if(!request)
{
fprintf(console,"gpgkeys: out of memory\n");
@ -297,6 +301,8 @@ search_key(char *searchkey)
strcat(request,opt->port);
else
strcat(request,"11371");
if(opt->path)
strcat(request,opt->path);
strcat(request,"/pks/lookup?op=index&options=mr&search=");
strcat(request,searchkey_encoded);
@ -593,6 +599,8 @@ main(int argc,char *argv[])
fprintf(console,"Host:\t\t%s\n",opt->host);
if(opt->port)
fprintf(console,"Port:\t\t%s\n",opt->port);
if(opt->path)
fprintf(console,"Path:\t\t%s\n",opt->path);
fprintf(console,"Command:\t%s\n",ks_action_to_string(opt->action));
}

View File

@ -47,7 +47,8 @@ extern int optind;
static int verbose=0,include_revoked=0,include_disabled=0;
static unsigned int http_flags=0;
static char host[MAX_HOST+1]={'\0'},proxy[MAX_PROXY+1]={'\0'},port[MAX_PORT+1]={'\0'};
static char host[MAX_HOST+1]={'\0'},proxy[MAX_PROXY+1]={'\0'},
port[MAX_PORT+1]={'\0'},path[URLMAX_PATH+1];
static FILE *input=NULL,*output=NULL,*console=NULL;
int
@ -89,7 +90,7 @@ send_key(int *eof)
memset(&hd,0,sizeof(hd));
request=malloc(strlen(host)+100);
request=malloc(strlen(host)+strlen(port)+strlen(path)+100);
if(!request)
{
fprintf(console,"gpgkeys: out of memory\n");
@ -141,7 +142,8 @@ send_key(int *eof)
iobuf_flush_temp(temp);
sprintf(request,"hkp://%s%s%s/pks/add",host,port[0]?":":"",port[0]?port:"");
sprintf(request,"hkp://%s%s%s%s/pks/add",
host,port[0]?":":"",port[0]?port:"",path);
if(verbose>2)
fprintf(console,"gpgkeys: HTTP URL is `%s'\n",request);
@ -237,15 +239,15 @@ get_key(char *getkey)
fprintf(output,"KEY 0x%s BEGIN\n",getkey);
request=malloc(strlen(host)+100);
request=malloc(strlen(host)+strlen(port)+strlen(path)+100);
if(!request)
{
fprintf(console,"gpgkeys: out of memory\n");
return KEYSERVER_NO_MEMORY;
}
sprintf(request,"hkp://%s%s%s/pks/lookup?op=get&options=mr&search=%s",
host,port[0]?":":"",port[0]?port:"", search);
sprintf(request,"hkp://%s%s%s%s/pks/lookup?op=get&options=mr&search=%s",
host,port[0]?":":"",port[0]?port:"",path,search);
if(verbose>2)
fprintf(console,"gpgkeys: HTTP URL is `%s'\n",request);
@ -659,7 +661,7 @@ search_key(char *searchkey)
search[len]='\0';
request=malloc(strlen(host)+100+strlen(search));
request=malloc(strlen(host)+strlen(port)+strlen(path)+100+strlen(search));
if(!request)
{
fprintf(console,"gpgkeys: out of memory\n");
@ -667,8 +669,8 @@ search_key(char *searchkey)
goto fail;
}
sprintf(request,"hkp://%s%s%s/pks/lookup?op=index&options=mr&search=%s",
host,port[0]?":":"",port[0]?port:"",search);
sprintf(request,"hkp://%s%s%s%s/pks/lookup?op=index&options=mr&search=%s",
host,port[0]?":":"",port[0]?port:"",path,search);
if(verbose>2)
fprintf(console,"gpgkeys: HTTP URL is `%s'\n",request);
@ -856,6 +858,12 @@ main(int argc,char *argv[])
continue;
}
if(sscanf(line,"PATH %" MKSTRING(URLMAX_PATH) "s\n",path)==1)
{
path[URLMAX_PATH]='\0';
continue;
}
if(sscanf(line,"VERSION %d\n",&version)==1)
{
if(version!=KEYSERVER_PROTO_VERSION)
@ -1020,6 +1028,8 @@ main(int argc,char *argv[])
fprintf(console,"Host:\t\t%s\n",host);
if(port[0])
fprintf(console,"Port:\t\t%s\n",port);
if(path[0])
fprintf(console,"Path:\t\t%s\n",path);
fprintf(console,"Command:\t%s\n",action==GET?"GET":
action==SEND?"SEND":"SEARCH");
}