Node.js 10 HTTPS服务器拒绝连接

m1c*_*4ls 14 ssl https curl openssl node.js

我有简单的Node.js HTTPS服务器

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

const config = {
  key: fs.readFileSync('cert/server-key.pem'),
  cert: fs.readFileSync('cert/server-crt.pem'),
  ca: fs.readFileSync('cert/ca-crt.pem'),
};

const server = https.createServer(config, ((req, res) => {
  console.log('Got request');

  res.end();
}));

server.listen(3333);
Run Code Online (Sandbox Code Playgroud)

curl在嵌入式系统上使用.

# curl -V
curl 7.52.1 (arm-unknown-linux-gnu) libcurl/7.52.1 wolfSSL/3.9.8
Protocols: file ftp ftps http https smtp smtps telnet tftp 
Features: IPv6 Largefile SSL UnixSockets  
Run Code Online (Sandbox Code Playgroud)

当我使用其他版本10的Node.js时 - 一切都运行良好.

Node.js v8.2.1上运行的HTTPS服务器

# curl -k -v "https://10.43.11.128:3333/"
*   Trying 10.43.11.128...
* TCP_NODELAY set
* Connected to 10.43.11.128 (10.43.11.128) port 3333 (#0)
* SSL connected
> GET / HTTP/1.1
> Host: 10.43.11.128:3333
> User-Agent: curl/7.52.1
> Accept: */*
Run Code Online (Sandbox Code Playgroud)

Node.js v10.1.0上运行的HTTPS服务器

# curl -k -v "https://10.43.11.128:3333/"
*   Trying 10.43.11.128...
* TCP_NODELAY set
* Connected to 10.43.11.128 (10.43.11.128) port 3333 (#0)
* SSL_connect failed with error -313: revcd alert fatal error
* Curl_http_done: called premature == 1
* Closing connection 0
curl: (35) SSL_connect failed with error -313: revcd alert fatal error
Run Code Online (Sandbox Code Playgroud)

有关HTTPS的Node.js 10有哪些变化?我怀疑我必须更改SSL设置,但我确定如何.


更新:

试图访问HTTP(Node.js v10.1.0)

# curl --insecure -v "10.43.11.128:3333/"
*   Trying 10.43.11.128...
* TCP_NODELAY set
* Connected to 10.43.11.128 (10.43.11.128) port 3333 (#0)
> GET / HTTP/1.1
> Host: 10.43.11.128:3333
> User-Agent: curl/7.52.1
> Accept: */*
> 
* Curl_http_done: called premature == 0
* Empty reply from server
* Connection #0 to host 10.43.11.128 left intact
curl: (52) Empty reply from server
Run Code Online (Sandbox Code Playgroud)

Wireshark捕获了pcap文件.

thi*_*_vm 0

验证curl 发送哪些标头,您可以使用 -v 参数。

卷曲-vIX“ https://10.43.11.128:3333/

也在节点中,

只需在 req.end() 之后使用 console.log(req._headers) 并比较您的标头以进一步解决问题。我还请求尝试使用wireshark(http://www.wireshark.org/)进行ssl连接测试。

因为它是通过 --insecure 工作的,但你需要知道原因。

--不安全

  • (SSL) 此选项明确允许curl 执行“不安全”的SSL 连接和传输。尝试使用默认安装的 CA 证书包来确保所有 SSL 连接的安全。这会使所有被视为“不安全”的连接失败,除非使用 -k, --insecure。

你也可以试试这个吗

const https = require("https"),
  fs = require("fs");

const options = {
  key: fs.readFileSync("/cert/server-key.pem"),
  cert: fs.readFileSync("/cert/server-cert.pem")
};

const app = express();

app.use((req, res) => {
  res.writeHead(200);
  res.end("hello world\n");
});

app.listen(8000);

https.createServer(options, app).listen(8080);
Run Code Online (Sandbox Code Playgroud)