Skip to content

Update mbedtls importer to import mbed-crypto #8723

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

Closed
wants to merge 15 commits into from

Conversation

mohammad1603
Copy link
Contributor

Description

Update the mbedtls importer to import the implementation of PSA Crypto APIs given by Mbed Crypto library.
In addition, it import the files to folders' structure as designed in #8680.
This PR depends on #8680 and the new version of mbedtls (Mbed TLS 2.14.0).

Pull request type

[ ] Fix
[ ] Refactor
[ ] Target update
[x] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Copy link
Contributor

@Patater Patater left a comment

Choose a reason for hiding this comment

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

What testing has been done so far? What's left to test?

TARGET_SRC:=$(TARGET_PREFIX)src
TARGET_INC:=$(TARGET_PREFIX)inc
TARGET_TESTS:=$(TARGET_PREFIX)TESTS
TARGET_SRV_IMPL:=$(TARGET_PREFIX_CRYPTO)/platform/COMPONENT_PSA_SRV_IMPL
TARGET_SPE:=$(TARGET_PREFIX_CRYPTO)/platform/COMPONENT_SPE
TARGETS_PSA_ACCELARATION:=$(TARGET_PREFIX_CRYPTO)/targets
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix spelling of "ACCELARATION"

TARGET_SRV_IMPL:=$(TARGET_PREFIX_CRYPTO)/platform/COMPONENT_PSA_SRV_IMPL
TARGET_SPE:=$(TARGET_PREFIX_CRYPTO)/platform/COMPONENT_SPE
TARGETS_PSA_ACCELARATION:=$(TARGET_PREFIX_CRYPTO)/targets
COMPONENT_NSPE:=$(TARGET_SRV_IMPL)/COMPONENT_NSPE
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be "COMPONENT_" or "TARGET_". It isn't consistent with the previous things.

Copy link
Contributor Author

@mohammad1603 mohammad1603 Nov 13, 2018

Choose a reason for hiding this comment

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

I am moving them back to component as a variable in the file, to be consistent with the other variables' names

@@ -62,6 +71,20 @@ rsync:
cp $(MBED_TLS_DIR)/LICENSE $(TARGET_PREFIX)
cp $(MBED_TLS_DIR)/apache-2.0.txt $(TARGET_PREFIX)
#
# Copying mbed Crypto into mbed library..
Copy link
Contributor

Choose a reason for hiding this comment

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

Use capital "Mbed". Probably also should say "Mbed OS" instead of "Mbed library".

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok

TARGET_SRC:=$(TARGET_PREFIX)src
TARGET_INC:=$(TARGET_PREFIX)inc
TARGET_TESTS:=$(TARGET_PREFIX)TESTS
TARGET_SRV_IMPL:=$(TARGET_PREFIX_CRYPTO)/platform/COMPONENT_PSA_SRV_IMPL
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be prefixed with "COMPONENT_" or "TARGET_"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as here #8723 (comment)

# Updating checked out version tag
echo $(MBED_TLS_RELEASE) > $(TARGET_PREFIX)VERSION.txt
#
# Create mbed Crypto target folder
mkdir -p $(TARGET_PREFIX_CRYPTO)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be done in "update" or perhaps "rsync"?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK

@@ -107,4 +136,5 @@ clean:
rm -rf $(TARGET_SRC)
rm -rf $(TARGET_INC)
rm -rf $(MBED_TLS_DIR)

rm -rf $(TARGET_SRV_IMPL)
rm -rf $(TARGET_SPE)
Copy link
Contributor

Choose a reason for hiding this comment

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

What about COMPONENT_NSPE or others? Should we remove those as well here?

Copy link
Contributor Author

@mohammad1603 mohammad1603 Nov 13, 2018

Choose a reason for hiding this comment

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

COMPONENT_NSPE will be deleted with TARGET_SRV_IMPL since it is an inner folder.
As I understood from @alzix that the acceleration folder and TARGET_PREFIX_CRYPTO folder should be always there and not deleted

@mohammad1603
Copy link
Contributor Author

@Patater the tests importer was tested locally and it import the files as expected, in addition @orenc17 used the importer to run on-target tests over PSoC6 and they seems to be ok

Copy link
Contributor

@Patater Patater left a comment

Choose a reason for hiding this comment

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

Dependent on Mbed TLS tag that contains Mbed Crypto

@@ -27,20 +27,29 @@
#

# Set the mbed TLS release to import (this can/should be edited before import)
MBED_TLS_RELEASE ?= mbedtls-2.13.1
MBED_TLS_RELEASE ?= mbedtls-2.14.0
Copy link
Contributor

Choose a reason for hiding this comment

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

The tag we use for the Mbed OS 5.11 release will be later than mbedtls-2.14.0. Not known yet what we'll use.

Copy link
Contributor

@simonbutcher simonbutcher left a comment

Choose a reason for hiding this comment

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

Some questions and some requested changes.

@@ -27,20 +27,29 @@
#

# Set the mbed TLS release to import (this can/should be edited before import)
MBED_TLS_RELEASE ?= mbedtls-2.13.1
MBED_TLS_RELEASE ?= mbedtls-2.14.0
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be changed yet. 2.14.0 hasn't been released, doesn't reflect the version in the library, and won't be the version shipping in Mbed OS 5.11. Please revert.


# Translate between mbed TLS namespace and mbed namespace
TARGET_PREFIX:=../
TARGET_PREFIX_CRYPTO:=../crypto/
Copy link
Contributor

Choose a reason for hiding this comment

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

The name we agreed for the directory was mbed-crypto, not crypto. Why the change?

Copy link
Contributor Author

@mohammad1603 mohammad1603 Nov 18, 2018

Choose a reason for hiding this comment

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

it was based on: Mbed-TLS/mbedtls#2146
I followed the submodule folder name.
cc @Patater

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @sbutcher-arm ,
i hope it's not crucial for you. since the PR into mbedTLS also follows the 'crypto' naming

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the target folder was renamed to mbed-crypto

TARGET_SRC:=$(TARGET_PREFIX)src
TARGET_INC:=$(TARGET_PREFIX)inc
TARGET_TESTS:=$(TARGET_PREFIX)TESTS
TARGET_SRV_IMPL:=$(TARGET_PREFIX_CRYPTO)/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL
TARGET_SPE:=$(TARGET_PREFIX_CRYPTO)/platform/TARGET_PSA/COMPONENT_SPE
TARGET_PSA_ACCELERATION:=$(TARGET_PREFIX_CRYPTO)/targets
Copy link
Contributor

Choose a reason for hiding this comment

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

I think calling it 'acceleration' is a mistake, and it should be 'drivers' or 'hardware'. Not all driver code/hardware support will speed up crypto operations, and may instead just offer additional security.

@@ -92,6 +118,9 @@ update: $(MBED_TLS_GIT_CFG) $(MBED_TLS_HA_GIT_CFG)
# Checking out the required release
git -C $(MBED_TLS_DIR) checkout $(MBED_TLS_RELEASE)
#
# Update and checkout git submodules
git -C $(MBED_TLS_DIR) submodule update --init --recursive
#
# Updating checked out version tag
echo $(MBED_TLS_RELEASE) > $(TARGET_PREFIX)VERSION.txt
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also capture the Crypto version? Or is the commit id of the submodule enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

The submodule ties down the Mbed Crypto version, but I think it'd be nice to add to the VERSION.txt file for humans so they don't have to go dig it up themselves.

pushd $(MBED_TLS_DIR)/crypto
git describe --tags --abbrev=12 --dirty --always >> $(TARGET_PREFIX)VERSION.txt
popd

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

# Create Mbed Crypto target folder
mkdir -p $(TARGET_PREFIX_CRYPTO)
#
# Copying Mbed Crypto into Mbed OS..
Copy link
Contributor

Choose a reason for hiding this comment

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

I think what's going on here is a bit opaque to outsiders and other teams. There needs to be explanation here, (or pointers to documentation elsewhere) what these directories are and what they mean.

We need to explain what SPE, NSPE are, and what the other directories are and what they mean.

And most of all, we need to explain why we have so many directories. It will seem bizarre and unnecessarily complicated to outsiders.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this directory hierarchy is exist in mbed-os I don't know how adding explanation here will help outsiders.
#8680 PR description explains that but not the merged code.
This PR: ARMmbed/mbed-os-5-docs#815 explains more about that and i think it will be helpful for outsiders

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok - Mbed TLS is my project that I work on daily, and these directories mean nothing to me. What do they do? What are they for? There's no explanation.

I think we need to either:

  • add comments to explain these directories, either in this file or in another file in this directory
  • tell me where there's other existing documentation that explains the structure elsewhere in the repository
  • add a comment that points the reader to documentation somewhere else

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 added the required documentation in the importer.

rm -rf $(TARGET_SPE)
rm -rf $(TARGET_PSA_ACCELERATION)

mkdir -p $(TARGET_SRV_IMPL)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we removing and making these directories? Unlike the other directories being made, won't there be other files in these directories which aren't being imported?

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 think only $(TARGET_PSA_ACCELERATION) shouldn't be removed, the others are created and only the importer copies files into them.

@simonbutcher
Copy link
Contributor

@andresag01 - Can you please review this?

Note to maintainers - please don't merge this until the TLS team have signed off on it.

TARGET_SRC:=$(TARGET_PREFIX)src
TARGET_INC:=$(TARGET_PREFIX)inc
TARGET_TESTS:=$(TARGET_PREFIX)TESTS
TARGET_SRV_IMPL:=$(TARGET_PREFIX_CRYPTO)/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@orenc17 does the build system recognize the PSA_TARGET folder?

@alzix
Copy link
Contributor

alzix commented Nov 19, 2018

It will after #8744 will be merged. Till then mbed-cli will ignore this folder.

Moran Peker and others added 2 commits November 20, 2018 15:14
set crypto storage related defines.
(cherry picked from commit 296001a)
@alekshex
Copy link
Contributor

alekshex commented Nov 21, 2018

@sbutcher-arm All the comments were treated can you please re review. Thank you!

Copy link
Contributor

@dgreen-arm dgreen-arm left a comment

Choose a reason for hiding this comment

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

I'm happy with the changes I requested.

@@ -140,3 +140,6 @@ conf unset MBEDTLS_SSL_TRUNCATED_HMAC

conf unset MBEDTLS_PLATFORM_TIME_TYPE_MACRO

conf set MBEDTLS_PSA_CRYPTO_STORAGE_C
Copy link
Contributor

Choose a reason for hiding this comment

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

These will be configurations of the crypto config.h. At this point we share a config.h, but that won't be true in the next release.

Therefore, I suggest putting a comment in to identify these as Crypto configs, as they have no meaning outside the Crypto submodule, and possibly structuring this to make the transition easier later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added documentation for the configurations

# Create Mbed Crypto target folder
mkdir -p $(TARGET_PREFIX_CRYPTO)
#
# Copying Mbed Crypto into Mbed OS..
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok - Mbed TLS is my project that I work on daily, and these directories mean nothing to me. What do they do? What are they for? There's no explanation.

I think we need to either:

  • add comments to explain these directories, either in this file or in another file in this directory
  • tell me where there's other existing documentation that explains the structure elsewhere in the repository
  • add a comment that points the reader to documentation somewhere else

@mohammad1603 mohammad1603 mentioned this pull request Nov 21, 2018
* Introduce the new folders' structure for the mbed crypto target folder.
* Explain about the need of the new configuration added to adjust-config.sh script
@bulislaw
Copy link
Member

@Patater @sbutcher-arm please see the fixes.

@@ -140,6 +140,8 @@ conf unset MBEDTLS_SSL_TRUNCATED_HMAC

conf unset MBEDTLS_PLATFORM_TIME_TYPE_MACRO

# The following configurations are a needed for Mbed Crypto submodule.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker - but it should be:

The following configurations are needed

# New folder structure is introduced here for targets with Secured-Partition-Environment
# and Non-Secured-Partition-Environment, below documentation for each folder:
# COMPONENT_PSA_SRV_IMPL - include secure service business logic implementation
# code. For example mbedCrytpo or secure time core logic
Copy link
Contributor

@simonbutcher simonbutcher Nov 22, 2018

Choose a reason for hiding this comment

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

Not a blocker - there are a few typos here, and the phrasing can be better. You don't need to say "New folder". In a year's time, the comment will still be there, and it won't be new! Revising the language I'd suggest:

 # The folder structure is for targets that compile to the Secured-Partition-Environment
 # and Non-Secured-Partition-Environments. Documentation for each folder:
 # COMPONENT_PSA_SRV_IMPL - includes secure service business logic implementation
 # code. For example Mbed Crypto or the secure time core logic

There's also a few typos in the following lines. eg. "includes" not "include"

Copy link
Contributor

@simonbutcher simonbutcher left a comment

Choose a reason for hiding this comment

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

The new documentation changes are good enough. Thanks @mohammad1603!

@simonbutcher
Copy link
Contributor

@adbridge / @cmonr / @0xc0170 - Can we merge this ASAP? The Mbed TLS release PR is dependent on it.

If it isn't merged soon, we'll have to absorb the changes into the release PR, and cancel this one.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 23, 2018

If it isn't merged soon, we'll have to absorb the changes into the release PR, and cancel this one.

Let's do it in one (there are still some CI issues being fixed)

@adbridge
Copy link
Contributor

Agree with @0xc0170

@simonbutcher
Copy link
Contributor

Ok - we can do that if it's easier for you. If you wish, you can label this as 'DO NOT MERGE' and I'll include it in my TLS release PR later in the day.

@Patater
Copy link
Contributor

Patater commented Nov 23, 2018

Note that this additionally depends on #8730 for psa_prot_internal_storage.h. This is not a hard dependency, but it means some parts of this PR are not testable without #8730 merged before (or after).

@Patater
Copy link
Contributor

Patater commented Nov 23, 2018

This should be closed in favor of #8859

@NirSonnenschein
Copy link
Contributor

closed in favor of #8859 which contains all changes from this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.