2002-06-29 15:46:34 +02:00
|
|
|
/* keyserver.c - generic keyserver code
|
2007-03-14 14:15:50 +01:00
|
|
|
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006,
|
|
|
|
* 2007 Free Software Foundation, Inc.
|
2002-06-29 15:46:34 +02:00
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-10-23 12:48:09 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2002-06-29 15:46:34 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-10-23 12:48:09 +02:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2002-06-29 15:46:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2002-07-09 21:40:18 +02:00
|
|
|
#include <assert.h>
|
2002-06-29 15:46:34 +02:00
|
|
|
#include "filter.h"
|
|
|
|
#include "keydb.h"
|
|
|
|
#include "status.h"
|
|
|
|
#include "exec.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "i18n.h"
|
|
|
|
#include "iobuf.h"
|
|
|
|
#include "memory.h"
|
2002-10-14 20:50:28 +02:00
|
|
|
#include "ttyio.h"
|
2002-06-29 15:46:34 +02:00
|
|
|
#include "options.h"
|
|
|
|
#include "packet.h"
|
2005-02-06 18:38:43 +01:00
|
|
|
#include "trustdb.h"
|
2002-06-29 15:46:34 +02:00
|
|
|
#include "keyserver-internal.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2007-03-14 14:15:50 +01:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
/* It seems Vista doesn't grok X_OK and so fails access() tests.
|
|
|
|
Previous versions interpreted X_OK as F_OK anyway, so we'll just
|
|
|
|
use F_OK directly. */
|
|
|
|
#undef X_OK
|
|
|
|
#define X_OK F_OK
|
|
|
|
#endif /* HAVE_W32_SYSTEM */
|
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
struct keyrec
|
|
|
|
{
|
|
|
|
KEYDB_SEARCH_DESC desc;
|
2004-05-10 23:46:00 +02:00
|
|
|
u32 createtime,expiretime;
|
2002-10-14 20:50:28 +02:00
|
|
|
int size,flags;
|
|
|
|
byte type;
|
|
|
|
IOBUF uidbuf;
|
2004-05-10 23:46:00 +02:00
|
|
|
unsigned int lines;
|
2002-10-14 20:50:28 +02:00
|
|
|
};
|
|
|
|
|
2005-12-23 22:33:32 +01:00
|
|
|
enum ks_action {KS_UNKNOWN=0,KS_GET,KS_GETNAME,KS_SEND,KS_SEARCH};
|
|
|
|
|
2004-04-15 20:16:17 +02:00
|
|
|
static struct parse_options keyserver_opts[]=
|
|
|
|
{
|
2006-02-23 23:39:40 +01:00
|
|
|
/* some of these options are not real - just for the help
|
|
|
|
message */
|
2006-02-22 21:34:48 +01:00
|
|
|
{"max-cert-size",0,NULL,NULL},
|
2006-02-23 23:39:40 +01:00
|
|
|
{"include-revoked",0,NULL,N_("include revoked keys in search results")},
|
|
|
|
{"include-subkeys",0,NULL,N_("include subkeys when searching by key ID")},
|
2005-09-15 00:31:21 +02:00
|
|
|
{"use-temp-files",0,NULL,
|
|
|
|
N_("use temporary files to pass data to keyserver helpers")},
|
|
|
|
{"keep-temp-files",KEYSERVER_KEEP_TEMP_FILES,NULL,
|
|
|
|
N_("do not delete temporary files after using them")},
|
|
|
|
{"refresh-add-fake-v3-keyids",KEYSERVER_ADD_FAKE_V3,NULL,
|
|
|
|
NULL},
|
|
|
|
{"auto-key-retrieve",KEYSERVER_AUTO_KEY_RETRIEVE,NULL,
|
|
|
|
N_("automatically retrieve keys when verifying signatures")},
|
|
|
|
{"honor-keyserver-url",KEYSERVER_HONOR_KEYSERVER_URL,NULL,
|
|
|
|
N_("honor the preferred keyserver URL set on the key")},
|
2006-02-22 21:20:58 +01:00
|
|
|
{"honor-pka-record",KEYSERVER_HONOR_PKA_RECORD,NULL,
|
|
|
|
N_("honor the PKA record set on a key when retrieving keys")},
|
2005-09-15 00:31:21 +02:00
|
|
|
{NULL,0,NULL,NULL}
|
2004-04-15 20:16:17 +02:00
|
|
|
};
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2005-12-23 22:33:32 +01:00
|
|
|
static int keyserver_work(enum ks_action action,STRLIST list,
|
|
|
|
KEYDB_SEARCH_DESC *desc,int count,
|
2006-03-14 03:42:02 +01:00
|
|
|
unsigned char **fpr,size_t *fpr_len,
|
2005-12-23 22:33:32 +01:00
|
|
|
struct keyserver_spec *keyserver);
|
2002-10-14 20:50:28 +02:00
|
|
|
|
2005-12-23 23:17:11 +01:00
|
|
|
/* Reasonable guess */
|
|
|
|
#define DEFAULT_MAX_CERT_SIZE 16384
|
|
|
|
|
|
|
|
static size_t max_cert_size=DEFAULT_MAX_CERT_SIZE;
|
|
|
|
|
2006-02-23 18:00:02 +01:00
|
|
|
static void
|
|
|
|
add_canonical_option(char *option,STRLIST *list)
|
|
|
|
{
|
|
|
|
char *arg=argsplit(option);
|
|
|
|
|
|
|
|
if(arg)
|
|
|
|
{
|
|
|
|
char *joined;
|
|
|
|
|
|
|
|
joined=xmalloc(strlen(option)+1+strlen(arg)+1);
|
|
|
|
/* Make a canonical name=value form with no spaces */
|
|
|
|
strcpy(joined,option);
|
|
|
|
strcat(joined,"=");
|
|
|
|
strcat(joined,arg);
|
2006-02-23 21:54:30 +01:00
|
|
|
append_to_strlist(list,joined);
|
2006-02-23 18:00:02 +01:00
|
|
|
xfree(joined);
|
|
|
|
}
|
|
|
|
else
|
2006-02-23 21:54:30 +01:00
|
|
|
append_to_strlist(list,option);
|
2006-02-23 18:00:02 +01:00
|
|
|
}
|
|
|
|
|
2004-04-16 17:19:35 +02:00
|
|
|
int
|
2002-06-29 15:46:34 +02:00
|
|
|
parse_keyserver_options(char *options)
|
|
|
|
{
|
2004-04-16 17:19:35 +02:00
|
|
|
int ret=1;
|
|
|
|
char *tok;
|
2006-02-24 04:57:11 +01:00
|
|
|
char *max_cert=NULL;
|
2005-12-23 23:17:11 +01:00
|
|
|
|
2006-02-22 21:34:48 +01:00
|
|
|
keyserver_opts[0].value=&max_cert;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-04-16 17:19:35 +02:00
|
|
|
while((tok=optsep(&options)))
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2002-07-22 19:52:02 +02:00
|
|
|
if(tok[0]=='\0')
|
|
|
|
continue;
|
|
|
|
|
2005-03-10 20:34:40 +01:00
|
|
|
/* For backwards compatibility. 1.2.x used honor-http-proxy and
|
|
|
|
there are a good number of documents published that recommend
|
|
|
|
it. */
|
|
|
|
if(ascii_strcasecmp(tok,"honor-http-proxy")==0)
|
|
|
|
tok="http-proxy";
|
|
|
|
else if(ascii_strcasecmp(tok,"no-honor-http-proxy")==0)
|
|
|
|
tok="no-http-proxy";
|
|
|
|
|
2004-04-15 20:16:17 +02:00
|
|
|
/* We accept quite a few possible options here - some options to
|
|
|
|
handle specially, the keyserver_options list, and import and
|
2004-04-19 18:02:11 +02:00
|
|
|
export options that pertain to keyserver operations. Note
|
|
|
|
that you must use strncasecmp here as there might be an
|
|
|
|
=argument attached which will foil the use of strcasecmp. */
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
#ifdef EXEC_TEMPFILE_ONLY
|
2005-03-17 23:55:17 +01:00
|
|
|
if(ascii_strncasecmp(tok,"use-temp-files",14)==0 ||
|
2004-04-19 18:02:11 +02:00
|
|
|
ascii_strncasecmp(tok,"no-use-temp-files",17)==0)
|
2004-09-28 16:50:05 +02:00
|
|
|
log_info(_("WARNING: keyserver option `%s' is not used"
|
2004-09-04 00:06:36 +02:00
|
|
|
" on this platform\n"),tok);
|
2002-06-29 15:46:34 +02:00
|
|
|
#else
|
2005-03-17 23:55:17 +01:00
|
|
|
if(ascii_strncasecmp(tok,"use-temp-files",14)==0)
|
2004-04-15 20:16:17 +02:00
|
|
|
opt.keyserver_options.options|=KEYSERVER_USE_TEMP_FILES;
|
2004-04-19 18:02:11 +02:00
|
|
|
else if(ascii_strncasecmp(tok,"no-use-temp-files",17)==0)
|
2004-04-15 20:16:17 +02:00
|
|
|
opt.keyserver_options.options&=~KEYSERVER_USE_TEMP_FILES;
|
2002-06-29 15:46:34 +02:00
|
|
|
#endif
|
2004-04-15 20:16:17 +02:00
|
|
|
else if(!parse_options(tok,&opt.keyserver_options.options,
|
|
|
|
keyserver_opts,0)
|
|
|
|
&& !parse_import_options(tok,
|
|
|
|
&opt.keyserver_options.import_options,0)
|
|
|
|
&& !parse_export_options(tok,
|
|
|
|
&opt.keyserver_options.export_options,0))
|
|
|
|
{
|
|
|
|
/* All of the standard options have failed, so the option is
|
|
|
|
destined for a keyserver plugin. */
|
2006-02-23 18:00:02 +01:00
|
|
|
add_canonical_option(tok,&opt.keyserver_options.other);
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
}
|
2004-04-16 17:19:35 +02:00
|
|
|
|
2006-02-22 21:34:48 +01:00
|
|
|
if(max_cert)
|
2005-12-23 23:17:11 +01:00
|
|
|
{
|
2006-02-22 21:34:48 +01:00
|
|
|
max_cert_size=strtoul(max_cert,(char **)NULL,10);
|
2005-12-23 23:17:11 +01:00
|
|
|
|
|
|
|
if(max_cert_size==0)
|
|
|
|
max_cert_size=DEFAULT_MAX_CERT_SIZE;
|
|
|
|
}
|
|
|
|
|
2004-04-16 17:19:35 +02:00
|
|
|
return ret;
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
2004-05-08 15:51:14 +02:00
|
|
|
void
|
2004-04-19 18:02:11 +02:00
|
|
|
free_keyserver_spec(struct keyserver_spec *keyserver)
|
|
|
|
{
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(keyserver->uri);
|
|
|
|
xfree(keyserver->scheme);
|
|
|
|
xfree(keyserver->auth);
|
|
|
|
xfree(keyserver->host);
|
|
|
|
xfree(keyserver->port);
|
|
|
|
xfree(keyserver->path);
|
|
|
|
xfree(keyserver->opaque);
|
2006-02-23 18:00:02 +01:00
|
|
|
free_strlist(keyserver->options);
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(keyserver);
|
2004-04-19 18:02:11 +02:00
|
|
|
}
|
|
|
|
|
2006-02-24 15:27:22 +01:00
|
|
|
/* Return 0 for match */
|
|
|
|
static int
|
|
|
|
cmp_keyserver_spec(struct keyserver_spec *one,struct keyserver_spec *two)
|
|
|
|
{
|
|
|
|
if(ascii_strcasecmp(one->scheme,two->scheme)==0)
|
|
|
|
{
|
|
|
|
if(one->host && two->host && ascii_strcasecmp(one->host,two->host)==0)
|
|
|
|
{
|
|
|
|
if((one->port && two->port
|
|
|
|
&& ascii_strcasecmp(one->port,two->port)==0)
|
|
|
|
|| (!one->port && !two->port))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if(one->opaque && two->opaque
|
|
|
|
&& ascii_strcasecmp(one->opaque,two->opaque)==0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try and match one of our keyservers. If we can, return that. If
|
|
|
|
we can't, return our input. */
|
|
|
|
struct keyserver_spec *
|
|
|
|
keyserver_match(struct keyserver_spec *spec)
|
|
|
|
{
|
|
|
|
struct keyserver_spec *ks;
|
|
|
|
|
|
|
|
for(ks=opt.keyserver;ks;ks=ks->next)
|
|
|
|
if(cmp_keyserver_spec(spec,ks)==0)
|
|
|
|
return ks;
|
|
|
|
|
|
|
|
return spec;
|
|
|
|
}
|
|
|
|
|
2005-07-20 23:15:04 +02:00
|
|
|
/* TODO: once we cut over to an all-curl world, we don't need this
|
|
|
|
parser any longer so it can be removed, or at least moved to
|
|
|
|
keyserver/ksutil.c for limited use in gpgkeys_ldap or the like. */
|
|
|
|
|
2004-04-14 23:33:45 +02:00
|
|
|
struct keyserver_spec *
|
2006-02-23 18:00:02 +01:00
|
|
|
parse_keyserver_uri(const char *string,int require_scheme,
|
2004-05-08 15:51:14 +02:00
|
|
|
const char *configname,unsigned int configlineno)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2002-07-09 21:40:18 +02:00
|
|
|
int assume_hkp=0;
|
2004-04-14 23:33:45 +02:00
|
|
|
struct keyserver_spec *keyserver;
|
2004-05-11 21:36:44 +02:00
|
|
|
const char *idx;
|
|
|
|
int count;
|
2006-02-23 18:00:02 +01:00
|
|
|
char *uri,*options;
|
2002-07-09 21:40:18 +02:00
|
|
|
|
2006-02-23 18:00:02 +01:00
|
|
|
assert(string!=NULL);
|
2002-07-09 21:40:18 +02:00
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
keyserver=xmalloc_clear(sizeof(struct keyserver_spec));
|
2004-04-14 23:33:45 +02:00
|
|
|
|
2006-02-23 18:00:02 +01:00
|
|
|
uri=xstrdup(string);
|
|
|
|
|
|
|
|
options=strchr(uri,' ');
|
|
|
|
if(options)
|
|
|
|
{
|
|
|
|
char *tok;
|
|
|
|
|
|
|
|
*options='\0';
|
|
|
|
options++;
|
|
|
|
|
|
|
|
while((tok=optsep(&options)))
|
|
|
|
add_canonical_option(tok,&keyserver->options);
|
|
|
|
}
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
/* Get the scheme */
|
|
|
|
|
2004-05-19 05:11:22 +02:00
|
|
|
for(idx=uri,count=0;*idx && *idx!=':';idx++)
|
2005-01-26 22:20:30 +01:00
|
|
|
{
|
|
|
|
count++;
|
|
|
|
|
|
|
|
/* Do we see the start of an RFC-2732 ipv6 address here? If so,
|
|
|
|
there clearly isn't a scheme so get out early. */
|
|
|
|
if(*idx=='[')
|
|
|
|
{
|
|
|
|
/* Was the '[' the first thing in the string? If not, we
|
|
|
|
have a mangled scheme with a [ in it so fail. */
|
|
|
|
if(count==1)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
2004-05-11 21:36:44 +02:00
|
|
|
|
|
|
|
if(count==0)
|
|
|
|
goto fail;
|
|
|
|
|
2005-01-26 22:20:30 +01:00
|
|
|
if(*idx=='\0' || *idx=='[')
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2004-05-08 15:51:14 +02:00
|
|
|
if(require_scheme)
|
|
|
|
return NULL;
|
|
|
|
|
2002-07-09 21:40:18 +02:00
|
|
|
/* Assume HKP if there is no scheme */
|
|
|
|
assume_hkp=1;
|
2005-07-27 20:10:56 +02:00
|
|
|
keyserver->scheme=xstrdup("hkp");
|
2006-02-21 06:20:08 +01:00
|
|
|
|
|
|
|
keyserver->uri=xmalloc(strlen(keyserver->scheme)+3+strlen(uri)+1);
|
|
|
|
strcpy(keyserver->uri,keyserver->scheme);
|
|
|
|
strcat(keyserver->uri,"://");
|
|
|
|
strcat(keyserver->uri,uri);
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
2002-09-30 05:28:41 +02:00
|
|
|
else
|
|
|
|
{
|
2004-05-11 21:36:44 +02:00
|
|
|
int i;
|
|
|
|
|
2006-02-21 06:20:08 +01:00
|
|
|
keyserver->uri=xstrdup(uri);
|
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
keyserver->scheme=xmalloc(count+1);
|
2004-05-11 21:36:44 +02:00
|
|
|
|
2002-09-30 05:28:41 +02:00
|
|
|
/* Force to lowercase */
|
2004-05-11 21:36:44 +02:00
|
|
|
for(i=0;i<count;i++)
|
|
|
|
keyserver->scheme[i]=ascii_tolower(uri[i]);
|
|
|
|
|
|
|
|
keyserver->scheme[i]='\0';
|
2002-09-30 05:28:41 +02:00
|
|
|
|
2004-05-11 21:36:44 +02:00
|
|
|
/* Skip past the scheme and colon */
|
|
|
|
uri+=count+1;
|
2002-09-30 05:28:41 +02:00
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-05-11 21:36:44 +02:00
|
|
|
if(ascii_strcasecmp(keyserver->scheme,"x-broken-hkp")==0)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
deprecated_warning(configname,configlineno,"x-broken-hkp",
|
|
|
|
"--keyserver-options ","broken-http-proxy");
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(keyserver->scheme);
|
|
|
|
keyserver->scheme=xstrdup("hkp");
|
2006-02-23 21:54:30 +01:00
|
|
|
append_to_strlist(&opt.keyserver_options.other,"broken-http-proxy");
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
2004-05-11 21:36:44 +02:00
|
|
|
else if(ascii_strcasecmp(keyserver->scheme,"x-hkp")==0)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
/* Canonicalize this to "hkp" so it works with both the internal
|
|
|
|
and external keyserver interface. */
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(keyserver->scheme);
|
|
|
|
keyserver->scheme=xstrdup("hkp");
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
2002-07-09 21:40:18 +02:00
|
|
|
if(assume_hkp || (uri[0]=='/' && uri[1]=='/'))
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2002-07-09 21:40:18 +02:00
|
|
|
/* Two slashes means network path. */
|
|
|
|
|
|
|
|
/* Skip over the "//", if any */
|
|
|
|
if(!assume_hkp)
|
|
|
|
uri+=2;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-12-22 19:09:41 +01:00
|
|
|
/* Do we have userinfo auth data present? */
|
|
|
|
for(idx=uri,count=0;*idx && *idx!='@' && *idx!='/';idx++)
|
|
|
|
count++;
|
|
|
|
|
|
|
|
/* We found a @ before the slash, so that means everything
|
|
|
|
before the @ is auth data. */
|
|
|
|
if(*idx=='@')
|
|
|
|
{
|
|
|
|
if(count==0)
|
|
|
|
goto fail;
|
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
keyserver->auth=xmalloc(count+1);
|
2004-12-22 19:09:41 +01:00
|
|
|
strncpy(keyserver->auth,uri,count);
|
|
|
|
keyserver->auth[count]='\0';
|
|
|
|
uri+=count+1;
|
|
|
|
}
|
|
|
|
|
2005-01-26 22:20:30 +01:00
|
|
|
/* Is it an RFC-2732 ipv6 [literal address] ? */
|
|
|
|
if(*uri=='[')
|
|
|
|
{
|
|
|
|
for(idx=uri+1,count=1;*idx
|
2005-04-11 20:24:09 +02:00
|
|
|
&& ((isascii (*idx) && isxdigit(*idx))
|
|
|
|
|| *idx==':' || *idx=='.');idx++)
|
2005-01-26 22:20:30 +01:00
|
|
|
count++;
|
|
|
|
|
|
|
|
/* Is the ipv6 literal address terminated? */
|
|
|
|
if(*idx==']')
|
|
|
|
count++;
|
|
|
|
else
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for(idx=uri,count=0;*idx && *idx!=':' && *idx!='/';idx++)
|
|
|
|
count++;
|
2004-05-11 21:36:44 +02:00
|
|
|
|
|
|
|
if(count==0)
|
2004-04-14 23:33:45 +02:00
|
|
|
goto fail;
|
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
keyserver->host=xmalloc(count+1);
|
2004-05-11 21:36:44 +02:00
|
|
|
strncpy(keyserver->host,uri,count);
|
|
|
|
keyserver->host[count]='\0';
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-05-11 21:36:44 +02:00
|
|
|
/* Skip past the host */
|
|
|
|
uri+=count;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-05-11 21:36:44 +02:00
|
|
|
if(*uri==':')
|
|
|
|
{
|
|
|
|
/* It would seem to be reasonable to limit the range of the
|
|
|
|
ports to values between 1-65535, but RFC 1738 and 1808
|
|
|
|
imply there is no limit. Of course, the real world has
|
|
|
|
limits. */
|
2002-07-09 21:40:18 +02:00
|
|
|
|
2004-05-19 05:11:22 +02:00
|
|
|
for(idx=uri+1,count=0;*idx && *idx!='/';idx++)
|
2002-07-09 21:40:18 +02:00
|
|
|
{
|
2004-05-11 21:36:44 +02:00
|
|
|
count++;
|
2002-07-09 21:40:18 +02:00
|
|
|
|
2004-05-11 21:36:44 +02:00
|
|
|
/* Ports are digits only */
|
|
|
|
if(!digitp(idx))
|
|
|
|
goto fail;
|
2002-07-09 21:40:18 +02:00
|
|
|
}
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 06:07:45 +02:00
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
keyserver->port=xmalloc(count+1);
|
2004-05-11 21:36:44 +02:00
|
|
|
strncpy(keyserver->port,uri+1,count);
|
|
|
|
keyserver->port[count]='\0';
|
2004-04-14 23:33:45 +02:00
|
|
|
|
2004-05-11 21:36:44 +02:00
|
|
|
/* Skip past the colon and port number */
|
|
|
|
uri+=1+count;
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
2004-05-11 21:36:44 +02:00
|
|
|
/* Everything else is the path */
|
|
|
|
if(*uri)
|
2005-07-27 20:10:56 +02:00
|
|
|
keyserver->path=xstrdup(uri);
|
2004-05-11 21:36:44 +02:00
|
|
|
else
|
2005-07-27 20:10:56 +02:00
|
|
|
keyserver->path=xstrdup("/");
|
2006-01-24 22:03:06 +01:00
|
|
|
|
2006-04-27 05:14:17 +02:00
|
|
|
if(keyserver->path[1])
|
2006-01-24 22:03:06 +01:00
|
|
|
keyserver->flags.direct_uri=1;
|
2002-07-09 21:40:18 +02:00
|
|
|
}
|
|
|
|
else if(uri[0]!='/')
|
|
|
|
{
|
|
|
|
/* No slash means opaque. Just record the opaque blob and get
|
|
|
|
out. */
|
2005-07-27 20:10:56 +02:00
|
|
|
keyserver->opaque=xstrdup(uri);
|
2002-07-09 21:40:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* One slash means absolute path. We don't need to support that
|
|
|
|
yet. */
|
2004-04-14 23:33:45 +02:00
|
|
|
goto fail;
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
2004-04-14 23:33:45 +02:00
|
|
|
return keyserver;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-04-14 23:33:45 +02:00
|
|
|
fail:
|
2004-04-19 18:02:11 +02:00
|
|
|
free_keyserver_spec(keyserver);
|
2004-04-14 23:33:45 +02:00
|
|
|
|
|
|
|
return NULL;
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
2004-05-22 05:50:20 +02:00
|
|
|
struct keyserver_spec *
|
|
|
|
parse_preferred_keyserver(PKT_signature *sig)
|
|
|
|
{
|
|
|
|
struct keyserver_spec *spec=NULL;
|
|
|
|
const byte *p;
|
|
|
|
size_t plen;
|
|
|
|
|
|
|
|
p=parse_sig_subpkt(sig->hashed,SIGSUBPKT_PREF_KS,&plen);
|
|
|
|
if(p && plen)
|
|
|
|
{
|
2005-07-27 20:10:56 +02:00
|
|
|
byte *dupe=xmalloc(plen+1);
|
2004-05-22 05:50:20 +02:00
|
|
|
|
|
|
|
memcpy(dupe,p,plen);
|
|
|
|
dupe[plen]='\0';
|
2004-12-12 06:10:22 +01:00
|
|
|
spec=parse_keyserver_uri(dupe,1,NULL,0);
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(dupe);
|
2004-05-22 05:50:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return spec;
|
|
|
|
}
|
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
static void
|
|
|
|
print_keyrec(int number,struct keyrec *keyrec)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2002-10-14 20:50:28 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
iobuf_writebyte(keyrec->uidbuf,0);
|
|
|
|
iobuf_flush_temp(keyrec->uidbuf);
|
|
|
|
printf("(%d)\t%s ",number,iobuf_get_temp_buffer(keyrec->uidbuf));
|
|
|
|
|
|
|
|
if(keyrec->size>0)
|
|
|
|
printf("%d bit ",keyrec->size);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if(keyrec->type)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2002-10-14 20:50:28 +02:00
|
|
|
const char *str=pubkey_algo_to_string(keyrec->type);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if(str)
|
|
|
|
printf("%s ",str);
|
2002-06-29 15:46:34 +02:00
|
|
|
else
|
2002-10-14 20:50:28 +02:00
|
|
|
printf("unknown ");
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
switch(keyrec->desc.mode)
|
|
|
|
{
|
2004-03-05 01:01:25 +01:00
|
|
|
/* If the keyserver helper gave us a short keyid, we have no
|
|
|
|
choice but to use it. Do check --keyid-format to add a 0x if
|
|
|
|
needed. */
|
2002-10-14 20:50:28 +02:00
|
|
|
case KEYDB_SEARCH_MODE_SHORT_KID:
|
2004-03-05 01:01:25 +01:00
|
|
|
printf("key %s%08lX",
|
|
|
|
(opt.keyid_format==KF_0xSHORT
|
|
|
|
|| opt.keyid_format==KF_0xLONG)?"0x":"",
|
|
|
|
(ulong)keyrec->desc.u.kid[1]);
|
2002-10-14 20:50:28 +02:00
|
|
|
break;
|
|
|
|
|
2004-03-05 01:01:25 +01:00
|
|
|
/* However, if it gave us a long keyid, we can honor
|
|
|
|
--keyid-format */
|
2002-10-14 20:50:28 +02:00
|
|
|
case KEYDB_SEARCH_MODE_LONG_KID:
|
2004-03-05 01:01:25 +01:00
|
|
|
printf("key %s",keystr(keyrec->desc.u.kid));
|
2002-10-14 20:50:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYDB_SEARCH_MODE_FPR16:
|
|
|
|
printf("key ");
|
|
|
|
for(i=0;i<16;i++)
|
2004-09-22 00:24:47 +02:00
|
|
|
printf("%02X",keyrec->desc.u.fpr[i]);
|
2002-10-14 20:50:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYDB_SEARCH_MODE_FPR20:
|
|
|
|
printf("key ");
|
|
|
|
for(i=0;i<20;i++)
|
2004-09-22 00:24:47 +02:00
|
|
|
printf("%02X",keyrec->desc.u.fpr[i]);
|
2002-10-14 20:50:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
break;
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
2002-10-14 20:50:28 +02:00
|
|
|
|
|
|
|
if(keyrec->createtime>0)
|
2004-09-29 19:41:58 +02:00
|
|
|
{
|
|
|
|
printf(", ");
|
|
|
|
printf(_("created: %s"),strtimestamp(keyrec->createtime));
|
|
|
|
}
|
2002-10-14 20:50:28 +02:00
|
|
|
|
|
|
|
if(keyrec->expiretime>0)
|
2004-10-06 21:51:45 +02:00
|
|
|
{
|
|
|
|
printf(", ");
|
|
|
|
printf(_("expires: %s"),strtimestamp(keyrec->expiretime));
|
|
|
|
}
|
2002-10-14 20:50:28 +02:00
|
|
|
|
|
|
|
if(keyrec->flags&1)
|
2004-09-29 19:41:58 +02:00
|
|
|
printf(" (%s)",_("revoked"));
|
2002-10-14 20:50:28 +02:00
|
|
|
if(keyrec->flags&2)
|
2004-09-29 19:41:58 +02:00
|
|
|
printf(" (%s)",_("disabled"));
|
2002-10-14 20:50:28 +02:00
|
|
|
if(keyrec->flags&4)
|
2004-09-29 19:41:58 +02:00
|
|
|
printf(" (%s)",_("expired"));
|
2002-10-14 20:50:28 +02:00
|
|
|
|
|
|
|
printf("\n");
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
/* Returns a keyrec (which must be freed) once a key is complete, and
|
|
|
|
NULL otherwise. Call with a NULL keystring once key parsing is
|
|
|
|
complete to return any unfinished keys. */
|
|
|
|
static struct keyrec *
|
|
|
|
parse_keyrec(char *keystring)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2002-10-14 20:50:28 +02:00
|
|
|
static struct keyrec *work=NULL;
|
|
|
|
struct keyrec *ret=NULL;
|
2002-11-01 17:15:45 +01:00
|
|
|
char *record;
|
2002-10-14 20:50:28 +02:00
|
|
|
int i;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if(keystring==NULL)
|
|
|
|
{
|
|
|
|
if(work==NULL)
|
|
|
|
return NULL;
|
|
|
|
else if(work->desc.mode==KEYDB_SEARCH_MODE_NONE)
|
|
|
|
{
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(work);
|
2002-10-14 20:50:28 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret=work;
|
|
|
|
work=NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if(work==NULL)
|
|
|
|
{
|
2005-07-27 20:10:56 +02:00
|
|
|
work=xmalloc_clear(sizeof(struct keyrec));
|
2002-10-14 20:50:28 +02:00
|
|
|
work->uidbuf=iobuf_temp();
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
/* Remove trailing whitespace */
|
|
|
|
for(i=strlen(keystring);i>0;i--)
|
* parse-packet.c (parse_signature): No need to reserve 8 bytes for the
unhashed signature cache any longer.
* misc.c (pct_expando): Add two new expandos - signer's fingerprint (%g),
and signer's primary fingerprint (%p).
* Makefile.am: Include W32LIBS where appropriate.
* g10.c (main): Add --rfc2440 alias for --openpgp since in a few months,
they won't be the same thing.
* keyserver.c (parse_keyserver_uri): Accept "http" as an alias for "hkp",
since it is occasionally written that way. (keyserver_spawn): Use
ascii_isspace to avoid locale issues.
* keygen.c (ask_user_id): Make --allow-freeform-uid apply to the email
field as well as the name field, and allow mixing fields when it is set.
* options.skel: Use subkeys.pgp.net as the default keyserver.
* trustdb.c (validate_one_keyblock): Certifications on revoked or expired
uids do not count in the web of trust.
* signal.c (init_one_signal, pause_on_sigusr, do_block): Only use
sigprocmask() if we have sigset_t, and only use sigaction() if we have
struct sigaction. This is for Forte c89 on Solaris which seems to define
only the function call half of the two pairs by default.
(pause_on_sigusr): Typo. (do_block): If we can't use sigprocmask() and
sigset_t, try to get the number of signals from NSIG as well as MAXSIG,
and if we can't, fail with an explanation.
* signal.c, tdbio.c: Comment out the transaction code. It was not used in
this version, and was causing some build problems on quasi-posix platforms
(Solaris and Forte c89).
* keylist.c (list_keyblock_colon): Don't include validity values when
listing secret keys since they can be incorrect and/or misleading. This
is a temporary kludge, and will be handled properly in 1.9/2.0.
* mainproc.c (check_sig_and_print): Only show the "key available from"
preferred keyserver line if the key is not currently present.
* keyedit.c (sign_uids): Do not sign expired uids without --expert (same
behavior as revoked uids). Do not allow signing a user ID without a
self-signature. --expert overrides. Add additional prompt to the
signature level question. (menu_expire): When changing expiration dates,
don't replace selfsigs on revoked uids since this would effectively
unrevoke them. There is also no point in replacing expired selfsigs.
This is bug #181
* g10.c (add_notation_data): Make sure that only ascii is passed to
iscntrl. Noted by Christian Biere.
* getkey.c (classify_user_id2): Replaced isspace by spacep
* keygen.c (ask_user_id): Ditto. (get_parameter_algo): Ditto.
* keyedit.c (keyedit_menu): Ditto.
* tdbdump.c (import_ownertrust): Ditto. s/isxdigit/hexdigitp/.
* revoke.c (ask_revocation_reason):
* keyserver.c (keyserver_spawn): Dito.
2003-07-10 16:30:07 +02:00
|
|
|
if(ascii_isspace(keystring[i-1]))
|
2002-10-14 20:50:28 +02:00
|
|
|
keystring[i-1]='\0';
|
|
|
|
else
|
|
|
|
break;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if((record=strsep(&keystring,":"))==NULL)
|
|
|
|
return ret;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if(ascii_strcasecmp("pub",record)==0)
|
|
|
|
{
|
2002-11-01 17:15:45 +01:00
|
|
|
char *tok;
|
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if(work->desc.mode)
|
|
|
|
{
|
|
|
|
ret=work;
|
2005-07-27 20:10:56 +02:00
|
|
|
work=xmalloc_clear(sizeof(struct keyrec));
|
2002-10-14 20:50:28 +02:00
|
|
|
work->uidbuf=iobuf_temp();
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return ret;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
classify_user_id(tok,&work->desc);
|
|
|
|
if(work->desc.mode!=KEYDB_SEARCH_MODE_SHORT_KID
|
|
|
|
&& work->desc.mode!=KEYDB_SEARCH_MODE_LONG_KID
|
|
|
|
&& work->desc.mode!=KEYDB_SEARCH_MODE_FPR16
|
|
|
|
&& work->desc.mode!=KEYDB_SEARCH_MODE_FPR20)
|
|
|
|
{
|
|
|
|
work->desc.mode=KEYDB_SEARCH_MODE_NONE;
|
|
|
|
return ret;
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
/* Note all items after this are optional. This allows us to
|
|
|
|
have a pub line as simple as pub:keyid and nothing else. */
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
work->lines++;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return ret;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
work->type=atoi(tok);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return ret;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
work->size=atoi(tok);
|
|
|
|
|
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return ret;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-09-28 16:50:05 +02:00
|
|
|
if(atoi(tok)<=0)
|
2004-05-10 23:46:00 +02:00
|
|
|
work->createtime=0;
|
|
|
|
else
|
|
|
|
work->createtime=atoi(tok);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return ret;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-09-28 16:50:05 +02:00
|
|
|
if(atoi(tok)<=0)
|
2004-05-10 23:46:00 +02:00
|
|
|
work->expiretime=0;
|
|
|
|
else
|
2004-09-04 00:06:36 +02:00
|
|
|
{
|
|
|
|
work->expiretime=atoi(tok);
|
|
|
|
/* Force the 'e' flag on if this key is expired. */
|
|
|
|
if(work->expiretime<=make_timestamp())
|
|
|
|
work->flags|=4;
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return ret;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
while(*tok)
|
|
|
|
switch(*tok++)
|
|
|
|
{
|
|
|
|
case 'r':
|
|
|
|
case 'R':
|
|
|
|
work->flags|=1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
case 'D':
|
|
|
|
work->flags|=2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'e':
|
|
|
|
case 'E':
|
|
|
|
work->flags|=4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(ascii_strcasecmp("uid",record)==0 && work->desc.mode)
|
|
|
|
{
|
|
|
|
char *userid,*tok,*decoded;
|
2002-08-28 21:34:58 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return ret;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
if(strlen(tok)==0)
|
|
|
|
return ret;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
userid=tok;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
/* By definition, de-%-encoding is always smaller than the
|
|
|
|
original string so we can decode in place. */
|
|
|
|
|
2002-11-01 17:15:45 +01:00
|
|
|
i=0;
|
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
while(*tok)
|
|
|
|
if(tok[0]=='%' && tok[1] && tok[2])
|
|
|
|
{
|
|
|
|
if((userid[i]=hextobyte(&tok[1]))==-1)
|
|
|
|
userid[i]='?';
|
|
|
|
|
|
|
|
i++;
|
|
|
|
tok+=3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
userid[i++]=*tok++;
|
|
|
|
|
|
|
|
/* We don't care about the other info provided in the uid: line
|
|
|
|
since no keyserver supports marking userids with timestamps
|
|
|
|
or revoked/expired/disabled yet. */
|
|
|
|
|
|
|
|
/* No need to check for control characters, as utf8_to_native
|
|
|
|
does this for us. */
|
|
|
|
|
|
|
|
decoded=utf8_to_native(userid,i,0);
|
2004-01-24 01:47:45 +01:00
|
|
|
if(strlen(decoded)>opt.screen_columns-10)
|
|
|
|
decoded[opt.screen_columns-10]='\0';
|
2002-10-14 20:50:28 +02:00
|
|
|
iobuf_writestr(work->uidbuf,decoded);
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(decoded);
|
2002-10-14 20:50:28 +02:00
|
|
|
iobuf_writestr(work->uidbuf,"\n\t");
|
|
|
|
work->lines++;
|
|
|
|
}
|
2004-02-22 01:36:34 +01:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
/* Ignore any records other than "pri" and "uid" for easy future
|
|
|
|
growth. */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: do this as a list sent to keyserver_work rather than calling
|
|
|
|
it once for each key to get the correct counts after the import
|
|
|
|
(cosmetics, really) and to better take advantage of the keyservers
|
|
|
|
that can do multiple fetches in one go (LDAP). */
|
|
|
|
static int
|
|
|
|
show_prompt(KEYDB_SEARCH_DESC *desc,int numdesc,int count,const char *search)
|
|
|
|
{
|
|
|
|
char *answer;
|
|
|
|
|
2002-11-05 05:28:40 +01:00
|
|
|
if(count && opt.command_fd==-1)
|
2002-10-14 20:50:28 +02:00
|
|
|
{
|
|
|
|
static int from=1;
|
|
|
|
tty_printf("Keys %d-%d of %d for \"%s\". ",from,numdesc,count,search);
|
|
|
|
from=numdesc+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
answer=cpr_get_no_help("keysearch.prompt",
|
|
|
|
_("Enter number(s), N)ext, or Q)uit > "));
|
|
|
|
/* control-d */
|
|
|
|
if(answer[0]=='\x04')
|
|
|
|
{
|
|
|
|
printf("Q\n");
|
|
|
|
answer[0]='q';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(answer[0]=='q' || answer[0]=='Q')
|
|
|
|
{
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(answer);
|
2002-10-14 20:50:28 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if(atoi(answer)>=1 && atoi(answer)<=numdesc)
|
|
|
|
{
|
|
|
|
char *split=answer,*num;
|
|
|
|
|
|
|
|
while((num=strsep(&split," ,"))!=NULL)
|
|
|
|
if(atoi(num)>=1 && atoi(num)<=numdesc)
|
2006-03-14 03:42:02 +01:00
|
|
|
keyserver_work(KS_GET,NULL,&desc[atoi(num)-1],1,
|
|
|
|
NULL,NULL,opt.keyserver);
|
2002-10-14 20:50:28 +02:00
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(answer);
|
2002-10-14 20:50:28 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
return 0;
|
2002-10-14 20:50:28 +02:00
|
|
|
}
|
2002-09-10 10:40:12 +02:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
/* Count and searchstr are just for cosmetics. If the count is too
|
|
|
|
small, it will grow safely. If negative it disables the "Key x-y
|
2004-08-23 16:39:48 +02:00
|
|
|
of z" messages. searchstr should be UTF-8 (rather than native). */
|
2002-10-14 20:50:28 +02:00
|
|
|
static void
|
|
|
|
keyserver_search_prompt(IOBUF buffer,const char *searchstr)
|
|
|
|
{
|
2004-05-10 23:46:00 +02:00
|
|
|
int i=0,validcount=0,started=0,header=0,count=1;
|
|
|
|
unsigned int maxlen,buflen,numlines=0;
|
2002-10-14 20:50:28 +02:00
|
|
|
KEYDB_SEARCH_DESC *desc;
|
|
|
|
byte *line=NULL;
|
2004-08-23 16:39:48 +02:00
|
|
|
char *localstr=NULL;
|
|
|
|
|
|
|
|
if(searchstr)
|
|
|
|
localstr=utf8_to_native(searchstr,strlen(searchstr),0);
|
2002-10-14 20:50:28 +02:00
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
desc=xmalloc(count*sizeof(KEYDB_SEARCH_DESC));
|
2002-10-14 20:50:28 +02:00
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
struct keyrec *keyrec;
|
|
|
|
int rl;
|
|
|
|
|
|
|
|
maxlen=1024;
|
|
|
|
rl=iobuf_read_line(buffer,&line,&buflen,&maxlen);
|
|
|
|
|
2002-11-05 05:28:40 +01:00
|
|
|
if(opt.with_colons)
|
|
|
|
{
|
|
|
|
if(!header && ascii_strncasecmp("SEARCH ",line,7)==0
|
|
|
|
&& ascii_strncasecmp(" BEGIN",&line[strlen(line)-7],6)==0)
|
|
|
|
{
|
|
|
|
header=1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if(ascii_strncasecmp("SEARCH ",line,7)==0
|
|
|
|
&& ascii_strncasecmp(" END",&line[strlen(line)-5],4)==0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
printf("%s",line);
|
|
|
|
}
|
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
/* Look for an info: line. The only current info: values
|
|
|
|
defined are the version and key count. */
|
|
|
|
if(!started && rl>0 && ascii_strncasecmp("info:",line,5)==0)
|
|
|
|
{
|
|
|
|
char *tok,*str=&line[5];
|
|
|
|
|
|
|
|
if((tok=strsep(&str,":"))!=NULL)
|
|
|
|
{
|
|
|
|
int version;
|
|
|
|
|
|
|
|
if(sscanf(tok,"%d",&version)!=1)
|
|
|
|
version=1;
|
|
|
|
|
|
|
|
if(version!=1)
|
|
|
|
{
|
|
|
|
log_error(_("invalid keyserver protocol "
|
|
|
|
"(us %d!=handler %d)\n"),1,version);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if((tok=strsep(&str,":"))!=NULL && sscanf(tok,"%d",&count)==1)
|
|
|
|
{
|
|
|
|
if(count==0)
|
|
|
|
goto notfound;
|
|
|
|
else if(count<0)
|
|
|
|
count=10;
|
|
|
|
else
|
|
|
|
validcount=1;
|
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
desc=xrealloc(desc,count*sizeof(KEYDB_SEARCH_DESC));
|
2002-10-14 20:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
started=1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rl==0)
|
|
|
|
{
|
|
|
|
keyrec=parse_keyrec(NULL);
|
|
|
|
|
|
|
|
if(keyrec==NULL)
|
|
|
|
{
|
|
|
|
if(i==0)
|
|
|
|
{
|
|
|
|
count=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(i!=count)
|
|
|
|
validcount=0;
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
2004-08-23 16:39:48 +02:00
|
|
|
if(show_prompt(desc,i,validcount?count:0,localstr))
|
2002-10-14 20:50:28 +02:00
|
|
|
break;
|
|
|
|
validcount=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
keyrec=parse_keyrec(line);
|
|
|
|
|
|
|
|
if(i==count)
|
|
|
|
{
|
|
|
|
/* keyserver helper sent more keys than they claimed in the
|
|
|
|
info: line. */
|
|
|
|
count+=10;
|
2005-07-27 20:10:56 +02:00
|
|
|
desc=xrealloc(desc,count*sizeof(KEYDB_SEARCH_DESC));
|
2002-10-14 20:50:28 +02:00
|
|
|
validcount=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(keyrec)
|
|
|
|
{
|
|
|
|
desc[i]=keyrec->desc;
|
|
|
|
|
2002-11-05 17:11:04 +01:00
|
|
|
if(!opt.with_colons)
|
2002-10-14 20:50:28 +02:00
|
|
|
{
|
2004-01-24 01:47:45 +01:00
|
|
|
/* screen_lines - 1 for the prompt. */
|
|
|
|
if(numlines+keyrec->lines>opt.screen_lines-1)
|
2002-11-05 17:11:04 +01:00
|
|
|
{
|
2004-08-23 16:39:48 +02:00
|
|
|
if(show_prompt(desc,i,validcount?count:0,localstr))
|
2002-11-05 17:11:04 +01:00
|
|
|
break;
|
|
|
|
else
|
|
|
|
numlines=0;
|
|
|
|
}
|
2002-10-14 20:50:28 +02:00
|
|
|
|
2002-11-05 17:11:04 +01:00
|
|
|
print_keyrec(i+1,keyrec);
|
|
|
|
}
|
2002-11-05 05:28:40 +01:00
|
|
|
|
2002-10-14 20:50:28 +02:00
|
|
|
numlines+=keyrec->lines;
|
|
|
|
iobuf_close(keyrec->uidbuf);
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(keyrec);
|
2002-10-14 20:50:28 +02:00
|
|
|
|
|
|
|
started=1;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
notfound:
|
2005-04-17 06:10:03 +02:00
|
|
|
/* Leave this commented out or now, and perhaps for a very long
|
|
|
|
time. All HKPish servers return HTML error messages for
|
|
|
|
no-key-found. */
|
|
|
|
/*
|
|
|
|
if(!started)
|
|
|
|
log_info(_("keyserver does not support searching\n"));
|
|
|
|
else
|
|
|
|
*/
|
2002-10-14 20:50:28 +02:00
|
|
|
if(count==0)
|
|
|
|
{
|
2004-08-23 16:39:48 +02:00
|
|
|
if(localstr)
|
|
|
|
log_info(_("key \"%s\" not found on keyserver\n"),localstr);
|
2002-10-14 20:50:28 +02:00
|
|
|
else
|
|
|
|
log_info(_("key not found on keyserver\n"));
|
|
|
|
}
|
2004-08-23 16:39:48 +02:00
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(localstr);
|
|
|
|
xfree(desc);
|
|
|
|
xfree(line);
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
2004-12-22 18:49:44 +01:00
|
|
|
/* We sometimes want to use a different gpgkeys_xxx for a given
|
|
|
|
protocol (for example, ldaps is handled by gpgkeys_ldap). Map
|
|
|
|
these here. */
|
|
|
|
static const char *
|
|
|
|
keyserver_typemap(const char *type)
|
|
|
|
{
|
2005-08-21 22:58:46 +02:00
|
|
|
if(strcmp(type,"ldaps")==0)
|
2005-07-27 03:24:57 +02:00
|
|
|
return "ldap";
|
2004-12-22 18:49:44 +01:00
|
|
|
else
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2005-08-27 05:09:40 +02:00
|
|
|
/* The PGP LDAP and the curl fetch-a-LDAP-object methodologies are
|
|
|
|
sufficiently different that we can't use curl to do LDAP. */
|
2005-08-21 22:58:46 +02:00
|
|
|
static int
|
2006-04-27 05:14:17 +02:00
|
|
|
direct_uri_map(const char *scheme,unsigned int is_direct)
|
2005-08-21 22:58:46 +02:00
|
|
|
{
|
2006-04-27 05:14:17 +02:00
|
|
|
if(is_direct && strcmp(scheme,"ldap")==0)
|
2005-08-21 22:58:46 +02:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-27 05:14:17 +02:00
|
|
|
#define GPGKEYS_PREFIX "gpgkeys_"
|
|
|
|
#define GPGKEYS_CURL GPGKEYS_PREFIX "curl" EXEEXT
|
|
|
|
#define GPGKEYS_PREFIX_LEN (strlen(GPGKEYS_CURL))
|
2002-06-29 15:46:34 +02:00
|
|
|
#define KEYSERVER_ARGS_KEEP " -o \"%O\" \"%I\""
|
|
|
|
#define KEYSERVER_ARGS_NOKEEP " -o \"%o\" \"%i\""
|
|
|
|
|
|
|
|
static int
|
2005-12-23 22:33:32 +01:00
|
|
|
keyserver_spawn(enum ks_action action,STRLIST list,KEYDB_SEARCH_DESC *desc,
|
2006-03-14 03:42:02 +01:00
|
|
|
int count,int *prog,unsigned char **fpr,size_t *fpr_len,
|
|
|
|
struct keyserver_spec *keyserver)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2005-12-08 06:52:41 +01:00
|
|
|
int ret=0,i,gotversion=0,outofband=0;
|
2002-06-29 15:46:34 +02:00
|
|
|
STRLIST temp;
|
2002-09-19 19:13:03 +02:00
|
|
|
unsigned int maxlen,buflen;
|
2005-08-21 22:58:46 +02:00
|
|
|
char *command,*end,*searchstr=NULL;
|
2002-06-29 15:46:34 +02:00
|
|
|
byte *line=NULL;
|
|
|
|
struct exec_info *spawn;
|
2004-12-22 18:49:44 +01:00
|
|
|
const char *scheme;
|
2005-07-19 10:50:28 +02:00
|
|
|
const char *libexecdir = get_libexecdir ();
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-04-19 18:02:11 +02:00
|
|
|
assert(keyserver);
|
2004-04-14 23:33:45 +02:00
|
|
|
|
2004-04-29 05:42:54 +02:00
|
|
|
#ifdef EXEC_TEMPFILE_ONLY
|
2004-05-21 14:29:53 +02:00
|
|
|
opt.keyserver_options.options|=KEYSERVER_USE_TEMP_FILES;
|
2004-04-29 05:42:54 +02:00
|
|
|
#endif
|
|
|
|
|
2005-03-31 05:58:53 +02:00
|
|
|
/* Build the filename for the helper to execute */
|
|
|
|
scheme=keyserver_typemap(keyserver->scheme);
|
|
|
|
|
2002-07-30 18:48:21 +02:00
|
|
|
#ifdef DISABLE_KEYSERVER_PATH
|
2005-03-31 05:58:53 +02:00
|
|
|
/* Destroy any path we might have. This is a little tricky,
|
|
|
|
portability-wise. It's not correct to delete the PATH
|
|
|
|
environment variable, as that may fall back to a system built-in
|
|
|
|
PATH. Similarly, it is not correct to set PATH to the null
|
|
|
|
string (PATH="") since this actually deletes the PATH environment
|
|
|
|
variable under MinGW. The safest thing to do here is to force
|
|
|
|
PATH to be GNUPG_LIBEXECDIR. All this is not that meaningful on
|
|
|
|
Unix-like systems (since we're going to give a full path to
|
|
|
|
gpgkeys_foo), but on W32 it prevents loading any DLLs from
|
2005-07-22 18:28:40 +02:00
|
|
|
directories in %PATH%.
|
|
|
|
|
|
|
|
After some more thinking about this we came to the conclusion
|
|
|
|
that it is better to load the helpers from the directory where
|
|
|
|
the program of this process lives. Fortunately Windows provides
|
|
|
|
a way to retrieve this and our get_libexecdir function has been
|
|
|
|
modified to return just this. Setting the exec-path is not
|
|
|
|
anymore required.
|
|
|
|
set_exec_path(libexecdir);
|
|
|
|
*/
|
2002-07-30 18:48:21 +02:00
|
|
|
#else
|
2005-03-31 05:58:53 +02:00
|
|
|
if(opt.exec_path_set)
|
|
|
|
{
|
|
|
|
/* If exec-path was set, and DISABLE_KEYSERVER_PATH is
|
|
|
|
undefined, then don't specify a full path to gpgkeys_foo, so
|
|
|
|
that the PATH can work. */
|
2006-01-22 22:40:20 +01:00
|
|
|
command=xmalloc(GPGKEYS_PREFIX_LEN+strlen(scheme)+3+strlen(EXEEXT)+1);
|
2005-03-31 05:58:53 +02:00
|
|
|
command[0]='\0';
|
|
|
|
}
|
|
|
|
else
|
2002-07-24 21:24:08 +02:00
|
|
|
#endif
|
2005-03-31 05:58:53 +02:00
|
|
|
{
|
|
|
|
/* Specify a full path to gpgkeys_foo. */
|
2005-07-27 20:10:56 +02:00
|
|
|
command=xmalloc(strlen(libexecdir)+strlen(DIRSEP_S)+
|
2006-01-22 22:40:20 +01:00
|
|
|
GPGKEYS_PREFIX_LEN+strlen(scheme)+3+strlen(EXEEXT)+1);
|
2005-07-19 10:50:28 +02:00
|
|
|
strcpy(command,libexecdir);
|
2005-03-31 05:58:53 +02:00
|
|
|
strcat(command,DIRSEP_S);
|
|
|
|
}
|
2002-07-24 21:24:08 +02:00
|
|
|
|
2005-08-21 22:58:46 +02:00
|
|
|
end=command+strlen(command);
|
|
|
|
|
2006-04-27 05:14:17 +02:00
|
|
|
/* Build a path for the keyserver helper. If it is direct_uri
|
|
|
|
(i.e. an object fetch and not a keyserver), then add "_uri" to
|
|
|
|
the end to distinguish the keyserver helper from an object
|
|
|
|
fetcher that can speak that protocol (this is a problem for
|
|
|
|
LDAP). */
|
|
|
|
|
2005-03-31 05:58:53 +02:00
|
|
|
strcat(command,GPGKEYS_PREFIX);
|
2004-12-22 18:49:44 +01:00
|
|
|
strcat(command,scheme);
|
2005-03-31 05:58:53 +02:00
|
|
|
|
2006-04-27 05:14:17 +02:00
|
|
|
/* This "_uri" thing is in case we need to call a direct handler
|
|
|
|
instead of the keyserver handler. This lets us use gpgkeys_curl
|
|
|
|
or gpgkeys_ldap_uri (we don't provide it, but a user might)
|
|
|
|
instead of gpgkeys_ldap to fetch things like
|
|
|
|
ldap://keyserver.pgp.com/o=PGP%20keys?pgpkey?sub?pgpkeyid=99242560 */
|
|
|
|
|
|
|
|
if(direct_uri_map(scheme,keyserver->flags.direct_uri))
|
|
|
|
strcat(command,"_uri");
|
2005-12-08 06:52:41 +01:00
|
|
|
|
2006-01-22 22:40:20 +01:00
|
|
|
strcat(command,EXEEXT);
|
|
|
|
|
2006-04-27 05:14:17 +02:00
|
|
|
/* Can we execute it? If not, try curl as our catchall. */
|
|
|
|
if(path_access(command,X_OK)!=0)
|
2005-08-21 22:58:46 +02:00
|
|
|
strcpy(end,GPGKEYS_CURL);
|
|
|
|
|
2004-04-15 20:16:17 +02:00
|
|
|
if(opt.keyserver_options.options&KEYSERVER_USE_TEMP_FILES)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2004-04-15 20:16:17 +02:00
|
|
|
if(opt.keyserver_options.options&KEYSERVER_KEEP_TEMP_FILES)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2005-07-27 20:10:56 +02:00
|
|
|
command=xrealloc(command,strlen(command)+
|
2002-06-29 15:46:34 +02:00
|
|
|
strlen(KEYSERVER_ARGS_KEEP)+1);
|
|
|
|
strcat(command,KEYSERVER_ARGS_KEEP);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-27 20:10:56 +02:00
|
|
|
command=xrealloc(command,strlen(command)+
|
2002-06-29 15:46:34 +02:00
|
|
|
strlen(KEYSERVER_ARGS_NOKEEP)+1);
|
|
|
|
strcat(command,KEYSERVER_ARGS_NOKEEP);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret=exec_write(&spawn,NULL,command,NULL,0,0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret=exec_write(&spawn,command,NULL,NULL,0,0);
|
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(command);
|
2005-04-17 06:10:03 +02:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
if(ret)
|
|
|
|
return ret;
|
|
|
|
|
2004-09-04 00:06:36 +02:00
|
|
|
fprintf(spawn->tochild,
|
|
|
|
"# This is a GnuPG %s keyserver communications file\n",VERSION);
|
2002-06-29 15:46:34 +02:00
|
|
|
fprintf(spawn->tochild,"VERSION %d\n",KEYSERVER_PROTO_VERSION);
|
|
|
|
fprintf(spawn->tochild,"PROGRAM %s\n",VERSION);
|
2004-04-19 18:02:11 +02:00
|
|
|
fprintf(spawn->tochild,"SCHEME %s\n",keyserver->scheme);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-04-19 18:02:11 +02:00
|
|
|
if(keyserver->opaque)
|
|
|
|
fprintf(spawn->tochild,"OPAQUE %s\n",keyserver->opaque);
|
2002-07-09 21:40:18 +02:00
|
|
|
else
|
|
|
|
{
|
2004-12-22 19:09:41 +01:00
|
|
|
if(keyserver->auth)
|
|
|
|
fprintf(spawn->tochild,"AUTH %s\n",keyserver->auth);
|
|
|
|
|
2004-04-19 18:02:11 +02:00
|
|
|
if(keyserver->host)
|
|
|
|
fprintf(spawn->tochild,"HOST %s\n",keyserver->host);
|
2002-07-09 21:40:18 +02:00
|
|
|
|
2004-04-19 18:02:11 +02:00
|
|
|
if(keyserver->port)
|
|
|
|
fprintf(spawn->tochild,"PORT %s\n",keyserver->port);
|
2004-05-11 21:36:44 +02:00
|
|
|
|
|
|
|
if(keyserver->path)
|
|
|
|
fprintf(spawn->tochild,"PATH %s\n",keyserver->path);
|
2002-07-09 21:40:18 +02:00
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2006-02-23 23:39:40 +01:00
|
|
|
/* Write global options */
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-04-15 20:16:17 +02:00
|
|
|
for(temp=opt.keyserver_options.other;temp;temp=temp->next)
|
2002-06-29 15:46:34 +02:00
|
|
|
fprintf(spawn->tochild,"OPTION %s\n",temp->d);
|
|
|
|
|
2006-02-23 23:39:40 +01:00
|
|
|
/* Write per-keyserver options */
|
|
|
|
|
2006-02-24 15:27:22 +01:00
|
|
|
for(temp=keyserver->options;temp;temp=temp->next)
|
2006-02-23 18:00:02 +01:00
|
|
|
fprintf(spawn->tochild,"OPTION %s\n",temp->d);
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
switch(action)
|
|
|
|
{
|
2005-12-23 22:33:32 +01:00
|
|
|
case KS_GET:
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
fprintf(spawn->tochild,"COMMAND GET\n\n");
|
|
|
|
|
|
|
|
/* Which keys do we want? */
|
|
|
|
|
|
|
|
for(i=0;i<count;i++)
|
|
|
|
{
|
2005-12-08 06:52:41 +01:00
|
|
|
int quiet=0;
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
if(desc[i].mode==KEYDB_SEARCH_MODE_FPR20)
|
|
|
|
{
|
|
|
|
int f;
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"0x");
|
|
|
|
|
|
|
|
for(f=0;f<MAX_FINGERPRINT_LEN;f++)
|
2004-09-22 00:24:47 +02:00
|
|
|
fprintf(spawn->tochild,"%02X",desc[i].u.fpr[f]);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
fprintf(spawn->tochild,"\n");
|
|
|
|
}
|
|
|
|
else if(desc[i].mode==KEYDB_SEARCH_MODE_FPR16)
|
|
|
|
{
|
|
|
|
int f;
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"0x");
|
|
|
|
|
|
|
|
for(f=0;f<16;f++)
|
2004-09-22 00:24:47 +02:00
|
|
|
fprintf(spawn->tochild,"%02X",desc[i].u.fpr[f]);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
fprintf(spawn->tochild,"\n");
|
|
|
|
}
|
|
|
|
else if(desc[i].mode==KEYDB_SEARCH_MODE_LONG_KID)
|
|
|
|
fprintf(spawn->tochild,"0x%08lX%08lX\n",
|
|
|
|
(ulong)desc[i].u.kid[0],
|
|
|
|
(ulong)desc[i].u.kid[1]);
|
2004-05-21 19:32:30 +02:00
|
|
|
else if(desc[i].mode==KEYDB_SEARCH_MODE_SHORT_KID)
|
2002-06-29 15:46:34 +02:00
|
|
|
fprintf(spawn->tochild,"0x%08lX\n",
|
|
|
|
(ulong)desc[i].u.kid[1]);
|
2005-12-07 23:34:11 +01:00
|
|
|
else if(desc[i].mode==KEYDB_SEARCH_MODE_EXACT)
|
|
|
|
{
|
|
|
|
fprintf(spawn->tochild,"0x0000000000000000\n");
|
|
|
|
quiet=1;
|
|
|
|
}
|
2004-10-05 16:33:02 +02:00
|
|
|
else if(desc[i].mode==KEYDB_SEARCH_MODE_NONE)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
BUG();
|
2004-08-23 21:20:17 +02:00
|
|
|
|
2005-12-07 23:34:11 +01:00
|
|
|
if(!quiet)
|
|
|
|
{
|
|
|
|
if(keyserver->host)
|
|
|
|
log_info(_("requesting key %s from %s server %s\n"),
|
|
|
|
keystr_from_desc(&desc[i]),
|
|
|
|
keyserver->scheme,keyserver->host);
|
|
|
|
else
|
|
|
|
log_info(_("requesting key %s from %s\n"),
|
|
|
|
keystr_from_desc(&desc[i]),keyserver->uri);
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-12-23 22:33:32 +01:00
|
|
|
case KS_GETNAME:
|
|
|
|
{
|
|
|
|
STRLIST key;
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"COMMAND GETNAME\n\n");
|
|
|
|
|
|
|
|
/* Which names do we want? */
|
|
|
|
|
|
|
|
for(key=list;key!=NULL;key=key->next)
|
|
|
|
fprintf(spawn->tochild,"%s\n",key->d);
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"\n");
|
|
|
|
|
|
|
|
if(keyserver->host)
|
|
|
|
log_info(_("searching for names from %s server %s\n"),
|
|
|
|
keyserver->scheme,keyserver->host);
|
|
|
|
else
|
|
|
|
log_info(_("searching for names from %s\n"),keyserver->uri);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case KS_SEND:
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
STRLIST key;
|
|
|
|
|
|
|
|
/* Note the extra \n here to send an empty keylist block */
|
|
|
|
fprintf(spawn->tochild,"COMMAND SEND\n\n\n");
|
|
|
|
|
|
|
|
for(key=list;key!=NULL;key=key->next)
|
|
|
|
{
|
2006-12-06 10:52:40 +01:00
|
|
|
armor_filter_context_t *afx;
|
2002-06-29 15:46:34 +02:00
|
|
|
IOBUF buffer=iobuf_temp();
|
2003-02-26 18:11:24 +01:00
|
|
|
KBNODE block;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
temp=NULL;
|
|
|
|
add_to_strlist(&temp,key->d);
|
|
|
|
|
2006-12-06 10:52:40 +01:00
|
|
|
afx = new_armor_context ();
|
|
|
|
afx->what = 1;
|
2005-01-06 17:23:47 +01:00
|
|
|
/* Tell the armor filter to use Unix-style \n line
|
|
|
|
endings, since we're going to fprintf this to a file
|
|
|
|
that (on Win32) is open in text mode. The win32 stdio
|
|
|
|
will transform the \n to \r\n and we'll end up with the
|
|
|
|
proper line endings on win32. This is a no-op on
|
|
|
|
Unix. */
|
2006-12-06 10:52:40 +01:00
|
|
|
afx->eol[0]='\n';
|
|
|
|
push_armor_filter (afx, buffer);
|
|
|
|
release_armor_context (afx);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-02-22 01:36:34 +01:00
|
|
|
/* TODO: Remove Comment: lines from keys exported this
|
|
|
|
way? */
|
2003-02-26 18:11:24 +01:00
|
|
|
|
|
|
|
if(export_pubkeys_stream(buffer,temp,&block,
|
* options.h, main.h, export.c (parse_export_options, do_export_stream),
g10.c (main): add new --export-options option. Current flags are
"include-non-rfc", "include-local-sigs", "include-attributes", and
"include-sensitive-revkeys".
* options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options,
keyserver_spawn): try passing unknown keyserver options to export options,
and if successful, use them when doing a keyserver --send-key.
* build-packet.c (build_sig_subpkt): We do not generate
SIGSUBPKT_PRIV_VERIFY_CACHE anymore.
2002-07-22 21:07:21 +02:00
|
|
|
opt.keyserver_options.export_options)==-1)
|
2002-06-29 15:46:34 +02:00
|
|
|
iobuf_close(buffer);
|
|
|
|
else
|
|
|
|
{
|
2003-02-26 18:11:24 +01:00
|
|
|
KBNODE node;
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
iobuf_flush_temp(buffer);
|
|
|
|
|
2003-02-26 18:11:24 +01:00
|
|
|
merge_keys_and_selfsig(block);
|
|
|
|
|
2004-02-22 01:36:34 +01:00
|
|
|
fprintf(spawn->tochild,"INFO %08lX%08lX BEGIN\n",
|
|
|
|
(ulong)block->pkt->pkt.public_key->keyid[0],
|
|
|
|
(ulong)block->pkt->pkt.public_key->keyid[1]);
|
2003-02-26 18:11:24 +01:00
|
|
|
|
|
|
|
for(node=block;node;node=node->next)
|
|
|
|
{
|
|
|
|
switch(node->pkt->pkttype)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case PKT_PUBLIC_KEY:
|
|
|
|
case PKT_PUBLIC_SUBKEY:
|
|
|
|
{
|
|
|
|
PKT_public_key *pk=node->pkt->pkt.public_key;
|
|
|
|
|
|
|
|
keyid_from_pk(pk,NULL);
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"%sb:%08lX%08lX:%u:%u:%u:%u:",
|
|
|
|
node->pkt->pkttype==PKT_PUBLIC_KEY?"pu":"su",
|
|
|
|
(ulong)pk->keyid[0],(ulong)pk->keyid[1],
|
|
|
|
pk->pubkey_algo,
|
|
|
|
nbits_from_pk(pk),
|
|
|
|
pk->timestamp,
|
|
|
|
pk->expiredate);
|
|
|
|
|
|
|
|
if(pk->is_revoked)
|
|
|
|
fprintf(spawn->tochild,"r");
|
|
|
|
if(pk->has_expired)
|
|
|
|
fprintf(spawn->tochild,"e");
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"\n");
|
|
|
|
}
|
2004-02-22 01:36:34 +01:00
|
|
|
break;
|
2003-02-26 18:11:24 +01:00
|
|
|
|
|
|
|
case PKT_USER_ID:
|
|
|
|
{
|
|
|
|
PKT_user_id *uid=node->pkt->pkt.user_id;
|
2003-03-04 16:24:12 +01:00
|
|
|
int r;
|
2003-02-26 18:11:24 +01:00
|
|
|
|
|
|
|
if(uid->attrib_data)
|
|
|
|
continue;
|
|
|
|
|
2003-03-04 16:24:12 +01:00
|
|
|
fprintf(spawn->tochild,"uid:");
|
|
|
|
|
|
|
|
/* Quote ':', '%', and any 8-bit
|
|
|
|
characters */
|
|
|
|
for(r=0;r<uid->len;r++)
|
|
|
|
{
|
|
|
|
if(uid->name[r]==':' || uid->name[r]=='%'
|
|
|
|
|| uid->name[r]&0x80)
|
2004-02-20 21:18:49 +01:00
|
|
|
fprintf(spawn->tochild,"%%%02X",
|
|
|
|
(byte)uid->name[r]);
|
2003-03-04 16:24:12 +01:00
|
|
|
else
|
|
|
|
fprintf(spawn->tochild,"%c",uid->name[r]);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,":%u:%u:",
|
|
|
|
uid->created,uid->expiredate);
|
2003-02-26 18:11:24 +01:00
|
|
|
|
|
|
|
if(uid->is_revoked)
|
|
|
|
fprintf(spawn->tochild,"r");
|
|
|
|
if(uid->is_expired)
|
|
|
|
fprintf(spawn->tochild,"e");
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"\n");
|
|
|
|
}
|
2004-02-22 01:36:34 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* This bit is really for the benefit of
|
|
|
|
people who store their keys in LDAP
|
|
|
|
servers. It makes it easy to do queries
|
|
|
|
for things like "all keys signed by
|
|
|
|
Isabella". */
|
|
|
|
case PKT_SIGNATURE:
|
|
|
|
{
|
|
|
|
PKT_signature *sig=node->pkt->pkt.signature;
|
|
|
|
|
|
|
|
if(!IS_UID_SIG(sig))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"sig:%08lX%08lX:%X:%u:%u\n",
|
|
|
|
(ulong)sig->keyid[0],(ulong)sig->keyid[1],
|
|
|
|
sig->sig_class,sig->timestamp,
|
|
|
|
sig->expiredate);
|
|
|
|
}
|
|
|
|
break;
|
2003-02-26 18:11:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-22 01:36:34 +01:00
|
|
|
fprintf(spawn->tochild,"INFO %08lX%08lX END\n",
|
|
|
|
(ulong)block->pkt->pkt.public_key->keyid[0],
|
|
|
|
(ulong)block->pkt->pkt.public_key->keyid[1]);
|
2003-02-26 18:11:24 +01:00
|
|
|
|
2006-10-06 07:46:07 +02:00
|
|
|
fprintf(spawn->tochild,"KEY %08lX%08lX BEGIN\n",
|
|
|
|
(ulong)block->pkt->pkt.public_key->keyid[0],
|
|
|
|
(ulong)block->pkt->pkt.public_key->keyid[1]);
|
2002-06-29 15:46:34 +02:00
|
|
|
fwrite(iobuf_get_temp_buffer(buffer),
|
|
|
|
iobuf_get_temp_length(buffer),1,spawn->tochild);
|
2006-10-06 07:46:07 +02:00
|
|
|
fprintf(spawn->tochild,"KEY %08lX%08lX END\n",
|
|
|
|
(ulong)block->pkt->pkt.public_key->keyid[0],
|
|
|
|
(ulong)block->pkt->pkt.public_key->keyid[1]);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
iobuf_close(buffer);
|
2004-08-23 21:20:17 +02:00
|
|
|
|
2004-10-11 23:08:37 +02:00
|
|
|
if(keyserver->host)
|
|
|
|
log_info(_("sending key %s to %s server %s\n"),
|
|
|
|
keystr(block->pkt->pkt.public_key->keyid),
|
|
|
|
keyserver->scheme,keyserver->host);
|
|
|
|
else
|
|
|
|
log_info(_("sending key %s to %s\n"),
|
|
|
|
keystr(block->pkt->pkt.public_key->keyid),
|
|
|
|
keyserver->uri);
|
2004-08-23 21:20:17 +02:00
|
|
|
|
2003-02-26 18:11:24 +01:00
|
|
|
release_kbnode(block);
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
free_strlist(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-12-23 22:33:32 +01:00
|
|
|
case KS_SEARCH:
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
STRLIST key;
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"COMMAND SEARCH\n\n");
|
|
|
|
|
|
|
|
/* Which keys do we want? Remember that the gpgkeys_ program
|
|
|
|
is going to lump these together into a search string. */
|
|
|
|
|
|
|
|
for(key=list;key!=NULL;key=key->next)
|
|
|
|
{
|
|
|
|
fprintf(spawn->tochild,"%s\n",key->d);
|
|
|
|
if(key!=list)
|
|
|
|
{
|
2005-07-27 20:10:56 +02:00
|
|
|
searchstr=xrealloc(searchstr,
|
2002-06-29 15:46:34 +02:00
|
|
|
strlen(searchstr)+strlen(key->d)+2);
|
|
|
|
strcat(searchstr," ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-27 20:10:56 +02:00
|
|
|
searchstr=xmalloc(strlen(key->d)+1);
|
2002-06-29 15:46:34 +02:00
|
|
|
searchstr[0]='\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat(searchstr,key->d);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"\n");
|
|
|
|
|
2004-10-11 23:08:37 +02:00
|
|
|
if(keyserver->host)
|
|
|
|
log_info(_("searching for \"%s\" from %s server %s\n"),
|
|
|
|
searchstr,keyserver->scheme,keyserver->host);
|
|
|
|
else
|
|
|
|
log_info(_("searching for \"%s\" from %s\n"),
|
|
|
|
searchstr,keyserver->uri);
|
2004-08-23 21:20:17 +02:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
log_fatal(_("no keyserver action!\n"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Done sending, so start reading. */
|
|
|
|
ret=exec_read(spawn);
|
|
|
|
if(ret)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Now handle the response */
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
2002-09-12 14:10:04 +02:00
|
|
|
int plen;
|
2002-10-14 20:50:28 +02:00
|
|
|
char *ptr;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-09-19 19:13:03 +02:00
|
|
|
maxlen=1024;
|
2002-06-29 15:46:34 +02:00
|
|
|
if(iobuf_read_line(spawn->fromchild,&line,&buflen,&maxlen)==0)
|
|
|
|
{
|
|
|
|
ret=G10ERR_READ_FILE;
|
|
|
|
goto fail; /* i.e. EOF */
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr=line;
|
|
|
|
|
2002-09-12 14:10:04 +02:00
|
|
|
/* remove trailing whitespace */
|
|
|
|
plen=strlen(ptr);
|
* parse-packet.c (parse_signature): No need to reserve 8 bytes for the
unhashed signature cache any longer.
* misc.c (pct_expando): Add two new expandos - signer's fingerprint (%g),
and signer's primary fingerprint (%p).
* Makefile.am: Include W32LIBS where appropriate.
* g10.c (main): Add --rfc2440 alias for --openpgp since in a few months,
they won't be the same thing.
* keyserver.c (parse_keyserver_uri): Accept "http" as an alias for "hkp",
since it is occasionally written that way. (keyserver_spawn): Use
ascii_isspace to avoid locale issues.
* keygen.c (ask_user_id): Make --allow-freeform-uid apply to the email
field as well as the name field, and allow mixing fields when it is set.
* options.skel: Use subkeys.pgp.net as the default keyserver.
* trustdb.c (validate_one_keyblock): Certifications on revoked or expired
uids do not count in the web of trust.
* signal.c (init_one_signal, pause_on_sigusr, do_block): Only use
sigprocmask() if we have sigset_t, and only use sigaction() if we have
struct sigaction. This is for Forte c89 on Solaris which seems to define
only the function call half of the two pairs by default.
(pause_on_sigusr): Typo. (do_block): If we can't use sigprocmask() and
sigset_t, try to get the number of signals from NSIG as well as MAXSIG,
and if we can't, fail with an explanation.
* signal.c, tdbio.c: Comment out the transaction code. It was not used in
this version, and was causing some build problems on quasi-posix platforms
(Solaris and Forte c89).
* keylist.c (list_keyblock_colon): Don't include validity values when
listing secret keys since they can be incorrect and/or misleading. This
is a temporary kludge, and will be handled properly in 1.9/2.0.
* mainproc.c (check_sig_and_print): Only show the "key available from"
preferred keyserver line if the key is not currently present.
* keyedit.c (sign_uids): Do not sign expired uids without --expert (same
behavior as revoked uids). Do not allow signing a user ID without a
self-signature. --expert overrides. Add additional prompt to the
signature level question. (menu_expire): When changing expiration dates,
don't replace selfsigs on revoked uids since this would effectively
unrevoke them. There is also no point in replacing expired selfsigs.
This is bug #181
* g10.c (add_notation_data): Make sure that only ascii is passed to
iscntrl. Noted by Christian Biere.
* getkey.c (classify_user_id2): Replaced isspace by spacep
* keygen.c (ask_user_id): Ditto. (get_parameter_algo): Ditto.
* keyedit.c (keyedit_menu): Ditto.
* tdbdump.c (import_ownertrust): Ditto. s/isxdigit/hexdigitp/.
* revoke.c (ask_revocation_reason):
* keyserver.c (keyserver_spawn): Dito.
2003-07-10 16:30:07 +02:00
|
|
|
while(plen>0 && ascii_isspace(ptr[plen-1]))
|
2002-09-12 14:10:04 +02:00
|
|
|
plen--;
|
2007-10-27 21:40:13 +02:00
|
|
|
ptr[plen]='\0';
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
if(*ptr=='\0')
|
|
|
|
break;
|
|
|
|
|
2002-09-10 10:40:12 +02:00
|
|
|
if(ascii_strncasecmp(ptr,"VERSION ",8)==0)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
gotversion=1;
|
|
|
|
|
|
|
|
if(atoi(&ptr[8])!=KEYSERVER_PROTO_VERSION)
|
|
|
|
{
|
|
|
|
log_error(_("invalid keyserver protocol (us %d!=handler %d)\n"),
|
|
|
|
KEYSERVER_PROTO_VERSION,atoi(&ptr[8]));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
2002-09-10 10:40:12 +02:00
|
|
|
else if(ascii_strncasecmp(ptr,"PROGRAM ",8)==0)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2002-09-10 10:40:12 +02:00
|
|
|
if(ascii_strncasecmp(&ptr[8],VERSION,strlen(VERSION))!=0)
|
2004-09-04 00:06:36 +02:00
|
|
|
log_info(_("WARNING: keyserver handler from a different"
|
|
|
|
" version of GnuPG (%s)\n"),&ptr[8]);
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
2002-09-10 10:40:12 +02:00
|
|
|
else if(ascii_strncasecmp(ptr,"OPTION OUTOFBAND",16)==0)
|
2002-06-29 15:46:34 +02:00
|
|
|
outofband=1; /* Currently the only OPTION */
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!gotversion)
|
|
|
|
{
|
|
|
|
log_error(_("keyserver did not send VERSION\n"));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!outofband)
|
|
|
|
switch(action)
|
|
|
|
{
|
2005-12-23 22:33:32 +01:00
|
|
|
case KS_GET:
|
|
|
|
case KS_GETNAME:
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
void *stats_handle;
|
|
|
|
|
|
|
|
stats_handle=import_new_stats_handle();
|
|
|
|
|
2002-09-19 19:13:03 +02:00
|
|
|
/* Slurp up all the key data. In the future, it might be
|
|
|
|
nice to look for KEY foo OUTOFBAND and FAILED indicators.
|
|
|
|
It's harmless to ignore them, but ignoring them does make
|
|
|
|
gpg complain about "no valid OpenPGP data found". One
|
|
|
|
way to do this could be to continue parsing this
|
|
|
|
line-by-line and make a temp iobuf for each key. */
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2006-03-14 03:42:02 +01:00
|
|
|
import_keys_stream(spawn->fromchild,stats_handle,fpr,fpr_len,
|
* main.h, import.c (parse_import_options, fix_hkp_corruption, import_one,
delete_inv_parts), g10.c (main): New import-option
"repair-hkp-subkey-bug", which repairs as much as possible the HKP
mangling multiple subkeys bug. It is on by default for keyserver
receives, and off by default for regular --import.
* main.h, import.c (import, import_one, delete_inv_parts), hkp.c
(hkp_ask_import), keyserver.c (keyserver_spawn): Use keyserver import
options when doing keyserver receives.
2002-07-24 23:17:19 +02:00
|
|
|
opt.keyserver_options.import_options);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
import_print_stats(stats_handle);
|
|
|
|
import_release_stats_handle(stats_handle);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nothing to do here */
|
2005-12-23 22:33:32 +01:00
|
|
|
case KS_SEND:
|
2002-06-29 15:46:34 +02:00
|
|
|
break;
|
|
|
|
|
2005-12-23 22:33:32 +01:00
|
|
|
case KS_SEARCH:
|
2004-08-23 21:20:17 +02:00
|
|
|
keyserver_search_prompt(spawn->fromchild,searchstr);
|
|
|
|
break;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
log_fatal(_("no keyserver action!\n"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
2005-07-19 10:50:28 +02:00
|
|
|
xfree(line);
|
|
|
|
xfree(searchstr);
|
|
|
|
|
2002-09-19 19:13:03 +02:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
*prog=exec_finish(spawn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-12-23 22:33:32 +01:00
|
|
|
keyserver_work(enum ks_action action,STRLIST list,KEYDB_SEARCH_DESC *desc,
|
2006-03-14 03:42:02 +01:00
|
|
|
int count,unsigned char **fpr,size_t *fpr_len,
|
|
|
|
struct keyserver_spec *keyserver)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
int rc=0,ret=0;
|
|
|
|
|
2004-05-20 22:42:01 +02:00
|
|
|
if(!keyserver)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
log_error(_("no keyserver known (use option --keyserver)\n"));
|
|
|
|
return G10ERR_BAD_URI;
|
|
|
|
}
|
|
|
|
|
2002-07-04 18:06:38 +02:00
|
|
|
#ifdef DISABLE_KEYSERVER_HELPERS
|
2002-09-12 14:45:58 +02:00
|
|
|
|
2002-07-04 18:06:38 +02:00
|
|
|
log_error(_("external keyserver calls are not supported in this build\n"));
|
|
|
|
return G10ERR_KEYSERVER;
|
|
|
|
|
2002-09-12 14:45:58 +02:00
|
|
|
#else
|
|
|
|
/* Spawn a handler */
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2006-03-14 03:42:02 +01:00
|
|
|
rc=keyserver_spawn(action,list,desc,count,&ret,fpr,fpr_len,keyserver);
|
2002-06-29 15:46:34 +02:00
|
|
|
if(ret)
|
|
|
|
{
|
|
|
|
switch(ret)
|
|
|
|
{
|
|
|
|
case KEYSERVER_SCHEME_NOT_FOUND:
|
2004-09-04 00:06:36 +02:00
|
|
|
log_error(_("no handler for keyserver scheme `%s'\n"),
|
2004-05-22 05:50:20 +02:00
|
|
|
keyserver->scheme);
|
2002-06-29 15:46:34 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYSERVER_NOT_SUPPORTED:
|
2004-09-04 00:06:36 +02:00
|
|
|
log_error(_("action `%s' not supported with keyserver "
|
|
|
|
"scheme `%s'\n"),
|
2005-12-23 22:33:32 +01:00
|
|
|
action==KS_GET?"get":action==KS_SEND?"send":
|
|
|
|
action==KS_SEARCH?"search":"unknown",
|
2004-05-22 05:50:20 +02:00
|
|
|
keyserver->scheme);
|
2002-10-14 20:50:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYSERVER_VERSION_ERROR:
|
2005-03-31 05:58:53 +02:00
|
|
|
log_error(_(GPGKEYS_PREFIX "%s does not support"
|
|
|
|
" handler version %d\n"),
|
2004-12-22 18:49:44 +01:00
|
|
|
keyserver_typemap(keyserver->scheme),
|
|
|
|
KEYSERVER_PROTO_VERSION);
|
2002-10-14 20:50:28 +02:00
|
|
|
break;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-10-13 20:40:13 +02:00
|
|
|
case KEYSERVER_TIMEOUT:
|
|
|
|
log_error(_("keyserver timed out\n"));
|
|
|
|
break;
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
case KEYSERVER_INTERNAL_ERROR:
|
|
|
|
default:
|
|
|
|
log_error(_("keyserver internal error\n"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return G10ERR_KEYSERVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
log_error(_("keyserver communications error: %s\n"),g10_errstr(rc));
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2002-09-10 10:40:12 +02:00
|
|
|
#endif /* ! DISABLE_KEYSERVER_HELPERS*/
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
keyserver_export(STRLIST users)
|
|
|
|
{
|
2004-02-20 21:18:49 +01:00
|
|
|
STRLIST sl=NULL;
|
|
|
|
KEYDB_SEARCH_DESC desc;
|
|
|
|
int rc=0;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-02-20 21:18:49 +01:00
|
|
|
/* Weed out descriptors that we don't support sending */
|
|
|
|
for(;users;users=users->next)
|
|
|
|
{
|
|
|
|
classify_user_id (users->d, &desc);
|
|
|
|
if(desc.mode!=KEYDB_SEARCH_MODE_SHORT_KID &&
|
|
|
|
desc.mode!=KEYDB_SEARCH_MODE_LONG_KID &&
|
|
|
|
desc.mode!=KEYDB_SEARCH_MODE_FPR16 &&
|
|
|
|
desc.mode!=KEYDB_SEARCH_MODE_FPR20)
|
|
|
|
{
|
|
|
|
log_error(_("\"%s\" not a key ID: skipping\n"),users->d);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
append_to_strlist(&sl,users->d);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sl)
|
|
|
|
{
|
2006-03-14 03:42:02 +01:00
|
|
|
rc=keyserver_work(KS_SEND,sl,NULL,0,NULL,NULL,opt.keyserver);
|
2004-02-20 21:18:49 +01:00
|
|
|
free_strlist(sl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
keyserver_import(STRLIST users)
|
|
|
|
{
|
|
|
|
KEYDB_SEARCH_DESC *desc;
|
|
|
|
int num=100,count=0;
|
|
|
|
int rc=0;
|
|
|
|
|
|
|
|
/* Build a list of key ids */
|
2005-07-27 20:10:56 +02:00
|
|
|
desc=xmalloc(sizeof(KEYDB_SEARCH_DESC)*num);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
for(;users;users=users->next)
|
|
|
|
{
|
|
|
|
classify_user_id (users->d, &desc[count]);
|
|
|
|
if(desc[count].mode!=KEYDB_SEARCH_MODE_SHORT_KID &&
|
|
|
|
desc[count].mode!=KEYDB_SEARCH_MODE_LONG_KID &&
|
|
|
|
desc[count].mode!=KEYDB_SEARCH_MODE_FPR16 &&
|
|
|
|
desc[count].mode!=KEYDB_SEARCH_MODE_FPR20)
|
|
|
|
{
|
2004-02-20 21:18:49 +01:00
|
|
|
log_error(_("\"%s\" not a key ID: skipping\n"),users->d);
|
2002-06-29 15:46:34 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
if(count==num)
|
|
|
|
{
|
|
|
|
num+=100;
|
2005-07-27 20:10:56 +02:00
|
|
|
desc=xrealloc(desc,sizeof(KEYDB_SEARCH_DESC)*num);
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count>0)
|
2006-03-14 03:42:02 +01:00
|
|
|
rc=keyserver_work(KS_GET,NULL,desc,count,NULL,NULL,opt.keyserver);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(desc);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-09-11 17:42:19 +02:00
|
|
|
keyserver_import_fprint(const byte *fprint,size_t fprint_len,
|
|
|
|
struct keyserver_spec *keyserver)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
KEYDB_SEARCH_DESC desc;
|
|
|
|
|
|
|
|
memset(&desc,0,sizeof(desc));
|
|
|
|
|
|
|
|
if(fprint_len==16)
|
|
|
|
desc.mode=KEYDB_SEARCH_MODE_FPR16;
|
|
|
|
else if(fprint_len==20)
|
|
|
|
desc.mode=KEYDB_SEARCH_MODE_FPR20;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memcpy(desc.u.fpr,fprint,fprint_len);
|
|
|
|
|
2006-03-14 03:42:02 +01:00
|
|
|
/* TODO: Warn here if the fingerprint we got doesn't match the one
|
|
|
|
we asked for? */
|
|
|
|
return keyserver_work(KS_GET,NULL,&desc,1,NULL,NULL,keyserver);
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-05-22 05:50:20 +02:00
|
|
|
keyserver_import_keyid(u32 *keyid,struct keyserver_spec *keyserver)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
KEYDB_SEARCH_DESC desc;
|
|
|
|
|
|
|
|
memset(&desc,0,sizeof(desc));
|
|
|
|
|
|
|
|
desc.mode=KEYDB_SEARCH_MODE_LONG_KID;
|
|
|
|
desc.u.kid[0]=keyid[0];
|
|
|
|
desc.u.kid[1]=keyid[1];
|
|
|
|
|
2006-03-14 03:42:02 +01:00
|
|
|
return keyserver_work(KS_GET,NULL,&desc,1,NULL,NULL,keyserver);
|
2004-04-19 18:02:11 +02:00
|
|
|
}
|
|
|
|
|
2004-05-21 19:32:30 +02:00
|
|
|
/* code mostly stolen from do_export_stream */
|
2002-06-29 15:46:34 +02:00
|
|
|
static int
|
|
|
|
keyidlist(STRLIST users,KEYDB_SEARCH_DESC **klist,int *count,int fakev3)
|
|
|
|
{
|
2004-05-21 19:32:30 +02:00
|
|
|
int rc=0,ndesc,num=100;
|
2002-06-29 15:46:34 +02:00
|
|
|
KBNODE keyblock=NULL,node;
|
2004-05-21 19:32:30 +02:00
|
|
|
KEYDB_HANDLE kdbhd;
|
|
|
|
KEYDB_SEARCH_DESC *desc;
|
|
|
|
STRLIST sl;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
*count=0;
|
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
*klist=xmalloc(sizeof(KEYDB_SEARCH_DESC)*num);
|
2004-05-21 19:32:30 +02:00
|
|
|
|
|
|
|
kdbhd=keydb_new(0);
|
|
|
|
|
|
|
|
if(!users)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2004-05-21 19:32:30 +02:00
|
|
|
ndesc = 1;
|
2005-07-27 20:10:56 +02:00
|
|
|
desc = xmalloc_clear ( ndesc * sizeof *desc);
|
2004-05-21 19:32:30 +02:00
|
|
|
desc[0].mode = KEYDB_SEARCH_MODE_FIRST;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (ndesc=0, sl=users; sl; sl = sl->next, ndesc++)
|
|
|
|
;
|
2005-07-27 20:10:56 +02:00
|
|
|
desc = xmalloc ( ndesc * sizeof *desc);
|
2004-05-21 19:32:30 +02:00
|
|
|
|
|
|
|
for (ndesc=0, sl=users; sl; sl = sl->next)
|
|
|
|
{
|
|
|
|
if(classify_user_id (sl->d, desc+ndesc))
|
|
|
|
ndesc++;
|
|
|
|
else
|
2004-09-04 00:06:36 +02:00
|
|
|
log_error (_("key \"%s\" not found: %s\n"),
|
2004-05-21 19:32:30 +02:00
|
|
|
sl->d, g10_errstr (G10ERR_INV_USER_ID));
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
2004-04-19 18:02:11 +02:00
|
|
|
|
2004-05-21 19:32:30 +02:00
|
|
|
while (!(rc = keydb_search (kdbhd, desc, ndesc)))
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2004-05-21 19:32:30 +02:00
|
|
|
if (!users)
|
|
|
|
desc[0].mode = KEYDB_SEARCH_MODE_NEXT;
|
|
|
|
|
|
|
|
/* read the keyblock */
|
|
|
|
rc = keydb_get_keyblock (kdbhd, &keyblock );
|
|
|
|
if( rc )
|
|
|
|
{
|
|
|
|
log_error (_("error reading keyblock: %s\n"), g10_errstr(rc) );
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
2004-04-19 18:02:11 +02:00
|
|
|
if((node=find_kbnode(keyblock,PKT_PUBLIC_KEY)))
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
2004-05-21 19:32:30 +02:00
|
|
|
/* This is to work around a bug in some keyservers (pksd and
|
|
|
|
OKS) that calculate v4 RSA keyids as if they were v3 RSA.
|
|
|
|
The answer is to refresh both the correct v4 keyid
|
|
|
|
(e.g. 99242560) and the fake v3 keyid (e.g. 68FDDBC7).
|
|
|
|
This only happens for key refresh using the HKP scheme
|
|
|
|
and if the refresh-add-fake-v3-keyids keyserver option is
|
|
|
|
set. */
|
|
|
|
if(fakev3 && is_RSA(node->pkt->pkt.public_key->pubkey_algo) &&
|
|
|
|
node->pkt->pkt.public_key->version>=4)
|
|
|
|
{
|
|
|
|
(*klist)[*count].mode=KEYDB_SEARCH_MODE_LONG_KID;
|
|
|
|
mpi_get_keyid(node->pkt->pkt.public_key->pkey[0],
|
|
|
|
(*klist)[*count].u.kid);
|
|
|
|
(*count)++;
|
|
|
|
|
|
|
|
if(*count==num)
|
|
|
|
{
|
|
|
|
num+=100;
|
2005-07-27 20:10:56 +02:00
|
|
|
*klist=xrealloc(*klist,sizeof(KEYDB_SEARCH_DESC)*num);
|
2004-05-21 19:32:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* v4 keys get full fingerprints. v3 keys get long keyids.
|
|
|
|
This is because it's easy to calculate any sort of keyid
|
|
|
|
from a v4 fingerprint, but not a v3 fingerprint. */
|
|
|
|
|
|
|
|
if(node->pkt->pkt.public_key->version<4)
|
|
|
|
{
|
|
|
|
(*klist)[*count].mode=KEYDB_SEARCH_MODE_LONG_KID;
|
|
|
|
keyid_from_pk(node->pkt->pkt.public_key,
|
|
|
|
(*klist)[*count].u.kid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t dummy;
|
|
|
|
|
|
|
|
(*klist)[*count].mode=KEYDB_SEARCH_MODE_FPR20;
|
|
|
|
fingerprint_from_pk(node->pkt->pkt.public_key,
|
|
|
|
(*klist)[*count].u.fpr,&dummy);
|
|
|
|
}
|
|
|
|
|
2004-08-23 16:39:48 +02:00
|
|
|
/* This is a little hackish, using the skipfncvalue as a
|
|
|
|
void* pointer to the keyserver spec, but we don't need
|
|
|
|
the skipfnc here, and it saves having an additional field
|
|
|
|
for this (which would be wasted space most of the
|
|
|
|
time). */
|
|
|
|
|
2004-05-21 19:32:30 +02:00
|
|
|
(*klist)[*count].skipfncvalue=NULL;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-05-21 19:32:30 +02:00
|
|
|
/* Are we honoring preferred keyservers? */
|
2004-04-19 18:02:11 +02:00
|
|
|
if(opt.keyserver_options.options&KEYSERVER_HONOR_KEYSERVER_URL)
|
|
|
|
{
|
|
|
|
PKT_user_id *uid=NULL;
|
|
|
|
PKT_signature *sig=NULL;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-05-21 19:32:30 +02:00
|
|
|
merge_keys_and_selfsig(keyblock);
|
|
|
|
|
2004-04-19 18:02:11 +02:00
|
|
|
for(node=node->next;node;node=node->next)
|
|
|
|
{
|
|
|
|
if(node->pkt->pkttype==PKT_USER_ID
|
|
|
|
&& node->pkt->pkt.user_id->is_primary)
|
|
|
|
uid=node->pkt->pkt.user_id;
|
|
|
|
else if(node->pkt->pkttype==PKT_SIGNATURE
|
|
|
|
&& node->pkt->pkt.signature->
|
|
|
|
flags.chosen_selfsig && uid)
|
|
|
|
{
|
|
|
|
sig=node->pkt->pkt.signature;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-22 05:50:20 +02:00
|
|
|
/* Try and parse the keyserver URL. If it doesn't work,
|
|
|
|
then we end up writing NULL which indicates we are
|
|
|
|
the same as any other key. */
|
2006-02-22 21:20:58 +01:00
|
|
|
if(sig)
|
2004-05-22 05:50:20 +02:00
|
|
|
(*klist)[*count].skipfncvalue=parse_preferred_keyserver(sig);
|
2004-04-19 18:02:11 +02:00
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
(*count)++;
|
|
|
|
|
|
|
|
if(*count==num)
|
|
|
|
{
|
|
|
|
num+=100;
|
2005-07-27 20:10:56 +02:00
|
|
|
*klist=xrealloc(*klist,sizeof(KEYDB_SEARCH_DESC)*num);
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
}
|
2004-04-19 18:02:11 +02:00
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-05-21 19:32:30 +02:00
|
|
|
if(rc==-1)
|
|
|
|
rc=0;
|
|
|
|
|
|
|
|
leave:
|
|
|
|
if(rc)
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(*klist);
|
|
|
|
xfree(desc);
|
2004-05-21 19:32:30 +02:00
|
|
|
keydb_release(kdbhd);
|
|
|
|
release_kbnode(keyblock);
|
|
|
|
|
|
|
|
return rc;
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note this is different than the original HKP refresh. It allows
|
|
|
|
usernames to refresh only part of the keyring. */
|
|
|
|
|
2005-12-07 23:34:11 +01:00
|
|
|
int
|
2002-06-29 15:46:34 +02:00
|
|
|
keyserver_refresh(STRLIST users)
|
|
|
|
{
|
2004-05-26 17:01:48 +02:00
|
|
|
int rc,count,numdesc,fakev3=0;
|
2002-06-29 15:46:34 +02:00
|
|
|
KEYDB_SEARCH_DESC *desc;
|
2005-02-06 18:38:43 +01:00
|
|
|
unsigned int options=opt.keyserver_options.import_options;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2005-02-06 18:38:43 +01:00
|
|
|
/* We switch merge-only on during a refresh, as 'refresh' should
|
|
|
|
never import new keys, even if their keyids match. */
|
|
|
|
opt.keyserver_options.import_options|=IMPORT_MERGE_ONLY;
|
|
|
|
|
|
|
|
/* Similarly, we switch on fast-import, since refresh may make
|
|
|
|
multiple import sets (due to preferred keyserver URLs). We don't
|
|
|
|
want each set to rebuild the trustdb. Instead we do it once at
|
|
|
|
the end here. */
|
|
|
|
opt.keyserver_options.import_options|=IMPORT_FAST;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
/* If refresh_add_fake_v3_keyids is on and it's a HKP or MAILTO
|
|
|
|
scheme, then enable fake v3 keyid generation. */
|
2004-04-15 20:16:17 +02:00
|
|
|
if((opt.keyserver_options.options&KEYSERVER_ADD_FAKE_V3) && opt.keyserver
|
2004-04-14 23:33:45 +02:00
|
|
|
&& (ascii_strcasecmp(opt.keyserver->scheme,"hkp")==0 ||
|
|
|
|
ascii_strcasecmp(opt.keyserver->scheme,"mailto")==0))
|
2002-06-29 15:46:34 +02:00
|
|
|
fakev3=1;
|
|
|
|
|
2004-05-26 17:01:48 +02:00
|
|
|
rc=keyidlist(users,&desc,&numdesc,fakev3);
|
2002-06-29 15:46:34 +02:00
|
|
|
if(rc)
|
|
|
|
return rc;
|
|
|
|
|
2004-05-26 17:01:48 +02:00
|
|
|
count=numdesc;
|
2002-06-29 15:46:34 +02:00
|
|
|
if(count>0)
|
2002-12-28 00:46:51 +01:00
|
|
|
{
|
2004-05-21 19:32:30 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Try to handle preferred keyserver keys first */
|
2006-01-07 22:04:13 +01:00
|
|
|
for(i=0;i<numdesc;i++)
|
2004-05-21 19:32:30 +02:00
|
|
|
{
|
|
|
|
if(desc[i].skipfncvalue)
|
|
|
|
{
|
|
|
|
struct keyserver_spec *keyserver=desc[i].skipfncvalue;
|
|
|
|
|
|
|
|
/* We use the keyserver structure we parsed out before.
|
|
|
|
Note that a preferred keyserver without a scheme://
|
|
|
|
will be interpreted as hkp:// */
|
|
|
|
|
2006-03-14 03:42:02 +01:00
|
|
|
rc=keyserver_work(KS_GET,NULL,&desc[i],1,NULL,NULL,keyserver);
|
2004-05-21 19:32:30 +02:00
|
|
|
if(rc)
|
|
|
|
log_info(_("WARNING: unable to refresh key %s"
|
|
|
|
" via %s: %s\n"),keystr_from_desc(&desc[i]),
|
|
|
|
keyserver->uri,g10_errstr(rc));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We got it, so mark it as NONE so we don't try and
|
|
|
|
get it again from the regular keyserver. */
|
|
|
|
|
|
|
|
desc[i].mode=KEYDB_SEARCH_MODE_NONE;
|
2004-05-26 17:01:48 +02:00
|
|
|
count--;
|
2004-05-21 19:32:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
free_keyserver_spec(keyserver);
|
|
|
|
}
|
|
|
|
}
|
2004-05-26 17:01:48 +02:00
|
|
|
}
|
2004-05-21 19:32:30 +02:00
|
|
|
|
2004-05-26 17:01:48 +02:00
|
|
|
if(count>0)
|
|
|
|
{
|
2004-04-14 23:33:45 +02:00
|
|
|
if(opt.keyserver)
|
2002-12-28 00:46:51 +01:00
|
|
|
{
|
|
|
|
if(count==1)
|
2004-04-14 23:33:45 +02:00
|
|
|
log_info(_("refreshing 1 key from %s\n"),opt.keyserver->uri);
|
2002-12-28 00:46:51 +01:00
|
|
|
else
|
|
|
|
log_info(_("refreshing %d keys from %s\n"),
|
2004-04-14 23:33:45 +02:00
|
|
|
count,opt.keyserver->uri);
|
2002-12-28 00:46:51 +01:00
|
|
|
}
|
|
|
|
|
2006-03-14 03:42:02 +01:00
|
|
|
rc=keyserver_work(KS_GET,NULL,desc,numdesc,NULL,NULL,opt.keyserver);
|
2002-12-28 00:46:51 +01:00
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(desc);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2005-02-06 18:38:43 +01:00
|
|
|
opt.keyserver_options.import_options=options;
|
|
|
|
|
|
|
|
/* If the original options didn't have fast import, and the trustdb
|
|
|
|
is dirty, rebuild. */
|
|
|
|
if(!(opt.keyserver_options.import_options&IMPORT_FAST))
|
|
|
|
trustdb_check_or_update();
|
|
|
|
|
2002-12-28 00:46:51 +01:00
|
|
|
return rc;
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
2002-08-20 14:45:57 +02:00
|
|
|
int
|
2002-06-29 15:46:34 +02:00
|
|
|
keyserver_search(STRLIST tokens)
|
|
|
|
{
|
|
|
|
if(tokens)
|
2006-03-14 03:42:02 +01:00
|
|
|
return keyserver_work(KS_SEARCH,tokens,NULL,0,NULL,NULL,opt.keyserver);
|
2002-06-29 15:46:34 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2005-12-07 23:34:11 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
keyserver_fetch(STRLIST urilist)
|
|
|
|
{
|
|
|
|
KEYDB_SEARCH_DESC desc;
|
|
|
|
STRLIST sl;
|
2005-12-08 16:37:26 +01:00
|
|
|
unsigned int options=opt.keyserver_options.import_options;
|
|
|
|
|
|
|
|
/* Switch on fast-import, since fetch can handle more than one
|
|
|
|
import and we don't want each set to rebuild the trustdb.
|
|
|
|
Instead we do it once at the end. */
|
|
|
|
opt.keyserver_options.import_options|=IMPORT_FAST;
|
2005-12-07 23:34:11 +01:00
|
|
|
|
|
|
|
/* A dummy desc since we're not actually fetching a particular key
|
|
|
|
ID */
|
|
|
|
memset(&desc,0,sizeof(desc));
|
|
|
|
desc.mode=KEYDB_SEARCH_MODE_EXACT;
|
|
|
|
|
|
|
|
for(sl=urilist;sl;sl=sl->next)
|
|
|
|
{
|
|
|
|
struct keyserver_spec *spec;
|
|
|
|
|
|
|
|
spec=parse_keyserver_uri(sl->d,1,NULL,0);
|
|
|
|
if(spec)
|
|
|
|
{
|
2005-12-08 06:52:41 +01:00
|
|
|
int rc;
|
|
|
|
|
2006-03-14 03:42:02 +01:00
|
|
|
rc=keyserver_work(KS_GET,NULL,&desc,1,NULL,NULL,spec);
|
2005-12-07 23:34:11 +01:00
|
|
|
if(rc)
|
2005-12-08 08:42:41 +01:00
|
|
|
log_info (_("WARNING: unable to fetch URI %s: %s\n"),
|
2005-12-07 23:34:11 +01:00
|
|
|
sl->d,g10_errstr(rc));
|
2005-12-08 06:52:41 +01:00
|
|
|
|
2005-12-07 23:34:11 +01:00
|
|
|
free_keyserver_spec(spec);
|
|
|
|
}
|
|
|
|
else
|
2005-12-08 08:42:41 +01:00
|
|
|
log_info (_("WARNING: unable to parse URI %s\n"),sl->d);
|
2005-12-07 23:34:11 +01:00
|
|
|
}
|
|
|
|
|
2005-12-08 16:37:26 +01:00
|
|
|
opt.keyserver_options.import_options=options;
|
|
|
|
|
|
|
|
/* If the original options didn't have fast import, and the trustdb
|
|
|
|
is dirty, rebuild. */
|
|
|
|
if(!(opt.keyserver_options.import_options&IMPORT_FAST))
|
|
|
|
trustdb_check_or_update();
|
|
|
|
|
2005-12-07 23:34:11 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2005-12-23 22:33:32 +01:00
|
|
|
|
2005-12-23 23:17:11 +01:00
|
|
|
/* Import key in a CERT or pointed to by a CERT */
|
|
|
|
int
|
2006-03-14 03:42:02 +01:00
|
|
|
keyserver_import_cert(const char *name,unsigned char **fpr,size_t *fpr_len)
|
2005-12-23 23:17:11 +01:00
|
|
|
{
|
|
|
|
char *domain,*look,*url;
|
|
|
|
IOBUF key;
|
2006-03-17 06:20:13 +01:00
|
|
|
int type,rc=G10ERR_GENERAL;
|
2005-12-23 23:17:11 +01:00
|
|
|
|
|
|
|
look=xstrdup(name);
|
|
|
|
|
|
|
|
domain=strrchr(look,'@');
|
|
|
|
if(domain)
|
|
|
|
*domain='.';
|
|
|
|
|
2006-03-17 06:20:13 +01:00
|
|
|
type=get_cert(look,max_cert_size,&key,fpr,fpr_len,&url);
|
2005-12-23 23:17:11 +01:00
|
|
|
if(type==1)
|
|
|
|
{
|
|
|
|
int armor_status=opt.no_armor;
|
|
|
|
|
|
|
|
/* CERTs are always in binary format */
|
|
|
|
opt.no_armor=1;
|
|
|
|
|
2006-03-14 03:42:02 +01:00
|
|
|
rc=import_keys_stream(key,NULL,fpr,fpr_len,
|
2006-03-14 03:23:00 +01:00
|
|
|
opt.keyserver_options.import_options);
|
2005-12-23 23:17:11 +01:00
|
|
|
|
|
|
|
opt.no_armor=armor_status;
|
|
|
|
|
|
|
|
iobuf_close(key);
|
|
|
|
}
|
2006-03-17 06:20:13 +01:00
|
|
|
else if(type==2 && *fpr)
|
2005-12-23 23:17:11 +01:00
|
|
|
{
|
2006-03-17 06:20:13 +01:00
|
|
|
/* We only consider the IPGP type if a fingerprint was provided.
|
|
|
|
This lets us select the right key regardless of what a URL
|
|
|
|
points to, or get the key from a keyserver. */
|
|
|
|
if(url)
|
2005-12-23 23:17:11 +01:00
|
|
|
{
|
2006-03-17 06:20:13 +01:00
|
|
|
struct keyserver_spec *spec;
|
2005-12-23 23:17:11 +01:00
|
|
|
|
2006-03-17 06:20:13 +01:00
|
|
|
spec=parse_keyserver_uri(url,1,NULL,0);
|
|
|
|
if(spec)
|
|
|
|
{
|
|
|
|
STRLIST list=NULL;
|
2005-12-23 23:17:11 +01:00
|
|
|
|
2006-03-17 06:20:13 +01:00
|
|
|
add_to_strlist(&list,url);
|
2005-12-23 23:17:11 +01:00
|
|
|
|
2006-03-17 06:20:13 +01:00
|
|
|
rc=keyserver_fetch(list);
|
|
|
|
|
|
|
|
free_strlist(list);
|
|
|
|
free_keyserver_spec(spec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(opt.keyserver)
|
|
|
|
{
|
|
|
|
/* If only a fingerprint is provided, try and fetch it from
|
|
|
|
our --keyserver */
|
|
|
|
|
|
|
|
rc=keyserver_import_fprint(*fpr,*fpr_len,opt.keyserver);
|
2005-12-23 23:17:11 +01:00
|
|
|
}
|
2006-04-27 05:38:56 +02:00
|
|
|
else
|
|
|
|
log_info(_("no keyserver known (use option --keyserver)\n"));
|
|
|
|
|
|
|
|
/* Give a better string here? "CERT fingerprint for \"%s\"
|
|
|
|
found, but no keyserver" " known (use option
|
|
|
|
--keyserver)\n" ? */
|
2005-12-23 23:17:11 +01:00
|
|
|
|
|
|
|
xfree(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
xfree(look);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2006-02-22 21:20:58 +01:00
|
|
|
/* Import key pointed to by a PKA record. Return the requested
|
|
|
|
fingerprint in fpr. */
|
2005-12-23 23:17:11 +01:00
|
|
|
int
|
2006-03-14 04:16:21 +01:00
|
|
|
keyserver_import_pka(const char *name,unsigned char **fpr,size_t *fpr_len)
|
2005-12-23 23:17:11 +01:00
|
|
|
{
|
|
|
|
char *uri;
|
|
|
|
int rc=-1;
|
2006-02-21 23:23:35 +01:00
|
|
|
|
2006-03-14 04:16:21 +01:00
|
|
|
*fpr=xmalloc(20);
|
|
|
|
*fpr_len=20;
|
|
|
|
|
|
|
|
uri = get_pka_info (name, *fpr);
|
2005-12-23 23:17:11 +01:00
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
struct keyserver_spec *spec;
|
2006-01-01 19:12:57 +01:00
|
|
|
spec = parse_keyserver_uri (uri, 1, NULL, 0);
|
2005-12-23 23:17:11 +01:00
|
|
|
if (spec)
|
|
|
|
{
|
2006-03-14 04:16:21 +01:00
|
|
|
rc=keyserver_import_fprint (*fpr, 20, spec);
|
2005-12-23 23:17:11 +01:00
|
|
|
free_keyserver_spec (spec);
|
|
|
|
}
|
|
|
|
xfree (uri);
|
|
|
|
}
|
|
|
|
|
2006-03-14 04:16:21 +01:00
|
|
|
if(rc!=0)
|
|
|
|
xfree(*fpr);
|
|
|
|
|
2005-12-23 23:17:11 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Import all keys that match name */
|
2005-12-23 22:33:32 +01:00
|
|
|
int
|
2006-03-14 03:42:02 +01:00
|
|
|
keyserver_import_name(const char *name,unsigned char **fpr,size_t *fpr_len,
|
|
|
|
struct keyserver_spec *keyserver)
|
2005-12-23 22:33:32 +01:00
|
|
|
{
|
|
|
|
STRLIST list=NULL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
append_to_strlist(&list,name);
|
|
|
|
|
2006-03-14 03:42:02 +01:00
|
|
|
rc=keyserver_work(KS_GETNAME,list,NULL,0,fpr,fpr_len,keyserver);
|
2005-12-23 22:33:32 +01:00
|
|
|
|
|
|
|
free_strlist(list);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2006-02-21 17:09:09 +01:00
|
|
|
|
|
|
|
/* Use the PGP Universal trick of asking ldap://keys.(maildomain) for
|
|
|
|
the key. */
|
|
|
|
int
|
2006-03-14 03:42:02 +01:00
|
|
|
keyserver_import_ldap(const char *name,unsigned char **fpr,size_t *fpr_len)
|
2006-02-21 17:09:09 +01:00
|
|
|
{
|
|
|
|
char *domain;
|
|
|
|
struct keyserver_spec *keyserver;
|
|
|
|
STRLIST list=NULL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
append_to_strlist(&list,name);
|
|
|
|
|
|
|
|
/* Parse out the domain */
|
|
|
|
domain=strrchr(name,'@');
|
|
|
|
if(!domain)
|
|
|
|
return G10ERR_GENERAL;
|
|
|
|
|
|
|
|
domain++;
|
|
|
|
|
|
|
|
keyserver=xmalloc_clear(sizeof(struct keyserver_spec));
|
|
|
|
|
|
|
|
keyserver->scheme=xstrdup("ldap");
|
|
|
|
keyserver->host=xmalloc(5+strlen(domain)+1);
|
|
|
|
strcpy(keyserver->host,"keys.");
|
|
|
|
strcat(keyserver->host,domain);
|
2006-02-22 21:20:58 +01:00
|
|
|
keyserver->uri=xmalloc(strlen(keyserver->scheme)+
|
|
|
|
3+strlen(keyserver->host)+1);
|
|
|
|
strcpy(keyserver->uri,keyserver->scheme);
|
|
|
|
strcat(keyserver->uri,"://");
|
|
|
|
strcat(keyserver->uri,keyserver->host);
|
2006-02-21 17:09:09 +01:00
|
|
|
|
2006-03-14 03:42:02 +01:00
|
|
|
rc=keyserver_work(KS_GETNAME,list,NULL,0,fpr,fpr_len,keyserver);
|
2006-02-21 17:09:09 +01:00
|
|
|
|
|
|
|
free_strlist(list);
|
|
|
|
|
|
|
|
free_keyserver_spec(keyserver);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|