Reputation: 71
I got correctly signed XML file generated by SoapUI. Code below is part of WSSE Header.
<ds:Reference URI="#id-AF3B7DA5121961AAD81538052175642352">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces PrefixList="k20 k201 v20 v201 v202 w" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>1rHcIC43O2CYNQesaNK/uQpnJ8M=</ds:DigestValue>
</ds:Reference>
As we can see the DigestValue is equal to 1rHcIC43O2CYNQesaNK/uQpnJ8M= but after my calculation is equal to sc6nLxoiPHloI1X/ufbMEMFEd6c=
My canonicalized Body element (c14n) looks as follows:
<soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-AF3B7DA5121961AAD81538052175642352"><v20:WyszukanieReceptWystawiajacegoRequest><kryteriaWyszukiwaniaRecept></kryteriaWyszukiwaniaRecept></v20:WyszukanieReceptWystawiajacegoRequest></soapenv:Body>
I am writing in PHP. To calculate DigestValue I'm using:
$canonicalizedXml = $doc->C14N(true, false, null, ['k20', 'k201', 'v20', 'v201', 'v202', 'w']);
$hash = sha1($canonicalizedXml, true);
$digestValue = base64_encode($hash);
Please tell me what I'm doing wrong.
Upvotes: 4
Views: 1354
Reputation: 71
Problem solved - To use C14N we need to load whole document and after that load the body element. C14N will add some attributes to body from root tag.
$bodyNode = $doc->getElementsByTagName('Body')->item(0);
$canonicalizedXml = $bodyNode->C14N(true, false, null, ['k20', 'k201', 'v20', 'v201', 'v202', 'w']);
$hash = sha1($canonicalizedXml, true);
$digestValue = base64_encode($hash);
Upvotes: 3