Fix missing cleanup in psa_cipher_setup #72
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!72
Loading…
Reference in a new issue
No description provided.
Delete branch "psa-fix_setup_cleanup"
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?
Fix #68.
Add non-regression tests: in
hash_setup,mac_setupandcipher_setup, after a failed setup or a successful setup+abort, call setup again with valid parameters and check that it succeeds.#68 suspected other setup functions might have issues with leaving around partially initialized contexts. Have our tests proven that they don't? It looks like the tests we've added in this PR just make sure the context is re-usable, not that we don't leave a partially initialized context around if setup fails.
Previously we could test with a policy of
PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, and did so from themac_setup()test. Do we still have coverage where we use a policy ofPSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY? Maybe we should add a "usage" argument toexercise_mac_setup()(andexercise_cipher_setup()).We used to test here that an application can call abort after setup fails. Do test this elsewhere or not care to test that case anymore?
k
some things to look at:
psa_cmac_setup - in this function if mbedtls_cipher_setup succeeds and mbedtls_cipher_cmac_starts fails
psa_generator_hkdf_setup - if psa_hmac_setup_internal succeeds but subsequesnt call to psa_hash_update fails.
Good point. I've changed the {failed-setup; successful-setup} sequences to {failed-setup; abort; failed-setup; successful-setup}.
We have coverage with different policies in
mac_policy.Since this function only tests
psa_mac_sign_setupand notpsa_mac_verify_setup, it only needs aUSAGE_SIGNpolicy, just like the corresponding cipher test callscipher_encrypt_setupwith aUSAGE_ENCRYPTpolicy. I think having bothUSAGE_SIGNandUSAGE_VERIFYhere was a leftover from the old days when MAC functions didn't check policies correctly.The tests
hash_setup,mac_setupandcipher_setupcheck that the context is reusable. That's the only black-box way of testing that the context is properly reinitialized. There's no black-box way to test that a context isn't “partially initialized”: it's either sufficiently pristine for setup or not.I don't think there's a way to test the case of
psa_cmac_setupwherembedtls_cipher_setupsucceeds andmbedtls_cipher_cmac_startsfails at the moment. An invalid key size is detected earlier, and an unsupported algorithm for CMAC can't be reached until we add support for Camellia and ARIA topsa_crypto(and at that point we may well allow them with CMAC).I've deliberately not touched KDF code because the KDF API has upcoming changes and these bad-case tests will need to change accordingly.
@ -120,6 +203,74 @@ static int construct_fake_rsa_key( unsigned char *buffer,return( len );Style: funny alignment here
@ -120,6 +203,74 @@ static int construct_fake_rsa_key( unsigned char *buffer,return( len );I rewrote the history to fix the indentation in the offending commit.
LGTM
Only change is indentation since @NirSonnenschein's review.
LGTM