Repository navigation
Conversation
A custom store (WOLFPKCS11_CUSTOM_STORE) closes a written record with wolfPKCS11_Store_Close(), which returns void. A store that commits on close, such as wolfBoot's flash keyvault, cannot report a failed commit, so storeDirty stays clear and the next store does not write the records again. Declare wolfPKCS11_Store_CloseCommit() in store.h. The file and TPM stores already implement it. A custom store opts in by defining WOLFPKCS11_CUSTOM_STORE_CLOSE_COMMIT and implementing it; written records are then closed through it, and a non-zero return fails the operation and marks the token for a full store. Without the define, custom stores build and behave as before. wolfPKCS11_Store_Close() still closes records that were read. A custom store's failure code is now mapped to BUFFER_E, on close and on write. Passed through, wolfBoot's -1 from a failed write read as PIN_INVALID_E, so C_CreateObject returned CKR_USER_NOT_LOGGED_IN, and a -4 on close would read as storage being turned off. tests/custom_store_test.c builds the library sources with a store kept in memory, once with the define and once without. It checks that a failed commit or write fails the create, that a failed write closes the record with commit set to 0, and that the next create writes every object again, then that the objects load back after C_Finalize. It is not built for NSS, which needs the file store, or with WOLFPKCS11_TPM_STORE, which cannot be built with a custom store.
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.
#257 writes only the token objects that changed, and relies on
storeDirty: a store pass that fails or is skipped makes the next pass write every object again. A custom store (WOLFPKCS11_CUSTOM_STORE) cannot set it when a record fails to commit, becausewolfPKCS11_Store_Close()returnsvoid. wolfBoot's TrustZone keyvault commits flash on close, so a failed flash commit leaves the record missing or stale while wolfPKCS11 carries on as if it were stored.This declares
wolfPKCS11_Store_CloseCommit(void* store, int commit)instore.h. The file and TPM stores already implement it (it was a static function). A custom store opts in by definingWOLFPKCS11_CUSTOM_STORE_CLOSE_COMMITand implementing it. Written records are then closed through it, and a non-zero return fails the operation and marks the token for a full store.commitis 0 when writing the record failed, so a store that can discard the record may do so. Without the define, custom stores build and behave exactly as before, andwolfPKCS11_Store_Close()still closes records that were read.Why a define: changing
wolfPKCS11_Store_Close()to returnintwould break every existing custom store at compile time, and weak symbols are not portable to every compiler a custom store is built with. A store can define the macro and the function unconditionally: older wolfPKCS11 versions ignore the define and keep callingwolfPKCS11_Store_Close(). wolfSSL/wolfBoot#957 does this for the keyvault.A custom store's failure code is now mapped to
BUFFER_E, on close and on write. Passed through, wolfBoot's-1from a failed write reads asPIN_INVALID_E, soC_CreateObjectreturnedCKR_USER_NOT_LOGGED_IN, and a-4on close would read as storage being turned off.New test
tests/custom_store_test.c. It builds the library sources with a store kept in memory, twice: with the define (custom_store_test) and without it (custom_store_legacy_test, which checks that a store with onlywolfPKCS11_Store_Close()still builds and keeps objects). With the define, it checks that a failed commit and a failed write both fail the create withCKR_FUNCTION_FAILED, that the failed write closes the record withcommitset to 0, that the next create writes every object again and the one after only its own, and that the objects load back afterC_Finalize. It fails on master at the failed commit check. The tests are not built with--enable-nss, which needs the file store, or with-DWOLFPKCS11_TPM_STORE, which cannot be built with a custom store (BUILD_CUSTOM_STORE_TESTinconfigure.ac). They are also the first CI coverage of a custom store build.Testing:
make checkpasses with no failures in the default,--enable-debug,--enable-nss,--enable-static --disable-shared, C++ (CC=clang++) and C++ debug configs. The pre-commit hookmake testpasses.stm32h5-tzPKCS#11 test app passes in m33mu (as in the wolfBoot integration job) and wolfPKCS11 closes written records withwolfPKCS11_Store_CloseCommit(). Thestm32u5-wolfcrypt-tzconfig builds. wolfBoot master with this change also passes, using the old close.ZD 21908