f-2708: Add test cases for KeyUsage#380
Open
miyazakh wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands whTest_CryptoKeyUsagePolicies to exercise server-side key usage enforcement (wh_Server_KeystoreEnforceKeyUsage) across AES CTR/ECB/GCM as well as the DMA cipher handlers, ensuring that keys cached without the appropriate usage flags are rejected with WH_ERROR_USAGE.
Changes:
- Add negative (rejection) tests for AES-CTR, AES-ECB, and AES-GCM non-DMA handlers when ENCRYPT/DECRYPT usage flags are missing.
- Add negative (rejection) tests for AES CTR/ECB/CBC/GCM DMA handlers (when
WOLFHSM_CFG_DMAis enabled). - Use
wh_Client_AesCtr{Dma}directly for CTR direction testing to ensureencis exercised as intended.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #380
No scan targets match the changed files in this PR. Review skipped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test: Add key usage policy enforcement tests for AES CTR/ECB/GCM and all DMA handlers
Background
wh_Server_KeystoreEnforceKeyUsageis called in every AES cipher handler on the serverside to prevent a cached key from being used in an operation its policy does not permit
(e.g., an ENCRYPT-only key being used to decrypt). However, the existing positive tests
in
whTestCrypto_Aesalways cache keys with bothWH_NVM_FLAGS_USAGE_ENCRYPTandWH_NVM_FLAGS_USAGE_DECRYPTset, so the enforcement logic is never actually exercised.Problem
Three gaps were identified:
No negative tests for CTR, ECB, or GCM — only
_HandleAesCbchad rejection tests(lines 5101–5214 of
wh_test_crypto.c). Deleting the enforcement call from any ofthe other three handlers caused zero test failures.
No tests at all for the DMA handlers —
_HandleAesCtrDma,_HandleAesEcbDma,_HandleAesCbcDma, and_HandleAesGcmDmaeach contain enforcement code but had notest coverage of any kind.
Fix
Added negative tests to
whTest_CryptoKeyUsagePoliciesintest/wh_test_crypto.c.Each test caches a key with restricted flags, then attempts the forbidden operation and
asserts that the server returns
WH_ERROR_USAGE.Non-DMA handlers
enc=1) without ENCRYPT flagWH_NVM_FLAGS_NONEenc=0) without DECRYPT flagWH_NVM_FLAGS_USAGE_ENCRYPTWH_NVM_FLAGS_NONEWH_NVM_FLAGS_USAGE_ENCRYPTWH_NVM_FLAGS_NONEWH_NVM_FLAGS_USAGE_ENCRYPTDMA handlers (active when built with
DMA=1)Notes
wh_Client_AesCtrdirectly (withenc=0/enc=1) becausewc_AesCtrEncryptis symmetric and always sendsenc=1through the wolfcryptcrypto callback.
wc_AesEcbEncrypt,wc_AesGcmDecrypt, etc.), which set the direction flag correctly through the callback.dec_tagis passed as a non-NULL zero buffer to satisfy theclient-side
BADARGSguard; the server rejects the request at the key usage checkbefore any cryptographic operation or DMA address processing occurs.
Files Changed
test/wh_test_crypto.cwhTest_CryptoKeyUsagePolicies