diff --git a/composer.json b/composer.json index 8218810d..e72868e9 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "ext-spl": "*", "simplesamlphp/assert": "~1.9", - "simplesamlphp/xml-common": "~2.3" + "simplesamlphp/xml-common": "~2.4" }, "require-dev": { "simplesamlphp/simplesamlphp-test-framework": "~1.10" diff --git a/src/Utils/XPath.php b/src/Utils/XPath.php index f6d5adba..c762b9e8 100644 --- a/src/Utils/XPath.php +++ b/src/Utils/XPath.php @@ -4,12 +4,9 @@ namespace SimpleSAML\XMLSecurity\Utils; -use DOMDocument; -use DOMElement; use DOMNode; use DOMXPath; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\Exception\RuntimeException; use SimpleSAML\XPath\XPath as XPathUtils; /** @@ -23,38 +20,18 @@ class XPath extends XPathUtils * Get a DOMXPath object that can be used to search for XMLDSIG elements. * * @param \DOMNode $node The document to associate to the DOMXPath object. + * @param bool $autoregister Whether to auto-register all namespaces used in the document * * @return \DOMXPath A DOMXPath object ready to use in the given document, with the XMLDSIG namespace already * registered. */ - public static function getXPath(DOMNode $node): DOMXPath + public static function getXPath(DOMNode $node, bool $autoregister = false): DOMXPath { - $xp = parent::getXPath($node); + $xp = parent::getXPath($node, $autoregister); + $xp->registerNamespace('ds', C::NS_XDSIG); $xp->registerNamespace('xenc', C::NS_XENC); - return $xp; - } - - /** - * Search for an element with a certain name among the children of a reference element. - * - * @param \DOMNode $ref The DOMDocument or DOMElement where encrypted data is expected to be found as a child. - * @param string $name The name (possibly prefixed) of the element we are looking for. - * - * @return \DOMElement|false The element we are looking for, or false when not found. - * - * @throws \SimpleSAML\XMLSecurity\Exception\RuntimeException If no DOM document is available. - */ - public static function findElement(DOMNode $ref, string $name): DOMElement|false - { - $doc = $ref instanceof DOMDocument ? $ref : $ref->ownerDocument; - if ($doc === null) { - throw new RuntimeException('Cannot search, no DOMDocument available'); - } - - $nodeset = self::getXPath($doc)->query('./' . $name, $ref); - - return $nodeset->item(0) ?? false; + return $xp; } }