php - 带有 SSL 证书的 cURL 失败 : error 58 unable to set private key file

标签 php ssl curl certificate

我正在尝试使用 cURL 连接到远程主机。连接需要使用证书和受密码保护的私钥。到目前为止,我没有成功使用以下代码:

<?php
    $wsdl       = 'https://domain.com/?wsdl';
    $certFile   = getcwd() . '/auth/cert.pem';
    $keyFile    = getcwd() . '/auth/key.pem';
    $password   = 'pwd';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,           $wsdl);
    curl_setopt($ch, CURLOPT_SSLCERT,       $certFile);
    curl_setopt($ch, CURLOPT_SSLKEYPASSWD,  $password);
    curl_setopt($ch, CURLOPT_SSLKEY,        $keyFile);
    #curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    #curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    #curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $output = curl_exec($ch);

    var_dump(curl_errno($ch));
    var_dump(curl_error($ch));

我一直得到的结果是错误 58: unable to set private key file: '/home/.../domains/.../public_html/auth/key.pem ' 输入 PEM

到目前为止我尝试过的事情:

我很确定问题出在我的配置中,但我不确定去哪里找。

最佳答案

我已经解决了这个问题。我认为,由于有关此问题的问题数量和不同解决方案的数量,其他人将从该解决方案中受益。开始了:

我使用 openssl CLI 程序将 .p12 key 文件转换为 .pem key 文件。诀窍在于转换发生的方式。

首先我用这个命令转换它,我遇到了问题中描述的问题:

openssl pkcs12 -in key.p12 -out key.pem -nodes -clcerts

虽然下面的命令起到了真正的作用:

openssl pkcs12 -in key.p12 -out key.pem -clcerts

有关更多信息,请参阅我使用的来源:https://community.qualys.com/docs/DOC-3273

关于php - 带有 SSL 证书的 cURL 失败 : error 58 unable to set private key file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27102176/

相关文章:

php - 在收到请求时在 Yii2 中的 $_POST 中设置值?

PHP JSON 扩展

ssl - TLS 握手如何在负载平衡系统中工作?

php - 使用 PHP 和 cURL 防止远程服务器欺骗

php - 通过 Rest Api 进行 Mautic 基本身份验证

http - 将 CURL 转换为 Golang 代码

php - 在 CodeIgniter 输出中使用 Exit 会使内容类型 header 变为 text/html 而不是定义的 header

php - 如何在 laravel 5 中创建全局辅助函数?

amazon-web-services - 对 AWS Elastic Beanstalk 的 HTTPS 请求返回 net::ERR_CERT_COMMON_NAME_INVALID

node.js - 缺少 PFX 或证书 + 私钥