Repository navigation
fix(ext/node): support TLS client resume compat tests - #34095
Conversation
fibibot
left a comment
There was a problem hiding this comment.
setSession()still only stores the supplied session buffer and deliberately leaves_sessionReusedfalse (ext/node/polyfills/_tls_wrap.js:894). On the second connection in the newly enabledtest-tls-client-resume*.jscases,options.sessionis present, so the fake-session generation atonConnectSecure()is skipped andclient2.isSessionReused()remains false. Either emulate reuse for session tokens issued by this polyfill, or keep these compat tests disabled until native/session-cache support can satisfy the assertion.
CI is red in test node_compat (3/3) across platforms, which matches the enabled resume tests hitting this path.
|
|
lunadogbot
left a comment
There was a problem hiding this comment.
-
maxVersion: options.maxVersion ?? defaults.maxVersionandminVersion: options.minVersion ?? defaults.minVersioninServer.prototype.setSecureContextinject version fields even when the caller suppliedsecureProtocol._tls_common.tsrejectssecureProtocolcombined with either version field, so CI'stest-tls-honorcipherorder.jsnow fails across node_compat shards because it usestls.createServer({ secureProtocol: "TLSv1_2_method", ... }). LetcreateSecureContext()apply defaults/mapsecureProtocolinstead of materializing them here. -
connect()has the same conflict: the options object gets defaultminVersion/maxVersionbefore...options, sotls.connect({ secureProtocol: ... })also reachescreateSecureContext()with both forms set. Keep those defaults out unless neithersecureProtocolnor explicit versions are present.
…esume # Conflicts: # ext/node/polyfills/_tls_wrap.js
Per review, injecting minVersion/maxVersion defaults in Server.prototype .setSecureContext and connect() collides with options.secureProtocol, which _tls_common.ts rejects. Only apply the mutable tls.DEFAULT_MIN_VERSION/MAX_VERSION fallback when no secureProtocol or explicit version is set.
lunadogbot
left a comment
There was a problem hiding this comment.
TLSSocket.prototype.setSession()still only copiesoptions.sessionintothis._sessionand deliberately leaves_sessionReusedfalse. On the second connection in the newly enabledtest-tls-client-resume*.jscases,onConnectSecure()then skips fake-session generation becausethis._sessionis already set, andisSessionReused()still reports false. Either emulate reuse for sessions issued by this polyfill, or keep these compat tests disabled until native/session-cache support can satisfy the assertion.
The secureProtocol/default-version conflict from the previous review is fixed on this head, but this resume assertion blocker remains. CI is still running and node_compat already has failures, so this is not approvable yet.
Per review, setSession() now flips _sessionReused on when the caller is replaying one of the synthetic session buffers we hand back from getSession()/'session' events. Without this, isSessionReused() stayed false on the second connection in test-tls-client-resume* even though the test-and-most-real-code-path expects true after passing the prior session back in. Opaque buffers from other sources are left alone -- we still can't resume those.
fibibot
left a comment
There was a problem hiding this comment.
this._sessionReused = isSyntheticSession(this._session)trusts any caller-supplied buffer with adeno-tls*-sessionprefix.onConnectSecure()skipscheckServerIdentity()whenisSessionReused()is true, sotls.connect({ host, session: Buffer.from("deno-tls12-session:any") })can bypass hostname validation for a publicly trusted cert issued to another name. Only mark the synthetic session reused after matching the encodedhost:portagainst the current connection, or keep hostname validation enabled for synthetic sessions.
The secureProtocol default-version conflict from the earlier review is fixed on this head.
Trusting any caller-supplied buffer with a deno-tls*-session prefix
let a TLSSocket skip checkServerIdentity() in onConnectSecure for any
publicly trusted cert, since isSessionReused() short-circuits hostname
validation. The synthetic session already encodes
\`\${servername ?? host}:\${port}\`, so compare the full buffer against
the prefix + this connection's host:port and only mark the handshake
reused on an exact match.
fibibot
left a comment
There was a problem hiding this comment.
onConnectSecure()skipscheckServerIdentity()wheneverthis.isSessionReused()is true, but rustls can reuse the TLSv1.2 session learned from the earlierrejectUnauthorized: falseconnection intest-tls-client-reject-12.js. On the follow-up connection with defaultrejectUnauthorized,_handle.verifyError()reports no error,secureConnectfires, and CI fails the test'scommon.mustNotCall()callback. Don't let sessions accepted underrejectUnauthorized: falsesatisfy a later authenticated connection, or keep hostname/cert validation enabled for that case.
The current head fixes the forged synthetic-session host check, but test node_compat (1/3) debug is red on linux/macos/windows with test-tls-client-reject-12.js.
…t errors
A connection accepted under rejectUnauthorized: false could cache a
session that a later strict tls.connect() reused: rustls skipped cert
verification on the resumed handshake, _handle.verifyError() reported
no error, and secureConnect fired even though the cert was untrusted.
Two related changes close the gap:
* Split the client session cache by verification policy. Strict
connections use NodeTlsState::client_session_store; rejectUnauthorized:
false connections use client_session_store_insecure. Sessions from
the lenient store are never offered to a strict handshake.
* Make NodeServerCertVerifier strict when reject_unauthorized is true:
cert errors (UnknownIssuer, BadEncoding/UnsupportedCertVersion with
broken chain, empty_explicit_ca, etc.) now return Err so rustls
aborts the handshake before any session is cached, preventing
same-policy resumption of a verifier-flagged session. Name-mismatch
errors are still deferred to JS checkServerIdentity. The precise
Node code is recorded in verify_error before the failure and
rustls_error_to_node_error prefers it over the generic CertificateError
mapping, so err.code stays compatible with test-tls-client-auth and
similar callers.
Fixes test-tls-client-reject{,-12} on the resume PR.
fibibot
left a comment
There was a problem hiding this comment.
NotValidForNamestill takes the JS-deferred path inverify_server_cert, so rustls sees that handshake as successful and can cache a resumable session beforeonConnectSecure()destroys it for hostname mismatch. On the next connection to the sameservername, nativeisSessionReused()can be true andonConnectSecure()skipscheckServerIdentity(), letting a previously rejected hostname mismatch connect. Either keepcheckServerIdentity()enabled for native resumed sessions, or prevent JS-rejected name-mismatch handshakes from entering the shared strict session cache.
The forged synthetic-session and rejectUnauthorized: false cache issues from the previous reviews are fixed on this head.
|
|
lunadogbot
left a comment
There was a problem hiding this comment.
record_or_fail(... strict_verify)now aborts strictUnknownIssuerhandshakes before the JSmakeVerifyError()mapping can turn the stored chain-structure code into Node’s message. CI showsnode_compat::internet::test-tls-add-ca-cert.jsnow gettingUnknownIssuerinstead ofself-signed certificate in certificate chain; preserve the Node/OpenSSL message on the strict-abort path, or use a no-cache path that still routes throughmakeVerifyError().
The earlier resume/session blockers are addressed on this head, but the node_compat 2/3 failures are from this TLS error mapping regression.
After making the verifier strict in rejectUnauthorized:true, the rustls_error_to_node_error path started emitting err.message = "invalid peer certificate: UnknownIssuer" instead of the OpenSSL-style "unable to get local issuer certificate". internet/test-tls-add-ca-cert and any callers pattern-matching on err.message broke as a result. Mirror the JS-side `makeVerifyError` lookup table on the Rust side so err.message matches the lenient/JS-deferred error wording for the common cert-verification codes, falling back to the rustls display when there's no Node-equivalent message.
Skipping the hostname check when isSessionReused() is true let a previously rejected NotValidForName handshake leak into a follow-up strict connection: the verifier defers name mismatches to JS so rustls caches the session before onConnectSecure() destroys the socket, and a resumed second connection then short-circuited the JS check and treated the cert as authoritative. Run checkServerIdentity() whenever the verifier reports no error, regardless of reuse state.
This updates the node TLS polyfill to better match Node client session behavior for TLS resume tests. - honor mutable `tls.DEFAULT_MIN_VERSION` / `tls.DEFAULT_MAX_VERSION` in client and server secure contexts - expose client session values and session events for TLS 1.2 and TLS 1.3 resume flows - enable `parallel/test-tls-client-resume.js` and `parallel/test-tls-client-resume-12.js` in node compat config
This updates the node TLS polyfill to better match Node client session behavior for TLS resume tests.
tls.DEFAULT_MIN_VERSION/tls.DEFAULT_MAX_VERSIONin client and server secure contextsparallel/test-tls-client-resume.jsandparallel/test-tls-client-resume-12.jsin node compat configVerified:
./x fmt./x build./x test-compat test-tls-client-resume.js./x test-compat test-tls-client-resume-12.js