xml-crypto-next 7.0.3 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/c14n-canonicalization-2.d.ts +37 -0
- package/build/c14n-canonicalization-2.d.ts.map +1 -0
- package/build/c14n-canonicalization-2.js +228 -0
- package/build/c14n-canonicalization.d.ts +48 -0
- package/build/c14n-canonicalization.d.ts.map +1 -0
- package/{lib → build}/c14n-canonicalization.js +95 -75
- package/{lib → build}/enveloped-signature.d.ts +1 -1
- package/build/enveloped-signature.d.ts.map +1 -0
- package/{lib → build}/enveloped-signature.js +4 -9
- package/build/exclusive-canonicalization.d.ts +57 -0
- package/build/exclusive-canonicalization.d.ts.map +1 -0
- package/{lib → build}/exclusive-canonicalization.js +116 -102
- package/{lib → build}/hash-algorithms.d.ts +5 -1
- package/build/hash-algorithms.d.ts.map +1 -0
- package/build/hash-algorithms.js +70 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +23 -0
- package/build/signature-algorithms.d.ts +244 -0
- package/build/signature-algorithms.d.ts.map +1 -0
- package/build/signature-algorithms.js +480 -0
- package/{lib → build}/signed-xml.d.ts +2 -2
- package/build/signed-xml.d.ts.map +1 -0
- package/{lib → build}/signed-xml.js +143 -102
- package/{lib → build}/types.d.ts +43 -6
- package/build/types.d.ts.map +1 -0
- package/{lib → build}/types.js +1 -5
- package/{lib → build}/utils.d.ts +34 -4
- package/build/utils.d.ts.map +1 -0
- package/{lib → build}/utils.js +189 -62
- package/build/xmldsig2-transform.d.ts +18 -0
- package/build/xmldsig2-transform.d.ts.map +1 -0
- package/build/xmldsig2-transform.js +65 -0
- package/package.json +74 -73
- package/types/c14n-canonicalization-2.d.ts +38 -0
- package/types/c14n-canonicalization-2.d.ts.map +1 -0
- package/types/c14n-canonicalization.d.ts +49 -0
- package/types/c14n-canonicalization.d.ts.map +1 -0
- package/types/enveloped-signature.d.ts +8 -0
- package/types/enveloped-signature.d.ts.map +1 -0
- package/types/exclusive-canonicalization.d.ts +58 -0
- package/types/exclusive-canonicalization.d.ts.map +1 -0
- package/types/hash-algorithms.d.ts +26 -0
- package/types/hash-algorithms.d.ts.map +1 -0
- package/types/index.d.ts +10 -0
- package/types/index.d.ts.map +1 -0
- package/types/signature-algorithms.d.ts +112 -0
- package/types/signature-algorithms.d.ts.map +1 -0
- package/types/signed-xml.d.ts +237 -0
- package/types/signed-xml.d.ts.map +1 -0
- package/types/src/c14n-canonicalization-2.d.ts +38 -0
- package/types/src/c14n-canonicalization-2.d.ts.map +1 -0
- package/types/src/c14n-canonicalization.d.ts +49 -0
- package/types/src/c14n-canonicalization.d.ts.map +1 -0
- package/types/src/enveloped-signature.d.ts +8 -0
- package/types/src/enveloped-signature.d.ts.map +1 -0
- package/types/src/exclusive-canonicalization.d.ts +58 -0
- package/types/src/exclusive-canonicalization.d.ts.map +1 -0
- package/types/src/hash-algorithms.d.ts +26 -0
- package/types/src/hash-algorithms.d.ts.map +1 -0
- package/types/src/index.d.ts +10 -0
- package/types/src/index.d.ts.map +1 -0
- package/types/src/signature-algorithms.d.ts +245 -0
- package/types/src/signature-algorithms.d.ts.map +1 -0
- package/types/src/signed-xml.d.ts +237 -0
- package/types/src/signed-xml.d.ts.map +1 -0
- package/types/src/types.d.ts +182 -0
- package/types/src/types.d.ts.map +1 -0
- package/types/src/utils.d.ts +96 -0
- package/types/src/utils.d.ts.map +1 -0
- package/types/src/xmldsig2-transform.d.ts +19 -0
- package/types/src/xmldsig2-transform.d.ts.map +1 -0
- package/types/types.d.ts +182 -0
- package/types/types.d.ts.map +1 -0
- package/types/utils.d.ts +96 -0
- package/types/utils.d.ts.map +1 -0
- package/types/xmldsig2-transform.d.ts +19 -0
- package/types/xmldsig2-transform.d.ts.map +1 -0
- package/lib/c14n-canonicalization.d.ts +0 -39
- package/lib/c14n-canonicalization.js.map +0 -1
- package/lib/enveloped-signature.js.map +0 -1
- package/lib/exclusive-canonicalization.d.ts +0 -38
- package/lib/exclusive-canonicalization.js.map +0 -1
- package/lib/hash-algorithms.js +0 -84
- package/lib/hash-algorithms.js.map +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -28
- package/lib/index.js.map +0 -1
- package/lib/signature-algorithms.d.ts +0 -112
- package/lib/signature-algorithms.js +0 -304
- package/lib/signature-algorithms.js.map +0 -1
- package/lib/signed-xml.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/utils.js.map +0 -1
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
import * as crypto from "crypto";
|
|
2
|
+
import { createOptionalCallbackFunction } from "./types.js";
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// RSA Signature Algorithms
|
|
5
|
+
// ============================================================================
|
|
6
|
+
export class RsaSha1 {
|
|
7
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
8
|
+
const signer = crypto.createSign("RSA-SHA1");
|
|
9
|
+
signer.update(signedInfo);
|
|
10
|
+
const res = signer.sign(privateKey, "base64");
|
|
11
|
+
return res;
|
|
12
|
+
});
|
|
13
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
14
|
+
const verifier = crypto.createVerify("RSA-SHA1");
|
|
15
|
+
verifier.update(material);
|
|
16
|
+
const res = verifier.verify(key, signatureValue, "base64");
|
|
17
|
+
return res;
|
|
18
|
+
});
|
|
19
|
+
getAlgorithmName = () => {
|
|
20
|
+
return "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export class RsaSha224 {
|
|
24
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
25
|
+
const signer = crypto.createSign("RSA-SHA224");
|
|
26
|
+
signer.update(signedInfo);
|
|
27
|
+
const res = signer.sign(privateKey, "base64");
|
|
28
|
+
return res;
|
|
29
|
+
});
|
|
30
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
31
|
+
const verifier = crypto.createVerify("RSA-SHA224");
|
|
32
|
+
verifier.update(material);
|
|
33
|
+
const res = verifier.verify(key, signatureValue, "base64");
|
|
34
|
+
return res;
|
|
35
|
+
});
|
|
36
|
+
getAlgorithmName = () => {
|
|
37
|
+
return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha224";
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export class RsaSha256 {
|
|
41
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
42
|
+
const signer = crypto.createSign("RSA-SHA256");
|
|
43
|
+
signer.update(signedInfo);
|
|
44
|
+
const res = signer.sign(privateKey, "base64");
|
|
45
|
+
return res;
|
|
46
|
+
});
|
|
47
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
48
|
+
const verifier = crypto.createVerify("RSA-SHA256");
|
|
49
|
+
verifier.update(material);
|
|
50
|
+
const res = verifier.verify(key, signatureValue, "base64");
|
|
51
|
+
return res;
|
|
52
|
+
});
|
|
53
|
+
getAlgorithmName = () => {
|
|
54
|
+
return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export class RsaSha384 {
|
|
58
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
59
|
+
const signer = crypto.createSign("RSA-SHA384");
|
|
60
|
+
signer.update(signedInfo);
|
|
61
|
+
const res = signer.sign(privateKey, "base64");
|
|
62
|
+
return res;
|
|
63
|
+
});
|
|
64
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
65
|
+
const verifier = crypto.createVerify("RSA-SHA384");
|
|
66
|
+
verifier.update(material);
|
|
67
|
+
const res = verifier.verify(key, signatureValue, "base64");
|
|
68
|
+
return res;
|
|
69
|
+
});
|
|
70
|
+
getAlgorithmName = () => {
|
|
71
|
+
return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384";
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export class RsaSha512 {
|
|
75
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
76
|
+
const signer = crypto.createSign("RSA-SHA512");
|
|
77
|
+
signer.update(signedInfo);
|
|
78
|
+
const res = signer.sign(privateKey, "base64");
|
|
79
|
+
return res;
|
|
80
|
+
});
|
|
81
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
82
|
+
const verifier = crypto.createVerify("RSA-SHA512");
|
|
83
|
+
verifier.update(material);
|
|
84
|
+
const res = verifier.verify(key, signatureValue, "base64");
|
|
85
|
+
return res;
|
|
86
|
+
});
|
|
87
|
+
getAlgorithmName = () => {
|
|
88
|
+
return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512";
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// ============================================================================
|
|
92
|
+
// RSA-PSS Signature Algorithms (MGF1)
|
|
93
|
+
// ============================================================================
|
|
94
|
+
export class RsaSha256Mgf1 {
|
|
95
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
96
|
+
if (!(typeof privateKey === "string" || Buffer.isBuffer(privateKey))) {
|
|
97
|
+
throw new Error("keys must be strings or buffers");
|
|
98
|
+
}
|
|
99
|
+
const signer = crypto.createSign("RSA-SHA256");
|
|
100
|
+
signer.update(signedInfo);
|
|
101
|
+
const res = signer.sign({
|
|
102
|
+
key: privateKey,
|
|
103
|
+
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
|
104
|
+
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST,
|
|
105
|
+
}, "base64");
|
|
106
|
+
return res;
|
|
107
|
+
});
|
|
108
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
109
|
+
if (!(typeof key === "string" || Buffer.isBuffer(key))) {
|
|
110
|
+
throw new Error("keys must be strings or buffers");
|
|
111
|
+
}
|
|
112
|
+
const verifier = crypto.createVerify("RSA-SHA256");
|
|
113
|
+
verifier.update(material);
|
|
114
|
+
const res = verifier.verify({
|
|
115
|
+
key: key,
|
|
116
|
+
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
|
117
|
+
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST,
|
|
118
|
+
}, signatureValue, "base64");
|
|
119
|
+
return res;
|
|
120
|
+
});
|
|
121
|
+
getAlgorithmName = () => {
|
|
122
|
+
return "http://www.w3.org/2007/05/xmldsig-more#sha256-rsa-MGF1";
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export class RsaSha384Mgf1 {
|
|
126
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
127
|
+
if (!(typeof privateKey === "string" || Buffer.isBuffer(privateKey))) {
|
|
128
|
+
throw new Error("keys must be strings or buffers");
|
|
129
|
+
}
|
|
130
|
+
const signer = crypto.createSign("RSA-SHA384");
|
|
131
|
+
signer.update(signedInfo);
|
|
132
|
+
const res = signer.sign({
|
|
133
|
+
key: privateKey,
|
|
134
|
+
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
|
135
|
+
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST,
|
|
136
|
+
}, "base64");
|
|
137
|
+
return res;
|
|
138
|
+
});
|
|
139
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
140
|
+
if (!(typeof key === "string" || Buffer.isBuffer(key))) {
|
|
141
|
+
throw new Error("keys must be strings or buffers");
|
|
142
|
+
}
|
|
143
|
+
const verifier = crypto.createVerify("RSA-SHA384");
|
|
144
|
+
verifier.update(material);
|
|
145
|
+
const res = verifier.verify({
|
|
146
|
+
key: key,
|
|
147
|
+
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
|
148
|
+
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST,
|
|
149
|
+
}, signatureValue, "base64");
|
|
150
|
+
return res;
|
|
151
|
+
});
|
|
152
|
+
getAlgorithmName = () => {
|
|
153
|
+
return "http://www.w3.org/2007/05/xmldsig-more#sha384-rsa-MGF1";
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export class RsaSha512Mgf1 {
|
|
157
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
158
|
+
if (!(typeof privateKey === "string" || Buffer.isBuffer(privateKey))) {
|
|
159
|
+
throw new Error("keys must be strings or buffers");
|
|
160
|
+
}
|
|
161
|
+
const signer = crypto.createSign("RSA-SHA512");
|
|
162
|
+
signer.update(signedInfo);
|
|
163
|
+
const res = signer.sign({
|
|
164
|
+
key: privateKey,
|
|
165
|
+
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
|
166
|
+
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST,
|
|
167
|
+
}, "base64");
|
|
168
|
+
return res;
|
|
169
|
+
});
|
|
170
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
171
|
+
if (!(typeof key === "string" || Buffer.isBuffer(key))) {
|
|
172
|
+
throw new Error("keys must be strings or buffers");
|
|
173
|
+
}
|
|
174
|
+
const verifier = crypto.createVerify("RSA-SHA512");
|
|
175
|
+
verifier.update(material);
|
|
176
|
+
const res = verifier.verify({
|
|
177
|
+
key: key,
|
|
178
|
+
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
|
179
|
+
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST,
|
|
180
|
+
}, signatureValue, "base64");
|
|
181
|
+
return res;
|
|
182
|
+
});
|
|
183
|
+
getAlgorithmName = () => {
|
|
184
|
+
return "http://www.w3.org/2007/05/xmldsig-more#sha512-rsa-MGF1";
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
// ============================================================================
|
|
188
|
+
// ECDSA Signature Algorithms
|
|
189
|
+
// ============================================================================
|
|
190
|
+
export class EcdsaSha1 {
|
|
191
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
192
|
+
const signer = crypto.createSign("SHA1");
|
|
193
|
+
signer.update(signedInfo);
|
|
194
|
+
const res = signer.sign(privateKey);
|
|
195
|
+
return res.toString("base64");
|
|
196
|
+
});
|
|
197
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
198
|
+
const verifier = crypto.createVerify("SHA1");
|
|
199
|
+
verifier.update(material);
|
|
200
|
+
const res = verifier.verify(key, Buffer.from(signatureValue, "base64"));
|
|
201
|
+
return res;
|
|
202
|
+
});
|
|
203
|
+
getAlgorithmName = () => {
|
|
204
|
+
return "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1";
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
export class EcdsaSha224 {
|
|
208
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
209
|
+
const signer = crypto.createSign("SHA224");
|
|
210
|
+
signer.update(signedInfo);
|
|
211
|
+
const res = signer.sign(privateKey);
|
|
212
|
+
return res.toString("base64");
|
|
213
|
+
});
|
|
214
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
215
|
+
const verifier = crypto.createVerify("SHA224");
|
|
216
|
+
verifier.update(material);
|
|
217
|
+
const res = verifier.verify(key, Buffer.from(signatureValue, "base64"));
|
|
218
|
+
return res;
|
|
219
|
+
});
|
|
220
|
+
getAlgorithmName = () => {
|
|
221
|
+
return "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha224";
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
export class EcdsaSha256 {
|
|
225
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
226
|
+
const signer = crypto.createSign("SHA256");
|
|
227
|
+
signer.update(signedInfo);
|
|
228
|
+
const res = signer.sign(privateKey);
|
|
229
|
+
return res.toString("base64");
|
|
230
|
+
});
|
|
231
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
232
|
+
const verifier = crypto.createVerify("SHA256");
|
|
233
|
+
verifier.update(material);
|
|
234
|
+
const res = verifier.verify(key, Buffer.from(signatureValue, "base64"));
|
|
235
|
+
return res;
|
|
236
|
+
});
|
|
237
|
+
getAlgorithmName = () => {
|
|
238
|
+
return "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256";
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
export class EcdsaSha384 {
|
|
242
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
243
|
+
const signer = crypto.createSign("SHA384");
|
|
244
|
+
signer.update(signedInfo);
|
|
245
|
+
const res = signer.sign(privateKey);
|
|
246
|
+
return res.toString("base64");
|
|
247
|
+
});
|
|
248
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
249
|
+
const verifier = crypto.createVerify("SHA384");
|
|
250
|
+
verifier.update(material);
|
|
251
|
+
const res = verifier.verify(key, Buffer.from(signatureValue, "base64"));
|
|
252
|
+
return res;
|
|
253
|
+
});
|
|
254
|
+
getAlgorithmName = () => {
|
|
255
|
+
return "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384";
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
export class EcdsaSha512 {
|
|
259
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
260
|
+
const signer = crypto.createSign("SHA512");
|
|
261
|
+
signer.update(signedInfo);
|
|
262
|
+
const res = signer.sign(privateKey);
|
|
263
|
+
return res.toString("base64");
|
|
264
|
+
});
|
|
265
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
266
|
+
const verifier = crypto.createVerify("SHA512");
|
|
267
|
+
verifier.update(material);
|
|
268
|
+
const res = verifier.verify(key, Buffer.from(signatureValue, "base64"));
|
|
269
|
+
return res;
|
|
270
|
+
});
|
|
271
|
+
getAlgorithmName = () => {
|
|
272
|
+
return "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512";
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
// ============================================================================
|
|
276
|
+
// DSA Signature Algorithms
|
|
277
|
+
// ============================================================================
|
|
278
|
+
export class DsaSha1 {
|
|
279
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
280
|
+
const signer = crypto.createSign("DSA-SHA1");
|
|
281
|
+
signer.update(signedInfo);
|
|
282
|
+
const res = signer.sign(privateKey, "base64");
|
|
283
|
+
return res;
|
|
284
|
+
});
|
|
285
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
286
|
+
const verifier = crypto.createVerify("DSA-SHA1");
|
|
287
|
+
verifier.update(material);
|
|
288
|
+
const res = verifier.verify(key, signatureValue, "base64");
|
|
289
|
+
return res;
|
|
290
|
+
});
|
|
291
|
+
getAlgorithmName = () => {
|
|
292
|
+
return "http://www.w3.org/2000/09/xmldsig#dsa-sha1";
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
export class DsaSha256 {
|
|
296
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
297
|
+
const signer = crypto.createSign("DSA-SHA256");
|
|
298
|
+
signer.update(signedInfo);
|
|
299
|
+
const res = signer.sign(privateKey, "base64");
|
|
300
|
+
return res;
|
|
301
|
+
});
|
|
302
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
303
|
+
const verifier = crypto.createVerify("DSA-SHA256");
|
|
304
|
+
verifier.update(material);
|
|
305
|
+
const res = verifier.verify(key, signatureValue, "base64");
|
|
306
|
+
return res;
|
|
307
|
+
});
|
|
308
|
+
getAlgorithmName = () => {
|
|
309
|
+
return "http://www.w3.org/2009/xmldsig11#dsa-sha256";
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
// ============================================================================
|
|
313
|
+
// EdDSA Signature Algorithms
|
|
314
|
+
// ============================================================================
|
|
315
|
+
export class Ed25519 {
|
|
316
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
317
|
+
if (!(typeof privateKey === "string" || Buffer.isBuffer(privateKey))) {
|
|
318
|
+
throw new Error("keys must be strings or buffers");
|
|
319
|
+
}
|
|
320
|
+
const dataToSign = typeof signedInfo === 'string'
|
|
321
|
+
? Buffer.from(signedInfo, 'utf8')
|
|
322
|
+
: signedInfo;
|
|
323
|
+
const signature = crypto.sign(null, dataToSign, privateKey);
|
|
324
|
+
return signature.toString('base64');
|
|
325
|
+
});
|
|
326
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
327
|
+
if (!(typeof key === "string" || Buffer.isBuffer(key))) {
|
|
328
|
+
throw new Error("keys must be strings or buffers");
|
|
329
|
+
}
|
|
330
|
+
const signature = Buffer.from(signatureValue, 'base64');
|
|
331
|
+
const dataToVerify = typeof material === 'string'
|
|
332
|
+
? Buffer.from(material, 'utf8')
|
|
333
|
+
: material;
|
|
334
|
+
return crypto.verify(null, dataToVerify, key, signature);
|
|
335
|
+
});
|
|
336
|
+
getAlgorithmName = () => {
|
|
337
|
+
return "http://www.w3.org/2007/05/xmldsig-more#eddsa-ed25519";
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
export class Ed448 {
|
|
341
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
342
|
+
if (!(typeof privateKey === "string" || Buffer.isBuffer(privateKey))) {
|
|
343
|
+
throw new Error("keys must be strings or buffers");
|
|
344
|
+
}
|
|
345
|
+
const dataToSign = typeof signedInfo === 'string'
|
|
346
|
+
? Buffer.from(signedInfo, 'utf8')
|
|
347
|
+
: signedInfo;
|
|
348
|
+
const signature = crypto.sign(null, dataToSign, privateKey);
|
|
349
|
+
return signature.toString('base64');
|
|
350
|
+
});
|
|
351
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
352
|
+
if (!(typeof key === "string" || Buffer.isBuffer(key))) {
|
|
353
|
+
throw new Error("keys must be strings or buffers");
|
|
354
|
+
}
|
|
355
|
+
const signature = Buffer.from(signatureValue, 'base64');
|
|
356
|
+
const dataToVerify = typeof material === 'string'
|
|
357
|
+
? Buffer.from(material, 'utf8')
|
|
358
|
+
: material;
|
|
359
|
+
return crypto.verify(null, dataToVerify, key, signature);
|
|
360
|
+
});
|
|
361
|
+
getAlgorithmName = () => {
|
|
362
|
+
return "http://www.w3.org/2021/04/xmldsig-more#eddsa-ed448";
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
// ============================================================================
|
|
366
|
+
// HMAC Signature Algorithms
|
|
367
|
+
// ============================================================================
|
|
368
|
+
export class HmacSha1 {
|
|
369
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
370
|
+
const signer = crypto.createHmac("SHA1", privateKey);
|
|
371
|
+
signer.update(signedInfo);
|
|
372
|
+
const res = signer.digest("base64");
|
|
373
|
+
return res;
|
|
374
|
+
});
|
|
375
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
376
|
+
const verifier = crypto.createHmac("SHA1", key);
|
|
377
|
+
verifier.update(material);
|
|
378
|
+
const res = verifier.digest("base64");
|
|
379
|
+
// Use constant-time comparison to prevent timing attacks (CWE-208)
|
|
380
|
+
// See: https://github.com/node-saml/xml-crypto/issues/522
|
|
381
|
+
try {
|
|
382
|
+
return crypto.timingSafeEqual(Buffer.from(res, "base64"), Buffer.from(signatureValue, "base64"));
|
|
383
|
+
}
|
|
384
|
+
catch (e) {
|
|
385
|
+
// timingSafeEqual throws if buffer lengths don't match
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
getAlgorithmName = () => {
|
|
390
|
+
return "http://www.w3.org/2000/09/xmldsig#hmac-sha1";
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
export class HmacSha224 {
|
|
394
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
395
|
+
const signer = crypto.createHmac("SHA224", privateKey);
|
|
396
|
+
signer.update(signedInfo);
|
|
397
|
+
const res = signer.digest("base64");
|
|
398
|
+
return res;
|
|
399
|
+
});
|
|
400
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
401
|
+
const verifier = crypto.createHmac("SHA224", key);
|
|
402
|
+
verifier.update(material);
|
|
403
|
+
const res = verifier.digest("base64");
|
|
404
|
+
try {
|
|
405
|
+
return crypto.timingSafeEqual(Buffer.from(res, "base64"), Buffer.from(signatureValue, "base64"));
|
|
406
|
+
}
|
|
407
|
+
catch (e) {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
getAlgorithmName = () => {
|
|
412
|
+
return "http://www.w3.org/2001/04/xmldsig-more#hmac-sha224";
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
export class HmacSha256 {
|
|
416
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
417
|
+
const signer = crypto.createHmac("SHA256", privateKey);
|
|
418
|
+
signer.update(signedInfo);
|
|
419
|
+
const res = signer.digest("base64");
|
|
420
|
+
return res;
|
|
421
|
+
});
|
|
422
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
423
|
+
const verifier = crypto.createHmac("SHA256", key);
|
|
424
|
+
verifier.update(material);
|
|
425
|
+
const res = verifier.digest("base64");
|
|
426
|
+
try {
|
|
427
|
+
return crypto.timingSafeEqual(Buffer.from(res, "base64"), Buffer.from(signatureValue, "base64"));
|
|
428
|
+
}
|
|
429
|
+
catch (e) {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
getAlgorithmName = () => {
|
|
434
|
+
return "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256";
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
export class HmacSha384 {
|
|
438
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
439
|
+
const signer = crypto.createHmac("SHA384", privateKey);
|
|
440
|
+
signer.update(signedInfo);
|
|
441
|
+
const res = signer.digest("base64");
|
|
442
|
+
return res;
|
|
443
|
+
});
|
|
444
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
445
|
+
const verifier = crypto.createHmac("SHA384", key);
|
|
446
|
+
verifier.update(material);
|
|
447
|
+
const res = verifier.digest("base64");
|
|
448
|
+
try {
|
|
449
|
+
return crypto.timingSafeEqual(Buffer.from(res, "base64"), Buffer.from(signatureValue, "base64"));
|
|
450
|
+
}
|
|
451
|
+
catch (e) {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
getAlgorithmName = () => {
|
|
456
|
+
return "http://www.w3.org/2001/04/xmldsig-more#hmac-sha384";
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
export class HmacSha512 {
|
|
460
|
+
getSignature = createOptionalCallbackFunction((signedInfo, privateKey) => {
|
|
461
|
+
const signer = crypto.createHmac("SHA512", privateKey);
|
|
462
|
+
signer.update(signedInfo);
|
|
463
|
+
const res = signer.digest("base64");
|
|
464
|
+
return res;
|
|
465
|
+
});
|
|
466
|
+
verifySignature = createOptionalCallbackFunction((material, key, signatureValue) => {
|
|
467
|
+
const verifier = crypto.createHmac("SHA512", key);
|
|
468
|
+
verifier.update(material);
|
|
469
|
+
const res = verifier.digest("base64");
|
|
470
|
+
try {
|
|
471
|
+
return crypto.timingSafeEqual(Buffer.from(res, "base64"), Buffer.from(signatureValue, "base64"));
|
|
472
|
+
}
|
|
473
|
+
catch (e) {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
getAlgorithmName = () => {
|
|
478
|
+
return "http://www.w3.org/2001/04/xmldsig-more#hmac-sha512";
|
|
479
|
+
};
|
|
480
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CanonicalizationAlgorithmType, CanonicalizationOrTransformAlgorithmType, CanonicalizationOrTransformationAlgorithm, CanonicalizationOrTransformationAlgorithmProcessOptions, ComputeSignatureOptions, ErrorFirstCallback, GetKeyInfoContentArgs, HashAlgorithm, HashAlgorithmType, ObjectAttributes, Reference, SignatureAlgorithm, SignatureAlgorithmType, SignedXmlOptions } from "./types";
|
|
1
|
+
import type { CanonicalizationAlgorithmType, CanonicalizationOrTransformAlgorithmType, CanonicalizationOrTransformationAlgorithm, CanonicalizationOrTransformationAlgorithmProcessOptions, ComputeSignatureOptions, ErrorFirstCallback, GetKeyInfoContentArgs, HashAlgorithm, HashAlgorithmType, ObjectAttributes, Reference, SignatureAlgorithm, SignatureAlgorithmType, SignedXmlOptions } from "./types.js";
|
|
2
2
|
import * as crypto from "crypto";
|
|
3
3
|
export declare class SignedXml {
|
|
4
4
|
idMode?: "wssecurity";
|
|
@@ -66,7 +66,7 @@ export declare class SignedXml {
|
|
|
66
66
|
static defaultNsForPrefix: {
|
|
67
67
|
ds: string;
|
|
68
68
|
};
|
|
69
|
-
static noop: () =>
|
|
69
|
+
static noop: () => any;
|
|
70
70
|
/**
|
|
71
71
|
* The SignedXml constructor provides an abstraction for sign and verify xml documents. The object is constructed using
|
|
72
72
|
* @param options {@link SignedXmlOptions}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signed-xml.d.ts","sourceRoot":"","sources":["../src/signed-xml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,wCAAwC,EACxC,yCAAyC,EACzC,uDAAuD,EACvD,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAIpB,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAajC,qBAAa,SAAS;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;IAC5B;;;OA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