Skip to content

Keep out CAs from cert manager if allowed only by callback - #11110

Open
mattia-moffa wants to merge 1 commit into
wolfSSL:masterfrom
mattia-moffa:20260806-ca-trust-sslctx
Open

Keep out CAs from cert manager if allowed only by callback#11110
mattia-moffa wants to merge 1 commit into
wolfSSL:masterfrom
mattia-moffa:20260806-ca-trust-sslctx

Conversation

@mattia-moffa

@mattia-moffa mattia-moffa commented Aug 7, 2026

Copy link
Copy Markdown
Member

Description

When an application's verify callback overrides ASN_NO_SIGNER_E or ASN_SELF_SIGNED_E on a cert, DoVerifyCallback() clears ret. ProcessPeerCerts() then reads ret==0 as proof that the CA is valid and calls AddCA() to add it to the WOLFSSL_CTX certificate manager.

Instead, the callback allowing a CA is meant to be a one-time exception, specific to that one peer (i.e. the CA shouldn't go to the CTX's cert manager permanently). This fix only adds the certificate temporarily (for this message) and then removes it from the certificate manager.

All of this is only relevant when WOLFSSL_ALT_CERT_CHAINS is not enabled, because the alt cert chains logic sets skipAddCA on an unverified cert before even doing the callback logic.

Fixes zd#22289

Testing

./configure && make && make check
./configure --enable-altcertchains && make && make check

@mattia-moffa mattia-moffa self-assigned this Aug 7, 2026
Copilot AI lite review requested due to automatic review settings August 7, 2026 20:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adjusts certificate-chain processing so that intermediate CA certificates are not added to the WOLFSSL_CTX certificate manager when they are only accepted due to an application verify-callback overriding ASN_NO_SIGNER_E or ASN_SELF_SIGNED_E. This preserves the intended “one-time exception” semantics of the callback and prevents unintended trust persistence across connections.

Changes:

  • Track the pre-callback verification result (preCbRet) in ProcessPeerCerts() before invoking DoVerifyCallback().
  • When the callback clears ASN_NO_SIGNER_E / ASN_SELF_SIGNED_E to success, set skipAddCA so the CA is not added to the cert manager.

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

Comment thread src/internal.c Outdated
@mattia-moffa

Copy link
Copy Markdown
Member Author

Jenkins retest this please

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m3

  • FLASH: .text +104 B (+0.1%, 123,911 B / 262,144 B, total: 47% used)

gcc-arm-cortex-m4

  • FLASH: .text +128 B (+0.1%, 202,223 B / 262,144 B, total: 77% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +192 B (+0.1%, 183,804 B / 1,048,576 B, total: 18% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +192 B (+0.0%, 776,476 B / 1,048,576 B, total: 74% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +192 B (+0.1%, 298,012 B / 1,048,576 B, total: 28% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .text +128 B (+0.0%, 328,496 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +64 B (+0.1%, 124,659 B / 262,144 B, total: 48% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +128 B (+0.1%, 238,817 B / 262,144 B, total: 91% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 202,159 B / 262,144 B, total: 77% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +128 B (+0.0%, 298,908 B / 1,048,576 B, total: 29% used)

gcc-arm-cortex-m7-tls13

@mattia-moffa

Copy link
Copy Markdown
Member Author

Jenkins retest this please

When an application's verify callback overrides ASN_NO_SIGNER_E or
ASN_SELF_SIGNED_E on a cert, DoVerifyCallback() clears ret.
ProcessPeerCerts() then reads ret==0 as proof that the CA is valid and
calls AddCA() to add it to the WOLFSSL_CTX certificate manager.

Instead, the callback allowing a CA is meant to be a one-time exception.
This fix only adds the certificate temporarily (for this message) and
then removes it from the certificate manager.

All of this is only relevant when WOLFSSL_ALT_CERT_CHAINS is not
enabled, because the alt cert chains logic sets skipAddCA on an
unverified cert before even doing the callback logic.
@mattia-moffa
mattia-moffa force-pushed the 20260806-ca-trust-sslctx branch from 6940aa6 to 6bb6321 Compare August 17, 2026 20:56
@mattia-moffa

Copy link
Copy Markdown
Member Author

Jenkins retest this please

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