From 222fa650636db0cf447c561b91704a22e31e4c92 Mon Sep 17 00:00:00 2001 From: Case Walker Date: Sun, 13 Aug 2023 23:49:48 -0400 Subject: [PATCH 1/3] Ensure prefixes are correctly added to the X509Certificate tags --- src/signed-xml.ts | 2 +- test/signature-unit-tests.spec.ts | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/signed-xml.ts b/src/signed-xml.ts index 55117699..d658da1d 100644 --- a/src/signed-xml.ts +++ b/src/signed-xml.ts @@ -198,7 +198,7 @@ export class SignedXml { if (publicCertMatches.length > 0) { x509Certs = publicCertMatches - .map((c) => `${utils.pemToDer(c).toString("base64")}`) + .map((c) => `<${prefix}X509Certificate>${utils.pemToDer(c).toString("base64")}`) .join(""); } diff --git a/test/signature-unit-tests.spec.ts b/test/signature-unit-tests.spec.ts index f1cbe3f4..b1889464 100644 --- a/test/signature-unit-tests.spec.ts +++ b/test/signature-unit-tests.spec.ts @@ -613,15 +613,15 @@ describe("Signature unit tests", function () { const xml = ''; const sig = new SignedXml(); + sig.privateKey = fs.readFileSync("./test/static/client.pem"); + sig.publicCert = fs.readFileSync("./test/static/client_public.pem"); + sig.CanonicalizationAlgorithms["http://DummyTransformation"] = DummyTransformation; sig.CanonicalizationAlgorithms["http://DummyCanonicalization"] = DummyCanonicalization; sig.HashAlgorithms["http://dummyDigest"] = DummyDigest; sig.SignatureAlgorithms["http://dummySignatureAlgorithm"] = DummySignatureAlgorithm; sig.signatureAlgorithm = "http://dummySignatureAlgorithm"; - sig.getKeyInfoContent = function () { - return "dummy key info"; - }; sig.canonicalizationAlgorithm = "http://DummyCanonicalization"; sig.privateKey = ""; @@ -673,11 +673,13 @@ describe("Signature unit tests", function () { "" + "dummy signature" + "" + - "dummy key info" + + "" + + "MIIBxDCCAW6gAwIBAgIQxUSXFzWJYYtOZnmmuOMKkjANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wMzA3MDgxODQ3NTlaFw0zOTEyMzEyMzU5NTlaMB8xHTAbBgNVBAMTFFdTRTJRdWlja1N0YXJ0Q2xpZW50MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+L6aB9x928noY4+0QBsXnxkQE4quJl7c3PUPdVu7k9A02hRG481XIfWhrDY5i7OEB7KGW7qFJotLLeMec/UkKUwCgv3VvJrs2nE9xO3SSWIdNzADukYh+Cxt+FUU6tUkDeqg7dqwivOXhuOTRyOI3HqbWTbumaLdc8jufz2LhaQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwDQYJKoZIhvcNAQEEBQADQQAfIbnMPVYkNNfX1tG1F+qfLhHwJdfDUZuPyRPucWF5qkh6sSdWVBY5sT/txBnVJGziyO8DPYdu2fPMER8ajJfl" + + "" + "" + ""; - expect(expected, "wrong signature format").to.equal(signature); + expect(signature, "wrong signature format").to.equal(expected); const signedXml = sig.getSignedXml(); const expectedSignedXml = @@ -710,17 +712,19 @@ describe("Signature unit tests", function () { "" + "dummy signature" + "" + - "dummy key info" + + "" + + "MIIBxDCCAW6gAwIBAgIQxUSXFzWJYYtOZnmmuOMKkjANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wMzA3MDgxODQ3NTlaFw0zOTEyMzEyMzU5NTlaMB8xHTAbBgNVBAMTFFdTRTJRdWlja1N0YXJ0Q2xpZW50MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+L6aB9x928noY4+0QBsXnxkQE4quJl7c3PUPdVu7k9A02hRG481XIfWhrDY5i7OEB7KGW7qFJotLLeMec/UkKUwCgv3VvJrs2nE9xO3SSWIdNzADukYh+Cxt+FUU6tUkDeqg7dqwivOXhuOTRyOI3HqbWTbumaLdc8jufz2LhaQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwDQYJKoZIhvcNAQEEBQADQQAfIbnMPVYkNNfX1tG1F+qfLhHwJdfDUZuPyRPucWF5qkh6sSdWVBY5sT/txBnVJGziyO8DPYdu2fPMER8ajJfl" + + "" + "" + "" + ""; - expect(expectedSignedXml, "wrong signedXml format").to.equal(signedXml); + expect(signedXml, "wrong signedXml format").to.equal(expectedSignedXml); const originalXmlWithIds = sig.getOriginalXmlWithIds(); const expectedOriginalXmlWithIds = ''; - expect(expectedOriginalXmlWithIds, "wrong OriginalXmlWithIds").to.equal(originalXmlWithIds); + expect(originalXmlWithIds, "wrong OriginalXmlWithIds").to.equal(expectedOriginalXmlWithIds); }); it("signer creates correct signature values", function () { From 9a1db6ecf742bf8713e96a41c61aead8dbf12b82 Mon Sep 17 00:00:00 2001 From: Case Walker Date: Mon, 14 Aug 2023 00:01:02 -0400 Subject: [PATCH 2/3] Cleanup unecessary private key --- test/signature-unit-tests.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/signature-unit-tests.spec.ts b/test/signature-unit-tests.spec.ts index b1889464..63196d8f 100644 --- a/test/signature-unit-tests.spec.ts +++ b/test/signature-unit-tests.spec.ts @@ -613,9 +613,7 @@ describe("Signature unit tests", function () { const xml = ''; const sig = new SignedXml(); - sig.privateKey = fs.readFileSync("./test/static/client.pem"); sig.publicCert = fs.readFileSync("./test/static/client_public.pem"); - sig.CanonicalizationAlgorithms["http://DummyTransformation"] = DummyTransformation; sig.CanonicalizationAlgorithms["http://DummyCanonicalization"] = DummyCanonicalization; sig.HashAlgorithms["http://dummyDigest"] = DummyDigest; From e1e19b47275ef6d73e444caf4f56b91c7133d65f Mon Sep 17 00:00:00 2001 From: Chris Barth Date: Wed, 4 Oct 2023 19:30:37 -0500 Subject: [PATCH 3/3] lint --- src/signed-xml.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/signed-xml.ts b/src/signed-xml.ts index 08f55799..98bef161 100644 --- a/src/signed-xml.ts +++ b/src/signed-xml.ts @@ -194,7 +194,12 @@ export class SignedXml { if (publicCertMatches.length > 0) { x509Certs = publicCertMatches - .map((c) => `<${prefix}X509Certificate>${utils.pemToDer(c).toString("base64")}`) + .map( + (c) => + `<${prefix}X509Certificate>${utils + .pemToDer(c) + .toString("base64")}`, + ) .join(""); }