Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pr/444
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbarth committed Jan 26, 2024
2 parents c943243 + 627d83f commit f1ac51c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -54,7 +54,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -68,4 +68,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ When signing a xml document you can pass the following options to the `SignedXml

- `privateKey` - **[required]** a `Buffer` or pem encoded `String` containing your private key
- `publicCert` - **[optional]** a `Buffer` or pem encoded `String` containing your public key
- `signatureAlgorithm` - **[optional]** one of the supported [signature algorithms](#signature-algorithms). Ex: `sign.signatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"`
- `canonicalizationAlgorithm` - **[optional]** one of the supported [canonicalization algorithms](#canonicalization-and-transformation-algorithms). Ex: `sign.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"`
- `signatureAlgorithm` - **[required]** one of the supported [signature algorithms](#signature-algorithms). Ex: `sign.signatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"`
- `canonicalizationAlgorithm` - **[required]** one of the supported [canonicalization algorithms](#canonicalization-and-transformation-algorithms). Ex: `sign.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"`

Use this code:

Expand Down Expand Up @@ -106,7 +106,24 @@ The result will be:

Note:

If you set the `publicCert` property, a `<X509Data></X509Data>` element with the public certificate will be generated in the signature.
If you set the `publicCert` and the `getKeyInfoContent` properties, a `<KeyInfo></KeyInfo>` element with the public certificate will be generated in the signature:

```xml
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
...[signature info removed]...
</SignedInfo>
<SignatureValue>vhWzpQyIYuncHUZV9W...[long base64 removed]...</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>MIIGYjCCBJagACCBN...[long base64 removed]...</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
```

For `getKeyInfoContent`, a default implementation `SignedXml.getKeyInfoContent` is available.

To customize this see [customizing algorithms](#customizing-algorithms) for an example.

## Verifying Xml documents
Expand Down
4 changes: 2 additions & 2 deletions src/signed-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ export class SignedXml {
}
this.implicitTransforms = implicitTransforms ?? this.implicitTransforms;
this.keyInfoAttributes = keyInfoAttributes ?? this.keyInfoAttributes;
this.getKeyInfoContent = getKeyInfoContent ?? SignedXml.noop;
this.getCertFromKeyInfo = getCertFromKeyInfo ?? this.getCertFromKeyInfo;
this.getKeyInfoContent = getKeyInfoContent ?? this.getKeyInfoContent;
this.getCertFromKeyInfo = getCertFromKeyInfo ?? SignedXml.noop;
this.xadesQualifyingProperties = null;
this.CanonicalizationAlgorithms;
this.HashAlgorithms;
Expand Down
3 changes: 3 additions & 0 deletions test/document-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe("Validated node references tests", function () {
const xml = fs.readFileSync("./test/static/valid_saml.xml", "utf-8");
const doc = new xmldom.DOMParser().parseFromString(xml);
const sig = new SignedXml();
sig.getCertFromKeyInfo = SignedXml.getCertFromKeyInfo;
sig.loadSignature(sig.findSignatures(doc)[0]);
const validSignature = sig.checkSignature(xml);
expect(validSignature).to.be.true;
Expand All @@ -73,6 +74,7 @@ describe("Validated node references tests", function () {
const xml = fs.readFileSync("./test/static/valid_saml.xml", "utf-8");
const doc = new xmldom.DOMParser().parseFromString(xml);
const sig = new SignedXml();
sig.getCertFromKeyInfo = SignedXml.getCertFromKeyInfo;
sig.loadSignature(sig.findSignatures(doc)[0]);
const validSignature = sig.checkSignature(xml);
expect(validSignature).to.be.true;
Expand All @@ -86,6 +88,7 @@ describe("Validated node references tests", function () {
const xml = fs.readFileSync("./test/static/valid_saml.xml", "utf-8");
const doc = new xmldom.DOMParser().parseFromString(xml);
const sig = new SignedXml();
sig.getCertFromKeyInfo = SignedXml.getCertFromKeyInfo;
sig.loadSignature(sig.findSignatures(doc)[0]);
const validSignature = sig.checkSignature(xml);
expect(validSignature).to.be.true;
Expand Down
1 change: 0 additions & 1 deletion test/key-info-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe("KeyInfo tests", function () {
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.getKeyInfoContent = SignedXml.getKeyInfoContent;
sig.computeSignature(xml);
const signedXml = sig.getSignedXml();
const doc = new xmldom.DOMParser().parseFromString(signedXml);
Expand Down
2 changes: 0 additions & 2 deletions test/signature-unit-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ describe("Signature unit tests", function () {
sig.signatureAlgorithm = "http://dummySignatureAlgorithm";
sig.canonicalizationAlgorithm = "http://DummyCanonicalization";
sig.privateKey = "";
sig.getKeyInfoContent = SignedXml.getKeyInfoContent;

sig.addReference({
xpath: "//*[local-name(.)='x']",
Expand Down Expand Up @@ -1237,7 +1236,6 @@ describe("Signature unit tests", function () {
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.getKeyInfoContent = SignedXml.getKeyInfoContent;
sig.computeSignature(xml);
const signedXml = sig.getSignedXml();

Expand Down

0 comments on commit f1ac51c

Please sign in to comment.