cURL错误60:SSL证书问题:证书已过期

70

我们在亚马逊EC2上运行两个应用程序(backend.example.comfrontend.example.com)。对于这些应用程序,我们使用了付费SSL证书。该证书的过期日期是2021年6月。但是今天我们收到了一个错误 -

cURL error 60: SSL certificate problem: certificate has expired (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

我们检查了证书过期日期,但没有问题(2021年6月)。然后我们按照这个线索进行 - curl:(60)SSL证书问题:无法获取本地颁发者证书(@Dahomz回答)。

之后,当我们使用命令 curl -v --url https://backend.example.com --cacert /etc/ssl/ssl.cert/cacert.pemexample.com 进行访问时,一切正常。响应如下 -

* Rebuilt URL to: https://backend.example.com/
*   Trying 127.0.0.1...
* Connected to backend.example.com (127.0.0.1) port 443 (#0)
* found 139 certificates in /etc/ssl/ssl.cert/cacert.pem
* found 600 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ******_RSA_***_***_GCM_*****
*    server certificate verification OK
*    server certificate status verification SKIPPED
*    common name: *.example.com (matched)
*    server certificate expiration date OK
*    server certificate activation date OK
*    certificate public key: RSA
*    certificate version: #3
*    subject: OU=Domain Control Validated,OU=PositiveSSL Wildcard,CN=*.example.xyz
*    start date: Mon, 04 May 2019 00:00:00 GMT
*    expire date: Wed, 07 June 2021 23:59:59 GMT
*    issuer: C=GB,ST=Greater Manchester,L=Salford,O=Sectigo Limited,CN=Sectigo RSA Domain Validation Secure Server CA
*    compression: NULL
* ALPN, server accepted to use http/1.1

但是当我们使用curl从frontend.example.com访问backend.example.com时,会抛出以下错误 -

Translated Text:

但是当我们使用curl从frontend.example.com访问backend.example.com时,会抛出以下错误 -

* Rebuilt URL to: https://backend.example.com/
*   Trying 127.0.0.1...
* Connected to backend.example.com (127.0.0.1) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/ssl.cert/cacert.pem
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / *****-RSA-*****-GCM-******
* ALPN, server accepted to use http/1.1
* Server certificate:
*    subject: OU=Domain Control Validated; OU=PositiveSSL Wildcard; CN=*.example.com
*    start date: Mar  4 00:00:00 2019 GMT
*    expire date: Apr  7 23:59:59 2021 GMT
*    issuer: C=GB; ST=Greater Manchester; L=Salford; O=Sectigo Limited; CN=Sectigo RSA Domain Validation Secure Server CA
*    SSL certificate verify result: certificate has expired (10), continuing anyway.

我的 curl 代码 -

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://backend.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, fopen(public_path("c.log"), 'w'));
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$output = curl_exec($ch);
$error = curl_error($ch);
$info = curl_getinfo($ch);
curl_close($ch);

4
不仅要检查叶证书,还要检查整个证书链。在被接受为根证书之前,Sectigo曾使用AddTrust进行链接,并且如果您的“后端”curl仍在使用已过期的AddTrust链,则可能会影响USERTrust根证书的验证。请参考https://support.sectigo.com/Com_KnowledgeDetailPage?Id=kA03l00000117LT 。 - dave_thompson_085
你能给我们一些解决这个问题的提示吗? - Hasan Hafiz Pasha
我使用了你提供的两行代码来解决我的问题:curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); - Doglas
如果您正在使用AWS Elastic Beanstalk(适用于我),请访问以下链接:https://aws.amazon.com/premiumsupport/knowledge-center/ec2-expired-certificate/ - hguzman
13个回答

57
为了解决问题,请从您的域名证书中删除过期的根证书。 操作步骤: 1. 访问https://whatsmychaincert.com 2. 测试您的服务器。 3. 如果确认您的根证书已过期,请下载并使用没有该证书的.crt文件。

1
谢谢您的回答。我建议您先编辑您的答案,将完整的修复方法放在前面,因为仅仅设置curl选项并不是一个解决方案,因为其他(旧)客户端访问相同的证书时问题仍然存在。网站whatsmychaincert.com非常出色,可以诊断此问题 - 谢谢! - BlueC
我同意@BlueC的观点:应该首先强调证书修复,然后再为OP添加临时curl修复。 - alleen1
这些步骤可以在服务器端解决问题。顺便提下,在第三步下载的证书将会替换旧的 CA 证书。 - codemonkey
我应该在哪里输入这些命令?在哪个文件中? - Cherryl Rarewings
2
不要使用 SSL_VERIFYPEER = 0,这会使您的请求容易受到中间人攻击。这不是一个解决方案,只是一个临时测试,绝不能在生产环境中使用! - MeanEYE
正如@MeanEYE所说,不要禁用SSL验证。 更多信息请参见https://curl.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html - LucianDex

26

如果您在Ubuntu 16系统上使用“curl”(或类似工具)时遇到问题,请按照以下步骤解决:

在Ubuntu 16系统上托管curl / 应用程序的服务器上:

  • 打开 /etc/ca-certificates.conf 文件
  • 删除(或注释)指定 AddTrust_External_Root.crt 的行
  • 运行命令:apt update && apt install ca-certificates
  • 运行命令:update-ca-certificates -f -v
  • 再次使用之前失败的URL尝试curl - 希望现在可以正常工作 :)

4
不起作用。当我们通过curl从frontend.abc.com访问backend.abc.com时,会显示相同的错误。 - Hasan Hafiz Pasha
@HasanHafizPasha,你是否遇到了curl的问题(就像我在帖子中提到的那样)? - mrmuggles
是的@mrmuggles,从前端应用程序调用curl。 - Hasan Hafiz Pasha
好的,如果你使用的是Ubuntu 16,它应该可以工作。你在运行上面的命令时有收到任何错误信息吗?另外,如果你可以访问后端,@Manu的答案更好,因为你可以“修复”源代码。 - mrmuggles
3
我相信你已经解决了我的问题,非常感谢。但在我的Debian系统上,我认为sudo dpkg-reconfigure ca-certificates可能是推荐的方式,以便通过取消选择AddTrust_External_Root来确保将文件保留在工具可以理解的格式中,而不是编辑/etc/ca-certificates.conf文件。 - Martin Dorey
我刚刚运行了sudo update-ca-certificates命令,它修复了Linux上过期的证书。 - haytham-med haytham

11

适用于Ubuntu 14.04

打开终端

sudo su
wget https://support.sectigo.com/Com_KnowledgeDetailPage?Id=kA01N000000rfBO -O SHA-2_Root_USERTrust_RSA_Certification_Authority.crt --no-check-certificate
cp SHA-2_Root_USERTrust_RSA_Certification_Authority.crt /usr/share/ca-certificates/mozilla/

然后运行dpkg-reconfigure ca-certificates,取消选中mozilla/AddTrust_External_Root.crt,并选中mozilla/2_Root_USERTrust_RSA_Certification_Authority.crt
或者运行sudo update-ca-certificates以取消选中它们。


29
今天 DST_Root_CA_X3.crt 证书过期了,Let's Encrypt 的证书也不能工作。为了解决这个问题,只需使用 sudo dpkg-reconfigure ca-certificates 工具来禁用该证书即可。 - Finesse
谢谢。我已经尝试修复这个问题5天了! - Pierre Priot
5
非常感谢你亲爱的:-),你的提示结束了我两天的噩梦。只是有一个小细节让我有些犹豫:在dpgk-reconfigure的第一个屏幕上...正确的答案是“询问”,然后会呈现可用证书列表。滚动到DST_Root_CA_X3.crt,取消选中并切换到“确定”。 - cucu8

5

您可以通过在$HOME/.curlrc文件中添加以下选项来启用不安全的连接:

$ echo "insecure" >> ~/.curlrc

不建议永久保留此设置,但对于快速且临时的解决方案,这是一个不错的选择。

参考资料:如何为所有HTTPS连接应用更改


我找到了一种更好的方法,不需要使用不安全的配置,我在这里分享了步骤:https://dev59.com/-7zpa4cB1Zd3GeqPL3sB#70011298 - Adrian Escutia Soto

3

0
我在2023年的Ubuntu上通过运行以下命令来修复这个问题:
sed -i 's|^mozilla\/DST_Root_CA_X3\.crt|!mozilla/DST_Root_CA_X3.crt|' /etc/ca-certificates.conf
curl -sk https://letsencrypt.org/certs/isrgrootx1.pem -o /usr/local/share/ca-certificates/ISRG_Root_X1.crt
update-ca-certificates --fresh

源代码:https://github.com/cloudposse/bastion/issues/67

0

我通过在服务器上运行更新来解决了问题:

sudo yum update

这似乎已经解决了与curl证书相关的任何问题。


0

0

我不得不在一台基于debian的服务器上解决这个问题

这是由openssl(curl依赖于openssl)系统使用引起的

这就是所发生的:

  1. 从您的系统中删除AddTrust_External_Root.crt文件(通常可以在/etc/ssl/certs中找到)。
    1. /etc/ca-certificates.conf中删除或注释掉“mozilla/AddTrust_External_Root”行。
    2. 运行sudo update-ca-certificates来更新openssl使用的证书。

也许它可以帮助你?


0

更改或编辑以下设置:

Change these files from the server in Custome Domain SSL

服务器密钥 = 服务器密钥是服务器使用的私有加密/解密密钥。

中间证书(CA) = 证书颁发机构(CA)是一种实体,发行数字证书,以验证证书主题的公钥所有权。

域名证书 = 域名证书是由认证机构颁发的电子文件,用于检查申请人使用特定域名的权限。


1
没有人会知道那是什么用户界面。 - tblev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接