Commit Graph

13866 Commits

Author SHA1 Message Date
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
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
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
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
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
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
Ronald Cron
d718a35a1f ssl_msg.c: Remove some now unnecessary code
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-23 12:12:36 +01:00
Ronald Cron
0db3a49330 ssl_tls12_server.c: parse_client_hello: Remove remaining record level code
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-23 12:12:36 +01:00
Ronald Cron
00160b910a ssl_tls12_server.c: Move ClientHello record sequence_number init
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-23 12:12:36 +01:00
Ronald Cron
943c1071bb ssl_tls12_server.c: Move ClientHello message_seq adjustment
Move ClientHello message_seq adjustment to the record layer.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-23 12:12:36 +01:00
Ronald Cron
a50110be71 ssl_tls12_server.c: Use mbedtls_ssl_read_record() only to read the ClientHello
In ssl_tls12_server.c:ssl_parse_client_hello(), remove
the code that directly reads the received data to read
the record expected to contain the ClientHello message.

The function already supported handling a ClientHello
read via mbedtls_ssl_read_record() in the following
cases:
- when the ClientHello was read as a post-handshake
  message (renegotiation).
- when the ClientHello was read by
  ssl_tls13_process_client_hello() during TLS 1.3 or
  TLS 1.2 version negotiation.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-23 12:12:36 +01:00
Ronald Cron
516e74ca5c ssl_tls12_server.c: Document replay check and update in ssl_parse_client_hello()
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-23 12:12:36 +01:00
Ronald Cron
39813964ef ssl_tls.c: Allow client hello fragmentation
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-23 12:12:36 +01:00
Bence Szépkúti
bbf8bbbdb6 Merge pull request #10575 from ronald-cron-arm/dtls-client-hello-defragmentation-prep
Some preparatory work for DTLS client hello defragmentation
2026-02-22 23:30:39 +00:00
Valerio Setti
3b4984243f Merge pull request #10595 from valeriosetti/fix-tls12-sha-guards
library: check_config: fix required hash algorithms for TLS 1.2
2026-02-20 09:14:13 +00:00
Gilles Peskine
5890b22b82 Fix a build error with MSVC
Also fixes a minor bug on Windows with timers running over ~49 days.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-19 16:53:52 +01:00
Gilles Peskine
137b5b776d Simplify MBEDTLS_TIMING_C to use mbedtls_ms_time()
Don't ship two slightly different wheels.

This reduces our platform adherence by using only `clock_gettime()` in the
library and not `gettimeofday()` as well.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-19 16:53:52 +01:00
Gilles Peskine
86eac795c9 Have MBEDTLS_TIMING_C require MBEDTLS_HAVE_TIME
Nowadays, the timing module just builds on a function that provides a timer
with millisecond resolution. In terms of platform requirements, this is
almost exactly equivalent to `mbedtls_ms_time()`
provides (`mbedtls_ms_time()` is arguably a little stronger because it is
supposed to last longer than a single timer object, but an application could
start a timer when it starts, so there's no real difference.) So it's a bit
silly that `timing.c` essentially reimplements this. Rely on
`mbedtls_ms_time()` instead.

This is an API break because in Mbed TLS 4.0, it was possible to enable
`MBEDTLS_TIMING_C` without `MBEDTLS_HAVE_TIME`. However, `timing.c` only
provided an implementation for Windows and Unix-like platforms, and on those
platforms, it is very likely that the default implementation of
`MBEDTLS_HAVE_TIME` would also work. (The main exception would be a platform
that has the traditional Unix function `gettimeofday()`, but not the 1990s
novelty `clock_gettime()`.) So make this an official requirement, as a
belated change that really should have gone into 4.0 if we'd taken the time
to dig into it.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-19 16:53:52 +01:00
Ronald Cron
4f0741498c ssl_msg.c: Improve handshake message fragmenting message
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-18 14:21:48 +01:00
Ronald Cron
7fe38dd934 ssl_msg.c: Improve HS message reassembly completed message
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-18 14:21:48 +01:00
Ronald Cron
86b7df5591 ssl_tls.c: Rename and expand ssl_tls13_get_hs_msg_name
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-18 14:21:48 +01:00
David Horstmann
059fe77e4b Fix missing type conversion in the TLS-Exporter
In the TLS-Exporter for TLS 1.3 we mistakenly call PSA_HASH_LENGTH() on
an mbedtls_md_type_t when it should be called on a psa_algorithm_t.

Fortunately, these two types have almost the same values, since we have
previously aligned them to make conversion more efficient. As a result,
PSA_HASH_LENGTH() produces exactly the same value when called on an
mbedtls_md_type_t as with the equivalent psa_algorithm_t.

Thanks to this happy coincidence, fix a largely cosmetic issue (rather
than a major functional bug).

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-02-16 16:59:20 +00:00
Valerio Setti
384a16746f library: check_config: remove redundant check on hash algorithms for TLS 1.2
TLS-PRF uses either SHA-256 and SHA-384, so the removed paragraph was not
correct. The correct version is already available few lines below in the
same header file.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-02-12 14:12:30 +01:00
Valerio Setti
2a72766d75 Merge pull request #10570 from valeriosetti/issue10349
mbedtls 4.x does not expose mbedtls_ecp_curve_list()
2026-02-03 11:01:11 +00:00
Manuel Pégourié-Gonnard
75eec4b477 Merge pull request #10577 from h1wind/patch-1
fix: Disabling the MBEDTLS_SSL_CLI_C feature caused a compilation error: unused parameter "ssl".
2026-01-29 10:30:18 +00:00
hi
4987340d24 fix code style in ssl_msg.c and add signoff
Signed-off-by: hi <hi@nosec.me>
2026-01-29 14:14:02 +08:00
hi
d823908335 fix: Disabling the MBEDTLS_SSL_CLI_C feature caused a compilation error: unused parameter "ssl".
Signed-off-by: hi <hi@nosec.me>
2026-01-29 14:14:02 +08:00
David Horstmann
d0bff58379 Merge pull request #10514 from ng-gsmk/development
mbedtls_ssl_get_alert(): getter for fatal alerts
2026-01-28 16:49:09 +00:00
Valerio Setti
4f1e4fba80 library: ssl: make the list of "TLS ID" <-> "group name" public when possible
This is only done when MBEDTLS_DEBUG_C is declared in order not to inflate
the library size.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-27 00:51:35 +01:00
Valerio Setti
fb317afa9f library: ssl: rework macro to define known TLS ID <-> group name list
- let the macro be an initializer for the array of known TLS IDs, not
  a variable declarator;
- last item's group name is NULL, not an empty string
- change then name of the macro from MBEDTLS_TLS_ID_GROUP_NAME_TABLE to
  MBEDTLS_SSL_IANA_TLS_GROUPS_INFO
- define a new public structure "mbedtls_ssl_iana_tls_group_info_t" to
  hold each element of the table and that can be used the go over the
  list from user code.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-27 00:36:17 +01:00
Nico Geyso
6afd8367b9 remove whitespace in mbedtls_ssl_session_msg_layer
to comply with coding style, remove blank new line for alert reset

Signed-off-by: Nico Geyso <ng@gsmk.de>
2026-01-26 13:22:44 +01:00
Nico Geyso
4f83ebedd1 Fix outstanding code review issues
- adjust function name to mbedtls_ssl_get_fatal_alert
- fix missing property name changes for  mbedtls_ssl_context

Signed-off-by: Nico Geyso <ng@gsmk.de>
2026-01-26 13:15:07 +01:00
Valerio Setti
7ca3c602b7 library: ssl: add macro for allocating a TLS-ID <-> group-name table
Being a macro allow the table to be instatiated only when/if necessary
by the consuming code.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-26 10:48:01 +01:00
Valerio Setti
2aecd2cd5f library|tests: ssl: remove secp256k1 from default groups
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-22 17:13:44 +01:00
Valerio Setti
335b1b6089 library: ssl: add missing secp256k1 to ssl_preset_default_groups
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-22 09:43:46 +01:00
Valerio Setti
67f30df5a1 library: ssl: use correct PSA_WANT for DH groups in ssl_preset_default_groups
Use proper PSA_WANT_DH_RFC7919_xxx instead of PSA_WANT_ALG_FFDH.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-22 09:43:46 +01:00
Valerio Setti
2707100ab7 library: ssl: move location of ssl_preset_default_groups()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-22 09:43:45 +01:00