Socket
Socket
Sign inDemoInstall

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.5 to 0.0.6

.travis.yml

50

lib/signed-xml.js

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

, ExclusiveCanonicalization = require('./exclusive-canonicalization').ExclusiveCanonicalization
, EnvelopedSignature = require('./enveloped-signature').EnvelopedSignature
, crypto = require('crypto')

@@ -104,3 +105,4 @@ , fs = require('fs')

SignedXml.CanonicalizationAlgorithms = {
'http://www.w3.org/2001/10/xml-exc-c14n#': ExclusiveCanonicalization
'http://www.w3.org/2001/10/xml-exc-c14n#': ExclusiveCanonicalization,
'http://www.w3.org/2000/09/xmldsig#enveloped-signature': EnvelopedSignature
}

@@ -121,15 +123,17 @@

if (!this.keyInfoProvider) {
throw "cannot validate signature since no key info resolver was provided"
throw new Error("cannot validate signature since no key info resolver was provided")
}
this.signingKey = this.keyInfoProvider.getKey(this.keyInfo)
if (!this.signingKey) throw "key info provider could not resolve key info " + this.keyInfo
if (!this.signingKey) throw new Error("key info provider could not resolve key info " + this.keyInfo)
var doc = new Dom().parseFromString(xml)
if (!this.validateReferences(doc))
return false
if (!this.validateReferences(doc)) {
return false;
}
if (!this.validateSignatureValue(doc))
return false
if (!this.validateSignatureValue(doc)) {
return false;
}

@@ -141,3 +145,3 @@ return true

var signedInfo = utils.findChilds(this.signatureXmlDoc.documentElement, "SignedInfo")
if (signedInfo.length==0) throw "could not find SignedInfo element in the message"
if (signedInfo.length==0) throw new Error("could not find SignedInfo element in the message")
var signedInfoCanon = this.getCanonXml([this.canonicalizationAlgorithm], signedInfo[0])

@@ -154,3 +158,3 @@ var signer = this.findSignatureAlgorithm(this.signatureAlgorithm)

if (algo) return new algo()
else throw "signature algorithm '" + name + "' is not supported"
else throw new Error("signature algorithm '" + name + "' is not supported");
}

@@ -161,3 +165,3 @@

if (algo) return new algo()
else throw "canonicalization algorithm '" + name + "' is not supported"
else throw new Error("canonicalization algorithm '" + name + "' is not supported");
}

@@ -168,3 +172,3 @@

if (algo) return new algo()
else throw "hash algorithm '" + name + "' is not supported"
else throw new Error("hash algorithm '" + name + "' is not supported");
}

@@ -180,5 +184,8 @@

if (elem.length==0) {
this.validationErrors.push("invalid signature: the signature refernces an element with uri "+
elem = select(doc, "//*[@*[local-name(.)='ID']='" + uri + "']")
if (elem.length==0) {
this.validationErrors.push("invalid signature: the signature refernces an element with uri "+
ref.uri + " but could not find such element in the xml")
return false
return false
}
}

@@ -207,3 +214,3 @@

var nodes = select(doc, "//*[local-name(.)='CanonicalizationMethod']/@Algorithm")
if (nodes.length==0) throw "could not find CanonicalizationMethod/@Algorithm element"
if (nodes.length==0) throw new Error("could not find CanonicalizationMethod/@Algorithm element")
this.canonicalizationAlgorithm = nodes[0].value

@@ -216,3 +223,3 @@

var references = select(doc, "//*[local-name(.)='SignedInfo']/*[local-name(.)='Reference' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")
if (references.length == 0) throw "could not find any Reference elements"
if (references.length == 0) throw new Error("could not find any Reference elements")

@@ -235,14 +242,14 @@ for (var i in references) {

var nodes = utils.findChilds(ref, "DigestMethod")
if (nodes.length==0) throw "could not find DigestMethod in reference " + ref.toString()
if (nodes.length==0) throw new Error("could not find DigestMethod in reference " + ref.toString())
var digestAlgoNode = nodes[0]
var attr = utils.findAttr(digestAlgoNode, "Algorithm")
if (!attr) throw "could not find Algorithm attribute in node " + digestAlgoNode.toString()
if (!attr) throw new Error("could not find Algorithm attribute in node " + digestAlgoNode.toString())
var digestAlgo = attr.value
nodes = utils.findChilds(ref, "DigestValue")
if (nodes.length==0) throw "could not find DigestValue node in reference " + ref.toString()
if (nodes.length==0) throw new Error("could not find DigestValue node in reference " + ref.toString())
if (nodes[0].childNodes.length==0 || !nodes[0].firstChild.data)
{
throw "could not find the value of DigestValue in " + nodes[0].toString()
throw new Error("could not find the value of DigestValue in " + nodes[0].toString())
}

@@ -372,4 +379,7 @@ var digestValue = nodes[0].firstChild.data

attr = utils.findAttr(node, "Id", null)
if (!attr) {
attr = utils.findAttr(node, "ID", null)
}
}
if (attr) return attr.value

@@ -376,0 +386,0 @@

9

package.json
{
"name": "xml-crypto",
"version": "0.0.5",
"version": "0.0.6",
"description": "Xml digital signature and encryption library for Node.js",

@@ -21,3 +21,6 @@ "engines": { "node": ">=0.4.0" },

"type" : "MIT License",
"url" : "http://www.opensource.org/licenses/mit-license.php" }]
}
"url" : "http://www.opensource.org/licenses/mit-license.php" }],
"scripts": {
"test": "./node_modules/nodeunit/bin/nodeunit test"
}
}

@@ -33,2 +33,6 @@ var select = require('../lib/xpath.js').SelectNodes

function verifySignature(test, xml, xpath) {
if (process.platform !== 'win32') {
test.done();
return;
}
var sig = new SignedXml()

@@ -61,2 +65,2 @@ sig.signingKey = fs.readFileSync("./test/static/client.pem")

}
}

@@ -5,3 +5,4 @@ var select = require('../lib/xpath.js').SelectNodes

function nodeExists(test, doc, xpath) {
function nodeExists(test, doc, xpath) {
if (!doc && !xpath) return
var node = select(doc, xpath)

@@ -11,2 +12,2 @@ test.ok(node.length==1, "xpath " + xpath + " not found")

exports.nodeExists = nodeExists
exports.nodeExists = nodeExists
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