13351 Commits

Author SHA1 Message Date
Waleed Elmelegy
41e0cdf8c1 Fix issue in handling legacy_compression_methods in ssl_tls13_parse_client_hello()
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2024-08-22 15:50:45 +00:00
Gilles Peskine
7f9470ac02
Merge pull request #9451 from minosgalanakis/fix-v3.6-issues-9186-and-9188-bp
[Backport 3.6] Fix v3.6 issues 9186 and 9188 bp
2024-08-12 09:34:19 +00:00
Gilles Peskine
3b41e1d2a5
Merge pull request #9403 from gilles-peskine-arm/psa-keystore-dynamic-prep-3.6
Backport 3.6: prepare for dynamic key store
2024-08-09 08:00:03 +00:00
Gilles Peskine
5eca4029c2 Fix inverted assertion message
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 20:08:23 +02:00
Gilles Peskine
4a85ff3997 Rename one more deprecated identifier
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:13:05 +02:00
Gilles Peskine
0d619b2dc7 Documentation improvements
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:13:05 +02:00
Gilles Peskine
52504f8568 Rename internal function psa_key_production_parameters_are_default
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:13:05 +02:00
Gilles Peskine
f36d785188 Implement psa_generate_key_custom
Implement `psa_generate_key_custom()` and
`psa_key_derivation_output_key_custom()`. These functions replace
`psa_generate_key_ext()` and `psa_key_derivation_output_key_ext()`.
They have the same functionality, but a slightly different interface:
the `ext` functions use a structure with a flexible array member to pass
variable-length data, while the `custom` functions use a separate parameter.

Keep the `ext` functions for backward compatibility with Mbed TLS 3.6.0.
But make them a thin wrapper around the new `custom` functions.

Duplicate the test code and data. The test cases have to be duplicated
anyway, and the test functions are individually more readable this way.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:12:06 +02:00
Michael Schuster
4d0d0ec028 Move the -Wmissing-prototypes option from library/CMakeLists.txt to the top-level CMakeLists.txt for GCC & Clang
Signed-off-by: Michael Schuster <michael@schuster.ms>
2024-08-06 12:09:13 +01:00
Michael Schuster
5be4fd784e Fix build of v3.6 with unset MBEDTLS_DHM_C but MBEDTLS_USE_PSA_CRYPTO set (fixes #9188)
Avoid compiler warning about size comparison (like in commit 7910cdd):

Clang builds fail, warning about comparing uint8_t to a size that may be >255.

Signed-off-by: Michael Schuster <michael@schuster.ms>
2024-08-06 11:26:00 +01:00
Michael Schuster
c9184fe7ab Fix server mode only build of v3.6 with MBEDTLS_SSL_CLI_C unset (fixes #9186)
Signed-off-by: Michael Schuster <michael@schuster.ms>
2024-08-06 11:26:00 +01:00
Gilles Peskine
7dea096086 Fix overlap between volatile keys and built-in keys
Fix interference between PSA volatile keys and built-in keys
when MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS is enabled and
MBEDTLS_PSA_KEY_SLOT_COUNT is more than 4096. This overlap used to make it
possible that a volatile key would receive the identifier of a built-in key,
and is now caught by a static assertion.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-07-17 12:21:21 +02:00
Gilles Peskine
708ec09e30 Assert that the key ID range for volatile keys is large enough
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-07-17 12:21:21 +02:00
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
Michael Grand (TrustnGo)
83da5abdd6 Fix typo in platform_util.c
Fix a typo in a conditional include.

Signed-off-by: Michael Grand (TrustnGo) <m.grand@trustngo.tech>
2024-07-11 17:31:22 +03: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