From be71d820d27234d7badc27ae7aecfd881f2b5953 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 15 Feb 2015 10:09:10 -0800 Subject: [PATCH] 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. --- contrib/gpg.rc | 4 ++-- gnupgparse.c | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/contrib/gpg.rc b/contrib/gpg.rc index d6c9defb..c713b6d5 100644 --- a/contrib/gpg.rc +++ b/contrib/gpg.rc @@ -65,10 +65,10 @@ set pgp_export_command="gpg --no-verbose --export --armor %r" set pgp_verify_key_command="gpg --verbose --batch --fingerprint --check-sigs %r" # read in the public key ring -set pgp_list_pubring_command="gpg --no-verbose --batch --quiet --with-colons --list-keys %r" +set pgp_list_pubring_command="gpg --no-verbose --batch --quiet --with-colons --with-fingerprint --with-fingerprint --list-keys %r" # read in the secret key ring -set pgp_list_secring_command="gpg --no-verbose --batch --quiet --with-colons --list-secret-keys %r" +set pgp_list_secring_command="gpg --no-verbose --batch --quiet --with-colons --with-fingerprint --with-fingerprint --list-secret-keys %r" # fetch keys # set pgp_getkeys_command="pkspxycwrap %r" 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 -- 2.40.0