-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Support volatile keys in external SE #3382
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
Support volatile keys in external SE #3382
Conversation
|
Thanks @stevew817 for the PR. This doesn't build in some configs, e.g. |
|
Interesting. I'm running with tests/scripts/basic-in-docker.sh, which does not throw this error. Is this script somehow only testing a previous version, and not updating with the latest in the working directory? Is there some script that needs to be run before it to get it to regenerate the output of the .function and .data files? |
|
You can pass component names ( |
b062248 to
68e9556
Compare
gilles-peskine-arm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this mostly looks good, but a few areas need work.
The CI results aren't very useful right now because builds without SE support break on p_drv being unused in psa_start_key_creation.
library/psa_crypto.c
Outdated
|
|
||
| if( attributes->core.lifetime != PSA_KEY_LIFETIME_VOLATILE ) | ||
| /* Check there is a proper handler for this lifetime */ | ||
| if ( PSA_KEY_LIFETIME_GET_LOCATION( lifetime ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code for persistent/volatile and local/external should be mostly orthogonal. As it stands, some validation is missing on persistent SE keys.
If MBEDTLS_PSA_CRYPTO_SE_C is enabled and MBEDTLS_PSA_CRYPTO_STORAGE_C is disabled, a persistent external key should be rejected. This configuration is currently rejected in check_config.h, but only because there is currently no support for volatile external keys, which this PR changes.
To keep this PR small, it's ok to keep the restriction in check_config.h and do the following later:
- Remove the restriction in
check_config.h. - In
all.sh, no longer systematically disableMBEDTLS_PSA_CRYPTO_SE_CwhenMBEDTLS_PSA_CRYPTO_STORAGE_Cis disabled. - Fix any failing test.
But please fix the existing bug that the key id isn't validated for keys in a secure element and add a non-regression test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any intent to support persistent SE-stored keys without having to require PSA Crypto Storage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because the metadata is always in internal storage. Due to the interface design (the application only remembers the key id, not its lifetime), it's difficult to have metadata spread over multiple storage areas.
169de02 to
3561551
Compare
|
Sorry I forgot to mention this earlier, but for future reference, please don't mark GitHub conversations as resolved when you're the author of the code: that's for the commenter to do when they've decided that the comment was resolved satisfactorily. In Mbed TLS, we have a convention for the coder use the 🚀 emoji to indicate “I've handled this comment in my local copy”, if you want to keep track of which comments you've handled. |
|
@gilles-peskine-arm Do you have insight into why those two CI jobs are still failing? |
|
The remaining CI failure is from the ABI compatibility checker. It says that the symbol So that's a pass from CI. I'll review shortly. |
gilles-peskine-arm
left a comment
There was a problem hiding this 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 library code and with the tests. The documentation needs a little improvement.
The commit history is hard to follow, so I'm requesting a rewrite of the history. The commits “Update PSA core to not persist SE keys declared volatile” and “Fixups after review” do too many things. Please break them up. At this point, you might as well remove the back-and-forth between these two commits. In general, please don't do mix refactoring and adding new things in the same commit.
And please use more descriptive commit messages. For example, “Enable figuring out number of cores when running on OS X” is a good commit message: it explains exactly what's going on. “Fix error from #3302” is not so good; it's acceptable because the diff is very simple, but “Fix typo in a macro that isn't used yet” would be more informative. “Update PSA core to not persist SE keys declared volatile” is not bad in itself but the commit does too much which isn't described in the commit message. “Simplify key checking” lacks explanations and “Fixups after review” is not informative at all.
Please add a changelog entry in ChangeLog.d.
To facilitate review, please save a copy of the current state in your fork (I use the naming convention original-branch-name-1, original-branch-name-2, etc. for successive versions) before force-pushing. Please avoid combining new content with a force-push that rewrites the history. Also, please don't rebase on top of the current target branch if there's no strong reason for it (like a force push). The reason for these requests is to make the force-push diff easy to review (in particular, if you're only restructuring commits or rewriting commit messages, the force-push diff should be empty).
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
3561551 to
62ec1d4
Compare
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
gilles-peskine-arm
left a comment
There was a problem hiding this 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 code and commit structure, thanks.
But CI is still unhappy.
|
@gilles-peskine-arm I've made the CI happy (at least the parts that are visible to me). |
ronald-cron-arm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few minor things and a few things I am not sure about.
| DOCKER="sudo docker" | ||
| fi | ||
|
|
||
| # Figure out the number of processors available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit is not related to the subject of this PR thus it would be better to put it in another PR. This is not a blocker though. If you are ok/have time to do it great, otherwise it's not a big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A practical reason not to “sneak in” unrelated commits is when these unrelated commits need to be backported. But this script doesn't exist in the LTS branches, so it's ok.
|
|
||
| Key registration: smoke test | ||
| register_key_smoke_test:TEST_SE_PERSISTENT_LIFETIME:1:PSA_SUCCESS | ||
| register_key_smoke_test:TEST_SE_PERSISTENT_LIFETIME:1:1:PSA_SUCCESS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit message is not rendered correctly by GitHub (too long), could you please rewrite it?
| psa_se_drv_table_entry_t **p_drv ) | ||
| { | ||
| psa_status_t status; | ||
| psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, the commit title is too long.
library/psa_crypto_slot_management.c
Outdated
| psa_key_file_id_t id, | ||
| psa_se_drv_table_entry_t **p_drv, | ||
| int creating ) | ||
| psa_status_t psa_validate_key_location( const psa_key_attributes_t *attributes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about to pass only the lifetime and not all attributes? The idea would be to pass only what is needed. I can see that psa_validate_key_policy() is designed that way.
library/psa_crypto_slot_management.h
Outdated
| } | ||
|
|
||
| /** Test whether the given parameters are acceptable for a persistent key. | ||
| /** Validate that a key's attributes point to a known location. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about just "Validate key's location" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because users will wonder what exactly the validation entails?
library/psa_crypto_slot_management.c
Outdated
| if( ! psa_is_key_id_valid( id, ! creating ) ) | ||
| return( PSA_ERROR_INVALID_ARGUMENT ); | ||
| return( PSA_SUCCESS ); | ||
| psa_status_t psa_validate_key_persistence( const psa_key_attributes_t *attributes ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With such a name, I would expect the function to validate the persistence part of the lifetime (LSB byte) but in fact it rather validates the key identifier thus this is a bit confusing to me.
What about for this function to just test the validity of the key's persistence? It should probably be moved to psa_crypto.c as not related to SE.
Then, I would check the key identifier by calling psa_is_key_id_valid() directly from psa_validate_key_attributes(). I don't see why psa_is_key_id_valid() is in this C file and not in psa_crypto.c as it does not seem to be related to SE. It could probably be renamed to psa_validate_key_id() for naming alignement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an unfortunate clash of terminology, with “persistence” referring both to the general idea of persisting a key in storage (which involves both the id attribute and the lifetime attribute), and to the persistence level in particular which is encoded in the lifetime.
I prefer to have a single entry point for the persistence attributes (id and lifetime). We may add further constraints in the future (for example, that a certain id range is reserved to a certain lifetime). This belongs in slot management, which is not specific to SE support.
So I don't think this part of the code should change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, yes in my mind, persistence here was for persistence level, thus I misunderstood the intent. Fine by me to keep it as it is then but probably that the documentation of the function should be improved along the line of @gilles-peskine-arm comments.
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
bd95312 to
14b8184
Compare
|
Force-push updated commit message length as requested by @ronald-cron-arm |
Inline with review comments. Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
|
@gilles-peskine-arm again, all failing CI is inside the ARM network and I cannot see what would've cause failure. |
|
The CI failures seem mainly to be in our Mbed OS testing: However, I don't know enough about this change or that testing to suggest what the problem is. There's also the ABI/API compatibility check failure, which Gilles said earlier can be ignored. |
|
Mbed OS Testing is currently broken thus just ignore it. Sorry for the inconvenience. Thus this PR does not have any CI issues currently. |
ronald-cron-arm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing my comments. LGTM.
|
CI passed except for:
So this is as good as a pass. |
| return( PSA_SUCCESS ); | ||
|
|
||
| if( psa_is_key_id_valid( key_id, | ||
| psa_key_lifetime_is_external( lifetime ) ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for missing this at the time, but psa_key_lifetime_is_external is wrong here. This allows any application to create a key with a key id that's reserved for the implementation, as long as the key is in a secure element. This wasn't a big issue at the time of this pull request because Mbed TLS didn't use the implementation key id range. But with #3547 (comment) it's beginning to use the range and we're going to have to backtrack this change.
Description
Implemented changes requested in #3288 to support volatile keys located in Secure Element drivers, and to not have the PSA core store information about those volatile keys persistently.
Status
READY
Requires Backporting
NO
Migrations
NO
Additional comments
Todos
Steps to test or reproduce
Tested through the updated SE HAL test suite.