Uh oh!
There was an error while loading. Please reload this page.
tls: fix bugs of double TLS - #48796
Conversation
Fixs two issues in `TLSWrap`, one of them is reported in nodejs#30896. 1. `TLSWrap` has exactly one `StreamListener`, however, that `StreamListener` can be replaced. We have not been rigorous enough here: if an active write has not been finished before the transition, the finish callback of it will be wrongly fired the successor `StreamListener`. 2. A `TLSWrap` does not allow more than one active write, as checked in the assertion about current_write in `TLSWrap::DoWrite()`. However, when users make use of an existing `tls.TLSSocket` to establish double TLS, by either tls.connect({socket: tlssock}) or tlsServer.emit('connection', tlssock) we have both of the user provided `tls.TLSSocket`, tlssock and a brand new created `TLSWrap` writing to the `TLSWrap` bound to tlssock, which easily violates the constranint because two writers have no idea of each other. The design of the fix is: when a `TLSWrap` is created on top of a user provided socket, do not send any data to the socket until all existing writes of the socket are done and ensure registered callbacks of those writes can be fired.
nodejs-github-bot
commented
Jul 16, 2023
Review requested:
|
Format code.
nodejs-github-bot
commented
Jul 16, 2023
Uh oh!
There was an error while loading. Please reload this page.
Remove unnecessary saving of `this` for arrow function.
Uh oh!
There was an error while loading. Please reload this page.
ywave620
commented
Jul 18, 2023
leftover processes found in the github hooked CI But it seems like these failures have nothing to do with this PR. Could somebody rerun the CI? |
ywave620
commented
Jul 20, 2023
cc @nodejs/crypto |
nodejs-github-bot
commented
Jul 20, 2023
nodejs-github-bot
commented
Jul 21, 2023
nodejs-github-bot
commented
Jul 23, 2023
nodejs-github-bot
commented
Jul 25, 2023
| StreamBase* stream, | ||
| SecureContext* sc); | ||
| SecureContext* sc, | ||
| bool stream_has_active_write); |
There was a problem hiding this comment.
Non-blocking nit: I'm generally not a fan of bool arguments to methods, largely because just seeing the true or false a the callsite tends not to be descriptive enough to let folks know what the impact is. I certainly won't block this change because of it, but I'd prefer a enum arg here instead.
mhdawson
commented
Jul 28, 2023
Landed in 662fe0be9d8e |
mhdawson
commented
Jul 28, 2023
ywave620
commented
Jul 29, 2023
ywave620
commented
Jul 30, 2023
mhdawson
commented
Aug 2, 2023
@ywave620 many thanks |
Fixs two issues in
TLSWrap, one of them is reported in #30896 (a 3 years log bug ...).TLSWraphas exactly oneStreamListener, however, thatStreamListenercan be replaced. We have not been rigorous enough here: if an active write has not been finished before the transition, the finish callback of it will be wrongly fired the successorStreamListener.A
TLSWrapdoes not allow more than one active write, as checked in the assertion about current_write inTLSWrap::DoWrite().However, when users make use of an existing
tls.TLSSocketto establish double TLS, byeither
or
we have both of the user provided
tls.TLSSocket, tlssock and a brand new createdTLSWrapwriting to theTLSWrapbound to tlssock, which easily violates the constranint because two writers have no idea of each other.The design of the fix is:
when a
TLSWrapis created on top of a user provided socket, do not send any data to the socket until all existing writes of the socket are done and ensure registered callbacks of those writes can be fired.