Skip to content

Expose the downstream socket fd to the TLS certificate callback#915

Open
rzvncj wants to merge 1 commit into
cloudflare:mainfrom
rzvncj:add-support-for-early-fd-extraction
Open

Expose the downstream socket fd to the TLS certificate callback#915
rzvncj wants to merge 1 commit into
cloudflare:mainfrom
rzvncj:add-support-for-early-fd-extraction

Conversation

@rzvncj

@rzvncj rzvncj commented Jun 15, 2026

Copy link
Copy Markdown

The async certificate_callback only receives &mut SslRef, with no handle to the underlying connection. Applications that select or forge a leaf per connection sometimes need connection-level context that is only reachable from the socket fd, which is unavailable at certificate-selection time.

handshake_with_callback already holds the stream when it pauses the handshake to invoke the callback, so capture the stream's fd and stash it on the SSL via ex_data just before the call. Add set_downstream_fd / get_downstream_fd helpers to the ext module of both openssl-derived backends -- the shared boringssl_openssl server path compiles against either, so both must carry the helper. The fd is stored as the same platform-conditional type as pingora-core's UniqueIDType (RawFd on unix, socket handle on Windows), so the call site passes io.id() through with no cast or truncation. No public trait signatures change; the rustls and s2n backends are untouched.

The async `certificate_callback` only receives `&mut SslRef`, with no
handle to the underlying connection. Applications that select or forge a
leaf per connection sometimes need connection-level context that is only
reachable from the socket fd, which is unavailable at
certificate-selection time.

`handshake_with_callback` already holds the stream when it pauses the
handshake to invoke the callback, so capture the stream's fd and stash it
on the SSL via `ex_data` just before the call. Add `set_downstream_fd` /
`get_downstream_fd` helpers to the ext module of both openssl-derived
backends -- the shared `boringssl_openssl` server path compiles against
either, so both must carry the helper. The fd is stored as the same
platform-conditional type as pingora-core's `UniqueIDType` (`RawFd` on
unix, socket handle on Windows), so the call site passes `io.id()` through
with no cast or truncation. No public trait signatures change; the rustls
and s2n backends are untouched.
@rzvncj rzvncj force-pushed the add-support-for-early-fd-extraction branch from 02bd02a to 9371d2b Compare June 15, 2026 10:52
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.

1 participant