繁体   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