From 58263a6ed3b13699290124c2e27d108a08828fc5 Mon Sep 17 00:00:00 2001 From: Ganesh Kshirsagar Date: Sun, 26 Feb 2023 14:34:40 +0530 Subject: [PATCH] Updated getKeyInfo function with actual implementation (#249) * Updated getKeyInfo function with actual implementation * Update lib/signed-xml.js Co-authored-by: LoneRifle * fix(key-info): ensure backcompat with `signingKey` --------- Co-authored-by: Ganesh Kshirsagar Co-authored-by: Chris Barth Co-authored-by: LoneRifle --- lib/signed-xml.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/signed-xml.js b/lib/signed-xml.js index 7b236944..125a9576 100644 --- a/lib/signed-xml.js +++ b/lib/signed-xml.js @@ -18,9 +18,17 @@ function FileKeyInfo(file) { this.file = file this.getKeyInfo = function(key, prefix) { - prefix = prefix || '' - prefix = prefix ? prefix + ':' : prefix - return "<" + prefix + "X509Data>" + var currentPrefix = prefix || '' + currentPrefix = currentPrefix ? currentPrefix + ':' : currentPrefix + var signingCert = ''; + if (key) { + var certArray = [].concat(key); + for(var i = 0; i < certArray.length; ++i) { + var cert = certArray[i] + signingCert += "<" + currentPrefix + "X509Certificate>" + cert + "" + } + } + return "<" + currentPrefix + "X509Data>" + signingCert + "" } this.getKey = function(keyInfo) { @@ -298,6 +306,7 @@ function SignedXml(idMode, options) { this.references = [] this.id = 0 this.signingKey = null + this.signingCert = null this.signatureAlgorithm = this.options.signatureAlgorithm || "http://www.w3.org/2000/09/xmldsig#rsa-sha1"; this.keyInfoProvider = null this.canonicalizationAlgorithm = this.options.canonicalizationAlgorithm || "http://www.w3.org/2001/10/xml-exc-c14n#" @@ -861,7 +870,7 @@ SignedXml.prototype.getKeyInfo = function(prefix) { if (this.keyInfoProvider) { res += "<" + currentPrefix + "KeyInfo>" - res += this.keyInfoProvider.getKeyInfo(this.signingKey, prefix) + res += this.keyInfoProvider.getKeyInfo(this.signingCert || this.signingKey, prefix) res += "" } return res