22/**
33 * xmlseclibs.php
44 *
5- * Copyright (c) 2007-2015 , Robert Richards <[email protected] >. 5+ * Copyright (c) 2007-2019 , Robert Richards <[email protected] >. 66 * All rights reserved.
77 *
88 * Redistribution and use in source and binary forms, with or without
3535 * POSSIBILITY OF SUCH DAMAGE.
3636 *
3737 * @author Robert Richards <[email protected] > 38- * @copyright 2007-2015 Robert Richards <[email protected] > 38+ * @copyright 2007-2019 Robert Richards <[email protected] > 3939 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
40- * @version 2 .0.0 modified
40+ * @version 3 .0.4 modified
4141 */
4242
4343class XMLSecurityKey {
@@ -589,6 +589,11 @@ public function locateSignature($objDoc, $pos=0) {
589589 $ query = ".//secdsig:Signature " ;
590590 $ nodeset = $ xpath ->query ($ query , $ objDoc );
591591 $ this ->sigNode = $ nodeset ->item ($ pos );
592+ $ query = "./secdsig:SignedInfo " ;
593+ $ nodeset = $ xpath ->query ($ query , $ this ->sigNode );
594+ if ($ nodeset ->length > 1 ) {
595+ throw new Exception ("Invalid structure - Too many SignedInfo elements found " );
596+ }
592597 return $ this ->sigNode ;
593598 }
594599 return null ;
@@ -675,6 +680,9 @@ public function canonicalizeSignedInfo() {
675680 $ xpath = $ this ->getXPathObj ();
676681 $ query = "./secdsig:SignedInfo " ;
677682 $ nodeset = $ xpath ->query ($ query , $ this ->sigNode );
683+ if ($ nodeset ->length > 1 ) {
684+ throw new Exception ("Invalid structure - Too many SignedInfo elements found " );
685+ }
678686 if ($ signInfoNode = $ nodeset ->item (0 )) {
679687 $ query = "./secdsig:CanonicalizationMethod " ;
680688 $ nodeset = $ xpath ->query ($ query , $ signInfoNode );
@@ -790,7 +798,7 @@ public function processTransforms($refNode, $objData, $includeCommentNodes = tru
790798 if ($ node ->localName == 'XPath ' ) {
791799 $ arXPath = array ();
792800 $ arXPath ['query ' ] = '(.//. | .//@* | .//namespace::*)[ ' .$ node ->nodeValue .'] ' ;
793- $ arXpath ['namespaces ' ] = array ();
801+ $ arXPath ['namespaces ' ] = array ();
794802 $ nslist = $ xpath ->query ('./namespace::* ' , $ node );
795803 foreach ($ nslist AS $ nsnode ) {
796804 if ($ nsnode ->localName != "xml " ) {
@@ -888,7 +896,7 @@ public function getRefIDs() {
888896 $ refids = array ();
889897
890898 $ xpath = $ this ->getXPathObj ();
891- $ query = "./secdsig:SignedInfo/secdsig:Reference " ;
899+ $ query = "./secdsig:SignedInfo[1] /secdsig:Reference " ;
892900 $ nodeset = $ xpath ->query ($ query , $ this ->sigNode );
893901 if ($ nodeset ->length == 0 ) {
894902 throw new Exception ("Reference nodes not found " );
@@ -905,7 +913,7 @@ public function validateReference() {
905913 $ this ->sigNode ->parentNode ->removeChild ($ this ->sigNode );
906914 }
907915 $ xpath = $ this ->getXPathObj ();
908- $ query = "./secdsig:SignedInfo/secdsig:Reference " ;
916+ $ query = "./secdsig:SignedInfo[1] /secdsig:Reference " ;
909917 $ nodeset = $ xpath ->query ($ query , $ this ->sigNode );
910918 if ($ nodeset ->length == 0 ) {
911919 throw new Exception ("Reference nodes not found " );
0 commit comments