Add mutex protection and std::expected get() to all key stores (issue #36) - #183
Conversation
…36) Seven previously unprotected key stores now serialise import, destroy, and get via a per-store std::mutex. All _get functions copy key material under the lock into an owning View struct and return std::expected<TView, CryptoError>, matching the rest of the architecture. The OpenSSL asym store uses EVP_PKEY_up_ref() instead of copying; callers must call EVP_PKEY_free(). CryptoErrorCode::InternalError added for allocation/up_ref failures. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Blocking: this PR currently does not compile.
Because every relevant CI job is failing at compile time, I did not run further local tests or merge. |
…updates Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Blocking review on the updated #183: the previous API-mismatch blockers are fixed, but this still is not ready to merge.
Verification: |
string_view return broke string concatenation on macOS clang CI
("const char[N] + std::string_view" is not valid standard C++).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Not ready to merge yet. CI is now green and the earlier
For the thread-safety issue this PR is closing, the OpenSSL asymmetric getter should capture both values under one lock, e.g. return a view/reference object containing the up-ref’d |
sign, verify, encapsulate, and decapsulate previously called ossl_asym_store_get() and ossl_asym_store_alg() under separate locks, creating a window where another thread could destroy/reimport the slot between the two calls. The new ossl_asym_store_get_with_alg() captures both the up_ref'd EVP_PKEY* and the stored alg atomically under one lock. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Reviewed latest head 3220379. I do not see any remaining code blockers. The previous issues look fixed:
Local verification passed:
GitHub CI is almost green: OpenSSL, PSA debug, PSA sanitize, TSan, IA compile, and all clang-tidy jobs have passed. |
What
Adds
std::mutexprotection and copy-under-lockget()functions returningstd::expected<TView, CryptoError>to all seven key stores that were previously unprotected.Why
Issue #36: concurrent import/destroy/get on the same key store had no synchronisation, creating data races. The
PQCkey stores already had a mutex but returnedstd::optional; this PR upgrades them tostd::expectedfor consistency with the rest of the architecture.Changes
arm_asm/key_store.hpp,ia_asm/key_store.hpp: Addedsym_store_mutex(),KeyViewstruct,key_store_get()→std::expected<KeyView, CryptoError>copying bytes under lock; import and destroy now lockedarm_asm/ec_key_store.hpp: Addedec_store_mutex(),EcKeyViewstruct,ec_key_store_get()→std::expected<EcKeyView, CryptoError>arm_asm/rsa.hpp: Addedrsa_store_mutex(),RsaKeyViewstruct,rsa_key_store_get()→std::expected<RsaKeyView, CryptoError>openssl/openssl_key_store.hpp: Addedossl_asym_store_mutex()andossl_raw_store_mutex(); asymget()callsEVP_PKEY_up_ref()under lock (caller mustEVP_PKEY_free()); rawget()copies bytes intoOpenSslRawView;ossl_asym_store_alg()also lockedarm_asm/pqc_key_store.hpp,psa_mbedtls/pqc_key_store.hpp:pqc_key_store_get_private/publicupgraded fromstd::optional<PqcKeyView>tostd::expected<PqcKeyView, CryptoError>arm_asm/arm_asm_backend.hpp,ia_asm/ia_asm_backend.hpp,arm_asm/hkdf.hpp,ia_asm/hkdf.hpp,openssl/openssl_backend.hpp: All call sites updated to use the newstd::expectedreturn types; OpenSSL asym call sites now callEVP_PKEY_free()at all exit pathssafe-crypto-lib/crypto_error.hpp: AddedCryptoErrorCode::InternalErrorfor allocation/up_reffailuresCloses #36