Repository navigation
tls: fix newSession after destroy and OCSP cert - #67650
Open
ShogunPanda wants to merge 1 commit into
Open
ShogunPanda wants to merge 1 commit into
ShogunPanda wants to merge 1 commit into
Conversation
The callback of the `newSession` event only checked that the handle was still set. If a TLS error destroyed the socket while the callback was pending, calling it afterwards still completed the handshake and emitted `'secure'` and `'secureConnection'` on the destroyed socket. Return early from it if the socket is already destroyed. The callbacks of `OCSPRequest`, `SNICallback` and `resumeSession` do not need the same check: the handshake does not read while they are pending, so a TLS error cannot destroy the socket in the meantime, and if the socket is closed some other way the existing `_handle` checks already cover it. Also, when the `SNICallback` returns a context that has no certificate, for example one that only provides CAs, the handshake uses the certificate of the server. The `OCSPRequest` event was still emitted with the certificate and the issuer of that context, which are both `null`. Use the context of the server in that case, so that the event reports the certificate that is actually in use. Assisted-By: OpenAI GPT-5.6 Sol <openai/gpt-5.6-sol> Signed-off-by: Paolo Insogna <paolo@cowtech.it>
Collaborator
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67650 +/- ##
==========================================
+ Coverage 90.71% 90.73% +0.01%
==========================================
Files 801 801
Lines 280906 280915 +9
Branches 54249 54266 +17
==========================================
+ Hits 254832 254883 +51
+ Misses 16246 16197 -49
- Partials 9828 9835 +7
🚀 New features to boost your workflow:
|
Collaborator
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.
Two small fixes in
lib/internal/tls/wrap.js.The callback of the
newSessionevent only checked that the handle was still set. If a TLS error destroyed the socket while the callback was pending, calling it afterwards still completed the handshake and emitted'secure'and'secureConnection'on the destroyed socket. It now returns early if the socket is already destroyed. The callbacks ofOCSPRequest,SNICallbackandresumeSessiondo not need the same check: the handshake does not read while they are pending, so a TLS error cannot destroy the socket in the meantime, and the existing_handlechecks cover the other ways of closing it.When the
SNICallbackreturns a context that has no certificate, for example one that only provides CAs, the handshake uses the certificate of the server. TheOCSPRequestevent was still emitted with the certificate and the issuer of that context, which are bothnull. It now uses the context of the server in that case, so that the event reports the certificate that is actually in use.Testing: added
test-tls-handshake-complete-after-destroy-newsession.jsandtest-tls-ocsp-request-sni-without-certificate.js; both fail without the change. Theparallel/test-tls-*andparallel/test-https-*suites and eslint pass.