cUrl双向认证

9
我正在尝试使用cUrl连接到第三方服务器。他们提供了一个p12文件,我已经在浏览器中安装了它。在使用浏览器时,我能从服务器获得响应。但是,在Linux终端执行cUrl命令时,我遇到了握手错误。
我将.p12文件提取为密钥和证书,然后运行以下命令: curl --key client.key --cert client.crt -X GET -v https://x.x.x.x:xxxx/folder/endpoint 然后收到以下回复:
Note: Unnecessary use of -X or --request, GET is already inferred.
*   Trying x.x.x.x...
* TCP_NODELAY set
* Connected to x.x.x.x (x.x.x.x) port xxxx (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS alert, Server hello (2):
* SSL certificate problem: unable to get local issuer certificate
* stopped the pause stream!
* Closing connection 0
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

我需要在哪里添加自签名证书?感觉我漏掉了什么。如前所述,当我从已导入证书的浏览器中访问时,它可以工作,所以我确定他们的证书没有问题。但我知道我漏掉了什么。

谢谢,

2个回答

12

如果你已经下载了证书或使用自签名证书(在我的情况下),那么在curl命令中需要添加--cacert选项。

curl --key client.key --cert client.crt --cacert bundle.pem -X GET -v https://x.x.x.x:xxxx/folder/endpoint

bundle.pem文件包括server.crtrootCA.crt

cat server.crt rootCA.crt >> bundle.pem


4
您的错误信息是:

无法获取本地颁发机构证书

这意味着curl无法从信任存储中找到颁发机构(签署服务器证书的CA)的证书:

/etc/ssl/certs/ca-certificates.crt

您需要下载CA证书并将其添加到信任存储中即可。

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