From 0d6f276f61c583d776687029c715b1ee4280e4ed Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 30 Mar 2021 17:28:45 +0200 Subject: 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 --- tools/card-call-scd.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tools/card-call-scd.c') 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 [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) -- cgit v1.2.3