aboutsummaryrefslogtreecommitdiffstats
path: root/tools/gpg-card.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2021-03-16 17:51:23 +0000
committerWerner Koch <[email protected]>2021-03-16 17:51:23 +0000
commite4c2d7be22ffb47b41a3b6c1152bd75dceed74e2 (patch)
tree81ece7edf157a06bbf4dd9058d4b03e6c5d394bc /tools/gpg-card.c
parentbuild: Check for the IBM TSS tools to run the tpm2d tests. (diff)
downloadgnupg-e4c2d7be22ffb47b41a3b6c1152bd75dceed74e2.tar.gz
gnupg-e4c2d7be22ffb47b41a3b6c1152bd75dceed74e2.zip
card: Generalize the CHV counter printing.
* tools/gpg-card.c (list_retry_counter): New. Factored out from the other functions. (cmd_verify): Re-read the chv status.
Diffstat (limited to 'tools/gpg-card.c')
-rw-r--r--tools/gpg-card.c93
1 files changed, 38 insertions, 55 deletions
diff --git a/tools/gpg-card.c b/tools/gpg-card.c
index c702f71a2..be6929c3a 100644
--- a/tools/gpg-card.c
+++ b/tools/gpg-card.c
@@ -830,6 +830,35 @@ list_all_kinfo (card_info_t info, keyinfolabel_t labels, estream_t fp,
}
+static void
+list_retry_counter (card_info_t info, estream_t fp)
+{
+ 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 OpenPGP card specific data. */
static void
list_openpgp (card_info_t info, estream_t fp, int no_key_lookup)
@@ -883,8 +912,7 @@ list_openpgp (card_info_t info, estream_t fp, int no_key_lookup)
info->chv1_cached? _("not forced"): _("forced"));
tty_fprintf (fp, "Max. PIN lengths .: %d %d %d\n",
info->chvmaxlen[0], info->chvmaxlen[1], info->chvmaxlen[2]);
- tty_fprintf (fp, "PIN retry counter : %d %d %d\n",
- info->chvinfo[0], info->chvinfo[1], info->chvinfo[2]);
+ list_retry_counter (info, fp);
tty_fprintf (fp, "Signature counter : %lu\n", info->sig_counter);
tty_fprintf (fp, "Capabilities .....:");
if (info->extcap.ki)
@@ -927,8 +955,6 @@ list_piv (card_info_t info, estream_t fp, int no_key_lookup)
{ "Key management ...:", "PIV.9D" },
{ NULL, NULL }
};
- const char *s;
- int i;
if (info->chvusage[0] || info->chvusage[1])
{
@@ -952,30 +978,11 @@ list_piv (card_info_t info, estream_t fp, int no_key_lookup)
tty_fprintf (fp, "\n");
}
- 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 -5: s = "[verified]"; break;
- default: s = "[?]"; break;
- }
- tty_fprintf (fp, " %s", s);
- }
- }
- tty_fprintf (fp, "\n");
+ list_retry_counter (info, fp);
list_all_kinfo (info, keyinfolabels, fp, no_key_lookup);
}
-
/* List Netkey card specific data. */
static void
list_nks (card_info_t info, estream_t fp, int no_key_lookup)
@@ -983,29 +990,8 @@ 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_retry_counter (info, fp);
list_all_kinfo (info, keyinfolabels, fp, no_key_lookup);
}
@@ -1017,14 +1003,8 @@ list_p15 (card_info_t info, estream_t fp, int no_key_lookup)
static struct keyinfolabel_s keyinfolabels[] = {
{ NULL, NULL }
};
- int i;
- tty_fprintf (fp, "PIN retry counter :");
- for (i=0; i < DIM (info->chvinfo); i++)
- {
- tty_fprintf (fp, " %d", info->chvinfo[i]);
- }
- tty_fprintf (fp, "\n");
+ list_retry_counter (info, fp);
list_all_kinfo (info, keyinfolabels, fp, no_key_lookup);
}
@@ -1347,7 +1327,7 @@ cmd_list (card_info_t info, char *argstr)
static gpg_error_t
cmd_verify (card_info_t info, char *argstr)
{
- gpg_error_t err;
+ gpg_error_t err, err2;
const char *pinref;
if (!info)
@@ -1366,7 +1346,10 @@ cmd_verify (card_info_t info, char *argstr)
if (err)
log_error ("verify failed: %s <%s>\n",
gpg_strerror (err), gpg_strsource (err));
- return err;
+ /* In any case update the CHV status, so that the next "list" shows
+ * the correct retry counter values. */
+ err2 = scd_getattr ("CHV-STATUS", info);
+ return err ? err : err2;
}