Skip to content

Commit

Permalink
assert: introduce fido_assert_authdata_raw_{ptr,len}
Browse files Browse the repository at this point in the history
  • Loading branch information
LDVG authored and kongeo committed Jun 21, 2023
1 parent 671ec80 commit b4bdd16
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/assert.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
}
Expand All @@ -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__);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/export.gnu
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/export.llvm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/export.msvc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/fido.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/fido/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit b4bdd16

Please sign in to comment.