Reputation: 21
I am trying to sign an XML file and in all the requests I make I get the error "Hash values do not match."
This is my XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://ws.hc2.dc.com/v1">
<soapenv:Body wsu:Id="id-2DCB6C8D1D61184E481607306401918160" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<v1:consultarHC2>
<v1:solicitud>
<v1:clave>75URP</v1:clave>
<v1:identificacion>888888881</v1:identificacion>
<v1:primerApellido>PRUEBAS</v1:primerApellido>
<v1:producto>64</v1:producto>
<v1:tipoIdentificacion>1</v1:tipoIdentificacion>
<v1:usuario>830514264</v1:usuario>
</v1:solicitud>
</v1:consultarHC2>
</soapenv:Body>
</soapenv:Envelope>
This is the DigestValu calculated in SoapUI oyEmssDWuGqQejZ4krpKmv2/KJc= however the value calculated in PHP is BzmNrO3Pdl1R6I1MWHw/QG5cn08=
My canonicalized Body element (c14n) looks as follows:
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://ws.hc2.dc.com/v1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-2DCB6C8D1D61184E481607306401918160"> <v1:consultarHC2> <v1:solicitud> <v1:clave>75URP</v1:clave> <v1:identificacion>888888881</v1:identificacion> <v1:primerApellido>PRUEBAS</v1:primerApellido> <v1:producto>64</v1:producto> <v1:tipoIdentificacion>1</v1:tipoIdentificacion> <v1:usuario>830514264</v1:usuario> </v1:solicitud> </v1:consultarHC2> </soapenv:Body>
The DigestValue is being calculated in PHP as follows:
//$data is equal to XML
$data = str_replace(["\r", "\n"], ['', ''], $data);
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->loadXML($data);
$bodyNode = $doc->getElementsByTagName('Body')->item(0);
$canonicalized = $bodyNode->C14N();
//OR
$canonicalized = $bodyNode->C14N(true);
//OR
$canonicalized = $bodyNode->C14N(false,false);
$digest = base64_encode(hash('SHA1', $canonicalized, true));
//OR
$digest = base64_encode(pack("H*", sha1($canonicalized)));
Please tell me what I am doing wrong, I need help I have not yet managed to get the generated value in SoapUI.
Upvotes: 2
Views: 545