1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-10-31 20:08:43 +01:00

* 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> 2001-12-13 Werner Koch <wk@gnupg.org>
* keybox-search.c (blob_cmp_name): Kludge to allow searching for * 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 * static char *
x509_email_kludge (const char *name) x509_email_kludge (const char *name)
{ {
#if 0 const unsigned char *p;
if (!strncmp (name, "1.2.840.113549.1.9.1=#", 22) unsigned char *buf;
&& hexdigitp (name+22) && hexdigitp (name+23)) int n;
{ /* 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 */ if (strncmp (name, "1.2.840.113549.1.9.1=#", 22))
return buf;
}
#endif
return NULL; 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) } 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*/ #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) if (pos + uidinfolen*nuids > length)
return 0; /* out of bounds */ return 0; /* out of bounds */
if (namelen < 1)
return 0;
for (idx=1 ;idx < nuids; idx++) for (idx=1 ;idx < nuids; idx++)
{ {
size_t mypos = pos; 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 */ return 0; /* error: better stop here out of bounds */
if (len < 2 || buffer[off] != '<') if (len < 2 || buffer[off] != '<')
continue; /* empty name or trailing 0 not stored */ continue; /* empty name or trailing 0 not stored */
len--; /* remove the null */ len--; /* one back */
if ( len < 3 || buffer[off+len-1] != '>') if ( len < 3 || buffer[off+len] != '>')
continue; /* not a prober email address */ continue; /* not a prober email address */
off++; len--; /* skip the leading angle bracket */ len--;
len--; /* don't compare the trailing one */ if (len == namelen && !memcmp (buffer+off+1, name, len))
if (len == namelen && !memcmp (buffer+off, name, len))
return 1; /* found */ return 1; /* found */
} }
return 0; /* not found */ return 0; /* not found */
@ -349,6 +351,8 @@ has_mail (KEYBOXBLOB blob, const char *name)
return 0; return 0;
namelen = strlen (name); namelen = strlen (name);
if (namelen && name[namelen-1] == '>')
namelen--;
return blob_cmp_mail (blob, name, namelen); return blob_cmp_mail (blob, name, namelen);
} }