Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS unable to read default CAs in ubuntu

On our testing environment we are connecting to another server with SSL signed by our company. Every time connection is made nodejs throws UNABLE_TO_VERIFY_LEAF_SIGNATURE. I have found workarounds by setting rejectUnauthorized: false, but this is not aplicable in our case.

The certificates are added to /etc/ssl/certs and tested with the environment variable SSL_CERT_DIR to be either /etc/ssl anb /etc/ssl/certs, but no result.

Also, it is not preferable to add somewhere in our files the certificate and add it to every request.

like image 905
viktorstaikov Avatar asked Dec 18 '13 12:12

viktorstaikov


People also ask

How do I run node js code in Ubuntu?

js and NPM(Node Package Manager) using “sudo apt install nodejs” and “sudo apt install npm” commands respectively. After installation, create a file with the “. js” extension, write Node. js code in it, and execute the file using the “node filename” command.

Does Nodejs use OpenSSL?

js website, Node. js 18 improves security with support for the OpenSSL 3.0 cryptography library, which includes open source implementations of SSL and TLS protocols for securing communications across networks.


1 Answers

This is because node does not use your system's CA configuration; it includes its own built-in list of acceptable CAs.

If you want a node SSL client to accept a custom CA, you have to pass the CA's certificate in the ca option.

// do something like this when your app starts up:
fs.readFile('/path/to/ca.pem', function(err, cert) {
    if (err) ...
    else certBuffer = cert;
});

// then when you make requests...
https.request({
    hostname: 'example.com',
    port: 443,
    path: '/',
    method: 'GET',
    ca: certBuffer
}, ...);
like image 103
josh3736 Avatar answered Sep 27 '22 20:09

josh3736