aboutsummaryrefslogtreecommitdiffstats
path: root/tools/card-call-scd.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2021-03-30 15:28:45 +0000
committerWerner Koch <[email protected]>2021-03-30 15:28:45 +0000
commit0d6f276f61c583d776687029c715b1ee4280e4ed (patch)
tree1c8fbd9c7170a6fbbe27e67764b882fb634236a5 /tools/card-call-scd.c
parentscd:p15: Return labels for keys and certificates. (diff)
downloadgnupg-0d6f276f61c583d776687029c715b1ee4280e4ed.tar.gz
gnupg-0d6f276f61c583d776687029c715b1ee4280e4ed.zip
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 <[email protected]>
Diffstat (limited to 'tools/card-call-scd.c')
-rw-r--r--tools/card-call-scd.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/card-call-scd.c b/tools/card-call-scd.c
index 95f28e564..5a2b3001d 100644
--- a/tools/card-call-scd.c
+++ b/tools/card-call-scd.c
@@ -157,6 +157,7 @@ release_card_info (card_info_t info)
while (info->kinfo)
{
key_info_t kinfo = info->kinfo->next;
+ xfree (kinfo->label);
xfree (info->kinfo);
info->kinfo = kinfo;
}
@@ -915,6 +916,36 @@ learn_status_cb (void *opaque, const char *line)
xfree (parm->chvlabels);
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;
case 10:
@@ -1153,6 +1184,10 @@ scd_learn (card_info_t 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. */
+ 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)