-
Notifications
You must be signed in to change notification settings - Fork 190
Move TLS 1.3 KDF into the FIPS module and wire up ACVP#3247
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@ ## main #3247 +/- ## ========================================== - Coverage 78.17% 78.16% -0.02% ========================================== Files 689 689 Lines 123733 123751 +18 Branches 17197 17204 +7 ========================================== Hits 96724 96724 - Misses 26091 26108 +17 - Partials 918 919 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1eb31e0 to
455cb10
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
517d39b to
3a3e644
Compare
cbb4cbd to
2009ae3
Compare
2009ae3 to
76d4d8b
Compare
Wire up the TLS-v1.3 (RFC 8446) KDF as an ACVP-testable algorithm in the FIPS modulewrapper. The acvptool subprocess handler (tls13.go) already existed but had no corresponding modulewrapper implementation. Add HKDFExtract and HKDFExpandLabel commands to the modulewrapper, register the TLS-v1.3 algorithm in the ACVP config (SHA2-256/384, DHE/PSK/PSK-DHE modes), and include NIST-published test vectors from the ACVP-Server repository. All 250 NIST test cases pass.
Introduces CRYPTO_tls13_hkdf_expand_label in crypto/fipsmodule/tls/kdf.c, mirroring the CRYPTO_tls1_prf pattern already in that file. The function builds the HkdfLabel structure (RFC 8446 §7.1) via CBB and calls HKDF_expand, bracketed by FIPS_service_indicator_lock_state / unlock_state and a post-success TLS13_KDF_verify_service_indicator call that approves SHA2-256 and SHA2-384 (matching what the ACVP config registers). Consumers now delegate: * ssl/tls13_enc.cc's hkdf_expand_label collapses to a thin wrapper. * The ACVP modulewrapper's HKDFExpandLabel delegates to the same function, so ACVP exercises the actual FIPS-module code path instead of a parallel label-construction reimplementation. A TLS13-KDF KAT (HKDF_extract -> CRYPTO_tls13_hkdf_expand_label, using the RFC 8448 early-secret / 'c e traffic' derivation) is added to the FIPS self-test, along with a matching break-kat.go entry. A new parameterised TLS13KDF_ServiceIndicatorTest covers the approval policy across SHA-1 / SHA-224 / SHA-256 / SHA-384 / SHA-512.
The RFC 8446 Section 7.1 "opaque label<7..255>" lower bound on the HkdfLabel.label field does not match real caller behavior: SSL_export_keying_material permits a zero-length caller label, which the ssl/test/runner exerciser relies on for TLS 1.3 exporter interop tests. Neither the pre-refactor ssl/tls13_enc.cc hkdf_expand_label nor BoringSSL's CRYPTO_tls13_hkdf_expand_label enforce the lower bound, so rejecting label_len == 0 here regressed every TLS-TLS13-* and QUIC-TLS13-* runner test that uses exportKeyingMaterial. The upper bound on out_len is already enforced implicitly by CBB_add_u16, so the explicit check is redundant. Drop the whole block and document what CBB enforces for us.
tests/ci/run_fips_callback_tests.sh::run_all_break_tests enumerates every KAT known to util/fipstools/break-kat.go, tampers the crypto_test binary for each, and runs FIPSCallback.PowerOnSelfTests expecting the AWS_LC_fips_failure_callback to be invoked with the exact failure-message sequence listed in crypto/fips_callback_test.cc::kat_failure_messages.
This PR added TLS13-KDF to break-kat.go and to boringssl_self_test_fast but forgot to teach the callback test about it, so when the broken binary runs with FIPS_CALLBACK_TEST_EXPECTED_FAILURE=TLS13-KDF the lookup misses and the test body hits FAIL("Failed to find expected message for ... TLS13-KDF"). That's what's blocking the fips-callback-amazonlinux:2023-aarch64 job.
The failure-message sequence mirrors TLS-KDF (same enclosing boringssl_self_test_fast path, so the outer "Power on self test failed" string is produced from bcm.c::BORINGSSL_bcm_power_on_self_test). The Expected/Calculated hex pair is derived by running the HKDF-Extract(SHA256, IKM=0^32, salt=kTLS13Salt) then CRYPTO_tls13_hkdf_expand_label(label="c e traffic", context=kTLS13ClientHelloHash) chain that self_check.c uses; break-kat zeroes the 32-byte kTLS13Secret in the binary image, producing the given Calculated bytes.
Address review feedback: - Rename the new modulewrapper ACVP handlers HKDFExtract/HKDFExpandLabel to TLS13_HKDFExtract/TLS13_HKDFExpandLabel. The ACVP command strings on the wire are unchanged; only the C++ identifiers move. This matches the existing TLSKDF / "TLSKDF/1.2/..." convention in the same file and disambiguates the new helpers from the generic HKDF / HKDF_expand helpers (KDA/HKDF and KDF/Feedback) already defined in this TU. - Add in-code attribution for the parts of this change that are ported from BoringSSL: the pair of ACVP handlers in modulewrapper.cc and the HkdfLabel/CBB construction in CRYPTO_tls13_hkdf_expand_label. The comment on the latter also calls out that the FIPS service-indicator lock/unlock and TLS13_KDF_verify_service_indicator call are AWS-LC-specific, to make the port vs. novel split explicit for future reviewers and for resyncs with BoringSSL upstream.
Address review comments from Nevine on PR aws#3247: * include/openssl/kdf.h: correct the documented contract for CRYPTO_tls13_hkdf_expand_label to match the actual implementation behavior. The previous text required |label_len| in [1, 249] but commit 12e6a75 intentionally stopped enforcing the lower bound to support SSL_export_keying_material callers that pass an empty label. * crypto/fipsmodule/tls/kdf.c: restore the explicit |out_len > UINT16_MAX| check that was removed in 12e6a75. CBB_add_u16 cannot enforce the bound on its own because the size_t-to-uint16_t narrowing happens in the implicit conversion at the call site, before CBB_add_u16 ever sees the value, silently producing a spec-violating HkdfLabel.length on oversized requests. The empty-label allowance from 12e6a75 stays; only the upper-bound check comes back. Comment clarified to explain which bounds CBB does and does not enforce.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit, but kHash[32] = {0} is fixed at 32 bytes even when the test exercises SHA-384 (output is 48 bytes). It doesn't really effect the correctness of the implementation though, just something that felt off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we introduce a check to bail early and enforce this?
if (label_len > 249 || hash_len > 255) {
OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
return 0;
}
Uh oh!
There was an error while loading. Please reload this page.
Issues
Addresses:
Description of changes:
Moves TLS 1.3 HKDF-Expand-Label (RFC 8446 §7.1) into the FIPS module and wires up the ACVP modulewrapper so we advertise
TLS-v1.3as a validated composite algorithm.CRYPTO_tls13_hkdf_expand_labelincrypto/fipsmodule/tls/kdf.c— builds theHkdfLabelstructure, callsHKDF_expand, handles the FIPS service indicator (approved for SHA2-256 / SHA2-384).Delegates both consumers —
ssl/tls13_enc.cc::hkdf_expand_labelbecomes a thin wrapper; the modulewrapper'sTLS13_HKDFExpandLabelhandler (wire commandHKDFExpandLabel/<HASH>) routes through the same code path.ACVP wiring — registers
TLS-v1.3/RFC8446ingetConfig, implementsHKDFExtract/andHKDFExpandLabel/commands, adds 250 NIST test vectors from the ACVP-Server repo.FIPS self-test — TLS13-KDF KAT in
self_check.cplus matchingbreak-kat.goentry.Call-outs:
Public API surface.
CRYPTO_tls13_hkdf_expand_labelis declared ininclude/openssl/kdf.halongsideCRYPTO_tls1_prffor consistency. BoringSSL keeps it private; happy to switch if reviewers prefer tighter scope.Ported from BoringSSL. The
HkdfLabel/CBBconstruction inCRYPTO_tls13_hkdf_expand_label, the ACVP handlers, thegetConfigblock, and the KAT vectors (commit480344d4fa) are all ported from BoringSSL. The FIPS service-indicator wiring is AWS-LC-specific. Attribution comments are in-line in the diff.Helper naming. The modulewrapper handlers are
TLS13_HKDFExtract/TLS13_HKDFExpandLabel(diverging from BoringSSL's names) to disambiguate from the pre-existing genericHKDF/HKDF_expandhelpers in the same TU.Testing:
All existing
crypto_test,ssl_test, andacvp_testspass. New coverage: fiveTLS13KDF_ServiceIndicatorTestcases and the TLS13-KDF self-test KAT.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.