Skip to content

Commit

Permalink
Updated getKeyInfo function with actual implementation (#249)
Browse files Browse the repository at this point in the history
* Updated getKeyInfo function with actual implementation

* Update lib/signed-xml.js

Co-authored-by: LoneRifle <LoneRifle@users.noreply.github.com>

* fix(key-info): ensure backcompat with `signingKey`

---------

Co-authored-by: Ganesh Kshirsagar <ganesh.kshirsagar@nice.com>
Co-authored-by: Chris Barth <chrisjbarth@hotmail.com>
Co-authored-by: LoneRifle <LoneRifle@users.noreply.github.com>
  • Loading branch information
4 people authored Feb 26, 2023
1 parent 52d5ad5 commit 58263a6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/signed-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ function FileKeyInfo(file) {
this.file = file

this.getKeyInfo = function(key, prefix) {
prefix = prefix || ''
prefix = prefix ? prefix + ':' : prefix
return "<" + prefix + "X509Data></" + 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 + "</" + currentPrefix + "X509Certificate>"
}
}
return "<" + currentPrefix + "X509Data>" + signingCert + "</" + currentPrefix + "X509Data>"
}

this.getKey = function(keyInfo) {
Expand Down Expand Up @@ -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#"
Expand Down Expand Up @@ -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 += "</" + currentPrefix + "KeyInfo>"
}
return res
Expand Down

0 comments on commit 58263a6

Please sign in to comment.