Skip to content

Commit

Permalink
Enable reference check
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed Apr 11, 2013
1 parent 07ccb29 commit 6e68544
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/FR3D/XmlDSig/Adapter/XmlseclibsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,18 @@ public function verify(DOMDocument $data)
$objKey->loadKey($this->getPublicKey());
}

//$objXMLSecDSig->validateReference();
return (1 === $objXMLSecDSig->verify($objKey));
// Check signature
if (1 !== $objXMLSecDSig->verify($objKey)) {
return false;
}

// Check references (data)
try {
$objXMLSecDSig->validateReference();
} catch(\Exception $e) {
return false;
}

return true;
}
}
25 changes: 25 additions & 0 deletions test/FR3D/XmlDSigTest/Adapter/CommonTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace FR3D\XmlDSigTest\Adapter;

use DOMDocument;
use DOMXPath;
use FR3D\XmlDSig\Adapter\AdapterInterface;

/**
Expand Down Expand Up @@ -59,4 +60,28 @@ public function testVerify()

$this->assertTrue($this->adapter->verify($data));
}

public function testManipulatedData()
{
$data = new DOMDocument();
$data->load(__DIR__ . '/_files/basic-doc-signed.xml');

$xpath = new DOMXPath($data);
$xpath->registerNamespace('s', 'urn:envelope');
$xpath->query('//s:Value')->item(0)->nodeValue = 'wrong test';

$this->assertFalse($this->adapter->verify($data));
}

public function testManipulatedSignature()
{
$data = new DOMDocument();
$data->load(__DIR__ . '/_files/basic-doc-signed.xml');

$xpath = new DOMXPath($data);
$xpath->registerNamespace('s', 'urn:envelope');
$xpath->query('//s:Value')->item(0)->nodeValue = 'wrong test';

$this->assertFalse($this->adapter->verify($data));
}
}

0 comments on commit 6e68544

Please sign in to comment.