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 <wk@gnupg.org>
This commit is contained in:
Werner Koch 2020-02-12 12:50:38 +01:00
parent 2c6092bc5d
commit 1abfce82bd
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
3 changed files with 21 additions and 12 deletions

View File

@ -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;
}

View File

@ -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, " <Key %s>\n", ki->keyref);
tty_fprintf (fp, "<Key %s>\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)

View File

@ -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. */
};