17040 Commits

Author SHA1 Message Date
Gilles Peskine
d97de551e4 Don't call memcpy(NULL, 0) which has undefined behavior
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-29 11:04:48 +02:00
Gilles Peskine
96b8d31ef6 ASN.1: test that we can parse what we can write
In asn1_write tests, when there's a parsing function corresponding to the
write function, call it and check that it can parse what we wrote.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-29 11:04:48 +02:00
Gilles Peskine
53875878b8 Fix copypasta in test data
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-29 11:04:48 +02:00
Gilles Peskine
53785928fa ASN.1 write tests: test with larger buffer
Test with the output buffer size up to *and including* the expected output
size plus one. `... < expected->len + 1` was evidently a mistake.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-29 11:04:48 +02:00
Gilles Peskine
bb34feea0d Fix bug whereby 0 was written as 0200 rather than 020100
0200 is not just non-DER, it's completely invalid, since there has to be a
sign bit.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-29 11:04:48 +02:00
Gilles Peskine
62f217b180 Add MPI write tests when the MPI object has a leading zero limb
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-29 11:04:48 +02:00
Gilles Peskine
4269185aa1 Fix mismatch between test data and test description
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-29 11:04:48 +02:00
Gilles Peskine
7f56783a0a Uncomment mbedtls_asn1_write_mpi tests with leading 1 bit
mbedtls_asn1_write_mpi() correctly handles the sign bit, so there's no
reason not to test that it's handled correctly.

Fix copypasta in test data that was commented out.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-29 11:04:48 +02:00
Zhangsen Wang
7d0e658386 Re-enable 7 tests disabled in mbedtls-2.28 because of an old OpenSSL bug
Signed-off-by: Zhangsen Wang <zhangsen.wang@arm.com>
2022-06-29 07:33:35 +00:00
Gilles Peskine
06c5e929ba
Merge pull request #5863 from wernerlewis/csr_subject_comma_2.28
[Backport 2.28] Fix output of commas and other special characters in X509 DN values
2022-06-28 21:00:47 +02:00
Gilles Peskine
d0aafa6cc1
Merge pull request #5984 from gilles-peskine-arm/changelog-improvements-20220609-2.28
Changelog improvements before the 2.28.1 release
2022-06-28 21:00:12 +02:00
Gilles Peskine
83f54aad6a Changelog: minor copyediting
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-28 00:05:58 +02:00
Gilles Peskine
cd1608914f Changelog: clarify a cmake-related entry as being about cmake
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-28 00:05:50 +02:00
Gilles Peskine
8960d0585b Changelog: mention bug id in bugfix entry
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-28 00:05:50 +02:00
Gilles Peskine
06900034cb Changelog: remove bugfix entry that's actually a robustness improvement
If the key agreement or the public key export in
ssl_write_client_key_exchange() fails, the handshake enters a failed state.
The only valid thing you can do in a failed handshake is to abort it, which
calls mbedtls_ssl_handshake_free(), which destroys ecdh_psa_privey. While
it's good hygiene to destroy the key in the function that creates it, it
would have been cleaned up a little later in the normal course of things
anyway, so there wasn't an actual bug.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-28 00:05:49 +02:00
Gilles Peskine
dc7e34ca2e Clarify potential ambiguity in changelog entry
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-27 14:48:44 +02:00
Gilles Peskine
c9529f9649 Fix null pointer dereference in mpi_mod_int(0, 2)
Fix a null pointer dereference when performing some operations on zero
represented with 0 limbs: mbedtls_mpi_mod_int() dividing by 2, or
mbedtls_mpi_write_string() in base 2.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-27 14:48:44 +02:00
Dave Rodgman
4118092105
Merge pull request #5825 from polhenarejos/mbedtls-2.28
Backport 2.28: Fix for order value for curve448
2022-06-27 13:47:31 +01:00
Gilles Peskine
52396ef622 Remove largely useless bit of test log to silence GCC 12
GCC 12 emits a warning because it thinks `buffer1` is used after having been
freed. The code is correct C because we're only using the value of
`(uintptr_t)buffer1`, not `buffer1`. However, we aren't using the value for
anything useful: it doesn't really matter if an alloc-free-alloc sequence
returns the same address twice. So don't print that bit of information, and
this way we don't need to save the old address.

Fixes #5974.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-27 14:30:48 +02:00
Werner Lewis
1421efa25e Fix case where final special char exceeds buffer
Signed-off-by: Werner Lewis <werner.lewis@arm.com>
2022-06-27 12:04:43 +01:00
Werner Lewis
2ee1e2dd22 Replace parsing with outputting
Signed-off-by: Werner Lewis <werner.lewis@arm.com>
2022-06-27 10:03:10 +01:00
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
8641102bc1 Fix impact evaluation
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-06-20 21:04:31 +02:00
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
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
Przemyslaw Stekiel
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
Przemyslaw Stekiel
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
Przemyslaw Stekiel
331c3421d1 Address review comments
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
2022-06-20 21:04:31 +02:00
Przemyslaw Stekiel
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
Przemyslaw Stekiel
5b6c4c9552 add client/server opaque test
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
2022-06-20 21:04:31 +02:00
Przemyslaw Stekiel
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
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
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
Manuel Pégourié-Gonnard
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
Gilles Peskine
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
Werner Lewis
9a2356b190 Add tests for exceeded buffer size
Signed-off-by: Werner Lewis <werner.lewis@arm.com>
2022-06-17 16:45:24 +01:00
Dave Rodgman
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
Andrzej Kurek
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
Andrzej Kurek
6b4f062cde Fix incorrect changelog entry
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-06-17 07:37:36 -04:00
Andrzej Kurek
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
Andrzej Kurek
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
Andrzej Kurek
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