diff --git a/src/assert.c b/src/assert.c index c464b6be..39d63bc9 100644 --- a/src/assert.c +++ b/src/assert.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022 Yubico AB. All rights reserved. + * Copyright (c) 2018-2023 Yubico AB. All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the LICENSE file. * SPDX-License-Identifier: BSD-2-Clause @@ -63,6 +63,10 @@ parse_assert_reply(const cbor_item_t *key, const cbor_item_t *val, void *arg) case 1: /* credential id */ return (cbor_decode_cred_id(val, &stmt->id)); case 2: /* authdata */ + if (fido_blob_decode(val, &stmt->authdata_raw) < 0) { + fido_log_debug("%s: fido_blob_decode", __func__); + return (-1); + } return (cbor_decode_assert_authdata(val, &stmt->authdata_cbor, &stmt->authdata, &stmt->authdata_ext)); case 3: /* signature */ @@ -804,6 +808,7 @@ fido_assert_reset_rx(fido_assert_t *assert) fido_blob_reset(&assert->stmt[i].id); fido_blob_reset(&assert->stmt[i].hmac_secret); fido_blob_reset(&assert->stmt[i].authdata_cbor); + fido_blob_reset(&assert->stmt[i].authdata_raw); fido_blob_reset(&assert->stmt[i].largeblob_key); fido_blob_reset(&assert->stmt[i].sig); fido_assert_reset_extattr(&assert->stmt[i].authdata_ext); @@ -876,6 +881,24 @@ fido_assert_authdata_len(const fido_assert_t *assert, size_t idx) return (assert->stmt[idx].authdata_cbor.len); } +const unsigned char * +fido_assert_authdata_raw_ptr(const fido_assert_t *assert, size_t idx) +{ + if (idx >= assert->stmt_len) + return (NULL); + + return (assert->stmt[idx].authdata_raw.ptr); +} + +size_t +fido_assert_authdata_raw_len(const fido_assert_t *assert, size_t idx) +{ + if (idx >= assert->stmt_len) + return (0); + + return (assert->stmt[idx].authdata_raw.len); +} + const unsigned char * fido_assert_sig_ptr(const fido_assert_t *assert, size_t idx) { @@ -1015,6 +1038,7 @@ static void fido_assert_clean_authdata(fido_assert_stmt *stmt) { fido_blob_reset(&stmt->authdata_cbor); + fido_blob_reset(&stmt->authdata_raw); fido_assert_reset_extattr(&stmt->authdata_ext); memset(&stmt->authdata, 0, sizeof(stmt->authdata)); } @@ -1040,6 +1064,12 @@ fido_assert_set_authdata(fido_assert_t *assert, size_t idx, goto fail; } + if (fido_blob_decode(item, &stmt->authdata_raw) < 0) { + fido_log_debug("%s: fido_blob_decode", __func__); + r = FIDO_ERR_INTERNAL; + goto fail; + } + if (cbor_decode_assert_authdata(item, &stmt->authdata_cbor, &stmt->authdata, &stmt->authdata_ext) < 0) { fido_log_debug("%s: cbor_decode_assert_authdata", __func__); @@ -1072,6 +1102,12 @@ fido_assert_set_authdata_raw(fido_assert_t *assert, size_t idx, stmt = &assert->stmt[idx]; fido_assert_clean_authdata(stmt); + if (fido_blob_set(&stmt->authdata_raw, ptr, len) < 0) { + fido_log_debug("%s: fido_blob_set", __func__); + r = FIDO_ERR_INTERNAL; + goto fail; + } + if ((item = cbor_build_bytestring(ptr, len)) == NULL) { fido_log_debug("%s: cbor_build_bytestring", __func__); r = FIDO_ERR_INTERNAL; diff --git a/src/export.gnu b/src/export.gnu index 9a5a3951..ea6ca7d3 100644 --- a/src/export.gnu +++ b/src/export.gnu @@ -20,6 +20,8 @@ fido_assert_allow_cred; fido_assert_authdata_len; fido_assert_authdata_ptr; + fido_assert_authdata_raw_len; + fido_assert_authdata_raw_ptr; fido_assert_blob_len; fido_assert_blob_ptr; fido_assert_clientdata_hash_len; diff --git a/src/export.llvm b/src/export.llvm index 29f1693c..2a923814 100644 --- a/src/export.llvm +++ b/src/export.llvm @@ -18,6 +18,8 @@ _es384_pk_to_EVP_PKEY _fido_assert_allow_cred _fido_assert_authdata_len _fido_assert_authdata_ptr +_fido_assert_authdata_raw_len +_fido_assert_authdata_raw_ptr _fido_assert_blob_len _fido_assert_blob_ptr _fido_assert_clientdata_hash_len diff --git a/src/export.msvc b/src/export.msvc index c446b909..c5b2edc0 100644 --- a/src/export.msvc +++ b/src/export.msvc @@ -19,6 +19,8 @@ es384_pk_to_EVP_PKEY fido_assert_allow_cred fido_assert_authdata_len fido_assert_authdata_ptr +fido_assert_authdata_raw_len +fido_assert_authdata_raw_ptr fido_assert_blob_len fido_assert_blob_ptr fido_assert_clientdata_hash_len diff --git a/src/fido.h b/src/fido.h index a2ecefb5..914e3776 100644 --- a/src/fido.h +++ b/src/fido.h @@ -80,6 +80,8 @@ void fido_init(int); void fido_set_log_handler(fido_log_handler_t *); const unsigned char *fido_assert_authdata_ptr(const fido_assert_t *, size_t); +const unsigned char *fido_assert_authdata_raw_ptr(const fido_assert_t *, + size_t); const unsigned char *fido_assert_clientdata_hash_ptr(const fido_assert_t *); const unsigned char *fido_assert_hmac_secret_ptr(const fido_assert_t *, size_t); const unsigned char *fido_assert_id_ptr(const fido_assert_t *, size_t); @@ -195,6 +197,7 @@ int fido_dev_set_transport_functions(fido_dev_t *, const fido_dev_transport_t *) int fido_dev_set_timeout(fido_dev_t *, int); size_t fido_assert_authdata_len(const fido_assert_t *, size_t); +size_t fido_assert_authdata_raw_len(const fido_assert_t *, size_t); size_t fido_assert_clientdata_hash_len(const fido_assert_t *); size_t fido_assert_count(const fido_assert_t *); size_t fido_assert_hmac_secret_len(const fido_assert_t *, size_t); diff --git a/src/fido/types.h b/src/fido/types.h index e4b5cf02..01d68200 100644 --- a/src/fido/types.h +++ b/src/fido/types.h @@ -199,6 +199,7 @@ typedef struct _fido_assert_stmt { fido_blob_t hmac_secret; /* hmac secret */ fido_assert_extattr_t authdata_ext; /* decoded extensions */ fido_blob_t authdata_cbor; /* raw cbor payload */ + fido_blob_t authdata_raw; /* raw authdata */ fido_authdata_t authdata; /* decoded authdata payload */ fido_blob_t sig; /* signature of cdh + authdata */ fido_blob_t largeblob_key; /* decoded large blob key */