6354 Commits

Author SHA1 Message Date
Gilles Peskine
2710fe2d5e
Merge pull request #7571 from bharsaklemukesh975/update-pkparse-tests-to-use-AES-2.28
Backport 2.28: Updating test-ca.key to use AES instead of DES
2023-05-16 19:15:11 +02:00
Fredrik Hesse
5b673a828d Replace references to Mbed Crypto with Mbed TLS through-out documentation and comments.
Signed-off-by: Fredrik Hesse <fredrik@hesse.se>
2023-05-15 15:27:54 +01:00
Gilles Peskine
e32e447407 Ignore *.o everywhere
We don't commit *.o files anywhere, not even as test data. So ignore them
everywhere.

Also remove a redundant ignore of *.exe in a subdirectory.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-05-12 13:57:39 +02:00
Mukesh Bharsakle
2599a71c74 updating test-ca.key to use AES instead of DES 2023-05-10 12:12:40 +01:00
Gilles Peskine
5ead738269
Merge pull request #7503 from gilles-peskine-arm/test-argument-types-union-2.28
Backport 2.28: Support larger integer test arguments
2023-05-04 10:05:25 +02:00
Gilles Peskine
4ac90508f8 Fix pastapasta
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-05-03 14:53:05 +02:00
Gilles Peskine
25c9f4bb8c typo
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-05-03 14:53:05 +02:00
Gilles Peskine
a4394d4be1 Document a known issue with testing of mbedtls_x509_crt_parse_path
The parse_path tests are known to fail when compiled for a 32-btt architecture
and run via qemu-user on Linux on a 64-bit host. This is due to a known
bug in Qemu: https://gitlab.com/qemu-project/qemu/-/issues/263

Document this, and add test cases to parse the files involved to confirm
that the problem is only with parse_path.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-05-03 14:53:05 +02:00
Gilles Peskine
ad72ea02b3 Improve testing of mbedtls_x509_crt_parse_file
Check the number of certificates found, as was done in the test of
mbedtls_x509_crt_parse_path().

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-05-03 14:53:04 +02:00
Valerio Setti
0eace4128b pk: fixing backport issues
Note: RSA is not supported in mbedtls-2.28 for opaque wrapping
so it was removed from test_suite_pkwrite.data.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-02 16:38:57 +02:00
Valerio Setti
974b816b3e test: check for exact length of returned pub key
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-02 16:06:40 +02:00
Valerio Setti
3f8bf06534 test: optimize code for pk_write_public_from_private()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-02 16:06:39 +02:00
Valerio Setti
39a669433b test: use better naming for the newly introduced test function
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-02 16:06:36 +02:00
Valerio Setti
b4468c45ac test: fix makefile for ec_pub.[der/pem] generation
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-02 16:04:46 +02:00
Valerio Setti
50dacdfd34 test: fix wrong private key file
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-02 16:00:58 +02:00
Valerio Setti
7406e967f0 test: add test function for public key derivation starting from private one
Data test cases are also included in the commit.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-02 16:00:53 +02:00
Manuel Pégourié-Gonnard
c69614bec0
Merge pull request #7505 from valeriosetti/issue7460-part1-backport
Backport: Fixing USE_PSA_INIT/DONE in SSL/X509/PK test suites
2023-05-02 10:44:15 +02:00
Gilles Peskine
dca0501089 Adjust code style for pointer types and casts
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
47903b17e9 typo
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
97f5cff2a2 Add test cases with a question mark
The test framework used to treat them specially (but no longer does). Add
these test cases as non-regression for how the test framework allows "?"
and especially "??" (which I think in the very distant path needed special
handling because the test data was embedded in a .c file, and thus ?? could
be interpreted as the prefix of a trigraph).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
5be40834e4 Fix wrong comment
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
f089972625 Explain the format argument expected by the test functions
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
c2fda4b7fb Fix typos in test descriptions
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
c627917439 Test the line number returned by parse_test_data
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
f599ddfb43 Remove string hack for mbedtls_mpi_mod_int testing
Now that the test framework can pass arbitrary values of type
mbedtls_mpi_sint, just do that.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
ba72662730 Allow more signed integer types in test function arguments
Now that the C code supports the full range of intmax_t, allow any size of
signed integer type in the .data file parser.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
6494d923f0 Support larger integer test arguments: C part
Change the type of signed integer arguments from int32_t to intmax_t.
This allows the C code to work with test function arguments with a range
larger than int32_t. A subsequent commit will change the .datax generator
to support larger types.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
615be63565 parse_function_arguments: stricter type parsing
Use normalization the equality comparisons instead of loose regular
expressions to determine the type of an argument of a test function.

Now declarations are parsed in a stricter way: there can't be ignored junk
at the beginning or at the end. For example, `long long unsigned int x`
was accepted as a test function argument (but not `long long unsigned x`),
although this was misleading since the value was truncated to the range of
int. Now only recognized types are accepted.

The new code is slightly looser in that it accepts `char const*` as well as
`const char*`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
46476e04f4 Support (void) as an argument list of a test function
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
f153c5676b parse_function_arguments: extract per-argument function
Internal refactoring only, no behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
3a37f19e31 parse_function_arguments: make local_vars a list
Internal refactoring only, no behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
9ad7bd3060 Support different types in the parameter store
The test framework stores size_t and int32_t values in the parameter store
by converting them all to int. This is ok in practice, since we assume int
covers int32_t and we don't have test data larger than 2GB. But it's
confusing and error-prone. So make the parameter store a union, which allows
size_t values not to be potentially truncated and makes the code a little
clearer.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
a299043d58 Simplify parsing of integers in .datax files
In the .datax parser, since we're calling strtol() anyway, rely on it for
verification. This makes the .datax parser very slightly more
liberal (leading spaces and '+' are now accepted), and changes the
interpretation of numbers with leading zeros to octal.

Before, an argument like :0123: was parsed as decimal, but an argument like
:0123+1: was parsed as a C expression and hence the leading zero marked an
octal representation. Now, a leading zero is always interpreted according to
C syntax, namely indicating octal. There are no nonzero integer constants
with a leading zero in a .data file, so this does not affect existing test
cases.

In the .datax generator, allow negative arguments to be 'int' (before, they
were systematically treated as 'exp' even though they didn't need to be).

In the .datax parser, validate the range of integer constants. They have to
fit in int32_t. In the .datax generator, use 'exp' instead of 'int' for
integer constants that are out of range.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
242b05b7b6 Exercise string parsing in the test framework
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
1780875e9b Simplify string escapes
Treat backslash as a universal escape character: "\n" is a newline,
backslash escapes any non-alphanumeric character.

This affects some test cases that had "\," standing for backslash-comma.
With the new uniform treatment of backslashes, this needs to be "\\,".

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
ab56a6952b Factor get_function_info out of gen_from_test_data
No intended behavior change. This commit is mainly to satisfy pylint, which
complains that gen_from_test_data now has too many variables. But it's a
good thing anyway to make the function a little more readable.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
f122aedb81 Add line number to a few error messages
This is just a quick improvement, not meant to tackle the problem as a
whole.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
13e836a508 printf testing: exercise integer parsing in the test framework
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
af2fc50b76 Remove stdint.h substitute for older MSVC
We now require at least Visual Studio 2013, which has stdint.h per
 https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2013/y4hta57s(v=vs.120)
so the workaround to define C99 types on pre-C99 MSVC is no longer needed.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:30 +02:00
Gilles Peskine
404923e15c Remove declarations of the nonstandard function strcasecmp
It is no longer used.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-28 13:19:27 +02:00
Valerio Setti
8388fddfdc test: use define for initializing ssl_message_queue struct
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-04-28 12:27:14 +02:00
Valerio Setti
89ae9b6c3f test: fix USE_PSA_INIT position in test_suite_ssl
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-04-28 09:38:55 +02:00
Stephan Koch
771552d471 Fix PSA AEAD ChaCha20 test dependency.
Signed-off-by: Stephan Koch <koch@oberon.ch>
2023-04-27 15:41:41 +01:00
Valerio Setti
d64e2493e1 test: update guards also for pkwrite and pkparse
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-04-27 12:02:09 +02:00
Valerio Setti
57456b343e test: fix max value in test_mx32
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-04-27 11:55:05 +02:00
valerio
5346ef5601 test: minor fix for non-initialized variable
Signed-off-by: valerio <valerio.setti@nordicsemi.no>
2023-04-27 11:54:48 +02:00
Valerio Setti
44570a5b66 test: fix USE_PSA_INIT/DONE for SSL test suite
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-04-27 11:44:32 +02:00
Valerio Setti
e7373a8a0f test: fix USE_PSA_INIT/DONE for x509 test suite
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-04-27 11:37:58 +02:00
Valerio Setti
19c8196212 test: fix USE_PSA_INIT/DONE for PK test suite
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-04-27 11:30:37 +02:00
Gilles Peskine
f549d9cb59 Stop supporting non-canonical case in mpi_write_string test data
We're using the non-standard function strcasecmp() just so that the case
of digits beyond 9 can be different in the library and in the test data.
Use matching case in the test data, and use a standard function for the
comparison.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-04-26 22:51:10 +02:00