1- var select = require ( 'xpath.js ' )
1+ var xpath = require ( 'xpath' )
22 , Dom = require ( 'xmldom' ) . DOMParser
33 , utils = require ( './utils' )
44 , c14n = require ( './c14n-canonicalization' )
55 , execC14n = require ( './exclusive-canonicalization' )
66 , EnvelopedSignature = require ( './enveloped-signature' ) . EnvelopedSignature
77 , crypto = require ( 'crypto' )
88 , fs = require ( 'fs' )
9- , xpath = require ( 'xpath.js' )
109
1110exports . SignedXml = SignedXml
1211exports . FileKeyInfo = FileKeyInfo
@@ -209,7 +208,7 @@ function HMACSHA1() {
209208 * @returns {Array } i.e. [{prefix: "saml", namespaceURI: "urn:oasis:names:tc:SAML:2.0:assertion"}]
210209 */
211210function findAncestorNs ( doc , docSubsetXpath ) {
212- var docSubset = xpath ( doc , docSubsetXpath ) ;
211+ var docSubset = xpath . select ( docSubsetXpath , doc ) ;
213212
214213 if ( ! Array . isArray ( docSubset ) || docSubset . length < 1 ) {
215214 return [ ] ;
@@ -418,7 +417,7 @@ SignedXml.prototype.validateReferences = function(doc) {
418417 var elemXpath ;
419418
420419 if ( uri == "" ) {
421- elem = select ( doc , "//*" )
420+ elem = xpath . select ( "//*" , doc )
422421 }
423422 else if ( uri . indexOf ( "'" ) != - 1 ) {
424423 // xpath injection
@@ -429,7 +428,7 @@ SignedXml.prototype.validateReferences = function(doc) {
429428 for ( var index in this . idAttributes ) {
430429 if ( ! this . idAttributes . hasOwnProperty ( index ) ) continue ;
431430 var tmp_elemXpath = "//*[@*[local-name(.)='" + this . idAttributes [ index ] + "']='" + uri + "']" ;
432- var tmp_elem = select ( doc , tmp_elemXpath )
431+ var tmp_elem = xpath . select ( tmp_elemXpath , doc )
433432 num_elements_for_id += tmp_elem . length ;
434433 if ( tmp_elem . length > 0 ) {
435434 elem = tmp_elem ;
@@ -519,15 +518,15 @@ SignedXml.prototype.loadSignature = function(signatureNode) {
519518
520519 this . signatureXml = signatureNode . toString ( ) ;
521520
522- var nodes = select ( signatureNode , ".//*[local-name(.)='CanonicalizationMethod']/@Algorithm" )
521+ var nodes = xpath . select ( ".//*[local-name(.)='CanonicalizationMethod']/@Algorithm" , signatureNode )
523522 if ( nodes . length == 0 ) throw new Error ( "could not find CanonicalizationMethod/@Algorithm element" )
524523 this . canonicalizationAlgorithm = nodes [ 0 ] . value
525524
526525 this . signatureAlgorithm =
527526 utils . findFirst ( signatureNode , ".//*[local-name(.)='SignatureMethod']/@Algorithm" ) . value
528527
529528 this . references = [ ]
530- var references = select ( signatureNode , ".//*[local-name(.)='SignedInfo']/*[local-name(.)='Reference']" )
529+ var references = xpath . select ( ".//*[local-name(.)='SignedInfo']/*[local-name(.)='Reference']" , signatureNode )
531530 if ( references . length == 0 ) throw new Error ( "could not find any Reference elements" )
532531
533532 for ( var i in references ) {
@@ -539,7 +538,7 @@ SignedXml.prototype.loadSignature = function(signatureNode) {
539538 this . signatureValue =
540539 utils . findFirst ( signatureNode , ".//*[local-name(.)='SignatureValue']/text()" ) . data . replace ( / \r ? \n / g, '' )
541540
542- this . keyInfo = select ( signatureNode , ".//*[local-name(.)='KeyInfo']" )
541+ this . keyInfo = xpath . select ( ".//*[local-name(.)='KeyInfo']" , signatureNode )
543542}
544543
545544/**
@@ -576,7 +575,7 @@ SignedXml.prototype.loadReference = function(ref) {
576575 transforms . push ( utils . findAttr ( trans , "Algorithm" ) . value )
577576 }
578577
579- var inclusiveNamespaces = select ( transformsNode , "//*[local-name(.)='InclusiveNamespaces']" ) ;
578+ var inclusiveNamespaces = xpath . select ( "//*[local-name(.)='InclusiveNamespaces']" , transformsNode ) ;
580579 if ( inclusiveNamespaces . length > 0 ) {
581580 inclusiveNamespacesPrefixList = inclusiveNamespaces [ 0 ] . getAttribute ( 'PrefixList' ) ;
582581 }
@@ -685,7 +684,7 @@ SignedXml.prototype.computeSignature = function(xml, opts) {
685684
686685 var signatureDoc = new Dom ( ) . parseFromString ( this . signatureXml )
687686
688- var referenceNode = select ( doc , location . reference ) ;
687+ var referenceNode = xpath . select ( location . reference , doc ) ;
689688
690689 if ( ! referenceNode || referenceNode . length === 0 ) {
691690 throw new Error ( "the following xpath cannot be used because it was not found: " + location . reference ) ;
@@ -736,7 +735,7 @@ SignedXml.prototype.createReferences = function(doc, prefix) {
736735 if ( ! this . references . hasOwnProperty ( n ) ) continue ;
737736
738737 var ref = this . references [ n ]
739- , nodes = select ( doc , ref . xpath )
738+ , nodes = xpath . select ( ref . xpath , doc )
740739
741740 if ( nodes . length == 0 ) {
742741 throw new Error ( 'the following xpath cannot be signed because it was not found: ' + ref . xpath )
0 commit comments