2017-09-06 107 views
1

我想通过https调用(通过PHP脚本)远程(SOAP)web服务器,它需要密码保护证书。 我使用的NuSOAP制作的电话,但我总是得到以下错误cURL错误58试图访问肥皂web服务器

nusoap_client:有WSDL错误:获取https://ws-t.pitre.tn.it/wcfrouting/wsdl/Documents.wsdl - HTTP错误:卷曲ERROR:58:无法使用客户证书(找不到钥匙或错误的口令?)

require_once("../nusoap/lib/nusoap.php"); 

$pitre_wsdl = "https://ws-t.pitre.tn.it/wcfrouting/wsdl/Documents.wsdl"; 
$client = new nusoap_client($pitre_wsdl, "wsdl"); 
$err = $client->getError(); 

if ($err) { 
    print("Error"); 
    exit(); 
} 

$client->setCredentials(
    "", 
    "", 
    "certificate", 
    array (
     "sslcertfile" => "../pitre/cert.p12", 
     "sslkeyfile" => "../pitre/cert.p12", 
     "certpassword" => "mypass", 
     "verifypeer" => FALSE, 
     "verifyhost" => FALSE 
    ) 
); 

$result = $client->call(
    "GetTemplatesDocuments", 
    array (
     "CodeAdm" => "myCode" 
    ) 
); 

与浏览器我可以访问wisdl没有问题。我尝试了以下的回答:

cURL with SSL certificates fails: error 58 unable to set private key file

我得到了相同的结果。

我错过了什么吗?

回答

1

我找到了答案,我的解决方案如下:

我无法使其与nu_soap工作,所以我切换到SoapClient的

我不得不转换之拳我的P12证书PEM格式使用OpenSSL的

openssl pkcs12 -in certificato.p12 -out certificato.pem -clcerts 

于是我下载了CA证书从这里https://curl.haxx.se/docs/caextract.html

这是我工作的代码

$params->a    = "a"; 
$params->b    = "b"; 
$params->c    = "c"; 
$params->d    = "d"; 
$params->e    = "e"; 

$context = stream_context_create(array (
    "ssl" => array (
     "verify_peer"  => false, 
     "verify_peer_name" => true, 
     "local_cert"  => getcwd()."\certificato.pem", //complete path is mandatory 
     "passphrase"  => "mypassphrase", 
     "allow_self_signed" => true 
    ), 
    "https" => array (
     "curl_verify_ssl_peer" => false, 
     "curl_verify_ssl_host" => false 
    ) 
)); 

$pitre_client = new SoapClient($pitre_wsdl, array (
    "trace"    => 1, 
    "exceptions"  => true, 
    "location"   => "https://ws-t.pitre.tn.it/wcfrouting/servicerouter.svc", 
    "cafile"   => getcwd()."\cacert.pem", //complete path is mandatory 
    "stream_context" => $context 
)); 

// the call 
$response = $pitre_client->GetTemplatesDocuments(
    array (
     'request' => $params //request key can be different 
    ) 
); 

我希望这会帮助别人面临着同样的问题