我如何获得PHP SOAP客户端运行在SSL使用无效的证书服务进行通信(How do I get t

2019-09-22 07:49发布

我试图使用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使用自签名的证书 - 当我wget的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并没有发现任何帮助。

任何人有什么想法?

Answer 1:

这是两年前,但我认为它应该有自己的答案。

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

朝着解决方案的第一步是使用stream_context构建您的SoapClient的选项时2 。 这将允许您指定更多的高级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流
  2. PHP:SoapClient的和SoapClient ::
  3. PHP:SSL上下文选项


文章来源: How do I get the PHP SOAP client to communicate with a service running over SSL with an invalid certificate
标签: php soap ssl