LetsEncrypt 根证书过期会破坏 Azure Function Node 应用程序

2023-12-12

我有一个作为 Azure 函数运行的节点应用程序。 每 60 秒它会进行多次 Web API 调用,其中一个 Web API 的 SSL 证书由 LetsEncrypt (R3) 签名。

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

现在该函数无法调用 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'

这将完全禁用证书验证。显然,这不是一个可以接受的长期解决方案。


The thing that ultimately solved the problem was restarting the Windows web servers the Node app was communicating with. I didn't think I would need to do this because my Chrome browser could query the same servers with no problems. There must be some difference between Node and the Chrome Browser. The act of restarting the servers the clients were talking to was enough to get around this difference.

这是我在摸索时想到的更多信息。

让我们加密

Lets Encrypt 最初使用特定的证书作为根证书颁发机构:DST 根 CA X3。其有效期为2000年10月1日至2021年10月1日。它不再有效。

Lets Encrypt 现在使用ISRG 根 X1作为根证书颁发机构。它的有效日期范围为 2015-06-04 至 2035-06-04。如果平台无法识别此根证书颁发机构,它就不会信任 Lets Encrypt。

Node

更新操作系统中的证书存储不会对 NodeJS 平台产生影响。

节点使用硬编码的证书颁发机构列表,定义于节点根证书.h. (See 本自述文件更多细节)。

最新的证书ISRG Root X1自版本以来一直是 Node 的一部分8.0.0. (See 这次提交).


Finally, if you want to write a tiny node application to test if a web request will work: here is one.
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);
        }
    }
})();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

LetsEncrypt 根证书过期会破坏 Azure Function Node 应用程序 的相关文章

随机推荐