Skip to content

Commit 78329fb

Browse files
authored
Rename signingCert -> publicCert and signingKey -> privateKey (#315)
1 parent c2b83f9 commit 78329fb

File tree

11 files changed

+86
-86
lines changed

11 files changed

+86
-86
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ _Signature Algorithm:_ RSA-SHA1 http://www.w3.org/2000/09/xmldsig#rsa-sha1
6767

6868
When signing a xml document you can specify the following properties on a `SignedXml` instance to customize the signature process:
6969

70-
- `sign.signingKey` - **[required]** a `Buffer` or pem encoded `String` containing your private key
70+
- `sign.privateKey` - **[required]** a `Buffer` or pem encoded `String` containing your private key
7171
- `sign.signatureAlgorithm` - **[optional]** one of the supported [signature algorithms](#signature-algorithms). Ex: `sign.signatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"`
7272
- `sign.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"`
7373

@@ -81,7 +81,7 @@ var xml = "<library>" + "<book>" + "<name>Harry Potter</name>" + "</book>" + "</
8181

8282
var sig = new SignedXml();
8383
sig.addReference("//*[local-name(.)='book']");
84-
sig.signingKey = fs.readFileSync("client.pem");
84+
sig.privateKey = fs.readFileSync("client.pem");
8585
sig.computeSignature(xml);
8686
fs.writeFileSync("signed.xml", sig.getSignedXml());
8787
```
@@ -118,9 +118,9 @@ To generate a `<X509Data></X509Data>` element in the signature you must provide
118118

119119
When verifying a xml document you must specify the following properties on a ``SignedXml` instance:
120120

121-
- `sign.signingCert` - **[optional]** your certificate as a string, a string of multiple certs in PEM format, or a Buffer, see [customizing algorithms](#customizing-algorithms) for an implementation example
121+
- `sign.publicCert` - **[optional]** your certificate as a string, a string of multiple certs in PEM format, or a Buffer, see [customizing algorithms](#customizing-algorithms) for an implementation example
122122

123-
The certificate that will be used to check the signature will first be determined by calling `.getCertFromKeyInfo()`, which function you can customize as you see fit. If that returns `null`, then `.signingCert` is used. If that is `null`, then `.signingKey` is used (for symmetrical signing applications).
123+
The certificate that will be used to check the signature will first be determined by calling `.getCertFromKeyInfo()`, which function you can customize as you see fit. If that returns `null`, then `.publicCert` is used. If that is `null`, then `.privateKey` is used (for symmetrical signing applications).
124124

125125
You can use any dom parser you want in your code (or none, depending on your usage). This sample uses [xmldom](https://github.com/jindw/xmldom) so you should install it first:
126126

@@ -144,7 +144,7 @@ var signature = select(
144144
"//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']"
145145
)[0];
146146
var sig = new SignedXml();
147-
sig.signingCert = new FileKeyInfo("client_public.pem");
147+
sig.publicCert = new FileKeyInfo("client_public.pem");
148148
sig.loadSignature(signature);
149149
var res = sig.checkSignature(xml);
150150
if (!res) console.log(sig.validationErrors);
@@ -179,7 +179,7 @@ If you keep failing verification, it is worth trying to guess such a hidden tran
179179
```javascript
180180
var option = { implicitTransforms: ["http://www.w3.org/TR/2001/REC-xml-c14n-20010315"] };
181181
var sig = new SignedXml(null, option);
182-
sig.signingCert = new FileKeyInfo("client_public.pem");
182+
sig.publicCert = new FileKeyInfo("client_public.pem");
183183
sig.loadSignature(signature);
184184
var res = sig.checkSignature(xml);
185185
```
@@ -272,7 +272,7 @@ A custom signing algorithm. The default is RSA-SHA1.
272272
```javascript
273273
function MySignatureAlgorithm() {
274274
/*sign the given SignedInfo using the key. return base64 signature value*/
275-
this.getSignature = function (signedInfo, signingKey) {
275+
this.getSignature = function (signedInfo, privateKey) {
276276
return "signature of signedInfo as base64...";
277277
};
278278

@@ -333,15 +333,15 @@ function signXml(xml, xpath, key, dest) {
333333

334334
/*configure the signature object to use the custom algorithms*/
335335
sig.signatureAlgorithm = "http://mySignatureAlgorithm";
336-
sig.signingCert = fs.readFileSync("my_public_cert.pem", "latin1");
336+
sig.publicCert = fs.readFileSync("my_public_cert.pem", "latin1");
337337
sig.canonicalizationAlgorithm = "http://MyCanonicalization";
338338
sig.addReference(
339339
"//*[local-name(.)='x']",
340340
["http://MyTransformation"],
341341
"http://myDigestAlgorithm"
342342
);
343343

344-
sig.signingKey = fs.readFileSync(key);
344+
sig.privateKey = fs.readFileSync(key);
345345
sig.addReference(xpath);
346346
sig.computeSignature(xml);
347347
fs.writeFileSync(dest, sig.getSignedXml());
@@ -361,10 +361,10 @@ If the private key is not stored locally and you wish to use a signing server or
361361

362362
```javascript
363363
function AsyncSignatureAlgorithm() {
364-
this.getSignature = function (signedInfo, signingKey, callback) {
364+
this.getSignature = function (signedInfo, privateKey, callback) {
365365
var signer = crypto.createSign("RSA-SHA1");
366366
signer.update(signedInfo);
367-
var res = signer.sign(signingKey, "base64");
367+
var res = signer.sign(privateKey, "base64");
368368
//Do some asynchronous things here
369369
callback(null, res);
370370
};
@@ -427,7 +427,7 @@ var xml = "<library>" + "<book>" + "<name>Harry Potter</name>" + "</book>" + "</
427427

428428
var sig = new SignedXml();
429429
sig.addReference("//*[local-name(.)='book']");
430-
sig.signingKey = fs.readFileSync("client.pem");
430+
sig.privateKey = fs.readFileSync("client.pem");
431431
sig.computeSignature(xml, {
432432
prefix: "ds",
433433
});
@@ -451,7 +451,7 @@ var xml = "<library>" + "<book>" + "<name>Harry Potter</name>" + "</book>" + "</
451451

452452
var sig = new SignedXml();
453453
sig.addReference("//*[local-name(.)='book']");
454-
sig.signingKey = fs.readFileSync("client.pem");
454+
sig.privateKey = fs.readFileSync("client.pem");
455455
sig.computeSignature(xml, {
456456
location: { reference: "//*[local-name(.)='book']", action: "after" }, //This will place the signature after the book element
457457
});

example/example.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const fs = require("fs");
77

88
function signXml(xml, xpath, key, dest) {
99
const sig = new SignedXml();
10-
sig.signingKey = fs.readFileSync(key);
10+
sig.privateKey = fs.readFileSync(key);
1111
sig.addReference(xpath);
1212
sig.computeSignature(xml);
1313
fs.writeFileSync(dest, sig.getSignedXml());
@@ -20,7 +20,7 @@ function validateXml(xml, key) {
2020
doc
2121
)[0];
2222
const sig = new SignedXml();
23-
sig.signingCert = key;
23+
sig.publicCert = key;
2424
sig.loadSignature(signature.toString());
2525
const res = sig.checkSignature(xml);
2626
if (!res) {

index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export interface HashAlgorithm {
9797
export interface SignatureAlgorithm {
9898
getAlgorithmName(): SignatureAlgorithmType;
9999

100-
getSignature(signedInfo: Node, signingKey: Buffer): string;
100+
getSignature(signedInfo: Node, privateKey: Buffer): string;
101101
}
102102

103103
/** Implement this to create a new TransformAlgorithm */
@@ -110,8 +110,8 @@ export interface TransformAlgorithm {
110110
/**
111111
* ### Sign
112112
* #### Properties
113-
* - {@link SignedXml#signingKey} [required]
114-
* - {@link SignedXml#keyInfoProvider} [optional]
113+
* - {@link SignedXml#privateKey} [required]
114+
* - {@link SignedXml#publicCert} [optional]
115115
* - {@link SignedXml#signatureAlgorithm} [optional]
116116
* - {@link SignedXml#canonicalizationAlgorithm} [optional]
117117
* #### Api
@@ -123,7 +123,7 @@ export interface TransformAlgorithm {
123123
*
124124
* ### Verify
125125
* #### Properties
126-
* - {@link SignedXml#keyInfoProvider} [required]
126+
* - {@link SignedXml#publicCert} [optional]
127127
* #### Api
128128
* - {@link SignedXml#loadSignature}
129129
* - {@link SignedXml#checkSignature}

lib/signed-xml.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ function RSASHA1() {
5858
* Sign the given string using the given key
5959
*
6060
*/
61-
this.getSignature = function (signedInfo, signingKey, callback) {
61+
this.getSignature = function (signedInfo, privateKey, callback) {
6262
const signer = crypto.createSign("RSA-SHA1");
6363
signer.update(signedInfo);
64-
const res = signer.sign(signingKey, "base64");
64+
const res = signer.sign(privateKey, "base64");
6565
if (callback) {
6666
callback(null, res);
6767
}
@@ -96,10 +96,10 @@ function RSASHA256() {
9696
* Sign the given string using the given key
9797
*
9898
*/
99-
this.getSignature = function (signedInfo, signingKey, callback) {
99+
this.getSignature = function (signedInfo, privateKey, callback) {
100100
const signer = crypto.createSign("RSA-SHA256");
101101
signer.update(signedInfo);
102-
const res = signer.sign(signingKey, "base64");
102+
const res = signer.sign(privateKey, "base64");
103103
if (callback) {
104104
callback(null, res);
105105
}
@@ -134,10 +134,10 @@ function RSASHA512() {
134134
* Sign the given string using the given key
135135
*
136136
*/
137-
this.getSignature = function (signedInfo, signingKey, callback) {
137+
this.getSignature = function (signedInfo, privateKey, callback) {
138138
const signer = crypto.createSign("RSA-SHA512");
139139
signer.update(signedInfo);
140-
const res = signer.sign(signingKey, "base64");
140+
const res = signer.sign(privateKey, "base64");
141141
if (callback) {
142142
callback(null, res);
143143
}
@@ -175,8 +175,8 @@ function HMACSHA1() {
175175
return "http://www.w3.org/2000/09/xmldsig#hmac-sha1";
176176
};
177177

178-
this.getSignature = function (signedInfo, signingKey) {
179-
const verifier = crypto.createHmac("SHA1", signingKey);
178+
this.getSignature = function (signedInfo, privateKey) {
179+
const verifier = crypto.createHmac("SHA1", privateKey);
180180
verifier.update(signedInfo);
181181
const res = verifier.digest("base64");
182182
return res;
@@ -311,8 +311,8 @@ function SignedXml(idMode, options) {
311311
this.idMode = idMode;
312312
this.references = [];
313313
this.id = 0;
314-
this.signingKey = null;
315-
this.signingCert = null;
314+
this.privateKey = null;
315+
this.publicCert = null;
316316
this.signatureAlgorithm =
317317
this.options.signatureAlgorithm || "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
318318
this.canonicalizationAlgorithm =
@@ -504,7 +504,7 @@ SignedXml.prototype.validateSignatureValue = function (doc, callback) {
504504
const signer = this.findSignatureAlgorithm(this.signatureAlgorithm);
505505
const res = signer.verifySignature(
506506
signedInfoCanon,
507-
this.getCertFromKeyInfo(this.keyInfo) || this.signingCert || this.signingKey,
507+
this.getCertFromKeyInfo(this.keyInfo) || this.publicCert || this.privateKey,
508508
this.signatureValue,
509509
callback
510510
);
@@ -519,7 +519,7 @@ SignedXml.prototype.validateSignatureValue = function (doc, callback) {
519519
SignedXml.prototype.calculateSignatureValue = function (doc, callback) {
520520
const signedInfoCanon = this.getCanonSignedInfoXml(doc);
521521
const signer = this.findSignatureAlgorithm(this.signatureAlgorithm);
522-
this.signatureValue = signer.getSignature(signedInfoCanon, this.signingKey, callback);
522+
this.signatureValue = signer.getSignature(signedInfoCanon, this.privateKey, callback);
523523
};
524524

525525
SignedXml.prototype.findSignatureAlgorithm = function (name) {
@@ -954,7 +954,7 @@ SignedXml.prototype.getKeyInfo = function (prefix) {
954954
keyInfoAttrs += " " + name + '="' + this.keyInfoAttributes[name] + '"';
955955
});
956956
}
957-
const keyInfoContent = this.getKeyInfoContent({ publicCert: this.signingCert, prefix });
957+
const keyInfoContent = this.getKeyInfoContent({ publicCert: this.publicCert, prefix });
958958
if (keyInfoAttrs !== "" || keyInfoContent != null) {
959959
res += "<" + currentPrefix + "KeyInfo" + keyInfoAttrs + ">";
960960
res += keyInfoContent;

test/document-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe("Document tests", function () {
1717
.toString()
1818
);
1919
const sig = new crypto.SignedXml();
20-
sig.signingCert = fs.readFileSync("./test/static/feide_public.pem");
20+
sig.publicCert = fs.readFileSync("./test/static/feide_public.pem");
2121
sig.loadSignature(signature);
2222
const result = sig.checkSignature(xml);
2323

@@ -37,7 +37,7 @@ describe("Document tests", function () {
3737
);
3838
const sig = new crypto.SignedXml();
3939
const feidePublicCert = fs.readFileSync("./test/static/feide_public.pem");
40-
sig.signingCert = feidePublicCert;
40+
sig.publicCert = feidePublicCert;
4141
sig.loadSignature(signature);
4242
const result = sig.checkSignature(xml);
4343

test/hmac-tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("HMAC tests", function () {
1515
)[0];
1616
const sig = new crypto.SignedXml();
1717
sig.enableHMAC();
18-
sig.signingCert = fs.readFileSync("./test/static/hmac.key");
18+
sig.publicCert = fs.readFileSync("./test/static/hmac.key");
1919
sig.loadSignature(signature);
2020
const result = sig.checkSignature(xml);
2121

@@ -31,7 +31,7 @@ describe("HMAC tests", function () {
3131
)[0];
3232
const sig = new crypto.SignedXml();
3333
sig.enableHMAC();
34-
sig.signingCert = fs.readFileSync("./test/static/hmac-foobar.key");
34+
sig.publicCert = fs.readFileSync("./test/static/hmac-foobar.key");
3535
sig.loadSignature(signature);
3636
const result = sig.checkSignature(xml);
3737

@@ -42,7 +42,7 @@ describe("HMAC tests", function () {
4242
const xml = "<library>" + "<book>" + "<name>Harry Potter</name>" + "</book>" + "</library>";
4343
const sig = new crypto.SignedXml();
4444
sig.enableHMAC();
45-
sig.signingKey = fs.readFileSync("./test/static/hmac.key");
45+
sig.privateKey = fs.readFileSync("./test/static/hmac.key");
4646
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#hmac-sha1";
4747
sig.addReference("//*[local-name(.)='book']");
4848
sig.computeSignature(xml);
@@ -54,7 +54,7 @@ describe("HMAC tests", function () {
5454
)[0];
5555
const verify = new crypto.SignedXml();
5656
verify.enableHMAC();
57-
verify.signingCert = fs.readFileSync("./test/static/hmac.key");
57+
verify.publicCert = fs.readFileSync("./test/static/hmac.key");
5858
verify.loadSignature(signature);
5959
const result = verify.checkSignature(sig.getSignedXml());
6060

test/key-info-tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ describe("KeyInfo tests", function () {
1010
it("adds X509Certificate element during signature", function () {
1111
const xml = "<root><x /></root>";
1212
const sig = new SignedXml();
13-
sig.signingKey = fs.readFileSync("./test/static/client.pem");
14-
sig.signingCert = fs.readFileSync("./test/static/client_public.pem");
13+
sig.privateKey = fs.readFileSync("./test/static/client.pem");
14+
sig.publicCert = fs.readFileSync("./test/static/client_public.pem");
1515
sig.computeSignature(xml);
1616
const signedXml = sig.getSignedXml();
1717
const doc = new xmldom.DOMParser().parseFromString(signedXml);
@@ -22,8 +22,8 @@ describe("KeyInfo tests", function () {
2222
it("make sure private hmac key is not leaked due to key confusion", function () {
2323
const xml = "<library>" + "<book>" + "<name>Harry Potter</name>" + "</book>" + "</library>";
2424
const sig = new crypto.SignedXml();
25-
sig.signingKey = fs.readFileSync("./test/static/hmac.key");
26-
sig.signingCert = fs.readFileSync("./test/static/hmac.key");
25+
sig.privateKey = fs.readFileSync("./test/static/hmac.key");
26+
sig.publicCert = fs.readFileSync("./test/static/hmac.key");
2727
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#hmac-sha1";
2828
sig.enableHMAC();
2929
sig.addReference("//*[local-name(.)='book']");

test/saml-response-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("SAML response tests", function () {
1313
doc
1414
)[0];
1515
const sig = new crypto.SignedXml();
16-
sig.signingCert = fs.readFileSync("./test/static/feide_public.pem");
16+
sig.publicCert = fs.readFileSync("./test/static/feide_public.pem");
1717
sig.loadSignature(signature);
1818
const result = sig.checkSignature(xml);
1919

@@ -29,7 +29,7 @@ describe("SAML response tests", function () {
2929
assertion
3030
)[0];
3131
const sig = new crypto.SignedXml();
32-
sig.signingCert = fs.readFileSync("./test/static/feide_public.pem");
32+
sig.publicCert = fs.readFileSync("./test/static/feide_public.pem");
3333
sig.loadSignature(signature);
3434
expect(function () {
3535
sig.checkSignature(xml);
@@ -46,7 +46,7 @@ describe("SAML response tests", function () {
4646
doc
4747
)[0];
4848
const sig = new crypto.SignedXml();
49-
sig.signingCert = fs.readFileSync("./test/static/saml_external_ns.pem");
49+
sig.publicCert = fs.readFileSync("./test/static/saml_external_ns.pem");
5050
sig.loadSignature(signature);
5151
const result = sig.checkSignature(xml);
5252
expect(result).to.be.true;
@@ -61,7 +61,7 @@ describe("SAML response tests", function () {
6161
assertion
6262
)[0];
6363
const sig = new crypto.SignedXml();
64-
sig.signingCert = fs.readFileSync("./test/static/feide_public.pem");
64+
sig.publicCert = fs.readFileSync("./test/static/feide_public.pem");
6565
sig.loadSignature(signature);
6666
expect(function () {
6767
sig.checkSignature(xml);
@@ -76,7 +76,7 @@ describe("SAML response tests", function () {
7676
doc
7777
)[0];
7878
const sig = new crypto.SignedXml();
79-
sig.signingCert = fs.readFileSync("./test/static/feide_public.pem");
79+
sig.publicCert = fs.readFileSync("./test/static/feide_public.pem");
8080
sig.loadSignature(signature);
8181
const result = sig.checkSignature(xml);
8282
// This doesn't matter, just want to make sure that we don't fail due to unknown algorithm

0 commit comments

Comments
 (0)