aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-11-27 11:28:16 +0100
committerWerner Koch <wk@gnupg.org>2020-11-27 11:28:16 +0100
commitad469609b101fe6c1128135180fef8eae13279ff (patch)
treeb186b061f08e93b8d76f9767f52fdff2c0a409ce
parent0e34683a6c4b037aa50ca0f97ddb9d5c4e499084 (diff)
downloadgnupg-ad469609b101fe6c1128135180fef8eae13279ff.tar.gz
card: Let the APDU command prints a description of the status word.
* tools/card-call-scd.c (scd_apdu_strerror): New. * tools/gpg-card.c (cmd_apdu): Print a description. -- Pretty convenient to explore smartcards.
-rw-r--r--tools/card-call-scd.c30
-rw-r--r--tools/gpg-card.c11
-rw-r--r--tools/gpg-card.h3
3 files changed, 43 insertions, 1 deletions
diff --git a/tools/card-call-scd.c b/tools/card-call-scd.c
index 1f7008902..bb739e684 100644
--- a/tools/card-call-scd.c
+++ b/tools/card-call-scd.c
@@ -1709,3 +1709,33 @@ agent_get_s2k_count (void)
return count;
}
+
+
+/* Return a malloced string describing the statusword SW. On error
+ * NULL is returned. */
+char *
+scd_apdu_strerror (unsigned int sw)
+{
+ gpg_error_t err;
+ char line[ASSUAN_LINELENGTH];
+ membuf_t data;
+ char *buf;
+
+ err = start_agent (0);
+ if (err)
+ return NULL;
+
+ init_membuf (&data, 64);
+ snprintf (line, sizeof line, "SCD GETINFO apdu_strerror 0x%x", sw);
+ err = assuan_transact (agent_ctx, line, put_membuf_cb, &data,
+ NULL, NULL, NULL, NULL);
+ if (err)
+ {
+ xfree (get_membuf (&data, NULL));
+ return NULL;
+ }
+
+ put_membuf (&data, "", 1);
+ buf = get_membuf (&data, NULL);
+ return buf;
+}
diff --git a/tools/gpg-card.c b/tools/gpg-card.c
index b4cd80c43..f4e33fa64 100644
--- a/tools/gpg-card.c
+++ b/tools/gpg-card.c
@@ -3501,7 +3501,16 @@ cmd_apdu (card_info_t info, char *argstr)
if (err)
goto leave;
if (!with_atr)
- log_info ("Statusword: 0x%04x\n", sw);
+ {
+ if (opt.interactive || opt.verbose)
+ {
+ char *p = scd_apdu_strerror (sw);
+ log_info ("Statusword: 0x%04x (%s)\n", sw, p? p: "?");
+ xfree (p);
+ }
+ else
+ log_info ("Statusword: 0x%04x\n", sw);
+ }
for (i=0; i < resultlen; )
{
size_t save_i = i;
diff --git a/tools/gpg-card.h b/tools/gpg-card.h
index 1622f2d5f..18ff5f68d 100644
--- a/tools/gpg-card.h
+++ b/tools/gpg-card.h
@@ -242,6 +242,9 @@ gpg_error_t scd_checkpin (const char *serialno);
unsigned long agent_get_s2k_count (void);
+char *scd_apdu_strerror (unsigned int sw);
+
+
/*-- card-yubikey.c --*/
gpg_error_t yubikey_commands (card_info_t info,
estream_t fp, int argc, const char *argv[]);