Curl 无法设置私钥文件:'/cert.pem';型质子交换膜

Curl 无法设置私钥文件:'/cert.pem';型质子交换膜,curl,openssl,Curl,Openssl,我正在使用curl使用公共证书文件从https站点下载数据 系统信息: OS:fedora 14 curl:curl 7.30.0 openssl:openssl 1.0.0a-fips 命令是, curl -v "https://<ip:<port>" --cert "./cert.pem" --cacert "./cacert.pem" --cert-type PEM * About to connect() to kng.com port 443 (#0) * T

我正在使用curl使用公共证书文件从https站点下载数据

系统信息:

  • OS:fedora 14
  • curl:curl 7.30.0
  • openssl:openssl 1.0.0a-fips
命令是,

curl -v "https://<ip:<port>" --cert "./cert.pem" --cacert "./cacert.pem" --cert-type PEM
* About to connect() to kng.com port 443 (#0)
*   Trying 11.19.37.123...
* Adding handle: conn: 0x8189e68
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x8189e68) send_pipe: 1, recv_pipe: 0
* Connected to fkng.com (11.19.37.123) port 443 (#0)
* unable to set private key file: './cert.pem' type PEM
* Closing connection 0
curl: (58) unable to set private key file: './cert.pem' type PEM
curl-v“https://在阅读了您使用的curl选项后,证书的私钥似乎不在同一个文件中。如果它在不同的文件中,您需要使用--key文件提及它并提供密码短语

因此,请确保cert.pem具有私钥(以及证书),或者使用--key选项提供私钥

此外,本文档还提到 请注意,此选项假定“证书”文件是私钥和私钥连接的

它们是如何连接的?这很简单。将它们一个接一个地放在同一个文件中

你可以在这方面得到更多帮助


我相信这可能会对您有所帮助。

我不确定这是否会对任何人有所帮助,但我遇到了这个错误(尽管我使用php而不是命令行创建它)为了解决这个问题,我必须确保在我查看的目录中没有旧的.key或.pem文件。通过删除它们并使用身份验证创建新文件,它工作得非常好!

当我使用Open SSL时,我遇到了这个问题,解决方案是将证书拆分为3个文件,并使用所有文件通过Curl进行调用:

openssl pkcs12 -in mycert.p12 -out ca.pem -cacerts -nokeys
openssl pkcs12 -in mycert.p12 -out client.pem -clcerts -nokeys 
openssl pkcs12 -in mycert.p12 -out key.pem -nocerts

curl --insecure --key key.pem --cacert ca.pem --cert client.pem:KeyChoosenByMeWhenIrunOpenSSL https://thesite

我有类似的情况,但我在不同的文件中使用密钥和证书


在我的例子中,您可以通过比较散列来检查密钥和锁的匹配情况(请参阅)。这有助于我识别不一致性。

我也遇到了同样的问题,最终我找到了一个解决方案,通过遵循Petter Ivarrson的

我的问题是在将.p12证书转换为.pem时。我使用了:

openssl pkcs12-in cert.p12-out cert.pem
这会将所有证书(CA+客户端)连同私钥一起转换并导出到一个文件中

问题是当我试图通过运行以下命令验证证书和密钥的哈希是否匹配时:

//获取证书哈希
openssl x509-noout-模数-在cert.pem中| openssl md5
//获取私钥散列
openssl rsa-noout-module-in cert.pem | openssl md5
这显示了不同的散列,这就是CURL失败的原因。 请看这里:

我猜这是因为所有证书都在一个文件(CA+客户端)中,而CURL使用CA证书而不是客户端证书,因为CA是列表中的第一个

因此,解决方案是仅导出客户端证书和私钥:

openssl pkcs12-in cert.p12-out cert.pem-clcerts
``
现在,当我重新运行验证时:
```嘘
openssl x509-noout-模数-在cert.pem中| openssl md5
openssl rsa-noout-module-in cert.pem | openssl md5
哈希匹配!!!

所以我可以通过运行

curl-ivk--cert./cert.pem:KeyChoosenByMeWhenIrunOpenSSLhttps://thesite.com

没有问题!!!感谢您提供的宝贵信息..还有一件事我不明白如何从公共证书中检索私钥。我可以使用此命令获取公钥“openssl x509