Skip to content

feat(rustls): implement TlsAcceptCallbacks support for rustls backend#833

Open
jsulmont wants to merge 5 commits intocloudflare:mainfrom
jsulmont:feat/rustls-tls-accept-callbacks
Open

feat(rustls): implement TlsAcceptCallbacks support for rustls backend#833
jsulmont wants to merge 5 commits intocloudflare:mainfrom
jsulmont:feat/rustls-tls-accept-callbacks

Conversation

@jsulmont
Copy link

@jsulmont jsulmont commented Mar 6, 2026

Summary

  • TlsSettings::with_callbacks() — previously returned an error ("Certificate callbacks are not supported with feature rustls"). Now accepts a TlsAcceptCallbacks and threads it through to Acceptor and the handshake path.
  • TlsRef — extended from an empty struct to carry peer certificate chain (Vec<CertificateDer>) and negotiated cipher suite name, with public accessors: peer_certificate_der(), peer_cert_chain_der(), current_cipher_name()
  • TlsStream::build_tls_ref() — extracts connection state from the underlying rustls session after handshake completes
  • handshake_with_callback() — now builds a populated TlsRef and passes it to the callback, matching the OpenSSL/BoringSSL path's behavior
  • Added set_certificate_chain_file() / set_private_key_file() builder methods on TlsSettings for use with the callbacks constructor
  • Added test_handshake_complete_callback integration test

Motivation

This enables downstream projects to use mTLS peer certificate inspection in post-handshake callbacks when using the rustls feature, which previously only worked with the OpenSSL/BoringSSL backend.

Test plan

  • cargo check -p pingora-core --features rustls
  • cargo clippy -p pingora-core --features rustls --tests
  • cargo fmt -p pingora-core -- --check
  • cargo test -p pingora-core --features rustls -- server::tests::test_handshake_complete_callback

 TlsSettings::with_callbacks() was previously unimplemented and returned
 an error. This change adds full callback support to the rustls TLS path:

 - TlsRef now carries peer certificates and cipher suite name
 - TlsStream::build_tls_ref() extracts session state after handshake
 - handshake_with_callback() passes populated TlsRef to callbacks
 - Added set_certificate_chain_file/set_private_key_file setters
 - Added test_handshake_complete_callback integration test
Jan van Lindt added 4 commits March 6, 2026 16:10
…nSSL backend

 with_single_cert() runs webpki validation on the server's own certificate
 chain, rejecting certs with unrecognized critical extensions. Replace with
 CertifiedKey::new() + with_cert_resolver() which loads the cert+key without
 upfront validation, matching how the OpenSSL backend behaves.

 Also re-exports sign::CertifiedKey, ResolvesServerCert, and ClientHello
 from pingora-rustls for downstream use.
 Add ConnectorOptions::server_cert_verifier to allow users to provide a
 custom rustls ServerCertVerifier for upstream connections. When set, the
 connector bypasses webpki for CA loading, server cert validation, and
 client cert validation — all three of which reject certificates with
 unrecognized critical extensions.

 Changes:
 - ConnectorOptions: add server_cert_verifier field (rustls feature-gated)
 - TlsConnector: use dangerous().with_custom_certificate_verifier() and
   with_client_cert_resolver() when custom verifier is provided
 - CustomServerCertVerifier: generalize delegate from WebPkiServerVerifier
   to dyn ServerCertVerifier for use with custom verifiers
 - ProxyServiceBuilder: add connector_options() builder method to override
   the default ConnectorOptions derived from ServerConf
 - pingora-rustls: re-export ResolvesClientCert and sign module
@drcaramelsyrup drcaramelsyrup requested a review from johnhurt March 6, 2026 18:33
@drcaramelsyrup drcaramelsyrup added enhancement New feature or request help wanted Extra attention is needed labels Mar 6, 2026
@johnhurt
Copy link
Contributor

johnhurt commented Mar 6, 2026

I think this is a great PR, and I would like to accept it. As contributors to this project have (unfortunately) realized, we are slow on reviews and ingestion, and extra slow when things are included that relate to parts of pingora that we don't use internally (like rustls or s2n integration). To help with that, I am hoping that we can find someone or organization that is willing to be a trusted reviewer for rustls-related prs. (Hence the help-wanted label).

If you or someone you know would like to volunteer to take that on, let us know here. We (and the other rustls pingorians) would appreciate it.

cc @hargut

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants