带SSL证书的cURL失败:错误58无法设置私钥文件

Ben*_*Ben 9 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));
Run Code Online (Sandbox Code Playgroud)

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

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

我很确定问题在于我的配置,但我不确定在哪里看.

Ben*_*Ben 15

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

我使用opensslCLI程序将.p12密钥文件转换为.pem密钥文件.诀窍是转换的方式.

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

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

  • `-nodes`删除密钥上的加密,这可能与您在此情况下尝试使用密码冲突. (2认同)