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. -Kevin
# HG changeset patch # User Kevin McCarthy <ke...@8t8.us> # Date 1424023738 28800 # Sun Feb 15 10:08:58 2015 -0800 # Node ID 47b4e57b2f1c68f40cf607e625b85a97aa03299e # Parent 385d7434c9d6f44c732fd12fc76d543f9d5d7233 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. diff --git a/pgplib.c b/pgplib.c --- a/pgplib.c +++ b/pgplib.c @@ -178,16 +178,17 @@ if (!kpp || !*kpp) return; kp = *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__ */ } pgp_key_t pgp_remove_key (pgp_key_t *klist, pgp_key_t key) { pgp_key_t *last; pgp_key_t p, q, r; diff --git a/pgplib.h b/pgplib.h --- a/pgplib.h +++ b/pgplib.h @@ -29,32 +29,26 @@ unsigned long sid1; unsigned long sid2; } pgp_sig_t; struct pgp_keyinfo { char *keyid; + char *fingerprint; struct pgp_uid *address; int flags; short keylen; time_t gen_time; int numalg; const char *algorithm; 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 */ typedef struct pgp_uid { char *addr; short trust; int flags; diff --git a/pgppubring.c b/pgppubring.c --- a/pgppubring.c +++ b/pgppubring.c @@ -151,16 +151,33 @@ snprintf (kring, sizeof (kring), "%s/pubring.%s", pgppath, version == 2 ? "pgp" : "pkr"); } pgpring_find_candidates (kring, (const char**) argv + optind, argc - optind); 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, unsigned char *digest) { struct md5_ctx ctx; unsigned int size = 0; @@ -216,22 +233,19 @@ p->numalg = alg; p->algorithm = pgp_pkalgbytype (alg); p->flags |= pgp_get_abilities (alg); 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++) expl = (expl << 8) + buff[j++]; p->keylen = expl; expl = (expl + 7) / 8; @@ -337,17 +351,20 @@ if (alg >= 1 && alg <= 3) skip_bignum (buff, l, j, &j, 2); else if (alg == 17 || alg == 16 || alg == 20) 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++) { for (id = 0, i = SHA_DIGEST_LENGTH - 8 + k * 4; i < SHA_DIGEST_LENGTH + (k - 1) * 4; i++) id = (id << 8) + digest[i]; snprintf ((char *) scratch + k * 8, sizeof (scratch) - k * 8, "%08lX", id); @@ -824,23 +841,20 @@ putchar (*id); else printf ("\\x%02x", (*id) & 0xff); } } static void print_fingerprint (pgp_key_t p) { - int i = 0; + if (!p->fingerprint) + return; - printf ("fpr:::::::::"); - for (i = 0; i < p->fp_len; i++) - printf ("%02X", p->fingerprint[i]); - printf (":\n"); - + printf ("fpr:::::::::%s:\n", p->fingerprint); } /* print_fingerprint() */ static void pgpring_dump_signatures (pgp_sig_t *sig) { for (; sig; sig = sig->next) { if (sig->sigtype == 0x10 || sig->sigtype == 0x11 ||
signature.asc
Description: PGP signature