1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\XMLSecurity; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* xmlseclibs.php |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2007-2017, Robert Richards <[email protected]>. |
9
|
|
|
* All rights reserved. |
10
|
|
|
* |
11
|
|
|
* Redistribution and use in source and binary forms, with or without |
12
|
|
|
* modification, are permitted provided that the following conditions |
13
|
|
|
* are met: |
14
|
|
|
* |
15
|
|
|
* * Redistributions of source code must retain the above copyright |
16
|
|
|
* notice, this list of conditions and the following disclaimer. |
17
|
|
|
* |
18
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
19
|
|
|
* notice, this list of conditions and the following disclaimer in |
20
|
|
|
* the documentation and/or other materials provided with the |
21
|
|
|
* distribution. |
22
|
|
|
* |
23
|
|
|
* * Neither the name of Robert Richards nor the names of his |
24
|
|
|
* contributors may be used to endorse or promote products derived |
25
|
|
|
* from this software without specific prior written permission. |
26
|
|
|
* |
27
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
30
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
31
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
32
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
33
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
34
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
35
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
36
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
37
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
38
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
39
|
|
|
* |
40
|
|
|
* @copyright 2007-2017 Robert Richards <[email protected]> |
41
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
42
|
|
|
*/ |
43
|
|
|
|
44
|
|
|
class XMLSecurityDSig extends \RobRichards\XMLSecLibs\XMLSecurityDSig |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* @return bool |
48
|
|
|
* @throws Exception |
49
|
|
|
*/ |
50
|
|
|
public function validateReference() |
51
|
|
|
{ |
52
|
|
|
$sigNode = $this->sigNode; |
53
|
|
|
$docElem = $sigNode->ownerDocument->documentElement; |
54
|
|
|
|
55
|
|
|
// enveloped signature, remove it |
56
|
|
|
if (!$docElem->isSameNode($sigNode)) { |
|
|
|
|
57
|
|
|
if ($sigNode->parentNode !== null) { |
58
|
|
|
$sigNode->parentNode->removeChild($sigNode); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
$xpath = $this->getXPathObj(); |
62
|
|
|
$query = "./secdsig:SignedInfo[1]/secdsig:Reference"; |
63
|
|
|
$nodeset = $xpath->query($query, $sigNode); |
64
|
|
|
if ($nodeset->length < 1) { |
65
|
|
|
throw new Exception("Reference nodes not found"); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/* Initialize/reset the list of validated nodes. */ |
69
|
|
|
$this->validatedNodes = []; |
|
|
|
|
70
|
|
|
|
71
|
|
|
foreach ($nodeset as $refNode) { |
72
|
|
|
if (!$this->processRefNode($refNode)) { |
73
|
|
|
/* Clear the list of validated nodes. */ |
74
|
|
|
$this->validatedNodes = null; |
75
|
|
|
throw new Exception("Reference validation failed"); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
return true; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|