mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-12 22:11:29 +02:00
card: Print the key's label if available.
* tools/gpg-card.h (struct key_info_s): Add field 'label'. * tools/card-call-scd.c (learn_status_cb): Parse KEY-LABEL. (scd_learn): Always request KEY-LABEL. * tools/gpg-card.c (nullnone): New. (list_one_kinfo, list_card): Use it. Print the label. -- PKCS#15 defines label which help to understand for what a key is intended. Print them. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
7f91263632
commit
0d6f276f61
@ -157,6 +157,7 @@ release_card_info (card_info_t info)
|
|||||||
while (info->kinfo)
|
while (info->kinfo)
|
||||||
{
|
{
|
||||||
key_info_t kinfo = info->kinfo->next;
|
key_info_t kinfo = info->kinfo->next;
|
||||||
|
xfree (kinfo->label);
|
||||||
xfree (info->kinfo);
|
xfree (info->kinfo);
|
||||||
info->kinfo = kinfo;
|
info->kinfo = kinfo;
|
||||||
}
|
}
|
||||||
@ -915,6 +916,36 @@ learn_status_cb (void *opaque, const char *line)
|
|||||||
xfree (parm->chvlabels);
|
xfree (parm->chvlabels);
|
||||||
parm->chvlabels = xstrdup (line);
|
parm->chvlabels = xstrdup (line);
|
||||||
}
|
}
|
||||||
|
else if (!memcmp (keyword, "KEY-LABEL", keywordlen))
|
||||||
|
{
|
||||||
|
/* The format of such a line is:
|
||||||
|
* KEY-LABEL <keyref> [label|"-"] */
|
||||||
|
const char *fields[2];
|
||||||
|
int nfields;
|
||||||
|
char *label;
|
||||||
|
|
||||||
|
line_buffer = pline = xstrdup (line);
|
||||||
|
|
||||||
|
if ((nfields = split_fields (line_buffer, fields, DIM (fields))) < 2)
|
||||||
|
goto leave; /* not enough args - ignore. */
|
||||||
|
|
||||||
|
keyref = fields[0];
|
||||||
|
/* We don't remove the percent escaping because that is only
|
||||||
|
* used in case of strange characters in the label; we
|
||||||
|
* should not print them. Note that this info is only for
|
||||||
|
* human consumption, anyway. */
|
||||||
|
label = xtrystrdup (fields[1]);
|
||||||
|
if (!label)
|
||||||
|
goto leave; /* We ignore malloc failures here. */
|
||||||
|
|
||||||
|
/* Check whether we already have an item for the keyref. */
|
||||||
|
kinfo = find_kinfo (parm, keyref);
|
||||||
|
if (!kinfo) /* New entry. */
|
||||||
|
kinfo = create_kinfo (parm, keyref);
|
||||||
|
|
||||||
|
xfree (kinfo->label);
|
||||||
|
kinfo->label = label;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 10:
|
case 10:
|
||||||
@ -1153,6 +1184,10 @@ scd_learn (card_info_t info)
|
|||||||
if (gpg_err_code (err) == GPG_ERR_INV_NAME
|
if (gpg_err_code (err) == GPG_ERR_INV_NAME
|
||||||
|| gpg_err_code (err) == GPG_ERR_UNSUPPORTED_OPERATION)
|
|| gpg_err_code (err) == GPG_ERR_UNSUPPORTED_OPERATION)
|
||||||
err = 0; /* Not implemented or GETATTR not supported. */
|
err = 0; /* Not implemented or GETATTR not supported. */
|
||||||
|
err = scd_getattr ("KEY-LABEL", info);
|
||||||
|
if (gpg_err_code (err) == GPG_ERR_INV_NAME
|
||||||
|
|| gpg_err_code (err) == GPG_ERR_UNSUPPORTED_OPERATION)
|
||||||
|
err = 0; /* Not implemented or GETATTR not supported. */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info == &dummyinfo)
|
if (info == &dummyinfo)
|
||||||
|
@ -373,6 +373,14 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return S or the string "[none]" if S is NULL. */
|
||||||
|
static GPGRT_INLINE const char *
|
||||||
|
nullnone (const char *s)
|
||||||
|
{
|
||||||
|
return s? s: "[none]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Read data from file FNAME up to MAX_GET_DATA_FROM_FILE characters.
|
/* Read data from file FNAME up to MAX_GET_DATA_FROM_FILE characters.
|
||||||
* On error return an error code and stores NULL at R_BUFFER; on
|
* On error return an error code and stores NULL at R_BUFFER; on
|
||||||
* success returns 0 and stores the number of bytes read at R_BUFLEN
|
* success returns 0 and stores the number of bytes read at R_BUFLEN
|
||||||
@ -668,7 +676,10 @@ list_one_kinfo (card_info_t info, key_info_t kinfo,
|
|||||||
{
|
{
|
||||||
tty_fprintf (fp, "[none]\n");
|
tty_fprintf (fp, "[none]\n");
|
||||||
tty_fprintf (fp, " keyref .....: %s\n", kinfo->keyref);
|
tty_fprintf (fp, " keyref .....: %s\n", kinfo->keyref);
|
||||||
tty_fprintf (fp, " algorithm ..: %s\n", kinfo->keyalgo);
|
if (kinfo->label)
|
||||||
|
tty_fprintf (fp, " label ......: %s\n", kinfo->label);
|
||||||
|
tty_fprintf (fp, " algorithm ..: %s\n",
|
||||||
|
nullnone (kinfo->keyalgo));
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,10 +701,13 @@ list_one_kinfo (card_info_t info, key_info_t kinfo,
|
|||||||
}
|
}
|
||||||
tty_fprintf (fp, "\n");
|
tty_fprintf (fp, "\n");
|
||||||
|
|
||||||
|
if (kinfo->label)
|
||||||
|
tty_fprintf (fp, " label ......: %s\n", kinfo->label);
|
||||||
|
|
||||||
if (!(err = scd_readkey (kinfo->keyref, &s_pkey)))
|
if (!(err = scd_readkey (kinfo->keyref, &s_pkey)))
|
||||||
{
|
{
|
||||||
char *tmp = pubkey_algo_string (s_pkey, NULL);
|
char *tmp = pubkey_algo_string (s_pkey, NULL);
|
||||||
tty_fprintf (fp, " algorithm ..: %s\n", tmp);
|
tty_fprintf (fp, " algorithm ..: %s\n", nullnone (tmp));
|
||||||
xfree (tmp);
|
xfree (tmp);
|
||||||
gcry_sexp_release (s_pkey);
|
gcry_sexp_release (s_pkey);
|
||||||
s_pkey = NULL;
|
s_pkey = NULL;
|
||||||
@ -701,7 +715,8 @@ list_one_kinfo (card_info_t info, key_info_t kinfo,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
maybe_set_card_removed (info, err);
|
maybe_set_card_removed (info, err);
|
||||||
tty_fprintf (fp, " algorithm ..: %s\n", kinfo->keyalgo);
|
tty_fprintf (fp, " algorithm ..: %s\n",
|
||||||
|
nullnone (kinfo->keyalgo));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kinfo->fprlen && kinfo->created)
|
if (kinfo->fprlen && kinfo->created)
|
||||||
@ -785,7 +800,8 @@ list_one_kinfo (card_info_t info, key_info_t kinfo,
|
|||||||
if (label_keyref)
|
if (label_keyref)
|
||||||
tty_fprintf (fp, " keyref .....: %s\n", label_keyref);
|
tty_fprintf (fp, " keyref .....: %s\n", label_keyref);
|
||||||
if (kinfo)
|
if (kinfo)
|
||||||
tty_fprintf (fp, " algorithm ..: %s\n", kinfo->keyalgo);
|
tty_fprintf (fp, " algorithm ..: %s\n",
|
||||||
|
nullnone (kinfo->keyalgo));
|
||||||
}
|
}
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
@ -1039,14 +1055,12 @@ list_card (card_info_t info, int no_key_lookup)
|
|||||||
{
|
{
|
||||||
estream_t fp = opt.interactive? NULL : es_stdout;
|
estream_t fp = opt.interactive? NULL : es_stdout;
|
||||||
|
|
||||||
tty_fprintf (fp, "Reader ...........: %s\n",
|
tty_fprintf (fp, "Reader ...........: %s\n", nullnone (info->reader));
|
||||||
info->reader? info->reader : "[none]");
|
|
||||||
if (info->cardtype)
|
if (info->cardtype)
|
||||||
tty_fprintf (fp, "Card type ........: %s\n", info->cardtype);
|
tty_fprintf (fp, "Card type ........: %s\n", info->cardtype);
|
||||||
if (info->cardversion)
|
if (info->cardversion)
|
||||||
print_a_version (fp, "Card firmware ....:", info->cardversion);
|
print_a_version (fp, "Card firmware ....:", info->cardversion);
|
||||||
tty_fprintf (fp, "Serial number ....: %s\n",
|
tty_fprintf (fp, "Serial number ....: %s\n", nullnone (info->serialno));
|
||||||
info->serialno? info->serialno : "[none]");
|
|
||||||
tty_fprintf (fp, "Application type .: %s%s%s%s\n",
|
tty_fprintf (fp, "Application type .: %s%s%s%s\n",
|
||||||
app_type_string (info->apptype),
|
app_type_string (info->apptype),
|
||||||
info->apptype == APP_TYPE_UNKNOWN && info->apptypestr? "(":"",
|
info->apptype == APP_TYPE_UNKNOWN && info->apptypestr? "(":"",
|
||||||
|
@ -125,6 +125,9 @@ struct key_info_s
|
|||||||
const char *keyalgo;
|
const char *keyalgo;
|
||||||
enum gcry_pk_algos keyalgo_id;
|
enum gcry_pk_algos keyalgo_id;
|
||||||
|
|
||||||
|
/* An optional malloced label for the key. */
|
||||||
|
char *label;
|
||||||
|
|
||||||
/* The three next items are mostly useful for OpenPGP cards. */
|
/* The three next items are mostly useful for OpenPGP cards. */
|
||||||
unsigned char fprlen; /* Use length of the next item. */
|
unsigned char fprlen; /* Use length of the next item. */
|
||||||
unsigned char fpr[32]; /* The binary fingerprint of length FPRLEN. */
|
unsigned char fpr[32]; /* The binary fingerprint of length FPRLEN. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user