684 Commits

Author SHA1 Message Date
Gilles Peskine
d8d5ea7cbc
Merge pull request #10965 from bjwtaylor/tl13-transform-resource-leak-4.1
Backport 4.1: Fix resource leak in populate transform
2026-10-27 12:34:51 +00:00
Ben Taylor
433c88651a Add comment explaining the derivation of the number of keys
This is a manual backport, not a direct cherry-pick, because the 4.1 key-count helper is located separately in the test suite. Place the explanation next to the existing formula.

Signed-off-by: Ben Taylor <ben.taylor@linaro.org>

(cherry picked from commit e0766f1b4a2133ea043e10cef86cc1c76f69b49b)
2026-10-21 08:28:28 +01:00
Ben Taylor
49fe7fc873 Add test for tansform setup resource leak
This is a manual backport, not a direct cherry-pick, because the target test header differs. The regression case is placed in the 4.1 suite without unrelated development tests.

Signed-off-by: Ben Taylor <ben.taylor@linaro.org>

(cherry picked from commit 95e95268a4c26608612f34f2bb76ff1dfa9ded0a)
2026-10-21 08:27:38 +01:00
Naveed
ff9388a77d Add an out_cid case to the ssl_context_load OOB length test
Cover the serialized out_cid length with the same construction as the
in_cid one, and rename the existing case to IN_CID accordingly. Give
the client and server sentinel CIDs different lengths so the two
fields can be told apart in the serialized data. Skip the CID cases
under configurations of MBEDTLS_SSL_CID_IN_LEN_MAX and
MBEDTLS_SSL_CID_OUT_LEN_MAX that the test does not support.

Signed-off-by: Naveed <naveed@bugqore.com>
2026-10-04 22:44:50 +05:30
Naveed
aed8d01bf2 Guard the in_cid size check in the CID case
The previous approach documented the in_cid_len > sizeof(in_cid) cap
as untestable, since the overflowing memcpy() lands inside the
transform structure where sanitizers cannot see it. It can be guarded
without a sanitizer: grow the in_cid field in the loaded data (keep
its bytes, pad to MBEDTLS_SSL_CID_IN_LEN_MAX + 1) and append the rest
of the serialized data untouched, so the in-buffer bounds check passes
and the cap is what must reject the length. Without the cap the
remaining data parses correctly aligned and the load succeeds, so the
test catches a regression by the return value alone.

Signed-off-by: Naveed <naveed@bugqore.com>
2026-10-04 22:44:50 +05:30
Naveed
bccab06703 Keep the out_cid length byte in the CID case's truncated data
With the loaded data cut right after the in_cid bytes, even the
pristine in_cid length tripped the (end - p) < in_cid_len + 1u bounds
check, since the out_cid length byte it accounts for was missing: the
truncation, not the corruption, was what got rejected. Keep the
out_cid length byte in the loaded data, so the pristine length passes
the check and only the corrupted length trips it. Also document why
this pre-existing check is the only one in the in_cid path that a
regression test can guard: the in_cid_len > sizeof(in_cid) cap
protects the memcpy() destination, and without it the overflow lands
in the out_cid field inside the transform structure, where sanitizers
cannot see it.

Signed-off-by: Naveed <naveed@bugqore.com>
2026-10-04 22:44:50 +05:30
Naveed
a3c9450cd2 Fix the CID case of the OOB length regression test
The corrupted in_cid length exercised the pre-existing size-cap check,
not the bounds check: the in_cid field is not the last one serialized,
and the MBEDTLS_SSL_CID_IN_LEN_MAX cap is smaller than the size of the
fields that follow it, so no corrupted length could reach past the end
of the full buffer, and reverting the bounds check did not change the
test's outcome. Truncate the loaded data right after the in_cid bytes,
load from a tightly allocated copy, and corrupt the length to one byte
past that end, so that reverting the bounds check now trips ASan with
an out-of-bounds read in the memcpy(), like the ALPN case.

Signed-off-by: Naveed <naveed@bugqore.com>
2026-10-04 22:44:50 +05:30
Naveed
e0177ae7e9 Address review: verify pristine load, corrupt ALPN length by exactly one
Load the serialized context once before corrupting it, to check the
data is well-formed to begin with. Shorten the second ALPN protocol so
the corrupted length overruns the serialized data by exactly one byte,
and assert that property at runtime. Document that the corrupted load
usually fails even without the bounds check, so the regression is only
caught when the suite runs under ASan or Valgrind.

Signed-off-by: Naveed <naveed@bugqore.com>
2026-10-04 22:44:50 +05:30
Naveed
63f1c42b7c Merge the two ssl_context_load OOB length tests
Fold ssl_context_load_rejects_oob_cid_length and
ssl_context_load_rejects_oob_alpn_length into a single parameterized
test function, since they shared most of their code.

Signed-off-by: Naveed <naveed@bugqore.com>
2026-10-04 22:44:50 +05:30
Naveed
5ece3de4d2 Reject out-of-bounds ALPN length in ssl_context_load
The serialized ALPN length was passed to memcmp() against each configured protocol without checking it against the remaining serialized data, so a malformed context could read past the end of the buffer. Bound it before the comparison, like the adjacent CID fields.

Signed-off-by: Naveed <naveed@bugqore.com>
2026-10-04 22:44:49 +05:30
Valerio Setti
1b40f0d573 tests: ssl: refine RSA dependencies of test functions
- mbedtls_endpoint_sanity() is only used for TLS 1.2 tests, where RSA
  signatures are limited to PKCS#1 v1.5. Moreover the test does not
  perform a full handshake, so only being able to hold an RSA public key
  is required here: PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY.
- move_handshake_to_state() is used for both TLS 1.2 and TLS 1.3 tests
  and the RSA capabilities it needs depend on the handshake state being
  reached, so the RSA dependency is set on test data instead.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-09-25 09:18:41 +02:00
Gilles Peskine
798b0b9f2d
Merge pull request #10847 from valeriosetti/remove-ecp-deps-backport4.1
[4.1] Reduce dependencies on private `ecp.h` header
2026-08-04 13:43:23 +00:00
Naveed
84f571eafb Force sentinel session ID length in serialized-load test
Signed-off-by: Naveed <naveed@bugqore.com>
2026-08-03 13:44:23 +05:30
Naveed
1933e828d0 Reject out-of-bounds session ID length in ssl_tls12_session_load
Signed-off-by: Naveed <naveed@bugqore.com>
2026-08-03 13:44:23 +05:30
Valerio Setti
f3e424057f tests: ssl_helpers: update TEST_AVAILABLE_ECC and TEST_UNAVAILABLE_ECC
Align to recent changes in TLS group ID related functions:
- 'mbedtls_ssl_get_ecp_group_id_from_tls_id' renamed to
  'mbedtls_ssl_is_tls_id_supported'.
- 'mbedtls_ssl_get_tls_id_from_ecp_group_id' renamed to
  'mbedtls_ssl_get_tls_id_from_ecp_group_id'.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-07-30 10:52:36 +02:00
Minos Galanakis
b05e6e0e0a Merge remote-tracking branch 'mbedtls-4.1-restricted' into mbedtls-4.1.1.rc 2026-06-26 22:05:03 +01:00
Ronald Cron
c0dbff0cf8
Merge pull request #1683 from valeriosetti/issue1585-backport4.1
[4.1] Stale DTLS- SRTP negotiation state after session_reset() (ARM-RZ7EMQAA)
2026-06-26 12:17:19 +02:00
Ronald Cron
0fe502312d tls13_fetch_handshake_msg(): Remove require_record_boundary parameter
Deduce it from the handshake message type

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-24 16:00:25 +02:00
Ronald Cron
1208d1cc25 tls13_record_boundary_alignement: Append empty hs msg
Append an empty handshake message to expand
the record instead of just a zero byte.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-24 16:00:25 +02:00
Ronald Cron
4165fe1dc2 Various improvements of tls13_(drop_early_data|record_boundary_alignment)()
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-24 16:00:25 +02:00
Ronald Cron
d13352bc40 test_suite_ssl: Add initialization to all zeroes of test endpoint structs
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-24 16:00:25 +02:00
Ronald Cron
0501eeb804 test_suite_ssl: Test EndOfEarlyData on record boundary enforcement
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-24 16:00:25 +02:00
Ronald Cron
996adce4b6 test_suite_ssl: Test client Finished on record boundary enforcement
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-24 16:00:25 +02:00
Ronald Cron
d00518a2ec test_suite_ssl: Test server Finished on record boundary enforcement
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-24 16:00:25 +02:00
Ronald Cron
b9793ca124 test_suite_ssl: Test ServerHello on record boundary enforcement
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-24 16:00:24 +02:00
Ronald Cron
dd97c26e9a test_suite_ssl: Test ClientHello on record boundary check
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-24 16:00:24 +02:00
Ronald Cron
f17c5ff90d tls13: Add record boundary checks
RFC 8446 (TLS 1.3 specification), Section 5.1, states:

Handshake messages MAY be coalesced into a single TLSPlaintext record
or fragmented across several records, provided that:
    ...
    -Handshake messages MUST NOT span key changes. Implementations
    MUST verify that all messages immediately preceding a key change
    align with a record boundary; if not, then they MUST terminate the
    connection with an "unexpected_message" alert. Because the
    ClientHello, EndOfEarlyData, ServerHello, Finished, and KeyUpdate
    messages can immediately precede a key change, implementations
    MUST send these messages in alignment with a record boundary.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-24 16:00:24 +02:00
Ronald Cron
2aaedab1eb test_suite_ssl: Add early data drop tests
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-24 16:00:23 +02:00
Valerio Setti
150f1c7b40 tests: ssl: split ssl_helpers between public and internal functions
Move functions in "ssl_helpers.h" that depend on internal headers to
"ssl_helpers_internal.h". This allows to include "ssl_helpers.h" also
in programs (which do not have access to internal headers).

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-06-24 14:42:10 +02:00
Ben Taylor
356e535ff5 Improve tls_transcript_error_propagation testing to check for error codes
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:44 +01:00
Ben Taylor
f234fc5a3c Update regression test
Co-authored-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Ben Taylor <32939606+bjwtaylor@users.noreply.github.com>
2026-06-24 11:05:44 +01:00
Ben Taylor
9709c1a6e5 fix code style
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:44 +01:00
Ben Taylor
76aa4682ce Improve testing
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:44 +01:00
Ben Taylor
0e3e118220 Remove check for NULL pointer
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:44 +01:00
Ben Taylor
d93c7b6289 Add client tests for RMS computation error
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:44 +01:00
Ben Taylor
64b837bef9 Add unsupported trigger check
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:43 +01:00
Ben Taylor
6b60598c88 Add further documentation to tls_abort_transcript_context
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:43 +01:00
Ben Taylor
a58163a339 Fixed code style
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:43 +01:00
Ben Taylor
0a0c86dca4 refactor initialisation in tls_transcript_error_propagation, so that the variables are initialised straight after they are declared
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:43 +01:00
Ben Taylor
cdad2f42b7 Add additional guard for sha256 in tests
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:43 +01:00
Ben Taylor
d6e6012544 Improve layout of the code for debugging with breakpoints
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:43 +01:00
Ronald Cron
762b68fe26 Improve dependencies and error handling
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:05:42 +01:00
Ben Taylor
591a5f24c2 tests: ssl: add regression tests for EMS/RMS error propagation
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-24 11:04:57 +01:00
Gilles Peskine
657760964e
Merge pull request #1660 from bjwtaylor/info-leak-in-ssl_write_new_session_ticket-4.1
Info leak in ssl write new session ticket 4.1
2026-06-24 09:42:16 +02:00
Gilles Peskine
3d5e440b41 Add DTLS handshake test with badmac_seen=1
Add a test entry point for a handshake with a specially crafted context.
This can be used for defense in depths for scenarios that we think can't
happen, but might actually happen due to a bug, or due to a new feature that
is insufficiently tested. This can also be a proxy for testing aspects of
renegotiation or session resumption in circumstances that are hard to
arrange.

In this commit, use it to test a DTLS handshake with `ssl->badmac_seen`
:(actually `ssl->badmac_seen_or_in_hsfraglen` in the 3.6 branch) set to a
nonzero value. This can't happen, as far as I know (`badmac_seen` can only
be nonzero during renegotiation, not during a nominal handshake or in
session resumption). But it could happen, for example, if
`mbedtls_ssl_session_reset()` failed to reset `badmac_seen`, as was the case
in Mbed TLS 4.0.0 to 4.1.0.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-15 19:18:47 +02:00
Gilles Peskine
84f66de73f Test DTLS renegotiation when badmac_seen_or_in_hsfraglen != 0
Non-regression test for a bug introduced with TLS handshake defragmentation
support in Mbed TLS 3.6.3, whereby the confusion between the `badmac_seen`
meaning and the `in_hsfraglen` meaning of `ssl->badmac_seen_or_in_hsfraglen`
causes renegotiation to be processed incorrectly after receiving a message
with a bad MAC.

The bug doesn't affect Mbed TLS 4.0.0 and above, but it's still good to have
more testing.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-15 19:06:37 +02:00
Gilles Peskine
9fe8059464 Add a missing dependency
Needed by a test certificate.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-15 18:52:26 +02:00
Ronald Cron
91d7da23a8 Remove unnecessary dependency
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-06-15 18:49:12 +02:00
Ben Taylor
f2a1306c86 Correct syntax of MBEDTLS_GET_UINT32_BE in write_new_session_ticket_mem
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-11 16:24:04 +01:00
Ben Taylor
5fa28bb6cd Improve test of non-initilisation of lifetime
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-11 16:24:04 +01:00