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). This fix records the real certificate verification result and skips AddCA() if the callback is what cleared a trust error. Other types of errors don't prevent AddCA() because in those cases the cert is still trusted.

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

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 records the real certificate verification result and skips
AddCA() if the callback is what cleared a trust error. Other types of
errors don't prevent AddCA() because in those cases the cert is still
trusted.

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 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
@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-m4-dtls13

  • FLASH: .text +64 B (+0.0%, 182,332 B / 1,048,576 B, total: 17% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +64 B (+0.0%, 774,908 B / 1,048,576 B, total: 74% used)

gcc-arm-cortex-m7

  • FLASH: .text -64 B (-0.0%, 201,327 B / 262,144 B, total: 77% used)

gcc-arm-cortex-m7-pq

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