Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove default for signature algorithm #408

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ _Canonicalization/Transformation Algorithm:_ Exclusive Canonicalization <http://

_Hashing/Digest Algorithm:_ Must be specified by the user

_Signature Algorithm:_ RSA-SHA1 <http://www.w3.org/2000/09/xmldsig#rsa-sha1>
_Signature Algorithm:_ Must be specified by the user

[You are able to extend xml-crypto with custom algorithms.](#customizing-algorithms)

Expand Down
7 changes: 5 additions & 2 deletions src/signed-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* One of the supported signature algorithms.
* @see {@link SignatureAlgorithmType}
*/
signatureAlgorithm: SignatureAlgorithmType = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
signatureAlgorithm?: SignatureAlgorithmType = undefined;
/**
* Rules used to convert an XML document into its canonical form.
*/
Expand Down Expand Up @@ -347,7 +347,10 @@
}
}

private findSignatureAlgorithm(name: SignatureAlgorithmType) {
private findSignatureAlgorithm(name?: SignatureAlgorithmType) {
LoneRifle marked this conversation as resolved.
Show resolved Hide resolved
if (name == null) {
throw new Error("signatureAlgorithm is required");

Check warning on line 352 in src/signed-xml.ts

View check run for this annotation

Codecov / codecov/patch

src/signed-xml.ts#L352

Added line #L352 was not covered by tests
}
const algo = this.SignatureAlgorithms[name];
if (algo) {
return new algo();
Expand Down Expand Up @@ -653,7 +656,7 @@
isEmptyUri = false,
}: Partial<Reference> & Pick<Reference, "xpath">): void {
if (digestAlgorithm == null) {
throw new Error("digestAlgorithm is required");

Check warning on line 659 in src/signed-xml.ts

View check run for this annotation

Codecov / codecov/patch

src/signed-xml.ts#L659

Added line #L659 was not covered by tests
}

this.references.push({
Expand Down
1 change: 1 addition & 0 deletions test/key-info-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe("KeyInfo tests", function () {
sig.privateKey = fs.readFileSync("./test/static/client.pem");
sig.publicCert = fs.readFileSync("./test/static/client_public.pem");
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signedXml = sig.getSignedXml();
const doc = new xmldom.DOMParser().parseFromString(signedXml);
Expand Down
2 changes: 2 additions & 0 deletions test/signature-integration-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("Signature integration tests", function () {
});

sig.canonicalizationAlgorithm = canonicalizationAlgorithm;
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signed = sig.getSignedXml();

Expand Down Expand Up @@ -177,6 +178,7 @@ describe("Signature integration tests", function () {
});
sig.privateKey = fs.readFileSync("./test/static/client.pem");
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);

const signed = sig.getSignedXml();
Expand Down
18 changes: 18 additions & 0 deletions test/signature-unit-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signedXml = sig.getOriginalXmlWithIds();
const doc = new xmldom.DOMParser().parseFromString(signedXml);
Expand Down Expand Up @@ -72,6 +73,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml, {
existingPrefixes: {
wsu: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd",
Expand All @@ -95,6 +97,7 @@ describe("Signature unit tests", function () {
digestAlgorithm: "http://www.w3.org/2000/09/xmldsig#sha1",
});
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signedXml = sig.getOriginalXmlWithIds();
const doc = new xmldom.DOMParser().parseFromString(signedXml);
Expand Down Expand Up @@ -129,6 +132,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml, {
attrs: attrs,
});
Expand Down Expand Up @@ -163,6 +167,7 @@ describe("Signature unit tests", function () {
digestAlgorithm: "http://www.w3.org/2000/09/xmldsig#sha1",
});
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);

const doc = new xmldom.DOMParser().parseFromString(sig.getSignedXml());
Expand All @@ -186,6 +191,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml, {
location: {
reference: "/root/name",
Expand Down Expand Up @@ -216,6 +222,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml, {
location: {
reference: "/root/name",
Expand Down Expand Up @@ -245,6 +252,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml, {
location: {
reference: "/root/name",
Expand Down Expand Up @@ -275,6 +283,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml, {
location: {
reference: "/root/name",
Expand Down Expand Up @@ -637,6 +646,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signedXml = sig.getSignedXml();
const expected =
Expand Down Expand Up @@ -956,6 +966,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signedXml = sig.getSignedXml();
const doc = new xmldom.DOMParser().parseFromString(signedXml);
Expand Down Expand Up @@ -1013,6 +1024,7 @@ describe("Signature unit tests", function () {
sig.getKeyInfoContent = getKeyInfoContentWithAssertionId.bind(this, { assertionId });
sig.privateKey = fs.readFileSync("./test/static/client.pem");
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml, {
prefix: "ds",
location: {
Expand Down Expand Up @@ -1045,6 +1057,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signedXml = sig.getSignedXml();

Expand Down Expand Up @@ -1081,6 +1094,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signedXml = sig.getSignedXml();

Expand All @@ -1105,6 +1119,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signedXml = sig.getSignedXml();

Expand Down Expand Up @@ -1143,6 +1158,7 @@ describe("Signature unit tests", function () {
});

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signedXml = sig.getSignedXml();

Expand All @@ -1169,6 +1185,7 @@ describe("Signature unit tests", function () {
sig.getKeyInfoContent = () => "<dummy/>";

sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signedXml = sig.getSignedXml();

Expand Down Expand Up @@ -1200,6 +1217,7 @@ describe("Signature unit tests", function () {
sig.privateKey = pemBuffer;
sig.publicCert = pemBuffer;
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
sig.computeSignature(xml);
const signedXml = sig.getSignedXml();

Expand Down