From 5495ee405d145acd3ed778839b1e997371ff2c74 Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Tue, 4 Feb 2014 09:14:13 +0100 Subject: [PATCH] implement reset instruction --- cmdline.ggo | 2 +- yubico-piv-tool.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cmdline.ggo b/cmdline.ggo index 7f54633..1c3e417 100644 --- a/cmdline.ggo +++ b/cmdline.ggo @@ -27,7 +27,7 @@ option "verbose" v "Print more information" int optional default="0" argoptional option "reader" r "Only use a matching reader" string optional option "key" k "Authentication key to use" string optional default="010203040506070801020304050607080102030405060708" -option "action" a "Action to take" values="version","generate","set-mgm-key" enum +option "action" a "Action to take" values="version","generate","set-mgm-key","reset" enum option "slot" s "What key slot to operate on" values="9a","9c","9d","9e" enum optional option "algorithm" A "What algorithm to use" values="RSA1024","RSA2048","ECCP256" enum optional default="RSA2048" option "new-key" n "New authentication key to use" string optional diff --git a/yubico-piv-tool.c b/yubico-piv-tool.c index 2ff40e7..66ef5eb 100644 --- a/yubico-piv-tool.c +++ b/yubico-piv-tool.c @@ -299,6 +299,23 @@ static bool set_mgm_key(SCARDHANDLE *card, unsigned const char *new_key, int ver return false; } +static bool reset(SCARDHANDLE *card, int verbose) { + APDU apdu; + unsigned char data[0xff]; + unsigned long recv_len = sizeof(data); + int sw; + + memset(apdu.raw, 0, sizeof(apdu)); + /* note: the reset function is only available when both pins are blocked. */ + apdu.st.ins = 0xfb; + sw = send_data(card, apdu, 4, data, &recv_len, verbose); + + if(sw == 0x9000) { + return true; + } + return false; +} + int send_data(SCARDHANDLE *card, APDU apdu, unsigned int send_len, unsigned char *data, unsigned long *recv_len, int verbose) { long rc; int sw; @@ -410,6 +427,10 @@ int main(int argc, char *argv[]) { fprintf(stderr, "The set-mgm-key action needs the new-key (-n) argument.\n"); return EXIT_FAILURE; } + } else if(args_info.action_arg == action_arg_reset) { + if(reset(&card, verbosity) == false) { + return EXIT_FAILURE; + } } return EXIT_SUCCESS;