Skip to content

Commit 3032517

Browse files
fcorneliLoneRifle
authored andcommitted
fix for enveloped signatures (#174)
Don't just remove the first signature node, find all the other signatures whose digest reference matches too
1 parent 0d768f5 commit 3032517

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/enveloped-signature.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
var xpath = require('xpath');
2+
var utils = require('./utils');
23

34
exports.EnvelopedSignature = EnvelopedSignature;
45

56
function EnvelopedSignature() {
67
}
78

8-
EnvelopedSignature.prototype.process = function (node) {
9-
var signature = xpath.select("./*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", node)[0];
10-
if (signature) signature.parentNode.removeChild(signature);
9+
EnvelopedSignature.prototype.process = function (node, options) {
10+
if (null == options.signatureNode) {
11+
// leave this for the moment...
12+
var signature = xpath.select("./*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", node)[0];
13+
if (signature) signature.parentNode.removeChild(signature);
14+
return node;
15+
}
16+
var signatureNode = options.signatureNode;
17+
var expectedSignatureValue = utils.findFirst(signatureNode, ".//*[local-name(.)='SignatureValue']/text()").data;
18+
var signatures = xpath.select(".//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", node);
19+
for (var h in signatures) {
20+
if (!signatures.hasOwnProperty(h)) continue;
21+
var signature = signatures[h];
22+
var signatureValue = utils.findFirst(signature, ".//*[local-name(.)='SignatureValue']/text()").data;
23+
if (expectedSignatureValue === signatureValue) {
24+
signature.parentNode.removeChild(signature);
25+
}
26+
}
1127
return node;
1228
};
1329

lib/signed-xml.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ SignedXml.prototype.createReferences = function(doc, prefix) {
815815
SignedXml.prototype.getCanonXml = function(transforms, node, options) {
816816
options = options || {};
817817
options.defaultNsForPrefix = options.defaultNsForPrefix || SignedXml.defaultNsForPrefix;
818+
options.signatureNode = this.signatureNode;
818819

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

0 commit comments

Comments
 (0)