Skip to content

feat: support pre-hashed RSA signing for HSM-backed PKCS#11 signers#320

Open
carlosmonastyrski wants to merge 3 commits into
mainfrom
PKI-319
Open

feat: support pre-hashed RSA signing for HSM-backed PKCS#11 signers#320
carlosmonastyrski wants to merge 3 commits into
mainfrom
PKI-319

Conversation

@carlosmonastyrski

Copy link
Copy Markdown
Contributor

Description 📣

Type ✨

  • Bug fix
  • New feature
  • Improvement
  • Breaking change
  • Documentation

Tests 🛠️

# Here's some code block to paste some code snippets

@linear

linear Bot commented Jul 20, 2026

Copy link
Copy Markdown

PKI-319

@infisical-review-police

Copy link
Copy Markdown

💬 Discussion in Slack: #pr-review-cli-320-feat-support-pre-hashed-rsa-signing-for-hsm-backed-pkcs-11-sig

Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel.

@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds CKM_RSA_PKCS as a new supported mechanism in resolveMechanism, enabling HSM-backed PKCS#11 signers to perform raw RSA PKCS#1 v1.5 signing on externally pre-hashed (DigestInfo-wrapped) data.

  • A two-line case "CKM_RSA_PKCS" branch is added to the resolveMechanism switch; it always returns the raw pkcs11.CKM_RSA_PKCS constant without consulting the isDigest parameter.
  • Unlike the existing CKM_ECDSA_SHA256/CKM_ECDSA_SHA384 cases — where isDigest=true redirects to the raw CKM_ECDSA mechanism — RSA PKCS mechanisms already use distinct PKCS#11 constants for hash-then-sign vs. raw, so no redirect logic is needed; however, there is also no guard preventing callers from reaching CKM_RSA_PKCS with isDigest=false.

Confidence Score: 3/5

The change is small and scoped to a single switch case, but it introduces a raw cryptographic signing path with no input-contract enforcement; a caller that omits isDigest could silently sign unhashed data.

The new CKM_RSA_PKCS case ignores isDigest, so a caller that sends the mechanism name without explicitly setting isDigest=true (the JSON zero value is false) will still reach CKM_RSA_PKCS. Many HSMs accept small raw payloads under this mechanism and will produce a PKCS#1 v1.5 signature over unhashed data — a cryptographically weak output that is structurally indistinguishable from a valid signature to a naive verifier. The ECDSA raw path (CKM_ECDSA) has the same gap but predates this PR; this PR widens the surface by adding the RSA equivalent.

packages/gateway-v2/pkcs11_enabled.go — specifically the new CKM_RSA_PKCS branch in resolveMechanism and any callers that construct signParams with this mechanism.

Important Files Changed

Filename Overview
packages/gateway-v2/pkcs11_enabled.go Adds CKM_RSA_PKCS raw-RSA mechanism for pre-hashed signing; isDigest is ignored for this case, unlike the ECDSA counterparts, which may allow unsigned (unhashed) data to be signed if callers omit the flag.

Reviews (1): Last reviewed commit: "Support pre-hashed RSA signing for HSM-b..." | Re-trigger Greptile

Comment thread packages/gateway-v2/pkcs11_enabled.go
Comment thread packages/gateway-v2/pkcs11_enabled.go
@veria-ai

veria-ai Bot commented Jul 20, 2026

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

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.

1 participant