I get the above error when I try to connect to a webserver with a node.js client I am writing at te moment.
But I get an error when I try to connect to the server.
'DEPTH_ZERO_SELF_SIGNED_CERT'
This is the code that sends the request. And turning off the certificate check is not a valid option. I need the connection to be secured.
var options =
{
hostname: baseUri,
port: 443,
path: 'oauth',
method: 'POST',
requestCert: true,
ca:fs.readFileSync('Comodo_PositiveSSL_bundle.crt'),
rejectUnauthorized: true,
headers: {
//'User-Agent': USER_AGENT,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': data.length
}
};
var req = http.request(options, (res) => {
console.log('statusCode: ', res.statusCode);
console.log('headers: ', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
});
req.write(data)
req.end();
req.on('error', (e) => {
console.error(e);
});
If someone can tell me how I can setup the certification correct so no error is generated?
Picture of the cert bundle. As you can see the bundle contains only the root certificates need to verify the certificate the server provides itself.
This solution is not related to the posted question but for error code of DEPTH_ZERO_SELF_SIGNED_CERT.
Below code throws the same error code
const https = require('https');
https.get('https://10.20.30.40:1234/v1/objects/storages', (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
}).on('error', (e) => {
console.error(e);
});
To solve the problem we have to apply process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
in https.get(). Kindly look at the problem fixed code in below lines.
const https = require('https');
https.get('https://10.20.30.40:1234/v1/objects/storages',
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0", (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
}).on('error', (e) => {
console.error(e);
});
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