From d2dd0f161a7ebdd3236e5d75d763f5ada69d5429 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Sun, 5 Jul 2026 01:21:21 +0200 Subject: [PATCH] Fix hmac-secret-mc check. Signed-off-by: Pol Henarejos --- src/fido/cbor_make_credential.c | 28 ++++++++++++------------- tests/pico-fido/test_035_hmac_secret.py | 20 ++++++++++++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/fido/cbor_make_credential.c b/src/fido/cbor_make_credential.c index 4ddc89e..c3be020 100644 --- a/src/fido/cbor_make_credential.c +++ b/src/fido/cbor_make_credential.c @@ -212,6 +212,20 @@ int cbor_make_credential(const uint8_t *data, size_t len) { } } CBOR_PARSE_MAP_END(map, 1); + if (hmac_secret_mc && extensions.hmac_secret != ptrue) { + CBOR_ERROR(CTAP2_ERR_MISSING_PARAMETER); + } + if (hmac_secret_mc) { + if (kax.present == false || kay.present == false || crv == 0 || hmac_alg == 0 || + salt_enc.present == false || salt_enc.len == 0 || + salt_auth.present == false || salt_auth.len == 0) { + CBOR_ERROR(CTAP2_ERR_MISSING_PARAMETER); + } + if (salt_enc.len != 32 + (hmacSecretPinUvAuthProtocol - 1) * IV_SIZE && + salt_enc.len != 64 + (hmacSecretPinUvAuthProtocol - 1) * IV_SIZE) { + CBOR_ERROR(CTAP1_ERR_INVALID_PARAMETER); + } + } rp_id = rp.id.data; user_name = user.parent.name.data; display_name = user.displayName.data; @@ -427,20 +441,6 @@ int cbor_make_credential(const uint8_t *data, size_t len) { CBOR_ERROR(CTAP2_ERR_INVALID_OPTION); } - if (hmac_secret_mc && extensions.hmac_secret != ptrue) { - CBOR_ERROR(CTAP2_ERR_MISSING_PARAMETER); - } - if (hmac_secret_mc) { - if (kax.present == false || kay.present == false || crv == 0 || hmac_alg == 0 || - salt_enc.present == false || salt_auth.present == false) { - CBOR_ERROR(CTAP2_ERR_MISSING_PARAMETER); - } - if (salt_enc.len != 32 + (hmacSecretPinUvAuthProtocol - 1) * IV_SIZE && - salt_enc.len != 64 + (hmacSecretPinUvAuthProtocol - 1) * IV_SIZE) { - CBOR_ERROR(CTAP1_ERR_INVALID_PARAMETER); - } - } - if (options.up == ptrue || options.up == NULL) { //14.1 if (pinUvAuthParam.present == true) { if (getUserPresentFlagValue() == false) { diff --git a/tests/pico-fido/test_035_hmac_secret.py b/tests/pico-fido/test_035_hmac_secret.py index ccd276c..7c40202 100644 --- a/tests/pico-fido/test_035_hmac_secret.py +++ b/tests/pico-fido/test_035_hmac_secret.py @@ -121,6 +121,26 @@ def test_missing_saltEnc(device,): device.GA(extensions={"hmac-secret": { 3: b'1234'}}) assert e.value.code == CtapError.ERR.MISSING_PARAMETER +def test_make_credential_hmac_secret_mc_empty_salt(device): + key_agreement = { + 1: 2, + 3: -25, + -1: 1, + -2: b'\x00' * 32, + -3: b'\x00' * 32, + } + with pytest.raises(CtapError) as e: + device.MC(extensions={ + "hmac-secret": True, + "hmac-secret-mc": { + 1: key_agreement, + 2: b'', + 3: b'\x00' * 32, + 4: 2, + }, + }) + assert e.value.code == CtapError.ERR.MISSING_PARAMETER + def test_bad_auth(device, MCHmacSecret): key_agreement = {