簡體   English   中英

錯誤:Heroku 上的自簽名證書 Node 12 應用程序

[英]Error: self signed certificate Node 12 app on Heroku

我在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)

首先,此錯誤發生在出站連接上,而不是入站連接上。 它發生是因為我的節點團隊在發布版本 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 中沒有任何變化,但在 node.js 中沒有任何變化。

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()`][]:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM