Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: Upgrade to Mbed TLS v2.25.0 #14652

Merged
merged 8 commits into from
May 31, 2021
Merged

Conversation

Patater
Copy link
Contributor

@Patater Patater commented May 10, 2021

Summary of changes

Upgrade to Mbed TLS v2.25.0

Please refer to the Mbed TLS v2.25.0 release notes at https://github.com/ARMmbed/mbedtls/releases/tag/v2.25.0 for more information about what comes with this release.

Impact of changes

None

Migration actions required

None

Documentation

None


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label May 10, 2021
@ciarmcom
Copy link
Member

@Patater, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

Copy link
Contributor

@LDong-Arm LDong-Arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good as everything was imported using the script. Waiting for manual testing.

0xc0170
0xc0170 previously approved these changes May 10, 2021
@mbed-ci
Copy link

mbed-ci commented May 10, 2021

Jenkins CI Test : ❌ FAILED

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM
jenkins-ci/mbed-os-ci_build-example-ARM
jenkins-ci/mbed-os-ci_build-example-GCC_ARM
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM
jenkins-ci/mbed-os-ci_build-greentea-ARM
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM

@LDong-Arm
Copy link
Contributor

LDong-Arm commented May 10, 2021

@Patater We need to backport a number of definitions to TF-M's PSA headers. I encountered the same issue when trying to compile for CYTFM_064B0S2_4343W and ARM_MUSCA_S1.

To reproduce the issue, either use Mbed CLI 1, or add mbed-mbedtls to an application's CMakeLists.txt if using mbed-tools. Here's a quick fix: LDong-Arm@cfe2c48 (I haven't polished the commit message yet.)

Alternatively, should we force use the Mbed TLS version of all PSA headers and remove ones from TF-M?

Comment on lines 6495 to 6496
ret = mbedtls_ecp_gen_key( grp_id, &ecp,
mbedtls_ctr_drbg_random,
Copy link
Contributor

@LDong-Arm LDong-Arm May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Mbed PSA targets (e.g. K64F), we get undefined symbol error for mbedtls_ecp_gen_key().

This call here is inside #if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR), which is enabled by the newly added connectivity/mbedtls/include/mbedtls/config_psa.h if MBEDTLS_ECP_C is defined.

The definition of mbedtls_ecp_gen_key() in connectivity/mbedtls/source/rsa.c requiresMBEDTLS_GENPRIME. But our script unsets it:

The comment from five years ago says
# not supported on all targets with mbed OS, nor used by mbed Client

I wonder if we should enable MBEDTLS_GENPRIME globally (if current targets support it), or enable it for Mbed PSA targets, or disable MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR to avoid the call?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be interesting to see whether mbedtls_ecp_gen_key() was called prior to the update. Though because we had something before doesn't automatically mean it was the most ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd like to avoid enabling GENPRIME_C if possible, but still be able to use PSA to import RSA keys or sign with them (at least verify would be good). I'll dig to see if this is a permitted configuration.

@@ -0,0 +1,993 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs to be added to platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/CMakeLists.txt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Patater Patater force-pushed the upgrade-mbedtls-2.25.0 branch from 4a0fc4a to db005d0 Compare May 12, 2021 14:53
@mergify mergify bot dismissed 0xc0170’s stale review May 12, 2021 14:53

Pull request has been modified.

#define MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS 1
#define PSA_WANT_ALG_RSA_PSS 1
#endif /* MBEDTLS_PKCS1_V21 */
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the configuration seems to be causing linker errors with mbed-os-example-crypto, as it is used to replace MBEDTLS_RSA_C and MBEDTLS_GENPRIME in ifdefs, but it only requires RSA_C to be enabled here. An example where it relies on MBEDTLS_GENPRIME (for mbedtls_rsa_gen_key):

#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR)

Wrapping this line with an #ifdef MBEDTLS_GENPRIME seems to result in the same behavior of the example as before this upgrade was introduced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came to the same conclusion and raised Mbed-TLS/mbedtls#4513

We can workaround this issue until the fix is available upstream.

Until we have a fix for Mbed-TLS/mbedtls#4512,
we need to patch the fix during import time. Otherwise, we run into
linker errors when PSA attempts to use RSA key generation, which we've
excluded.

This patch is extracted from
Mbed-TLS/mbedtls#4513
Copy link
Contributor

@LDong-Arm LDong-Arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Patater Thanks, the fix looks good to me.

@Patater We need to backport a number of definitions to TF-M's PSA headers. I encountered the same issue when trying to compile for CYTFM_064B0S2_4343W and ARM_MUSCA_S1.

To reproduce the issue, either use Mbed CLI 1, or add mbed-mbedtls to an application's CMakeLists.txt if using mbed-tools. Here's a quick fix: LDong-Arm@cfe2c48 (I haven't polished the commit message yet.)

Alternatively, should we force use the Mbed TLS version of all PSA headers and remove ones from TF-M?

We still need to address this for TF-M targets. They are similar to the mbedtls_ecc_group_to_psa() issue we worked around previously, but now we have multiple definitions to handle instead of just one...

LDong-Arm added 2 commits May 14, 2021 17:31
In order for Mbed TLS to use the PSA Crypto API, definitions of
`MBEDTLS_SVC_KEY_ID_INIT`, `mbedtls_svc_key_id_t` and
`mbedtls_svc_key_id_is_null()` need to be present but are not provided
by the PSA headers from TF-M.

To solve this issue, this commit copies those definitions from Mbed
TLS's original `psa/crypto_types.h` and `psa/crypto_values.h` into a
separate `mbedtls_svc_key_id.h` for TF-M PSA.
We have added definitions that are needed by Mbed TLS's PSK key exchange
but missing from TF-M's PSA to `mbedtls_svc_key_id.h`. To pick up those
definitions, TF-M's `psa/crypto_values.h' needs to include
`mbedtls_svc_key_id.h`.
@ciarmcom ciarmcom added the stale Stale Pull Request label May 20, 2021
@mbed-ci
Copy link

mbed-ci commented May 20, 2021

Jenkins CI Test : ❌ FAILED

Build Number: 3 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_tfm-integration ✔️
jenkins-ci/mbed-os-ci_greentea-test

@mergify mergify bot added needs: work and removed needs: CI labels May 20, 2021
@LDong-Arm
Copy link
Contributor

connectivity-netsocket-tests-tests-network-interface failed on NUCLEO_F767ZI:

[1621526174.13][CONN][RXD] >>> Running case #4: 'NETWORKINTERFACE_CONN_DISC_REPEAT'...
[1621526174.23][CONN][INF] found KV pair in stream: {{__testcase_start;NETWORKINTERFACE_CONN_DISC_REPEAT}}, queued...
mbedgt: :37::FAIL: Expected 0 Was -3010
[1621526234.23][CONN][RXD] :37::FAIL: Expected 0 Was -3010
[1621526234.23][CONN][INF] found KV pair in stream: {{__testcase_finish;NETWORKINTERFACE_CONN_DISC_REPEAT;0;1}}, queued...
[1621526234.33][CONN][RXD] >>> 'NETWORKINTERFACE_CONN_DISC_REPEAT': 0 passed, 1 failed with reason 'Assertion Failed'

I happen to have this target at home, will try it locally tomorrow.

@ciarmcom ciarmcom removed the stale Stale Pull Request label May 20, 2021
@LDong-Arm
Copy link
Contributor

LDong-Arm commented May 21, 2021

The test always passes on my local board. Also, it didn't fail on other boards in CI. The error -3010 from the log is a DHCP failure, so most likely the network glitched during the run.

@0xc0170 @Patater Please rerun the CI and it'll most likely pass.

@LDong-Arm
Copy link
Contributor

LDong-Arm commented May 24, 2021

I just double checked by running the failing test on CI boards, from my machine. Two of the three NUCLEO_F767ZI labelled with HAS_ETH_CONNECTION have network problems (DHCP always fails), and only one has working connection.

@ARMmbed/mbed-os-maintainers This needs to be fixed before we rerun CI on this and any other PRs.

@Patater
Copy link
Contributor Author

Patater commented May 25, 2021

CI Started

@mbed-ci
Copy link

mbed-ci commented May 25, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 4 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️
jenkins-ci/mbed-os-ci_tfm-integration ✔️

@ciarmcom ciarmcom removed the stale Stale Pull Request label May 25, 2021
@adbridge
Copy link
Contributor

@Patater it would be nice if there was a bullet point summary of what this version of TLS actually brings (as this will go into the release notes for the next release). Also if there is any impact or any migrations required......

@Patater
Copy link
Contributor Author

Patater commented May 25, 2021

Added link to the Mbed TLS v2.25.0 release notes in the description

@ciarmcom ciarmcom added the stale Stale Pull Request label May 26, 2021
@0xc0170 0xc0170 removed the stale Stale Pull Request label May 31, 2021
@0xc0170 0xc0170 merged commit a2d62f9 into ARMmbed:master May 31, 2021
@mergify mergify bot removed the ready for merge label May 31, 2021
@mbedmain mbedmain added release-version: 6.12.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants