带有 SSL 证书的 PHP SOAP 客户端 [英] PHP SOAP client with certificates over SSL

查看:38
本文介绍了带有 SSL 证书的 PHP SOAP 客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码设置 Soap 客户端:

I'm trying to set up a Soap client with the following code:

<?php
$wsdl           = 'https://domain.com/?wsdl';
$endpoint       = 'https://domain.com';
$certificate    = dirname(__FILE__) . '/CertWithKey.pem';
$password       = 'pwd';

$options = array(
    'location'      => $endpoint,
    'keep_alive'    => true,
    'trace'         => true,
    'local_cert'    => $certificate,
    'passphrase'    => $password,
    'cache_wsdl'    => WSDL_CACHE_NONE
);

try {
    $soapClient = new SoapClient($wsdl, $options);
} catch(Exception $e) {
    var_dump($e);
}

我得到了一个带有 .crt 认证文件的 .p12 密钥文件.使用 openssl 我已将 .p12 文件转换为 .pem 文件,然后将其与 .crt 文件合并.CertWithKey.pem 看起来不错,文件中有两个证书块.

I was given a .p12 key-file with a .crt certification file. Using openssl I've converted the .p12-file to a .pem-file and then merged it with the .crt-file. The CertWithKey.pem looks good to me, two certificate-blocks are in the file.

无论我尝试做什么,我总是收到一个异常消息 SOAP-ERROR: Parsing WSDL: 无法从https://domain.com/?wsdl"加载:加载失败外部实体https://domain.com/?wsdl".

No matter what I try to do, I keep getting an exception with the message SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://domain.com/?wsdl' : failed to load external entity "https://domain.com/?wsdl".

在与远程方通话后,他们承认有请求进入,但他们记录了此错误:ssl 握手被系统中断 [提示:在浏览器中按下停止按钮?!].

After phoning with the remote party they acknowlegde that a request is coming in but they're logging this error: ssl handshake interrupted by system [hint: stop button pressed in browser?!].

由于目前我在网上没有找到任何有用的信息,所以我想请教大家对此事的一些见解.

Since I didn't find any useful information on the net so far I figured to ask you guys for some insight on the matter.

有什么建议可以尝试吗?我正在运行 PHP 5.3.8,并且服务器的 IP 地址在远程方的防火墙中被列入白名单.

Any suggestions what can be tried? I'm running PHP 5.3.8 and the server's IP-address is white listed in the firewall at the remote party.

推荐答案

我已经解决了这个问题.我认为,由于有关此问题的问题数量和不同解决方案的数量,其他人将从该解决方案中受益.这是:

I've fixed this problem. I think, due to the number of questions regarding this issue and number of different solutions, others will benefit from the solution. Here goes:

我使用 openssl CLI 程序将 .p12 密钥文件转换为 .pem 密钥文件.诀窍在于转换发生的方式.

I used the openssl CLI program to convert the .p12 key-file to a .pem key-file. The trick is the way the conversion takes place.

首先我用这个命令转换它,我遇到了问题中描述的问题:

First I converted it with this command and I had the issue as described in the question:

openssl pkcs12 -in key.p12 -out key.pem -nodes -clcerts

虽然下面的命令做了实际的技巧:

While the command below did the actual trick:

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

有关更多信息,请参阅我使用的来源:https://community.qualys.com/文档/DOC-3273

For more info please see the source I used: https://community.qualys.com/docs/DOC-3273

这篇关于带有 SSL 证书的 PHP SOAP 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆