30917 Commits

Author SHA1 Message Date
Valerio Setti
3d54a9d7a3 generate_test_[keys/cert_macros]: minor fixes
- remove new line at beginning of test_keys.h
- add footer at the end of both generated files

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
d714259c01 generate_test_keys: move output file writing to a separate function
This helps removing the previous pylint exception.

Also use "with" statement for opening the file in order to
ensure that all the content is flushed to the file before
exiting.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
42efdd83ff generate_test_keys: sort keys before processing them
Without this fix keys could be listed differently on Ubuntu 16
between different runs therefore causing
check_generated_files() to fail.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
feb87a9dfc check-generated-files: add test_certs.h file to the list of checked items
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
97e4e04a52 generate_test_cert_macros: minor fixes
- use build_tree to get the project root path
- remove "if True" in an "if" statement

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
e2f2dd5b91 generated_test_keys: minor fixes
- rewrite output file (do not append)
- remove useless "os" import
- move pylint for main() function

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
b090df2e35 generate_test_keys: remove left-over variable
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
91eefe4e45 tests/CMakeLists: fix indentation
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
1717821867 generate_test_keys: do not quit script if output file already exists
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
a8753694f2 generate_test_keys: add missing flush at the end of script
Ensure that all the data is actually written to the output file.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
1c56ca4c02 test_suite_pk: use explicit key bit size instead of RSA_KEY_SIZE
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
351236a3a9 generate_test_keys: use build_tree to guess the MbedTLS root path
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
ba91d44cd3 generate_test_cert_macros: minor fixes
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
911363e8cb cmake: relocate custom commands for test_certs.h and test_keys.h generation
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
c2293190fe generate_test_cert_macros: embed input args
- Embed input arguments inside the script so as to simplify the
  calls in Makefiles/CMakeLists.
- add a new "--list-dependencies" command line option to print
  out the list of dependencies.
- Modify tests/Makefile accordinlgy.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
5241f395ec tests/Makefile: minor fix: specify Python binary to be used
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
85a006635f fix "make generated_files" for test_keys.h and test_certs.h
This also add the check in tests/scripts/check-generated-files.sh

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
b627199d60 generate_test_keys: add default output file option
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
4b9aebf4d9 tests: remove test_certs.h and test_keys.h as they are auto-generated
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
a607a1b322 test: automatically generate test_certs.h and test_keys.h
Ensure that when tests are built also test_certs.h and
test_keys.h are generated.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02:00
Valerio Setti
cd96473fd3 tests: update Makefile to generate tests/src/test_keys.h
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-05-07 10:54:44 +02: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
Janos Follath
7fa3134dab Fix Changelog formatting
Add EOL and remove trailing whitespaces.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-05-03 10:50:33 +05:30
Gilles Peskine
82cd3d1014
Merge pull request #9089 from ronald-cron-arm/add-cve-2024-30166-ref-3.6
[Backport 3.6] ChangeLog: Add missing reference to CVE in security entry
2024-05-02 19:47:36 +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
313be884c3
Merge pull request #9076 from gilles-peskine-arm/cpp-unbounded-write-3.6
Backport 3.6: ssl_mail_client: Fix unbounded write of sprintf()
2024-05-02 16:06:27 +00: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
Gilles Peskine
209704a9b3
Merge pull request #9077 from Ryan-Everett-arm/3.6-fix-get-and-lock-key-slot-threading-bug
Backport 3.6: Wipe the returned slot pointer upon failure in `psa_get_and_lock_key_slot`
2024-05-02 15:48:18 +00:00
Ronald Cron
68613a46ce ChangeLog: Add missing reference to CVE in security entry
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-05-02 17:27:18 +02: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
Manuel Pégourié-Gonnard
8c2b301b82
Merge pull request #9050 from gilles-peskine-arm/test-dependencies-20240314-3.6
Backport 3.6: Fix some test case dependencies (PEM_C)
2024-05-02 08:00:22 +00:00
Ryan Everett
629715aeb1 Add changelog
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-30 14:09:43 +01:00
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
Mingjie Shen
41995bec9a ssl_mail_client: Fix code style issue
Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2024-04-30 13:00:35 +02:00
Mingjie Shen
623812887a ssl_mail_client: Check return value of mbedtls_snprintf
The return value of snprintf() is the number of characters (excluding
the null terminator) which would have been written to the buffer if
enough space had been available. Thus, a return value of size or more
means the output was truncated.

Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2024-04-30 13:00:35 +02:00
Mingjie Shen
6f216e4a73 ssl_mail_client: Replace snprintf with mbedtls_snprintf
Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2024-04-30 13:00:34 +02:00
Mingjie Shen
73d649e089 ssl_mail_client: Fix unbounded write of sprintf()
These calls to sprintf may overflow buf because opt.mail_from and opt.mail_to
are controlled by users. Fix by replacing sprintf with snprintf.

Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2024-04-30 13:00:33 +02:00
Ryan Everett
97cc7f89be Rewrite changelog
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-30 11:17:04 +01:00
Ryan Everett
b1c3d6e07b Add changelog
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-30 11:17:04 +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
Manuel Pégourié-Gonnard
4b2639c23f
Merge pull request #9033 from valeriosetti/issue8871-backport
[3.6 backport] Improve test key generation in test_suite_pk
2024-04-29 09:25:40 +00:00
Paul Elliott
405d1f6434 Add Changelog entry
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2024-04-26 19:20:45 +01: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
Gilles Peskine
289079855b 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:53:02 +02:00
Gilles Peskine
69eba519f0 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:35:04 +02:00
Gilles Peskine
786dff6701 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 18:22:22 +02:00