Skip to content

Emission of secure events changed across versions of node #29421

@tufosa

Description

@tufosa

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.docIssues and PRs related to the documentations.tlsIssues and PRs related to the tls subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions