Skip to content

Commit 073d4a6

Browse files
authored
Ensure the X509Certificate tag is properly prefixed (#377)
1 parent 2aa2d13 commit 073d4a6

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/signed-xml.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ export class SignedXml {
194194

195195
if (publicCertMatches.length > 0) {
196196
x509Certs = publicCertMatches
197-
.map((c) => `<X509Certificate>${utils.pemToDer(c).toString("base64")}</X509Certificate>`)
197+
.map(
198+
(c) =>
199+
`<${prefix}X509Certificate>${utils
200+
.pemToDer(c)
201+
.toString("base64")}</${prefix}X509Certificate>`,
202+
)
198203
.join("");
199204
}
200205

test/signature-unit-tests.spec.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,13 @@ describe("Signature unit tests", function () {
555555
const xml = '<root><x xmlns="ns"></x><y attr="value"></y><z><w></w></z></root>';
556556
const sig = new SignedXml();
557557

558+
sig.publicCert = fs.readFileSync("./test/static/client_public.pem");
558559
sig.CanonicalizationAlgorithms["http://DummyTransformation"] = DummyTransformation;
559560
sig.CanonicalizationAlgorithms["http://DummyCanonicalization"] = DummyCanonicalization;
560561
sig.HashAlgorithms["http://dummyDigest"] = DummyDigest;
561562
sig.SignatureAlgorithms["http://dummySignatureAlgorithm"] = DummySignatureAlgorithm;
562563

563564
sig.signatureAlgorithm = "http://dummySignatureAlgorithm";
564-
sig.getKeyInfoContent = function () {
565-
return "<ds:dummy>dummy key info</ds:dummy>";
566-
};
567565
sig.canonicalizationAlgorithm = "http://DummyCanonicalization";
568566
sig.privateKey = "";
569567

@@ -615,11 +613,13 @@ describe("Signature unit tests", function () {
615613
"</ds:SignedInfo>" +
616614
"<ds:SignatureValue>dummy signature</ds:SignatureValue>" +
617615
"<ds:KeyInfo>" +
618-
"<ds:dummy>dummy key info</ds:dummy>" +
616+
"<ds:X509Data>" +
617+
"<ds:X509Certificate>MIIBxDCCAW6gAwIBAgIQxUSXFzWJYYtOZnmmuOMKkjANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wMzA3MDgxODQ3NTlaFw0zOTEyMzEyMzU5NTlaMB8xHTAbBgNVBAMTFFdTRTJRdWlja1N0YXJ0Q2xpZW50MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+L6aB9x928noY4+0QBsXnxkQE4quJl7c3PUPdVu7k9A02hRG481XIfWhrDY5i7OEB7KGW7qFJotLLeMec/UkKUwCgv3VvJrs2nE9xO3SSWIdNzADukYh+Cxt+FUU6tUkDeqg7dqwivOXhuOTRyOI3HqbWTbumaLdc8jufz2LhaQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwDQYJKoZIhvcNAQEEBQADQQAfIbnMPVYkNNfX1tG1F+qfLhHwJdfDUZuPyRPucWF5qkh6sSdWVBY5sT/txBnVJGziyO8DPYdu2fPMER8ajJfl</ds:X509Certificate>" +
618+
"</ds:X509Data>" +
619619
"</ds:KeyInfo>" +
620620
"</ds:Signature>";
621621

622-
expect(expected, "wrong signature format").to.equal(signature);
622+
expect(signature, "wrong signature format").to.equal(expected);
623623

624624
const signedXml = sig.getSignedXml();
625625
const expectedSignedXml =
@@ -652,17 +652,19 @@ describe("Signature unit tests", function () {
652652
"</ds:SignedInfo>" +
653653
"<ds:SignatureValue>dummy signature</ds:SignatureValue>" +
654654
"<ds:KeyInfo>" +
655-
"<ds:dummy>dummy key info</ds:dummy>" +
655+
"<ds:X509Data>" +
656+
"<ds:X509Certificate>MIIBxDCCAW6gAwIBAgIQxUSXFzWJYYtOZnmmuOMKkjANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wMzA3MDgxODQ3NTlaFw0zOTEyMzEyMzU5NTlaMB8xHTAbBgNVBAMTFFdTRTJRdWlja1N0YXJ0Q2xpZW50MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+L6aB9x928noY4+0QBsXnxkQE4quJl7c3PUPdVu7k9A02hRG481XIfWhrDY5i7OEB7KGW7qFJotLLeMec/UkKUwCgv3VvJrs2nE9xO3SSWIdNzADukYh+Cxt+FUU6tUkDeqg7dqwivOXhuOTRyOI3HqbWTbumaLdc8jufz2LhaQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwDQYJKoZIhvcNAQEEBQADQQAfIbnMPVYkNNfX1tG1F+qfLhHwJdfDUZuPyRPucWF5qkh6sSdWVBY5sT/txBnVJGziyO8DPYdu2fPMER8ajJfl</ds:X509Certificate>" +
657+
"</ds:X509Data>" +
656658
"</ds:KeyInfo>" +
657659
"</ds:Signature>" +
658660
"</root>";
659661

660-
expect(expectedSignedXml, "wrong signedXml format").to.equal(signedXml);
662+
expect(signedXml, "wrong signedXml format").to.equal(expectedSignedXml);
661663

662664
const originalXmlWithIds = sig.getOriginalXmlWithIds();
663665
const expectedOriginalXmlWithIds =
664666
'<root><x xmlns="ns" Id="_0"/><y attr="value" Id="_1"/><z><w Id="_2"/></z></root>';
665-
expect(expectedOriginalXmlWithIds, "wrong OriginalXmlWithIds").to.equal(originalXmlWithIds);
667+
expect(originalXmlWithIds, "wrong OriginalXmlWithIds").to.equal(expectedOriginalXmlWithIds);
666668
});
667669

668670
it("signer creates correct signature values", function () {

0 commit comments

Comments
 (0)