AMB*_*sra 6 heroku ssl-certificate node.js
我在heroku上有一个应用程序。我将它的版本从节点 6 升级到节点 12。在本地环境升级到 12 后,它开始出现以下错误。
Error: self signed certificate
Run Code Online (Sandbox Code Playgroud)
在本地环境中,我通过使用以下命令忽略了此错误。
NODE_TLS_REJECT_UNAUTHORIZED=0
Run Code Online (Sandbox Code Playgroud)
但这不是我在生产环境中的选择。我正在使用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)
Run Code Online (Sandbox Code Playgroud)
首先,此错误发生在出站连接上,而不是入站连接上。发生这种情况是因为我的节点团队在发布版本 12 时进行了代码更改。在版本 11 中一切都很好。让我分享一下详细信息。问题是 Node.js(不再?)默认发送 SNI 记录。您可以像这样解决它:
const options = {
port: 993,
host: 'imap.gmail.com',
servername: 'imap.gmail.com', // SNI
};
tls.connect(options, () => { /* ... */ });
Run Code Online (Sandbox Code Playgroud)
除非您传递 -servername imap.gmail.com,否则它不会验证。
(GMail 会发回带有颁发者的证书:OU =“未提供 SNI;请修复您的客户端。”,CN = invalid2.invalid ^^)
上述信息来源 https://github.com/nodejs/node/issues/28167
注意:除了 Node.js 之外,OpenSSL 没有任何变化。
Node 团队已为此添加了警告。 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()`][]:
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
339 次 |
| 最近记录: |