[英]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。(請參閱下面的錯誤)。
錯在哪里?
我嘗試在我自己的機器上運行類似的代碼並遇到類似的問題,即使在從 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'
這將完全禁用證書驗證。 顯然,這不是一個可以接受的長期解決方案。
這是我在四處摸索時想出的更多信息。
讓加密
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 的一部分。 (請參閱此提交)。
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.