gpt4 book ai didi

ssl - Curl 不考虑给定的证书(使用 --cert 选项)

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:33 36 4
gpt4 key购买 nike

我正在尝试使用 curl 调用 URL,我使用了以下命令:

curl https://testenvironment/login --cert Qa1Certificate.pem

我得到的结果是:

curl: (60) Peer certificate cannot be authenticated with known CA certificates
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.

Qa1Certificate.pem 放在当前目录中,我相信它没有被考虑在内,因为当我使用不存在的文件名运行相同的命令时:

curl https://testenvironment/login --cert ThisFileDoesNotExist.pem

我得到了相同的结果。

我知道我可以使用 -k 或 --insecure 选项(或其他禁用 curl 证书验证的方法)获得我需要的东西,但我想了解如何使用该证书来成功执行对我的测试环境的 GET。

测试环境使用我使用 openSSL 获得的自签名证书。

最佳答案

TLDR:它是 --cacert

来自手册页,它应该在您的系统上or on the web :

-E, --cert <certificate[:password]>

(TLS) Tells curl to use the specified client certificate file when getting a file with HTTPS, FTPS or another SSL-based protocol. [snip rest]

注意“客户端证书”这个词。 --cert 用于指定证书和可能的 key 以验证客户端,而不是验证服务器。现在考虑手册页上的另一个条目:

--cacert

(TLS) Tells curl to use the specified certificate file to verify the peer. The file may contain multiple CA certificates. The certificate(s) must be in PEM format. Normally curl is built to use a default file for this, so this option is typically used to alter that default file.

这是指定一个或多个证书以验证(特别是锚定)服务器证书的选项。由于您的服务器证书是自签名的,因此该证书是它自己的 anchor /根并且实际上是 CA 证书,即使服务器实际上不是 CA。

这就是为什么您发布的错误消息包含这些词您可以使用 --cacert 选项指定备用文件。它没有说 --cert

client 证书(和 key )是否被读取取决于您正在运行的 curl 的特定构建所使用的中间件。 IME 如果使用 OpenSSL 构建,如果您使用不存在的文件名指定 --cert,它确实会出错,但是使用 NSS(在 Ubuntu 14.04LTS 上)构建的版本仅在服务器请求客户端身份验证时才会出错,大多数服务器都没有。

关于ssl - Curl 不考虑给定的证书(使用 --cert 选项),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48185310/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com