Reputation: 115
I'd like to ask for your lights on the below: Using nodeJS, I'm trying to establish https connection between my server, which acts as a client in this case and an external server. We want to use client certificate validation, and the external server has provided self-signed private.key and client.crt certificate. My code is the below:
router.get('/mywebhook', function (req, res) {
console.log('/mywebhook');
var request = require("request");
//var options;
var options = { method: 'GET',
url: 'https://externalserverURL'
,cert: fs.readFileSync('certs/client_crt.pem')
,key: fs.readFileSync('certs/key.pem')
}
request(options, function (error, response, body) {
if (error){
//throw new Error(error);
console.log(error);
return res.end(error);
}
console.log('all ok')
return res.end(body);
});
});
I am getting though, the below error: Error: self signed certificate code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
Setting sst-strict = false is something I want to avoid. Am I missing something? Any help?
Upvotes: 1
Views: 2177
Reputation: 2787
You may either add extra root certificates to your server or you may do Node spesific configuration with environment variable.
env NODE_EXTRA_CA_CERTS=./rootCA.crt node client.js
Upvotes: 2