From fbd3f981c6674481b8e085601d0be848dd71aaa5 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Tue, 16 Oct 2018 19:02:14 +0300 Subject: [PATCH] some refactoring and add new commands for fido u2f --- client/cmdhffido.c | 54 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/client/cmdhffido.c b/client/cmdhffido.c index 11f99b63..49d57a68 100644 --- a/client/cmdhffido.c +++ b/client/cmdhffido.c @@ -37,7 +37,13 @@ static int CmdHelp(const char *Cmd); -int CmdHFMFPInfo(const char *cmd) { +int FIDOSelect(bool ActivateField, bool LeaveFieldON, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw) { + uint8_t data[] = {0xA0, 0x00, 0x00, 0x06, 0x47, 0x2F, 0x00, 0x01}; + + return EMVSelect(ActivateField, LeaveFieldON, data, sizeof(data), Result, MaxResultLen, ResultLen, sw, NULL); +} + +int CmdHFFidoInfo(const char *cmd) { if (cmd && strlen(cmd) > 0) PrintAndLog("WARNING: command don't have any parameters.\n"); @@ -49,14 +55,10 @@ int CmdHFMFPInfo(const char *cmd) { PrintAndLog("--------------------------------------------"); SetAPDULogging(false); - uint8_t data[APDU_AID_LEN] = {0}; - int datalen = 0; - param_gethex_to_eol("A0000006472F0001", 0, data, sizeof(data), &datalen); - uint8_t buf[APDU_RES_LEN] = {0}; size_t len = 0; uint16_t sw = 0; - int res = EMVSelect(true, false, data, datalen, buf, sizeof(buf), &len, &sw, NULL); + int res = FIDOSelect(true, false, buf, sizeof(buf), &len, &sw); if (res) return res; @@ -84,10 +86,46 @@ int CmdHFMFPInfo(const char *cmd) { return 0; } +int CmdHFFidoRegister(const char *cmd) { + + // here will be command extraction + // challenge parameter [32 bytes] - The challenge parameter is the SHA-256 hash of the Client Data, a stringified JSON data structure that the FIDO Client prepares + // application parameter [32 bytes] - The application parameter is the SHA-256 hash of the UTF-8 encoding of the application identity + + SetAPDULogging(true); + + uint8_t buf[APDU_RES_LEN] = {0}; + size_t len = 0; + uint16_t sw = 0; + int res = FIDOSelect(true, false, buf, sizeof(buf), &len, &sw); + + if (res) { + PrintAndLog("Can't select authenticator. Exit..."); + return res; + } + + if (sw != 0x9000) { + PrintAndLog("APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff)); + return 2; + } + + + + + return 0; +}; + +int CmdHFFidoAuthenticate(const char *cmd) { + + return 0; +}; + static command_t CommandTable[] = { - {"help", CmdHelp, 1, "This help"}, - {"info", CmdHFMFPInfo, 0, "Info about FIDO tag"}, + {"help", CmdHelp, 1, "This help."}, + {"info", CmdHFFidoInfo, 0, "Info about FIDO tag."}, + {"reg", CmdHFFidoRegister, 0, "FIDO U2F Registration Message."}, + {"auth", CmdHFFidoAuthenticate, 0, "FIDO U2F Authentication Message."}, {NULL, NULL, 0, NULL} };