--- pgplib.h 2002/02/01 23:55:24 1.1 +++ pgplib.h 2002/02/01 23:56:11 @@ -61,6 +61,11 @@ struct pgp_keyinfo *parent; struct pgp_signature *sigs; struct pgp_keyinfo *next; + unsigned int fingerprint_is_md5; /* == true (!= 0) if fingerprint is an + MD5 hash */ + unsigned char fingerprint[20]; /* large enough to hold SHA-1 and RIPEMD160 + hashes (20 bytes), MD5 hashes just use the + first 16 bytes */ } pgp_key_t; --- pgppubring.c 2002/02/01 23:55:13 1.1 +++ pgppubring.c 2002/02/01 23:57:08 @@ -50,10 +50,12 @@ extern int optind; #include "sha1.h" +#include "md5.h" #include "lib.h" #include "pgplib.h" #include "pgppacket.h" +#define MD5_DIGEST_LENGTH 16 #ifdef HAVE_FGETPOS #define FGETPOS(fp,pos) fgetpos((fp),&(pos)) @@ -65,6 +67,7 @@ static short dump_signatures = 0; +static short dump_fingerprints = 0; static void pgpring_find_candidates (char *ringfile, const char *hints[], int nhints); @@ -83,7 +86,7 @@ char pgppath[_POSIX_PATH_MAX]; char kring[_POSIX_PATH_MAX]; - while ((c = getopt (argc, argv, "25sk:S")) != EOF) + while ((c = getopt (argc, argv, "f25sk:S")) != EOF) { switch (c) { @@ -93,6 +96,12 @@ break; } + case 'f': + { + dump_fingerprints = 1; + break; + } + case 'k': { _kring = optarg; @@ -113,7 +122,7 @@ default: { - fprintf (stderr, "usage: %s [-k | [-2 | -5] [ -s]] [hints]\n", + fprintf (stderr, "usage: %s [-k | [-2 | -5] [ -s] [-S] [-f]] [hints]\n", argv[0]); exit (1); } @@ -148,10 +157,38 @@ /* The actual key ring parser */ +static void pgp_make_pgp2_fingerprint (unsigned char *buff, + unsigned char *digest) +{ + + MD5_CTX context; + unsigned int size = 0; + + + MD5Init (&context); + + size = (buff[0] << 8) + buff[1]; + size = ((size + 7) / 8); + buff = &buff[2]; + + MD5Update (&context, buff, size); + buff = &buff[size]; + + size = (buff[0] << 8) + buff[1]; + size = ((size + 7) / 8); + buff = &buff[2]; + + MD5Update (&context, buff, size); + + MD5Final (digest, &context); + +} /* pgp_make_pgp2_fingerprint() */ + static pgp_key_t *pgp_parse_pgp2_key (unsigned char *buff, size_t l) { pgp_key_t *p; unsigned char alg; + unsigned char digest[MD5_DIGEST_LENGTH]; size_t expl; unsigned long id; time_t gen_time = 0; @@ -182,6 +219,11 @@ p->algorithm = pgp_pkalgbytype (alg); p->flags |= pgp_get_abilities (alg); + /* j now points to the key material, which we need for the fingerprint */ + p->fingerprint_is_md5 = 1; + pgp_make_pgp2_fingerprint (&buff[j], digest); + (void) memcpy (p->fingerprint, digest, MD5_DIGEST_LENGTH); + expl = 0; for (i = 0; i < 2; i++) expl = (expl << 8) + buff[j++]; @@ -291,10 +333,12 @@ if (alg >= 1 && alg <= 3) skip_bignum (buff, l, j, &j, 2); - else if (alg == 17 || alg == 16) + else if (alg == 17 || alg == 16 || alg == 20) skip_bignum (buff, l, j, &j, 1); + p->fingerprint_is_md5 = 0; pgp_make_pgp3_fingerprint (buff, j, digest); + (void) memcpy (p->fingerprint, digest, sizeof(p->fingerprint)); for (k = 0; k < 2; k++) { @@ -772,6 +816,25 @@ } } +static void print_fingerprint (pgp_key_t *p) { + + unsigned int i = 0; + unsigned int max = 0; + + len = 20; + if (p->fingerprint_is_md5) { + len = 16; + } + + printf ("fpr:::::::::"); + for (i = 0; i < len; i++) { + printf ("%02X", p->fingerprint[i]); + } + printf (":\n"); + +} /* print_fingerprint() */ + + static void pgpring_dump_signatures (pgp_sig_t *sig) { for (; sig; sig = sig->next) @@ -854,6 +917,9 @@ print_userid (uid->addr); printf (":\n"); + if (dump_fingerprints) { + print_fingerprint (p); + } } if (dump_signatures)