0

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?

Arpit
  • 190
  • 1
  • 4
  • 15
  • any resolution this issue, i too stuck with the same and was referencing this module https://www.npmjs.com/package/ssl-root-cas but cannpt resolve the LEAF SIGNATURE error. I'm making a post request call to an end point with proper headers and i get this error when executing that request. – Sai May 02 '16 at 15:11
  • No, I do not get any resolution to this yet. I had to use rejectUnauthorized flag which basically disables all checks of certificate validity for node js. – Arpit May 03 '16 at 08:49
  • Ok, i use the same (process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';) in my code. But it looks like definitely not a good idea. – Sai May 03 '16 at 13:35
  • I used the same. It's not a good idea. It's like going non SSL for self signed certificate. – Arpit May 04 '16 at 04:18

0 Answers0