【问题标题】:cURL unable to use client certificate (no key found or wrong pass phrase?)cURL 无法使用客户端证书(找不到密钥或密码错误?)
【发布时间】:2016-02-17 19:47:59
【问题描述】:

我在不同的帖子中阅读并尝试了数千种解决方案,但似乎没有一个适合我。这三个就是例子。

cURL is unable to use client certificate , in local server

php openssl_get_publickey() and curl - unable to use client certificate (no key found or wrong pass phrase?)

Getting (58) unable to use client certificate (no key found or wrong pass phrase?) from 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));
   }
}

【问题讨论】:

    标签: php ssl curl


    【解决方案1】:

    已解决与 cURL。

    问题是pem 文件的路径。

    我使用的是base_url() . 'public/cert.pem',但这是不可能的。相反,我需要使用相对路径,例如./public/cert.pem

    【讨论】:

      猜你喜欢
      • 2015-06-30
      • 2016-06-14
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      • 1970-01-01
      • 1970-01-01
      • 2014-01-24
      相关资源
      最近更新 更多