diff --git a/kbx/ChangeLog b/kbx/ChangeLog index 8451dd250..7c4047f95 100644 --- a/kbx/ChangeLog +++ b/kbx/ChangeLog @@ -1,3 +1,10 @@ +2001-12-14 Werner Koch + + * 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 * keybox-search.c (blob_cmp_name): Kludge to allow searching for diff --git a/kbx/keybox-blob.c b/kbx/keybox-blob.c index 1f5fe2bbd..44d53d3d0 100644 --- a/kbx/keybox-blob.c +++ b/kbx/keybox-blob.c @@ -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; } diff --git a/kbx/keybox-defs.h b/kbx/keybox-defs.h index 308c1fff3..8b5b91b54 100644 --- a/kbx/keybox-defs.h +++ b/kbx/keybox-defs.h @@ -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*/ diff --git a/kbx/keybox-search.c b/kbx/keybox-search.c index e168d2b97..376bc23ae 100644 --- a/kbx/keybox-search.c +++ b/kbx/keybox-search.c @@ -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); }