1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-23 15:01:00 +03:00
Commit Graph

16919 Commits

Author SHA1 Message Date
8776042e44 Merge pull request #935 from mpg/buf-overread-use-psa-static-ecdh-2.28
[2.28] Fix potential heap buffer overread with `USE_PSA_CRYPTO`
2022-06-23 11:57:29 +02:00
ed36d20ea6 Save code size by calling get_type only once
This is an external function, so in the absence of link-time
optimisation (LTO) the compiler can't know anything about it and has to
call it the number of times it's called in the source code.

This only matters for pk_ec, but change pk_rsa as well for the sake of
uniformity.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-23 09:50:30 +02:00
5721059281 Mark internal int SSL functions CHECK_RETURN_CRITICAL
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:06:14 +02:00
d904d66639 Mark static int SSL functions CHECK_RETURN_CRITICAL
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:06:12 +02:00
08b2ebd2be Improve readability with less negation.
Err, I mean don't worsen readability by not using more negation.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
06e1fcdb45 Add comments when can_do() is safe to use
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
8641102bc1 Fix impact evaluation
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
d80d8a40ee Add negative tests for opaque mixed-PSK (server)
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
a49a00cc24 Add negative tests for opaque mixed-PSK (client)
ssl_client2.c used to check that we force a ciphersuite that worked;
that would have prevented testing so I removed it. The library should be
robust even when the application tries something that doesn't work.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
938be422c6 Add negative test for Opaque key & static ECDH
That's actually the only non-PSK key exchange that needs to be
negative-tested: all the other key exchanges are either positive-tested
or use RSA, for which we can't even create opaque keys in this branch.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
b3de3fd68c ssl-opt.sh: adapt paramteters of key opaque cases
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
2022-06-20 21:04:31 +02:00
67fc488515 ssl_client2/ssl_server_2: use PSA_ALG_ANY_HASH as algorithm for opaque key
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
2022-06-20 21:04:31 +02:00
331c3421d1 Address review comments
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
2022-06-20 21:04:31 +02:00
69e567c0e1 ssl_server2.c: fix build err (key_slot - unused variable)
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
2022-06-20 21:04:31 +02:00
5b6c4c9552 add client/server opaque test
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
2022-06-20 21:04:31 +02:00
ab09c9eb79 Add key_opaque option to ssl_server2.c + test
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
2022-06-20 21:04:31 +02:00
b9c7ea459e Improve a comment.
ECDSA keys work with mbedtls_pk_ec() too, but we don't want to accept
them here, so the comment should reflect that the check is not just
about ensuring pk_ec() works.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
a4a4aab542 Improve contract of mbedtls_pk_ec/rsa()
Trusting the caller to perform the appropriate check is both risky, and
a bit user-unfriendly. Returning NULL on error seems both safer
(dereferencing a NULL pointer is more likely to result in a clean crash,
while mis-casting a pointer might have deeper, less predictable
consequences) and friendlier (the caller can just check the return
value for NULL, which is a common idiom).

Only add that as an additional way of using the function, for the sake
of backwards compatibility. Calls where we know the type of the context
for sure (for example because we just set it up) were legal and safe, so
they should remain legal without checking the result for NULL, which
would be redundant.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
853f06732e Clarify warning about mbedtls_pk_ec/rsa()
The previous wording "ensure it holds an XXX" context did not mean
anything without looking at the source.

Looking at the source, the criterion is:
- for mbedtls_pk_rsa(), that the info structure uses rsa_alloc_wrap;
- for mbedtls_pk_ec(), that it uses eckey_alloc_wrap or
ecdsa_alloc_wrap, since mbedtls_ecdsa_context is a typedef for
mbedtls_ecp_keypair. (Note that our test code uses mbedtls_pk_ec() on
contexts of type MBEDTLS_PK_ECDSA.)

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
5b3f24f214 Fix unchecked return value from internal function
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
37e5999ac3 Fix potential buffer overread with USE_PSA
Using opaque keys for static ECDH is not supported in this branch (will
be introduced in 3.2). In case we reach that point, error out cleanly
instead of miscasting a pointer. Since opaque keys were introduced,
mbedtls_pk_can_do() was no longer a precise enough check.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
bb54fce91e Merge pull request #944 from AndrzejKurek/clihlo_cookie_pxy_fix_2_28
[Backport 2.28] Add a client hello cookie_len overflow test
2022-06-20 19:35:54 +02:00
9a2356b190 Add tests for exceeded buffer size
Signed-off-by: Werner Lewis <werner.lewis@arm.com>
2022-06-17 16:45:24 +01:00
46b5cb553a Add test-case for checking curve order
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-06-17 13:46:45 +01:00
719c723afc test_suite_ssl: Use a zero fragment offset in a test with a too short record
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-06-17 07:37:49 -04:00
6b4f062cde Fix incorrect changelog entry
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-06-17 07:37:36 -04:00
3c036f54cc Add missing test dependencies for cookie parsing
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-06-17 07:37:27 -04:00
4353d3d593 Split a debug message into two - for clarity
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-06-17 07:37:14 -04:00
33f41a8fa8 Add the mbedtls prefix to ssl_check_dtls_clihlo_cookie
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-06-17 07:37:02 -04:00
a39170bbed Add a changelog entry for the cookie parsing bounds bug
Co-authored-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-06-17 07:36:50 -04:00
862acb8403 Add cookie parsing tests to test_suite_ssl
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-06-17 07:36:42 -04:00
e5af9fabf7 Add missing sid_len in calculations of cookie sizes
This could lead to a potential buffer overread with small
MBEDTLS_SSL_IN_CONTENT_LEN.
Change the bound calculations so that it is apparent
what lengths and sizes are used.

Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-06-17 07:36:35 -04:00
f333dfab4a More SSL debug messages for ClientHello parsing
In particular, be verbose when checking the ClientHello cookie in a possible
DTLS reconnection.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-17 07:36:26 -04:00
02c9d3b9c2 Fix parsing of special chars in X509 DN values
Use escape mechanism defined in RFC 1779 when parsing commas and other
special characters in X509 DN values. Resolves failures when generating
a certificate with a CSR containing a comma in subject value.
Fixes #769.

Signed-off-by: Werner Lewis <werner.lewis@arm.com>
2022-06-08 14:38:38 +01:00
7e163d796c Merge pull request #5893 from AndrzejKurek/ssl-opt-client-kill-fix-2.28
[Backport 2.28] Fix a bug with executing ssl-client2 in ssl-opt.sh in a subshell
2022-06-08 14:26:42 +01:00
ce02537b0c Merge pull request #5828 from wernerlewis/time_utc_2.28
[Backport 2.28] Use ASN1 UTC tags for dates before 2000
2022-06-08 13:55:38 +01:00
d27cdcc16f Fix a bug with executing ssl-client2 in ssl-opt.sh in a subshell
When executing eval in the background, the next "$!" gives the
eval PID, not the ssl-client2 pid. This causes problems when
a client times out and the script tries to kill it. Instead, it
kills the parent eval call.
This caused problems with subsequent proxy tests receiving
old packets from a client from a previous test.
Moving the "&" to inside the eval call fixes the problem.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-06-06 15:12:55 -04:00
1b54a05f77 Use ASN1 UTC tags for dates before 2000
Signed-off-by: Werner Lewis <werner.lewis@arm.com>
2022-06-01 16:28:10 +01:00
7bda291427 Merge pull request #5859 from paul-elliott-arm/fix_ct_uninit_memory_access_2.28
Backport 2.28: Fix uninitialised memory access in constant time functions
2022-06-01 11:42:47 +02:00
adf225dfd6 Merge pull request #5848 from tom-daubney-arm/2-28_x25519_program
[2.28] Rewrite x25519 example program
2022-05-31 11:26:27 +02:00
c227ea5942 Adds Changelog entry
Adds change log entry.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2022-05-30 14:12:24 +01:00
d99f8b2897 Rewrite x25519 example program
Rewrite x25519 example program to fix fatal bug and show
current best practices with the ECDH API.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2022-05-30 14:09:02 +01:00
5bc9a26e31 Merge pull request #5877 from tom-cosgrove-arm/fix-typos-220526-2.28
Backport 2.28: Fix spelling and typographical errors found by cspell
2022-05-30 11:35:59 +01:00
b16280cef5 Merge pull request #5885 from Summer-ARM/mbedtls-2.28
Backport 2.28: Remove duplicated PSA_WANT_ALG_CMAC in crypto_config.h
2022-05-30 09:41:34 +01:00
fd8aa65d3d Remove duplicated PSA_WANT_ALG_CMAC in crypto_config.h
Signed-off-by: Summer Qin <summer.qin@arm.com>
2022-05-30 10:43:53 +08:00
2b1507574c Fix spelling and typographical errors found by cspell
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-05-26 11:55:43 +01:00
b830028314 Fix uninitialised memory access in constant time functions
Fix an issue reported by Coverity whereby some constant time functions
called from the ssl decrypt code could potentially access uninitialised
memory.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2022-05-19 18:31:35 +01:00
bdd6905a5c Merge pull request #5850 from bootstrap-prime/mbedtls-2.28
Fix typos in documentation and constants with typo finding tool
2022-05-19 16:53:37 +01:00
d03d6d4ca0 Merge pull request #5849 from gilles-peskine-arm/psa-raw_key_agreement-buffer_too_small-2.28
Backport 2.28: Make psa_raw_key_agreement return BUFFER_TOO_SMALL
2022-05-19 16:05:27 +01:00
7ef96ea856 Fix typos in documentation and constants with typo finding tool
Signed-off-by: bootstrap-prime <bootstrap.prime@gmail.com>
2022-05-18 14:08:33 -04:00