1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-04 08:02:28 +03:00
Commit Graph

6579 Commits

Author SHA1 Message Date
f919393e05 Return back to modifying input parameters in pkcs12_parse_pbe_params
Return back to modifying input parameters in pkcs12_parse_pbe_params
to avoid change in behaviour.

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-15 15:34:25 +01:00
6060cf1043 Add new mbedtls_pkcs12_pbe_ext function to replace old function
Add new mbedtls_pkcs12_pbe_ext function to replace
old mbedtls_pkcs12_pbe function that have security
issues.

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-15 15:33:39 +01:00
bd26a8de92 More spelling corrections
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-12 19:22:08 +02:00
f08ca83b4f Update spelling "mbed TLS" to "Mbed TLS"
The official spelling of the trade mark changed from all-lowercase "mbed"
to normal proper noun capitalization "Mbed" a few years ago. We've been
using the new spelling in new text but still have the old spelling in a
lot of text. This commit updates most occurrences of "mbed TLS":

```
sed -i -e 's/mbed TLS/Mbed TLS/g' $(git ls-files ':!ChangeLog' ':!tests/data_files/**' ':!tests/suites/*.data' ':!programs/x509/*' ':!configs/tfm*')
```

Justification for the omissions:

* `ChangeLog`: historical text.
* `test/data_files/**`, `tests/suites/*.data`, `programs/x509/*`: many
  occurrences are significant names in certificates and such. Changing
  the spelling would invalidate many signatures and tests.
* `configs/tfm*`: this is an imported file. We'll follow the upstream
  updates.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-12 19:21:54 +02:00
6d5a5c17b1 Improve pkcs12 pbe tests
* Simplify pkcs12 tests to use algo parameters instead of asn1 buffers.
* Fix output buffers allocation size.

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-08 16:19:20 +01:00
38a89ad507 Improve & test legacy mbedtls_pkcs12_pbe
* Prevent pkcs12_pbe encryption when PKCS7 padding has been
  disabled since this not part of the specs.
* Allow decryption when PKCS7 padding is disabled for legacy
  reasons, However, invalid padding is not checked.
* Document new behaviour, known limitations and possible
  security concerns.
* Add tests to check these scenarios. Test data has been
  generated by the below code using OpenSSL as a reference:

int main()
{
    char pass[] = "\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB";
    unsigned char salt[] = "\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC";
    unsigned char plaintext[] = "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA";
    unsigned char *ciphertext = NULL;
    int iter = 10;
    X509_ALGOR *alg =  X509_ALGOR_new();
    int ciphertext_len = 0;
    int alg_nid = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
    alg->parameter = ASN1_TYPE_new();
    struct asn1_object_st * aobj;
    PKCS5_pbe_set0_algor(alg, alg_nid, iter,
                         salt, sizeof(salt)-1);

    aobj = alg->algorithm;
    printf("\"30%.2X", 2 + aobj->length + alg->parameter->value.asn1_string->length);
    printf("06%.2X", aobj->length);
    for (int i = 0; i < aobj->length; i++) {
        printf("%.2X", aobj->data[i]);
    }

    for (int i = 0; i < alg->parameter->value.asn1_string->length; i++) {
        printf("%.2X", alg->parameter->value.asn1_string->data[i]);
    }
    printf("\":\"");

    for (int i = 0; i < sizeof(pass)-1; i++) {
        printf("%.2X", pass[i] & 0xFF);
    }
    printf("\":\"");
    for (int i = 0; i < sizeof(plaintext)-1; i++) {
        printf("%.2X", plaintext[i]);
    }
    printf("\":");
    printf("0");
    printf(":\"");

    unsigned char * res = PKCS12_pbe_crypt(alg, pass, sizeof(pass)-1, plaintext, sizeof(plaintext)-1, &ciphertext, &ciphertext_len, 1);

    if (res == NULL)
        printf("Encryption failed!\n");
    for (int i = 0; i < ciphertext_len; i++) {
        printf("%.2X", res[i]);
    }
    printf("\"\n");

    return 0;
}

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-08 15:13:54 +01:00
525e355563 Change pkcs5 test dependencies from MBEDTLS_SHA1_C to MBEDTLS_MD_CAN_SHA1
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-04 18:20:32 +01:00
d2a03cb6b8 Fix mbedtls_pkcs5_pbes test function failure
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-04 18:01:42 +01:00
dcad168acf Improve mbedtls_pkcs5_pbes2_ext function test data
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-04 17:56:39 +01:00
d4e57c3623 Fix unused parameters warnings when MBEDTLS_CIPHER_PADDING_PKCS7 is disabled
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-04 17:50:18 +01:00
23ae41626c Fix heap overflow issue in pkcs5_pbes2 testing functions
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-04 17:47:09 +01:00
b66cb65410 Add new mbedtls_pkcs5_pbe2_ext function
Add new mbedtls_pkcs5_pbe2_ext function to replace old
function with possible security issues.

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-04 17:46:26 +01:00
894258f03c ssl-opt.sh doesn't actually use OPENSSL_LEGACY: remove unused function
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-04 15:47:37 +02:00
9bb5d495e8 Detect GnuTLS support for TLS-RSA-WITH-NULL-SHA256
TLS-RSA-WITH-NULL-SHA256, like other SHA256-based cipher suites, was first
introduced in TLS 1.2. Mbed TLS accepts it in earlier protocol versions as
well. This is technically a bug, which older versions of GnuTLS also have.
GnuTLS 3.4.7 fixed this bug. Adapt compat.sh to automatically omit
TLS-RSA-WITH-NULL-SHA256 in invalid protocol versions if GnuTLS doesn't
support it. It's already not included in invalid protocol versions in
OpenSSL interoperability testing.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-04 15:47:17 +02:00
a240fe3c19 Fix code style
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-04 11:29:39 +01:00
ba3b14dad9 For tests, rename TEST_BUFFERS_EQUAL() to TEST_MEMORY_COMPARE()
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-04 11:23:02 +01:00
cd5a7c76f2 Rename the length argument to TEST_CALLOC() to be the more accurate item_count
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-04 11:20:39 +01:00
30ceb23f3e For tests, rename TEST_CALLOC_OR_FAIL() to just TEST_CALLOC()
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-04 11:20:19 +01:00
20e27de0bb For tests, rename ASSERT_ALLOC_WEAK() to TEST_CALLOC_OR_SKIP()
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-04 11:09:08 +01:00
1357502bca For tests, rename ASSERT_ALLOC() to TEST_CALLOC_OR_FAIL()
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-04 11:05:59 +01:00
f88ee8b007 For tests, rename ASSERT_COMPARE() to TEST_BUFFERS_EQUAL()
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-04 11:04:40 +01:00
5ffb19741d config-wrapper-zeroize-memset.h should be user-config-zeroize-memset.h and not include mbedtls_config.h
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-01 14:44:11 +01:00
7f18f44053 Move zeroize-as-memset into a config file under tests/
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-01 14:43:48 +01:00
5117062bb6 Add a build to all.sh to check mbedtls_platform_zeroize() calls
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-01 11:24:27 +01:00
f7829b099d Fix incorrect use of mbedtls_platform_zeroize() in tests
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-01 11:24:27 +01:00
12a2bfc970 Merge pull request #8096 from davidhorstmann-arm/2.28-initialize-struct-get-other-name
[Backport 2.28] Coverity fix: Set `type_id` in `x509_get_other_name()`
2023-08-31 14:10:06 +00:00
4ee11a074f Merge pull request #8132 from davidhorstmann-arm/2.28-fix-unnecessary-include-prefixes
[Backport 2.28] Fix unnecessary header prefix in tests
2023-08-31 07:32:29 +00:00
1804a15342 Fix unnecessary header prefix in tests
Remove unnecessary "../library" prefix from test suite include. This
aligns the test suite with the development branch

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-08-30 15:48:30 +01:00
930cbeeb5b check_test_cases: add a comment to explain idx in walk_compat_sh
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-30 18:33:47 +08:00
b2cd07ce09 compat: list all test cases properly
When calling `add_xxx_ciphersuites`, we have to set MODE properly.
This commit adjusts order to address this issue in list_test_case
which matches what we do in a normal execution.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-30 13:44:54 +08:00
8aba83bf22 compat.sh: return $? in option --list-test-case to handle error case
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-30 11:41:37 +08:00
67fe2644ae check_test_cases.py: do not redirect stderr to stdout
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-30 11:41:28 +08:00
8844844582 check_test_cases.py: use check_output to capture error and return
This commit includes:
 - use subprocess.check_output to report error and capture return
   value
 - add comment as a reminder for option --list-test-case

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-30 11:41:18 +08:00
9412a46ab6 check_test_cases.py: simplify how to store test case description
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-30 11:40:53 +08:00
f0dbde1bdc compat.sh: uniform TITLE format for --list-test-case and run_client
uniform_title is used to print identical format of $TITLE between
--list-test-case and run_client. In such way, no matter how $TITLE
is developed, --list-test-case will in the same format of test case
description as stored in OUTCOME.CSV.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-30 11:40:09 +08:00
a81131d358 compat.sh: fix uncompatiable name of peers in --list-test-case
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-30 11:36:19 +08:00
7e1c0c7f79 compat.sh: uniform test description
Test case description is printed by different block of code. This
causes code maintenance harder since we need to maintain two parts
of code with same functionality. print_test_title is used to
control test case description in compat.sh

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-30 11:35:56 +08:00
baced97929 check_test_cases.py: support checking test coverage in compat.sh
Test case description in compat.sh is in format of
    [ogm]->[ogm] TLSmode, VERIFY CIPHERSUITE_NAME

This program calls compat.sh to list all potential test case
descriptions then checks test case duplication.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-30 10:28:21 +08:00
dd21fc97ba compat.sh: add --list-test-case
The option --list-test-case lists all potential test cases without
executing them. The test case description is identical with $TITLE
during test case execution.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-30 10:25:21 +08:00
67bf9f6359 compat.sh: add --preserve-logs option
Similar to ssl-opt.sh.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-08-28 17:36:22 +02:00
549a96120e Remove GNUTLS_LEGACY
It isn't used anywhere.

Keep the command line options of all.sh to avoid breaking any wrapper
scripts that people might have.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-08-27 21:50:06 +02:00
c67c3b3db6 Reduce adherence on "legacy" OpenSSL and GnuTLS
None of the tests actually need GNUTLS_LEGACY (3.3.8): GNUTLS (3.4.10)
works.

Only single-DES actually needs OPENSSL_LEGACY (1.0.1j). For the rest,
OPENSSL (1.0.2g) works.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-08-27 21:39:10 +02:00
af2ad3dba7 Minor robustness improvement
Let openssl use any experimental or obsolete cipher that's not in ALL.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-08-27 21:32:36 +02:00
b1bd9be762 ssl-opt.sh doesn't actually use OPENSSL_LEGACY, so remove it
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-08-27 21:31:47 +02:00
1cf437bc57 Correct analyze_outcomes identation
Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
2023-08-24 09:27:28 +01:00
8d77ec2f7d PSA_CRYPTO_DRIVER_TEST_ALL is incompatible with MBEDTLS_PSA_CRYPTO_CONFIG
Explain how PSA_CRYPTO_DRIVER_TEST_ALL works and why we have it. Note that
it is incompatible with MBEDTLS_PSA_CRYPTO_CONFIG.

MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS is in the full config, so there's no need to
add it explicitly.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-08-23 18:23:20 +02:00
14b36ef54a Make non-executed tests that are not in the allow list an error
* Turn the warnings produced when finding non-executed tests that
   are not in the allow list into errors.

Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
2023-08-23 16:52:44 +01:00
c895733349 Add EdDSA and XTS to the allow list
As specified in
https://github.com/Mbed-TLS/mbedtls/issues/5390#issuecomment-1669585707
EdDSA and XTS tests are legitimately never executed, so add them to
the allow list.

Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
2023-08-23 16:52:44 +01:00
45d49595b7 Add a flag for requiring full coverage in coverage tests
Introduce the --require-full-coverage in analyze_outcomes.py so that
when analyze_outcomes.py --require-full-coverage is called, those
tests that are not executed and are not in the allowed list issue an
error instead of a warning.

Note that it is useful to run analyze_outcomes.py on incomplete test
results, so this error mode needs to remain optional in the long
term.

Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
2023-08-23 16:52:44 +01:00
2fdd503c4e Add allow list for non-executed test cases
The allow list explicits which test cases are allowed to not be
executed when testing. This may be, for example, because a feature
is yet to be developed but the test for that feature is already in
our code base.

Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
2023-08-23 16:52:44 +01:00