aboutsummaryrefslogtreecommitdiffstats
path: root/tools/card-tool-misc.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2019-02-13 08:46:36 +0000
committerWerner Koch <[email protected]>2019-02-13 08:49:07 +0000
commit7e1cd2cd416f852fc039af310e3df1ce395d89a9 (patch)
tree10e09c9a4f15399f674ea055bb1c99983f0f3333 /tools/card-tool-misc.c
parentscd: Implement decryption for PIV cards. (diff)
downloadgnupg-7e1cd2cd416f852fc039af310e3df1ce395d89a9.tar.gz
gnupg-7e1cd2cd416f852fc039af310e3df1ce395d89a9.zip
card: New command "yubikey".
* tools/card-tool-yubikey.c: New. * tools/Makefile.am (gpg_card_tool_SOURCES): Add it. * tools/card-call-scd.c (scd_apdu): Allow returning data. * tools/card-tool-misc.c (send_apdu): New. Move from gpg-card-tool.c and let it return data. Change all callers. * tools/gpg-card-tool.c (cmd_writecert): Prepend the certref with the current application type. (cmd_yubikey): New. -- This command allows listing of active applications and to enable or disable selected applications. This is in particular useful to disable the OpenPGP application so that the PIV support can easily be tested. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'tools/card-tool-misc.c')
-rw-r--r--tools/card-tool-misc.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/card-tool-misc.c b/tools/card-tool-misc.c
index 06fcb6705..d0fb55dab 100644
--- a/tools/card-tool-misc.c
+++ b/tools/card-tool-misc.c
@@ -77,3 +77,37 @@ hex_to_buffer (const char *string, size_t *r_length)
*r_length = n;
return buffer;
}
+
+
+/* Direct sending of an hex encoded APDU with error printing. This is
+ * a simple wrapper around scd_apdu. */
+gpg_error_t
+send_apdu (const char *hexapdu, const char *desc, unsigned int ignore,
+ unsigned char **r_data, size_t *r_datalen)
+{
+ gpg_error_t err;
+ unsigned int sw;
+
+ err = scd_apdu (hexapdu, &sw, r_data, r_datalen);
+ if (err)
+ log_error ("sending card command %s failed: %s\n", desc,
+ gpg_strerror (err));
+ else if (!hexapdu || !strcmp (hexapdu, "undefined"))
+ ;
+ else if (ignore == 0xffff)
+ ; /* Ignore all status words. */
+ else if (sw != 0x9000)
+ {
+ switch (sw)
+ {
+ case 0x6285: err = gpg_error (GPG_ERR_OBJ_TERM_STATE); break;
+ case 0x6982: err = gpg_error (GPG_ERR_BAD_PIN); break;
+ case 0x6985: err = gpg_error (GPG_ERR_USE_CONDITIONS); break;
+ default: err = gpg_error (GPG_ERR_CARD);
+ }
+ if (!(ignore && ignore == sw))
+ log_error ("card command %s failed: %s (0x%04x)\n", desc,
+ gpg_strerror (err), sw);
+ }
+ return err;
+}