PSA PAKE: support persistent keys created with Mbed TLS 3.x #506
No reviewers
Labels
No labels
api-break
approved
bug
component-docs
component-platform
component-test
dependencies
deprecation
DO-NOT-MERGE
enhancement
good first issue
help wanted
needs-adoption
needs-backports
needs-ci
needs-design-approval
needs-info
needs-preceding-pr
needs-review
needs-reviewer
needs-work
priority-high
priority-low
priority-medium
priority-scheduled
priority-very-high
resolved-after-1.1
single-reviewer
size-l
size-m
size-optimisation
size-s
size-xs
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-Mbed-TLS/TF-PSA-Crypto!506
Loading…
Reference in a new issue
No description provided.
Delete branch "jpake-persistent-key-compat-1.0"
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?
Support persistent PAKE keys created with Mbed TLS 3.x. Without this patch, such keys are rejected since the encoding of PAKE algorithms has changed. There is no way to fix this from application code unless the key is exportable. Fixes https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/505, including a test.
Also document PAKE limitations (https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/502, https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/503, https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/504).
PR checklist
@ -12,1 +12,4 @@PSA storage save: PASSWORD-JPAKE(SHA_256)depends_on:PSA_WANT_ALG_JPAKE:PSA_WANT_ALG_SHA_256:CAN_EXERCISE_JPAKEkey_storage_save:0x0001:PSA_KEY_TYPE_PASSWORD:8:PSA_KEY_USAGE_DERIVE | PSA_KEY_USAGE_EXPORT:PSA_ALG_JPAKE(PSA_ALG_SHA_256):PSA_ALG_NONE:"4c":"505341004b455900000000000100000003120800014000000901000a00000000010000004c"The storage format is documented in https://github.com/Mbed-TLS/mbedtls/blob/mbedtls-3.6.0/docs/architecture/mbed-crypto-storage-specification.md#key-file-format-for-mbed-tls-2250 (it hasn't change since Mbed TLS 2.25). There is Python code to construct storage content in
mbedtls_framework.psa_storage.However, you can have reasonable confidence that the test data is what it should be, without inspecting the string, in the following way:
key_storage_saveconstructs a key with the specified content, and checks that the resulting file content is identical to what is passed as the last parameter.key_storage_readgoes the other way round. Thus, if akey_storage_readtest case has a matchingkey_storage_savetest cases, you can have strong confidence that the representation matches what the library does.@ -10,6 +10,30 @@ PSA storage save: AES-GCM+CTRdepends_on:PSA_WANT_KEY_TYPE_AESThis test case has no matching
key_storage_savetest case, since the library no longer officially allows such a key. However, what matters most here is that this is how a JPAKE key was represented in Mbed TLS 3.x, as evidenced by thekey_storage_savetest case in https://github.com/Mbed-TLS/mbedtls/pull/10444 with identical file content.@ -191,13 +258,22 @@ static int test_read_key(const psa_key_attributes_t *expected_attributes,exported_material, length);I intend to amend the last commit to fix this, to facilitate future
git bisect. I'm waiting for the CI to progress, in case there are other similar problems.LGTM, thanks!
I only have minor feedback, all of which can be left for a post-release follow-up (if it needs addressing).
@ -42,6 +42,23 @@ int psa_can_do_hash(psa_algorithm_t hash_alg);*/#define PSA_KEY_TYPE_DES ((psa_key_type_t) 0x2301)/** The beta encoding of JPAKE algorithms, with no hash.Question: should we even include that one in the doxygen output?
@ -537,0 +544,4 @@* - When using the built-in implementation, the user ID and the peer ID* must be `"client"` (6-byte string) and `"server"` (6-byte string),* or the other way round.* Third-party drivers may or may not have this limitation.Note: also, user and peer ID can't have the same value (for example they can't both be "client"). I'm not sure if that's worth mentioning explicitly. We support exactly two cases:
Previously we were injecting a large input either at the
PUBLICstep or at thePROOFstep. Now we're only injecting it at thePUBLICstep. Is that intentional?(Non-blocking: if there's anything to change if can be done in a follow-up.)
Previously we were testing just 1 above the normal size for this step, now we're testing 1 above the maximum size over all steps. Again, was that intentional? (Again, non-blocking.)
@ -141,0 +168,4 @@** We use one particular cipher suite (picking the* hash algorithm from the key policy), so test cases must depend on* CAN_EXERCISE_JPAKE or else setup will fail.Minor: this macro is not actually used by tests, which currently directly depend on
PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT:PSA_WANT_ECC_SECP_R1_256. This is equivalent, so everything's functionally correct, but in terms of readability we should either stop defining that macro, or actually use it.Interestingly the stability checks have failed to run on this PR. Seems possibly related to using a non-default target branch.
@ -42,6 +42,23 @@ int psa_can_do_hash(psa_algorithm_t hash_alg);*/#define PSA_KEY_TYPE_DES ((psa_key_type_t) 0x2301)/** The beta encoding of JPAKE algorithms, with no hash.I wasn't sure, but it is legitimately visible to applications if they query the policy of a key in storage, so I think it should.
The call for the
ZK_PROOFoutput would also have been out-of-sequence, not just with an invalid size. So it wasn't actually serving its stated purpose. I didn't deliberately set off to remove it, but keeping it wouldn't be right either, so I don't propose to bring it back. What should really happen would be to splitERR_INJECT_{LARGE,SMALL}_BUFFER_SIZEintoERR_INJECT_{LARGE,SMALL}_BUFFER_SIZE_AT_STEP_xxx, but that's out of scope here, I've added a note to https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/508.The intent was a wrong size, and as far as I can tell with no particular attention to how the size was wrong. (In particular I recall being a little surprised that we didn't always check one less than the expected size, which would catch the most likely mistake: attempting to read/write the expected amount of data without checking that there the buffer was large enough.) So I just treated it as “pass the wrong buffer size” when I split the output buffer sizes.
LGTM, thanks!
@ -13,0 +22,4 @@depends_on:PSA_WANT_ALG_JPAKE:PSA_WANT_ALG_SHA_256:CAN_EXERCISE_JPAKEkey_storage_save:0x0001:PSA_KEY_TYPE_PASSWORD:8:PSA_KEY_USAGE_DERIVE:PSA_ALG_JPAKE(PSA_ALG_SHA_256):PSA_ALG_NONE:"4c":"505341004b455900000000000100000003120800004000000901000a00000000010000004c"PSA storage read: PASSWORD-JPAKE(SHA_256) (non-exportable)Minor: do we really need
CAN_EXERCISE_JPAKEforsavetests?@ -13,0 +22,4 @@depends_on:PSA_WANT_ALG_JPAKE:PSA_WANT_ALG_SHA_256:CAN_EXERCISE_JPAKEkey_storage_save:0x0001:PSA_KEY_TYPE_PASSWORD:8:PSA_KEY_USAGE_DERIVE:PSA_ALG_JPAKE(PSA_ALG_SHA_256):PSA_ALG_NONE:"4c":"505341004b455900000000000100000003120800004000000901000a00000000010000004c"PSA storage read: PASSWORD-JPAKE(SHA_256) (non-exportable)That's a good point! We don't. I was following the pattern in the storage tests where read and save test cases have the same dependencies (on the key type and the algorithm), even though save tests only need the key type to be supported, not the algorithm.
In general, requiring the algorithm to be supported makes our tests more widely applicable, since other implementations of the PSA crypto API specification (and possibly we in the future) are allowed to refuse to create a key whose policy specifies an unsupported algorithm. On the other hand, in the case of JPAKE,
CAN_EXERCISE_JPAKEis specifically about the primitive, which is not specified in the key policy, this reason doesn't apply.We don't actually care about expanding the test coverage: it doesn't matter whether it's possible to create a persistent PASSWORD-JPAKE key in configurations without secp256r1. So this isn't a test gap, it's just something surprising in the code.
Given the urgency of this pull request, I'll only remove the unnecessary dependency if I need to do some other rework.
LGTM