From 26d9ed50fac253f9908bdd4918e0abc1e5fe35a4 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 15 Feb 2015 10:08:58 -0800 Subject: [PATCH] Convert pgp_key_t fingerprint to a char* (see #3695) Currently only pgppubring.c is using the fingerprint field, and is using it to store a binary version of the fingerprint. Convert the field to store a null-terminated string. Modify pgppubring.c to use to use the new field. --- pgplib.c | 1 + pgplib.h | 8 +------- pgppubring.c | 36 +++++++++++++++++++++++++----------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/pgplib.c b/pgplib.c index 1a42cb7f6..93f8b06e3 100644 --- a/pgplib.c +++ b/pgplib.c @@ -183,6 +183,7 @@ static void _pgp_free_key (pgp_key_t *kpp) pgp_free_uid (&kp->address); FREE (&kp->keyid); + FREE (&kp->fingerprint); /* mutt_crypt.h: 'typedef struct pgp_keyinfo *pgp_key_t;' */ FREE (kpp); /* __FREE_CHECKED__ */ } diff --git a/pgplib.h b/pgplib.h index 9992e5ecb..6cfd3bd82 100644 --- a/pgplib.h +++ b/pgplib.h @@ -34,6 +34,7 @@ pgp_sig_t; struct pgp_keyinfo { char *keyid; + char *fingerprint; struct pgp_uid *address; int flags; short keylen; @@ -43,13 +44,6 @@ struct pgp_keyinfo struct pgp_keyinfo *parent; struct pgp_signature *sigs; struct pgp_keyinfo *next; - - short fp_len; /* length of fingerprint. - * 20 for sha-1, 16 for md5. - */ - unsigned char fingerprint[20]; /* large enough to hold SHA-1 and RIPEMD160 - hashes (20 bytes), MD5 hashes just use the - first 16 bytes */ }; /* Note, that pgp_key_t is now pointer and declared in crypt.h */ diff --git a/pgppubring.c b/pgppubring.c index 654e4f4ea..8da3bbb88 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -156,6 +156,23 @@ int main (int argc, char * const argv[]) return 0; } +static char *binary_fingerprint_to_string (unsigned char *buff, size_t length) +{ + int i; + char *fingerprint, *pf; + + pf = fingerprint = (char *)safe_malloc ((length * 2) + 1); + + for (i = 0; i < length; i++) + { + sprintf (pf, "%02X", buff[i]); + pf += 2; + } + *pf = 0; + + return fingerprint; +} + /* The actual key ring parser */ static void pgp_make_pgp2_fingerprint (unsigned char *buff, @@ -221,12 +238,9 @@ static pgp_key_t pgp_parse_pgp2_key (unsigned char *buff, size_t l) if (dump_fingerprints) { /* j now points to the key material, which we need for the fingerprint */ - p->fp_len = MD5_DIGEST_LENGTH; pgp_make_pgp2_fingerprint (&buff[j], digest); - memcpy (p->fingerprint, digest, MD5_DIGEST_LENGTH); + p->fingerprint = binary_fingerprint_to_string (digest, MD5_DIGEST_LENGTH); } - else /* just to be usre */ - memset (p->fingerprint, 0, MD5_DIGEST_LENGTH); expl = 0; for (i = 0; i < 2; i++) @@ -342,7 +356,10 @@ static pgp_key_t pgp_parse_pgp3_key (unsigned char *buff, size_t l) skip_bignum (buff, l, j, &j, 1); pgp_make_pgp3_fingerprint (buff, j, digest); - p->fp_len = SHA_DIGEST_LENGTH; + if (dump_fingerprints) + { + p->fingerprint = binary_fingerprint_to_string (digest, SHA_DIGEST_LENGTH); + } for (k = 0; k < 2; k++) { @@ -829,13 +846,10 @@ static void print_userid (const char *id) static void print_fingerprint (pgp_key_t p) { - int i = 0; - - printf ("fpr:::::::::"); - for (i = 0; i < p->fp_len; i++) - printf ("%02X", p->fingerprint[i]); - printf (":\n"); + if (!p->fingerprint) + return; + printf ("fpr:::::::::%s:\n", p->fingerprint); } /* print_fingerprint() */ -- 2.40.0