0

我正在尝试通过 requestjs 使用 badssl.com 的自签名证书。我使用 node-ssl-root-cas 注入证书

这是代码,我一直在出错。

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);
});

我尝试像这样修改 ssl-root-cas 的根数组

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);
});

在这两种情况下,我都会遇到以下错误

{ [Error: unable to verify the first certificate] code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }

有没有办法在节点 js 中使用自签名证书?

4

0 回答 0