2016-09-27 52 views
1

我的Pem文件採用此格式。捲曲錯誤:無法設置私鑰文件:'test.pem'類型PEM

Bag Attributes 
localKeyID: 
friendlyName: test 
subject=/C=GB/ST=London/L=Soho/O=Rightmove/OU=RTDF/CN=cmexpertise 
issuer=/C=GB/ST=London/L=Soho/O=Rightmove/OU=Operations/CN=RTDF Test Issuing CA v3/[email protected] 
-----BEGIN CERTIFICATE----- 

-----END CERTIFICATE----- 

Bag Attributes 
localKeyID: 
friendlyName: test 
subject=/C=GB/ST=London/L=Soho/O=Rightmove/OU=RTDF/CN=cmexpertise 
issuer=/C=GB/ST=London/L=Soho/O=Rightmove/OU=Operations/CN=RTDF Test Issuing CA v3/[email protected] 
-----BEGIN CERTIFICATE----- 

-----END CERTIFICATE----- 

Bag Attributes 
localKeyID: 
friendlyName: test 
subject=/C=GB/ST=London/L=Soho/O=Rightmove/OU=RTDF/CN=cmexpertise 
issuer=/C=GB/ST=London/L=Soho/O=Rightmove/OU=Operations/CN=RTDF Test Issuing CA v3/[email protected] 
-----BEGIN RSA PRIVATE KEY----- 
Proc-Type: 4,ENCRYPTED 
DEK-Info: DES-EDE3-CBC,B9E036426B7AEDA6 
-----END RSA PRIVATE KEY----- 

我正在使用PHP的這段代碼。我收到這個錯誤。

Curl Error: unable to set private key file: 'test.pem' type PEM

代碼。

$json_data // it's a json array. 

    $url = "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails"; 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 

    // $pemFile = tmpfile(); 
    // fwrite($pemFile, "test.pem"); //the path for the pem file 
    // $tempPemPath = stream_get_meta_data($pemFile); 
    // $tempPemPath = $tempPemPath['uri']; 

    curl_setopt($ch, CURLOPT_SSLCERT, "test.pem"); 
    curl_setopt($ch,CURLOPT_SSLCERTTYPE,"PEM"); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/javascript')); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, True); 
    curl_setopt($ch, CURLOPT_POST, True); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); 
    curl_setopt($ch, CURLOPT_VERBOSE, true); 

    $result = curl_exec($ch); 

    if(!$result) 
    { 
     echo "Curl Error: " . curl_error($ch); 
    } 
    else 
    { 
     echo "Success: ". $result; 
    } 

    $info = curl_getinfo($ch); 

    curl_close($ch); // close cURL handler 

    if (empty($info['http_code'])) { 
      die("No HTTP code was returned"); 
    } else { 
     // load the HTTP codes 
     $http_codes = parse_ini_file("path/to/the/ini/file/I/pasted/above"); 

     // echo results 
     echo "The server responded: <br />"; 
     echo $info['http_code'] . " " . $http_codes[$info['http_code']]; 
    } 

我的證書解碼器在網上查詢: https://www.sslshopper.com/certificate-decoder.html 和證書是在本網站有效。

那麼這裏有什麼問題我無法弄清楚。 我也嘗試過使用ssl命令。

+1

捲曲錯誤:無法加載PEM客戶端證書,OpenSSL的錯誤錯誤:0200107B:系統庫:FOPEN:未知的錯誤,(找不到鑰匙,錯誤的密碼短語,或錯誤的文件格式?)。這是我使用php代碼和pem文件時得到的錯誤。原因是該文件中的私鑰與證書中的相應公鑰不匹配。 – Veeram

+0

@Reddy。謝謝你的回覆。有兩個錯誤,一個是pem文件錯誤,另一個錯誤是我沒有在代碼中包含CURLOPT_SSLCERTPASSWD()。 – Bhavin

回答

0

有兩個錯誤。

  • 一個錯誤是pem文件在pem文件生成中存在錯誤。
  • 另一個錯誤是我沒有在代碼中包含CURLOPT_SSLCERTPASSWD()。

代碼,

curl_setopt($ch,CURLOPT_SSLCERTTYPE,"PEM"); 
    curl_setopt($ch, CURLOPT_SSLCERT, "test.pem"); 
    curl_setopt($ch, CURLOPT_SSLCERTPASSWD, '******'); // password 
相關問題