1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-06-07 22:42:02 +03:00

13634 Commits

Author SHA1 Message Date
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
7e7dc6fdda Align endif comments with auxiliary macros
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
6354411670 Remove unused function
mbedtls_oid_get_md_alg() is used in X.509, but
mbedtls_oid_get_oid_by_md() is only used in crypto.

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
71ccc723cd Remove macros for crypto OID
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
d2fe51cfc4 Add the x509_oid module to the build
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-03 15:51:34 +02:00
Gilles Peskine
86e45ba0ba Rename OID functions and types to mbedtls_x509_oid_xxx in x509_oid
Avoid clashes with the functions and the type that are still defined in
TF-PSA-Crypto. They are now internal names, so it doesn't really matter, but
having the same name as the ones declared in TF-PSA-Crypto's `oid.h` would
cause problems during the transition.

Remove the unused name for `struct mbedtls_oid_descriptor_t`, and rename the
rest:

```
perl -i -pe 's/mbedtls_oid_/mbedtls_x509_oid_/g' library/x509_oid.[hc]
./framework/scripts/code_style.py --fix library/x509_oid.[hc]
```

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
b825dcfe2d Update file names in comments
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-03 15:51:34 +02:00
Valerio Setti
ffac311aaf library: debug: fix guards for EC helper functions
Move mbedtls_debug_print_ecp(), mbedtls_debug_print_ec_coord() and
mbedtls_debug_print_psa_ec() under the same guards as debug_print_pk().

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-05-27 09:58:02 +02:00
Valerio Setti
199a15645d library: debug: make mbedtls_debug_print_ecp() internal
Remove the public definition of mbedtls_debug_print_ecp(). The function
is only used internally in debug.c, so we can then make the function
static.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-05-27 09:56:27 +02:00
Valerio Setti
153a906a51 library: debug: remove mbedtls_debug_printf_ecdh()
The function is not used anywhere and can be removed.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-05-23 15:08:48 +02:00
Valerio Setti
28ef01a3c1 library: debug: make mbedtls_debug_print_psa_ec() static
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-05-23 15:03:26 +02:00
Deomid rojer Ryabkov
7dddc1724f Mark ssl_tls12_preset_suiteb_sig_algs const
Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-05-15 15:27:40 +03:00
Deomid rojer Ryabkov
e2d71ccc64 Mark ssl_tls12_preset_default_sig_algs const
To place in flash and save RAM on targets where this applies.

Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-05-15 15:27:40 +03: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
46771ff0d6 Remove trace of secp224k1
The curve secp224k1 was supported in the legacy API in Mbed TLS <=3.6, but
removed after 3.6, and was never implemented in PSA. Remove this old trace
of it.

This is a partial cherry-pick of 32c82f0c369117b22d8a40e51723c364156d1aff

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-07 19:17:35 +02: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
08d8cc57dbe7be54fe3f88ecbc2729300c48d450 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
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
Valerio Setti
d24dfad7af library: x509: remove sig_opts from mbedtls_x509_sig_alg_gets()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-05-07 09:06:52 +02:00
Valerio Setti
68878ccdd0 library: x509: simplify RSA-PSS management
- Do not store RSA-PSS signature options in CRL/CRT/CSR structures;
- During the parsing phase, just ensure that MGF1 hash alg is the same
  as the one used for the message.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-05-07 09:06:52 +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
Max Fillinger
dba07e152e Add missing ifdef for mbedtls_ssl_tls13_exporter
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-04-16 14:48:14 +02:00
Gilles Peskine
bc694b3cbd Fix printf of enum
The enum is promoted to `int`, so `%d` is a correct format,
but `gcc -Wformat` complains.

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
c67befee6a Add a log message on every SSL state transition
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-09 12:52:26 +02:00
Gilles Peskine
f670ba5e52 Always call mbedtls_ssl_handshake_set_state
Call a single function for all handshake state changes, for easier tracing.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-09 12:52:22 +02:00
Manuel Pégourié-Gonnard
ed4a2b4f0a Merge branch 'development-restricted' into merge-from-restricted
* development-restricted:
  Add missing credit for set_hostname issue
  Add changelog entry for TLS 1.2 Finished fix
  TLS1.2: Check for failures in Finished calculation
  ssl_session_reset: preserve HOSTNAME_SET flag
  Document the need to call mbedtls_ssl_set_hostname
  Improve documentation of mbedtls_ssl_set_hostname
  Changelog entries for requiring mbedls_ssl_set_hostname() in TLS clients
  Add a note about calling mbedtls_ssl_set_hostname to mbedtls_ssl_setup
  mbedtls_ssl_set_hostname tests: add tests with CA callback
  Call mbedtls_ssl_set_hostname in the generic endpoint setup in unit tests
  Require calling mbedtls_ssl_set_hostname() for security
  Create error code for mbedtls_ssl_set_hostname not called
  Keep track of whether mbedtls_ssl_set_hostname() has been called
  Access ssl->hostname through abstractions in certificate verification
  mbedtls_ssl_set_hostname tests: baseline
  Add a flags field to mbedtls_ssl_context
  Automate MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK dependency
  Make guards more consistent between X.509-has-certs and SSL-has-certs
  Fix Doxygen markup
  Make ticket_alpn field private

 Conflicts:
	programs/ssl/ssl_test_common_source.c
2025-04-01 09:40:47 +02:00
Max Fillinger
af2035fcad Fix mistake in previous comment change
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 17:08:12 +01:00
Max Fillinger
ee33b31f0b Fix HkdfLabel comment
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 17:08:12 +01:00
Max Fillinger
5826883ca5 Allow maximum label length in Hkdf-Expand-Label
Previously, the length of the label was limited to the maximal length
that would be used in the TLS 1.3 key schedule. With the keying material
exporter, labels of up to 249 bytes may be used.

Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 17:08:12 +01:00
Max Fillinger
9c5bae5026 Fix max. label length in key material exporter
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 17:08:12 +01:00
Max Fillinger
53d9168502 Document BAD_INPUT_DATA error in key material exporter
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 17:08:12 +01:00
Max Fillinger
c6fd1a24d2 Use one maximum key_len for all exported keys
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 17:06:48 +01:00
Max Fillinger
3e1291866d Fix output size check for key material exporter
HKDF-Expand can produce at most 255 * hash_size bytes of key material,
so this limit applies to the TLS 1.3 key material exporter.

Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 17:06:48 +01:00
Max Fillinger
28916ac8fe Increase allowed output size of HKDF-Expand-Label
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 17:06:48 +01:00
Max Fillinger
0747388254 Fix #endif comment
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 16:53:58 +01:00
Max Fillinger
2fe35f61bf Create MBEDTLS_SSL_KEYING_MATERIAL_EXPORT option
Add the option MBEDTLS_SSL_KEYING_MATERIAL_EXPORT to mbedtls_config.h
to control if the function mbedtls_ssl_export_keying_material() should
be available. By default, the option is disabled.

This is because the exporter for TLS 1.2 requires client_random and
server_random need to be stored after the handshake is complete.

Signed-off-by: Max Fillinger <max@max-fillinger.net>
2025-03-28 16:53:58 +01:00
Max Fillinger
281fb79116 Remove TLS 1.2 Exporter if we don't have randbytes
The TLS-Exporter in TLS 1.2 requires client_random and server_random.
Unless MBEDTLS_SSL_CONTEXT_SERIALIZATION is defined, these aren't stored
after the handshake is completed.

Therefore, mbedtls_ssl_export_keying_material() exists only if either
MBEDTLS_SSL_CONTEXT_SERIALIZATION is defined or MBEDTLS_SSL_PROTO_TLS1_2
is *not* defined.

Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 16:53:58 +01:00
Max Fillinger
c9f2c9adba Revert "Store randbytes for TLS 1.2 TLS-Exporter"
This reverts commit cb01dd1333f8083af469e9a0c59f316f1eb0cfe3.

Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 16:53:58 +01:00
Max Fillinger
155cea0900 Use fewer magic numbers in TLS-Exporter functions
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 16:53:58 +01:00
Max Fillinger
f2dda15ce8 Add label length argument to tls_prf_generic()
This way, it's not required that the label is null-terminated. This
allows us to avoid an allocation in
mbedtls_ssl_tls12_export_keying_material().

Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 16:53:58 +01:00
Max Fillinger
48150f5dc3 Store randbytes for TLS 1.2 TLS-Exporter
Previously, if MBEDTLS_SSL_CONTEXT_SERIALIZATION is not defined,
randbytes are not stored after the handshake is done, but they are
needed for TLS-Exporter in TLS 1.2.

This commit also saves randbytes if MBEDTLS_SSL_PROTO_TLS1_2 is defined.

Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
2025-03-28 16:53:58 +01:00