gpt4 book ai didi

curl - 无法设置私钥文件 : './cert.pem' type PEM

转载 作者:行者123 更新时间:2023-12-03 10:59:31 25 4
gpt4 key购买 nike

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

系统信息:

  • 操作系统:软呢帽 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

    我已授予 .pem 的所有权限文件,仍然 curl 抛出错误。

    最佳答案

    我遇到了同样的问题,最终我找到了一个无需拆分文件即可工作的解决方案,遵循 Petter Ivarrson 的 answer

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

    openssl pkcs12 -in cert.p12 -out cert.pem

    这会将所有证书(CA + CLIENT)与私钥一起转换并导出到一个文件中。

    问题是当我尝试通过运行验证证书和 key 的哈希是否匹配时:

    // 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 证书而不是 CLIENT 证书。因为 CA 在列表中排名第一。

    所以解决方案是只导出 CLIENT 证书和私钥:

    openssl pkcs12 -in cert.p12 -out cert.pem -clcerts
    ``

    Now when I re-run the verification:
    ```sh
    openssl x509 -noout -modulus -in cert.pem | openssl md5
    openssl rsa -noout -modulus -in cert.pem | openssl md5

    哈希匹配!!!

    所以我能够通过运行发出 curl 请求

    curl -ivk --cert ./cert.pem:KeyChoosenByMeWhenIrunOpenSSL https://thesite.com

    没有问题!!! 😀

    话虽如此......我认为最好的解决方案是将证书拆分为单独的文件并像 Petter Ivarsson 所写的那样单独使用它们:

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

    关于curl - 无法设置私钥文件 : './cert.pem' type PEM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16624704/

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