curl: (60) SSL证书问题:无法获取本地颁发者证书

486
root@sclrdev:/home/sclr/certs/FreshCerts# curl --ftp-ssl --verbose ftp://{abc}/ -u trup:trup --cacert /etc/ssl/certs/ca-certificates.crt
* About to connect() to {abc} port 21 (#0)
*   Trying {abc}...
* Connected to {abc} ({abc}) port 21 (#0)
< 220-Cerberus FTP Server - Home Edition
< 220-This is the UNLICENSED Home Edition and may be used for home, personal use only
< 220-Welcome to Cerberus FTP Server
< 220 Created by Cerberus, LLC
> AUTH SSL
< 234 Authentication method accepted
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS alert, Server hello (2):
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0
curl: (60) SSL certificate problem: unable to get local issuer certificate
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.

我曾经遇到过类似的问题。这个链接对我有用:https://dev59.com/NmAg5IYBdhLWcg3w9e_m#29649024 - Sagruob
2
在我的情况下,https://superuser.com/a/719047/137881 有所帮助。 - Abdull
请查看以下链接以获取解决方案:https://dev59.com/WV4b5IYBdhLWcg3wojFg#61177063 - pankaj
如果您是在组织机构而不是个人电脑上工作,可能会处于代理互联网连接中。如果任何可能的解决方案都不起作用,请请求静态IP。 - Deepak Thakur
显示剩余2条评论
37个回答

0

这可能是由于使用Homebrew引起的。在我的情况下,问题是由于安装了一些其他软件的依赖项时,Homebrew中损坏的curl导致的,该软件影响了操作系统提供的完全正常的curl

使用which curl命令检查curl来自何方。如果是来自Homebrew,则可以运行brew unlink curl将其“隐藏”。


0
对我来说,问题出在AVG防病毒软件的“web-shield”上。禁用了web-shield,并结合其他答案中提供的解决方案,解决了我的问题。
使用选项--trace-ascii对调试非常有帮助:
curl --trace-ascii - https://www.example.com

使用--trace-ascii -中的-会导致跟踪信息打印到标准输出(stdout)。
如果AVG引起问题,你会看到类似的文本。
0040: .U.../generated by AVG Antivirus for SSL/TLS scanning1.0...U....
0080: AVG Web/Mail Shield1!

-1

我曾经遇到过Digicert的问题,我创建了一个digicertca.pem文件,将中间证书和根证书粘贴在一起形成一个文件。

curl https://cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem
curl https://cacerts.digicert.com/DigiCertSHA2SecureServerCA.crt.pem

curl -v https://mydigisite.com/sign_on --cacert DigiCertCA.pem
...
*  subjectAltName: host "mydigisite.com" matched cert's "mydigisite.com"
*  issuer: C=US; O=DigiCert Inc; CN=DigiCert SHA2 Secure Server CA
*  SSL certificate verify ok.
> GET /users/sign_in HTTP/1.1
> Host: mydigisite.com
> User-Agent: curl/7.65.1
> Accept: */*
...

Eorekan有答案,但只有我和另外一个人点赞了他的回答。


-2

特别针对Windows用户,使用curl-7.57.0-win64-mingw或类似版本。

这可能有点晚了,现有的答案是正确的。但我仍然在我的Windows机器上努力了一段时间才让它工作,尽管这个过程实际上非常简单。因此,分享一下逐步过程。

这个错误基本上意味着,curl无法验证目标URI的证书。如果您信任证书颁发机构(CA),则可以将其添加到受信任证书列表中。

为此,请浏览URI(例如在Chrome中)并按照以下步骤操作:

  1. 右键点击安全的挂锁图标
  2. 点击证书,会打开一个窗口显示证书详情
  3. 进入“认证路径”选项卡
  4. 点击根证书
  5. 点击“查看证书”,会打开另一个证书窗口
  6. 进入“详细信息”选项卡
  7. 点击“复制到文件”,会打开导出向导
  8. 点击下一步
  9. 选择“Base-64 编码 X.509 (.CER)”
  10. 点击下一步
  11. 指定友好名称,如“MyDomainX.cer”(浏览到所需目录)
  12. 点击下一步
  13. 点击完成,将保存证书文件
  14. 现在打开这个.cer文件并复制其中的内容(包括-----BEGIN CERTIFICATE-----和-----END CERTIFICATE-----)
  15. 现在进入curl.exe所在的目录,例如:C:\SomeFolder\curl-7.57.0-win64-mingw\bin
  16. 使用文本编辑器打开curl-ca-bundle.crt文件
  17. 将复制的证书文本追加到文件末尾。保存

现在你的命令应该可以在curl中正常执行了。


3
感谢您的评论,如果您能在下投票的原因上多加说明,我们将不胜感激。 - Arghya C
我在“C:\xampp\apache\bin”(Windows)中找不到名为“curl-ca-bundle.crt”的文件。我猜这就是被踩的原因。我在上述提到的“bin”文件夹中有我的“curl.exe”。 - kathikeyan A

-2
对于我的M1 Mac,我只需使用这个命令就可以了:
/bin/bash -c "$(curl -fsSLk https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

我在这里做的是在“-fsSLk”中添加了一个k

不是真正的解决方案...请阅读使用手册。 - Mr.P

-5

这可以帮助你使用 Guzzle:

$client = new Client(env('API_HOST'));
$client->setSslVerification(false);

已在 guzzle/guzzle 3.* 上进行测试


-6
简单解决方案: 在~/.sdkman/etc/config中,将sdkman_insecure_ssl=true更改为sdkman_insecure_ssl=false 步骤:
nano ~/.sdkman/etc/config
sdkman_insecure_ssl=false更改为sdkman_insecure_ssl=true
保存并退出

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