Skip to content

Commit

Permalink
fix for enveloped signatures (#174)
Browse files Browse the repository at this point in the history
Don't just remove the first signature node, find all the other signatures
whose digest reference matches too
  • Loading branch information
fcorneli authored and LoneRifle committed Feb 11, 2019
1 parent 0d768f5 commit 3032517
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/enveloped-signature.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
var xpath = require('xpath');
var utils = require('./utils');

exports.EnvelopedSignature = EnvelopedSignature;

function EnvelopedSignature() {
}

EnvelopedSignature.prototype.process = function (node) {
var signature = xpath.select("./*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", node)[0];
if (signature) signature.parentNode.removeChild(signature);
EnvelopedSignature.prototype.process = function (node, options) {
if (null == options.signatureNode) {
// leave this for the moment...
var signature = xpath.select("./*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", node)[0];
if (signature) signature.parentNode.removeChild(signature);
return node;
}
var signatureNode = options.signatureNode;
var expectedSignatureValue = utils.findFirst(signatureNode, ".//*[local-name(.)='SignatureValue']/text()").data;
var signatures = xpath.select(".//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", node);
for (var h in signatures) {
if (!signatures.hasOwnProperty(h)) continue;
var signature = signatures[h];
var signatureValue = utils.findFirst(signature, ".//*[local-name(.)='SignatureValue']/text()").data;
if (expectedSignatureValue === signatureValue) {
signature.parentNode.removeChild(signature);
}
}
return node;
};

Expand Down
1 change: 1 addition & 0 deletions lib/signed-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ SignedXml.prototype.createReferences = function(doc, prefix) {
SignedXml.prototype.getCanonXml = function(transforms, node, options) {
options = options || {};
options.defaultNsForPrefix = options.defaultNsForPrefix || SignedXml.defaultNsForPrefix;
options.signatureNode = this.signatureNode;

var canonXml = node.cloneNode(true) // Deep clone

Expand Down

0 comments on commit 3032517

Please sign in to comment.