Node - TLS version logging for outbound connections?

I would like to register which versions of TLS use my Node application, if possible, without changing any code.

I tried both NODE_DEBUG=tls,http, and DEBUG=*which, of course, added a lot of information to the logs, but did not say anything about the versions of TLS used.

Is it possible?

+4
source share
1 answer

I am not sure that I am not changing the code, but you can do it this way:

const tls = require('tls');

const url = 'someurl';
console.log('Connecting..');

const socket = tls.connect(443, url, () => {
  console.log('Tls.connect', socket.authorized ? 'authorized' : 'unauthorized');  
  console.log('Cipher: ' + JSON.stringify(socket.getCipher()));
  console.log('Protocol: ' + JSON.stringify(socket.getProtocol()));
});

This will produce the result as follows:

Listening...
Connecting..
Tls.connect authorized
Cipher: {"name":"ECDHE-RSA-AES128-GCM-SHA256","version":"TLSv1/SSLv3"}
Protocol: "TLSv1.2"
+1
source

Source: https://habr.com/ru/post/1692991/


All Articles