From 94966347452632f8140fae70f7fcbadcc2b81071 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 7 May 2020 19:47:07 +0200 Subject: [PATCH] card: Allow listing of NKS cards. * tools/card-call-scd.c (learn_status_cb): Always fill chvinfo. * tools/gpg-card.h (struct card_info_s): Increase size of chvinfo and chvmaxlen. * tools/gpg-card.c (list_nks): New. (print_a_version): Support single part version numbers. (list_card): Call list_nks. -- Note that chvmaxlen is not yet used with NKS. Signed-off-by: Werner Koch --- tools/card-call-scd.c | 2 +- tools/gpg-card.c | 40 +++++++++++++++++++++++++++++++++++++++- tools/gpg-card.h | 4 ++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/tools/card-call-scd.c b/tools/card-call-scd.c index c6ae5edd4..2e8fee8f4 100644 --- a/tools/card-call-scd.c +++ b/tools/card-call-scd.c @@ -913,7 +913,7 @@ learn_status_cb (void *opaque, const char *line) p++; } } - else if (parm->apptype == APP_TYPE_PIV) + else { for (i=0; *p && i < DIM (parm->chvinfo); i++) { diff --git a/tools/gpg-card.c b/tools/gpg-card.c index 03b5c8c18..deb9ead0e 100644 --- a/tools/gpg-card.c +++ b/tools/gpg-card.c @@ -916,6 +916,41 @@ list_piv (card_info_t info, estream_t fp, int no_key_lookup) +/* List Netkey card specific data. */ +static void +list_nks (card_info_t info, estream_t fp, int no_key_lookup) +{ + static struct keyinfolabel_s keyinfolabels[] = { + { NULL, NULL } + }; + const char *s; + int i; + + tty_fprintf (fp, "PIN retry counter :"); + for (i=0; i < DIM (info->chvinfo); i++) + { + if (info->chvinfo[i] >= 0) + tty_fprintf (fp, " %d", info->chvinfo[i]); + else + { + switch (info->chvinfo[i]) + { + case -1: s = "[error]"; break; + case -2: s = "-"; break; /* No such PIN or info not available. */ + case -3: s = "[blocked]"; break; + case -4: s = "[nullpin]"; break; + case -5: s = "[verified]"; break; + default: s = "[?]"; break; + } + tty_fprintf (fp, " %s", s); + } + } + tty_fprintf (fp, "\n"); + list_all_kinfo (info, keyinfolabels, fp, no_key_lookup); +} + + + static void print_a_version (estream_t fp, const char *prefix, unsigned int value) { @@ -929,8 +964,10 @@ print_a_version (estream_t fp, const char *prefix, unsigned int value) tty_fprintf (fp, "%s %u.%u.%u.%u\n", prefix, a, b, c, d); else if (b) tty_fprintf (fp, "%s %u.%u.%u\n", prefix, b, c, d); - else + else if (c) tty_fprintf (fp, "%s %u.%u\n", prefix, c, d); + else + tty_fprintf (fp, "%s %u\n", prefix, d); } @@ -974,6 +1011,7 @@ list_card (card_info_t info, int no_key_lookup) { case APP_TYPE_OPENPGP: list_openpgp (info, fp, no_key_lookup); break; case APP_TYPE_PIV: list_piv (info, fp, no_key_lookup); break; + case APP_TYPE_NKS: list_nks (info, fp, no_key_lookup); break; default: break; } } diff --git a/tools/gpg-card.h b/tools/gpg-card.h index 0e12955a1..fc01684b0 100644 --- a/tools/gpg-card.h +++ b/tools/gpg-card.h @@ -167,8 +167,8 @@ struct card_info_s required for each signing. Note that the gpg-agent might cache it anyway. */ int is_v2; /* True if this is a v2 openpgp card. */ - int chvmaxlen[3]; /* Maximum allowed length of a CHV. */ - int chvinfo[3]; /* Allowed retries for the CHV; 0 = blocked. */ + int chvmaxlen[4]; /* Maximum allowed length of a CHV. */ + int chvinfo[4]; /* Allowed retries for the CHV; 0 = blocked. */ unsigned char chvusage[2]; /* Data object 5F2F */ struct { unsigned int ki:1; /* Key import available. */