* keybox-blob.c (x509_email_kludge): New.

(_keybox_create_x509_blob): Insert an extra email address if the
subject's DN has an email part.
* keybox-defs.h: Added the xtoi_2 and digitp macros.
This commit is contained in:
Werner Koch 2001-12-14 20:48:07 +00:00
parent 6d27c940b2
commit 134d401a4e
4 changed files with 52 additions and 19 deletions

View File

@ -1,3 +1,10 @@
2001-12-14 Werner Koch <wk@gnupg.org>
* keybox-blob.c (x509_email_kludge): New.
(_keybox_create_x509_blob): Insert an extra email address if the
subject's DN has an email part.
* keybox-defs.h: Added the xtoi_2 and digitp macros.
2001-12-13 Werner Koch <wk@gnupg.org>
* keybox-search.c (blob_cmp_name): Kludge to allow searching for

View File

@ -773,21 +773,29 @@ _keybox_create_pgp_blob (KEYBOXBLOB *r_blob, KBNODE keyblock)
static char *
x509_email_kludge (const char *name)
{
#if 0
if (!strncmp (name, "1.2.840.113549.1.9.1=#", 22)
&& hexdigitp (name+22) && hexdigitp (name+23))
{ /* this looks pretty much like an email address in the
subjects DN we use this to add an additional user ID
entry. This way, openSSL generated keys get a nicer and
usable listing */
char *buf = NULL;
/* FIXME */
const unsigned char *p;
unsigned char *buf;
int n;
return buf;
}
#endif
return NULL;
if (strncmp (name, "1.2.840.113549.1.9.1=#", 22))
return NULL;
/* This looks pretty much like an email address in the subject's DN
we use this to add an additional user ID entry. This way,
openSSL generated keys get a nicer and usable listing */
name += 22;
for (n=0, p=name; hexdigitp (p) && hexdigitp (p+1); p +=2, n++)
;
if (*p != '#' || !n)
return NULL;
buf = xtrymalloc (n+3);
if (!buf)
return NULL; /* oops, out of core */
*buf = '<';
for (n=1, p=name; *p != '#'; p +=2, n++)
buf[n] = xtoi_2 (p);
buf[n++] = '>';
buf[n] = 0;
return buf;
}

View File

@ -156,6 +156,20 @@ void _keybox_free (void *p);
} while (0)
/* some macros to replace ctype ones and avoid locale problems */
#define digitp(p) (*(p) >= '0' && *(p) <= '9')
#define hexdigitp(a) (digitp (a) \
|| (*(a) >= 'A' && *(a) <= 'F') \
|| (*(a) >= 'a' && *(a) <= 'f'))
/* the atoi macros assume that the buffer has only valid digits */
#define atoi_1(p) (*(p) - '0' )
#define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1))
#define atoi_4(p) ((atoi_2(p) * 100) + atoi_2((p)+2))
#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \
*(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
#endif /*KEYBOX_DEFS_H*/

View File

@ -219,6 +219,9 @@ blob_cmp_mail (KEYBOXBLOB blob, const char *name, size_t namelen)
if (pos + uidinfolen*nuids > length)
return 0; /* out of bounds */
if (namelen < 1)
return 0;
for (idx=1 ;idx < nuids; idx++)
{
size_t mypos = pos;
@ -230,12 +233,11 @@ blob_cmp_mail (KEYBOXBLOB blob, const char *name, size_t namelen)
return 0; /* error: better stop here out of bounds */
if (len < 2 || buffer[off] != '<')
continue; /* empty name or trailing 0 not stored */
len--; /* remove the null */
if ( len < 3 || buffer[off+len-1] != '>')
len--; /* one back */
if ( len < 3 || buffer[off+len] != '>')
continue; /* not a prober email address */
off++; len--; /* skip the leading angle bracket */
len--; /* don't compare the trailing one */
if (len == namelen && !memcmp (buffer+off, name, len))
len--;
if (len == namelen && !memcmp (buffer+off+1, name, len))
return 1; /* found */
}
return 0; /* not found */
@ -349,6 +351,8 @@ has_mail (KEYBOXBLOB blob, const char *name)
return 0;
namelen = strlen (name);
if (namelen && name[namelen-1] == '>')
namelen--;
return blob_cmp_mail (blob, name, namelen);
}