繁体   English   中英

如何让PHP SOAP客户端与使用无效证书通过SSL运行的服务进行通信

[英]How do I get the PHP SOAP client to communicate with a service running over SSL with an invalid certificate

我正在尝试使用PHP SOAP客户端使用SOAP服务,但它失败并显示以下消息:

SoapFault: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://domain.com/webservice.asmx?wsdl' : failed to load external entity "https://domain.com/webservice.asmx?wsdl"\n in /Users/andrewdchancox/Projects/test/testsoap.php on line 10

我已经下载了wsdl文件并从本地的apache实例提供它,并且它没有任何问题加载。 我唯一能想到的可能是Web服务通过SSL运行并带有自签名证书 - 当我忘记wsdl时,我收到以下错误:

--2012-09-11 16:28:39--
https://domain.com/webservice.asmx?wsdl
Resolving domain.com (domain.com)... 11.111.111.11
Connecting to domain.com (domain.com)|11.111.111.11|:443... connected.
ERROR: The certificate of ‘domain.com’ is not trusted.
ERROR: The certificate of ‘domain.com’ hasn't got a known issuer.

我已经google了一下并彻底阅读了PHP SOAP客户端的PHP文档 - http://php.net/manual/en/class.soapclient.php和它的构造函数 - http://www.php.net/manual/ en / soapclient.soapclient.php并没有找到任何帮助。

有人有任何想法吗?

这是两年前,但我认为值得回答。

PHP中的SoapClient类使用PHP流通过HTTP进行通信。 由于各种原因,SSL over PHP流是不安全的1 ,但在这种情况下,你的问题是它太安全了。

解决方案的第一步是在构建SoapClient 2时使用stream_context选项。 这将允许您指定更高级的SSL设置3

// Taken from note 1 below.
$contextOptions = array(
    'ssl' => array(
        'verify_peer'   => true,
        'cafile'        => '/etc/ssl/certs/ca-certificates.crt',
        'verify_depth'  => 5,
        'CN_match'      => 'api.twitter.com',
        'disable_compression' => true,
        'SNI_enabled'         => true,
        'ciphers'             => 'ALL!EXPORT!EXPORT40!EXPORT56!aNULL!LOW!RC4'
    )
);
$sslContext = stream_context_create($contextOptions);
// Then use this context when creating your SoapClient.
$soap = new SoapClient('https://domain.com/webservice.asmx?wsdl', array('stream_context' => $sslContext));

解决问题的理想方法是创建自己的CA证书,使用该证书签署SSL证书,并将CA证书添加到cafile 更好的方法可能是cafile拥有该证书,以避免一些流氓CA为您的域签署别人的证书,但这并不总是实用的。

如果您正在执行的操作不需要是安全的(例如在测试期间),您还可以在流上下文中使用SSL设置来降低连接的安全性。 allow_self_signed选项将允许自签名证书:

$contextOptions = array(
    'ssl' => array(
        'allow_self_signed' => true,
    )
);
$sslContext = stream_context_create($contextOptions);
$soap = new SoapClient('https://domain.com/webservice.asmx?wsdl', array('stream_context' => $sslContext));

链接:

  1. 生存深层:PHP安全 - 传输层安全性(HTTPS,SSL和TLS) - PHP Streams
  2. PHP:SoapClient :: SoapClient
  3. PHP:SSL上下文选项

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM