Commit Graph

611 Commits

Author SHA1 Message Date
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
ed0aebd2c5 tests: bulk replace MBEDTLS_RSA_C with PSA_HAVE_ALG_SOME_RSA_SIGN
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-03-16 13:52:01 +01:00
David Horstmann
ff51a1a176 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-05 14:31:46 +00:00
David Horstmann
687a1ba907 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-05 14:31:46 +00:00
David Horstmann
0ecde06ce9 Add non-regression test for verify_result init
Write a testcase to get verify_result before we have performed a
handshake and make sure that it is initialised to a failure value.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-02-05 14:31:43 +00: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
Valerio Setti
c3f585b8ee tests: ssl: fix typo in comment in test_mbedtls_ssl_get_supported_group_list
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-30 22:02:08 +01:00
Valerio Setti
476a2edea7 library: extend mbedtls_ssl_iana_tls_group_info_t structure
Add new field that tells if the corresponding group is supported or not
in the current build.

Test function "test_mbedtls_ssl_get_supported_group_list" is extended
to verify this new feature.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-28 10:52:07 +01:00
Valerio Setti
d658f3d41e tests: ssl: skip testing of MBEDTLS_SSL_IANA_TLS_GROUP_NONE
This is already indirectly checked in 'test_mbedtls_tls_id_group_name_table'
because it's the last item of the list.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-27 12:26:21 +01:00
Valerio Setti
bb4f584876 tests: ssl: improve test_mbedtls_tls_id_group_name_table()
Check provided group_name also against the value returned from
mbedtls_ssl_get_curve_name_from_tls_id().

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-27 00:44:56 +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
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
c87adb64f2 tests: ssl: add test for TLS-ID <-> curve-name table
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-26 11:09:20 +01:00
Valerio Setti
8686ad1a9e tests: ssl: add testing for mbedtls_ssl_get_supported_group_list()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-22 10:33:44 +01:00
Nico Geyso
6140cfb438 tests/ssl_get_alert_after_fatal - add invalid param case
Signed-off-by: Nico Geyso <ng@gsmk.de>
2025-12-10 23:01:57 +01:00
Nico Geyso
13200ab116 Fix more C code style issues
Signed-off-by: Nico Geyso <ng@gsmk.de>
2025-12-10 19:37:07 +01:00
Nico Geyso
f9a734f2b7 Fix C code style issues
Signed-off-by: Nico Geyso <ng@gsmk.de>
2025-12-10 19:37:07 +01:00
Nico Geyso
0841ceadf7 test ssl_get_alert_after_fatal - remove mbedtls_ssl_conf_rng
Signed-off-by: Nico Geyso <ng@gsmk.de>
2025-12-10 19:37:07 +01:00
Nico Geyso
d589854611 mbedtls_ssl_get_alert(): getter for fatal alerts
Even though the TLS RFCs do not mandate libraries to expose *Error
Alerts* (as defined in RFC8446 6.2 for TLS 1.3 and in RFC5246 7.2.2 for
TLS 1.2) to the user, there are use cases when it is handy to get the
actual last received fatal error instead of a generic one. For instance
this enables the user to differ between received fatal errors in case
`mbedtls_ssl_handshake()`, `mbedtls_ssl_handshake_step()` or
`mbedtls_ssl_read()` returned `MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE`.

This changesets stores the last incoming fatal alert in
`mbedtls_ssl_context` and provides `mbedtls_ssl_get_alert()` as a getter
for retrieving it. Another option would be to provide a callback
mechanisms for all kinds of alerts (not only fatals) but for simplicity
I discarded this option.

Signed-off-by: Nico Geyso <ng@gsmk.de>
2025-12-10 19:37:07 +01:00
Anton Matkin
6eb5335ef0 Fixed issues with policy verification, since wildcard JPAKE policy is now disallowed, changed to concrete jpake algorithm (with SHA256 hash)
Signed-off-by: Anton Matkin <anton.matkin@arm.com>
2025-08-12 13:50:48 +02:00
Anton Matkin
1b70084bd9 TF-PSA-Crypto submodule link fixup
Signed-off-by: Anton Matkin <anton.matkin@arm.com>
2025-08-12 13:50:45 +02:00
Valerio Setti
80a623089d tests: ssl: allow more groups in conf_group()
Previously 3 different groups were allowed, but since the removal of
secp192r1 and secp224r1 only secp256r1 was left. This commit adds
other 2 options.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-08-06 11:38:45 +02:00
Valerio Setti
d0d0791aed remove usage of secp192[k|r]1 curves
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-08-06 09:15:35 +02:00
Valerio Setti
70a4a31cb5 remove secp224[k|r]1 curves
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-08-06 09:15:35 +02:00
Ben Taylor
9020426b14 remove MBEDTLS_USE_PSA_CRYPTO from tests
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-07-30 07:55:14 +01:00
Ben Taylor
c801d3293e include private pk.h internally
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-07-17 15:18:53 +01:00
Manuel Pégourié-Gonnard
921331867d Merge pull request #10197 from gilles-peskine-arm/ssl_helpers-split_perform_handshake-dev
Break down mbedtls_test_ssl_perform_handshake
2025-06-30 09:39:29 +00:00
Gilles Peskine
760608d47b Properly initialize SSL endpoint objects
In some cases, we were calling `mbedtls_test_ssl_endpoint_free()` on an
uninitialized `mbedtls_test_ssl_endpoint` object if the test case failed
early, e.g. due to `psa_crypto_init()` failing. This was largely harmless,
but could have caused weird test results in case of failure, and was flagged
by Coverity.

Use a more systematic style for initializing the stack object as soon as
it's declared.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-24 18:42:04 +02:00
Gilles Peskine
b836d46870 Fix accidentally skipped test assertion
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-24 18:42:04 +02:00
Gilles Peskine
fb2ce055a3 SSL tests: make client authentication more uniform, defaulting on
There was a discrepancy between how `mbedtls_test_ssl_endpoint_init()` and
`mbedtls_test_ssl_perform_handshake()` handled client authentication:
`mbedtls_test_ssl_endpoint_init()` defaulted to
`MBEDTLS_SSL_VERIFY_REQUIRED` on both sides, whereas
`mbedtls_test_ssl_perform_handshake()` obeyed `options->srv_auth_mode` which
defaulted to no verification of the client certificate.

Make this more uniform. Now `mbedtls_test_ssl_endpoint_init()` obeys
`options->srv_auth_mode` on servers (still forcing verification on clients,
which is the library default anyway). Also, `options->srv_auth_mode` is now
enabled by default. Thus:

* Tests that call `mbedtls_test_ssl_perform_handshake()` now perform client
  certificate verification, unless they disable it explicitly.
* Tests that call `mbedtls_test_ssl_endpoint_init()` on a server are
  unchanged. (They would change if they were setting
  `options->srv_auth_mode` explicitly, which previously was ignored, but
  no test function did this.)

This means that a few test functions now perform client certificate
verification whereas they previously don't. This is harmless except in
`handshake_ciphersuite_select`, where one test case
`Handshake, select ECDH-RSA-WITH-AES-256-CBC-SHA384, opaque` fails with
client authentication because the test code doesn't deal with the weirdness
of static ECDH correctly with respect to client authentication. So keep
the previous behavior in `handshake_ciphersuite_select`, by explicitly
turning off client authentication.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-28 21:36:28 +02:00
Gilles Peskine
ca8a9ac4af Remove unused parameters to endpoint init/free
The DTLS context and the queues now conveyed inside the endpoint object.
Remove the unused parameters.

No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-28 20:23:22 +02:00
Gilles Peskine
353eb33d0c Use TEST_EQUAL(a,b) instead of TEST_ASSERT(a==b)
Regexp replacement then `code_style.py --fix`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-28 20:22:12 +02:00
David Horstmann
232da48471 Merge pull request #9421 from mfil/feature/implement_tls_exporter
Implement TLS-Exporter
2025-04-17 14:47:13 +00:00
Manuel Pégourié-Gonnard
a5db6c14fd Fix record insertion
We were not making enough room. We want to move everything from the
place where we are going to insert the new record.

This was not causing failures because the code does not look at the
content after the inserted record, because it correctly returns an error
when seeing the inserted record. But as a matter on principle, the test
code should be doing what it says: just insert a new record but leave
a valid fragment after it.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-04-11 10:14:22 +02:00
Manuel Pégourié-Gonnard
8d73bdc679 Improve comments
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-04-10 09:38:53 +02:00
Manuel Pégourié-Gonnard
132f5b99c8 Use same dependencies for helper functions
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-04-09 12:52:26 +02:00
Manuel Pégourié-Gonnard
0a1996f8ee Tighten dependency declarations
These are not optimal. For example, the tests should in principle be
able to run in builds without ECDSA, by using RSA certs instead. Ideally
PSK should work too.

However, getting optimal dependencies would be a lot of work that's
largely orthogonal to the purpose of this PR, so we'll settle for good
enough.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-04-09 12:52:26 +02:00
Gilles Peskine
c0721e0e8e Improve documentation
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-09 12:52:26 +02:00
Gilles Peskine
eb48890bd5 Remove redundant setup
mbedtls_test_ssl_endpoint_init() already takes care of setting up debugging.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-09 12:52:26 +02:00
Gilles Peskine
84ccbd8002 Simulate closing the connection mid-message
Simulate the server closing the connection after a partial handshake
message.

These test cases don't send a close_notify alert. The test cases
"insert alert record" exercise what happens if the server sends an alert.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-09 12:52:26 +02:00
Gilles Peskine
5e3c0bd82b Also test inserting non-empty, non-handshake records
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-09 12:52:26 +02:00
Gilles Peskine
c34ea472fb Fix the build without MBEDTLS_DEBUG_C
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-09 12:52:26 +02:00
Gilles Peskine
074267282f Fix the build in PSK-only configurations
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-09 12:52:26 +02:00
Gilles Peskine
7ab9fb6d14 Pacify ancient clang -Wmissing-initializer
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-09 12:52:26 +02:00
Gilles Peskine
7c1dbeff49 Test split, coalesced-split and empty handshake records
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-09 12:52:26 +02:00
Gilles Peskine
92122edf4b Create handshake record coalescing tests
Create tests that coalesce the handshake messages in the first flight from
the server. This lets us test the behavior of the library when a handshake
record contains multiple handshake messages.

Only non-protected (non-encrypted, non-authenticated) handshake messages are
supported.

The test code works for all protocol versions, but it is only effective in
TLS 1.2. In TLS 1.3, there is only a single non-encrypted handshake record,
so we can't test records containing more than one handshake message without
a lot more work.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-09 12:52:26 +02:00
Max Fillinger
1a1ec2fcce Fix up merge conflict resolution
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 17:54:08 +01:00
Max Fillinger
8e0b8c9d9f Exporter tests: Add missing depends-ons
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 17:08:10 +01:00
Max Fillinger
9dc7b19a6a Exporter tests: Free endpoints before PSA_DONE()
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 17:06:48 +01:00
Max Fillinger
364afea9d3 Exporter tests: Fix possible uninitialized variable use
Signed-off-by: Max Fillinger <max@max-fillinger.net>
2025-03-28 17:06:48 +01:00