我使用curl使用公共证书文件从https站点下载数据。
系统信息:
命令是,
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我已经给了.pem文件所有的权限,但还是会抛出一个错误。
发布于 2013-05-18 18:54:22
在读取了您使用的选项的cURL 文档之后,证书的私钥似乎不在同一个文件中。如果它位于不同的文件中,则需要使用--密钥文件并提供密码。
因此,请确保cert.pem有私钥(连同证书),或者使用--key选项提供私钥。
此外,本文档还提到,注意此选项假定了一个“证书”文件,即私钥和连接的私有证书!
它们是如何连接的?这很容易。把它们一个接一个地放在同一个文件里。
您可以在这个这里上获得更多的帮助。
我相信这可能对你有帮助。
发布于 2017-06-30 13:13:36
当我使用Open时,我遇到了这个问题,解决方案是将cert拆分到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发布于 2020-05-08 13:31:02
我也遇到了同样的问题,最终我找到了一种不分裂文件的解决方案,方法是遵循Petter的回答
我的问题是当将.p12证书转换为.pem时。我用:
openssl pkcs12 -in cert.p12 -out cert.pem这会将所有证书(CA + CLIENT)与私钥一起转换并导出到一个文件中。
问题是当我试图通过运行验证证书和密钥的散列是否匹配时:
// Get certificate HASH
openssl x509 -noout -modulus -in cert.pem | openssl md5
// Get private key HASH
openssl rsa -noout -modulus -in cert.pem | openssl md5这显示了不同的散列,这就是CURL失败的原因。见此处:https://michaelheap.com/curl-58-unable-to-set-private-key-file-server-key-type-pem/
我猜这是因为所有证书都在一个文件(CA + CLIENT)中,CURL使用CA证书而不是客户端证书。因为CA是列表中的第一位。
因此,解决方案是只将客户端证书与私钥一起导出:
openssl pkcs12 -in cert.p12 -out cert.pem -clcerts
``
Now when I re-run the verification:
```shopenssl x509 -noout -modulus -in cert.pem openssl md5
openssl rsa -noout -modulus -in cert.pem cert.pem openssl md5
**HASHES MATCHED !!!**
So I was able to make a curl request by running
```javascriptcurl -ivk -cert ./cert.pem:KeyChoosenByMeWhenIrunOpenSSL https://thesite.com
without problems!!!
That being said... I think the best solution is to split the certificates into separate file and use them separately like Petter Ivarsson wrote:
```javascript卷曲-不安全-键key.pem - ca.pem -cert client.pem:KeyChoosenByMeWhenIrunOpenSSL https://thesite.com
https://stackoverflow.com/questions/16624704
复制相似问题