Skip to content

keymgmt: fetch CKA_ALLOWED_MECHANISMS on-demand for RSA-PSS type detection - #764

Closed
creatica-soft wants to merge 1 commit into
openssl-projects:mainfrom
creatica-soft:fix/rsa-pss-load-allowed-mechs
Closed

keymgmt: fetch CKA_ALLOWED_MECHANISMS on-demand for RSA-PSS type detection#764
creatica-soft wants to merge 1 commit into
openssl-projects:mainfrom
creatica-soft:fix/rsa-pss-load-allowed-mechs

Conversation

@creatica-soft

Copy link
Copy Markdown

When an RSA key is loaded from the token (via OSSL_STORE), the CKA_ALLOWED_MECHANISMS attribute is not included in the fetch template. p11prov_obj_is_rsa_pss() then returns false for every loaded key — the encoder emits rsaEncryption instead of id-RSASSA-PSS in SubjectPublicKeyInfo.

The problem

  1. PSS-restricted RSA keys have CKA_ALLOWED_MECHANISMS set to PSS-only mechanisms at generation time (p11prov_rsapss_gen).
  2. When the same key is loaded back via OSSL_STORE, the store's find template only requests CKA_MODULUS and CKA_PUBLIC_EXPONENT (prep_rsa_find in store.c). CKA_ALLOWED_MECHANISMS is never fetched.
  3. p11prov_obj_is_rsa_pss() reads from the object's local attribute cache — finds nothing — returns false.
  4. The encoder then writes the unrestricted rsaEncryption OID in the SPKI, and the signature layer cannot determine that PSS padding is required.

The fix

Add a helper get_or_fetch_allowed_mechs() to p11prov_obj_is_rsa_pss() that:

  • First checks the local attribute cache (fast path, no token I/O)
  • If absent, opens a temporary session and fetches the attribute via C_GetAttributeValue
  • Caches the result on the object via p11prov_obj_add_attr(), so every subsequent call hits the fast path

Testing

Tested with SoftHSM (post-2.7.0 main branch) and p11-kit 0.26.4 on Alpine 3.24. The patch restores correct RSA-PSS SPKI encoding for loaded keys — verified via the FastPKI integration suite where previously a PSS-restricted OCSP responder key had its certificate SPKI incorrectly reported as rsaEncryption.

Add the `SUPPORT_SLH_DSA` variable to test initialization scripts and update
`setup.sh` to generate an SLH-DSA key pair when supported. Introduce the
`tslhdsa` script and update `tgenkey.c` and `tdemoca` to verify SLH-DSA
operations (key generation, CSR creation, and signatures) with compatible
PKCS#11 tokens.

Additionally, this fixes a copy-paste bug in `tdemoca` where the ML-DSA CSR
generation incorrectly used the ED25519 key URI.

Assisted-by: Gemini:Gemini Pro Latest
Signed-off-by: Simo Sorce <simo@redhat.com>
@creatica-soft
creatica-soft force-pushed the fix/rsa-pss-load-allowed-mechs branch from a712437 to d2bbeb5 Compare August 8, 2026 11:47
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