尝试访问 soap 网络服务器时出现 cURL 错误 58

cURL error 58 while trying to access soap webserver

我正在尝试通过 https 调用(通过 PHP 脚本)远程 (SOAP) 网络服务器,它需要受密码保护的证书。 我正在使用 nuSoap 进行调用,但我总是收到以下错误

nusoap_client:出现 wsdl 错误:正在获取 https://ws-t.pitre.tn.it/wcfrouting/wsdl/Documents.wsdl - HTTP 错误:cURL 错误: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

我得到了相同的结果。

我是不是漏掉了什么?

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

我无法让它与 nu_soap 一起使用,所以我切换到 SoapClient

首先我必须使用 openssl 将我的 p12 证书转换为 pem 格式

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

我希望这对面临同样问题的人有所帮助