【问题标题】:WS-Security, and how to AuthenticateWS-Security,以及如何进行身份验证
【发布时间】:2018-01-26 07:50:32
【问题描述】:

服务文档说我需要使用 WS-Security。 在他们的支持下,我得到了一个 p12 文件,我应该使用它。

到目前为止我做了什么
我运行了 SoapUI 应用程序,对其进行了配置,添加了 wsdl 等,并收到了消息 <faultstring>These policy alternatives can not be satisfied: (...)</faultstring> 所以我发现我需要在请求中添加基本的身份验证。我得到了正确的答案。

我现在需要什么
我需要在我的 PHP 应用程序上使用它来处理 SOAP 请求。
首先,我将p12 文件更改为pem,然后尝试:

$soapClient = new SoapClient('https://int.pz.gov.pl/pz-services/tpSigning?wsdl',
        array('location' => 'https://int.pz.gov.pl/pz-services/tpSigning?wsdl', 
        'trace' => 1,"exceptions" => 1, 
        'local_cert'=>'path/cert_file.pem',
        'passphrase'=>'cert_password'
));

但我仍然收到关于不满足政策的相同失败消息:

These policy alternatives can not be satisfied: 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}AsymmetricBinding: Received Timestamp does not match the requirements 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}X509Token: The received token does not match the token inclusion requirement 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}SignedParts: Soap Body is not SIGNED in (...)

帮助?
仅使用 PHP 是否有可能?我尝试了几种解决方案,找到了一些扩展 SoapClient 的类(使用用户/密码,而不是 p12/pem 文件),甚至在 c# 中找到了解决方案(如果这是我需要做的,我已经准备好使用它 - 使用 WebSocket 将 xml 发送到 c# ,并将其发送回浏览器),但这些都不起作用。

【问题讨论】:

    标签: php xml web-services soap ws-security


    【解决方案1】:

    将证书更改为 pem 格式是正确的方法。本机 PHP 肥皂客户端类无法处理 p12 证书。您是否尝试过以下方法?

    try {
        $oClient = new SoapClient(
            'https://int.pz.gov.pl/pz-services/tpSigning?wsdl',
            [
                'authentication' => SOAP_AUTHENTICATION_DIGEST,
                'exceptions' => true,
                'local_cert' => dirname(__FILE__) . 'mycert.pem',
                'passphrase' => 'my_passphrase',
                'trace' => true, 
            ]
        );
    } catch (SoapFault $oSoapFault) {
        echo "<pre>";
        var_dump($oSoapFault);
        echo "</pre>";
    }
    

    默认情况下,PHP SOAP 客户端类使用 SOAP_AUTHENTICATION_BASIC。也许 DIGEST auth 是正确的方法?通常证书包括所有数据。

    您不需要位置选项。在没有直接 wsdl 文件的情况下,使用带有目标命名空间的非 wsdl 对话作为 uri 选项时,只需要 location 选项。

    并始终牢记:与 SoapUI 一起工作的东西不应该与本机 PHP 客户端一起运行。 ;)

    【讨论】:

    • 嗯,这不会改变答案。文档不清楚我实际上应该如何处理从他们那里获得的证书。我尝试了一些来自互联网的解决方案,在涉及 XML 时我更接近了一点,但我还有另一个问题,SSL 握手:stackoverflow.com/questions/48463831/…
    • 我已经看到,这是一个 X509 WSSE 请求。好吧,这有点复杂。我过去以面向对象的方式完成了 X509 WSSE 请求,而不使用 XML 作为字符串。这可以用纯 PHP 来完成。我将使用 X509 WSSE 请求查找我的旧存储库,并将其发布在此处作为另一个答案。
    • 那将是很大的帮助!不耐烦地等待:)
    • 前段时间在堆栈溢出时发布的这个不错的解决方案怎么样? stackoverflow.com/questions/24288234/…
    猜你喜欢
    • 2015-10-20
    • 2014-02-01
    • 2016-09-13
    • 1970-01-01
    • 1970-01-01
    • 2016-02-10
    • 2016-09-05
    • 2011-04-30
    • 2011-10-17
    相关资源
    最近更新 更多