13943 Commits

Author SHA1 Message Date
Gilles Peskine
657760964e
Merge pull request #1660 from bjwtaylor/info-leak-in-ssl_write_new_session_ticket-4.1
Info leak in ssl write new session ticket 4.1
2026-06-24 09:42:16 +02:00
Gilles Peskine
7674b49934
Merge pull request #1656 from valeriosetti/issue1598-backport4.1
[4.1] PKCS7 accepts weak hashes
2026-06-23 16:40:44 +02:00
Ronald Cron
788a536868
Merge pull request #1673 from bjwtaylor/pkcs-free-stale-pointers-4.1
Pkcs free stale pointers 4.1
2026-06-22 17:54:49 +02:00
Valerio Setti
0b556f5a2d pkcs7: add MBEDTLS_PKCS7_ALLOW_WEAK_SIGNATURES build symbol
It allows weak hash algorithms to be used in PKCS7. It's only added in the
LTS branch for backward compatibility, but it's disabled by default because
that's the safest choice.

This commit also updates test data in order to test the new build symbol.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-06-22 11:46:29 +02:00
Valerio Setti
7cc706ca5a pkcs7: replace MBEDTLS_ERR_PKCS7_VERIFY_FAIL with MBEDTLS_ERR_PKCS7_VERIFY_FAIL
This also updates test data.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-06-22 11:45:56 +02:00
Valerio Setti
f27a1572e3 pkcs7: split MD/PK check in mbedtls_pkcs7_data_or_hash_verify
Follow the default Mbed TLS coding style and ease debugging (i.e. placing
of breakpoints).

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-06-22 11:45:56 +02:00
Valerio Setti
b4d729fb02 pkcs7: fail verification if MD alg or sig_alg are not secure
Add a check on mbedtls_pkcs7_data_or_hash_verify() so that the verification
fails if the MD alg specified in PKCS7 structure or the signature
algorithm specified in the X.509 certificate are not in the list of
secure algorithms (i.e. mbedtls_x509_crt_profile_default).

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-06-22 11:45:56 +02:00
Valerio Setti
9bcea79cb5 x509: make profile checking functions internally available
Following functions

- x509_profile_check_md_alg
- x509_profile_check_pk_alg

are made non-static and moved to x509_internal.h so that other library
files can used them.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-06-22 11:45:56 +02:00
Valerio Setti
227bb646b1 x509_crt: add SHA3 algs to mbedtls_x509_crt_profile_default
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-06-22 11:45:56 +02:00
Valerio Setti
833a926a92 x509_crt: remove old invalid comment
ssl_preset_default_hashes was removed in
f0cda410a4bca0f45f66bdbf0714cd0eb2ea4718 but the comment in 'x509_crt.c'
wasn't updated.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-06-22 11:45:56 +02:00
Gilles Peskine
2660eea3f0
Merge pull request #1629 from gilles-peskine-arm/basic-constaints-sequence-check-4.1
Backport 4.1: Fix CA bit forgery through invalid basicConstraints
2026-06-18 15:36:46 +02:00
Ben Taylor
b1a4b07509 Add fix for stale pointer after mbedtls_pkcs7_free
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-18 13:04:13 +01:00
Gilles Peskine
1f5b89077c
Merge pull request #1655 from bjwtaylor/ECDHE-PSK-integer-overflow-restricted-4.1
Backport Ecdhe psk integer overflow restricted fix to  4.1
2026-06-16 11:49:57 +02:00
Ronald Cron
5ea102945d
Merge pull request #1661 from minosgalanakis/public-sync/mbedtls-4.1-14062026
[Sync] Merge mbedtls-4.1 into Merge mbedtls-4.1-restricted
2026-06-16 09:02:13 +02:00
Ronald Cron
9d54126d0e
Merge pull request #1646 from bjwtaylor/oob-key-exchange-restricted-4.1
Add fix for OOB key exchange error 4.1
2026-06-15 22:42:15 +02:00
Minos Galanakis
e1896dbfd8 Merge remote-tracking branch 'public/mbedtls-4.1' into public-sync/mbedtls-4.1-14062026
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-06-14 19:36:52 +01:00
Ben Taylor
dd5a8501c0 Improve robustness of tlen and lifetime variables
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-11 16:24:04 +01:00
Ben Taylor
56e314728b Add fix for leak
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-11 16:24:04 +01:00
Ben Taylor
f63ca6e0af Added fix for Integer overflow using a large ECDHE Identity
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
(cherry picked from commit baf449db7e31f031ed5def0fecf417122f72d3ee)
2026-06-10 14:34:10 +01:00
Ronald Cron
b9af3cd809
Merge pull request #1608 from minosgalanakis/security/mlfbyt4c_tls13_policy_bypass_4.1
Backport 4.1: TLS1.3 client HRR policy bypass[ARM-MLFBYT4C]
2026-06-10 13:04:01 +02:00
Gilles Peskine
4ac13cc65f Stop accepting basicConstraints with only pathLenConstraint
In an X.509 certificate, a basicConstraints extension where the cA
field (BOOLEAN) is omitted but the pathLenConstraint field (INTEGER )is
present is syntactically valid, but RFC 5280 states that CAs MUST NOT emit
such a certificate.

Historically, since XySSL 0.9 in 2008, if a basicConstraints extension
started with an INTEGER field, we interpreted that field as a cA value. This
was a deliberate change:

> Fixed x509_get_ext() to accept some rare certificates (like
> www.openssl.org:443) which have an INTEGER instead of a BOOLEAN for
> Extension::BasicConstraints::cA.

However, 18 years later, this does not seem to be relevant, and the details
seem to have been lost. Furthermore, major implementations follow RFC 5280
and interpret `SEQUENCE { INTEGER n }` with cA being set to its default
value (FALSE) and pathLenConstraint set to `n`. This means that such a
certificate with n != 0 would be interpreted as a CA certificate in Mbed TLS
but as a leaf certificate elsewhere, which is dangerous.

Since CAs are not supposed to emit such certificates, stop accepting them
altogether.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 11:34:32 +02:00
Gilles Peskine
ef81e71061 Remove unreachable CSR extensionRequest check
It is now unreachable because:

- end_set == end_attr_data is enforced at library/x509_csr.c:236.
- end_exts == end_set is enforced at library/x509_csr.c:248.
- x509_csr_parse_extensions() only returns success if *p == end_exts, enforced
  at library/x509_csr.c:188.

So after a successful x509_csr_parse_extensions() call, *p == end_exts ==
end_set == end_attr_data. The condition at line 257 cannot be true.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 11:34:22 +02:00
Gilles Peskine
44b833324b Tighten CSR extensionRequest bounds
Don't allow parts of a compound (SEQUENCE or SET) to go beyond the
containing compound.

The inline CSR regression test is derived from the existing "X509 CSR
ASN.1 (OK)" DER test vector. In the extensionRequest attribute, the original
well-formed fragment is:

    a029 3027 06092a864886f70d01090e 311a 3018 ...

where 31 1a is the SET containing the Extensions sequence and 30 18 is the
contained Extensions sequence. The malformed test changes only the SET
length byte, from 1a to 19:

    a029 3027 06092a864886f70d01090e 3119 3018 ...

The attribute SEQUENCE length and the inner Extensions sequence length are
left unchanged. This makes the SET one byte too short for its containing
attribute, so the parser must reject it with
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH instead of parsing the trailing byte as
data outside the SET.

There is no known security impact, just some risk reduction.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-06-05 11:34:13 +02:00
Ben Taylor
1ac3989db6 Add fix for OOB key exchange error
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-06-05 09:49:35 +01:00
Ronald Cron
a73dce874b
Merge pull request #1588 from gilles-peskine-arm/ssl_tls13_prepare_new_session_ticket-psa_get_random-4.1
Backport 4.1: Fix ssl_tls13_prepare_new_session_ticket returning 1 on an RNG failure
2026-05-29 16:20:07 +02:00
Gilles Peskine
9007fc4b9b Fix lax basicConstraints parsing
When parsing the basicConstraints extension, reject junk after the SEQUENCE
inside the extension (which is probably benign), and reject a SEQUENCE that
extends beyond the extension (could be very dangerous).

Add a non-regression test where a certificate that is technically malformed,
but accepted as a leaf certificate by OpenSSL and other X.509
implementations, to be accepted as a CA certificate by Mbed TLS.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-05-26 20:51:52 +02:00
Minos Galanakis
e16f0e0b01 ssl_write_supported_groups_ext: Updated documentation
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-05-26 10:31:03 +01:00
Janos Follath
a4f79350ac
Merge pull request #10742 from valeriosetti/backport-pr10741
[backport 4.1] mbedtls_config.c missing mbedtls_platform_requirements.h
2026-05-26 09:24:50 +00:00
Minos Galanakis
f8adf74988 sll_client: align TLS 1.3 supported_groups filtering with PSA curve support
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-05-20 15:00:52 +01:00
Minos Galanakis
cec2cef6b5 tls13_client: fix HRR selected_group validation
Reject HRR selected_group unless it matches the client’s original
supported_groups and is locally supported, so unadvertised groups are not
accepted in the second ClientHello.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-05-12 15:02:05 +01:00
Gilles Peskine
465d6e9669 Fix ssl_tls13_prepare_new_session_ticket returning 1 on an RNG failure
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-05-04 18:44:05 +02:00
Valerio Setti
23538fd562 include mbedtls_platform_requirements.h in mbedtls_config.c
This is required because if the user defined configuration file (not the
default one provided by mbedtls) includes files from the standard
C library then __STDC_WANT_LIB_EXT1__ won't be defined there which
cause weird build failures.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-04-29 17:10:04 +02:00
Gilles Peskine
ded271a8c4
Merge pull request #10696 from yiwu0b11/destdir_install_env_support-4.1
Backport 4.1: Support DESTDIR for install and add build-system test
2026-04-29 14:37:40 +00:00
Valerio Setti
5875ffa6fc
Merge pull request #10713 from valeriosetti/backport-pr10650
[backport 4.1] check_config: add missing check for TLS 1.3 key exchanges
2026-04-24 14:32:42 +00:00
Valerio Setti
f2ab107392 check_config: fix error message for missing TLS 1.2 key exchanges
Align the error message to the one used for the same check in TLS 1.3.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-04-23 14:51:52 +02:00
Valerio Setti
1caa7db5e8 check_config: add check for TLS 1.3 key exchanges
When MBEDTLS_SSL_PROTO_TLS1_3 is enabled ensure that at least one of the
related key exchanges is also enabled.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-04-23 14:51:48 +02:00
Valerio Setti
2882b73697 library: check_config: remove RSA encryption requirement from ECDHE-RSA
ECDHE-RSA only requires RSA signature, not encryption. This commits fixes
guards in "mbedtls_check_config.h".

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-04-22 17:17:41 +02:00
Yi Wu
897daf3ea1 Support DESTDIR for install and add build-system test
Signed-off-by: Yi Wu <yi.wu2@arm.com>
2026-04-20 10:48:29 +01:00
Viktor Sokolovskiy
4302c8dffb Pacify uncrustify
Signed-off-by: Viktor Sokolovskiy <maokaman@gmail.com>
2026-04-18 02:02:15 +03:00
Viktor Sokolovskiy
5fc28f4016 ssl: accept TLS 1.2 rsa_pss_rsae in client SKE
Fix a TLS 1.2 client regression that caused valid ServerKeyExchange signatures using rsa_pss_rsae_* to be rejected.

Allow rsa_pss_rsae_* in the TLS 1.2 client ServerKeyExchange parse path when the algorithm is supported and was offered by the client. Add OpenSSL and GnuTLS interoperability coverage for TLS 1.2 servers that force rsa_pss_rsae_sha256.

Fixes #10668.

Signed-off-by: Viktor Sokolovskiy <maokaman@gmail.com>
2026-04-17 19:16:20 +03:00
Minos Galanakis
e89565f92a Bump version
./scripts/bump_version.sh --version 4.1.0 \
  --so-crypto 18 --so-tls 23 --so-x509 9

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-26 22:34:28 +00:00
Minos Galanakis
308e7fb232 Merge remote-tracking branch 'restricted/development-restricted' into mbedtls-4.1.0.rc3
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-26 22:18:31 +00:00
Ronald Cron
1330606ca1 dtls: Fix adaptation to first ClientHello
For each received ClientHello fragment, check
that its epoch is zero and update the
record-level sequence number.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:45:24 +01:00
Ronald Cron
1141cd0fb6 Improve comments
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:45:24 +01:00
Ronald Cron
f2f44a9c9f Restrict mapping of UNEXPECTED_RECORD to UNEXPECTED_MESSAGE
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:45:24 +01:00
Ronald Cron
c9264ad227 dtls: Fix log level
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
140ebea442 dtls: parse_client_hello: Adapt mbedtls_ssl_read_record() error code
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
f9b7441542 dtls: Keep invalid/unexpected record header error code
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
0c301a686a dtls: Improve comment
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00
Ronald Cron
912ef74195 Update buffering when adapting to ClientHello message_seq
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 08:44:16 +01:00