Skip to content

Add TPM support for wc_SignCert_cb callback API#450

Merged
dgarske merged 8 commits intowolfSSL:masterfrom
jackctj117:cert-callback
Feb 23, 2026
Merged

Add TPM support for wc_SignCert_cb callback API#450
dgarske merged 8 commits intowolfSSL:masterfrom
jackctj117:cert-callback

Conversation

@jackctj117
Copy link
Contributor

@jackctj117 jackctj117 commented Jan 8, 2026

Prereq PR: wolfSSL/wolfssl#9632
This pull request introduces a new callback-based approach for TPM-based certificate and CSR signing, which is recommended for FIPS compliance and simplifies the signing process. The changes add a dedicated internal signing callback and supporting context structure, update the main CSR signing function to select between the new and legacy approaches based on the device ID, and provide thorough documentation for both methods.

Callback-based TPM signing enhancements:

  • Added wolfTPM2_SignCertCb, an internal callback that implements the wc_SignCertCb interface, enabling direct TPM-based signing for both RSA and ECC keys without relying on wolfCrypt crypto callbacks. This supports FIPS compliance and simplifies the code path.
  • Introduced CSR_MakeAndSign_Cb, a new internal function that generates and signs CSRs or self-signed certificates using the callback-based approach, leveraging the new signing callback for direct TPM operations.
  • Defined the TpmSignCbCtx structure in wolftpm/tpm2_wrap.h to hold TPM device and key references for use with the signing callback.

Main CSR signing function update:

  • Updated wolfTPM2_CSR_MakeAndSign_ex to select the callback-based signing approach when devId is INVALID_DEVID, and fall back to the legacy crypto callback method for backward compatibility. This includes logic to determine key type and set signature type appropriately. [1] [2]

Documentation improvements:

  • Added detailed comments in csr.c describing both the new callback-based and legacy crypto callback approaches for TPM certificate signing, including usage recommendations and instructions.

Dependent on wolfSSL/wolfssl#9632

Testing
Setup:
TPM simulator: swtpm running on port 2321
Built wolfSSL with: --enable-certgen --enable-certreq --enable-certext --enable-cryptocb
Built wolfTPM with: --enable-swtpm --enable-certgen --enable-debug
Tests Run:
Generated RSA and ECC test keys in TPM
Created CSRs using ./examples/csr/csr
Validated CSRs with openssl req -text -noout
Results:
wc_SignCert_cb compiled into wolfSSL
wolfTPM2_SignCertCb and CSR_MakeAndSign_Cb compiled into wolfTPM
Generated valid RSA (1228 bytes) and ECC (696 bytes) CSRs
CSRs verified successfully with OpenSSL

@jackctj117 jackctj117 self-assigned this Jan 8, 2026
@jackctj117 jackctj117 marked this pull request as draft January 8, 2026 22:23
@jackctj117 jackctj117 marked this pull request as ready for review January 9, 2026 23:30
@jackctj117 jackctj117 requested a review from wolfSSL-Bot January 9, 2026 23:30
@dgarske dgarske requested review from dgarske and removed request for wolfSSL-Bot January 27, 2026 19:35
@dgarske dgarske removed their request for review February 6, 2026 17:54
@jackctj117 jackctj117 requested a review from Copilot February 13, 2026 17:10
Copy link

Copilot AI left a comment

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 introduces a new callback-based approach for TPM certificate and CSR signing to improve FIPS compliance and simplify the signing process. The implementation adds a direct TPM signing callback that bypasses wolfCrypt crypto callbacks when devId is INVALID_DEVID, while maintaining backward compatibility with the legacy crypto callback approach.

Changes:

  • Added wolfTPM2_SignCertCb callback function and TpmSignCbCtx structure for direct TPM-based signing
  • Implemented CSR_MakeAndSign_Cb function to generate and sign CSRs/certificates using the callback approach
  • Updated wolfTPM2_CSR_MakeAndSign_ex to select between callback-based and legacy approaches based on devId

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
wolftpm/tpm2_wrap.h Added TpmSignCbCtx structure to hold TPM device and key references for the signing callback
src/tpm2_wrap.c Implemented wolfTPM2_SignCertCb callback, CSR_MakeAndSign_Cb function, and updated main CSR signing logic
examples/csr/csr.c Added comprehensive documentation explaining both callback-based and crypto callback approaches

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…) block so it only runs for the new callback path
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jackctj117 jackctj117 requested a review from dgarske February 17, 2026 23:54
@dgarske dgarske assigned dgarske and wolfSSL-Bot and unassigned jackctj117 and dgarske Feb 18, 2026
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

Please add a CI test that enables the WOLFSSL_CERT_SIGN_CB wolfSSL option so we get coverage on this.

dgarske
dgarske previously approved these changes Feb 20, 2026
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

Looks good thanks!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aidangarske aidangarske self-assigned this Feb 20, 2026
@dgarske dgarske assigned jackctj117 and unassigned aidangarske Feb 20, 2026
Copy link
Member

@aidangarske aidangarske left a comment

Choose a reason for hiding this comment

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

Nice job with this I have some nits and changes.

I verified this run and test with RSA and ECC and CSR generation and OpenSSL validation passes. The CI currently tests compilation but not the actual new callback code path. The missing SKID extension could cause issues for users who rely on that extension being present in their CSRs.

Also Another thing to consider is updating wolfTPM2_CSR_Generate_ex() to also support the callback-based approach for consistency, or document that only wolfTPM2_CSR_MakeAndSign_ex() supports the new path.

…alidation, SKID extension, and -signcb example option
@aidangarske aidangarske requested a review from dgarske February 23, 2026 17:00
@dgarske dgarske merged commit bdd6277 into wolfSSL:master Feb 23, 2026
68 checks passed
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.

5 participants