Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xml-crypto

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-crypto - npm Package Compare versions

Comparing version 0.0.17 to 0.0.18

test/static/signature_with_inclusivenamespaces.pem

27

lib/exclusive-canonicalization.js

@@ -35,3 +35,3 @@ var utils = require('./utils')

}
attrListToRender.sort(this.attrCompare)

@@ -58,3 +58,3 @@

*/
ExclusiveCanonicalization.prototype.renderNs = function(node, prefixesInScope, defaultNs) {
ExclusiveCanonicalization.prototype.renderNs = function(node, prefixesInScope, defaultNs, inclusiveNamespacesPrefixList) {
var res = ""

@@ -65,3 +65,3 @@ var newDefaultNs = defaultNs

var currNs = node.namespaceURI || ""
//handle the namespaceof the node itself

@@ -84,2 +84,9 @@ if (node.prefix) {

var attr = node.attributes[i]
//handle all prefixed attributes that are included in the prefix list and where
//the prefix is not defined already
if (attr.prefix && prefixesInScope.indexOf(attr.localName) === -1 && inclusiveNamespacesPrefixList.indexOf(attr.localName) >= 0) {
nsListToRender.push({"prefix": attr.localName, "namespaceURI": attr.value});
prefixesInScope.push(attr.localName);
}

@@ -106,3 +113,3 @@ //handle all prefixed attributes that are not xmlns definitions and where

ExclusiveCanonicalization.prototype.processInner = function(node, prefixesInScope, defaultNs) {
ExclusiveCanonicalization.prototype.processInner = function(node, prefixesInScope, defaultNs, inclusiveNamespacesPrefixList) {

@@ -113,3 +120,3 @@ if (node.data) return utils.normalizeXmlIncludingCR(node.data)

res += node.tagName
var ns = this.renderNs(node, prefixesInScope, defaultNs)
var ns = this.renderNs(node, prefixesInScope, defaultNs, inclusiveNamespacesPrefixList)
res += ns.rendered

@@ -121,3 +128,3 @@ res += this.renderAttrs(node)

var pfxCopy = prefixesInScope.slice(0)
res += this.processInner(node.childNodes[i], pfxCopy, ns.newDefaultNs)
res += this.processInner(node.childNodes[i], pfxCopy, ns.newDefaultNs, inclusiveNamespacesPrefixList)
}

@@ -136,4 +143,8 @@

*/
ExclusiveCanonicalization.prototype.process = function(node) {
var res = this.processInner(node, [], "")
ExclusiveCanonicalization.prototype.process = function(node, options) {
var options = options || {};
var inclusiveNamespacesPrefixList = options.inclusiveNamespacesPrefixList || [];
if (!(inclusiveNamespacesPrefixList instanceof Array)) inclusiveNamespacesPrefixList = inclusiveNamespacesPrefixList.split(' ');
var res = this.processInner(node, [], "", inclusiveNamespacesPrefixList)
return res

@@ -140,0 +151,0 @@ //var doc = new Dom().parseFromString(res)

@@ -38,3 +38,2 @@ var select = require('xpath.js')

var res = shasum.digest('base64')
//console.log("hash for " + xml + "is " + res)
return res

@@ -54,3 +53,2 @@ }

var res = shasum.digest('base64')
//console.log("hash for " + xml + "is " + res)
return res

@@ -250,4 +248,3 @@ }

}
var canonXml = this.getCanonXml(ref.transforms, elem[0])
var canonXml = this.getCanonXml(ref.transforms, elem[0], { inclusiveNamespacesPrefixList: ref.inclusiveNamespacesPrefixList });

@@ -257,5 +254,2 @@ var hash = this.findHashAlgorithm(ref.digestAlgorithm)

//console.log(digest)
//console.log(ref.digestValue)
if (digest!=ref.digestValue) {

@@ -321,2 +315,3 @@ this.validationErrors.push("invalid signature: for uri " + ref.uri +

var transforms = []
var inclusiveNamespacesPrefixList;
nodes = utils.findChilds(ref, "Transforms")

@@ -330,2 +325,7 @@ if (nodes.length!=0) {

}
var inclusiveNamespaces = select(transformsNode, "//*[local-name(.)='InclusiveNamespaces']");
if (inclusiveNamespaces.length > 0) {
inclusiveNamespacesPrefixList = inclusiveNamespaces[0].getAttribute('PrefixList');
}
}

@@ -337,6 +337,6 @@

this.addReference(null, transforms, digestAlgo, utils.findAttr(ref, "URI").value, digestValue)
this.addReference(null, transforms, digestAlgo, utils.findAttr(ref, "URI").value, digestValue, inclusiveNamespacesPrefixList)
}
SignedXml.prototype.addReference = function(xpath, transforms, digestAlgorithm, uri, digestValue) {
SignedXml.prototype.addReference = function(xpath, transforms, digestAlgorithm, uri, digestValue, inclusiveNamespacesPrefixList) {
this.references.push({

@@ -347,3 +347,4 @@ "xpath": xpath,

"uri": uri,
"digestValue": digestValue
"digestValue": digestValue,
"inclusiveNamespacesPrefixList": inclusiveNamespacesPrefixList
});

@@ -436,7 +437,7 @@ }

SignedXml.prototype.getCanonXml = function(transforms, node) {
SignedXml.prototype.getCanonXml = function(transforms, node, options) {
var canonXml = node
for (var t in transforms) {
var transform = this.findCanonicalizationAlgorithm(transforms[t])
canonXml = transform.process(canonXml)
canonXml = transform.process(canonXml, options);
//TODO: currently transform.process may return either Node or String value (enveloped transformation returns Node, exclusive-canonicalization returns String).

@@ -443,0 +444,0 @@ //This eitehr needs to be more explicit in the API, or all should return the same.

{
"name": "xml-crypto",
"version": "0.0.17",
"version": "0.0.18",
"description": "Xml digital signature and encryption library for Node.js",

@@ -5,0 +5,0 @@ "engines": { "node": ">=0.4.0" },

@@ -7,3 +7,3 @@ var ExclusiveCanonicalization = require("../lib/exclusive-canonicalization").ExclusiveCanonicalization

var compare = function(test, xml, xpath, expected) {
var compare = function(test, xml, xpath, expected, inclusiveNamespacesPrefixList) {
test.expect(1)

@@ -13,3 +13,3 @@ var doc = new Dom().parseFromString(xml)

var can = new ExclusiveCanonicalization()
var result = can.process(elem).toString()
var result = can.process(elem, { inclusiveNamespacesPrefixList: inclusiveNamespacesPrefixList }).toString()

@@ -74,3 +74,36 @@ test.equal(expected, result)

"Exclusive canonicalization works on xml with prefixed namespace defined in inclusive list": function (test) {
compare(test,
"<root xmlns:p=\"ns\"><p:child xmlns:inclusive=\"ns2\"><inclusive:inner xmlns:inclusive=\"ns2\">123</inclusive:inner></p:child></root>",
"//*[local-name(.)='child']",
"<p:child xmlns:inclusive=\"ns2\" xmlns:p=\"ns\"><inclusive:inner>123</inclusive:inner></p:child>",
"inclusive")
},
"Exclusive canonicalization works on xml with multiple prefixed namespaces defined in inclusive list": function (test) {
compare(test,
"<root xmlns:p=\"ns\"><p:child xmlns:inclusive=\"ns2\" xmlns:inclusive2=\"ns3\"><inclusive:inner xmlns:inclusive=\"ns2\">123</inclusive:inner><inclusive2:inner xmlns:inclusive2=\"ns3\">456</inclusive2:inner></p:child></root>",
"//*[local-name(.)='child']",
"<p:child xmlns:inclusive2=\"ns3\" xmlns:inclusive=\"ns2\" xmlns:p=\"ns\"><inclusive:inner>123</inclusive:inner><inclusive2:inner>456</inclusive2:inner></p:child>",
"inclusive inclusive2")
},
"Exclusive canonicalization works on xml with prefixed namespace defined in inclusive list defined outside output nodes": function (test) {
compare(test,
"<root xmlns:p=\"ns\" xmlns:inclusive=\"ns2\"><p:child><inclusive:inner xmlns:inclusive=\"ns2\">123</inclusive:inner></p:child></root>",
"//*[local-name(.)='child']",
"<p:child xmlns:p=\"ns\"><inclusive:inner xmlns:inclusive=\"ns2\">123</inclusive:inner></p:child>",
"inclusive")
},
"Exclusive canonicalization works on xml with prefixed namespace defined in inclusive list used on attribute": function (test) {
compare(test,
"<root xmlns:p=\"ns\"><p:child xmlns:inclusive=\"ns2\"><p:inner foo=\"inclusive:bar\">123</p:inner></p:child></root>",
"//*[local-name(.)='child']",
"<p:child xmlns:inclusive=\"ns2\" xmlns:p=\"ns\"><p:inner foo=\"inclusive:bar\">123</p:inner></p:child>",
"inclusive")
},
"Exclusive canonicalization works on xml with default namespace inside output nodes": function (test) {

@@ -77,0 +110,0 @@ compare(test,

@@ -75,2 +75,18 @@ var select = require('xpath.js')

test.done();
},
"signature with inclsuive namespaces": function(test) {
var xml = fs.readFileSync('./test/static/signature_with_inclusivenamespaces.xml', 'utf-8');
var doc = new Dom({ignoreWhiteSpace: true}).parseFromString(xml);
//ensure xml has not white space
xml = doc.firstChild.toString()
var signature = crypto.xpath(doc, "//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0];
var sig = new crypto.SignedXml();
sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/signature_with_inclusivenamespaces.pem");
sig.loadSignature(signature.toString());
var result = sig.checkSignature(xml);
test.equal(result, true);
test.done();
}

@@ -77,0 +93,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc