31064 Commits

Author SHA1 Message Date
Valerio Setti
270dcd15d9 tests: update Makefile to generate tests/src/test_keys.h
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-29 17:14:50 +02:00
Gilles Peskine
77c13e67d4 Fix PSK invocation: GnuTLS PSK length
ssl-opt.sh uses a 3-byte PSK in many test cases. Unfortunately GnuTLS >=3.4.0
rejects a PSK that is less than 4 bytes long:

> Error setting the PSK credentials: The request is invalid.

Use a longer PSK throughout ssl-opt. Only the test cases involving GnuTLS
need to change, but it's easier to do a global search-and-replace, and it's
easier to not have to worry about mismatches in constructed test cases
later, so replace everything.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-29 16:09:52 +02:00
Gilles Peskine
c158fe6eb8 Fix PSK invocation: GnuTLS prompting
When given a PSK key but no username, gnutls-cli prompts for a password.
Prevent that by passing --pskusername with the same identity that
ssl_server2 uses by default.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-29 16:05:54 +02:00
Gilles Peskine
2776240af4 Fix PSK invocation: OpenSSL client
Only s_server has a -nocert option, s_client doesn't. Fixes OpenSSL client
test cases in PSK-only builds.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-29 16:05:38 +02:00
Gilles Peskine
d00b93b621 Require RSA when using server1* key or certificate
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-29 16:03:29 +02:00
Gilles Peskine
dde67bbb5a 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-04-29 12:38:16 +02:00
Manuel Pégourié-Gonnard
024d3daa7d
Merge pull request #8986 from valeriosetti/issue8871
Improve test key generation in test_suite_pk
2024-04-29 09:25:37 +00:00
Gilles Peskine
e855317957 Fix skipped tests in configurations without RSA
Tighten the matching when detecting which certificates are in use to
determine algorithm requirements. This fixes a bug whereby all tests were
skipped in configurations without RSA except for an Mbed TLS client against
a GnuTLS or OpenSSL server, due to *server2* matching ssl_server2.
Fixes #8366.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-26 21:28:49 +02:00
Paul Elliott
0f37a157a2 Add Changelog entry
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2024-04-26 18:56:00 +01:00
Paul Elliott
a3daff47d8 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 18:47:40 +01:00
Thomas Daubney
ff33abd599 Modify component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa
Replace relevant Mbed TLS API config options with their PSA
API equivalents.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-04-26 17:08:34 +01:00
Thomas Daubney
6258621a0b Modify component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa
Replace relevant Mbed TLS API config options with their PSA
API equivalents.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-04-26 17:01:16 +01:00
Thomas Daubney
b8cbbe7c90 Modify component_test_tls1_2_default_stream_cipher_only_use_psa
Replace relevant Mbed TLS API config options with their PSA
API equivalents.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-04-26 16:46:06 +01:00
Gilles Peskine
014a63b2cf Convert recent RSA key files in PEM format from PKCS8 to PKCS1
Like `openssl rsa`, `openssl genrsa` changed its output format from PKCS8 to
PKCS1 in OpenSSL 3.0. Note that the makefile instructions assume older
OpenSSL. Convert the files that were generated with OpenSSL 3.x and hence
were not in the intended format. The files are converted, not regenerated,
so the key material is the same.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-26 11:51:08 +02:00
Gilles Peskine
0652b62d5e Fix rsa_pkcs1_*_clear.der to actually be PKCS#1 files
With OpenSSL 3.0.2 (which I used to generate the previous set of "pkcs1" DER
files), the output of `openssl rsa -outform DER` is actually a
PKCS#8-encoded key, despite what the documentation says. This is a change
from OpenSSL 1.x, where the output is a PKCS#1-encoded key. OpenSSL 3.0.8
documents the output as PKCS#8.

Change to `openssl pkey`, which seems more reliable. The documentation
states that the output is PKCS#8, but the output is actually consistently
PKCS#1 at least from 1.0.2g to 3.3.0.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-25 16:32:38 +02:00
Gilles Peskine
cbb4507b44 Use large enough keys when testing parsing of non-word-aligned RSA sizes
When PSA is available, we exercise the parsed RSA key with PKCS#1v1.5
signature, which requires the modulus size in bytes to be at least
tLen + 11 (per RFC 8017 §9.2) where tLen = hLen + oidLen + 6 and
hLen = 32, oidLen = 9 for SHA-512 or SHA3-512. 10 is the DER overhead
(3 ASN.1 type-length headers with lengths <128). Replace 512-bit test
cases (good enough for SHA-256 but not SHA-384 and up) by 768-bit and
up (good enough for SHA-512).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-24 16:28:00 +02:00
Gilles Peskine
9c3ebe30b8 Add some test RSA keys of sizes 768 and up
These are sufficiently large for PKCS#1v1.5 signature with SHA-512 or
SHA3-512. Cover some non-word-aligned sizes.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-24 16:21:59 +02:00
Gilles Peskine
b612f9fe7c Cleartext RSA keys: also make DER formats available
We can use DER keys in builds without PEM, so it's good to have them around.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-24 16:21:19 +02:00
Manuel Pégourié-Gonnard
771fd7d1dc
Merge pull request #9022 from mpg/compat-fixes-dev
[dev] Small fixes to compat.sh (partial forward-port)
2024-04-24 07:11:49 +00:00
Ronald Cron
87a6d277a8
Merge pull request #9040 from Ryan-Everett-arm/crypto-config-psa_crypto_rsa_no_genprime
Make component_test_psa_crypto_rsa_no_genprime work with PSA_CRYPTO_CONFIG set
2024-04-23 06:30:39 +00:00
Gilles Peskine
1f4e0390bd Fix misspelled dependency: there is no MBEDTLS_PEM_C
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-22 17:24:45 +02:00
Gilles Peskine
6b3a9ee2d8 Allow PSA to not support RSA keys with non-byte-aligned sizes
Work around https://github.com/Mbed-TLS/mbedtls/issues/9048

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-22 17:24:45 +02:00
Gilles Peskine
57a0b915fd Remove redundant dependency
In the test data, remove a dependency that is already present on the function.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-22 17:24:45 +02:00
Ryan Everett
fcd744fe69 Set MBEDTLS_PSA_CRYPTO_CONFIG in component_test_no_rsa_key_pair_gen
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-22 10:44:24 +01:00
Manuel Pégourié-Gonnard
eb86b906d7 Fix full invocation of ssl-opt.sh
The previous commit had:
- one obvious mistake (-f NULL with default -e runs nothing)
- one unforeseen issue: OPENSSL_NEXT skips static ECDH
- arguably scope creep: the stated goal was to simplify the full
invocation (in particular, make it obvious that everything is run
without having to remember the default value of EXCLUDE), but it also
made an unrelated change: running most tests with OPENSSL_NEXT (hence
the previous point).

This commit should fix all this, in particular it switches back to
running most tests with OPENSSL and using OPENSSL_NEXT only when needed.

Hopefully in the future we'll do the opposite: most tests will run with
a recent OpenSSL, and only those that need an older one will use
something older. But that will be another PR.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-04-22 10:25:09 +02:00
Manuel Pégourié-Gonnard
3caada646e
Merge pull request #9035 from valeriosetti/asn1-missing-guard-in-rsa
Auto-enable ASN1 when RSA is enabled
2024-04-22 07:48:43 +00:00
Valerio Setti
ec3b90f348 changelog: fix text
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-19 11:09:56 +02:00
Valerio Setti
ce86865258 add changelog
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-19 09:38:23 +02:00
Valerio Setti
89f5af84af adjust_legacy_crypto: enable ASN1_[PARSE|WRITE]_C when RSA_C
RSA needs ASN1 functions to parse/write private and public keys,
but there is no guards in the code for that. So we need to enable
ASN1 support whenever RSA is enabled.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-18 18:47:34 +02:00
Ryan Everett
daa322a2de Update component_test_psa_crypto_rsa_no_genprime
Prepare this component for PSA_CRYPTO_CONFIG to be on by default.
Rename it so that the name is still accurate when we remove legacy symbols

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-18 16:50:02 +01:00
Valerio Setti
36188219fc generate_test_keys: split group_id and key bitsize in the generated structure
- group_id is only used for EC keys;
- key bitsize only for RSA.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 17:06:26 +02:00
Valerio Setti
40eaf120af test_suite_pk: fix some descriptions in data file
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 17:06:26 +02:00
Valerio Setti
ee74339180 generate_test_keys: minor improvements
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 17:06:21 +02:00
Manuel Pégourié-Gonnard
62d0bb8f2c Simplify full invocation of compat.sh
We actually only need two invocations.

This also moves all the default tests to OPENSSL_NEXT, which is good
because OPENSSL is ancient.

I have no idea why NULL doesn't work with OPENSSL_NEXT (1.1.1a) server,
because according to the manpage [1], "ALL,COMPLEMENTOFALL" (which is
what we are using) should do it, and indeed

    $OPENSSL_NEXT ciphers "ALL,COMPLEMENTOFALL" | tr ':' '\n'

lists NULL ciphersuites, and also they work client-side with
OPENSSL_NEXT...

[1] https://www.openssl.org/docs/man1.1.1/man1/ciphers.html

Also, while at it, remove partial invocation (only non-default) from one
component, as we already have a full invocation in the same config (plus
ASan) in another component.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-04-17 12:39:00 +02:00
Manuel Pégourié-Gonnard
68deadd455
Merge pull request #8566 from mpg/driver-status
Document driver testing status
2024-04-17 07:57:15 +00:00
Valerio Setti
37bc93cbeb test_suite_pk: fix guards for pk_psa_setup()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:25:40 +02:00
Valerio Setti
57d23e229c test_suite_pk: remove PK_PARSE_C unnecessary dependencies
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-16 17:01:31 +02:00
Valerio Setti
50e5979680 test_suite_pk: remove RSA key generation/size dependencies
- MBEDTLS_GENPRIME is removed because now we rely on predefined
  RSA keys.
- MBEDTLS_RSA_GEN_KEY_MIN_BITS is replaced with RSA_KEY_SIZE which
  is set on top of test_suite_pk to a value which is supported
  in the predefined_keys[] array.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-16 16:00:35 +02:00
Valerio Setti
186f458d92 test_suite_pk: enhance pk_psa_setup() to support all key types
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-16 15:37:47 +02:00
Valerio Setti
42f2e21054 test_suite_pk: use pk_setup() instead of mbedtls_rsa_gen_key() in pk_psa_wrap_sign_ext()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-16 15:03:42 +02:00
Valerio Setti
4d14581d87 test_suite_pk: use predefined RSA keys in pk_setup_for_type()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-16 15:00:52 +02:00
Valerio Setti
1f6dab7c24 test_suite_pk: rename pk_genkey() and pk_psa_genkey()
- pk_genkey -> pk_setup
- pk_psa_genkey -> pk_psa_setup

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-16 14:44:58 +02:00
Valerio Setti
91fdff096e test_suite_pk: fix get_predefined_key_data() return value
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-16 14:22:31 +02:00
Valerio Setti
9aa4fa9572 generate_test_keys: generate also look-up table in script
Remove static declaration of look-up table from test_suite_pk
and generate it automatically with Python.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-16 14:10:02 +02:00
Valerio Setti
7031a4ebd8 generate_test_keys: generate arrays for all keys in asymmetric_key_data.py
Only unused (from test_suite_pk point of view) EC curves are skipped.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-16 10:31:15 +02:00
Valerio Setti
59c614be39 generate_test_keys: generate also RSA public key arrays
This is to manage RSA and EC keys in the same way in order to
prepare for the following commits.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-15 18:44:39 +02:00
Valerio Setti
862d14e694 generate_test_keys: minor improvements
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-15 17:58:43 +02:00
Valerio Setti
776dce51d3 asymmetric_key_data: fix public RSA-2048 key
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-15 17:41:21 +02:00
Valerio Setti
8f40460b2b generate_test_keys: fix mypy issue for imported path
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-15 15:09:10 +02:00
Manuel Pégourié-Gonnard
4575d230bf Add a note on hits usefulness
And fix a typo while at it.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-04-15 10:54:49 +02:00