-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Description
- Version: v8.16.1, v10.16.3, v12.8.1
- Platform: Linux tufopad 4.15.0-58-generic transform streams: unpipe or ignore future writes after .push(null) #64-Ubuntu SMP Tue Aug 6 11:12:41 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
- Subsystem: tls
It seems to be a bit of discordance in the emission of the secure event across versions of node and also if you use the deprecated createSecurePair vs new tls.TLSSocket.
Steps to reproduce
First, you'll need to clone this repo containing the sample code.
This program starts a tls.Server, and then two clients, one using the deprecated createSecurePair and the other using tls.TLSSocket. It just opens the connections and wait for the different events to trigger. Each event leaves a trace. It reproduces 2 cases per client (4 in total): one just opening the connection (write: false) and the other opening the connection and immediately writing an empty string to the socket (write: true). Therefore the 4 cases are:
- SecurePair-write-false
- SecurePair-write-true
- TLSSocket-write-false
- TLSSocket-write-true
In order to reproduce the bug, run node main.js using different versions of nodejs and observe the differences in behaviour through the traces left by the program. It seems like both the secure and secureConnection events are emitted with different criteria depending on the version of node used.
I undestand that createSecurePair is deprecated and therefore should not be used, but I believe that the new way of doing things (tls.TLSSocket) should have the same behaviour as the old createSecurePair in order to make the transition easier. It seems reasonable to wait for the secure event before attempting to write anything. This is how the old createSecurePair behaved in node v8.16.1, but this behaviour has been changed in node 10 and node 12.
Also the documented secureConnect event is never emitted. An undocumented secure event is emitted instead. I see that this has been reported before (at least here and here), but the docs haven't been fixed.
node v8.16.1
Creating SecurePair write false client...
(node:31271) [DEP0064] DeprecationWarning: tls.createSecurePair() is deprecated. Please use tls.TLSSocket instead.
secureConnection
secure
Creating TLSSocket write false client...
ERROR: TLSSocket with write false did NOT receive secure event
Creating SecurePair write true client...
secureConnection
secure
Creating TLSSocket write true client...
secureConnection
secure
Finished
The only case not emitting any event is TLSSocket-write-false.
node v10.16.3
Creating SecurePair write false client...
(node:31533) [DEP0064] DeprecationWarning: tls.createSecurePair() is deprecated. Please use tls.TLSSocket instead.
ERROR: SecurePair with write false did NOT receive secure event
Creating TLSSocket write false client...
ERROR: TLSSocket with write false did NOT receive secure event
Creating SecurePair write true client...
secureConnection
secure
Creating TLSSocket write true client...
secureConnection
secure
Finished
All write-false cases fail (as in do not emit events) and all write-true cases
pass.
node v12.8.1
Creating SecurePair write false client...
(node:31828) [DEP0064] DeprecationWarning: tls.createSecurePair() is deprecated. Please use tls.TLSSocket instead.
ERROR: SecurePair with write false did NOT receive secure event
Creating TLSSocket write false client...
ERROR: TLSSocket with write false did NOT receive secure event
Creating SecurePair write true client...
secure
Creating TLSSocket write true client...
secureConnection
secure
Finished
All write-false cases fail and the write-true cases behave slightly different,
as one of them (SecurePair-write-true) never emit the secureConnection event.