Skip to content

Resuming after a TLS cert hook pause re-runs certificate selection and misdispatches verify-client hooks #13730

Closed

Description

@maskit

When a TS_SSL_CERT_HOOK plugin pauses the handshake and later reenables it, the TLS library calls ssl_cert_callback() again (src/iocore/net/SSLUtils.cc). By then the cert hooks have already finished, but the callback does not recognize that state.

Sequence

  1. The cert hook pauses, and ssl_cert_callback() returns -1.
  2. The plugin reenables. SSLNetVConnection::reenable() calls resume_tls_event() (CERT_INVOKE → CERT), then invoke_tls_event(), which finds no further cert hook and moves the state to HANDSHAKE_HOOKS_CLIENT_CERT.
  3. The library calls the callback again. OpenSSL re-invokes cert_cb from tls_post_process_client_hello() after a negative return. BoringSSL re-runs the select certificate callback once Honor TLS handshake hook pauses on BoringSSL #13729 returns a retry for the pause.
  4. In HANDSHAKE_HOOKS_CLIENT_CERT, calledHooks(TS_EVENT_SSL_CERT) returns false, so selectCertificate() runs a second time.
  5. callHooks(TS_EVENT_SSL_CERT) in HANDSHAKE_HOOKS_CLIENT_CERT starts the TS_SSL_VERIFY_CLIENT_HOOK list and invokes it with TS_EVENT_SSL_CERT.

Effect

  • Verify-client hooks are called early and with TS_EVENT_SSL_CERT instead of TS_EVENT_SSL_VERIFY_CLIENT.
  • The second selectCertificate() may replace an SSL_CTX that the cert hook plugin set while it held the pause. Not yet confirmed; it depends on whether the name or IP lookup finds a match.

With no verify-client hooks registered, callHooks() returns success and the handshake completes, which may be why this has gone unnoticed.

Possible fix

In ssl_cert_callback(), when the hook state shows the cert hooks have completed (HANDSHAKE_HOOKS_CLIENT_CERT / HANDSHAKE_HOOKS_CLIENT_CERT_INVOKE), skip selectCertificate() and callHooks(TS_EVENT_SSL_CERT) and continue as success. The CA cert and session ticket steps at the end of the callback still need to run on that call, since the paused call skipped them.

Testing

A test that pauses the cert hook with a verify-client hook registered, and checks that the verify-client hook only receives TS_EVENT_SSL_VERIFY_CLIENT, should cover both backends.

Found while reviewing #13729. The sequence above is from reading the code; it has not been reproduced yet.

Activity

  1. moonchen commented on Oct 2, 2026

    @moonchen
    Contributor

    Following up from #13729, let’s track both callback resume fixes here. These apply to OpenSSL and BoringSSL.

    • ClientHello — ssl_client_hello_callback(): Skip completed hooks on retry, even after the handshake advances to SNI. This prevents dispatching SNI hooks with the ClientHello event.
    • Certificate — ssl_cert_callback(): Skip completed certificate selection and cert hooks. Preserve the plugin-selected certificate and finish any remaining CA and session-ticket setup. This also prevents dispatching verify-client hooks with the cert event.

    Make these callbacks safe to retry: resume from the saved state, skip completed hooks, and finish any remaining finalization.

    Regression tests should cover:

    • Delayed ClientHello hooks followed by delayed cert hooks.
    • Correct hook event IDs.
    • Switching certificate contexts during a cert-hook pause and preserving the plugin-selected certificate after resuming.
    • No verify-client hook invocation when client authentication is disabled.
    • Both backends, with TLS 1.2 and TLS 1.3.
  2. added 4 commits that reference this issue on Oct 5, 2026
    d7d35b8
    3148e2b
    884214a
    67ebca6
  3. added a commit that references this issue on Oct 14, 2026
    1d232a3
  4. added a commit that references this issue on Nov 2, 2026
    6eada49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions