错误:Heroku上的自签名证书节点12应用程序

时间:2020-10-06 11:59:33

标签: node.js heroku ssl-certificate

我在heroku上有一个应用程序。我将其版本从节点6升级到了节点12。 在本地环境上升级到12后,开始出现跟踪错误。

Error: self signed certificate

在本地环境中,我通过使用以下命令忽略了此错误。

NODE_TLS_REJECT_UNAUTHORIZED=0

但这不是我在生产环境上的选择。 我正在使用 heroku自动证书管理来满足我的SSL需求,并且在Node版本12上运行良好。

理想情况下,它不会出现该错误,因为在生产服务器上,我通过使用 heroku自动证书管理

进行了正确的证书设置

我的证书有效,但是我在日志中看到自签名证书错误。 感谢您的帮助。

错误的堆栈跟踪如下。

Error: self signed certificate (Most recent call first)
at TLSSocket.onConnectSecure (_tls_wrap.js line 1501 col 33)
at TLSSocket.emit (events.js line 315 col 19)
at TLSSocket.EventEmitter.emit (domain.js line 483 col 11)
at TLSSocket._finishInit (_tls_wrap.js line 936 col 7)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js line 710 col 11)
at Socket.ondata (internal/js_stream_socket.js line 72 col 21)
at Socket.emit (events.js line 315 col 19)
at Socket.EventEmitter.emit (domain.js line 483 col 11)
at addChunk (_stream_readable.js line 295 col 11)
at readableAddChunk (_stream_readable.js line 271 col 8)

1 个答案:

答案 0 :(得分:2)

首先,此错误发生在出站连接而不是入站连接上。 由于代码更改使我的节点团队在发布版本12时发生了这种情况。 在版本11中很好。让我分享细节。 问题是Node.js(不再?)默认发送SNI记录。您可以像这样解决它:

const options = {
  port: 993,
  host: 'imap.gmail.com',
  servername: 'imap.gmail.com',  // SNI
};
tls.connect(options, () => { /* ... */ });

除非您通过-servername imap.gmail.com,否则它将无法验证。

(GMail很有帮助地向发卡行发送了证书:OU =“未提供SNI;请修复您的客户端。”,CN = invalid2.invalid ^^)

以上信息的来源 https://github.com/nodejs/node/issues/28167

注意:在OpenSSL中,节点上什么都没有改变。

节点团队为此添加了警告。 https://github.com/nodejs/node/commit/b8ea47162d84ade96698cb45a0de5c0dd9959251

`tls.connect()` returns a [`tls.TLSSocket`][] object.

Unlike the `https` API, `tls.connect()` does not enable the
SNI (Server Name Indication) extension by default, which may cause some
servers to return an incorrect certificate or reject the connection
altogether. To enable SNI, set the `servername` option in addition
to `host`.

The following illustrates a client for the echo server example from
[`tls.createServer()`][]: