fix(ext/node): implement ALPNCallback and SNICallback for TLS server#33360
Open
bartlomieju wants to merge 3 commits intomainfrom
Open
fix(ext/node): implement ALPNCallback and SNICallback for TLS server#33360bartlomieju wants to merge 3 commits intomainfrom
bartlomieju wants to merge 3 commits intomainfrom
Conversation
Implements ALPNCallback and SNICallback options for node:tls server, fixing protocol negotiation and certificate selection that previously reported false/null. Uses rustls's Acceptor API to intercept the ClientHello before creating the ServerConnection, allowing JS callbacks to select certificates and ALPN protocols per-connection. The fast path (no callbacks) is preserved. Also adds getServername() support for server-side TLS connections, NoApplicationProtocol alert mapping, and ALPN callback validation (ERR_TLS_ALPN_CALLBACK_INVALID_RESULT, ERR_TLS_ALPN_CALLBACK_WITH_PROTOCOLS). Closes #33346
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements
ALPNCallbackandSNICallbackoptions fornode:tls.createServer(), which were previously accepted but never invoked.SecureContextfor certificate selectionERR_TLS_ALPN_CALLBACK_WITH_PROTOCOLSwhen bothALPNCallbackandALPNProtocolsare set,ERR_TLS_ALPN_CALLBACK_INVALID_RESULTwhen callback returns a protocol not in the client's listNoApplicationProtocolalert now correctly maps toERR_SSL_TLSV1_ALERT_NO_APPLICATION_PROTOCOLApproach
Uses rustls's
AcceptorAPI to intercept theClientHellobefore creating theServerConnection. This allows extracting SNI and ALPN from the client hello, calling back to JS for callback-based selection, then building a per-connectionServerConfig. The existing fast path (directServerConnection::new) is preserved when no callbacks are set.Closes #33346
Test plan
tests/specs/node/tls_alpn_sni_callbacks/(ALPNCallback, SNICallback, both together)tls_jsstreamsocket_close,tls-connect-simple)ALPNProtocols(without callback) still workscargo clippyclean