我的服务器代码(在 AWS Lambda .net Core 3.1 上运行)突然停止了对我的 API 服务器的身份验证。它已经工作多年,但今天它停止同时在生产和开发环境中工作。我得到的错误是
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
相关源码是
WebRequest httpWebRequest2 = WebRequest.Create(APIurl);
httpWebRequest2.Method = "GET";
httpWebRequest2.Accept = "application/json"
httpWebRequest2.Timeout = 60 * 1000
httpWebRequest2.Headers.Add("Authorization", _APIToken);
WebResponse response = httpWebRequest2.GetResponseAsync().Result;
我正在使用 letsencrypt 来生成证书,并且无论是用于我的开发 api url 还是用于生产 api url 的证书都没有过期。 HTTPS 查询在我尝试过的所有其他平台上都能成功。
在这一点上,我什至不知道还有什么可以解决的。我可以根据需要提供更多信息。
最佳答案
这是 Lambda 函数用来运行其运行时环境的 Amazon Linux 2
的一个问题。在这篇文章中,Amazon Linux 2 使用 OpenSSL 1.0(特别是软件包 openssl-1.0.2k-19.amzn2.0.6.x86_64
)。 As of today, September 30th 2021, Let's Encrypt's older certificate from DST Root CA X3 expired已经过期,其中的一个怪癖是来自 Let's Encrypt 的默认首选证书链不再适用于 OpenSSL 1.0。
您可以解决此问题,如 this post 中所述取决于您如何生成 Let's Encrypt 证书。例如我们利用 CertBot并且需要传递 --preferred-chain 'ISRG Root X1'
参数来为 OpenSSL 1.0 生成兼容的证书。
希望底层运行时环境能尽快与默认链偏好兼容。
关于c# - 无法建立 SSL 连接 : System. Security.Authentication.AuthenticationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69395823/