diff --git a/client/fido/cbortools.c b/client/fido/cbortools.c index ad6931030..59dbe9b4d 100644 --- a/client/fido/cbortools.c +++ b/client/fido/cbortools.c @@ -463,3 +463,19 @@ int CBOREncodeElm(json_t *root, char *rootElmId, CborEncoder *encoder) { return res; } + +CborError CBOREncodeClientDataHash(json_t *root, CborEncoder *encoder) { + uint8_t buf[100] = {0}; + size_t jlen; + + JsonLoadBufAsHex(root, "$.ClientDataHash", buf, sizeof(buf), &jlen); + + // fill with 0x00 if not found + if (!jlen) + jlen = 32; + + int res = cbor_encode_byte_string(encoder, buf, jlen); + cbor_check(res); + + return 0; +} diff --git a/client/fido/cbortools.h b/client/fido/cbortools.h index c7ef7658a..1e3fa8c0f 100644 --- a/client/fido/cbortools.h +++ b/client/fido/cbortools.h @@ -33,5 +33,6 @@ extern CborError CborGetStringValue(CborValue *elm, char *data, size_t maxdatale extern CborError CborGetStringValueBuf(CborValue *elm); extern int CBOREncodeElm(json_t *root, char *rootElmId, CborEncoder *encoder); +extern CborError CBOREncodeClientDataHash(json_t *root, CborEncoder *encoder); #endif /* __CBORTOOLS_H__ */ diff --git a/client/fido/fidocore.c b/client/fido/fidocore.c index 21889cfd6..88d386f02 100644 --- a/client/fido/fidocore.c +++ b/client/fido/fidocore.c @@ -282,22 +282,6 @@ int FIDOCheckDERAndGetKey(uint8_t *der, size_t derLen, bool verbose, uint8_t *pu #define fido_check_if(r) if ((r) != CborNoError) {return r;} else #define fido_check(r) if ((r) != CborNoError) return r; -int CBOREncodeClientDataHash(json_t *root, CborEncoder *encoder) { - uint8_t buf[100] = {0}; - size_t jlen; - - JsonLoadBufAsHex(root, "$.ClientDataHash", buf, sizeof(buf), &jlen); - - // fill with 0x00 if not found - if (!jlen) - jlen = 32; - - int res = cbor_encode_byte_string(encoder, buf, jlen); - fido_check(res); - - return 0; -} - int FIDO2CreateMakeCredentionalReq(json_t *root, uint8_t *data, size_t maxdatalen, size_t *datalen) { if (datalen) *datalen = 0;