1
0
mirror of https://github.com/ARMmbed/mbedtls.git synced 2025-05-11 09:22:05 +08:00

31953 Commits

Author SHA1 Message Date
Gilles Peskine
c3af2f48c4 ClientHello may be fragmented in renegotiation
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-12 10:55:11 +01:00
Gilles Peskine
494e4943b5 Move the defragmentation documentation to mbedtls_ssl_handshake
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-12 10:55:10 +01:00
Gilles Peskine
1933932e55 Refer to the API documentation for details
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-12 10:53:11 +01:00
Gilles Peskine
b5ccd32390 Document the limitations of TLS handshake message defragmentation
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-12 10:53:11 +01:00
Gilles Peskine
43f636ff4d
Merge pull request #1316 from gilles-peskine-arm/zeroize-psa-202503-3.6
Backport 3.6: Zeroize PSA temporary heap buffers
2025-03-11 17:38:28 +01:00
David Horstmann
0326decca7 Add changelog entry for TLS 1.2 Finished fix
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2025-03-11 15:53:26 +00:00
Gilles Peskine
d3b3c6740f More generally, what needs psa_crypto_init also needs threading
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-11 14:45:54 +01:00
Manuel Pégourié-Gonnard
579f91ad44
Merge pull request #10046 from mpg/fix-defrag-interleave-3.6
Fix defrag interleave 3.6
2025-03-11 12:38:21 +01:00
Georgios Vasilakis
d5e64f71db PSA core: Allow enabling one volatile/builtin key
The current impelementation asserts if the user
sets MBEDTLS_PSA_KEY_SLOT_COUNT to one or if they
limit their builtin range to one key.

This removes the requirement and allows for only
one key volatile/builtin to be enabled.

Signed-off-by: Georgios Vasilakis <georgios.vasilakis@nordicsemi.no>
2025-03-11 09:37:29 +01:00
Manuel Pégourié-Gonnard
8a4ec49671 Cleanly reject non-HS in-between HS fragments
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-03-10 21:38:48 +01:00
Waleed Elmelegy
443908bc5d Replace zero by PSA_ALG_NONE in key derivation input functions
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2025-03-10 14:20:09 +00:00
Bence Szépkúti
db475821f9 Fix comments
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2025-03-08 01:02:57 +01:00
Bence Szépkúti
23e941a2e7 Update changelog to call out MinGW
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2025-03-08 00:42:44 +01:00
David Horstmann
b5ef7da7cb TLS1.2: Check for failures in Finished calculation
If the calc_finished function returns an error code, don't ignore it but
instead return the error code to stop the handshake as the Finished
message may be incorrect.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2025-03-07 17:25:54 +00:00
Bence Szépkúti
c6934ff670 Never use %zu on MinGW
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2025-03-07 17:54:20 +01:00
Bence Szépkúti
8154c5823e Remove Everest VS2010 compatibility headers
These headers were necessary for compatibility with Visual Studio 2010,
and interfere with the system headers on Visual Studio 2013+, eg. when
building Mbed TLS using the .sln file shipped with the project.

Move the still-required definition of "inline" to callconv.h, where the
definition for GCC also lives.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2025-03-07 17:54:19 +01:00
Bence Szépkúti
f65983d670 Fix MSVC version guard for C99 format size specifiers
Visual Studio 2013 (_MSC_VER == 1800) doesn't support %zu - only use it
on 2015 and above (_MSC_VER >= 1900).

%ldd works on Visual Studio 2013, but this patch keeps the two macro
definitions together, for simplicity's sake.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2025-03-07 17:45:27 +01:00
Bence Szépkúti
1e62c95148 Disable fatal assertions in Windows printf tests
The Windows CRT treats any invalid format specifiers passed to the CRT
as fatal assertion failures. Disable thie behaviour temporarily while
testing if the format specifiers we use are supported.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2025-03-07 17:45:27 +01:00
Bence Szépkúti
9cde9d4b2c Add testcase for MBEDTLS_PRINTF_MS_TIME
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2025-03-07 17:45:26 +01:00
Bence Szépkúti
85d92ec1ce Test handling of format macros defined in debug.h
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2025-03-07 17:45:26 +01:00
Bence Szépkúti
d5102c9d7c Run test_suite_debug without MBEDTLS_SSL_TLS_C
Move the suite's global dependency on MBEDTLS_SSL_TLS_C to the
individual test cases.

Add an preprocesor guard around string_debug to prevent warning about unused
functions.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2025-03-07 17:45:26 +01:00
Gilles Peskine
26c378cb73
Merge pull request #10030 from gilles-peskine-arm/tls-defragment-incremental-3.6
Backport 3.6: Incremental TLS handshake defragmentation
2025-03-07 13:17:39 +01:00
Gilles Peskine
c22e315086 Fix a log message
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-07 10:44:57 +01:00
Gilles Peskine
229e200cb4 Note unused variables when debugging is disabled
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 21:33:32 +01:00
Gilles Peskine
dee926359c Pacify uncrustify
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 21:33:29 +01:00
Gilles Peskine
ce726b23fa Fix uninitialized variable
The of m_bytes value isn't actually used when it's uninitialized,
because *data is null, but that's very fragile.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 19:27:50 +01:00
Gilles Peskine
0a467ccd24 Unify handshake fragment log messages
There is no longer any different processing at this point, just
near-identical log messages.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 19:22:52 +01:00
Gilles Peskine
b888cca5b6 Fix handshake defragmentation when the record has multiple messages
A handshake record may contain multiple handshake messages, or multiple
fragments (there can be the final fragment of a pending message, then zero
or more whole messages, and an initial fragment of an incomplete message).
This was previously untested, but supported, so don't break it.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 19:22:40 +01:00
Gilles Peskine
3175fc3be2 Fix end check before memmove
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 19:10:41 +01:00
Gilles Peskine
184cac1eb6 Zeroize temporary heap buffers used when deriving an ECC key
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 12:42:30 +01:00
Gilles Peskine
e847afd9ef Zeroize temporary heap buffers used in PSA operations
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 12:41:59 +01:00
Gilles Peskine
7719169ef4 Update framework
Changed log messages and added more tests in
`tests/opt-testcases/handshake-generated.sh`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 09:35:55 +01:00
David Horstmann
9a9f0c77cf
Merge pull request #1312 from gilles-peskine-arm/ssl-hostname-unset-magic-pointer-3.6
Backport 3.6: require setting the hostname for verification
2025-03-05 17:59:12 +00:00
Gilles Peskine
58c3301f65 Make conversion explicit to silence MSVC warning
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
302f37b05d Fix dodgy printf calls
Pacify `clang -Wformat-pedantic`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
cc856a2c0e Handshake defragmentation: reassemble incrementally
Reassemble handshake fragments incrementally instead of all at the end. That
is, every time we receive a non-initial handshake fragment, append it to the
initial fragment. Since we only have to deal with at most two handshake
fragments at the same time, this simplifies the code (no re-parsing of a
record) and is a little more memory-efficient (no need to store one record
header per record).

This commit also fixes a bug. The previous code did not calculate offsets
correctly when records use an explicit IV, which is the case in TLS 1.2 with
CBC (encrypt-then-MAC or not), GCM and CCM encryption (i.e. all but null and
ChachaPoly). This led to the wrong data when an encrypted handshake message
was fragmented (Finished or renegotiation). The new code handles this
correctly.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
22c51b9a0b mbedtls_ssl_prepare_handshake_record(): log offsets after decryption
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
af0c461f39 mbedtls_ssl_prepare_handshake_record(): refactor first fragment prep
Minor refactoring of the initial checks and preparation when receiving the
first fragment. Use `ssl->in_hsfraglen` to determine whether there is a
pending handshake fragment, for consistency, and possibly for more
robustness in case handshake fragments are mixed with non-handshake
records (although this is not currently supported anyway).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
1e81d349b8 Tweak handshake fragment log message
In preparation for reworking mbedtls_ssl_prepare_handshake_record(),
tweak the "handshake fragment:" log message.

This changes what information is displayed when a record contains data
beyond the expected end of the handshake message. This case is currently
untested and its handling will change in a subsequent commit.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
3d490a91ad Tweak "waiting for more handshake fragments" log message
In preparation for reworking mbedtls_ssl_prepare_handshake_record(), tweak
the "waiting for more handshake fragments" log message in
ssl_consume_current_message(), and add a similar one in
mbedtls_ssl_prepare_handshake_record(). Assert both.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
b6102b6ccf Fix Doxygen markup
Pacify `clang -Wdocumentation`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
134677d44c
Merge pull request #10029 from gilles-peskine-arm/tls-defragment-generate-tests-3.6
Backport 3.6: Generate TLS handshake defragmentation tests
2025-03-05 16:49:21 +01:00
Gilles Peskine
2e7def5748 Update framework
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 10:08:29 +01:00
Gilles Peskine
9d54be57b0 Generate handshake defragmentation test cases: update analyze_outcomes
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 10:08:21 +01:00
Manuel Pégourié-Gonnard
1d25c71ab6
Merge pull request #9562 from valeriosetti/md-psa-dispatch-3.6
Backport 3.6: md: allow dispatch to PSA whenever CRYPTO_CLIENT is enabled
2025-03-04 08:34:11 +00:00
Gilles Peskine
2e7f2a2e48 Switch to generated handshake tests
Replace `tests/opt-testcases/handshake-manual.sh` by
`tests/opt-testcases/handshake-generated.sh`. They are identical except for
comments, and for some extra dependencies on
`MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED` which are needed in `development,
but not in `mbedtls-3.6. Those dependencies don't hurt the useful coverage
of the tests, so we'll live with them.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-03 21:03:22 +01:00
Gilles Peskine
6183a645fc Normalize requirements in defragmentation test cases
Be more uniform in where certificate authentication and ECDSA are explicitly
required. A few test cases now run in PSK-only configurations where they
always could. Add a missing requirement on ECDSA to test cases that are
currently skipped.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-03 21:00:50 +01:00
Gilles Peskine
49e1ed277e Normalize messages in defragmentation test cases
Make some test case descriptions and log patterns follow more systematic
patterns.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-03 21:00:50 +01:00
Gilles Peskine
8321ab574c Normalize whitespace in defragmentation test cases
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-03 21:00:50 +01:00
Gilles Peskine
8ef2e74704 Move most TLS handshake defragmentation tests to a separate file
Prepare for those test cases to be automatically generated by a script.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-03 21:00:48 +01:00