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

Has*_*sha 36 ssl curl

我们在 amazon ec2 ( backend.abc.com & frontend.abc.com )上运行 2 个应用程序。对于该应用程序,我们使用了付费 SSL 证书。该证书到期日为2021 年 6 月。但是今天,我们遇到了一个错误——

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

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

之后,当我们通过 - 卷曲 abc.com 时curl -v --url https://backend.abc.com --cacert /etc/ssl/ssl.cert/cacert.pem,它工作正常。像这样的回应——

* Rebuilt URL to: https://backend.abc.com/
*   Trying 127.0.0.1...
* Connected to backend.abc.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: *.abc.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=*.abc.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
Run Code Online (Sandbox Code Playgroud)

但是当我们通过 curl从frontend.abc.com打到backend.abc.com 时,它会抛出这个错误 -

* Rebuilt URL to: https://backend.abc.com/
*   Trying 127.0.0.1...
* Connected to backend.abc.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=*.abc.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.
Run Code Online (Sandbox Code Playgroud)

我的卷曲代码 -

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://backend.abc.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);
Run Code Online (Sandbox Code Playgroud)

Man*_*anu 35

要解决此问题,请从域证书中删除过期的根证书。

  1. https://whatsmychaincert.com
  2. 测试您的服务器
  3. 如果他们确认您的根证书已过期,请下载并使用没有此证书的 .crt。

(可选)当您这样做时,您可以使用此临时 curl 修复程序,以免您的网站出现错误:添加此选项:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
Run Code Online (Sandbox Code Playgroud)

  • 不要使用 SSL_VERIFYPEER = 0,这会使您的请求受到中间人攻击。这不是一个解决方案,只是一个临时测试,永远不应该在生产中使用! (2认同)

mrm*_*les 14

如果您在 Ubuntu 16 系统上遇到“curl”(或类似问题)的问题,我们可以通过以下方式修复它:

在托管 curl / 应用程序失败的 Ubuntu 16 系统上:

  • nano /etc/ca-certificates.conf
  • 删除指定 AddTrust_External_Root.crt 的行(或注释)
  • apt update && apt install ca-certificates
  • 更新-ca-certificates -f -v
  • 使用之前失败的 URL 再次尝试 curl - 希望它现在可以工作:)

  • 它不起作用。当我们通过curl从frontend.abc.com访问backend.abc.com时,它显示了相同的错误。 (4认同)
  • 我确信并感谢您解决我的问题,但在我的 Debian 系统上,我认为“sudo dpkg-reconfigure ca-certificates”可能是“nano /etc/ca-certificates.conf”取消选择的推荐方法添加Trust_External_Root,以确保将文件保持为工具可以理解的格式。 (3认同)

小智 6

对于 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/
Run Code Online (Sandbox Code Playgroud)

然后 dpkg-reconfigure ca-certificates取消选中的mozilla / AddTrust_External_Root.crt和检查的mozilla / 2_Root_USERTrust_RSA_Certification_Authority.crt
或运行sudo update-ca-certificates于取消选中的。

  • 今天,“DST_Root_CA_X3.crt”证书已过期,Let's Encrypt 证书不起作用。要修复此问题,只需使用“sudo dpkg-reconfigure ca-certificates”工具停用证书即可。 (29认同)
  • Grazie mille caro :-),你的提示结束了两天的噩梦。只是一个小补充让我有点犹豫:在 dpgk-reconfigure 的第一个屏幕中......正确的答案是“询问”,然后会显示可用证书的列表。滚动到 DST_Root_CA_X3.crt,取消选中并按 Tab 键选择“确定”。 (5认同)

Adr*_*oto 6

insecure您可以将此选项添加到 文件中来启用连接$HOME/.curlrc

$ echo "insecure" >> ~/.curlrc

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

参考:如何将更改应用于所有 HTTPS 连接