2576 Commits

Author SHA1 Message Date
Dave Rodgman
f154831067 bump version
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2024-01-22 16:47:12 +00:00
Janos Follath
eaeff5b75a Add warning for PKCS 1.5 decryption
Any timing variance dependant on the output of this function enables a
Bleichenbacher attack. It is extremely difficult to use safely.

In the Marvin attack paper
(https://people.redhat.com/~hkario/marvin/marvin-attack-paper.pdf) the
author suggests that implementations of PKCS 1.5 decryption that don't
include a countermeasure should be considered inherently dangerous.

They suggest that all libraries implement the same countermeasure, as
implementing different countermeasures across libraries enables the
Bleichenbacher attack as well.

This is extremely fragile and therefore we don't implement it. The use
of PKCS 1.5 in Mbed TLS implements the countermeasures recommended in
the TLS standard (7.4.7.1 of RFC 5246) and is not vulnerable.

Add a warning to PKCS 1.5 decryption to warn users about this.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-01-22 15:58:57 +00:00
Dave Rodgman
3a91dad9dc Add docs re Everest license
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-08 11:41:55 +00:00
Dave Rodgman
d0ac48087b Bump version
./scripts/bump_version.sh --version 2.28.6 --so-crypto 7 --so-x509 1 --so-tls 14

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-03 13:02:18 +00:00
Dave Rodgman
0f2971a968 Update headers
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-03 12:54:54 +00:00
Minos Galanakis
c7a8ea998d Bump version to 2.28.5
```
./scripts/bump_version.sh --version 2.28.5
```

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2023-10-03 22:24:04 +01:00
Minos Galanakis
6d169947e9 Merge branch 'mbedtls-2.28-restricted' into mbedtls-2.28.5rc0-pr
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2023-10-03 22:22:36 +01:00
Gilles Peskine
fe4d93ad4d ssl_cache: return error codes on error
mbedtls_ssl_cache_get() and mbedtls_ssl_cache_set() returned 1 on many error
conditions. Change this to returning a negative MBEDTLS_ERR_xxx error code.

Completeness: after this commit, there are no longer any occurrences of
`return 1` or `ret = 1`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-29 13:40:33 +02:00
Gilles Peskine
917dd8bd81 Add new error code for SSL cache entry not found
There was no good error to return in this case.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-29 13:39:49 +02:00
Dave Rodgman
7a8ec0f56c
Merge pull request #8209 from lpy4105/issue/8168/2.28_fix-aesni-selection
2.28: Fix AESNI selection
2023-09-26 16:55:28 +00:00
Pengyu Lv
8068b0835b Fix comment
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-09-26 09:27:04 +08:00
Waleed Elmelegy
916ed7b8db restore internal comment in cipher.h due to LTS
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-25 15:18:48 +01:00
Waleed Elmelegy
8ce42ebd87 Remove invalid comments from cipher.h
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-25 14:21:49 +01:00
Manuel Pégourié-Gonnard
e4138e3279 Fix a typo
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-09-25 14:13:24 +01:00
Manuel Pégourié-Gonnard
8013e685f5 Clarify calling sequence in the Cipher layer
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-09-25 14:12:08 +01:00
Manuel Pégourié-Gonnard
3697954ac6 Fix inconsistent documentation of cipher_setup()
- the \internal note said that calling cipher_init() first would be made
mandatory later, but the documention of the ctx parameter already said
the context had to be initialized...
- the documentation was using the word initialize for two different
meanings (calling setup() vs calling init()), making the documentation
of the ctx parameter quite confusing (you must initialize before you can
initialize...)

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-09-25 14:10:49 +01:00
Waleed Elmelegy
08fd33a875 Add warning to mbedtls_cipher_setup() about setting padding mode
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-22 14:45:25 +01:00
Pengyu Lv
20384f416e Fix the comments of some guards
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-09-21 10:14:16 +08:00
Dave Rodgman
f4cf4a6e25
Merge pull request #1070 from gilles-peskine-arm/merge-2.28-restricted-20230915
Merge mbedtls-2.28 into restricted
2023-09-20 12:07:55 +01:00
Gilles Peskine
9cacae3c7a Merge remote-tracking branch 'upstream-public/mbedtls-2.28' into HEAD 2023-09-15 18:32:36 +02:00
Waleed Elmelegy
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
Pengyu Lv
7fb6fc60ce padlock: introduce MBEDTLS_VIA_PADLOCK_HAVE_CODE
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-09-14 14:02:02 +08:00
Gilles Peskine
3d9978e9b3
Merge pull request #8172 from ronald-cron-arm/psa-config-add-comment
Backport 2.28: Add comment about HKDF in config_psa.h
2023-09-13 12:56:02 +00:00
Pengyu Lv
e707dc1bb5 aesni: refine the condition of MBEDTLS_HAVE_X86_64
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-09-13 18:10:41 +08:00
Pengyu Lv
dc5a88b6a4 aesni: make AESNI only operate on X86 and X86_64
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-09-13 18:10:41 +08:00
Pengyu Lv
5a0915953a aesni: define MBEDTLS_HAVE_X86
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-09-13 18:10:25 +08:00
Gilles Peskine
bd26a8de92 More spelling corrections
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-12 19:22:08 +02:00
Gilles Peskine
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
Ronald Cron
fa9392abcd PSA config: Add comment about HKDF.
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2023-09-12 09:22:52 +02:00
Waleed Elmelegy
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
Gilles Peskine
937b91eb6f Fix boolean options in the wrong section
Boolean options that modify the behavior of a module are supposed to be in
the "feature support" section, not in the "configuration options" support:
that section is documented to contain commented-out definitions with a
value, for which the comment contains the default version. In particular,
merely uncommenting a definition in the "configuration options" section is
not supposed to change anything.

Move the offending boolean options to the proper section.

This causes those options to be enabled by `config.py full` unless
explicitly excluded. For the moved options:

* Everest is already explicitly excluded.
* The ALT options need to link against a custom function, so exclude them.
* `MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE` is ok for testing, and is
  currently never tested in `all.sh`. With this commit, we will now test the
  library with it enabled in configurations based on `full`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-07 17:40:16 +02:00
Tom Cosgrove
5c46332184
Merge pull request #8146 from tom-cosgrove-arm/define-psa-macros-to-1-2.28
Backport 2.28: Define all PSA_xxx macros to 1 rather than have them empty, for consistency
2023-09-04 22:26:54 +01:00
Waleed Elmelegy
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
Waleed Elmelegy
7d8f95b4e2 Improve mbedtls_pkcs5_pbes2_ext function signature comments
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-04 17:50:53 +01:00
Waleed Elmelegy
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
Tom Cosgrove
95b5d79cbf Move the description of MBEDTLS_TEST_DEFINES_ZEROIZE to before its use
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-01 14:44:09 +01:00
Tom Cosgrove
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
Tom Cosgrove
73285cc075 Define all PSA_xxx macros to 1 rather than have them empty, for consistency
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-01 13:07:39 +01:00
Tom Cosgrove
43210b56f3 Add the ability to verify mbedtls_platform_zeroize() calls with -Wsizeof-pointer-memaccess
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-01 11:24:27 +01:00
Gilles Peskine
9471815dd3
Merge pull request #7828 from davidhorstmann-arm/2.28-reword-net-free-description-2544
[Backport 2.28] Reword the description of `mbedtls_net_free()`
2023-08-21 21:17:14 +00:00
Gilles Peskine
7fbbb61238 Merge remote-tracking branch 'mbedtls-2.28' into calloc-also-zeroizes-2-28 2023-08-21 17:25:47 +02:00
Chien Wong
8aa8d78ed9
Add potential missing inline definition
Signed-off-by: Chien Wong <m@xv97.com>
2023-08-10 12:24:43 +08:00
Chien Wong
12f6f28e15
Improve doc on special use of A in ecp group structure
Signed-off-by: Chien Wong <m@xv97.com>
2023-08-09 22:15:14 +08:00
Waleed Elmelegy
01b6df76db Improve mbedtls_pkcs5_pbes2 function signature comments
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-08-08 15:37:28 +01:00
Waleed Elmelegy
412629c815 Improve & test legacy mbedtls_pkcs5_pbe2
* Prevent pkcs5_pbe2 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.
* Add tests to check these scenarios. Test data has been
  reused but with changing padding data in last block to
  check for valid/invalid padding.
* Document new behaviour, known limitations and possible
  security concerns.

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-08-08 15:36:05 +01:00
Gilles Peskine
b438348774
Merge pull request #8010 from marekjansta/fix-x509-ec-algorithm-identifier-2.28
Backport 2.28: Fixed x509 certificate generation to conform to RFCs when using ECC key
2023-08-07 19:14:52 +00:00
Dave Rodgman
403ce0a6cc Bump version numbers
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-08-02 15:35:45 +01:00
Marek Jansta
0a6743b2de Fixed AlgorithmIdentifier parameters when used with ECDSA signature algorithm in x509 certificate
Signed-off-by: Marek Jansta <jansta@2n.cz>
2023-07-31 17:33:23 +02:00
Marek Jansta
f5257c06d1 Cherry picked required prerequisites from dev branch, git hash 0167244b
Signed-off-by: Marek Jansta <jansta@2n.cz>
2023-07-31 17:33:16 +02:00
Gilles Peskine
e5507d5f20 Fix empty union when TLS is disabled
When all TLS 1.2 support is disabled, union mbedtls_ssl_premaster_secret was
empty, which is not valid C even if the union is never used. Fixes #6628.

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