【问题标题】:curl server certificate verification failedcurl服务器证书验证失败
【发布时间】:2018-10-20 17:59:46
【问题描述】:

我有一堆使用 curl 与各种服务通信的 PHP 脚本。目前,其中一项服务的 SSL 证书已更新,当我尝试从服务器的 CLI 获取它时,我的 curl 开始为它哭泣:

~$ curl https://example.com

curl: (60) server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority (CA) public keys (CA certs). If the default bundle file isn't adequate, you can specify an alternate file using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in the bundle, the certificate verification probably failed due to a problem with the certificate (it might be expired, or the name might not match the domain name in the URL).

If you'd like to turn off curl's verification of the certificate, use the -k (or --insecure) option.

目前,我将 verify => false 硬编码到我的所有请求中,以保持我的脚本正常运行,但这不是我想要的。

我得到了最新的cacert file from mozilla,把它放在/etc/ssl/certs/ca-certificates.crt,然后运行sudo update-ca-certificates,它运行成功了(我想..)

~$ sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

但话又说回来,curl 对此不太满意,如果不通过 -k 标志,仍然无法获取我的资源。

【问题讨论】:

标签: php linux ssl curl


【解决方案1】:

您可以使用openssl s_client 命令进一步调试问题,以便找出证书的问题所在。

openssl s_client -showcerts -servername myservice.com -connect myservice.com:443

【讨论】:

  • 这是一些有用的信息,谢谢。它说verify error:num=18:self signed certificate,但证书显然不是自签名的,它是COMODO 证书。有些东西很可疑..
  • 你可以用附加参数-servername myservice.com再试一次吗,它可能与this question有关?
  • 现在错误变成了verify return code: 21 (unable to verify the first certificate),所以我认为这是一个错误配置的服务器,我必须向服务维护人员提出问题,除了现在跳过验证之外我无能为力。
  • 是的,据说 ca 证书没有正确地与证书文件捆绑在一起。只需将证书颁发机构 crt 粘贴到与证书相同的文件中,然后重新启动网络服务器。可能是 nginx。
猜你喜欢
  • 2011-07-07
  • 2013-06-17
  • 1970-01-01
  • 2016-09-23
  • 2015-06-30
  • 1970-01-01
  • 1970-01-01
  • 2015-06-05
  • 2014-10-14
相关资源
最近更新 更多