17513 Commits

Author SHA1 Message Date
ashesman
cf01d78e7e Update library/ssl_msg.c
Co-authored-by: Gilles Peskine <gilles.peskine@arm.com>
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-24 16:02:26 +00:00
Ashley Duncan
272cc19ab5 Fixed undefined behavior in ssl_read if buf parameter is NULL.
Signed-off-by: Ashley Duncan <ashes.man@gmail.com>
2023-02-24 16:02:25 +00:00
Gilles Peskine
4dcc08c244
Merge pull request #7138 from davidhorstmann-arm/2.28-fix-oid-printing-bug
[Backport 2.28] Fix bugs in OID to string conversion
2023-02-21 23:16:48 +01:00
Gilles Peskine
cddf9150b2
Merge pull request #7110 from lpy4105/issue/6947/backport-apply-exclusions-in-code_style_py
Backport 2.28: code_style.py: Apply exclusions when restyling a list of files
2023-02-21 10:11:22 +01:00
Dave Rodgman
b0926916f6
Merge pull request #7086 from tom-cosgrove-arm/dont-use-lstrlenW-228
Backport 2.28: Don't use lstrlenW() on Windows
2023-02-20 15:11:32 +00:00
David Horstmann
e8ef6adde0 Correct error code in test_suite_x509parse.data
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 15:01:01 +00:00
David Horstmann
0518d53ba7 Change error codes to more appropriate codes
The more precise error codes are borrowed from the ASN1 module.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
David Horstmann
d138181190 Change += to |= for clearer semantics
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
David Horstmann
8f81d8a305 Make overflow checks more readable
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
David Horstmann
b91ba4b7bf Add ChangeLog for OID-to-string fixes
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
David Horstmann
071dd3579c Add testcases for overlong encoding of OIDs
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
David Horstmann
beb90e30de Disallow overlong encoding when parsing OIDs
OID subidentifiers are encoded as follow. For every byte:
* The top bit is 1 if there is another byte to come, 0 if this is the
last byte.
* The other 7 bits form 7 bits of the number. These groups of 7 are
concatenated together in big-endian order.

Overlong encodings are explicitly disallowed by the BER/DER/X690
specification. For example, the number 1 cannot be encoded as:

0x80 0x80 0x01

It must be encoded as:

0x01

Enforce this in Mbed TLS' OID DER-to-string parser.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
David Horstmann
c714416d16 Add tests for mbedtls_oid_get_numeric_string()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
David Horstmann
cdaee54773 Fix incorrect printing of OIDs
The first 2 components of an OID are combined together into the same
subidentifier via the formula:

subidentifier = (component1 * 40) + component2

The current code extracts component1 and component2 using division and
modulo as one would expect. However, there is a subtlety in the
specification[1]:

>This packing of the first two object identifier components recognizes
>that only three values are allocated from the root node, and at most
>39 subsequent values from nodes reached by X = 0 and X = 1.

If the root node (component1) is 2, the subsequent node (component2)
may be greater than 38. For example, the following are real OIDs:
* 2.40.0.25, UPU standard S25
* 2.49.0.0.826.0, Met Office
* 2.999, Allocated example OID

This has 2 implications that the current parsing code does not take
account of:
1. The second component may be > 39, so (subidentifier % 40) is not
correct in all circumstances.
2. The first subidentifier (containing the first 2 components) may be
more than one byte long. Currently we assume it is just 1 byte.

Improve parsing code to deal with these cases correctly.

[1] Rec. ITU-T X.690 (02/2021), 8.19.4

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
Pengyu Lv
e95df0bd70 Fix CI failure
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-02-16 18:12:51 +08:00
Pengyu Lv
4a37eef78f Only check files known to git
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-02-16 18:12:51 +08:00
Pengyu Lv
bae83d25eb Improve readability
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-02-16 18:12:51 +08:00
Pengyu Lv
44b75a605b adjust help message
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-02-16 18:12:51 +08:00
Pengyu Lv
75e11d3703 print skipped file names to stdout
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-02-16 18:12:51 +08:00
Pengyu Lv
a4b9b7700a code_style.py: Add helpers to print warning and skipped files
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-02-16 18:12:51 +08:00
Pengyu Lv
b1c9cc3ae4 code_style.py: Apply exclusions to the file list
This commit rename `--files` options to `--subset` and
it means to check a subset of the files known to git.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-02-16 18:12:51 +08:00
Gilles Peskine
908e810098
Merge pull request #6929 from paul-elliott-arm/fix_iar_warnings
Backport 2.28: Fix IAR warnings
2023-02-14 20:01:03 +01:00
Paul Elliott
fc820d96e0 Fix IAR warnings
IAR was warning that conditional execution could bypass initialisation of
variables, although those same variables were not used uninitialised. Fix
this along with some other IAR warnings.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2023-02-13 15:07:44 +00:00
Manuel Pégourié-Gonnard
79e0433bf8
Merge pull request #7072 from mpg/cleanup-md-tests-2.28
[Backport] Clean up MD tests
2023-02-13 09:51:33 +01:00
Gilles Peskine
430c6338de
Merge pull request #7089 from sergio-nsk/patch-2
Backport 2.28: Fix unreachable code compiler warning in psa_crypto_driver_wrappers.c
2023-02-12 23:56:30 +01:00
Sergey
26f53f107e
Fix compiler warning: unreachable code
Signed-off-by: Sergey <sergio_nsk@yahoo.de>
2023-02-11 18:20:20 -07:00
Tom Cosgrove
0289c19b8a Don't use lstrlenW() on Windows
The lstrlenW() function isn't available to UWP apps, and isn't necessary, since
when given -1, WideCharToMultiByte() will process the terminating null character
itself (and the length returned by the function includes this character).

Resolves #2994

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-02-10 21:48:33 +00:00
Gilles Peskine
a15b405a46
Merge pull request #7070 from yanrayw/2.28-7008-compatsh-disable-VERIFY-for-PSK
Backport 2.28: compat.sh: remove VERIFY and duplicate test cases for PSK
2023-02-10 15:07:31 +01:00
Gilles Peskine
da829035a2
Merge pull request #7053 from KloolK/typos-backport
[Backport 2.28] Fix typos
2023-02-10 15:07:03 +01:00
Gilles Peskine
a4c10abaf9
Merge pull request #7063 from AndrzejKurek/2.28_x508_san_parsing_testing
[2.28 Backport] X.509: Fix bug in SAN parsing and enhance negative testin
2023-02-10 15:05:30 +01:00
Manuel Pégourié-Gonnard
36076983ed
Merge pull request #7065 from gilles-peskine-arm/coding-style-doc-2.28
Backport 2.28: Switch to the new coding style: documentation
2023-02-10 10:05:34 +01:00
Manuel Pégourié-Gonnard
2122f44d9b Use TEST_EQUAL in one more place in test_suite_md
The only remaining occurrences of TEST_ASSERT are now pointer comparison,
to NULL or to a reference md_info. That is, the output of the following
command is empty:

    grep TEST_ASSERT tests/suites/test_suite_md.function |
        egrep -v '= NULL|== md_info|md_info =='

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-02-09 09:26:23 +01:00
Manuel Pégourié-Gonnard
3c30191c28 Use ASSERT_COMPARE in test_suite_md
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-02-09 09:26:22 +01:00
Yanray Wang
21daf2930a compat.sh: simplify code of iterating on VERIFY for PSK tests
Since PSK cipher suites do not allow client certificate verification,
PSK test cases should be executed under VERIFY=NO. SUB_VERIFIES is
used to constrain verification option for PSK tests.

With aforementioned change, the latter check of
$VERIFY=YES && $TYPE!=PSK is redundant so it's removed.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-02-09 12:30:03 +08:00
Yanray Wang
8332db92bd compat.sh: remove G_CLIENT_PRIO as it's not used
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-02-09 12:15:04 +08:00
Yanray Wang
34ddcc9691 compat.sh: display "no" even if $VERIFY=YES for PSK test cases
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-02-09 12:15:04 +08:00
Yanray Wang
89ac843941 compat.sh: do not filter PSK ciphersuites for GnuTLS if $VERIFY=YES
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-02-09 12:15:04 +08:00
Yanray Wang
b1ae735f09 compat.sh: remove check_openssl_server_bug
As there is no $VERIFY for PSK test cases,
check_openssl_server_bug is not functional in compat.sh.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-02-09 12:15:04 +08:00
Yanray Wang
571e24b6a5 compat.sh: avoid running duplicate test cases for PSK
With the introduction of PSK_TESTS,
 - Either `compat.sh -V NO` or `compat.sh -V YES` runs the PSK tests
 - `compat.sh` or `compat.sh -V "NO YES"` runs PSK tests only once

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-02-09 12:15:04 +08:00
Yanray Wang
eafa355691 compat.sh: ignore $VERIFY in PSK TYPE
There is no need to provide CA file in PSK. Thus VERIFY is
meaningless for PSK. This change omits the arguments passed to
the client and server for $VERIFY=YES.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-02-09 12:15:04 +08:00
Gilles Peskine
55a77fdc4e Improve test and coding standards overview
Make testing and coding standards separate bullet points.

For the coding standards, add a "must", since some of it is now enforced on
the CI.

For tests, don't ask for "fully tested before submission": we don't expect
contributors to run all the tests locally. Ask for basic local testing, and
remind users to check CI results after submission.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-02-08 19:45:41 +01:00
Gilles Peskine
b5e9cd37a0 Announce coding style change in the changelog
It doesn't affect users, but it affects some other external consumers of the
library.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-02-08 19:45:41 +01:00
Hanno Becker
3818fd9d58 Add a ChangeLog entry
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-02-08 09:19:09 -05:00
hanno-becker
95f316ac38 X.509: Improve negative testing for SubjectAltName parsing
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-02-08 08:57:49 -05:00
hanno-becker
c4f885dc02 X.509: Remove red'n bounds checks and zeroiz'n in OtherName parsing
- ASN.1 parsing functions check that length don't exceed buffer bounds,
  so checks `p + len > end` are redundant.
- If `p + len == end`, this is erroneous because we expect further fields,
  which is automatically caught by the next ASN.1 parsing call.

Hence, the two branches handling `p + len >= end` in x509_get_other_name()
can be removed.

Further, zeroization of the `other_name` structure isn't necessary
because it's not confidential (and it's also not performed on other
error conditions in this function).
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-02-08 08:50:01 -05:00
hanno-becker
75ab076971 Fix X.509 SAN parsing
Fixes #2838. See the issue description for more information.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-02-08 08:46:42 -05:00
Gilles Peskine
bfe79030a9
Merge pull request #7021 from lpy4105/issue/backport-do-not-run-x86-tests-on-arm64
Backport 2.28: all.sh: test_m32_xx is not supported on arm64 host
2023-02-07 10:26:16 +01:00
Gilles Peskine
d6bb16a5b8
Merge pull request #6976 from davidhorstmann-arm/2.28-c-build-helper-improvements
[Backport 2.28] Minor improvements to `c_build_helper.py`
2023-02-07 10:26:03 +01:00
Jan Bruckner
6d47550723 Fix typos
Signed-off-by: Jan Bruckner <jan@janbruckner.de>
2023-02-07 07:27:49 +01:00
Manuel Pégourié-Gonnard
54faadce7a Fix style in test_suite_md.function
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-02-06 13:15:56 +01:00