Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
591 views
in Technique[技术] by (71.8m points)

php - cURL错误(58):无法设置私钥文件:'/var/www/work/xml/keys/client.pem'类型PEM(cURL Error (58): unable to set private key file: '/var/www/work/xml/keys/client.pem' type PEM)

I am getting this error, while connecting to a server using private and public keys.

(使用私钥和公钥连接到服务器时,出现此错误。)

cURL Error (58): unable to set private key file: '/var/www/work/xml/keys/client.pem' type PEM

(cURL错误(58):无法设置私钥文件:'/var/www/work/xml/keys/client.pem'类型PEM)

My private keys contain both key and certificate.

(我的私钥包含密钥和证书。)

It has also password.

(它也有密码。)

My current code is here:

(我当前的代码在这里:)

    $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
";
    }
    else 
    {
        header("Content-Type: text/xml");
        print_r($data);
    }

    curl_close($ch);
  ask by Gajendra Bang translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

it appears your script can not access the $keyfile file correctly.

(看来您的脚本无法正确访问$keyfile文件。)

you may want to double-check that your script (or process) has the correct privileges, or modify the file permissions.

(您可能需要仔细检查您的脚本(或进程)是否具有正确的特权,或修改文件许可权。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...