cURL错误(58):无法设置私钥文件:“/var/www/work/xml/keys/客户端.pem”类型的PEM

iqjalb3h  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(67)

我在使用私钥和公钥连接到服务器时遇到此错误。

cURL错误(58):无法设置私钥文件:“/var/www/work/xml/keys/客户端.pem”类型的PEM

我的私钥包含密钥和证书。它也有密码。
我的当前代码如下:

$url="https://example.website.com";

    $pemfile = "/var/www/work/xml/keys/server.pem";
    $keyfile = "/var/www/work/xml/keys/client.pem";

    $requestXml = file_get_contents("net.xml");

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_HTTP_VERSION, 1.1); 
    curl_setopt($ch, CURLOPT_PORT, 443); 
    curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);

    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 

    curl_setopt($ch, CURLOPT_FAILONERROR, 0); 

    curl_setopt($ch, CURLOPT_SSLCERT, $pemfile); 
    curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM'); 
    curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'PASSWORD'); 

    curl_setopt($ch, CURLOPT_SSLKEY, $keyfile); 
    curl_setopt($ch, CURLOPT_SSLKEYPASSWD, "PASSWORD");

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXml);

    $data = curl_exec($ch);
    $curl_errno = curl_errno($ch);
    $curl_error = curl_error($ch);

    if ($curl_errno > 0) 
    {
        echo "cURL Error ($curl_errno): $curl_error\n";
    }
    else 
    {
        header("Content-Type: text/xml");
        print_r($data);
    }

    curl_close($ch);
yvfmudvl

yvfmudvl1#

您的脚本似乎无法正确访问$keyfile文件。您可能需要仔细检查您的脚本(或进程)是否具有正确的权限,或者修改文件权限。

相关问题