From f4bb63a728b88f01ac542b09934e55a3021e90f9 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Sat, 17 Nov 2018 01:55:29 +0200 Subject: [PATCH] sketch for get cmd code name --- client/cmdhffido.c | 6 ++++-- client/fido/cbortools.c | 21 +++++++++++++++------ client/fido/cbortools.h | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/client/cmdhffido.c b/client/cmdhffido.c index bcac719ae..b3eb47384 100644 --- a/client/cmdhffido.c +++ b/client/cmdhffido.c @@ -49,6 +49,8 @@ static int CmdHelp(const char *Cmd); +#define FIDO2_CMD_INFO 0x04 + 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}; @@ -82,7 +84,7 @@ int FIDOAuthentication(uint8_t *params, uint8_t paramslen, uint8_t controlb, uin } int FIDO2GetInfo(uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw) { - uint8_t data[] = {0x04}; + uint8_t data[] = {FIDO2_CMD_INFO}; return FIDOExchange((sAPDU){0x80, 0x10, 0x00, 0x00, sizeof(data), data}, Result, MaxResultLen, ResultLen, sw); } @@ -148,7 +150,7 @@ int CmdHFFidoInfo(const char *cmd) { PrintAndLog("FIDO2 version: (%d)", len); dump_buffer((const unsigned char *)buf, len, NULL, 0); - TinyCborPrintFIDOPackage(&buf[1], len - 1); + TinyCborPrintFIDOPackage(FIDO2_CMD_INFO, &buf[1], len - 1); return 0; } diff --git a/client/fido/cbortools.c b/client/fido/cbortools.c index 19f9abc2f..edf881925 100644 --- a/client/fido/cbortools.c +++ b/client/fido/cbortools.c @@ -121,7 +121,11 @@ static CborError dumpelm(CborValue *it, bool *got_next, int nestingLevel) { return CborNoError; } -static CborError dumprecursive(CborValue *it, bool isMapType, int nestingLevel) { +char *getCmdCodeDescription (uint8_t cmdCode, uint8_t memberNum) { + return NULL; +} + +static CborError dumprecursive(uint8_t cmdCode, CborValue *it, bool isMapType, int nestingLevel) { int elmCount = 0; while (!cbor_value_at_end(it)) { CborError err; @@ -141,7 +145,7 @@ static CborError dumprecursive(CborValue *it, bool isMapType, int nestingLevel) err = cbor_value_enter_container(it, &recursed); if (err) return err; // parse error - err = dumprecursive(&recursed, (type == CborMapType), nestingLevel + 1); + err = dumprecursive(cmdCode, &recursed, (type == CborMapType), nestingLevel + 1); if (err) return err; // parse error err = cbor_value_leave_container(it, &recursed); @@ -157,8 +161,13 @@ static CborError dumprecursive(CborValue *it, bool isMapType, int nestingLevel) err = dumpelm(it, &got_next, (isMapType && (elmCount % 2)) ? 0 : nestingLevel); if (err) return err; -// if (nestingLevel == 1 && isMapType && !(elmCount % 2)) -// printf(" ()"); + if (cmdCode > 0 && nestingLevel == 1 && isMapType && !(elmCount % 2)) { + int64_t val; + cbor_value_get_int64(it, &val); + char *desc = getCmdCodeDescription(cmdCode, val); + if (desc) + printf(" (%s)", desc); + } break; } } @@ -187,7 +196,7 @@ int TinyCborInit(uint8_t *data, size_t length, CborValue *cb) { return 0; } -int TinyCborPrintFIDOPackage(uint8_t *data, size_t length) { +int TinyCborPrintFIDOPackage(uint8_t cmdCode, uint8_t *data, size_t length) { CborValue cb; int res; res = TinyCborInit(data, length, &cb); @@ -196,7 +205,7 @@ int TinyCborPrintFIDOPackage(uint8_t *data, size_t length) { - CborError err = dumprecursive(&cb, false, 0); + CborError err = dumprecursive(cmdCode, &cb, false, 0); if (err) { fprintf(stderr, "CBOR parsing failure at offset %d: %s\n", diff --git a/client/fido/cbortools.h b/client/fido/cbortools.h index f49751b56..93d46209f 100644 --- a/client/fido/cbortools.h +++ b/client/fido/cbortools.h @@ -17,6 +17,6 @@ #include #include -extern int TinyCborPrintFIDOPackage(uint8_t *data, size_t length); +extern int TinyCborPrintFIDOPackage(uint8_t cmdCode, uint8_t *data, size_t length); #endif /* __CBORTOOLS_H__ */