From 317ea305298d8327ecf601815514479ccf04eb59 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Tue, 27 Nov 2018 13:45:29 +0200 Subject: [PATCH] refactoring and GetAssertion works --- client/cmdhffido.c | 20 +++++++++++++++++--- client/fido/cbortools.c | 7 ++++++- client/fido/fidocore.c | 15 +++++++++------ client/fido/fidocore.h | 3 ++- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/client/cmdhffido.c b/client/cmdhffido.c index db427236c..b63f8582f 100644 --- a/client/cmdhffido.c +++ b/client/cmdhffido.c @@ -759,7 +759,7 @@ int CmdHFFido2MakeCredential(const char *cmd) { } // parse returned cbor - MakeCredentionalParseRes(root, &buf[1], len - 1, verbose, verbose2, showCBOR, showDERTLV); + FIDO2MakeCredentionalParseRes(root, &buf[1], len - 1, verbose, verbose2, showCBOR, showDERTLV); if (root) { res = json_dump_file(root, fname, JSON_INDENT(2)); @@ -875,14 +875,28 @@ int CmdHFFido2GetAssertion(const char *cmd) { return 0; } -/* PrintAndLog("MakeCredential result (%d b) OK.", len); + PrintAndLog("GetAssertion result (%d b) OK.", len); if (showCBOR) { PrintAndLog("CBOR get assertion response:"); PrintAndLog("---------------- CBOR ------------------"); - TinyCborPrintFIDOPackage(fido2CmdMakeCredential, true, &buf[1], len - 1); + TinyCborPrintFIDOPackage(fido2CmdGetAssertion, true, &buf[1], len - 1); PrintAndLog("---------------- CBOR ------------------"); } + + // parse returned cbor + FIDO2GetAssertionParseRes(root, &buf[1], len - 1, verbose, verbose2, showCBOR); + +/* if (root) { + res = json_dump_file(root, fname, JSON_INDENT(2)); + if (res) { + PrintAndLog("ERROR: can't save the file: %s", fname); + return 200; + } + PrintAndLog("File `%s` saved.", fname); + } */ + json_decref(root); + return 0; }; diff --git a/client/fido/cbortools.c b/client/fido/cbortools.c index 59dbe9b4d..8ab104a1c 100644 --- a/client/fido/cbortools.c +++ b/client/fido/cbortools.c @@ -455,7 +455,12 @@ CborError CborGetStringValueBuf(CborValue *elm) { }; int CBOREncodeElm(json_t *root, char *rootElmId, CborEncoder *encoder) { - json_t *elm = json_object_get(root, rootElmId); + json_t *elm = NULL; + if (rootElmId && strlen(rootElmId) && rootElmId[0] == '$') + elm = json_path_get(root, rootElmId); + else + elm = json_object_get(root, rootElmId); + if (!elm) return 1; diff --git a/client/fido/fidocore.c b/client/fido/fidocore.c index 88d386f02..38b147125 100644 --- a/client/fido/fidocore.c +++ b/client/fido/fidocore.c @@ -352,7 +352,7 @@ bool CheckrpIdHash(json_t *json, uint8_t *hash) { return !memcmp(hash, hash2, 32); } -int MakeCredentionalParseRes(json_t *root, uint8_t *data, size_t dataLen, bool verbose, bool verbose2, bool showCBOR, bool showDERTLV) { +int FIDO2MakeCredentionalParseRes(json_t *root, uint8_t *data, size_t dataLen, bool verbose, bool verbose2, bool showCBOR, bool showDERTLV) { CborParser parser; CborValue map, mapsmt; int res; @@ -567,17 +567,15 @@ int FIDO2CreateGetAssertionReq(json_t *root, uint8_t *data, size_t maxdatalen, s cbor_encoder_init(&encoder, data, maxdatalen, 0); // create main map - res = cbor_encoder_create_map(&encoder, &map, 5); + res = cbor_encoder_create_map(&encoder, &map, 3); fido_check_if(res) { // rpId res = cbor_encode_uint(&map, 1); fido_check_if(res) { -// char hashval[300] = {0}; -// JsonLoadStr(json, "$.RelyingPartyEntity.id", hashval); - res = CBOREncodeElm(root, "RelyingPartyEntity", &map); + res = CBOREncodeElm(root, "$.RelyingPartyEntity.id", &map); fido_check(res); - } + } // clientDataHash res = cbor_encode_uint(&map, 2); @@ -602,3 +600,8 @@ int FIDO2CreateGetAssertionReq(json_t *root, uint8_t *data, size_t maxdatalen, s return 0; } + +int FIDO2GetAssertionParseRes(json_t *root, uint8_t *data, size_t dataLen, bool verbose, bool verbose2, bool showCBOR) { + + return 0; +} diff --git a/client/fido/fidocore.h b/client/fido/fidocore.h index 4baf029bb..092261104 100644 --- a/client/fido/fidocore.h +++ b/client/fido/fidocore.h @@ -50,7 +50,8 @@ extern char *fido2GetCmdErrorDescription(uint8_t errorCode); extern bool CheckrpIdHash(json_t *json, uint8_t *hash); extern int FIDO2CreateMakeCredentionalReq(json_t *root, uint8_t *data, size_t maxdatalen, size_t *datalen); -extern int MakeCredentionalParseRes(json_t *root, uint8_t *data, size_t dataLen, bool verbose, bool verbose2, bool showCBOR, bool showDERTLV); +extern int FIDO2MakeCredentionalParseRes(json_t *root, uint8_t *data, size_t dataLen, bool verbose, bool verbose2, bool showCBOR, bool showDERTLV); extern int FIDO2CreateGetAssertionReq(json_t *root, uint8_t *data, size_t maxdatalen, size_t *datalen); +extern int FIDO2GetAssertionParseRes(json_t *root, uint8_t *data, size_t dataLen, bool verbose, bool verbose2, bool showCBOR); #endif /* __FIDOCORE_H__ */