13337 Commits

Author SHA1 Message Date
Gilles Peskine
b6bf370159 Assert that key ID ranges don't overlap
Ensure that a key ID can't be in range for more than one of volatile keys,
persistent (i.e. user-chosen) keys or built-in keys.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-07-17 12:21:21 +02:00
Gilles Peskine
d72ad738bd Prevent mbedtls_psa_register_se_key with volatile keys
mbedtls_psa_register_se_key() is not usable with volatile keys, since there
is no way to return the implementation-chosen key identifier which would be
needed to use the key. Document this limitation. Reject an attempt to create
such an unusable key. Fixes #9253.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-07-17 12:21:21 +02:00
Gilles Peskine
86c603702e Reorder blocks to avoid double negations
Convert `#if !... A #else B #endif` to `#if ... B #else A`. No semantic change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-07-17 12:21:21 +02:00
Gilles Peskine
4804847b15 Make it possible to enable CTR_DRBG/PSA without a PSA AES driver
Make it possible, but not officially supported, to switch the CTR_DRBG
module to PSA mode even if MBEDTLS_AES_C is defined. This is not really
useful in practice, but is convenient to test the PSA mode without setting
up drivers.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-07-17 12:21:21 +02:00
Gilles Peskine
cd693c36fd MBEDTLS_STATIC_ASSERT: make it work outside of a function
At the top level, the macro would have had to be used without a following
semicolon (except with permissive compilers that accept spurious semicolons
outside of a function), which is confusing to humans and indenters. Fix
that.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-07-17 12:21:21 +02:00
Gilles Peskine
422a276c5e
Merge pull request #9045 from Troy-Butler/handle-null-args
[Backport 3.6] Fix NULL argument handling in mbedtls_xxx_free() functions
2024-07-04 14:50:59 +00:00
Gilles Peskine
41204b86d8
Merge pull request #9272 from sezrab/silence-3.6
[Backport 3.6] Silence gcc 12.2.0 warning
2024-07-04 14:49:41 +00:00
Gilles Peskine
c03041844b
Merge pull request #9341 from gilles-peskine-arm/psa_cipher_decrypt-ccm_star-iv_length_enforcement-3.6
Backport 3.6: psa_cipher_decrypt CCM*: fix rejection of messages shorter than 3 bytes
2024-07-04 14:39:29 +00:00
Gilles Peskine
acef7b3894
Merge pull request #9132 from andre-rosa/check-overflow-when-reading-padding-len-on-aes-128-cbc-decryption-for-mbedtls-3.6
Backport 3.6: Add invalid `padding_len` check in `get_pkcs_padding`
2024-07-03 14:41:17 +00:00
Gilles Peskine
b47c3b3111 psa_cipher_decrypt CCM*: fix rejection of messages shorter than 3 bytes
Credit to Cryptofuzz. Fixes #9314.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-07-03 09:42:35 +02:00
Patrick Wildt
38bc960ecf Silence gcc 12.2.0 warning
Unfortunately this compiler complains about a variable potentially being
used un-initialized.  Silence the warning by initializing it to a sane
default.

Signed-off-by: Patrick Wildt <pwildt@google.com>
2024-06-17 12:24:02 +01:00
Tom Cosgrove
8fb5df859c
Merge pull request #9248 from sezrab/fix-function-parameter-3.6
[Backport 3.6] Fix incorrect array length in function prototype
2024-06-13 07:55:57 +00:00
Tom Cosgrove
07f9459a24
Merge pull request #9245 from lhuang04/mbedtls_3_6_psk_null_back_port
Set psk to NULL in ssl_psk_remove -backpor to 3.6
2024-06-12 12:00:28 +00:00
Sam Berry
9722fd133d Fix incorrect array length in function prototype
Issue #9179 (MBEDTLS_SSL_CID_OUT_LEN_MAX changed to
MBEDTLS_SSL_CID_IN_LEN_MAX in library\ssl.h and library\ssl_tls.c)

Signed-off-by: Sam Berry <sam.berry@arm.com>
2024-06-12 11:16:46 +01:00
lhuang04
6d4d94f3d0 Set psk to NULL in ssl_psk_remove -backpor to 3.6
Summary:
Backport [PR 9241](https://github.com/Mbed-TLS/mbedtls/pull/9241) to 3.6
branch.

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
Signed-off-by: lhuang04 <lhuang04@fb.com>
2024-06-11 13:05:02 -07:00
Gilles Peskine
400659b565 Use unsigned long rather than size_t for format string readability
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-06-05 11:49:51 +02:00
Gilles Peskine
eeb4ff5662 Fix uint32_t printed as unsigned int
This is ok in practice since we don't support 16-bit platforms, but it makes
`arm-none-eabi-gcc-10 -mthumb -Wformat` complain.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-06-05 11:49:50 +02:00
Gilles Peskine
dc49258c8a Guard configuration-specific code
A large block of code is only reachable if MBEDTLS_PK_USE_PSA_EC_DATA is
enabled, i.e. if MBEDTLS_USE_PSA_CRYPTO is enabled with driver-only ECC.
Compilers are likely to figure it out, but still, for clarity and
robustness, do guard that block of code with the appropriate conditional
compilation guard.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-05-29 20:09:36 +02:00
Gilles Peskine
b69757ab61 Fix a compilation warning in pk.c when PSA is enabled and RSA is disabled
It isn't detected on the CI because we only test this with an ancient Clang
that doesn't warn. Old GCC, modern GCC and modern Clang do
warn (-Wunused-but-set-variable).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-05-14 12:06:20 +02:00
Andre Goddard Rosa
3711734a0a Add invalid padding_len check in get_pkcs_padding
When trying to decrypt data with an invalid key, we found that `mbedtls`
returned `0x6200` (`-25088`), which means "_CIPHER - Input data contains
invalid padding and is rejected_" from `mbedtls_cipher_finish`, but it also
set the output len as `18446744073709551516`.

In case we detect an error with padding, we leave the output len zero'ed
and return `MBEDTLS_ERR_CIPHER_INVALID_PADDING`.

Here's a reference for the way `openssl` checks the padding length:
  - 1848c561ec/crypto/evp/evp_enc.c (L1023)
  - b554eef43b

So add a check ensuring output is set to the least-harmful value in the
error cases.

With the robustness fix:
`PASSED (125 suites, 26644 tests run)`

Without the robustness fix:
`FAILED (125 suites, 26644 tests run)`

Signed-off-by: Andre Goddard Rosa <andre.goddard@gmail.com>
Signed-off-by: Andre Goddard Rosa <agoddardrosa@roku.com>
2024-05-13 09:27:57 -05:00
Gilles Peskine
c4f4ff9210
Merge pull request #9085 from nileshkale123/fix/redefinition_warning_for_gnu_source_backport_3.6
Backport 3.6: Fixed issue of redefinition warning messages for _GNU_SOURCE
2024-05-06 12:40:45 +00:00
Manuel Pégourié-Gonnard
67a92b7442
Merge pull request #9090 from valeriosetti/issue9068-backport
[Backport 3.6] Undefined reference to mbedtls_md_error_from_psa() function
2024-05-03 07:52:41 +00:00
Valerio Setti
b82fbf5634 md: fix guards for mbedtls_md_error_from_psa()
This should be CRYPTO_CLIENT and not CRYPTO_C as this function
can be used even when CRYPTO_C is not defined.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-02 18:18:45 +02:00
Gilles Peskine
51e96ad34c
Merge pull request #9074 from Ryan-Everett-arm/8357-fix-3.6
Backport 3.6: Fix error handling for secure element keys in `psa_start_key_creation`
2024-05-02 16:06:09 +00:00
nilesh.kale
2a0a62859c Fixed issue of redefinition warning messages for _GNU_SOURCE
Signed-off-by: nilesh.kale <nilesh.kale@espressif.com>
2024-05-02 14:27:44 +05:30
Ryan Everett
1a3573e226 Clarify psa_get_and_lock_key_slot return behaviour
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-30 14:09:43 +01:00
Ryan Everett
231f15ba11 Explicitly document return behaviour
A bug existed previously where this guarantee was not met,
causing some issues in multi-threaded code.

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-30 14:09:43 +01:00
Ryan Everett
d4ea40de44 Fix potential non-NULL slot return on failure
If psa_get_and_lock_key_slot fails, the slot must be wiped.
This fixes a bug where a pointer to some valid key slot can
be incorrectly returned

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-30 14:09:43 +01:00
Ryan Everett
b5a20d3bc5 Fix error handling for secure element keys in psa_start_key_creation
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-30 11:17:04 +01:00
Gilles Peskine
3dbb502098
Merge pull request #9066 from paul-elliott-arm/fix_ubsan_mp_aead_gcm_3.6
[Backport 3.6] Add early exit if zero length AEAD additional data passed in.
2024-04-30 09:48:24 +00:00
Paul Elliott
304766ffa8 Add early exit if zero length AEAD AD passed in.
With multipart AEAD, if we attempt to add zero length additional data,
then with the buffer sharing fixes this can now lead to undefined
behaviour when using gcm. Fix this by returning early, as there is
nothing to do if the input length is zero.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2024-04-26 19:20:45 +01:00
Valerio Setti
4a350cac4f pk: fix unused variable in copy_from_psa()
key_bits is unused when neither MBEDTLS_RSA_C or MBEDTLS_PK_HAVE_ECC_KEYS
are defined.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Gilles Peskine
974006b00d
Merge pull request #9000 from tom-cosgrove-arm/fix-compilation-when-memcpy-is-function-like-macro-3.6
Backport 3.6: Fix compilation when memcpy() is a function-like macro
2024-04-09 11:34:51 +00:00
Ronald Cron
8d63084bd1 tls13: Do not initiate at all resumption if tickets not supported
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-04-05 14:16:32 +02:00
Ronald Cron
698c8e902e ssl_msg.c: Rename _check_new_session_ticket to _is_new_session_ticket
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-04-05 14:16:32 +02:00
Ronald Cron
6071f611f6 tls13: cli: Ignore tickets if not supported
If a TLS 1.3 client receives a ticket and
the feature is not enabled, ignore it.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-04-05 14:16:32 +02:00
Norbert Fabritius
93b2c32ece Constify parameter of ssl_tls13_session_load
Signed-off-by: Norbert Fabritius <norbert.fabritius@esrlabs.com>
2024-04-05 14:16:31 +02:00
Norbert Fabritius
ba1de9fa4e Enable ssl_tls13_get_ciphersuite_hash_alg only if macro is active
Signed-off-by: Norbert Fabritius <norbert.fabritius@esrlabs.com>
2024-04-05 14:16:31 +02:00
Norbert Fabritius
b6ff6101d9 Unconditionally define session variable
Signed-off-by: Norbert Fabritius <norbert.fabritius@esrlabs.com>
2024-04-05 14:16:31 +02:00
Ronald Cron
5e297b984d tls13: srv: Fix guards of _is_psk_(ephemeral_)available
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-04-05 14:16:31 +02:00
Norbert Fabritius
da0d169fae Guard ticket specific TLS 1.3 function with macro
Guard ssl_tls13_write_new_session_ticket_coordinate with
MBEDTLS_SSL_SESSION_TICKETS macro.

Signed-off-by: Norbert Fabritius <norbert.fabritius@esrlabs.com>
2024-04-05 14:16:31 +02:00
Bence Szépkúti
ec17c1c1ab
Merge pull request #9005 from valeriosetti/issue8712-backport
[Backport 3.6] Clarify the documentation of mbedtls_pk_setup_opaque
2024-04-04 13:41:15 +00:00
Valerio Setti
a53f54350e pk: simplify mbedtls_pk_sign_ext()
In case of opaque keys skip the check of the supported primary/enrollment
algorithms. Just try to perfom the signature and if the wrapped key
does not support RSA PSS the operation will fail automatically.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-04 09:42:01 +02:00
Troy-Butler
da73abc8d7 Fix NULL handling in mbedtls_ssl_config.free() function
Signed-off-by: Troy-Butler <squintik@outlook.com>
2024-04-02 13:37:31 -04:00
Tom Cosgrove
b32d7ae0fe Fix compilation of ssl_tls13_generic.c when memcpy() is a function-like macro
Fixes #8994

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2024-04-02 14:52:29 +01:00
Paul Elliott
30978ec650
Merge pull request #8874 from stevenwdv/development
Fix compilation on macOS without apple-clang
2024-03-29 13:59:36 +00:00
Minos Galanakis
9860056006 Revert "Autogenerated files for 3.6.0"
This reverts commit e8a6833b2878f1c08b8f96fe35e2812367e32ef3.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-03-27 17:36:15 +00:00
Troy-Butler
9ac3e23f5d Fix NULL argument handling in mbedtls_xxx_free() functions
Signed-off-by: Troy-Butler <squintik@outlook.com>
2024-03-22 14:46:04 -04:00
Minos Galanakis
e8a6833b28 Autogenerated files for 3.6.0
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-03-22 16:00:55 +00:00
Minos Galanakis
4492dbd286 Version Bump for 3.6.0
./scripts/bump_version.sh --version 3.6.0 --so-crypto 16 --so-x509 7  --so-tls 21

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-03-22 11:46:25 +00:00