sketch for get cmd code name

This commit is contained in:
merlokk 2018-11-17 01:55:29 +02:00
parent 8201526f6e
commit f4bb63a728
3 changed files with 20 additions and 9 deletions

View file

@ -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;
}

View file

@ -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",

View file

@ -17,6 +17,6 @@
#include <stddef.h>
#include <stdint.h>
extern int TinyCborPrintFIDOPackage(uint8_t *data, size_t length);
extern int TinyCborPrintFIDOPackage(uint8_t cmdCode, uint8_t *data, size_t length);
#endif /* __CBORTOOLS_H__ */