Summary
Follow-up to #596. With #597, signing leaves out KeyInfo whenever getKeyInfoContent returns no content, because XMLDSig requires KeyInfo to have at least one child element (4.5). That includes configurations that set keyInfoAttributes, so the caller asks for a KeyInfo with those attributes and gets a signature without one, with no error.
#597 omits the element instead of throwing so that configurations that sign in 6.x keep signing. For 7.0, an explicit error is the better contract.
Expected
computeSignature() throws when keyInfoAttributes has at least one attribute and getKeyInfoContent returns null or an empty string. For example:
const sig = new SignedXml({
privateKey,
canonicalizationAlgorithm: "http://www.w3.org/2001/10/xml-exc-c14n#",
signatureAlgorithm: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
keyInfoAttributes: { Id: "key" },
});
sig.addReference({
xpath: "//*[local-name(.)='book']",
digestAlgorithm: "http://www.w3.org/2001/04/xmlenc#sha256",
transforms: ["http://www.w3.org/2001/10/xml-exc-c14n#"],
});
sig.computeSignature("<library><book/></library>"); // should throw
Configurations without keyInfoAttributes keep omitting KeyInfo when there is no content.
Release notes
This is a breaking change: the PR needs the breaking-change and semver-major labels and an entry in the README's Upgrading section.
Summary
Follow-up to #596. With #597, signing leaves out
KeyInfowhenevergetKeyInfoContentreturns no content, because XMLDSig requiresKeyInfoto have at least one child element (4.5). That includes configurations that setkeyInfoAttributes, so the caller asks for aKeyInfowith those attributes and gets a signature without one, with no error.#597 omits the element instead of throwing so that configurations that sign in 6.x keep signing. For 7.0, an explicit error is the better contract.
Expected
computeSignature()throws whenkeyInfoAttributeshas at least one attribute andgetKeyInfoContentreturnsnullor an empty string. For example:Configurations without
keyInfoAttributeskeep omittingKeyInfowhen there is no content.Release notes
This is a breaking change: the PR needs the
breaking-changeandsemver-majorlabels and an entry in the README's Upgrading section.