Dgitally signing the XML request

272 views
Skip to first unread message

Milind Bhadange

unread,
Apr 1, 2013, 2:14:33 AM4/1/13
to xmlse...@googlegroups.com
Hi,
 
I am trying to create the soap request using this library. I need to create digitally signing the XML request  (i.e. generate the envelope the digest value is expected to be the hash of the message generated after using the certificates.). For that I am writing below code:
 
<?php
 
$xml = '
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.service.com">
 <soapenv:Header>
  <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/xx/secext">
   <wsse:UsernameToken>
    <wsse:Username>user@service</wsse:Username>
    <wsse:Password>a1234567</wsse:Password>
   </wsse:UsernameToken>  
  </wsse:Security>
 </soapenv:Header>
 <soapenv:Body>
  <ws:Request>
   <ws:secrtySbj>
    <ws:usrname>SOAPAPI@user</ws:usrname>
    <ws:pswrd>newYear2012</ws:pswrd>
   </ws:secrtySbj>
   <ws:doc>
.
.
.
.
.
   </ws:doc>
    </soapenv:Body>
</soapenv:Envelope>';
$doc = new DOMDocument();
$doc->formatOutput = true;
$doc->preserveWhiteSpace = false;
$doc->loadXML($xml);
$objDSig = new XMLSecurityDSig(FALSE);
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
//$objDSig->addObject($doc->documentElement);
$objDSig->addReference($doc, XMLSecurityDSig::SHA1, array('http://www.w3.org/2000/09/xmldsig#enveloped-signature'));
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private'));
/* load private key */
$objKey->loadKey(dirname(__FILE__) . '/privkey.pem', TRUE);
$objDSig->sign($objKey);
/* Add associated public key */
$objDSig->add509Cert(file_get_contents(dirname(__FILE__) . '/mycert.pem'));
$objDSig->appendSignature($doc->firstChild->firstChild->firstChild);
$request = $doc->saveXML();
 
?>
 
 
But when I trying to send this request I am getting following error in response:
 
 
<?xml version="1.0" encoding="UTF-8"?>

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<env:Fault>
<faultcode>XML Parse Error</faultcode>
<faultstring>Hash values do not match.</faultstring>
<faultactor>ADP Secure Web Services Gateway</faultactor></env:Fault></env:Body></env:Envelope>
 
 
Anybody out there, who could please help me with what is wrong here?
 
 
Regards,
Milind
 
 
Reply all
Reply to author
Forward
0 new messages