NodeJS无法读取ubuntu中的默认CA.

vik*_*kov 6 ssl certificate ca node.js

在我们的测试环境中,我们使用我们公司签署的SSL连接到另一台服务器.每次建立连接时,nodejs都会抛出 UNABLE_TO_VERIFY_LEAF_SIGNATURE.我通过设置rejectUnauthorized:false找到了变通方法,但在我们的例子中这不是适用的.

证书将添加到/ etc/ssl/certs,并使用环境变量SSL_CERT_DIR进行测试,使其成为/ etc/ssl/ etc/ssl/certs,但没有结果.

此外,最好在我们的文件中添加证书并将其添加到每个请求中.

jos*_*736 5

这是因为节点不使用您系统的CA配置;因此,请参见图9。它包括其自己的内置可接受CA列表

如果希望节点SSL客户端接受自定义CA,则必须在ca选项中传递CA的证书。

// do something like this when your app starts up:
fs.readFile('/path/to/ca.pem', function(err, cert) {
    if (err) ...
    else certBuffer = cert;
});

// then when you make requests...
https.request({
    hostname: 'example.com',
    port: 443,
    path: '/',
    method: 'GET',
    ca: certBuffer
}, ...);
Run Code Online (Sandbox Code Playgroud)