Skip to content

Fix issues found in static code analysis - #212

Open
LinuxJedi wants to merge 14 commits into
wolfSSL:masterfrom
LinuxJedi:fenrir-fixes
Open

Fix issues found in static code analysis#212
LinuxJedi wants to merge 14 commits into
wolfSSL:masterfrom
LinuxJedi:fenrir-fixes

Conversation

@LinuxJedi

Copy link
Copy Markdown
Member

Contains the following:

  • Rollback token insertion on store failure F-8638
  • Generate fresh IVs before key persistence F-8669
  • Persist HKDF token keys F-8635
  • Grow object find results dynamically F-8657
  • Enforce AES-CTR counter boundaries F-8652
  • Retain CBC-PAD final output for retry F-8636
  • Preserve key-wrap-pad decrypt retries F-8653
  • Restrict private objects to user sessions F-8650
  • Stop advertising unsupported SSL3 derive F-8651
  • Validate default interface filters F-8659

Apply version and flag validation even when C_GetInterface receives a NULL interface name. Add static and dynamic API regression coverage for rejected filters.
Remove CKM_SSL3_MASTER_KEY_DERIVE from the advertised mechanism tables because no handler implements it. Add coverage confirming applications can no longer select the unavailable mechanism.
Require a normal user login for private object discovery, handle lookup, and creation, preventing an SO session from using private objects. Preserve NSS public-session behavior and add authorization regression coverage.
Keep AES key-wrap-pad decryption state intact when the output buffer is too small so the caller can retry. Extend the regression test to exercise the size query and retry paths.
Cache final CBC-PAD plaintext until the caller supplies a sufficient output buffer instead of advancing or corrupting state on CKR_BUFFER_TOO_SMALL. Add coverage for a successful retry.
Honor ulCounterBits when incrementing AES-CTR counters, including non-byte-aligned counters, and reject input that would exhaust the counter space. Add single-part and multipart boundary tests.
Replace the fixed WP11_FIND_MAX result storage with a dynamically growing array and propagate allocation failures. Add coverage for enumerating more objects than the former limit.
Add CKK_HKDF to the symmetric-key encode, decode, load, and store paths so HKDF token keys survive library reinitialization. Add persistence regression coverage.
Generate a fresh AES-GCM nonce immediately before each private or secret object encoding so persisted ciphertext never reuses an all-zero or prior IV. Compare persisted IVs and ciphertext for equal keys in the regression test.
Restore the token object list, count, and next identifier when persistence fails after insertion so the failed object cannot remain dangling. Add a read-only-store regression test covering failure and recovery.
Copilot AI lite review requested due to automatic review settings August 20, 2026 14:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses multiple findings from static code analysis across wolfPKCS11’s storage/persistence layer, object enumeration, login/private-object access rules, PKCS#11 v3 interface filtering, and AES operation boundary handling, and adds/updates regression tests to lock in the fixes.

Changes:

  • Fix persistence and token-state correctness (rollback on store failure, fresh IV generation timing, HKDF token-key persistence coverage).
  • Improve crypto operation correctness and retry semantics (AES-CTR counter boundary enforcement, CBC-PAD final retry, AES key-wrap-pad decrypt retry).
  • Tighten API/visibility behavior (private objects restricted to user sessions, stop advertising unimplemented SSL3 derive, validate default-interface version/flags).

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
wolfpkcs11/internal.h Updates internal constants/comments and exposes new helper prototypes and error code.
src/internal.c Core implementation changes: dynamic find handle list, persistence IV generation timing, HKDF persistence path, login-state private access rules, CBC-PAD retry buffer, AES-CTR overflow enforcement, key-wrap-pad retry semantics, store rollback fix.
src/crypto.c Plumbs new find/CTR behaviors into PKCS#11 entry points and maps CTR overflow to CKR_DATA_LEN_RANGE.
src/slot.c Removes advertising and mechanism-info support for unimplemented SSL3 master derive in NSS builds.
src/wolfpkcs11.c Tightens C_GetInterface selection rules for default interface + version/flags filtering.
tests/pkcs11v3test.c Adds negative tests for default interface retrieval with unsupported version/flags.
tests/pkcs11test.c Adds SSL3 mechanism visibility checks, “find many objects” regression, and expands private-object access tests (SO restrictions).
tests/aes_ctr_counterbits_test.c Adds AES-CTR counter overflow regression test coverage.
tests/decrypt_final_bufsize_test.c Adds CBC-PAD final retry regression asserting plaintext is retained.
tests/aes_keywrap_pad_test.c Adds key-wrap-pad decrypt retry regression without reinit after BUFFER_TOO_SMALL.
tests/copyobject_token_test.c Adds regression test for rollback on token persistence failure during copy.
tests/include.am Adds new HKDF persistence test binary to the test build.
tests/hkdf_persistence_test.c New regression test validating HKDF token key persistence and fresh IV usage for persisted secrets.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/copyobject_token_test.c
Comment thread tests/hkdf_persistence_test.c Outdated
Limit normal-user-only enforcement to standard PKCS#11 builds. Restore the NSS internal-module lookup and SO creation behavior required by TLS ticket handling, with regression coverage for both modes.
Build persisted-store test paths with PATH_SEP so the HKDF persistence and nonce regression coverage works on Windows as well as POSIX platforms.
Include io.h for the Windows _chmod declaration used by the token-store failure regression test.
Expose CKM_SSL3_MASTER_KEY_DERIVE in NSS builds as a target-key marker without CKF_DERIVE, preserving ticket-secret unwrap and session resumption without claiming C_DeriveKey support.

Update mechanism discovery coverage for both NSS and standard builds. Validated with make check in both configurations and the Firefox CI container.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants