13903 Commits

Author SHA1 Message Date
Minos Galanakis
e89565f92a Bump version
./scripts/bump_version.sh --version 4.1.0 \
  --so-crypto 18 --so-tls 23 --so-x509 9

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-26 22:34:28 +00:00
Minos Galanakis
308e7fb232 Merge remote-tracking branch 'restricted/development-restricted' into mbedtls-4.1.0.rc3
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-26 22:18:31 +00:00
Ronald Cron
1330606ca1 dtls: Fix adaptation to first ClientHello
For each received ClientHello fragment, check
that its epoch is zero and update the
record-level sequence number.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:45:24 +01:00
Ronald Cron
1141cd0fb6 Improve comments
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:45:24 +01:00
Ronald Cron
f2f44a9c9f Restrict mapping of UNEXPECTED_RECORD to UNEXPECTED_MESSAGE
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:45:24 +01:00
Ronald Cron
c9264ad227 dtls: Fix log level
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
140ebea442 dtls: parse_client_hello: Adapt mbedtls_ssl_read_record() error code
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
f9b7441542 dtls: Keep invalid/unexpected record header error code
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
0c301a686a dtls: Improve comment
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
912ef74195 Update buffering when adapting to ClientHello message_seq
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
16c5dd99b3 Introduce ssl_buffering_shift_slots
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
676d74e4c7 dtls: Error out on invalid/unexpected record header
Error out on invalid/unexpected record header
when reading the DTLS 1.2 ClientHello.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
315c970fbe dtls: Fix debug log
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
cb0b594a9d Merge pull request #10442 from davidhorstmann-arm/verify-result-default-failure
Hardening: Make `mbedtls_ssl_get_verify_result()` default to failure
2026-03-17 10:36:38 +00:00
Valerio Setti
ae885590fb library: bulk replace MBEDTLS_RSA_C with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC
Follow the same pattern that was used in the past to remove dependency
on MBEDTLS_RSA_C and use PSA_WANT instead.

Relying on MBEDTLS_RSA_C is fine only when builtin drivers are compiled
since all PSA_WANT are converted to legacy build symbols. However when
builtin drivers are not built (ex: in case of TF-M), then part of the code
in TLS/X509 won't be compiled because MBEDTLS_RSA_C is not set. OTOH
it's not possible to declare that symbol in a configuration file because
it's a legacy one and it will be rejected by buildtime checks.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-03-16 13:52:01 +01:00
Janos Follath
6714b39017 Improve ssl_parse_signature_algorithm
Simplify and improve error reporting and remove unnecessary
initialisation (the caller is responsible for initialising those
values).

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:28:36 +00:00
Janos Follath
5ffef28971 Fix code style
Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:28:36 +00:00
Janos Follath
7b255e3a12 ssl_parse_signature_algorithm: match error codes
The caller is returning MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER if
ssl_parse_signature_algorithm() fails, but
ssl_parse_signature_algorithm() returns
MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE upon failure. There is no good reason
for this mismatch and better to be aligned.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:28:36 +00:00
Janos Follath
c46eccf6ef ssl_parse_signature_algorithm: caller to get bytes
After the recent refactoring ssl_parse_signature_algorithm() sends an
alert on failure, but the caller also sends an alert on failure. Sending
two alerts is at least a protocol violation, and might not leave the SSL
context in a good state.

It is simpler to have the caller read the two bytes, and pass them to
this function.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:28:36 +00:00
Janos Follath
3d02353281 Fix code style
Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:28:36 +00:00
Janos Follath
e8894974cb Reintroduce ssl_parse_signature_algorithm
The logic was easier to follow before 693a47a, which removed the
ssl_parse_signature_algorithm function and introduced the bug being
fixed in this PR.

When validating multiple conditions, it's easier to read, easier to
debug and, as we can see, easier to get right if you validate them
separately.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:27:21 +00:00
Janos Follath
d7b85b76a6 sig_algs: fix typo in client's sig_algs check
This bug caused the client accepting sig_algs used by the server that
it explicitly wanted to disallow.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-03-16 12:26:21 +00:00
Manuel Pégourié-Gonnard
d8868c432f Merge pull request #1486 from ronald-cron-arm/tls12-2nd-client-hello
Fix TLS 1.2 client hello after HRR
2026-03-16 10:58:50 +01:00
Valerio Setti
95f0885507 library: x509: fix guard in mbedtls_x509_crt_profile_next
Replace MBEDTLS_ECP_C with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY which is
already used in all other profiles in this file.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-03-13 12:01:18 +01:00
Gilles Peskine
b9ff81c4c5 Merge remote-tracking branch 'development' into merge-development-restricted-20260311 2026-03-11 12:32:56 +01:00
David Horstmann
624fc2e0de Move TLS 1.3 verify-result setting for PSK
When we are doing PSK, we'd like to set verify_result to
MBEDTLS_X509_BADCERT_SKIP_VERIFY. Previously this was done in
mbedtls_ssl_set_hs_psk() but this is inadequate since this function may
be called for early data (where certificate verification happens later
in the handshake.

Instead, set this value after writing / processing the encrypted
extensions on the server / client respectively, so that we know whether
we are doing certificate verification or not for sure. This change is
effective only for TLS 1.3 as TLS 1.2 sets verify_result for PSK in
ssl_parse_certificate_coordinate().

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-03-10 15:12:47 +00:00
Ronald Cron
b5749b88f6 Merge pull request #10576 from ronald-cron-arm/dtls-client-hello-defragmentation
Add support for (D)TLS 1.2 client hello defragmentation
2026-03-10 14:46:07 +00:00
Ronald Cron
09210ea54f Restore seq number check of post-handshake ClientHello msg
The check was wrongly removed by the commit
"ssl_tls12_server.c: Move ClientHello message_seq adjustment".

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-10 10:12:55 +01:00
Ronald Cron
7f40da187c ssl_tls12_server.c: Move back the digest update
Move back the digest update just after
the call to mbedtls_ssl_read_record().
It fits well here as we explain in the
comment associated to the call to
mbedtls_ssl_read_record() that we
update it manually.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-10 08:25:21 +01:00
Ronald Cron
65a038198e Improve comments
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-09 23:28:50 +01:00
Manuel Pégourié-Gonnard
fe2599ea82 Merge pull request #1487 from davidhorstmann-arm/fix-null-pointer-dereference
Fix null pointer dereference in `mbedtls_x509_string_to_names()`
2026-03-09 12:43:08 +01:00
Ronald Cron
32479c6a72 cmake: Introduce TF_PSA_CRYPTO_PRIVATE_INCLUDE_DIRS
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-09 08:28:51 +01:00
Gilles Peskine
cf02249039 Merge remote-tracking branch 'development' into merge-development-restricted-20260309 2026-03-08 20:24:58 +01:00
Gilles Peskine
b38e28dbf0 Make sure we declare TF-PSA-Crypto platform requirements before including system headers
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 11:54:35 +01:00
Gilles Peskine
037f3c62ff Tell MSVC to allow non-s functions where needed
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 11:32:18 +01:00
Gilles Peskine
37fd7d5210 Start from a clean baseline for C11 ext1 and POSIX features
Define `_POSIX_C_SOURCE` and `_XOPEN_SOURCE` in a single place that
applies everywhere, to make things simple.

This may break some platforms that require special handling for POSIX
functions and types. Subsequent commits will add platform-specific hacks
as needed.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 11:32:18 +01:00
Gilles Peskine
e8dec9c031 Unify the detection of Unix-like platforms
We were using slightly different guards to decide whether to include
`<unistd.h>` in different places. Unify those.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 11:32:18 +01:00
Gilles Peskine
3d4b7cd3f9 Merge remote-tracking branch 'development' into development-restricted 2026-03-03 19:00:20 +01:00
Gilles Peskine
436f1e30ad Include the config in mbedtls_commmon.h as promised
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-02 12:25:02 +00:00
Gilles Peskine
a3d55d9ec7 Document the purpose of mbedtls_common.h
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-02 12:25:01 +00:00
Gilles Peskine
4ec9536339 Temporarily force standard *printf functions on MingW
On MingW, temporarily force the use of the standard versions of `snprintf()`
and `vsnprintf()` (since we set `__USE_MINGW_ANSI_STDIO` in
`mbedtls_platform_requirements.h`). Do not honor `platform.h` configuration,
because with the current TF-PSA-Crypto, `MBEDTLS_PLATFORM_VSNPRINTF_ALT and
`MBEDTLS_PLATFORM_SNPRINTF_ALT` are always enabled on MinGW, so what matters
is the setting of `__USE_MINGW_ANSI_STDIO` when `platform.c` is built, and
until https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/694, the legacy printf
functions are used there.

Revert this commit once the `tf-psa-crypto` module is updated with the merge
of https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/694.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-26 21:34:32 +01:00
Gilles Peskine
cdf3b0a535 MingW: insist on standard-compliant printf() and friends
Always activate `__USE_MINGW_ANSI_STDIO` unless overridden on the command
line. This is necessary with older versions of MingW and/or Windows,
where snprintf does not always zero-terminate the buffer, and does
not support formats such as `"%zu"` for size_t and `"%lld"` for long long.

Simplify debug.h accordingly. The macros `MBEDTLS_PRINTF_SIZET`,
`MBEDTLS_PRINTF_SIZET_HAX` and `MBEDTLS_PRINTF_LONGLONG` are no longer
needed, but they are still used in our code base and must stay in debug.h
for backward compatibility.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-26 20:56:03 +01:00
Gilles Peskine
3c67824964 test_suite_debug: test the printf used by debug.c
In `test_suite_debug`, test `mbedtls_debug_snprintf()`, which uses
`mbedtls_vsnprintf()` like `mbedtls_debug_print_msg()`. Do this instead of
testing `mbedtls_snprintf()`, which might be subtly different (older
Windows runtimes had slightly different behavior for vsnprintf() vs
snprintf(); TF-PSA-Crypto might pick up a different function if the
platform configuration is different in TF-PSA-Crypto and Mbed TLS).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-26 20:56:03 +01:00
Gilles Peskine
3a98885950 Create a header to declare platform requirements
On some platforms, the system headers expose different interfaces depending
on what macros are defined, for example to provide different standards
compliance level. Create a common place where we can declare such macros,
so that our code can behave in the same way when it's in different files.
Individual .c files can still override these requirements by defining
macros before including the common header, if it's really necessary.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-26 19:54:23 +00:00
Gilles Peskine
29d00fa861 Create a mbedtls_common.h for the project
We already have `x509_internal.h` which is common to all parts of the X.509
library, and `ssl_misc.h` which is common to all parts of the TLS library.
Also create `mbedtls_common.h` which is for the Mbed TLS project as a whole.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-26 19:54:15 +00:00
Bence Szépkúti
c2cb8565a5 Merge pull request #10607 from gilles-peskine-arm/timing-use-mstime
Simplify MBEDTLS_TIMING_C to use mbedtls_ms_time()
2026-02-26 14:38:50 +00:00
Ronald Cron
8731587e41 tls13: Commit to session resume only when we actually do it
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-26 15:16:51 +01:00
Ronald Cron
ed767bada9 tls13: Do not negotiate TLS 1.2 after an HRR
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-26 15:16:46 +01:00
David Horstmann
f549fc7bdc Fix null pointer dereference in string to names
In mbedtls_x509_string_to_names() we were not checking for allocation
failures. An allocation failure would lead to a memcpy() to a null
pointer address.

Fix this by checking the result of the call to mbedtls_calloc() and
returning MBEDTLS_ERR_X509_ALLOC_FAILED in the error case.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-02-26 13:34:01 +00:00
Ronald Cron
53dd7d0dce ssl_tls12_server.c: Update hs status after some validations of the ClientHello
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:28:12 +01:00