Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM request - Get TLS version

Tags:

node.js

tls1.2

In node i'm using npm module "request" : https://www.npmjs.com/package/request

I want to know how i can retrieve from response the TLS version used, TLS1.0, TLS1.1, TLS1.2.

var request = require("request");

request.get({url: "https://www.google.com/"}, function(err, response, body) {

     console.log(response.req.connection._tlsOptions); // ??
     process.exit(0);

});

One of our provider will soon manage only TLS1.2 and i want to know which version is used now in order to know if i have to specify secureProtocol: "TLSv1_2_method" for this provider.

like image 459
Daphoque Avatar asked Oct 20 '25 13:10

Daphoque


2 Answers

require('request').get("https://www.google.com/").on('response',
  (response) =>
    console.log(response.socket.getProtocol())
  ); ""

tlsSocket.getProtocol() can not be used in callback as connection is closed by then, and TLS connection metadata is no longer available.

https://nodejs.org/api/tls.html#tls_class_tls_tlssocket

Methods that return TLS connection metadata (e.g. tls.TLSSocket.getPeerCertificate() will only return data while the connection is open.

like image 71
Sunil Mohan Ranta Avatar answered Oct 22 '25 02:10

Sunil Mohan Ranta


You can send a request to howsmyssl.com

var allData = ''
require('request')({
    uri: 'https://howsmyssl.com/a/check'
}).on('data', function(data) {
    allData += data.toString()
}).on('end', function() {
    console.log(JSON.parse(allData).tls_version)
})
like image 20
ZECTBynmo Avatar answered Oct 22 '25 03:10

ZECTBynmo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!