Beispiel #1
0
    public function testSignSoapMessage()
    {
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wns1="urn:hello-world:1.0"><SOAP-ENV:Body><wns1:sayHello xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wns1="urn:hello-world:1.0"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
  <ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"></ds:CanonicalizationMethod>
    <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod>
  <ds:Reference URI=""><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod><ds:DigestValue>QG06QpnB5HBcTxoj9sP4lwgr5fs=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>KbCRtraU6vpqojaPm2ArAsWR/2xBqP0J7nplkXUmQpQkoFWiawnIW8pHVp0RWddlyP9TYBT0f10hN75oxkTvtmHQrxwAC6rjngr+872cHLKnpSZlfUVzAd2QSYR6Gbgk/lSKzZInwe9IEhexQjQ1qDldqu62D8imAyllCtg8bCXLfyHFjixLk19IkJoDjDula1PMLPLpEDuSy934jHSiy3PdA1HwNdlw/1oAqnlcrIA152ywAuPdaFMGgV5JqRPBH5y/wHQ0+4g1VlF7pttigFQcrXLEEZUrz2hdkVb71mZNZFlKIZ70Mdh9WjdgmsMpf1d41w9oOKtrzv46roMmIA==</ds:SignatureValue>
<ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIIEVDCCAzygAwIBAgIJAPTrkMJbCOr1MA0GCSqGSIb3DQEBBQUAMHkxCzAJBgNVBAYTAlVTMQ4wDAYDVQQIEwV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B8dtrN5mrt28ILickQjguu46h6vChgQ4YfIAoA1KWNsZJUuuIzTDjE5xz2hsW37CI0yrNesv2ho2hhP+fIaxCGmcwLYXL80UaPRglYk5+wPWFOt3QFAVoEgwjLX9+y+c2Gu7xLgHAFZVRjQ5hhKT0Nj3vhnt0k8LcognNl1wKuWda7VL4tODp/2IOXr5o5v/OL3UesGfeWfvr8LVmMc5f7/vLAu1+2Yk+/C9/EZyf3BDZQ4z8ae/iwqprCTUIEjhUDcq4+0YN2EIw6suGE2FtWlsIywNErmoOhdrmntU61n3nFCQBi7QDUnZrAFrl4/bmk3eRJ00nE=</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature></wns1:sayHello></SOAP-ENV:Body></SOAP-ENV:Envelope>
';
        try {
            $this->client->__call('sayHello', []);
        } catch (\Exception $e) {
            // Ignore
        }
        $lastRequest = $this->client->__getLastRequest();
        TestCase::assertEquals($expected, $lastRequest);
        $dom = new DOMDocument();
        $dom->loadXML($lastRequest);
        $body = $dom->getElementsByTagNameNS($dom->documentElement->namespaceURI, 'Body')->item(0);
        $firstElement = $body->firstChild;
        // Check Signature
        $xmlDSigAdapter = $this->client->getXmlDSigAdapter();
        $newData = new DOMDocument();
        $newData->loadXML($firstElement->C14N());
        TestCase::assertTrue($xmlDSigAdapter->verify($newData));
    }
Beispiel #2
0
 function __doRequest($request, $location, $action, $version, $one_way = 0)
 {
     if (!$this->xmlDSigAdapter) {
         return parent::__doRequest($request, $location, $action, $version, $one_way);
     }
     // Some WS providers use NS1 for his own use and conflicts with the signature calc
     $request = str_replace(array(':ns1', 'ns1:'), array(':wns1', 'wns1:'), $request);
     $dom = new DOMDocument();
     $dom->loadXML($request);
     $body = $dom->getElementsByTagNameNS($dom->documentElement->namespaceURI, 'Body')->item(0);
     $firstElement = $body->firstChild;
     /* Not necessary since ext/Soap don't add Text nodes between Elements
        foreach($body->childNodes as $node){
            if ($node->nodeType === XML_ELEMENT_NODE) {
                $firstElement = $node;
                break;
            }
        }
        */
     $newData = new DOMDocument();
     $newData->loadXML($firstElement->C14N());
     $this->xmlDSigAdapter->sign($newData);
     /* DOM mode for add the signed node
        $firstElement->appendChild($dom->importNode($newData->firstChild->lastChild, true));
        $request = $dom->saveXML();
        */
     /* Compatibility mode for add signed node without lost namespaces declaration */
     $newBody = '<SOAP-ENV:Body>' . $newData->C14N() . '</SOAP-ENV:Body>';
     $request = preg_replace('#<SOAP-ENV:Body>.*</SOAP-ENV:Body>#', $newBody, $request);
     if ($this->debugMode) {
         $this->lastRequest = $request;
     }
     return parent::__doRequest($request, $location, $action, $version, $one_way);
 }