1

I am using node version 8.9.1 and wwant to know which version of TLS does it use by default.

I tried googling and looked at the node js documentation but could not find the answer

Anil Kumar R
  • 283
  • 1
  • 4
  • 12
  • You can check `openssl` version with `node -p process.versions | grep openssl` [ref](https://github.com/nodejs/node/issues/20248) – Gabriel Bleu Sep 24 '18 at 12:01
  • when i run that command it shows openssl version as 1.0.21. What should i conclude from this @GabrielBleu – Anil Kumar R Sep 24 '18 at 14:17

1 Answers1

4

You can generate a self signed certificate with :

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes

It will create key.pem and cert.pem files in current directory, you can then start a server with :

const tls = require('tls');
const fs = require('fs');

const options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

const server = tls.createServer(options, (socket) => {
  console.log('server connected',
          socket.authorized ? 'authorized' : 'unauthorized', socket.getProtocol());
  socket.write('welcome!\n');
  socket.setEncoding('utf8');
  socket.pipe(socket);
});
server.listen(8000, () => {
  console.log('server bound');
});

and connect to it using openssl s_client :

openssl s_client -connect 127.0.0.1:8000

Testing on node v8.11.3 will output :

server bound
server connected unauthorized TLSv1.2

ref :

Gabriel Bleu
  • 9,703
  • 2
  • 30
  • 43