【问题标题】:Node.js HTTPS configuration error - no common encryption algorithm(s)Node.js HTTPS 配置错误 - 没有通用加密算法
【发布时间】:2018-10-16 01:46:04
【问题描述】:

我见过其他类似的问题,但没有解决我的问题。我已经生成了我的 TLS (openSSL) 自签名证书,但似乎无法在我的 NodeJS 服务器上运行。

生成 SSL 的说明

openssl req -newkey rsa:2048 -keyout key.pem -x509 -days 365 -out certificate.pem

openssl x509 -text -noout -in certificate.pem

openssl pkcs12 -inkey key.pem -in certificate.pem -export -out certificate.p12

openssl pkcs12 -in certificate.p12 -noout -info  // verify certificate

所以最后我有.p12 也称为PFX 类型证书。下面是我的 Node.js 代码:

    // ------- Start HTTPS configuration ----------------

const options = {

    pfs: fs.readFileSync('./server/security-certificate/certificate.p12'),     
    passphrase: 'secrete2'
};
https.createServer(options, app).listen(8443);


    // -------- End HTTPS configuration -----------------

    // Also listen for HTTP 
var port = 8000;
app.listen(port, function(){
    console.log('running at localhost: '+port);
});

这是我运行curl 命令时的输出,HTTP 请求服务正确,只有 HTTPS 有问题:

此外,如果我这样做:

export CURL_CA_BUNDLE=/var/www/html/node_app/server/security-certificate/cert.p12

然后我收到以下错误: curl: (77) Problem with the SSL CA cert (path? access rights?)



如果我尝试使用 HTTPS 和端口在浏览器中访问,浏览器说它无法加载页面。

我关注的参考链接: Node.js HTTPS:

https://nodejs.org/dist/latest-v8.x/docs/api/https.html#https_https_createserver_options_requestlistener

我正在使用 AWS RedHat Linux

【问题讨论】:

标签: node.js https openssl self-signed rhel6


【解决方案1】:

目前还不知道上面贴出的与我的.p12捆绑证书相关的问题的解决方案(在我的Node.js配置中使用)。

但是我注意到,当我更改代码并尝试使用 .pem 证书时,它与 curl -k <MY-URL> 命令正常工作。

const options = {
    cert: fs.readFileSync('./server/security-certificate/cert.pem'),    
    key: fs.readFileSync('./server/security-certificate/key.pem'),      

    //pfs: fs.readFileSync('./server/security-certificate/cert.p12'),   // didn't work

    passphrase: 'secrete'
};

https.createServer(options, app).listen(8443);

如果有人知道更好的解决方案/答案,请发布。到目前为止,我不确定为什么 .p12 证书不起作用。是不是应该重命名为.pfx(有什么不同和效果)?

【讨论】:

    猜你喜欢
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 2012-10-26
    • 2021-04-28
    • 2014-04-07
    • 2015-07-17
    相关资源
    最近更新 更多