I am trying to use self signed certificate of badssl.com through requestjs. I used node-ssl-root-cas to inject certificates
Here is the code & I am getting error all the time.
var request = require('request');
var fs = require('fs');
var path = require('path');
var buffer = fs.readFileSync('bad.crt');
request.get({
url: 'https://self-signed.badssl.com/',
agentOptions:{
ca :buffer
}
},function responseHandle(error, response, body){
console.log(error);
});
I tried modifying the root array of ssl-root-cas like this
var request = require('request');
var fs = require('fs');
var path = require('path');
var buffer = fs.readFileSync('bad.crt');
var cas = require('ssl-root-cas');
cas.push(buffer);
cas.inject();
request.get({
url: 'https://self-signed.badssl.com/'
},function responseHandle(error, response, body){
console.log(error);
});
In both the cases I am getting following error
{ [Error: unable to verify the first certificate] code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }
Is there no way to use self signed certificates with node js?