Skip to content

Signing ignores keyInfoAttributes when there is no KeyInfo content #598

Description

@cjbarth

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions