简体   繁体   English

cURL无法使用客户端证书(找不到密钥或错误的密码?)

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

I have read and tried thousands of solutions in different posts and none of them seems to work with me. 我已经在不同的帖子中阅读并尝试了数以千计的解决方案,但似乎没有一个与我合作。 This three are example of that. 这三个就是这样的例子。

cURL is unable to use client certificate , in local server cURL无法在本地服务器中使用客户端证书

php openssl_get_publickey() and curl - unable to use client certificate (no key found or wrong pass phrase?) php openssl_get_publickey()和curl - 无法使用客户端证书(找不到密钥或错误的密码?)

Getting (58) unable to use client certificate (no key found or wrong pass phrase?) from curl 获取(58)无法使用客户端证书(没有找到密钥或错误的密码?)来自curl

I received a .p12 certificate which I converted to .pem file in https://www.sslshopper.com/ssl-converter.html 我收到了.p12证书,我在https://www.sslshopper.com/ssl-converter.html转换为.pem文件

The password is correct otherwise it wouldn't convert it. 密码是正确的,否则它不会转换它。

$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));

I have tried with SoapUI application and works fine but with cURL I'm receiving the error: 我尝试过使用SoapUI应用程序并且工作正常但是使用cURL我收到错误:

unable to use client certificate (no key found or wrong pass phrase?) 无法使用客户端证书(没有找到密钥或错误的密码?)

I have tried without success: 我试过没有成功:

  1. Disable CURLOPT_SSL_VERIFYPEER and/or CURLOPT_SSL_VERIFYHOST 禁用CURLOPT_SSL_VERIFYPEER和/或CURLOPT_SSL_VERIFYHOST
  2. Add CURLOPT_SSLKEYTYPE and/or CURLOPT_SSLKEY fields 添加CURLOPT_SSLKEYTYPE和/或CURLOPT_SSLKEY字段

EDIT 1: 编辑1:

I have been trying around with SOAPClient besides cURL and it seems that the error might be the headers. 除了cURL,我一直在尝试使用SOAPClient,似乎错误可能是标题。

My headers after print_r($soapClient) are the following: 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

I would like to know how can I remove the action="" ? 我想知道如何删除action="" I tried to extend the original class without success in terms of changing the header. 我试图在更改标题方面扩展原始类但没有成功。

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));
   }
}

Solved with cURL. 解决了cURL。

The problem was the path of the pem file. 问题是pem文件的路径。

I was using base_url() . 'public/cert.pem' 我正在使用base_url() . 'public/cert.pem' base_url() . 'public/cert.pem' but that's not possible. base_url() . 'public/cert.pem'但这是不可能的。 Instead I need to use a relative path such as ./public/cert.pem . 相反,我需要使用相对路径,如./public/cert.pem

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP CURL错误:无法使用客户端证书(找不到密钥或密码短语错误?) - PHP CURL error: unable to use client certificate (no key found or wrong pass phrase?) 卷曲失败,并显示错误#58:无法使用客户端证书(找不到密钥或密码短语错误?) - Curl failed with error #58: unable to use client certificate (no key found or wrong pass phrase?) 无法使用客户端证书(找不到密钥或密码错误?) - unable to use client certificate(no key found or wrong pass phrase?) 贝宝(PHP):无法使用客户端证书(找不到密钥或密码错误?) - Paypal(PHP): unable to use client certificate (no key found or wrong pass phrase?) cURL无法在本地服务器中使用客户端证书 - cURL is unable to use client certificate , in local server PHP CURL“ NSS:找不到客户端证书(未指定昵称)”问题 - PHP CURL “NSS: client certificate not found (nickname not specified)” Issue Curl 失败:NSS:未找到客户端证书(未指定昵称)-在 Centos 7 - Curl failed: NSS: client certificate not found (nickname not specified) - On Centos 7 NSS:找不到带有CURL的Paypal的客户端证书(未指定昵称) - NSS: client certificate not found (nickname not specified) with Paypal with CURL 在PHP中使用curl和客户端证书以及单独文件中的私钥 - Using curl in php with client certificate and private key in separate files cURL 58错误无法加载客户端密钥-8178 - cURL 58 error Unable to load client key -8178
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM