node.js - mac 使用带有 ssl 证书的 Node 验证失败

标签 node.js ssl https pfx

正如 Node api 文档中所指定的,我尝试了第一个使用 openssl 自行创建和签名的证书。一切都很好,除了无法从android测试客户端,因为它需要一个ca证书。当我尝试第二种方法(使用 pfx 而不是使用 key 、证书)时,https.createserver 会引发错误

crypto.js:145
      c.context.loadPKCS12(pfx);
                ^
Error: mac verify failure
    at Object.exports.createCredentials (crypto.js:145:17)
    at Server (tls.js:1130:28)
    at new Server (https.js:35:14)
    at Object.exports.createServer (https.js:54:10)
    at Object.<anonymous> (C:\iTollonServer\iTollonServer\iTollonServer\app.js:105:7)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

来自 Node Api 的代码:

// curl -k https://localhost:8000/
var https = require('https');
var fs = require('fs');

var options = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};

https.createServer(options, function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8000);
Or

var https = require('https');
var fs = require('fs');

var options = {
  pfx: fs.readFileSync('server.pfx')
};

https.createServer(options, function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8000);

最佳答案

在 pfx 情况下,您应该添加选项

passphrase: 'password'

关于node.js - mac 使用带有 ssl 证书的 Node 验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22859121/

相关文章:

javascript - 我通过 SocketIO 事件实时收集大量数据。我应该为每个 SocketIO 事件验证 JWT token 吗?

c# - 如何为 IIS 创建自己的证书颁发机构?

ios - 通过 https 的 React-native 加载图像有效,而 http 无效

node.js - Node.js post 请求中的套接字挂起错误

web-services - 如果使用安全网络服务,我是否需要 SSL 证书?

javascript - 很难理解 Javascript 中的 "Probably Equals"

javascript - 使用 Async.parallel 我的参数的生命周期不会超过使用 MongoDB 的 NodeJS 中的异步调用

go - 使用 Go 后端的 net::ERR_CERT_INVALID

java - Tomcat 7 的 CA 证书安装过程

json - 我没有从 Amazon Lambda 获得适当的 JSON 响应