From f7354c705d48ef5f5164fe6ede027238a4770b3c Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Mon, 26 Nov 2018 19:16:47 +0200 Subject: [PATCH] extract some descriptions from cose_key --- client/fido/cose.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ client/fido/cose.h | 1 + 2 files changed, 50 insertions(+) diff --git a/client/fido/cose.c b/client/fido/cose.c index 90bb66308..bc86fee65 100644 --- a/client/fido/cose.c +++ b/client/fido/cose.c @@ -11,6 +11,8 @@ // #include "cose.h" +#include +#include "cbortools.h" #include "util.h" static const char COSEEmptyStr[] = ""; @@ -126,8 +128,55 @@ const char *GetCOSEAlgDescription(int id) { return COSEEmptyStr; } +COSEValueNameDesc_t *GetCOSEktyElm(int id) { + for (int i = 0; i < ARRAYLEN(COSEKeyTypeValueDesc); i++) + if (COSEKeyTypeValueDesc[i].Value == id) + return &COSEKeyTypeValueDesc[i]; + return NULL; +} + +const char *GetCOSEktyDescription(int id) { + COSEValueNameDesc_t *elm = GetCOSEktyElm(id); + if (elm) + return elm->Description; + return COSEEmptyStr; +} + int COSEGetECDSAKey(uint8_t *data, size_t datalen, bool verbose, uint8_t *public_key) { + CborParser parser; + CborValue map; + int64_t i64; + + if(verbose) + PrintAndLog("----------- CBOR decode ----------------"); + // kty + int res = CborMapGetKeyById(&parser, &map, data, datalen, 1); + if(!res) { + cbor_value_get_int64(&map, &i64); + if(verbose) + PrintAndLog("kty [%lld] %s", (long long)i64, GetCOSEktyDescription(i64)); + } + + // algorithm + res = CborMapGetKeyById(&parser, &map, data, datalen, 3); + if(!res) { + cbor_value_get_int64(&map, &i64); + if(verbose) + PrintAndLog("algorithm [%lld] %s", (long long)i64, GetCOSEAlgDescription(i64)); + } + + // curve + res = CborMapGetKeyById(&parser, &map, data, datalen, -1); + if(!res) { + cbor_value_get_int64(&map, &i64); + if(verbose) + PrintAndLog("curve [%lld] %s", (long long)i64, GetCOSEAlgDescription(i64)); + } + + + if(verbose) + PrintAndLog("----------- CBOR decode ----------------"); return 0; } diff --git a/client/fido/cose.h b/client/fido/cose.h index 1b685e4a8..209239ec4 100644 --- a/client/fido/cose.h +++ b/client/fido/cose.h @@ -19,6 +19,7 @@ extern const char *GetCOSEAlgName(int id); extern const char *GetCOSEAlgDescription(int id); +extern const char *GetCOSEktyDescription(int id); extern int COSEGetECDSAKey(uint8_t *data, size_t datalen, bool verbose, uint8_t *public_key);