6354 Commits

Author SHA1 Message Date
Agathiyan Bragadeesh
7b0ee1e655 Fix control bypass warnings
Declarations have been moved to the top of functions to fix this

Signed-off-by: Agathiyan Bragadeesh <agathiyan.bragadeesh2@arm.com>
2023-07-27 15:51:46 +01:00
Gowtham Suresh Kumar
34d8bd37d9 Fix warnings from clang-16
Running clang-16 on mbedtls reports warnings of type "-Wstrict-prototypes".
This patch fixes these warnings by adding void to functions with no
arguments. The generate_test_code.py is modified to insert void into test
functions with no arguments in *.function files.

Signed-off-by: Gowtham Suresh Kumar <gowtham.sureshkumar@arm.com>
2023-07-27 00:03:21 +01:00
Gowtham Suresh Kumar
1e3af2485f Update test scripts to use latest/earliest compilers
The Ubuntu 16.04 and 22.04 docker images have been updated with
earliest and latest versions of gcc and clang respectively.
This patch adds the necessary component and support functions
required for the CI to run these compilers.

For FreeBSD we invoke the function by name so a condition is added
to disable the existing test_clang_opt function for linux.

Signed-off-by: Gowtham Suresh Kumar <gowtham.sureshkumar@arm.com>
2023-07-26 16:55:39 +01:00
Gilles Peskine
ba986f3725 PermissionIssueTracker is obsoleted by ShebangIssueTracker
ShebangIssueTracker implements the rule that scripts must be executable if
and only if they have a shebang line. By removing PermissionIssueTracker, we
now allow files with any extension to be executable (provided they have a
shebang line), and allow *.sh and *.pl to be non-executable modules if they
don't have a shebang line (as was already the case for *.py).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-25 21:54:36 +02:00
Gilles Peskine
46c30b85e1 Pacify Pylint
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-25 21:54:36 +02:00
Gilles Peskine
f4ae0792fd Make --quiet a little less quiet
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-25 21:54:36 +02:00
Gilles Peskine
e1d4f9da23 Error out if run from the wrong directory
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-25 21:54:36 +02:00
Gilles Peskine
369f190b37 Add --quiet option to suppress demos' output
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-25 21:54:36 +02:00
Gilles Peskine
e721827803 Minor readability improvements
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-25 21:54:36 +02:00
Gilles Peskine
93aaf2e998 Run demo scripts in some builds
Run the sample program demo scripts in builds with a configuration
that is at least as complete as the default configuration.

Do not run sample programs in all configurations since they are
expected to fail if a required feature is missing.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-25 21:54:35 +02:00
Gilles Peskine
2c8bbce36d Run demo scripts and check that they work
run_demos.py is the frontend to a framework for smoke-testing the
sample programs. It runs scripts called programs/*/*_demo.sh
("demo scripts") and check that they succeed. A typical demo script
runs one sample program or a combination of sample programs to
demonstrate their usage.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-25 21:54:35 +02:00
Agathiyan Bragadeesh
1dd20a32e2 Remove trailing backslash
Signed-off-by: Agathiyan Bragadeesh <agathiyan.bragadeesh2@arm.com>
2023-07-24 10:50:53 +01:00
Gilles Peskine
1fc71160b1 Add missing dependencies on real entropy
Tests that call mbedtls_test_ssl_endpoint_init() need mbedtls_entropy_func()
to work.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-20 20:04:27 +02:00
Gilles Peskine
24d0124868 Fix copypasta in function documentation
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-20 18:11:22 +02:00
Gilles Peskine
58d085419c MBEDTLS_PSA_INJECT_ENTROPY: check the seed file UID
The seed file UID is part of the library's stable interface.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-20 18:11:22 +02:00
Gilles Peskine
154dadfae8 MBEDTLS_PSA_INJECT_ENTROPY: check the lifecycle of the seed file
The seed file is part of the stable interface of PSA_CRYPTO_INJECT_ENTROPY,
because it has to survive a library upgrade on a device. So check that its
existence and content are as expected at each point in the tested life cycle.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-20 18:11:22 +02:00
Gilles Peskine
cf21e944f6 Modernize remove_seed_file()
This function was written before the PSA storage layer switched to the PSA
ITS API as its storage abstraction. Now we can just call PSA ITS functions
unconditionally.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-20 18:11:22 +02:00
Gilles Peskine
55e89985f0 Test MBEDTLS_PSA_INJECT_ENTROPY
Until now, we were never enabling this option in any test.

MBEDTLS_PSA_INJECT_ENTROPY requires MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES, so
it cannot be enabled in the full config and it gets its own component.

Test with MBEDTLS_USE_PSA_CRYPTO enabled, since MBEDTLS_PSA_INJECT_ENTROPY
is a very PSA feature (which can break non-PSA applications), and Mbed
OS (for whch MBEDTLS_PSA_INJECT_ENTROPY was designed) enables
MBEDTLS_USE_PSA_CRYPTO when it enables MBEDTLS_PSA_INJECT_ENTROPY.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-20 18:11:21 +02:00
Gilles Peskine
bfda1a96bb MBEDTLS_PSA_INJECT_ENTROPY: Skip incompatible tests
When MBEDTLS_PSA_INJECT_ENTROPY is enabled, we disable standard entropy
sources, so mbedtls_entropy_func() doesn't work out of the box. Disable
tests that rely on it. MBEDTLS_PSA_INJECT_ENTROPY is intended for PSA-only
environments anyway, so it doesn't matter if some legacy features don't work
normally.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-20 18:10:26 +02:00
Gilles Peskine
4f8bf3cc54 MBEDTLS_PSA_INJECT_ENTROPY: Make sure the seed file exist when running tests
The seed file must exist before running tests. Because the location is
somewhat platform- and configuration-dependent, and to be friendly to
developers who run test suites individually and aren't familiar with this
feature, rely on the test framework code rather than on test scripts to
create the seed file.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-20 18:09:02 +02:00
Gilles Peskine
73521b0715 Tests: provide necessary functions for MBEDTLS_PSA_INJECT_ENTROPY
The build option MBEDTLS_PSA_INJECT_ENTROPY requires some extra platform
functions, for historical reasons. To enable us to test this option, provide
a version of these functions for testing.

(These versions would actually work in production, but providing them in the
library in a way that doesn't break existing users might be slightly tricky,
so it's out of scope of this commit.)

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-20 18:08:24 +02:00
Agathiyan Bragadeesh
27e2989840 Back port TEST_FAIL
Signed-off-by: Agathiyan Bragadeesh <agathiyan.bragadeesh2@arm.com>
2023-07-18 12:54:30 +01:00
Andrzej Kurek
0841b5a178 Add a workaround for max test suite parameter sizes
int isn't enough for SIZE_MAX/2.
Hardcoding the value will make the compilers complain.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-07-14 15:16:35 -04:00
Andrzej Kurek
6e4a9beb2b Disable msan errors on null allocation in all.sh
Such error was raised in platform tests,
and it's a valid test case.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-07-14 10:16:11 -04:00
Andrzej Kurek
f1e61fcb09 Add a dummy usage of a pointer in tests
This way clang with O1 doesn't optimize it.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-07-14 10:16:00 -04:00
Andrzej Kurek
d95b8edf29 Disable asan errors on null allocation in all.sh
Such error was raised in platform tests,
and it's a valid test case.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-07-14 10:13:40 -04:00
Andrzej Kurek
f35490e7af Move the overallocation test to test suites
This way the compiler does not complain about
an overly large allocation made.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-07-14 10:13:31 -04:00
Gowtham Suresh Kumar
21f2b7a64b tests/test_suite_ecp: Fix ECP group compare test
ECP group compare function should not check the value of T. We only need
to assert the value of T after the ECP group copy function is called.

Signed-off-by: Gowtham Suresh Kumar <gowtham.sureshkumar@arm.com>
2023-07-12 13:59:18 +01:00
Gilles Peskine
76a54ff1a8
Merge pull request #7901 from tgonzalezorlandoarm/tg/7879-backport
Backport 2.28: tests/test_suite_pem: Augment DES test cases with AES: PEM
2023-07-10 18:27:55 +02:00
Dave Rodgman
814a14a994
Merge pull request #7897 from tgonzalezorlandoarm/7136-backport
Backport 2.28: Record the outcome of each test case in compat.sh
2023-07-10 12:08:41 +01:00
Tomás González
991c49f812 tests/test_suite_pem: Augment DES test cases with AES: PEM
A few negative test cases in test_suite_pem.data rely on DES
(“invalid iv”, “malformed”). DES is deprecated.
Construct similar test cases using AES.

Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
2023-07-10 11:38:30 +01:00
Yanray Wang
5659981cf8 ssl-opt.sh: support to parse --outcome-file
Adjust where to set absolute path for MBEDTLS_TEST_OUTCOME_FILE
as it's supposed to set its absolute path after all possible
value assignment.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-07-10 09:38:24 +01:00
Dave Rodgman
b18d45f042
Merge pull request #7483 from gilles-peskine-arm/mbedtls_x509_crt_parse_path-qemu-bug-2.28
Backport 2.28: More mbedtls_x509_crt_parse_path() tests, and note qemu-user bug when 32-bit code run on 64-bit host
2023-07-07 19:15:46 +01:00
Dave Rodgman
f8f4c6053a
Merge branch 'mbedtls-2.28' into mbedtls_x509_crt_parse_path-qemu-bug-2.28
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-07-07 15:15:47 +01:00
Yanray Wang
44ba969acb compat.sh: add support to record outcome of test cases
If the environment variable MBEDTLS_TEST_OUTCOME_FILE is set,
the test outcome file records each test case in a single line
with the format of

 PLATFORM;CONFIGURATION;compat;TEST CASE DESCRIPTION;RESULT;[CAUSE]

- CONFIGURATION comes from MBEDTLS_TEST_CONFIGURATION to record
  configuration of each test case
- PLATFORM is either set by users or calculated from test
  platform
- RESULT is one of PASS, FAIL or SKIP. If test case fails,
  srv_out/cli_out follows as FAILURE CAUSE.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-07-07 12:23:08 +01:00
Yanray Wang
0f386b7372 compat.sh: call record_fail if test case fails
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-07-07 11:34:54 +01:00
David Horstmann
6762231e4b Use CONFIG_H variable rather than config file name
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-07-05 14:35:25 +01:00
David Horstmann
175afbdfe8 all.sh component to test cmake custom config file
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-07-05 14:35:25 +01:00
Dave Rodgman
08efc3d768
Merge pull request #7854 from daverodgman/fix-unused-aes-2.28
Fix AES dependencies - build TF-M config cleanly - backport 2.28
2023-07-03 16:48:39 +01:00
Dave Rodgman
bf99828d7b Nicer formatting
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-06-29 12:14:41 +01:00
Dave Rodgman
173227d41e Test combinations of macros for aes.o
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-06-29 12:14:34 +01:00
David Horstmann
5c019e0f65 Add regression testcase for string_to_names()
Test against a string with no '=' or ',' in it, which previously caused
mbedtls_x509_string_to_names() to return 0.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-06-27 17:34:58 +01:00
Gilles Peskine
63b50b56cd
Merge pull request #7753 from lpy4105/backport-2.28/issue/renew_cert_2024-01-01
Backport 2.28: Updating crt/crl files due to expiry before 2024-01-01
2023-06-21 12:29:12 +02:00
Demi Marie Obenour
5d7cd012ac x509parse tests: Replace TEST_ASSERT with TEST_EQUAL
The latter gives much more informative errors.

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
2023-06-19 11:04:47 -04:00
Valerio Setti
e20ec4f1dd crypto_config_test_driver_extension: treat PUBLIC_KEY the same way as KEY_PAIR
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-06-19 10:03:29 +02:00
Pengyu Lv
343ff1200d Fix typo and long line format
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-06-19 11:41:12 +08:00
Pengyu Lv
ea8027921b Update crl-rsa-pss-*.pem manually
The rules will be in a seperate PR.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-06-19 11:41:12 +08:00
Jerry Yu
a69934f249 upgrade server9-bad-saltlen.crt
Upgrade scripts
```python
import subprocess
from asn1crypto import pem, x509,core

output_filename="server9-bad-saltlen.crt"
tmp_filename="server9-bad-saltlen.crt.tmp"
tmp1_filename="server9-bad-saltlen.crt.tmp1"

subprocess.check_call(rf''' openssl x509 -req -extfile server5.crt.openssl.v3_ext \
        -passin "pass:PolarSSLTest" -CA test-ca.crt -CAkey test-ca.key \
        -set_serial 24 -days 3650 \
        -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:max \
        -sigopt rsa_mgf1_md:sha256 -sha256 \
        -in server9.csr -out {output_filename}
''',shell=True)

with open(output_filename,'rb') as f:
    _,_,der_bytes=pem.unarmor(f.read())
    target_certificate=x509.Certificate.load(der_bytes)

with open(tmp_filename,'wb') as f:
    f.write(target_certificate['tbs_certificate'].dump())

subprocess.check_call(rf'openssl dgst -sign test-ca.key -passin "pass:PolarSSLTest" \
                        -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:32 \
                        -sigopt rsa_mgf1_md:sha256 -out {tmp1_filename} {tmp_filename}',
                        shell=True)

with open(tmp1_filename,'rb') as f:
    signature_value= core.OctetBitString(f.read())

with open(output_filename,'wb') as f:
    target_certificate['signature_value']=signature_value
    f.write(pem.armor('CERTIFICATE',target_certificate.dump()))
```

Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
2023-06-19 11:41:12 +08:00
Pengyu Lv
33536d170e Update server9*.crt
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-06-19 11:41:12 +08:00
Pengyu Lv
3ed1653df4 Add server9-bad-{mgfhash,saltlen}.crt
Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-06-19 11:41:12 +08:00