簡體   English   中英

LetsEncrypt 根證書過期中斷 Azure Function 節點應用

[英]LetsEncrypt root certificate expiry breaks Azure Function Node application

我有一個運行為 Azure function 的節點應用程序。每 60 秒它會進行一次 web api 調用,web api 之一的 SSL 證書由 LetsEncrypt (R3) 簽名。

2021 年 9 月 30 日,根證書到期。 https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021/

現在 function 無法調用 API。(請參閱下面的錯誤)。

錯在哪里?

  • 是NodeJS本身的錯嗎? 它是否內置了自己的一組根證書?
  • 或者是 Azure 的故障? 運行它的服務器是否應該設置正確的根證書集?
  • 還是我應該做點什么?

我嘗試在我自己的機器上運行類似的代碼並遇到類似的問題,即使在從 Windows 證書存儲中刪除所有過期的證書之后也是如此。

這是在 Azure Function 應用程序中拋出的錯誤:

Result: Failure Exception: AggregateError: RequestError: certificate has expired 
at ClientRequest.<anonymous> (C:/home/site/wwwroot/node_modules/got/dist/source/core/index.js:953:111) 
at ClientRequest.origin.emit (C:/home/site/wwwroot/node_modules/@szmarczak/http-timer/dist/source/index.js:39:20) RequestError: certificate has expired 
at ClientRequest.<anonymous> (C:/home/site/wwwroot/node_modules/got/dist/source/core/index.js:953:111) 
at ClientRequest.origin.emit (C:/home/site/wwwroot/node_modules/@szmarczak/http-timer/dist/source/index.js:39:20) Stack: AggregateError: RequestError: certificate has expired at ClientRequest.<anonymous>

真正的觸發因素是我的第一個電話

import { Issuer } from 'openid-client';

// ...

// This line of code throws the exception
const laqorrIssuer = await Issuer.discover(clientMetaData.laqorr_api_base);

如果您需要讓您的 Node 應用程序緊急運行,只需在開頭添加這行代碼即可。

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

這將完全禁用證書驗證。 顯然,這不是一個可以接受的長期解決方案。


最終解決問題的方法是重新啟動與 Node 應用程序通信的 Windows web 服務器。 我認為我不需要這樣做,因為我的 Chrome 瀏覽器可以毫無問題地查詢相同的服務器。 Node 和 Chrome 瀏覽器之間肯定有一些區別。 重新啟動客戶端正在與之通信的服務器的行為足以解決這種差異。

這是我在四處摸索時想出的更多信息。

讓加密

Lets Encrypt 最初使用特定證書作為根證書頒發機構: DST Root CA X3 它的有效范圍是從 2000-10-01 到 2021-10-01。 它不再有效。

Lets Encrypt 現在使用ISRG Root X1作為根證書頒發機構。 它的有效日期范圍為 2015-06-04 到 2035-06-04。 如果一個平台不承認這個根證書頒發機構,它就不會信任 Lets Encrypt。

節點

更新操作系統中的證書存儲不會對 NodeJS 平台產生影響。

Node 使用硬編碼的證書頒發機構列表,定義在node_root_certs.h中。 (有關詳細信息,請參閱此自述文件)。

最新的證書ISRG Root X1自版本8.0.0以來一直是 Node 的一部分。 (請參閱此提交)。


最后,如果您想編寫一個微型節點應用程序來測試 web 請求是否有效:這是一個。
 const got = require('got'); (async () => { try { // Change this to the url you want to test const url = 'https://letsencrpt.org'; console.log(`Reading from ${url}`); const response = await got(url); console.log(response.body); } catch (error) { console.log(`error: ${error}`); if(error.response) { console.log(error.response.body); } } })();

暫無
暫無

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

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