Make key ids global and define their range #104
No reviewers
Labels
No labels
api-spec
bug
CLA requested
CLA valid
compliance
DO NOT MERGE
duplicate
enhancement
feature branch
good first issue
HEADER FORMATTING ISSUE
help wanted
Information
invalid
Jira status: AWAITING REVIEW
Jira status: CLOSED
Jira status: DONE
Jira status: IN PROGRESS
Jira status: IN REVIEW
Jira status: OPEN
Jira status: REOPENED
Jira status: RESOLVED
mirrored
mirror internally
needs: backports
needs: ci
needs: design review
needs: preceding PR
needs: review
needs: work
notabug
open for community contribution
Product Backlog
question
ready for merge
security
stale
type: bug
type: enhancement
type: question
web pages
wontfix
writing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-ARMmbed/mbed-crypto!104
Loading…
Reference in a new issue
No description provided.
Delete branch "psa-global_key_id"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Make key ids global: you no longer need to specify a key's lifetime when you open it, the key id is enough. This is the “global model” of key ids, as opposed to the former “drive letter” model. Internal ref: https://github.com/ARMmbed/psa-crypto/issues/138
Carve the range of possible key ids into 3 sub-ranges: one for the application, one for the implementation and one reserved for future use. Internal ref: https://github.com/ARMmbed/psa-crypto/issues/136
The decision to permit key id zero is not discussed anywhere - not sure if this is deliberately to leave that decision to the application?
@ -85,10 +85,30 @@ typedef uint32_t psa_algorithm_t;*/Suggest to remove the first "future" in the sentence.
I cannot recall - did we decide that key id of zero was valid or always invalid? - or if we should have a key id that is always invalid/null.
Or is this now an application decision whether or not to allocate a key with id of zero? - is this worth mentioning at all?
@ -1440,6 +1440,19 @@*/Needs a
usuffix. Same for the following three constants@ -1443,0 +1445,4 @@#define PSA_KEY_ID_USER_MIN ((psa_key_id_t)0x00000001)/** The maximum value for a key identifier chosen by the application.*/#define PSA_KEY_ID_USER_MAX ((psa_key_id_t)0x3fffffff)Are these reserved ranges implementation defined or part of PSA spec?
Would nobody ever open a key that doesn't have a
#PSA_KEY_LIFETIME_PERSISTENTlifetime? Is open not used for volatile keys? Is this obvious enough from the function documentation?Would anybody ever try this, (perhaps from separate threads or processes)?
Two issues:
@ -48,0 +55,4 @@TEST_ASSERT( test_uses_key_id( key_id ) )/* Destroy all key ids that may have been created by the current test case. */static void psa_purge_key_storage( void )What does it mean to return 1 here instead of 0? Isn't it a test error to use a key_id greater than PSA_MAX_PERSISTENT_KEY_IDENTIFIER? Or do we want all tests to look like they are using all keys outside this range?
@ -85,10 +85,30 @@ typedef uint32_t psa_algorithm_t;*/I'm in two minds about id=0. On the one hand, allowing it violates the general principle that 0 is a “safe” invalid value. On the other hand, forbidding it means that you can't recognize a valid key id by a simple bit mask, and you can calculate a key id hash by just taking an n-bit hash.
I'd rather keep
PSA_KEY_ID_VENDOR_MIN ≤ 1to not gratuitously break existing code. Is 1..0x3fffffff a sensible range? Should it be 1..0x40000000? Or am I just imagining things and 1..0x3fffffff (or 1..0x7fffffff) is perfectly fine?Volatile keys don't have a key id. I think that's now clearly explained in the doc of
psa_key_id_t. Maybe it needs to be explained elsewhere as well?Since volatile keys don't have a key id, you can't open them.
@ -1443,0 +1445,4 @@#define PSA_KEY_ID_USER_MIN ((psa_key_id_t)0x00000001)/** The maximum value for a key identifier chosen by the application.*/#define PSA_KEY_ID_USER_MAX ((psa_key_id_t)0x3fffffff)Part of PSA spec. An application needs to know what key ids it can use, and so does an implementation.
This seems limiting. No way to share volatile keys?
What's the connection with sharing? Why would sharing require a persistent id?
What's the current API for key sharing ? We discussed proposals in https://github.com/ARMmbed/psa-crypto/issues/72 , but that was done by the services team, and I can't find any design document now.
@ -85,10 +85,30 @@ typedef uint32_t psa_algorithm_t;*/How many places does an implementation need to verify that a valid key id has been provided? - just during key creation and key opening it seems, so the need to check both ends of the range rather than just a one sided range isn't going to set off the code bloat alarm.
If we implement ARMmbed/psa-crypto#158 to unify handles and key ids then "zero is special" returns anyway to represent the NULL handle.
How can you know you are opening the same volatile key without having a persistent ID? Do we prevent opening multiple handles to the same key?
You can't open a volatile key. Opening requires a persistent key id.
Yes, understood. Because you can't open a volatile key, I'm highlighting potential difficulty in obtaining multiple handles to a volatile key. It's easy to get multiple handles to a persistent key; I don't believe we prevent obtaining multiple handles to a persistent key.
Because you can't open a volatile key.
There's no way to obtain multiple handles to the same volatile key. Sharing creates a separate handle which (at least conceptually) points to a copy of the key material.
@ -85,10 +85,30 @@ typedef uint32_t psa_algorithm_t;*/“Reserved for future use” is an idiom, so I'd rather keep it. Should I just stop the sentence there?
@ -1440,6 +1440,19 @@*/Does this actually matter, given that the constants are being cast? If it does we need to change all the literals in the specification, not just these.
@ -48,0 +55,4 @@TEST_ASSERT( test_uses_key_id( key_id ) )/* Destroy all key ids that may have been created by the current test case. */static void psa_purge_key_storage( void )It's an error to use such a key id, but not a test error: there's at least one test case that does it precisely to check that the implementation returns the expected error code. The cleanup code calls
psa_destroy_persistent_keywhich is an internal function and may not enforce the limitation, so the code that sets up the information used by the cleanup code arranges not to callpsa_destroy_persistent_keyout of range.@ -85,10 +85,30 @@ typedef uint32_t psa_algorithm_t;*/I decided that being consistent with “0 is invalid”, and protecting against the application forgetting to set a value that it really should have set (which is part of the reason for “0 is invalid”), are more important than making the permitted range exactly describable with a power of 2. So I've changed
PSA_KEY_ID_VENDOR_MINto 0.@athoelke @Patater The PR is now ready for re-review. I haven't addressed all your comments, but for some of them I'm waiting for clarifications since I'm not sure whether you're requesting a change.
Thanks for answering my questions. Sharing is out of scope for this PR, so resolving this conversation.
@ -1440,6 +1440,19 @@*/Maximal*
@ -1440,6 +1440,19 @@*/Maximal*
@ -1440,6 +1440,19 @@*/Maximum would be good. Minimal/Maximal; Minimum/Maximum.
@ -1440,6 +1440,19 @@*/Thanks. Fixed, also application → implementation.
CI failure is ABI job (known to fail until https://github.com/ARMmbed/mbedtls/pull/2636 lands in the development branch) and
USE_PSA_CRYPTO, which doesn't work on the API branch.@ -85,10 +85,30 @@ typedef uint32_t psa_algorithm_t;*/Repetition of "future" has been eliminated.
@ -1440,6 +1440,19 @@*/Can be changed later (in a different PR), if deemed necessary.