Skip to content

Adding tolerance in a few tests for existing objects on token - #79

Closed
ProsaicSatsuma wants to merge 1 commit into
masterfrom
tolerance_in_tests_for_existing_objects
Closed

Adding tolerance in a few tests for existing objects on token#79
ProsaicSatsuma wants to merge 1 commit into
masterfrom
tolerance_in_tests_for_existing_objects

Conversation

@ProsaicSatsuma

Copy link
Copy Markdown
Contributor

Adds tolerance in a few tests for existing objects on the token

@Nicolas-Peiffer

Copy link
Copy Markdown
Contributor

Hello @ProsaicSatsuma , TY 🙏 for your contribution.

In 2026 the big project for crypto11 is to add the support of PKCS#11 v3.2 and the support of the ML-KEM PQC algorithm:

The other big project for 2026 is giving + moving the crypto11 project under the Eclipse Foundation.

Maybe crypto11@v2 will solve your problem? Some v2 release candidates are already available and v2 will be shipped soonish.

For testing we now rely on this project https://github.com/pqctoday-org/pqctoday-hsm

A couple of example of our tests improvements: d7ef862, 64bd799, da787f0

Nicolas-Peiffer added a commit that referenced this pull request Aug 4, 2026
Five assertions in keys_test.go counted every matching object on the
token rather than the ones the test created, so they only passed against
a token that started empty. On a persistent token — CloudHSM, a shared
dev HSM, or a rerun after a crash left keys behind — they failed:

  - TestFindingKeysWithAttributes, searching on CkaValueLen 16 and 32
  - TestFindingKeyPairsWithAttributes, searching on CkaKeyType CKK_RSA
  - TestFindingPrivateKeysWithAttributes, the same search
  - TestFindingAllKeys and TestFindingAllKeyPairs

Take the fix proposed in PR #79, by way of the idiom
this branch already uses in TestFindAllCertificates: identify the objects
by an attribute instead of counting them. #79 snapshotted a baseline
count and asserted n + len(baseline), which still races against anything
created concurrently and, more importantly, passes even when the finder
returns the wrong keys. Matching on CKA_ID does not.

Add two generic helpers, requireKeysFound and requireKeysAbsent, and
convert the five sites. Keys whose CKA_ID cannot be read are skipped
rather than failing the test, since they are by definition not ours.
Searches by label keep their exact counts: the labels are randomBytes(),
so those searches are already isolated and the count is the stronger
assertion.

The CkaValueLen searches also gain an exclusion check. require.Len was
the only thing asserting that a 256-bit key does not answer a
CkaValueLen=16 query; containment alone would have dropped that, so
requireKeysAbsent now states it directly.

TestFindingPrivateKeysWithAttributes is not in #79 — it landed in 62bbca8
and reproduced the same pattern.

#79

Co-Authored-By: Rob Fitzpatrick <19215121+ProsaicSatsuma@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Nicolas-Peiffer Nicolas-Peiffer added this to the v2.0.0 milestone Aug 4, 2026
@Nicolas-Peiffer Nicolas-Peiffer self-assigned this Aug 4, 2026
@Nicolas-Peiffer

Copy link
Copy Markdown
Contributor

Closing this PR as implemented for crypto11@v2 by 68c3cbb. Original PR author @ProsaicSatsuma is mentioned in the commit 68c3cbb as his contribution was used as the basis.

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.

2 participants