Commit Graph

13761 Commits

Author SHA1 Message Date
Chaitanya Tata
ecfaeaddb3 Fix unused function warning
commit 4ac4008fa0 ("Access
ssl->hostname through abstractions in certificate verification").

Due to this an unused function warning can occur if neither SNI nor
handshake is enabled.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2026-03-26 19:03:40 +05:30
Bence Szépkúti
444d0ac2c1 Merge pull request #10443 from davidhorstmann-arm/verify-result-default-failure-3.6
[Backport 3.6] Hardening: Make `mbedtls_ssl_get_verify_result()` default to failure
2026-03-17 12:14:48 +00:00
David Horstmann
0501209507 Move TLS 1.3 verify-result setting for PSK
When we are doing PSK, we'd like to set verify_result to
0 to indicate success. 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-16 17:19:30 +00:00
Manuel Pégourié-Gonnard
e24f1e5c2c Merge pull request #10609 from mpg/pk-psa-large-stack-buffers
[3.6] PK: avoid large stack buffers in "to/from PSA" functions
2026-03-13 08:53:48 +00:00
Ronald Cron
828e3817ac Merge pull request #10623 from ronald-cron-arm/dtls-client-hello-defragmentation-3.6
Backport 3.6: Add support for (D)TLS 1.2 client hello defragmentation
2026-03-10 14:46:41 +00:00
Ronald Cron
7476e4067d 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:15:42 +01:00
Ronald Cron
d6977afbd8 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 09:47:29 +01:00
Ronald Cron
1222d8cbf4 Improve comments
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-10 09:47:28 +01:00
Gilles Peskine
9cd92b207f Support testing baremetal builds without the UNIXLIKE code
When `MBEDTLS_TEST_PLATFORM_IS_NOT_UNIXLIKE` is defined, do not enable
`MBEDTLS_PLATFORM_IS_UNIXLIKE`. This lets us test baremetal builds as such
even if we happen to be building for Linux or other Unix-like platform.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
168461a3a9 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-03 15:19:58 +01:00
Gilles Peskine
f2c25e0133 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-03-03 15:19:58 +01:00
Manuel Pégourié-Gonnard
c763c2e837 PK: use EC macro for EC key size
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-03 09:53:08 +01:00
Manuel Pégourié-Gonnard
4c4cfe98de PK: use PSA size macros when exporting to PSA
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-03 09:50:53 +01:00
Manuel Pégourié-Gonnard
023c51b282 PK: adjust size macro in case PSA is disabled
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-27 10:37:34 +01:00
Manuel Pégourié-Gonnard
127b0352b3 PK: move another large buffer to the heap
Was previously missed as it only exists when USE_PSA_CRYPTO is enabled.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-27 10:32:19 +01:00
Manuel Pégourié-Gonnard
571d78361a PK: zeroize dummy signature just to be sure
The signature of a dummy hash for which no pre-image is know is probably
not sensitive, but zeroize it anyway.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-27 10:32:04 +01:00
Manuel Pégourié-Gonnard
81ecc37372 PK: clarify comment about key export
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-27 10:32:04 +01:00
Manuel Pégourié-Gonnard
bc69abd2cb PK: use existing macros and functions
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-27 10:32:04 +01:00
Ronald Cron
97a25e4c68 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:37:33 +01:00
Ronald Cron
09546ee120 ssl_msg.c: Remove some now unnecessary code
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:30:00 +01:00
Ronald Cron
2086b20f28 ssl_tls12_server.c: parse_client_hello: Remove remaining record level code
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:30:00 +01:00
Ronald Cron
6a9fc0ce77 ssl_tls12_server.c: Move ClientHello record sequence_number init
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:30:00 +01:00
Ronald Cron
5a744e8d34 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-24 15:30:00 +01:00
Ronald Cron
06abef2307 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-24 15:30:00 +01:00
Ronald Cron
17acd871c1 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-24 15:30:00 +01:00
Ronald Cron
4a8d476568 ssl_tls.c: Allow client hello fragmentation
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:30:00 +01:00
Manuel Pégourié-Gonnard
c5121ed11e PK: only use PSA macros when the header has been included...
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 11:04:23 +01:00
Manuel Pégourié-Gonnard
3e7657c81f PK: use smarter size for stack buffer
The original macro was accounting for the size of public FFDH keys,
which are not a concern for PK. Use sizes for key types supported by PK,
this brings the size of the buffer from 1kB to 528 bytes in the default
config.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 10:14:21 +01:00
Manuel Pégourié-Gonnard
06830d69df PK: avoid 1kB stack buffer in rsa_alt_check_pair()
Again, guarded by RSA_C, so use of heap is clearly OK.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 10:01:29 +01:00
Manuel Pégourié-Gonnard
a76d2129ba PK: avoid using a > 2kB stack buffer in RSA -> PSA
Here the code path is guarded by RSA_C so using the heap is clearly OK.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 09:54:12 +01:00
Manuel Pégourié-Gonnard
ee2c3e819f Adjust guard for 3.6
In all.sh component test_psa_crypto_config_accel_rsa_crypto, where RSA
is provided only by a drivers, we were using a stack buffer. However
that was not correct, as "opaque" (PSA-held) RSA keys are still
possible. This was pointed by failing test cases in test_suite_pk, such
as "PSA import into PSA: opaque RSA, EXPORT (ok)".

As usual with 3.6, we need more complicated pre-processor conditions.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 09:42:06 +01:00
Manuel Pégourié-Gonnard
4bebabb687 PSA: improve PSA_EXPORT_KEY_OUTPUT_SIZE; PK: use it
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 09:42:06 +01:00
Manuel Pégourié-Gonnard
6b90afb2bb PK: ensure we test with keys on the stack or heap
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 09:42:06 +01:00
Manuel Pégourié-Gonnard
56771d12b8 PK: improve naming & doc of internal macro
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 09:42:06 +01:00
Manuel Pégourié-Gonnard
925341971d PK: validate type upfront when copying from PSA
The type was validated near the end of the function when importing, but
if makes more sense to validate upfront before we possibly allocate a
buffer, export the key to it etc.

This also guarantees a sensible error value without requiring a special
case when exporting on the stack.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 09:42:06 +01:00
Manuel Pégourié-Gonnard
70454dc75b PK: rework failure case of internal size function
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 09:42:06 +01:00
Manuel Pégourié-Gonnard
00fd34ef18 PK: return helpful error on API misuse
This makes test_suite_pk pass again, but beyond that I think it's the
right thing to do.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 09:42:06 +01:00
Manuel Pégourié-Gonnard
210c613361 PK: fix stack buffer size for ECC keys
This fixes 2 out of the 3 tests cases that were failing in
test_suite_pk. The last failure will be adressed in the next commit.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 09:42:06 +01:00
Manuel Pégourié-Gonnard
eb8289d072 PK: adjust heap buffer size for key type+bits
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 09:42:06 +01:00
Manuel Pégourié-Gonnard
4d14271515 PK: avoid large stack buffer in to/from PSA functions
But still retain the ability to function without a heap when only ECC is
enabled.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-23 09:42:06 +01:00
Bence Szépkúti
34fcd9ae4f Merge pull request #10603 from ronald-cron-arm/dtls-client-hello-defragmentation-prep-3.6
Backport 3.6: Some preparatory work for DTLS client hello defragmentation
2026-02-22 23:30:44 +00:00
Ronald Cron
3b6bd65334 ssl_msg.c: Improve handshake message fragmenting message
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-18 14:41:57 +01:00
Ronald Cron
a02505a7be ssl_msg.c: Improve HS message reassembly completed message
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-18 14:41:56 +01:00
Ronald Cron
c065fdd4d4 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:41:56 +01:00
Manuel Pégourié-Gonnard
fbfd13e22b Merge pull request #10597 from valeriosetti/fix-tls12-sha-guards-backport
[backport] library: check_config: fix required hash algorithms for TLS 1.2
2026-02-18 08:23:38 +00:00
David Horstmann
d179019ec2 Set verify_result to 0 when not checking certs
When we are using PSK or authmode is MBEDTLS_SSL_VERIFY_NONE, set
verify_result to 0 rather than MBEDTLS_X509_BADCERT_SKIP_VERIFY.

This is specific to the 3.6 LTS, to preserve the previous behaviour of
the library in these cases, which was determined by the default value
of verify_result being 0.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-02-17 14:41:59 +00:00
David Horstmann
79b6980887 Set verify_result in non-verification cases
When we are using PSK or when authmode == MBEDTLS_SSL_VERIFY_NONE, we
intentionally do not verify the certificate. In these cases, do not keep
verify_result at -1u but set it to MBEDTLS_X509_BADCERT_SKIP_VERIFY to
indicate that no certificate verification took place.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-02-17 14:39:53 +00:00
David Horstmann
01ef42d5fe Initialize verify_result in session free
Initialize the verify_result field in mbedtls_ssl_session_free().
Previously we were just zeroising the entire session object, which would
yield a default 'success' value if the same object were reused.

Test that this initialisation is actually happening by setting
verify_result manually to zero and calling mbedtls_ssl_session_free() on
the session before checking its value.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-02-17 14:39:53 +00:00
David Horstmann
c42f73fe34 Switch to a default value of -1u
Since we explicitly document the value 0xFFFFFFFF or -1u as representing
'result not available', we can use it as a sensible default value
without creating an API change. Use this value instead of introducing a
new verification result value.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-02-17 14:39:53 +00:00
David Horstmann
710aaa7ae7 Set verify_result to failure by default
At initialization, set the verify_result field of the ssl session to
MBEDTLS_X509_VERIFY_NOT_STARTED, rather than 0 as it is by default
currently. This prevents mbedtls_ssl_get_verify_result() from indicating
that certificate verification has passed if it is called prior to the
handshake happening.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-02-17 14:38:28 +00:00