]> granicus.if.org Git - neomutt/commitdiff
Convert pgp_key_t fingerprint to a char* (see #3695)
authorKevin McCarthy <kevin@8t8.us>
Sun, 15 Feb 2015 18:08:58 +0000 (10:08 -0800)
committerKevin McCarthy <kevin@8t8.us>
Sun, 15 Feb 2015 18:08:58 +0000 (10:08 -0800)
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
pgplib.h
pgppubring.c

index 1a42cb7f69c7651a581e261065d9c55aaebd1a11..93f8b06e3132628e860ab594853fa417aa1668b1 100644 (file)
--- 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__ */
 }
index 9992e5ecb0c8b9b515ec46e1f3cfb9c67a5e3c66..6cfd3bd82d211a0547d01a056160d114137c68bc 100644 (file)
--- 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 */
 
index 654e4f4eade7708507083b4d57331b80d060977e..8da3bbb88d54f481f5c05cdde4a6b675586a1db2 100644 (file)
@@ -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() */