2017-02-26 55 views
0

我試圖使用PHP中的Curl連接到一個單一登錄API 但我得到一個-8018錯誤。 我將私鑰轉換爲RSA密鑰。但我仍然是一個錯誤。PHP捲曲錯誤:無法加載客戶端證書-8018。 (連接到SSO API)

這裏是PHP源:

$cert_file = 'etc/pki/nssdb/new.pem'; 
    $cert_password = '123456'; 
    curl_setopt_array($curl, array(
     CURLOPT_URL => "UUL" 
     CURLOPT_RETURNTRANSFER => true, 
     CURLOPT_ENCODING => "", 
     CURLOPT_MAXREDIRS => 10, 
     CURLOPT_TIMEOUT => 300, 
     CURLOPT_SSL_VERIFYPEER => false, 
     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
     CURLOPT_CUSTOMREQUEST => "POST", 
     CURLOPT_SSLCERT => $cert_file, 
     CURLOPT_SSLCERTPASSWD => $cert_password, 
     CURLOPT_SSLCERTTYPE => 'pem', 
     CURLOPT_HTTPHEADER => array(
      "cache-control: no-cache", 
      "X-IAS-APIKEY: PEdk3kOkMtYsYzfb", 
      'Content-Length: 0', 
     ), 
    )); 
    $response = curl_exec($curl); 
    $err = curl_error($curl); 

    curl_close($curl); 
    if ($err) { 
     echo "cURL Error #:" . $err; 
    } else { 
     echo $response; 
    } 
} 

下面是結果(添加在NSS DB證書後)

回答

0

我解決了problem.The問題是RSA密鑰不證書信息。我將證書密鑰轉換爲RSA,但該文件沒有證書信息,我們必須隨密鑰一起提交。所以通過導出公共部分,然後私有RSA部分,並最終將它們放在代碼中一起工作。

$cert_password = '****'; 
    curl_setopt_array($curl, array(
     CURLOPT_URL => URL, 
     CURLOPT_RETURNTRANSFER => true, 
     CURLOPT_ENCODING => "", 
     CURLOPT_MAXREDIRS => 10, 
     CURLOPT_TIMEOUT => 300, 
     CURLOPT_SSL_VERIFYPEER => false, 
     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
     CURLOPT_CUSTOMREQUEST => "POST", 
     CURLOPT_SSLCERT => $cert_file, 
     CURLOPT_SSLKEY => $cert_key, 
     CURLOPT_SSLCERTPASSWD => $cert_password, 
     CURLOPT_SSLCERTTYPE => 'pem', 
     CURLOPT_HTTPHEADER => array(
      "cache-control: no-cache", 
      "X-IAS-APIKEY: APIKEY", 
      'Content-Length: 0', 
     ), 
    )); 
    $response = curl_exec($curl); 
    $err = curl_error($curl); 

我希望這個答案可以幫助某人。

謝謝你