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

Openless PSA crypto APIs implementation #3547

Merged
merged 55 commits into from
Nov 20, 2020

Conversation

ronald-cron-arm
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm commented Aug 7, 2020

Description

This PR is the second part of the work related to #3265, the first part being #3527.

This PR implements the openless PSA crypo APIs that take as input or return a key identifier instead of a key handle (see #3265 for details).

Status

Done

Requires Backporting

No, PSA only

@ronald-cron-arm ronald-cron-arm self-assigned this Aug 7, 2020
@ronald-cron-arm ronald-cron-arm added this to the August 2020 Sprint milestone Aug 7, 2020
@ronald-cron-arm ronald-cron-arm linked an issue Aug 7, 2020 that may be closed by this pull request
@ronald-cron-arm ronald-cron-arm added the needs-preceding-pr Requires another PR to be merged first label Aug 7, 2020
@ronald-cron-arm ronald-cron-arm removed the needs-preceding-pr Requires another PR to be merged first label Sep 18, 2020
@ronald-cron-arm ronald-cron-arm force-pushed the psa-openless branch 2 times, most recently from 9b6be96 to d1f88fc Compare September 18, 2020 12:43
@ronald-cron-arm ronald-cron-arm added needs-review Every commit must be reviewed by at least two team members, and removed needs-ci Needs to pass CI tests needs-work labels Sep 18, 2020
@ronald-cron-arm
Copy link
Contributor Author

The CI is as good as it can. Apart from Mbed OS tests, "merge TLS Testing" and "pr-merge" are falling because of the "ABI-API" testing as expected as this PR changes the definition of API parameter types.

@mpg mpg requested review from mpg and removed request for mpg September 22, 2020 08:50
@ronald-cron-arm
Copy link
Contributor Author

ronald-cron-arm commented Nov 19, 2020

Forced push from 2a61649 to eb9a307:
2a61649 can be found here.
Starting from 2a61649 I have removed the commit "tests: psa: Reset systematically key attributes" (873e688) (no conflict during this history rewrite) and then added the new commit that add psa_reset_key_attributes() where needed.

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

Approved. I'd prefer to improve the lock/acquire terminology, but since this is purely internal, I'm ok with doing that in a follow-up.

@ronald-cron-arm
Copy link
Contributor Author

Approved. I'd prefer to improve the lock/acquire terminology, but since this is purely internal, I'm ok with doing that in a follow-up.

Great. I agree with you that the lock/acquire terminology can and must be improved and I am going to work on it in the coming days. @bensze01 ok to approve on your side as well?

bensze01
bensze01 previously approved these changes Nov 20, 2020
Copy link
Contributor

@bensze01 bensze01 left a comment

Choose a reason for hiding this comment

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

I've left a couple of suggestions, but they are all just typo fixes in comments.
Since no actual code changes are necessary, I'm approving this PR.

@@ -34,6 +34,40 @@
extern "C" {
#endif

/*
* To support temporary both openless APIs and psa_open_key(), define
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* To support temporary both openless APIs and psa_open_key(), define
* To support both openless APIs and psa_open_key() temporarily, define

* key slot.
*
* This counter is decremented by one each time a library function stops
* accessing to the key slot and states it by calling the
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* accessing to the key slot and states it by calling the
* accessing the key slot and states it by calling the


/*
* Create a new persistent or volatile key. When creating the key,
* one of the description of the previously created persistent key
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* one of the description of the previously created persistent key
* one of the descriptions of the previously created persistent keys

@@ -38,16 +38,15 @@ typedef struct
psa_core_key_attributes_t attr;

/*
* Number of on-going accesses, read and/or write, to the key slot by the
* library.
* Number of locks, read and/or write, to the key slot by the library.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Number of locks, read and/or write, to the key slot by the library.
* Number of locks on the key slot held by the library.

*
* A key slot is accessed iff its access counter is strickly greater than
* 0.
* A key slot is locked iff its lock counter is strickly greater than 0.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* A key slot is locked iff its lock counter is strickly greater than 0.
* A key slot is locked iff its lock counter is strictly greater than 0.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
After a call to psa_get_key_attributes() to retrieve
the attributes of a key into a psa_key_attributes_t
structure, a call to psa_reset_key_attributes() is
mandated to free the resources that may be
referenced by the psa_key_attributes_t structure.
Not calling psa_reset_key_attributes() may result in
a memory leak.

When a test function calls psa_get_key_parameters()
the associated key attributes are systematically
reset in the clean-up part of the function with a
comment to emphasize the need for the reset and make
it more visible.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
@ronald-cron-arm
Copy link
Contributor Author

ronald-cron-arm commented Nov 20, 2020

Force push from eb9a307 to 3a4f0e3:
I've just reworked the penultimate commit "Improve/fix documentation" to address Bence's last comments.
You can find the diff between eb9a307 to 3a4f0e3 here.

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

As before, approved on the condition of a follow-up that improves acquire/lock terminology.

@gilles-peskine-arm gilles-peskine-arm removed the needs-reviewer This PR needs someone to pick it up for review label Nov 20, 2020
Copy link
Contributor

@bensze01 bensze01 left a comment

Choose a reason for hiding this comment

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

All of my comments were addressed, so I'm approving this PR as well.

@bensze01 bensze01 added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, labels Nov 20, 2020
@gilles-peskine-arm
Copy link
Contributor

CI passed except for expected ABI/API changes (psa_key_handle_tpsa_key_identifier_t or mbedtls_svc_key_id_t, changes in internal structures). I filed #3904 for the improvements around acquire/lock naming. This is ready for merge.

*/
static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key )
{
return( ( key.key_id == 0 ) && ( key.owner == 0 ) );
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm May 28, 2021

Choose a reason for hiding this comment

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

This should be just key.key_id == 0, shouldn't it? If a client passes a null key id, owner information will be attached to it, but owner information about a null key id is not relevant. Fixing in #4392.

@ronald-cron-arm ronald-cron-arm deleted the psa-openless branch July 21, 2023 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the openless crypto API
4 participants