Hrishikesh Bawane
Hrishikesh Bawane

Reputation: 199

How to force nodejs socket.io client use TLSv1.2?

I have a nodejs socket.io client that uses TLSv1.3 by default when trying to connect to the server. I want to disable TLSv1.3 (or force the client to use TLSv1.2 specifically). The client snippet for connection:

const socket = io.connect("wss://test.mydomain.com", {
    path: "/persistent-connection",
    transports: ["websocket", "polling"]
});

I have searched through the socket.io documentation but could not find something like setting secureProtocol:"TLSv1_2_method" in the client options. Any idea as to how this can be achieved? Any pointers are welcome.

Upvotes: 1

Views: 1098

Answers (1)

Sandeep Patel
Sandeep Patel

Reputation: 5148

If you are using Nodejs 10.x or above you can use NODE_OPTIONS=--tls-max-v1.2 CLI option to configure TLS version or in code you can do as below:

const tls = require('tls');

tls.DEFAULT_MAX_VERSION = 'TLSv1.2';

Upvotes: 3

Related Questions