【问题标题】:Getting (58) unable to use client certificate (no key found or wrong pass phrase?) from curl从 curl 获取(58)无法使用客户端证书(找不到密钥或密码错误?)
【发布时间】:2015-06-30 05:22:26
【问题描述】:

我正在尝试对需要客户端证书的第三方 API 进行测试调用。我通过 openssl 使用此命令生成了一个新证书:

req -new -newkey rsa:2048 -nodes -out mycsr.csr -keyout mykey.key

然后我将 csr 发送给他们,他们将 mycert.crt 发回给我。我将证书和密钥连接在一起:

cat mycert.crt mykey.key > mycertandkey.pem

最后,我将 mycert.crt 添加到 ca-certificates 文件夹和 ca-certificates.conf 并运行“update-ca-certificates --fresh”。

现在,我正在尝试使用以下命令从 bash 进行 curl 调用:

curl -X GET --cert mycertandkey.pem -H 'Accept-Encoding: gzip,deflate' -H 'Content-Type: application/json' https://api.URL.com

我也试过了:

curl -X GET --cert mycertandkey.pem --cacert mycert.crt -H 'Accept-Encoding: gzip,deflate' -H 'Content-Type: application/json' https://api.URL.com

和:

curl -X GET --cert mycertandkey.pem --cacert mycert.crt --key mykey.key -H 'Accept-Encoding: gzip,deflate' -H 'Content-Type: application/json' https://api.URL.com

还有我能想到的所有其他组合。我总是收到错误消息“curl: (58) 无法使用客户端证书(未找到密钥或密码错误?)”。密钥没有密码。所有证书/密钥文件都有 777 权限。

过去我在证书方面工作不多,我觉得我错过了一些东西,尤其是因为我似乎只有一个证书。其他公司发给我的证书是 cacert 还是我的客户证书?我是否将私钥连接到错误的证书?

我在网上找到了很多关于这个的零碎信息,但是如果有人知道关于这个主题的好教程,我也非常感激。

【问题讨论】:

    标签: ssl curl ssl-certificate


    【解决方案1】:

    向我的私钥添加密码解决了我的问题。

    我使用以下命令添加密码:

    ssh-keygen -p -f mykey.key
    

    在成功运行该命令之前,我需要更改密钥文件的权限。 777 限制不够, ssh-keygen 不会碰它。将权限更改为 600 即可解决此问题。

    chmod 600 mykey.key
    

    添加密码后,我重新创建了 .pem 文件。现在我可以使用以下命令成功地使用它进行 curl 调用:

    curl -X GET --cert mycertandkey.pem:mypassphrase -H 'Accept-Encoding: gzip,deflate' -H 'Content-Type: application/json' https://api.URL.com
    

    【讨论】:

      【解决方案2】:

      如果您不能使用本地生成的证书并且来自 https://developer.tizen.org/forums/native-application-development/curl-ssl-problem-local-ssl-certificate ...

      如果生成的自签名本地证书用于开发不正确,则可能是这样 (首先我尝试了一个命令 openssl req -x509 -config ./openssl-ca.cnf -newkey rsa:4096 -sha256 -nodes -out cacert.pem -outform PEM ,但它没有工作,然后出现错误“curl_easy_perform() failed: Problem with the local SSL certificate”)。

      正确的方法可能应该像下一个链接中描述的那样(用于生成本地自签名的三个文件,用于客户端身份验证的开发目的): https://blog.atulr.com/localhost-https/

      (然后我测试了我可以将结果证书与 libcurl 一起使用,请参见示例 simplessl.c,并在此 simplessl.c 示例中将文件名更新为类似的内容:

      static const char *pCertFile = "localdomain.crt";
      static const char *pCACertFile = "cacert.pem";
      pKeyName  = "localdomain.insecure.key";
      

      【讨论】:

        猜你喜欢
        • 2016-02-17
        • 1970-01-01
        • 2016-06-14
        • 2015-10-26
        • 2014-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多