使用PHP将WSSE头添加到XML

使用PHP将WSSE头添加到XML,php,xml,soap-client,xmlseclibs,Php,Xml,Soap Client,Xmlseclibs,我目前正在开发一个WS-client,它需要在将请求发送到服务器之前对其进行签名。我有一个私钥和一个证书用于此目的,但我正在与安全头斗争。输出XML的预期结构应如下所示: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="ht

我目前正在开发一个WS-client,它需要在将请求发送到服务器之前对其进行签名。我有一个私钥和一个证书用于此目的,但我正在与安全头斗争。输出XML的预期结构应如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-
1.0.xsd"><wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="CertId-45..."
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-
1.0.xsd"> ... </wsse:BinarySecurityToken><ds:Signature Id="Signature-13"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="#id-14">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>62...</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
...
</ds:SignatureValue>
<ds:KeyInfo Id="KeyId-...">
<wsse:SecurityTokenReference wsu:Id="STRId-..." xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-
wss-wssecurity-utility-1.0.xsd"><wsse:Reference URI="#CertId-..." ValueType="http://docs.oasis-
open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/></wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature></wsse:Security></soapenv:Header>
<soapenv:Body wsu:Id="id-14" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
xml
变量包含我知道是正确的xml代码。它已经在SoapUI(我必须提供我的密钥和密码)和我的提供商提供的在线测试服务上进行了测试。这意味着发送的数据是100%正确的

然而,我的PHP代码以“内部错误”结束。我认为这与缺乏证书等有关。我不确定是否有办法从回复中获得更多信息,但没有关于上述错误的文档

我一直在玩弄几种格式的选项和密钥库、私钥和证书,但没有得到任何积极的结果。我认为这一切都与没有发送正确的标题有关


非常感谢。

您在这里要求不高。不清楚您得到了哪些错误,也不清楚具体是什么在起作用。所以实际上你的问题似乎太宽泛了。关于如何使用PHP创建和添加WSSE标题的现有资料实际上甚至已经存在于本网站上,因此,明确地说,绝对不清楚您在这里要求的是什么,正如标题中的文本所示,这个问题以前曾被问过,但您没有强调它与现有资料的不同之处。此外,您可能根本不需要任何头,因为证书是在SOAP之上的传输层上处理的。大多数人似乎使用用户名和密码身份验证。我必须发送我的提供者指定的标题。我不认为它太宽,因为问题很具体:生成如图所示的头文件。您已经能够创建XML签名了吗?您是否已经能够创建SOAP头,并且能够针对远程系统验证这一点?您当前的代码是什么样子的?您从远程系统返回的错误是什么?关于您返回的错误消息或代码,远程系统的文档说明了什么?到目前为止,你在解决这个问题上遇到了什么困难?我正在吃午饭,我会尽快补充信息。不要着急,慢慢吃更重要:)
$context = stream_context_create(array(
    'ssl' => array(
        'verify_peer' => false,
        'allow_self_signed' => true,
        'ciphers'=>'SSLv3'
    )
));

$client = new SoapClient($url, array(
    //'connection_timeout' => 100,
   /* 'passphrase' => $pass,

    'local_cert' => $keystore,*/
    'stream_context' => $context,
   // 'connection_timeout' => 1,
    'trace' => true, 
    'exceptions' => true
));

$soapBody = new \SoapVar($xml, \XSD_ANYXML);

try{
    $client->__soapCall('SOMEACTION', array($soapBody));
}
catch (SoapFault $exception) {
        echo $exception->getMessage();

    }