簡體   English   中英

cURL無法使用客戶端證書(找不到密鑰或錯誤的密碼?)

[英]cURL unable to use client certificate (no key found or wrong pass phrase?)

我已經在不同的帖子中閱讀並嘗試了數以千計的解決方案,但似乎沒有一個與我合作。 這三個就是這樣的例子。

cURL無法在本地服務器中使用客戶端證書

php openssl_get_publickey()和curl - 無法使用客戶端證書(找不到密鑰或錯誤的密碼?)

獲取(58)無法使用客戶端證書(沒有找到密鑰或錯誤的密碼?)來自curl

我收到了.p12證書,我在https://www.sslshopper.com/ssl-converter.html轉換為.pem文件

密碼是正確的,否則它不會轉換它。

$xml = 'my xml here';
$url = 'https://qly.mbway.pt/Merchant/requestFinancialOperationWS';

$headers = array( 
    'Content-Type: text/xml; charset="utf-8"', 
    'Content-Length: ' . strlen($xml), 
    'Accept: text/xml', 
    'Cache-Control: no-cache', 
    'Pragma: no-cache'
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSLCERT, base_url() . 'public/cert.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'my password here');
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 

$data = curl_exec($ch); 

if(!$data)
    print_r('ERROR: ' . curl_error($ch));
else
    print_r('SUCCESS: ' . curl_error($ch));

我嘗試過使用SoapUI應用程序並且工作正常但是使用cURL我收到錯誤:

無法使用客戶端證書(沒有找到密鑰或錯誤的密碼?)

我試過沒有成功:

  1. 禁用CURLOPT_SSL_VERIFYPEER和/或CURLOPT_SSL_VERIFYHOST
  2. 添加CURLOPT_SSLKEYTYPE和/或CURLOPT_SSLKEY字段

編輯1:

除了cURL,我一直在嘗試使用SOAPClient,似乎錯誤可能是標題。

print_r($soapClient)之后的標題如下:

Host: qly.mbway.pt
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.5.9-1ubuntu4.14
Content-Type: application/soap+xml; charset=utf-8; action=""
Content-Length: 1750

我想知道如何刪除action="" 我試圖在更改標題方面擴展原始類但沒有成功。

class MySoapClient extends SoapClient 
{   
   public function __construct($wsdl, $options = array())
   {
     $ctx_opts = array('http' => array('header' => array('Content-Type' => 'application/soapyyyyyml')));

     $ctx = stream_context_create($ctx_opts);

     parent::__construct($wsdl, array('stream_context' => $ctx));
   }
}

解決了cURL。

問題是pem文件的路徑。

我正在使用base_url() . 'public/cert.pem' base_url() . 'public/cert.pem'但這是不可能的。 相反,我需要使用相對路徑,如./public/cert.pem

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM