wolfPKCS11
wolfPKCS11 is a PKCS#11 library built on wolfSSL. I hardened it against bad input and bad state, with a regression test for each fix.
Main changes
- Made login lockout race-safe and fixed lockout reporting and the C_SetPIN lockout path.#227
- Made token store failures visible and kept stored state consistent when a write fails.#232
- Bound stored object policy to the encrypted key data and validated stored records on load.#229 #228
- Fixed digest, sign and verify length handling, including lengths that do not fit in 32 bits.#241 #239
- Added WOLFPKCS11_DEFAULT_DEVID and software PIN hashing for embedded builds using a wolfCrypt device.#307
One design choice
PIN hashing runs outside the slot lock because it is slow. I split the check into reserve and done steps. Reserve counts in-flight attempts plus failures under the lock and refuses a guess at the limit before hashing, capping racing guesses.
A bug I fixed
Lockout compared the failure counter with == and hashed the PIN with no lock held. Concurrent guesses all passed and the counter stepped past the limit. The fix reserves attempts under the lock, compares with >=, and counts SO C_SetPIN failures. (#227)
How it was checked
| PR | Evidence |
|---|---|
| #227 | Tests for concurrent failures, in-flight guesses and C_SetPIN lockout, using a debug hook to force the race. |
| #241 | New digest_length_test.c and sign_verify_mac_test.c cover oversized, too-small and zero-length cases. |
| #307 | CI runs default_devid_pin_kdf_test across three jobs, one on wolfSSL v5.8.2-stable. |
What is not done yet
Lockout covers the two PIN types within one slot, not a global limit across slots. Device callbacks must finish synchronously; WC_PENDING_E fails the operation.
All my merged pull requests 28 in wolfSSL/wolfPKCS11
- #307Support a default wolfCrypt device ID and software PIN hashing
- #263Fix object class, key type and store name checks from security review findings
- #236Make key material and certificate values fixed after creation
- #234Validate KDF and TLS derive parameters and derived key state
- #231Fix info field padding, mechanism flags and API docs
- #229Bind stored object policy to the encrypted key data
- #240Fix sign, verify and MAC parameter checks
- #237Require key and certificate values at create and fix attribute getters
- #235Validate attribute templates before changing objects
- #228Validate stored object records and scrub key buffers on errors
- #244Stage TPM store records in memory until commit
- #242Zeroize transient MAC, AES and RNG buffers
- #241Fix digest, sign and verify length handling
- #239Reject AES encrypt and decrypt lengths that do not fit in 32 bits
- #238Fix AES and OAEP parameter checks and output lengths
- #233Tighten ECDH derive input checks and derived key state
- #232Report token store failures and keep stored state consistent
- #230Release session operation state on replace, error and cancel
- #243Tighten unwrap, key pair generation and encapsulation checks
- #227Fix login lockout, logout and PIN cache state handling
- #246Forward declare WP11_Object_WrapTpmKey for the no-store TPM build
- #216Reject templates whose class or key type contradicts the key generation mechanism
- #215Fix data object copy and partial update attribute handling
- #214Reserve the NSS email length prefix in object store sizing
- #213Assign a token-owned unique id to every object and harden object find
- #179Add Negative testing and Validation for wolfPKCS11
- #177security review wolfPKCS11 Findings and Test Additions
- #77Fix `C_FindObjects` API Failure to Locate X.509 Certificate by Type