Skip to content

Return available attributes alongside PKCS11 partial errors - #194

Open
omrzk wants to merge 1 commit into
miekg:masterfrom
omrzk:fix/partial-attribute-values-174
Open

omrzk wants to merge 1 commit into
miekg:masterfrom
omrzk:fix/partial-attribute-values-174

Conversation

@omrzk

@omrzk omrzk commented Oct 30, 2026

Copy link
Copy Markdown

GetAttributeValue drops every value when a module reports an unavailable or sensitive attribute. PKCS#11 requires the other requested attributes to be processed even when CKR_ATTRIBUTE_SENSITIVE, CKR_ATTRIBUTE_TYPE_INVALID, or CKR_BUFFER_TOO_SMALL is returned.

Allow the size query to continue for those partial-result statuses, copy the available values and return them alongside the original module error. Unavailable values remain nil, fatal errors still return no attributes, and allocated buffers are freed on every exit. Use the module's unavailable-information sentinel without depending on Go's integer width.

Fixes #174.

Validation with Go 1.26.10 and SoftHSM 2.6.1 on Linux/amd64:

  • Both new sensitive/invalid-attribute regression cases fail on the original code, returning no attributes. The invalid-object control preserves fatal-error behavior.
  • Full go test -race -p 2 ./... -count=1, ten focused race repetitions, focused AddressSanitizer tests, and go build -p 2 ./... pass.
  • go vet -p 2 ./... reports the existing testing.T.Fatal call from a non-test goroutine in parallel_test.go:222; clean upstream produces the same diagnostic.

The regression uses the software HSM and existing test token, not physical hardware. The buffer-too-small status is handled consistently but is not independently forced by the SoftHSM cases. Generated token-state changes are excluded from the patch.

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.

Returning attributes through GetAttributeValue in certain error scenarios

1 participant