1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-03 12:11:33 +01:00

* gpgkeys_hkp.c (write_quoted): Use %-encoding instead of \-encoding.

(parse_hkp_index): Use new keyserver key listing format, and add support
for disabled keys via include-disabled.
This commit is contained in:
David Shaw 2002-10-14 20:01:05 +00:00
parent 943566f53f
commit 3ee825e211
2 changed files with 135 additions and 103 deletions

View File

@ -1,5 +1,10 @@
2002-10-14 David Shaw <dshaw@jabberwocky.com> 2002-10-14 David Shaw <dshaw@jabberwocky.com>
* gpgkeys_hkp.c (write_quoted): Use %-encoding instead of
\-encoding.
(parse_hkp_index): Use new keyserver key listing format, and add
support for disabled keys via include-disabled.
* gpgkeys_ldap.c (get_key): Don't print keysize unless it's >0. * gpgkeys_ldap.c (get_key): Don't print keysize unless it's >0.
(printquoted): Use %-encoding instead of \-encoding. (printquoted): Use %-encoding instead of \-encoding.
(search_key): Use new keyserver key listing format. (search_key): Use new keyserver key listing format.

View File

@ -35,7 +35,7 @@
#define SEARCH 2 #define SEARCH 2
#define MAX_LINE 80 #define MAX_LINE 80
int verbose=0,include_revoked=0; int verbose=0,include_revoked=0,include_disabled=0;
unsigned int http_flags=0; unsigned int http_flags=0;
char host[80]={'\0'},port[10]={'\0'}; char host[80]={'\0'},port[10]={'\0'};
FILE *input=NULL,*output=NULL,*console=NULL; FILE *input=NULL,*output=NULL,*console=NULL;
@ -373,7 +373,7 @@ write_quoted(IOBUF a, const char *buf, char delim)
{ {
char quoted[5]; char quoted[5];
sprintf(quoted,"\\x%02X",delim); sprintf(quoted,"%%%02X",delim);
while(*buf) while(*buf)
{ {
@ -382,9 +382,9 @@ write_quoted(IOBUF a, const char *buf, char delim)
if(iobuf_writestr(a,quoted)) if(iobuf_writestr(a,quoted))
return -1; return -1;
} }
else if(*buf=='\\') else if(*buf=='%')
{ {
if(iobuf_writestr(a,"\\x5c")) if(iobuf_writestr(a,"%25"))
return -1; return -1;
} }
else else
@ -408,136 +408,156 @@ write_quoted(IOBUF a, const char *buf, char delim)
int int
parse_hkp_index(IOBUF buffer,char *line) parse_hkp_index(IOBUF buffer,char *line)
{ {
static int open=0,revoked=0;
static char *key=NULL,*type=NULL,*uid=NULL;
static u32 bits,createtime;
int ret=0; int ret=0;
/* printf("Open %d, LINE: \"%s\", uid: %s\n",open,line,uid); */ /* printf("Open %d, LINE: \"%s\"\n",open,line); */
dehtmlize(line); dehtmlize(line);
/* printf("Now open %d, LINE: \"%s\", uid: %s\n",open,line,uid); */ /* printf("Now open %d, LINE: \"%s\"\n",open,line); */
/* Try and catch some bastardization of HKP. If we don't have if(line[0]=='\0')
certain unchanging landmarks, we can't reliably parse the return 0;
response. This only complains about problems within the key else if(ascii_strncasecmp(line,"pub",3)==0)
section itself. Headers and footers should not matter. */
if(open && line[0]!='\0' &&
ascii_strncasecmp(line,"pub ",4)!=0 &&
ascii_strncasecmp(line," ",4)!=0)
{ {
free(key); char *tok,*keyid,*uid=NULL,number[15];
free(uid); int bits=0,type=0,disabled=0,revoked=0;
fprintf(console,"gpgkeys: this keyserver does not support searching\n"); u32 createtime=0;
return -1;
}
/* For multiple UIDs */ line+=3;
if(open && uid!=NULL)
{
ret=0;
if(!(revoked && !include_revoked)) if(*line=='-')
{ {
char intstr[11]; disabled=1;
if(!include_disabled)
if(key) return 0;
write_quoted(buffer,key,':');
iobuf_writestr(buffer,":");
write_quoted(buffer,uid,':');
iobuf_writestr(buffer,":");
iobuf_writestr(buffer,revoked?"1:":":");
sprintf(intstr,"%u",createtime);
write_quoted(buffer,intstr,':');
iobuf_writestr(buffer,":::");
if(type)
write_quoted(buffer,type,':');
iobuf_writestr(buffer,":");
sprintf(intstr,"%u",bits);
write_quoted(buffer,intstr,':');
iobuf_writestr(buffer,"\n");
ret=1;
} }
if(strncmp(line," ",4)!=0) line++;
{
revoked=0;
free(key);
free(uid);
uid=NULL;
open=0;
}
}
if(ascii_strncasecmp(line,"pub ",4)==0)
{
char *tok,*temp;
open=1;
line+=4;
tok=strsep(&line,"/"); tok=strsep(&line,"/");
if(tok==NULL) if(tok==NULL)
return ret; return ret;
if(tok[strlen(tok)-1]=='R') if(tok[strlen(tok)-1]=='R')
type="RSA"; type=1;
else if(tok[strlen(tok)-1]=='D') else if(tok[strlen(tok)-1]=='D')
type="DSA"; type=17;
else
type=NULL;
bits=atoi(tok); bits=atoi(tok);
tok=strsep(&line," "); keyid=strsep(&line," ");
if(tok==NULL)
return ret;
key=strdup(tok);
tok=strsep(&line," "); tok=strsep(&line," ");
if(tok==NULL) if(tok!=NULL)
return ret;
/* The date parser wants '-' instead of '/', so... */
temp=tok;
while(*temp!='\0')
{
if(*temp=='/')
*temp='-';
temp++;
}
createtime=scan_isodatestr(tok);
}
if(open)
{
if(line==NULL)
{ {
uid=strdup("Key index corrupted"); char *temp=tok;
return ret;
/* The date parser wants '-' instead of '/', so... */
while(*temp!='\0')
{
if(*temp=='/')
*temp='-';
temp++;
}
createtime=scan_isodatestr(tok);
} }
if(line!=NULL)
{
while(*line==' ' && *line!='\0')
line++;
if(*line!='\0')
{
if(strncmp(line,"*** KEY REVOKED ***",19)==0)
{
revoked=1;
if(!include_revoked)
return 0;
}
else
uid=line;
}
}
if(keyid)
{
iobuf_writestr(buffer,"pub:");
write_quoted(buffer,keyid,':');
iobuf_writestr(buffer,":");
if(type)
{
sprintf(number,"%d",type);
write_quoted(buffer,number,':');
}
iobuf_writestr(buffer,":");
if(bits)
{
sprintf(number,"%d",bits);
write_quoted(buffer,number,':');
}
iobuf_writestr(buffer,":");
if(createtime)
{
sprintf(number,"%d",createtime);
write_quoted(buffer,number,':');
}
iobuf_writestr(buffer,"::");
if(revoked)
write_quoted(buffer,"r",':');
if(disabled)
write_quoted(buffer,"d",':');
if(uid)
{
iobuf_writestr(buffer,"\nuid:");
write_quoted(buffer,uid,':');
}
iobuf_writestr(buffer,"\n");
ret=1;
}
}
else if(ascii_strncasecmp(line," ",3)==0)
{
while(*line==' ' && *line!='\0') while(*line==' ' && *line!='\0')
line++; line++;
if(*line=='\0') if(*line!='\0')
return ret;
if(strncmp(line,"*** KEY REVOKED ***",19)==0)
{ {
revoked=1; iobuf_writestr(buffer,"uid:");
return ret; write_quoted(buffer,line,':');
iobuf_writestr(buffer,"\n");
} }
uid=strdup(line);
} }
#if 0
else if(open)
{
/* Try and catch some bastardization of HKP. If we don't have
certain unchanging landmarks, we can't reliably parse the
response. This only complains about problems within the key
section itself. Headers and footers should not matter. */
fprintf(console,"gpgkeys: this keyserver does not support searching\n");
ret=-1;
}
#endif
return ret; return ret;
} }
@ -575,7 +595,7 @@ handle_old_hkp_index(IOBUF inp)
m_free(line); m_free(line);
if(ret>-1) if(ret>-1)
fprintf(output,"COUNT %d\n%s",count,iobuf_get_temp_buffer(buffer)); fprintf(output,"info:1:%d\n%s",count,iobuf_get_temp_buffer(buffer));
iobuf_close(buffer); iobuf_close(buffer);
} }
@ -802,7 +822,7 @@ main(int argc,char *argv[])
if(sscanf(line,"VERSION %d\n",&version)==1) if(sscanf(line,"VERSION %d\n",&version)==1)
{ {
if(version!=0) if(version!=KEYSERVER_PROTO_VERSION)
{ {
ret=KEYSERVER_VERSION_ERROR; ret=KEYSERVER_VERSION_ERROR;
goto fail; goto fail;
@ -838,6 +858,13 @@ main(int argc,char *argv[])
else else
include_revoked=1; include_revoked=1;
} }
else if(strcasecmp(start,"include-disabled")==0)
{
if(no)
include_disabled=0;
else
include_disabled=1;
}
else if(strcasecmp(start,"honor-http-proxy")==0) else if(strcasecmp(start,"honor-http-proxy")==0)
{ {
if(no) if(no)
@ -911,7 +938,7 @@ main(int argc,char *argv[])
/* Send the response */ /* Send the response */
fprintf(output,"VERSION 0\n"); fprintf(output,"VERSION %d\n",KEYSERVER_PROTO_VERSION);
fprintf(output,"PROGRAM %s\n\n",VERSION); fprintf(output,"PROGRAM %s\n\n",VERSION);
if(verbose>1) if(verbose>1)