From 1abfce82bd525de2976c31b83bb0e67e33364e58 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 12 Feb 2020 12:50:38 +0100 Subject: [PATCH] card: List more info for an OpenPGP key. * tools/gpg-card.h (struct pubkey_s): Add field created. * tools/card-keys.c (parse_key_record): Set that field. * tools/gpg-card.c (print_shax_fpr): Print the fingerprint without spaces for easier c+p. (list_one_kinfo): Print the actual used fingerprint and creation date from the keyblock. -- A common problem with OpenPGP cards is that the fingerprint as stored on the card does not match the actual fingerprint. Print both values to be able to investigate such issues. Signed-off-by: Werner Koch --- tools/card-keys.c | 4 ++++ tools/gpg-card.c | 28 ++++++++++++++++------------ tools/gpg-card.h | 1 + 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/tools/card-keys.c b/tools/card-keys.c index ad06f2ff7..4706cb320 100644 --- a/tools/card-keys.c +++ b/tools/card-keys.c @@ -174,6 +174,10 @@ parse_key_record (char **fields, int nfields, pubkey_t *r_pubkey) pubkey = xtrycalloc (1, sizeof *pubkey); if (!pubkey) return gpg_error_from_syserror (); + + if (nfields > 5) + pubkey->created = parse_timestamp (fields[5], NULL); + *r_pubkey = pubkey; return 0; } diff --git a/tools/gpg-card.c b/tools/gpg-card.c index 0b640dee0..c526d56f7 100644 --- a/tools/gpg-card.c +++ b/tools/gpg-card.c @@ -537,13 +537,8 @@ print_shax_fpr (estream_t fp, const unsigned char *fpr, unsigned int fprlen) if (fpr) { - /* FIXME: Fix formatting for FPRLEN != 20 */ - for (i=0; i < fprlen ; i+=2, fpr += 2 ) - { - if (i == 10 ) - tty_fprintf (fp, " "); - tty_fprintf (fp, " %02X%02X", *fpr, fpr[1]); - } + for (i=0; i < fprlen ; i++, fpr++) + tty_fprintf (fp, "%02X", *fpr); } else tty_fprintf (fp, " [none]"); @@ -698,7 +693,7 @@ list_one_kinfo (key_info_t firstkinfo, key_info_t kinfo, if (kinfo->fprlen && kinfo->created) { - tty_fprintf (fp, " fingerprint :"); + tty_fprintf (fp, " stored fpr .: "); print_shax_fpr (fp, kinfo->fpr, kinfo->fprlen); tty_fprintf (fp, " created ....: %s\n", isotimestamp (kinfo->created)); @@ -725,7 +720,7 @@ list_one_kinfo (key_info_t firstkinfo, key_info_t kinfo, * fingerprint or a reference to it. */ if (kb->protocol == GNUPG_PROTOCOL_OPENPGP) { - tty_fprintf (fp, " main key .:"); + tty_fprintf (fp, " main key .: "); for (ki=firstkinfo; ki; ki = ki->next) if (pubkey->grip_valid && !memcmp (ki->grip, pubkey->grip, KEYGRIP_LEN)) @@ -744,11 +739,20 @@ list_one_kinfo (key_info_t firstkinfo, key_info_t kinfo, else s = NULL; if (s) - tty_fprintf (fp, " <%s>\n", s); + tty_fprintf (fp, "<%s>\n", s); else - tty_fprintf (fp, " \n", ki->keyref); + tty_fprintf (fp, "\n", ki->keyref); + + tty_fprintf (fp, " fpr ......: "); + for (; pubkey; pubkey = pubkey->next) + if (pubkey->grip_valid + && !memcmp (ki->grip, pubkey->grip, KEYGRIP_LEN)) + break; + print_shax_fpr (fp, pubkey->fpr, pubkey->fprlen); + tty_fprintf (fp, " created ..: %s\n", + isotimestamp (pubkey->created)); } - else + else /* Print the primary key as fallback. */ print_shax_fpr (fp, pubkey->fpr, pubkey->fprlen); } for (uid = kb->uids; uid; uid = uid->next) diff --git a/tools/gpg-card.h b/tools/gpg-card.h index 67ecc4683..005316182 100644 --- a/tools/gpg-card.h +++ b/tools/gpg-card.h @@ -67,6 +67,7 @@ struct pubkey_s unsigned char grip[KEYGRIP_LEN]; unsigned char fpr[MAX_FINGERPRINT_LEN]; unsigned char fprlen; /* The used length of a FPR. */ + time_t created; /* The creation date of the key. */ unsigned int grip_valid:1;/* The grip is valid. */ unsigned int requested: 1;/* This is the requested grip. */ };