【问题标题】:Server aborted the SSL handshake error服务器中止 SSL 握手错误
【发布时间】:2015-11-18 05:15:10
【问题描述】:

我无法让服务器在 HTTPS 工作 node.js 之后运行。我的目标是让 Hapi 服务器使用自签名证书运行。

这就是我生成自签名证书的方式:

openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
rm csr.pem

这就是我在 Hapi 中启动服务器的方式:

server.connection({
    port: 9920,
    tls: {
        key: fs.readFileSync(path.resolve(__dirname, './cert/key.pem')),
        cert: fs.readFileSync(path.resolve(__dirname, './cert/cert.pem')),
        rejectUnauthorized: false
    },
    routes: {
        cors: true
    }
 });

为了验证这不是 Hapi 唯一的问题,我验证这在 vanilla node.js 中也不起作用:

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

var options = {
  key: fs.readFileSync(path.resolve(__dirname, './cert/key.pem')), 
  cert: fs.readFileSync(path.resolve(__dirname, './cert/cert.pem')),
  rejectUnauthorized: false
};

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

这两个服务器都在 curl 中抛出相同的错误:

$ curl -kiv https://localhost:9920
* Rebuilt URL to: https://localhost:9920/
*   Trying ::1...
* connect to ::1 port 9920 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9920 (#0)
* Server aborted the SSL handshake
* Closing connection 0
curl: (35) Server aborted the SSL handshake

版本:

  • 节点:v4.1.1
  • npm: 3.4.0

发生了什么事?

【问题讨论】:

  • 如果服务器中止握手,您需要查看服务器端的错误,而不是客户端。

标签: node.js ssl hapijs


【解决方案1】:

不是 ssl 方面的专家,因为使用的不多,但如果您检查此代码,选项集与您配置的不同。

https://github.com/hapijs/university/blob/master/lib/config.js#L6

可能没有正确创建密钥和证书,请检查这些文档以确保您正确使用方法hapi & node

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-27
    • 2016-10-31
    • 2017-02-11
    • 2016-03-02
    • 1970-01-01
    • 1970-01-01
    • 2012-09-03
    相关资源
    最近更新 更多