1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-07 06:42:56 +03:00
Commit Graph

6663 Commits

Author SHA1 Message Date
Ben Taylor
4df61d408d fix style issues
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-07-30 07:55:14 +01:00
Ben Taylor
dbea0a9cc5 Remove additional unused no rng case
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-07-30 07:55:14 +01:00
Ben Taylor
1e2e2ea36d Added back crypto treatment of certs as the keyfile is now passed in and the previous rng issue should no longer be relevent
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-07-30 07:55:14 +01:00
Ben Taylor
98ecfdb440 corrected code style
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-07-30 07:55:14 +01: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
Valerio Setti
cd1b7ffa70 tests: x509write: replace MBEDTLS_ECDSA_DETERMINISTIC with PSA_WANT one
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-07-29 10:40:12 +02:00
Ben Taylor
361ce2b484 Rename mbedtls_pk_setup_opaque to mbedtls_pk_wrap_psa
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-07-24 08:25:28 +01:00
Ben Taylor
5be8511151 Fix too many arguments in mbedtls_pk_verify_new
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-07-21 07:53:15 +01:00
Ben Taylor
0c787e3de8 Remove additional calls to mbedtls_pk_verify_ext
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-07-21 07:53:15 +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
Minos Galanakis
83bef5b66a Merge tag 'mbedtls-4.0.0-beta' into mbedtls-4.0.0-beta-mergeback
Mbed TLS 4.0.0-beta
2025-07-07 17:40:18 +03: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
0038408f55 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-27 11:12:55 +01:00
Gilles Peskine
042ee3b318 Fix accidentally skipped test assertion
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-27 11:12:55 +01:00
Minos Galanakis
ed87da7ad7 Merge remote-tracking branch 'restricted/development-restricted' into future_rc
As set by process the tf-psa-crypto submodule is set
to point to tf-psa-crypto-release-sync input.
2025-06-27 10:50:33 +01:00
Gilles Peskine
f68f45c827 Merge pull request #10213 from valeriosetti/issue298-development
[development] PK: try storing all private RSA keys in PSA (2/3)
2025-06-25 15:23:27 +00:00
Valerio Setti
27eb0141b9 tests: suite_x509parse: rename variable in x509parse_crt()
- rename result_ext to result_back_comp
- add a comment to describe its purpose

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-06-25 10:25:02 +02:00
Valerio Setti
210b61111b tests: suite_x509parse: fix indentation in x509parse_crt()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-06-25 10:25:02 +02:00
Valerio Setti
2747ac1e70 tests: x509parse: fix RSA key in DER certificates
The previous key was not correct so it could not be imported into PSA
for validation inside the PK module.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-06-25 10:25:02 +02:00
Valerio Setti
11345e9de3 tests: x509parse: fix return values for invalid RSA keys
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-06-25 10:25:02 +02: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
Felix Conway
5b84ae14e9 Replace __attribute__((nonstring)) with macro MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING
This macro applies __attribute__((nonstring)) when using a compiler that supports it

Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-06-20 11:48:16 +01:00
Felix Conway
79b513894a Add __attribute__ ((nonstring)) to remove unterminated-string-initialization warning
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-06-20 11:48:16 +01:00
Manuel Pégourié-Gonnard
f5a63d1456 Fix invalid test data by aligning with 3.6
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-06-12 09:42:03 +02:00
Manuel Pégourié-Gonnard
d2262f2304 Uncomment tests now that crypto is fixed
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-06-12 09:42:03 +02:00
Valerio Setti
a81d6dfb05 tests|programs: remove usage of mbedtls_ecp_set_max_ops()
PK restartable operations are now implemented using PSA interruptible
ones, so mbedtls_ecp_set_max_ops() can be removed in favor of
psa_interruptible_set_max_ops().

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-06-12 06:39:18 +02:00
Gilles Peskine
b4cbc156ef Merge pull request #10192 from valeriosetti/fixes-for-ecp-restartable-part2
[development] Some pre-requisites for psa#299
2025-06-05 07:50:53 +00:00
Gilles Peskine
b828820f7a Declare oid_xxx_numeric_string only when they are defined
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-03 15:51:34 +02:00
Gilles Peskine
02ec585518 Replace MBEDTLS_OID_C by function-specific dependencies
For each function in `x509_oid.c`, determine where it is used and only
include it in the build if it is needed by the X.509 code. Define the
corresponding internal tables only when they are consumed by a function.

This makes Mbed TLS completely independent of the compilation option
`MBEDTLS_OID_C`. This option remains present only in sample configs for
crypto, where it must stay until TF-PSA-Crypto no longer relies on this
option.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-03 15:51:34 +02:00
Gilles Peskine
cd4c0d7b00 Move OID string definitions back to mbedtls/oid.h
Some code that parses or writes X.509 needs to know OID values. We provide a
convenient list. Don't remove this list from the public interface of the
library.

For user convenience, expose these values in the same header as before and
with the same name as before: `MBEDTLS_OID_xxx` in `<mbedtls/oid.h>`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-03 15:51:34 +02:00
Gilles Peskine
4c83221320 Replace MBEDTLS_ERR_OID_NOT_FOUND with MBEDTLS_ERR_X509_UNKNOWN_OID
Replace the non-X.509-named error code `MBEDTLS_ERR_OID_NOT_FOUND` with
`MBEDTLS_ERR_X509_UNKNOWN_OID`, which already exists and is currently not
used for anything.

Public functions in X.509 propagate this error code, so it needs to have a
public name.

Remove the definition of `MBEDTLS_ERR_OID_NOT_FOUND` in `x509_oid.h`, then

```
git grep -l MBEDTLS_ERR_OID_NOT_FOUND | xargs perl -i -pe 's/\bMBEDTLS_ERR_OID_NOT_FOUND\b/MBEDTLS_ERR_X509_UNKNOWN_OID/g'
```

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-03 15:51:34 +02:00
Gilles Peskine
47f1d7be95 Replace MBEDTLS_ERR_OID_BUF_TOO_SMALL with PSA_ERROR_BUFFER_TOO_SMALL
Remove the definition of `MBEDTLS_ERR_OID_BUF_TOO_SMALL` in `x509_oid.h`,
and use the corresponding PSA error instead.

```
git grep -l MBEDTLS_ERR_OID_BUF_TOO_SMALL | xargs perl -i -pe 's/\bMBEDTLS_ERR_OID_BUF_TOO_SMALL\b/PSA_ERROR_BUFFER_TOO_SMALL/p'
edit library/x509_oid.h
```

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-03 15:51:34 +02:00
Gilles Peskine
32a1112e88 Remove MBEDTLS_OID_X509_EXT_xxx constants
They're just aliases for the corresponding MBEDTLS_X509_EXT_xxx. We don't
need separate names.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-03 15:51:34 +02:00
Gilles Peskine
b7ef4df001 Remove OID tables that are not used in X.509
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-03 15:51:34 +02:00
Gilles Peskine
532e3ee104 Switch library and tests to the x509_oid module
```
git grep -l -P 'mbedtls_oid_get_(?!numeric_string\b)' | xargs perl -i -pe 's/\bmbedtls_oid_get_(?!numeric_string\b)/mbedtls_x509_oid_get_/'
./framework/scripts/code_style.py --since HEAD~1 --fix
```

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-03 15:51:34 +02:00
Gilles Peskine
86a47f85fa Switch to "x509_oid.h" in code that uses OID functions
Keep "mbedtls/oid.h" in code that only uses OID macros.

```
git grep -l mbedtls_oid_ '**/*.[hc]' tests/suites/*.function | xargs perl -i -pe 's!["<]mbedtls/oid\.h[">]!"x509_oid.h"!g'
```

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-03 15:51:34 +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
Valerio Setti
03a86e783b test: suites: pkcs7/x509parse: add missing PSA_INIT and PSA_DONE
Both PKCS7 and X509 rely on PK module under the hood and the latter can
use PSA to store keys and perform operations. Therefore psa_crypto_init()
must be called before any operation can be done with PKCS7 and X509.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-05-28 15:47:42 +02:00
Manuel Pégourié-Gonnard
5989da22a9 Add tests for bug in mbedtls_x509_string_to_names()
The commented out tests cause crashes (in different ways) until the bug
is fixed; the first two test are passing already and are here mostly to
provide a reference point.

The bug report was using programs/x509/cert_write, but string_to_names()
is what it was really targetting, which is better for automated tests.
The strings used are a minor adapation of those from the report.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-05-28 13:01:28 +02:00
Manuel Pégourié-Gonnard
a4ffc4e4c6 Merge remote-tracking branch 'public/development' into development-restricted
* public/development: (23 commits)
  tests: suite_x509parse: set PSA max operations in x509_verify_restart()
  library: debug: remove mbedtls_debug_printf_ecdh()
  library: debug: make mbedtls_debug_print_psa_ec() static
  Remove call to pk_decrypt() in ssl_server2
  Change hardcoded error values in ssl-opt to take in the PSA error alias
  Test with GCC 15 with sloppy union initialization
  Update crypto with the union initialization fixes
  Mark ssl_tls12_preset_suiteb_sig_algs const
  Mark ssl_tls12_preset_default_sig_algs const
  Use PSA macros for the `pkalgs` domain
  reverted compat-2.x.h removal from psa-transition.md
  Correct ChangeLog file extension
  Add ChangeLog
  remove compat-2.x.h
  Remove trace of secp224k1
  Update submodules
  Improve comments
  Allow gcc-15 to be in $PATH
  Enable drivers when testing with GCC 15
  GCC 15: Silence -Wunterminated-string-initialization
  ...
2025-05-28 12:41:28 +02:00
Valerio Setti
4a2e7b9ed8 tests: suite_x509parse: set PSA max operations in x509_verify_restart()
Set also psa_interruptible_set_max_ops() when mbedtls_ecp_set_max_ops()
is set so that the same amount of operations will be used both if legacy
ECDSA_C or PSA is used under the hood to perform the operation.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-05-23 15:15:22 +02:00
Manuel Pégourié-Gonnard
bda3ab9278 Add unit test for new behaviour of string_to_names()
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-05-12 12:34:11 +02:00
Gilles Peskine
49b7ef635f Merge pull request #10166 from gilles-peskine-arm/oid-split-restore-x509
Restore the OID module for use in X.509
2025-05-12 07:59:55 +00:00
Gilles Peskine
1876efc157 Merge remote-tracking branch 'development' into HEAD 2025-05-07 14:41:13 +02:00
Gilles Peskine
47c8579ed0 Copy OID files that are getting moved to tf-psa-crypto
The OID module is used by both crypto and X.509. It has moved to the
`tf-psa-crypto` subdirectory, and the sibling commit
08d8cc57db removes this subdirectory from the
`mbedtls` repository in order to make `tf-psa-crypto` a submodule. We want
to access the relevant parts directly from X.509 rather than go through the
crypto repository, because OID functions are only accessible as private
interfaces, and crypto doesn't know when a particular OID function is needed
in the build since it depends on X.509 configuration options.

Make a copy of the OID module and its unit tests. In a follow-up, the X.509
module will switch to consuming this copy rather than the one that went into
TF-PSA-Crypto.

Rename the files from `*oid*` to `*x509_oid*` to follow the naming
convention that submodules of X.509 are prefixed with `x509`. This also
avoids file name clashes with TF-PSA-Crypto.

Since OID is not a public interface of Mbed TLS 4.x, move the header file
into `library`.

This commit only makes the files available. Subsequent commits will take
care of making these files used in the build.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-07 14:35:04 +02:00
Valerio Setti
b8d5649ab6 tests: test_suite_x509: adapt RSA-PSS tests
Parsing of CRT files with message's hash alg different from the MGF1 was
allowed in the past, but now it fails. So we need to move/adapt tests
relying on this feature, from a "verify" scope to a "parse" one.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-05-07 09:06:52 +02:00
Valerio Setti
7f6f4e6907 library: pass NULL options parameter to mbedtls_pk_verify_ext()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-05-07 09:06:52 +02:00