From be71d820d27234d7badc27ae7aecfd881f2b5953 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 15 Feb 2015 10:09:10 -0800 Subject: Add fingerprint record parsing for pgp list keys. (see #3695) Modify parse_pub_line to parse fpr records and add the fingerprint to the pgp_key_t's fingerprint field. Add "--with-fingerprint --with-fingerprint" to the pgp_list_pubring_command and pgp_list_secring_command commands in contrib/gpg.rc. The second invocation generates fpr records for subkeys too. --- gnupgparse.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'gnupgparse.c') diff --git a/gnupgparse.c b/gnupgparse.c index cd564f88..fd754a00 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -121,6 +121,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) pgp_uid_t *uid = NULL; int field = 0, is_uid = 0; int is_pub = 0; + int is_fpr = 0; char *pend, *p; int trust = 0; int flags = 0; @@ -148,6 +149,9 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) if (!*p && (field != 1) && (field != 10)) continue; + if (is_fpr && (field != 10)) + continue; + switch (field) { case 1: /* record type */ @@ -164,10 +168,12 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) *is_subkey = 1; else if (!mutt_strcmp (p, "uid")) is_uid = 1; + else if (!mutt_strcmp (p, "fpr")) + is_fpr = 1; else return NULL; - if (!(is_uid || (*is_subkey && option (OPTPGPIGNORESUB)))) + if (!(is_uid || is_fpr || (*is_subkey && option (OPTPGPIGNORESUB)))) memset (&tmp, 0, sizeof (tmp)); break; @@ -290,6 +296,14 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) if (!(pend && (*p || is_pub))) break; + if (is_fpr) + { + /* don't let a subkey fpr overwrite an existing primary key fpr */ + if (!tmp.fingerprint) + tmp.fingerprint = safe_strdup (p); + break; + } + /* ignore user IDs on subkeys */ if (!is_uid && (*is_subkey && option (OPTPGPIGNORESUB))) break; @@ -349,7 +363,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) } /* merge temp key back into real key */ - if (!(is_uid || (*is_subkey && option (OPTPGPIGNORESUB)))) + if (!(is_uid || is_fpr || (*is_subkey && option (OPTPGPIGNORESUB)))) k = safe_malloc (sizeof (*k)); memcpy (k, &tmp, sizeof (*k)); /* fixup parentship of uids after mering the temp key into -- cgit v1.2.3