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.
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.
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.
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
}, ...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With