xml-crypto-next 7.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/LICENSE +22 -0
- package/README.md +592 -0
- package/lib/c14n-canonicalization.d.ts +39 -0
- package/lib/c14n-canonicalization.js +230 -0
- package/lib/c14n-canonicalization.js.map +1 -0
- package/lib/enveloped-signature.d.ts +7 -0
- package/lib/enveloped-signature.js +43 -0
- package/lib/enveloped-signature.js.map +1 -0
- package/lib/exclusive-canonicalization.d.ts +38 -0
- package/lib/exclusive-canonicalization.js +246 -0
- package/lib/exclusive-canonicalization.js.map +1 -0
- package/lib/hash-algorithms.d.ts +13 -0
- package/lib/hash-algorithms.js +47 -0
- package/lib/hash-algorithms.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +28 -0
- package/lib/index.js.map +1 -0
- package/lib/signature-algorithms.d.ts +104 -0
- package/lib/signature-algorithms.js +242 -0
- package/lib/signature-algorithms.js.map +1 -0
- package/lib/signed-xml.d.ts +236 -0
- package/lib/signed-xml.js +1040 -0
- package/lib/signed-xml.js.map +1 -0
- package/lib/types.d.ts +144 -0
- package/lib/types.js +56 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +65 -0
- package/lib/utils.js +271 -0
- package/lib/utils.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import type { CanonicalizationAlgorithmType, CanonicalizationOrTransformAlgorithmType, CanonicalizationOrTransformationAlgorithm, CanonicalizationOrTransformationAlgorithmProcessOptions, ComputeSignatureOptions, ErrorFirstCallback, GetKeyInfoContentArgs, HashAlgorithm, HashAlgorithmType, ObjectAttributes, Reference, SignatureAlgorithm, SignatureAlgorithmType, SignedXmlOptions } from "./types";
|
|
2
|
+
import * as crypto from "crypto";
|
|
3
|
+
export declare class SignedXml {
|
|
4
|
+
idMode?: "wssecurity";
|
|
5
|
+
idAttributes: string[];
|
|
6
|
+
/**
|
|
7
|
+
* A {@link Buffer} or pem encoded {@link String} containing your private key
|
|
8
|
+
*/
|
|
9
|
+
privateKey?: crypto.KeyLike;
|
|
10
|
+
publicCert?: crypto.KeyLike;
|
|
11
|
+
/**
|
|
12
|
+
* One of the supported signature algorithms.
|
|
13
|
+
* @see {@link SignatureAlgorithmType}
|
|
14
|
+
*/
|
|
15
|
+
signatureAlgorithm?: SignatureAlgorithmType;
|
|
16
|
+
/**
|
|
17
|
+
* Rules used to convert an XML document into its canonical form.
|
|
18
|
+
*/
|
|
19
|
+
canonicalizationAlgorithm?: CanonicalizationAlgorithmType;
|
|
20
|
+
/**
|
|
21
|
+
* It specifies a list of namespace prefixes that should be considered "inclusive" during the canonicalization process.
|
|
22
|
+
*/
|
|
23
|
+
inclusiveNamespacesPrefixList: string[];
|
|
24
|
+
namespaceResolver: XPathNSResolver;
|
|
25
|
+
implicitTransforms: ReadonlyArray<CanonicalizationOrTransformAlgorithmType>;
|
|
26
|
+
keyInfoAttributes: {
|
|
27
|
+
[attrName: string]: string;
|
|
28
|
+
};
|
|
29
|
+
getKeyInfoContent: typeof SignedXml.getKeyInfoContent;
|
|
30
|
+
getCertFromKeyInfo: typeof SignedXml.getCertFromKeyInfo;
|
|
31
|
+
objects?: Array<{
|
|
32
|
+
content: string;
|
|
33
|
+
attributes?: ObjectAttributes;
|
|
34
|
+
}>;
|
|
35
|
+
private id;
|
|
36
|
+
private signedXml;
|
|
37
|
+
private signatureXml;
|
|
38
|
+
private signatureNode;
|
|
39
|
+
private signatureValue;
|
|
40
|
+
private originalXmlWithIds;
|
|
41
|
+
private keyInfo;
|
|
42
|
+
/**
|
|
43
|
+
* Contains the references that were signed.
|
|
44
|
+
* @see {@link Reference}
|
|
45
|
+
*/
|
|
46
|
+
private references;
|
|
47
|
+
/**
|
|
48
|
+
* Contains the canonicalized XML of the references that were validly signed.
|
|
49
|
+
*
|
|
50
|
+
* This populates with the canonical XML of the reference only after
|
|
51
|
+
* verifying the signature is cryptographically authentic.
|
|
52
|
+
*/
|
|
53
|
+
private signedReferences;
|
|
54
|
+
/**
|
|
55
|
+
* To add a new transformation algorithm create a new class that implements the {@link TransformationAlgorithm} interface, and register it here. More info: {@link https://github.com/node-saml/xml-crypto#customizing-algorithms|Customizing Algorithms}
|
|
56
|
+
*/
|
|
57
|
+
CanonicalizationAlgorithms: Record<CanonicalizationOrTransformAlgorithmType, new () => CanonicalizationOrTransformationAlgorithm>;
|
|
58
|
+
/**
|
|
59
|
+
* To add a new hash algorithm create a new class that implements the {@link HashAlgorithm} interface, and register it here. More info: {@link https://github.com/node-saml/xml-crypto#customizing-algorithms|Customizing Algorithms}
|
|
60
|
+
*/
|
|
61
|
+
HashAlgorithms: Record<HashAlgorithmType, new () => HashAlgorithm>;
|
|
62
|
+
/**
|
|
63
|
+
* To add a new signature algorithm create a new class that implements the {@link SignatureAlgorithm} interface, and register it here. More info: {@link https://github.com/node-saml/xml-crypto#customizing-algorithms|Customizing Algorithms}
|
|
64
|
+
*/
|
|
65
|
+
SignatureAlgorithms: Record<SignatureAlgorithmType, new () => SignatureAlgorithm>;
|
|
66
|
+
static defaultNsForPrefix: {
|
|
67
|
+
ds: string;
|
|
68
|
+
};
|
|
69
|
+
static noop: () => null;
|
|
70
|
+
/**
|
|
71
|
+
* The SignedXml constructor provides an abstraction for sign and verify xml documents. The object is constructed using
|
|
72
|
+
* @param options {@link SignedXmlOptions}
|
|
73
|
+
*/
|
|
74
|
+
constructor(options?: SignedXmlOptions);
|
|
75
|
+
/**
|
|
76
|
+
* Due to key-confusion issues, it's risky to have both hmac
|
|
77
|
+
* and digital signature algorithms enabled at the same time.
|
|
78
|
+
* This enables HMAC and disables other signing algorithms.
|
|
79
|
+
*/
|
|
80
|
+
enableHMAC(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Builds the contents of a KeyInfo element as an XML string.
|
|
83
|
+
*
|
|
84
|
+
* For example, if the value of the prefix argument is 'foo', then
|
|
85
|
+
* the resultant XML string will be "<foo:X509Data></foo:X509Data>"
|
|
86
|
+
*
|
|
87
|
+
* @return an XML string representation of the contents of a KeyInfo element, or `null` if no `KeyInfo` element should be included
|
|
88
|
+
*/
|
|
89
|
+
static getKeyInfoContent({ publicCert, prefix }: GetKeyInfoContentArgs): string | null;
|
|
90
|
+
/**
|
|
91
|
+
* Returns the value of the signing certificate based on the contents of the
|
|
92
|
+
* specified KeyInfo.
|
|
93
|
+
*
|
|
94
|
+
* @param keyInfo KeyInfo element (@see https://www.w3.org/TR/2008/REC-xmldsig-core-20080610/#sec-X509Data)
|
|
95
|
+
* @return the signing certificate as a string in PEM format
|
|
96
|
+
*/
|
|
97
|
+
static getCertFromKeyInfo(keyInfo?: Node | null): string | null;
|
|
98
|
+
/**
|
|
99
|
+
* Validates the signature of the provided XML document synchronously using the configured key info provider.
|
|
100
|
+
*
|
|
101
|
+
* @param xml The XML document containing the signature to be validated.
|
|
102
|
+
* @returns `true` if the signature is valid
|
|
103
|
+
* @throws Error if no key info resolver is provided.
|
|
104
|
+
*/
|
|
105
|
+
checkSignature(xml: string): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Validates the signature of the provided XML document synchronously using the configured key info provider.
|
|
108
|
+
*
|
|
109
|
+
* @param xml The XML document containing the signature to be validated.
|
|
110
|
+
* @param callback Callback function to handle the validation result asynchronously.
|
|
111
|
+
* @throws Error if the last parameter is provided and is not a function, or if no key info resolver is provided.
|
|
112
|
+
*/
|
|
113
|
+
checkSignature(xml: string, callback: (error: Error | null, isValid?: boolean) => void): void;
|
|
114
|
+
private getCanonSignedInfoXml;
|
|
115
|
+
private getCanonReferenceXml;
|
|
116
|
+
private calculateSignatureValue;
|
|
117
|
+
private findSignatureAlgorithm;
|
|
118
|
+
private findCanonicalizationAlgorithm;
|
|
119
|
+
private findHashAlgorithm;
|
|
120
|
+
validateElementAgainstReferences(elemOrXpath: Element | string, doc: Document): Reference;
|
|
121
|
+
private validateReference;
|
|
122
|
+
findSignatures(doc: Node): Node[];
|
|
123
|
+
/**
|
|
124
|
+
* Loads the signature information from the provided XML node or string.
|
|
125
|
+
*
|
|
126
|
+
* @param signatureNode The XML node or string representing the signature.
|
|
127
|
+
*/
|
|
128
|
+
loadSignature(signatureNode: Node | string): void;
|
|
129
|
+
/**
|
|
130
|
+
* Load the reference xml node to a model
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
private loadReference;
|
|
134
|
+
/**
|
|
135
|
+
* Adds a reference to the signature.
|
|
136
|
+
*
|
|
137
|
+
* @param xpath The XPath expression to select the XML nodes to be referenced.
|
|
138
|
+
* @param transforms An array of transform algorithms to be applied to the selected nodes.
|
|
139
|
+
* @param digestAlgorithm The digest algorithm to use for computing the digest value.
|
|
140
|
+
* @param uri The URI identifier for the reference. If empty, an empty URI will be used.
|
|
141
|
+
* @param digestValue The expected digest value for the reference.
|
|
142
|
+
* @param inclusiveNamespacesPrefixList The prefix list for inclusive namespace canonicalization.
|
|
143
|
+
* @param isEmptyUri Indicates whether the URI is empty. Defaults to `false`.
|
|
144
|
+
* @param id An optional `Id` attribute for the reference.
|
|
145
|
+
* @param type An optional `Type` attribute for the reference.
|
|
146
|
+
*/
|
|
147
|
+
addReference({ xpath, transforms, digestAlgorithm, uri, digestValue, inclusiveNamespacesPrefixList, isEmptyUri, id, type, }: Partial<Reference> & Pick<Reference, "xpath">): void;
|
|
148
|
+
/**
|
|
149
|
+
* Returns the list of references.
|
|
150
|
+
*/
|
|
151
|
+
getReferences(): Reference[];
|
|
152
|
+
getSignedReferences(): string[];
|
|
153
|
+
/**
|
|
154
|
+
* Compute the signature of the given XML (using the already defined settings).
|
|
155
|
+
*
|
|
156
|
+
* @param xml The XML to compute the signature for.
|
|
157
|
+
* @param callback A callback function to handle the signature computation asynchronously.
|
|
158
|
+
* @returns void
|
|
159
|
+
* @throws TypeError If the xml can not be parsed.
|
|
160
|
+
*/
|
|
161
|
+
computeSignature(xml: string): void;
|
|
162
|
+
/**
|
|
163
|
+
* Compute the signature of the given XML (using the already defined settings).
|
|
164
|
+
*
|
|
165
|
+
* @param xml The XML to compute the signature for.
|
|
166
|
+
* @param callback A callback function to handle the signature computation asynchronously.
|
|
167
|
+
* @returns void
|
|
168
|
+
* @throws TypeError If the xml can not be parsed.
|
|
169
|
+
*/
|
|
170
|
+
computeSignature(xml: string, callback: ErrorFirstCallback<SignedXml>): void;
|
|
171
|
+
/**
|
|
172
|
+
* Compute the signature of the given XML (using the already defined settings).
|
|
173
|
+
*
|
|
174
|
+
* @param xml The XML to compute the signature for.
|
|
175
|
+
* @param opts An object containing options for the signature computation.
|
|
176
|
+
* @returns If no callback is provided, returns `this` (the instance of SignedXml).
|
|
177
|
+
* @throws TypeError If the xml can not be parsed, or Error if there were invalid options passed.
|
|
178
|
+
*/
|
|
179
|
+
computeSignature(xml: string, options: ComputeSignatureOptions): void;
|
|
180
|
+
/**
|
|
181
|
+
* Compute the signature of the given XML (using the already defined settings).
|
|
182
|
+
*
|
|
183
|
+
* @param xml The XML to compute the signature for.
|
|
184
|
+
* @param opts An object containing options for the signature computation.
|
|
185
|
+
* @param callback A callback function to handle the signature computation asynchronously.
|
|
186
|
+
* @returns void
|
|
187
|
+
* @throws TypeError If the xml can not be parsed, or Error if there were invalid options passed.
|
|
188
|
+
*/
|
|
189
|
+
computeSignature(xml: string, options: ComputeSignatureOptions, callback: ErrorFirstCallback<SignedXml>): void;
|
|
190
|
+
/**
|
|
191
|
+
* Adds all references to the SignedInfo after the signature placeholder is inserted.
|
|
192
|
+
*/
|
|
193
|
+
private addAllReferences;
|
|
194
|
+
private getKeyInfo;
|
|
195
|
+
/**
|
|
196
|
+
* Creates XML for Object elements to be included in the signature
|
|
197
|
+
*
|
|
198
|
+
* @param prefix Optional namespace prefix
|
|
199
|
+
* @returns XML string with Object elements or empty string if none
|
|
200
|
+
*/
|
|
201
|
+
private getObjects;
|
|
202
|
+
getCanonXml(transforms: Reference["transforms"], node: Node, options?: CanonicalizationOrTransformationAlgorithmProcessOptions): string;
|
|
203
|
+
/**
|
|
204
|
+
* Ensure an element has Id attribute. If not create it with unique value.
|
|
205
|
+
* Work with both normal and wssecurity Id flavour
|
|
206
|
+
*/
|
|
207
|
+
private ensureHasId;
|
|
208
|
+
/**
|
|
209
|
+
* Create the SignedInfo element
|
|
210
|
+
*
|
|
211
|
+
*/
|
|
212
|
+
private createSignedInfo;
|
|
213
|
+
/**
|
|
214
|
+
* Create the Signature element
|
|
215
|
+
*
|
|
216
|
+
*/
|
|
217
|
+
private createSignature;
|
|
218
|
+
/**
|
|
219
|
+
* Returns just the signature part, must be called only after {@link computeSignature}
|
|
220
|
+
*
|
|
221
|
+
* @returns The signature XML.
|
|
222
|
+
*/
|
|
223
|
+
getSignatureXml(): string;
|
|
224
|
+
/**
|
|
225
|
+
* Returns the original xml with Id attributes added on relevant elements (required for validation), must be called only after {@link computeSignature}
|
|
226
|
+
*
|
|
227
|
+
* @returns The original XML with IDs.
|
|
228
|
+
*/
|
|
229
|
+
getOriginalXmlWithIds(): string;
|
|
230
|
+
/**
|
|
231
|
+
* Returns the original xml document with the signature in it, must be called only after {@link computeSignature}
|
|
232
|
+
*
|
|
233
|
+
* @returns The signed XML.
|
|
234
|
+
*/
|
|
235
|
+
getSignedXml(): string;
|
|
236
|
+
}
|