node-opcua-pki 6.3.0 → 6.5.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/bin/pki.ts +1 -1
- package/dist/bin/install_prerequisite.mjs +1 -1
- package/dist/bin/pki.mjs +3425 -3
- package/dist/bin/pki.mjs.map +1 -1
- package/dist/{chunk-VXGTT7QM.mjs → chunk-GCHH54PS.mjs} +9 -1
- package/dist/{chunk-VXGTT7QM.mjs.map → chunk-GCHH54PS.mjs.map} +1 -1
- package/dist/index.d.mts +507 -68
- package/dist/index.d.ts +507 -68
- package/dist/index.js +662 -1244
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +713 -1296
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/readme.md +23 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,142 +1,317 @@
|
|
|
1
1
|
import { SubjectOptions, CertificatePurpose, Subject, Certificate, DER, CertificateRevocationList } from 'node-opcua-crypto';
|
|
2
2
|
export { Subject, SubjectOptions } from 'node-opcua-crypto';
|
|
3
3
|
|
|
4
|
+
/** RSA key size in bits. */
|
|
4
5
|
type KeySize = 1024 | 2048 | 3072 | 4096;
|
|
6
|
+
/** Hex-encoded SHA-1 certificate thumbprint. */
|
|
5
7
|
type Thumbprint = string;
|
|
8
|
+
/** A filesystem path to a file. */
|
|
6
9
|
type Filename = string;
|
|
10
|
+
/** Status of a certificate in the trust store. */
|
|
7
11
|
type CertificateStatus = "unknown" | "trusted" | "rejected";
|
|
8
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use {@link KeySize} instead.
|
|
15
|
+
*/
|
|
9
16
|
type KeyLength = 1024 | 2048 | 3072 | 4096;
|
|
10
17
|
declare function quote(str?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Subject Alternative Name (SAN) parameters for certificate
|
|
20
|
+
* generation.
|
|
21
|
+
*/
|
|
11
22
|
interface ProcessAltNamesParam {
|
|
23
|
+
/** DNS host names to include in the SAN extension. */
|
|
12
24
|
dns?: string[];
|
|
25
|
+
/** IP addresses to include in the SAN extension. */
|
|
13
26
|
ip?: string[];
|
|
27
|
+
/** OPC UA application URI for the SAN extension. */
|
|
14
28
|
applicationUri?: string;
|
|
15
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for creating a Certificate Signing Request (CSR).
|
|
32
|
+
*/
|
|
16
33
|
interface CreateCertificateSigningRequestOptions extends ProcessAltNamesParam {
|
|
34
|
+
/** X.500 subject for the certificate. */
|
|
17
35
|
subject?: SubjectOptions | string;
|
|
18
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Extended CSR options that include filesystem paths and
|
|
39
|
+
* certificate purpose — used internally by the OpenSSL toolbox.
|
|
40
|
+
*/
|
|
19
41
|
interface CreateCertificateSigningRequestWithConfigOptions extends CreateCertificateSigningRequestOptions {
|
|
42
|
+
/** Root directory of the PKI store. */
|
|
20
43
|
rootDir: Filename;
|
|
44
|
+
/** Path to the OpenSSL configuration file. */
|
|
21
45
|
configFile: Filename;
|
|
46
|
+
/** Path to the private key file. */
|
|
22
47
|
privateKey: Filename;
|
|
48
|
+
/** Intended purpose of the certificate. */
|
|
23
49
|
purpose: CertificatePurpose;
|
|
24
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Validity period parameters for certificate generation.
|
|
53
|
+
*/
|
|
25
54
|
interface StartDateEndDateParam {
|
|
55
|
+
/** Certificate "Not Before" date. Defaults to now. */
|
|
26
56
|
startDate?: Date;
|
|
57
|
+
/** Certificate "Not After" date (computed from validity). */
|
|
27
58
|
endDate?: Date;
|
|
59
|
+
/** Number of days the certificate is valid. @defaultValue 365 */
|
|
28
60
|
validity?: number;
|
|
29
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Parameters for creating a self-signed certificate.
|
|
64
|
+
*/
|
|
30
65
|
interface CreateSelfSignCertificateParam extends ProcessAltNamesParam, StartDateEndDateParam {
|
|
66
|
+
/** X.500 subject for the certificate. */
|
|
31
67
|
subject?: SubjectOptions | string;
|
|
32
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Extended self-signed certificate options that include
|
|
71
|
+
* filesystem paths and purpose — used internally.
|
|
72
|
+
*/
|
|
33
73
|
interface CreateSelfSignCertificateWithConfigParam extends CreateSelfSignCertificateParam {
|
|
74
|
+
/** Root directory of the PKI store. */
|
|
34
75
|
rootDir: Filename;
|
|
76
|
+
/** Path to the OpenSSL configuration file. */
|
|
35
77
|
configFile: Filename;
|
|
78
|
+
/** Path to the private key file. */
|
|
36
79
|
privateKey: Filename;
|
|
80
|
+
/** Intended purpose of the certificate. */
|
|
37
81
|
purpose: CertificatePurpose;
|
|
38
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* General-purpose parameters passed to CA operations such as
|
|
85
|
+
* {@link CertificateAuthority.signCertificateRequest} and
|
|
86
|
+
* {@link CertificateAuthority.revokeCertificate}.
|
|
87
|
+
*/
|
|
39
88
|
interface Params extends ProcessAltNamesParam, StartDateEndDateParam {
|
|
89
|
+
/** X.500 subject for the certificate. */
|
|
40
90
|
subject?: SubjectOptions | string;
|
|
91
|
+
/** Path to the private key file. */
|
|
41
92
|
privateKey?: string;
|
|
93
|
+
/** Path to the OpenSSL configuration file. */
|
|
42
94
|
configFile?: string;
|
|
95
|
+
/** Root directory of the PKI store. */
|
|
43
96
|
rootDir?: string;
|
|
97
|
+
/** Output filename for the generated certificate. */
|
|
44
98
|
outputFile?: string;
|
|
99
|
+
/** CRL revocation reason (e.g. `"keyCompromise"`). */
|
|
45
100
|
reason?: string;
|
|
46
101
|
}
|
|
47
102
|
declare function adjustDate(params: StartDateEndDateParam): void;
|
|
48
103
|
declare function adjustApplicationUri(params: Params): void;
|
|
49
104
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
declare const g_config: {
|
|
55
|
-
opensslVersion: string;
|
|
56
|
-
silent: boolean;
|
|
57
|
-
force: boolean;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
declare const doDebug: string | boolean;
|
|
61
|
-
declare const displayError = true;
|
|
62
|
-
declare const displayDebug: boolean;
|
|
63
|
-
declare function debugLog(...args: unknown[]): void;
|
|
64
|
-
declare function warningLog(...args: unknown[]): void;
|
|
65
|
-
|
|
66
|
-
declare function displayChapter(str: string): void;
|
|
67
|
-
declare function displayTitle(str: string): void;
|
|
68
|
-
declare function displaySubtitle(str: string): void;
|
|
69
|
-
declare function display(str: string): void;
|
|
70
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Options for creating a {@link CertificateAuthority}.
|
|
107
|
+
*/
|
|
71
108
|
interface CertificateAuthorityOptions {
|
|
109
|
+
/** RSA key size for the CA private key. */
|
|
72
110
|
keySize: KeySize;
|
|
111
|
+
/** Filesystem path where the CA directory structure is stored. */
|
|
73
112
|
location: string;
|
|
113
|
+
/**
|
|
114
|
+
* X.500 subject for the CA certificate.
|
|
115
|
+
* Accepts a slash-delimited string (e.g. `"/CN=My CA/O=Acme"`) or
|
|
116
|
+
* a structured {@link SubjectOptions} object.
|
|
117
|
+
*
|
|
118
|
+
* @defaultValue {@link defaultSubject}
|
|
119
|
+
*/
|
|
74
120
|
subject?: string | SubjectOptions;
|
|
75
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* An OpenSSL-based Certificate Authority (CA) that can create,
|
|
124
|
+
* sign, and revoke X.509 certificates.
|
|
125
|
+
*
|
|
126
|
+
* The CA maintains a standard OpenSSL directory layout under
|
|
127
|
+
* {@link CertificateAuthority.rootDir | rootDir}:
|
|
128
|
+
*
|
|
129
|
+
* ```
|
|
130
|
+
* <location>/
|
|
131
|
+
* ├── conf/ OpenSSL configuration
|
|
132
|
+
* ├── private/ CA private key (cakey.pem)
|
|
133
|
+
* ├── public/ CA certificate (cacert.pem)
|
|
134
|
+
* ├── certs/ Signed certificates
|
|
135
|
+
* ├── crl/ Revocation lists
|
|
136
|
+
* ├── serial Next serial number
|
|
137
|
+
* ├── crlnumber Next CRL number
|
|
138
|
+
* └── index.txt Certificate database
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* const ca = new CertificateAuthority({
|
|
144
|
+
* keySize: 2048,
|
|
145
|
+
* location: "/var/pki/CA"
|
|
146
|
+
* });
|
|
147
|
+
* await ca.initialize();
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
76
150
|
declare class CertificateAuthority {
|
|
151
|
+
/** RSA key size used when generating the CA private key. */
|
|
77
152
|
readonly keySize: KeySize;
|
|
153
|
+
/** Root filesystem path of the CA directory structure. */
|
|
78
154
|
readonly location: string;
|
|
155
|
+
/** X.500 subject of the CA certificate. */
|
|
79
156
|
readonly subject: Subject;
|
|
80
157
|
constructor(options: CertificateAuthorityOptions);
|
|
158
|
+
/** Absolute path to the CA root directory (alias for {@link location}). */
|
|
81
159
|
get rootDir(): string;
|
|
160
|
+
/** Path to the OpenSSL configuration file (`conf/caconfig.cnf`). */
|
|
82
161
|
get configFile(): string;
|
|
162
|
+
/** Path to the CA certificate in PEM format (`public/cacert.pem`). */
|
|
83
163
|
get caCertificate(): string;
|
|
84
164
|
/**
|
|
85
|
-
*
|
|
165
|
+
* Path to the current Certificate Revocation List in DER format.
|
|
166
|
+
* (`crl/revocation_list.der`)
|
|
86
167
|
*/
|
|
87
168
|
get revocationListDER(): string;
|
|
88
169
|
/**
|
|
89
|
-
*
|
|
170
|
+
* Path to the current Certificate Revocation List in PEM format.
|
|
171
|
+
* (`crl/revocation_list.crl`)
|
|
90
172
|
*/
|
|
91
173
|
get revocationList(): string;
|
|
174
|
+
/**
|
|
175
|
+
* Path to the concatenated CA certificate + CRL file.
|
|
176
|
+
* Used by OpenSSL for CRL-based verification.
|
|
177
|
+
*/
|
|
92
178
|
get caCertificateWithCrl(): string;
|
|
179
|
+
/**
|
|
180
|
+
* Initialize the CA directory structure, generate the CA
|
|
181
|
+
* private key and self-signed certificate if they do not
|
|
182
|
+
* already exist.
|
|
183
|
+
*/
|
|
93
184
|
initialize(): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Rebuild the combined CA certificate + CRL file.
|
|
187
|
+
*
|
|
188
|
+
* This concatenates the CA certificate with the current
|
|
189
|
+
* revocation list so that OpenSSL can verify certificates
|
|
190
|
+
* with CRL checking enabled.
|
|
191
|
+
*/
|
|
94
192
|
constructCACertificateWithCRL(): Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* Append the CA certificate to a signed certificate file,
|
|
195
|
+
* creating a PEM certificate chain.
|
|
196
|
+
*
|
|
197
|
+
* @param certificate - path to the certificate file to extend
|
|
198
|
+
*/
|
|
95
199
|
constructCertificateChain(certificate: Filename): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Create a self-signed certificate using OpenSSL.
|
|
202
|
+
*
|
|
203
|
+
* @param certificateFile - output path for the signed certificate
|
|
204
|
+
* @param privateKey - path to the private key file
|
|
205
|
+
* @param params - certificate parameters (subject, validity, SANs)
|
|
206
|
+
*/
|
|
96
207
|
createSelfSignedCertificate(certificateFile: Filename, privateKey: Filename, params: Params): Promise<void>;
|
|
97
208
|
/**
|
|
98
|
-
*
|
|
209
|
+
* Revoke a certificate and regenerate the CRL.
|
|
99
210
|
*
|
|
100
|
-
* @
|
|
101
|
-
* @param
|
|
102
|
-
* @param params
|
|
103
|
-
*
|
|
104
|
-
* @async
|
|
211
|
+
* @param certificate - path to the certificate file to revoke
|
|
212
|
+
* @param params - revocation parameters
|
|
213
|
+
* @param params.reason - CRL reason code
|
|
214
|
+
* (default `"keyCompromise"`)
|
|
105
215
|
*/
|
|
106
216
|
revokeCertificate(certificate: Filename, params: Params): Promise<void>;
|
|
107
217
|
/**
|
|
218
|
+
* Sign a Certificate Signing Request (CSR) with this CA.
|
|
219
|
+
*
|
|
220
|
+
* The signed certificate is written to `certificate`, and the
|
|
221
|
+
* CA certificate chain plus CRL are appended to form a
|
|
222
|
+
* complete certificate chain.
|
|
108
223
|
*
|
|
109
|
-
* @param certificate
|
|
110
|
-
* @param certificateSigningRequestFilename
|
|
111
|
-
* @param
|
|
112
|
-
* @
|
|
113
|
-
* @param params.startDate - startDate of the certificate
|
|
114
|
-
* @param params.validity - number of day of validity of the certificate
|
|
224
|
+
* @param certificate - output path for the signed certificate
|
|
225
|
+
* @param certificateSigningRequestFilename - path to the CSR
|
|
226
|
+
* @param params1 - signing parameters (validity, dates, SANs)
|
|
227
|
+
* @returns the path to the signed certificate
|
|
115
228
|
*/
|
|
116
229
|
signCertificateRequest(certificate: Filename, certificateSigningRequestFilename: Filename, params1: Params): Promise<Filename>;
|
|
230
|
+
/**
|
|
231
|
+
* Verify a certificate against this CA.
|
|
232
|
+
*
|
|
233
|
+
* @param certificate - path to the certificate file to verify
|
|
234
|
+
*/
|
|
117
235
|
verifyCertificate(certificate: Filename): Promise<void>;
|
|
118
236
|
}
|
|
119
237
|
|
|
120
|
-
|
|
121
|
-
|
|
238
|
+
/**
|
|
239
|
+
* Options for creating a {@link CertificateManager}.
|
|
240
|
+
*/
|
|
122
241
|
interface CertificateManagerOptions {
|
|
242
|
+
/**
|
|
243
|
+
* RSA key size for generated private keys.
|
|
244
|
+
* @defaultValue 2048
|
|
245
|
+
*/
|
|
123
246
|
keySize?: KeySize;
|
|
247
|
+
/** Filesystem path where the PKI directory structure is stored. */
|
|
124
248
|
location: string;
|
|
125
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Parameters for {@link createSelfSignedCertificate}.
|
|
252
|
+
* All fields from {@link CreateSelfSignCertificateParam} are required.
|
|
253
|
+
*/
|
|
126
254
|
interface CreateSelfSignCertificateParam1 extends CreateSelfSignCertificateParam {
|
|
255
|
+
/**
|
|
256
|
+
* Output path for the certificate.
|
|
257
|
+
* @defaultValue `"own/certs/self_signed_certificate.pem"`
|
|
258
|
+
*/
|
|
127
259
|
outputFile?: Filename;
|
|
260
|
+
/** X.500 subject for the certificate. */
|
|
128
261
|
subject: SubjectOptions | string;
|
|
262
|
+
/** OPC UA application URI for the SAN extension. */
|
|
129
263
|
applicationUri: string;
|
|
264
|
+
/** DNS host names to include in the SAN extension. */
|
|
130
265
|
dns: string[];
|
|
266
|
+
/** Certificate "Not Before" date. */
|
|
131
267
|
startDate: Date;
|
|
268
|
+
/** Number of days the certificate is valid. */
|
|
132
269
|
validity: number;
|
|
133
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Options to fine-tune certificate verification behaviour.
|
|
273
|
+
* Passed to {@link CertificateManager.verifyCertificate}.
|
|
274
|
+
*
|
|
275
|
+
* Without any options, `verifyCertificate` is **strict**: only
|
|
276
|
+
* certificates that are explicitly present in the trusted store
|
|
277
|
+
* will return {@link VerificationStatus.Good}. Unknown or
|
|
278
|
+
* rejected certificates return
|
|
279
|
+
* {@link VerificationStatus.BadCertificateUntrusted} even when
|
|
280
|
+
* their issuer chain is valid.
|
|
281
|
+
*
|
|
282
|
+
* Set {@link acceptCertificateWithValidIssuerChain} to `true`
|
|
283
|
+
* to accept certificates whose issuer chain validates against
|
|
284
|
+
* a trusted CA — even if the leaf certificate itself is not
|
|
285
|
+
* in the trusted store.
|
|
286
|
+
*/
|
|
134
287
|
interface VerifyCertificateOptions {
|
|
288
|
+
/** Accept certificates whose "Not After" date has passed. */
|
|
135
289
|
acceptOutdatedCertificate?: boolean;
|
|
290
|
+
/** Accept issuer certificates whose "Not After" date has passed. */
|
|
136
291
|
acceptOutDatedIssuerCertificate?: boolean;
|
|
292
|
+
/** Do not fail when a CRL is missing for an issuer. */
|
|
137
293
|
ignoreMissingRevocationList?: boolean;
|
|
294
|
+
/** Accept certificates whose "Not Before" date is in the future. */
|
|
138
295
|
acceptPendingCertificate?: boolean;
|
|
296
|
+
/**
|
|
297
|
+
* Accept a certificate that is not in the trusted store when
|
|
298
|
+
* its issuer (CA) certificate is trusted, the signature is
|
|
299
|
+
* valid, and the certificate does not appear in the CRL.
|
|
300
|
+
*
|
|
301
|
+
* When `false` (the default), only certificates explicitly
|
|
302
|
+
* placed in the trusted store are accepted — this is the
|
|
303
|
+
* same behaviour as {@link CertificateManager.isCertificateTrusted}.
|
|
304
|
+
*
|
|
305
|
+
* @defaultValue false
|
|
306
|
+
*/
|
|
307
|
+
acceptCertificateWithValidIssuerChain?: boolean;
|
|
139
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* OPC UA certificate verification status codes.
|
|
311
|
+
*
|
|
312
|
+
* These mirror the OPC UA `StatusCode` values for certificate
|
|
313
|
+
* validation results.
|
|
314
|
+
*/
|
|
140
315
|
declare enum VerificationStatus {
|
|
141
316
|
/** The certificate provided as a parameter is not valid. */
|
|
142
317
|
BadCertificateInvalid = "BadCertificateInvalid",
|
|
@@ -171,7 +346,18 @@ declare enum VerificationStatus {
|
|
|
171
346
|
/** Validation OK. */
|
|
172
347
|
Good = "Good"
|
|
173
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Find the issuer certificate for a given certificate within
|
|
351
|
+
* a provided certificate chain.
|
|
352
|
+
*
|
|
353
|
+
* @param certificate - the DER-encoded certificate whose issuer to find
|
|
354
|
+
* @param chain - candidate issuer certificates to search
|
|
355
|
+
* @returns the matching issuer certificate, or `null` if not found
|
|
356
|
+
*/
|
|
174
357
|
declare function findIssuerCertificateInChain(certificate: Certificate, chain: Certificate[]): Certificate | null;
|
|
358
|
+
/**
|
|
359
|
+
* Lifecycle state of a {@link CertificateManager} instance.
|
|
360
|
+
*/
|
|
175
361
|
declare enum CertificateManagerState {
|
|
176
362
|
Uninitialized = 0,
|
|
177
363
|
Initializing = 1,
|
|
@@ -179,35 +365,107 @@ declare enum CertificateManagerState {
|
|
|
179
365
|
Disposing = 3,
|
|
180
366
|
Disposed = 4
|
|
181
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* Manages a GDS-compliant PKI directory structure for an OPC UA
|
|
370
|
+
* application.
|
|
371
|
+
*
|
|
372
|
+
* The PKI store layout follows the OPC UA specification:
|
|
373
|
+
*
|
|
374
|
+
* ```
|
|
375
|
+
* <location>/
|
|
376
|
+
* ├── own/
|
|
377
|
+
* │ ├── certs/ Own certificate(s)
|
|
378
|
+
* │ └── private/ Own private key
|
|
379
|
+
* ├── trusted/
|
|
380
|
+
* │ ├── certs/ Trusted peer certificates
|
|
381
|
+
* │ └── crl/ CRLs for trusted certs
|
|
382
|
+
* ├── rejected/ Untrusted / rejected certificates
|
|
383
|
+
* └── issuers/
|
|
384
|
+
* ├── certs/ CA (issuer) certificates
|
|
385
|
+
* └── crl/ CRLs for issuer certificates
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* File-system watchers keep the in-memory indexes in sync with
|
|
389
|
+
* on-disk changes. Call {@link dispose} when the instance is no
|
|
390
|
+
* longer needed to release watchers and allow the process to
|
|
391
|
+
* exit cleanly.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```ts
|
|
395
|
+
* const cm = new CertificateManager({ location: "/var/pki" });
|
|
396
|
+
* await cm.initialize();
|
|
397
|
+
* const status = await cm.verifyCertificate(cert);
|
|
398
|
+
* await cm.dispose();
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
182
401
|
declare class CertificateManager {
|
|
402
|
+
#private;
|
|
403
|
+
/**
|
|
404
|
+
* Dispose **all** active CertificateManager instances,
|
|
405
|
+
* closing their file watchers and freeing resources.
|
|
406
|
+
*
|
|
407
|
+
* This is mainly useful in test tear-down to ensure the
|
|
408
|
+
* Node.js process can exit cleanly.
|
|
409
|
+
*/
|
|
410
|
+
static disposeAll(): Promise<void>;
|
|
411
|
+
/**
|
|
412
|
+
* Assert that all CertificateManager instances have been
|
|
413
|
+
* properly disposed. Throws an Error listing the locations
|
|
414
|
+
* of any leaked instances.
|
|
415
|
+
*
|
|
416
|
+
* Intended for use in test `afterAll()` / `afterEach()`
|
|
417
|
+
* hooks to catch missing `dispose()` calls early.
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```ts
|
|
421
|
+
* after(() => {
|
|
422
|
+
* CertificateManager.checkAllDisposed();
|
|
423
|
+
* });
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
static checkAllDisposed(): void;
|
|
427
|
+
/**
|
|
428
|
+
* When `true` (the default), any certificate that is not
|
|
429
|
+
* already in the trusted or rejected store is automatically
|
|
430
|
+
* written to the rejected folder the first time it is seen.
|
|
431
|
+
*/
|
|
183
432
|
untrustUnknownCertificate: boolean;
|
|
433
|
+
/** Current lifecycle state of this instance. */
|
|
184
434
|
state: CertificateManagerState;
|
|
435
|
+
/** @deprecated Use {@link folderPollingInterval} instead (typo fix). */
|
|
185
436
|
folderPoolingInterval: number;
|
|
437
|
+
/** Interval in milliseconds for file-system polling (when enabled). */
|
|
438
|
+
get folderPollingInterval(): number;
|
|
439
|
+
set folderPollingInterval(value: number);
|
|
440
|
+
/** RSA key size used when generating the private key. */
|
|
186
441
|
readonly keySize: KeySize;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
442
|
+
/**
|
|
443
|
+
* Create a new CertificateManager.
|
|
444
|
+
*
|
|
445
|
+
* The constructor creates the root directory if it does not
|
|
446
|
+
* exist but does **not** initialise the PKI store — call
|
|
447
|
+
* {@link initialize} before using any other method.
|
|
448
|
+
*
|
|
449
|
+
* @param options - configuration options
|
|
450
|
+
*/
|
|
192
451
|
constructor(options: CertificateManagerOptions);
|
|
452
|
+
/** Path to the OpenSSL configuration file. */
|
|
193
453
|
get configFile(): string;
|
|
454
|
+
/** Root directory of the PKI store. */
|
|
194
455
|
get rootDir(): string;
|
|
456
|
+
/** Path to the private key file (`own/private/private_key.pem`). */
|
|
195
457
|
get privateKey(): string;
|
|
458
|
+
/** Path to the OpenSSL random seed file. */
|
|
196
459
|
get randomFile(): string;
|
|
197
|
-
/**
|
|
198
|
-
* returns the certificate status trusted/rejected
|
|
199
|
-
* @param certificate
|
|
200
|
-
*/
|
|
201
|
-
getCertificateStatus(certificate: Buffer): Promise<CertificateStatus>;
|
|
202
460
|
/**
|
|
203
461
|
* Move a certificate to the rejected store.
|
|
204
|
-
* If the certificate was previously trusted, it will be
|
|
462
|
+
* If the certificate was previously trusted, it will be removed from the trusted folder.
|
|
205
463
|
* @param certificate - the DER-encoded certificate
|
|
206
464
|
*/
|
|
207
465
|
rejectCertificate(certificate: Certificate): Promise<void>;
|
|
208
466
|
/**
|
|
209
467
|
* Move a certificate to the trusted store.
|
|
210
|
-
* If the certificate was previously rejected, it will be
|
|
468
|
+
* If the certificate was previously rejected, it will be removed from the rejected folder.
|
|
211
469
|
* @param certificate - the DER-encoded certificate
|
|
212
470
|
*/
|
|
213
471
|
trustCertificate(certificate: Certificate): Promise<void>;
|
|
@@ -221,6 +479,9 @@ declare class CertificateManager {
|
|
|
221
479
|
get issuersCertFolder(): string;
|
|
222
480
|
/** Path to the issuer CRL folder. */
|
|
223
481
|
get issuersCrlFolder(): string;
|
|
482
|
+
/** Path to the own certificate folder. */
|
|
483
|
+
get ownCertFolder(): string;
|
|
484
|
+
get ownPrivateFolder(): string;
|
|
224
485
|
/**
|
|
225
486
|
* Check if a certificate is in the trusted store.
|
|
226
487
|
* If the certificate is unknown and `untrustUnknownCertificate` is set,
|
|
@@ -230,29 +491,75 @@ declare class CertificateManager {
|
|
|
230
491
|
* or `"BadCertificateInvalid"` if the certificate cannot be parsed.
|
|
231
492
|
*/
|
|
232
493
|
isCertificateTrusted(certificate: Certificate): Promise<string>;
|
|
233
|
-
|
|
494
|
+
/**
|
|
495
|
+
* Internal verification hook called by {@link verifyCertificate}.
|
|
496
|
+
*
|
|
497
|
+
* Subclasses can override this to inject additional validation
|
|
498
|
+
* logic (e.g. application-level policy checks) while still
|
|
499
|
+
* delegating to the default chain/CRL/trust verification.
|
|
500
|
+
*
|
|
501
|
+
* @param certificate - the DER-encoded certificate to verify
|
|
502
|
+
* @param options - verification options forwarded from the
|
|
503
|
+
* public API
|
|
504
|
+
* @returns the verification status code
|
|
505
|
+
*/
|
|
234
506
|
protected verifyCertificateAsync(certificate: Certificate, options: VerifyCertificateOptions): Promise<VerificationStatus>;
|
|
235
507
|
/**
|
|
236
|
-
* Verify certificate
|
|
237
|
-
*
|
|
238
|
-
*
|
|
508
|
+
* Verify a certificate against the PKI trust store.
|
|
509
|
+
*
|
|
510
|
+
* This performs a full validation including trust status,
|
|
511
|
+
* issuer chain, CRL revocation checks, and time validity.
|
|
512
|
+
*
|
|
513
|
+
* @param certificate - the DER-encoded certificate to verify
|
|
514
|
+
* @param options - optional flags to relax validation rules
|
|
515
|
+
* @returns the verification status code
|
|
239
516
|
*/
|
|
240
517
|
verifyCertificate(certificate: Certificate, options?: VerifyCertificateOptions): Promise<VerificationStatus>;
|
|
518
|
+
/**
|
|
519
|
+
* Initialize the PKI directory structure, generate the
|
|
520
|
+
* private key (if missing), and start file-system watchers.
|
|
521
|
+
*
|
|
522
|
+
* This method is idempotent — subsequent calls are no-ops.
|
|
523
|
+
* It must be called before any certificate operations.
|
|
524
|
+
*/
|
|
241
525
|
initialize(): Promise<void>;
|
|
242
|
-
private _initialize;
|
|
243
526
|
/**
|
|
244
527
|
* Dispose of the CertificateManager, releasing file watchers
|
|
245
528
|
* and other resources. The instance should not be used after
|
|
246
529
|
* calling this method.
|
|
247
530
|
*/
|
|
248
531
|
dispose(): Promise<void>;
|
|
532
|
+
/**
|
|
533
|
+
* Force a full re-scan of all PKI folders, rebuilding
|
|
534
|
+
* the in-memory `_thumbs` index from scratch.
|
|
535
|
+
*
|
|
536
|
+
* Call this after external processes have modified the
|
|
537
|
+
* PKI folders (e.g. via `writeTrustList` or CLI tools)
|
|
538
|
+
* to ensure the CertificateManager sees the latest
|
|
539
|
+
* state without waiting for file-system events.
|
|
540
|
+
*/
|
|
541
|
+
reloadCertificates(): Promise<void>;
|
|
249
542
|
protected withLock2<T>(action: () => Promise<T>): Promise<T>;
|
|
250
543
|
/**
|
|
544
|
+
* Create a self-signed certificate for this PKI's private key.
|
|
251
545
|
*
|
|
252
|
-
*
|
|
546
|
+
* The certificate is written to `params.outputFile` or
|
|
547
|
+
* `own/certs/self_signed_certificate.pem` by default.
|
|
253
548
|
*
|
|
549
|
+
* @param params - certificate parameters (subject, SANs,
|
|
550
|
+
* validity, etc.)
|
|
254
551
|
*/
|
|
255
552
|
createSelfSignedCertificate(params: CreateSelfSignCertificateParam1): Promise<void>;
|
|
553
|
+
/**
|
|
554
|
+
* Create a Certificate Signing Request (CSR) using this
|
|
555
|
+
* PKI's private key and configuration.
|
|
556
|
+
*
|
|
557
|
+
* The CSR file is written to `own/certs/` with a timestamped
|
|
558
|
+
* filename.
|
|
559
|
+
*
|
|
560
|
+
* @param params - CSR parameters (subject, SANs)
|
|
561
|
+
* @returns the filesystem path to the generated CSR file
|
|
562
|
+
*/
|
|
256
563
|
createCertificateRequest(params: CreateSelfSignCertificateParam): Promise<Filename>;
|
|
257
564
|
/**
|
|
258
565
|
* Add a CA (issuer) certificate to the issuers store.
|
|
@@ -351,26 +658,158 @@ declare class CertificateManager {
|
|
|
351
658
|
*/
|
|
352
659
|
findIssuerCertificate(certificate: Certificate): Promise<Certificate | null>;
|
|
353
660
|
/**
|
|
354
|
-
*
|
|
355
|
-
*
|
|
661
|
+
* Check whether a certificate has been revoked by its issuer's CRL.
|
|
662
|
+
*
|
|
663
|
+
* - Self-signed certificates are never considered revoked.
|
|
664
|
+
* - If no `issuerCertificate` is provided, the method attempts
|
|
665
|
+
* to find it via {@link findIssuerCertificate}.
|
|
666
|
+
*
|
|
667
|
+
* @param certificate - the DER-encoded certificate to check
|
|
668
|
+
* @param issuerCertificate - optional issuer certificate; looked
|
|
669
|
+
* up automatically when omitted
|
|
670
|
+
* @returns `Good` if not revoked, `BadCertificateRevoked` if the
|
|
671
|
+
* serial number appears in a CRL,
|
|
672
|
+
* `BadCertificateRevocationUnknown` if no CRL is available,
|
|
673
|
+
* or `BadCertificateChainIncomplete` if the issuer cannot be
|
|
674
|
+
* found.
|
|
356
675
|
*/
|
|
357
|
-
_checkRejectedOrTrusted(certificate: Buffer): Promise<CertificateStatus>;
|
|
358
|
-
private _moveCertificate;
|
|
359
|
-
private _findAssociatedCRLs;
|
|
360
676
|
isCertificateRevoked(certificate: Certificate, issuerCertificate?: Certificate | null): Promise<VerificationStatus>;
|
|
361
|
-
private _pending_crl_to_process;
|
|
362
|
-
private _on_crl_process?;
|
|
363
|
-
private queue;
|
|
364
|
-
private _on_crl_file_added;
|
|
365
|
-
private _process_next_crl;
|
|
366
|
-
private _readCertificates;
|
|
367
|
-
private waitAndCheckCRLProcessingStatus;
|
|
368
677
|
}
|
|
369
678
|
|
|
679
|
+
/**
|
|
680
|
+
* Options for creating a PFX (PKCS#12) file.
|
|
681
|
+
*/
|
|
682
|
+
interface CreatePFXOptions {
|
|
683
|
+
/** Path to the certificate file (PEM or DER). */
|
|
684
|
+
certificateFile: Filename;
|
|
685
|
+
/** Path to the private key file (PEM). */
|
|
686
|
+
privateKeyFile: Filename;
|
|
687
|
+
/** Output path for the generated PFX file. */
|
|
688
|
+
outputFile: Filename;
|
|
689
|
+
/**
|
|
690
|
+
* Optional passphrase to protect the PFX file.
|
|
691
|
+
* If omitted, the PFX is created without a password.
|
|
692
|
+
*/
|
|
693
|
+
passphrase?: string;
|
|
694
|
+
/**
|
|
695
|
+
* Optional path(s) to CA / intermediate certificate files
|
|
696
|
+
* to include in the PFX bundle.
|
|
697
|
+
*/
|
|
698
|
+
caCertificateFiles?: Filename[];
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Options for extracting data from a PFX (PKCS#12) file.
|
|
702
|
+
*/
|
|
703
|
+
interface ExtractPFXOptions {
|
|
704
|
+
/** Path to the PFX file. */
|
|
705
|
+
pfxFile: Filename;
|
|
706
|
+
/**
|
|
707
|
+
* Passphrase used when the PFX was created.
|
|
708
|
+
* Pass an empty string for unprotected PFX files.
|
|
709
|
+
*/
|
|
710
|
+
passphrase?: string;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Result of extracting data from a PFX file.
|
|
714
|
+
*/
|
|
715
|
+
interface ExtractPFXResult {
|
|
716
|
+
/** The certificate in PEM format. */
|
|
717
|
+
certificate: string;
|
|
718
|
+
/** The private key in PEM format. */
|
|
719
|
+
privateKey: string;
|
|
720
|
+
/**
|
|
721
|
+
* The CA / intermediate certificates in PEM format
|
|
722
|
+
* (empty string if none).
|
|
723
|
+
*/
|
|
724
|
+
caCertificates: string;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Create a PFX (PKCS#12) file from a certificate and private key.
|
|
728
|
+
*
|
|
729
|
+
* Wraps:
|
|
730
|
+
* ```
|
|
731
|
+
* openssl pkcs12 -export
|
|
732
|
+
* -in <cert> -inkey <key>
|
|
733
|
+
* [-certfile <ca>]
|
|
734
|
+
* -out <pfx>
|
|
735
|
+
* -passout pass:<passphrase>
|
|
736
|
+
* ```
|
|
737
|
+
*
|
|
738
|
+
* @param options — see {@link CreatePFXOptions}
|
|
739
|
+
*/
|
|
740
|
+
declare function createPFX(options: CreatePFXOptions): Promise<void>;
|
|
741
|
+
/**
|
|
742
|
+
* Extract the client/server certificate from a PFX file.
|
|
743
|
+
*
|
|
744
|
+
* Wraps:
|
|
745
|
+
* ```
|
|
746
|
+
* openssl pkcs12 -in <pfx> -clcerts -nokeys
|
|
747
|
+
* -passin pass:<passphrase>
|
|
748
|
+
* ```
|
|
749
|
+
*
|
|
750
|
+
* @returns the certificate in PEM format.
|
|
751
|
+
*/
|
|
752
|
+
declare function extractCertificateFromPFX(options: ExtractPFXOptions): Promise<string>;
|
|
753
|
+
/**
|
|
754
|
+
* Extract the private key from a PFX file.
|
|
755
|
+
*
|
|
756
|
+
* Wraps:
|
|
757
|
+
* ```
|
|
758
|
+
* openssl pkcs12 -in <pfx> -nocerts -nodes
|
|
759
|
+
* -passin pass:<passphrase>
|
|
760
|
+
* ```
|
|
761
|
+
*
|
|
762
|
+
* @returns the private key in PEM format.
|
|
763
|
+
*/
|
|
764
|
+
declare function extractPrivateKeyFromPFX(options: ExtractPFXOptions): Promise<string>;
|
|
765
|
+
/**
|
|
766
|
+
* Extract the CA / intermediate certificates from a PFX file.
|
|
767
|
+
*
|
|
768
|
+
* Wraps:
|
|
769
|
+
* ```
|
|
770
|
+
* openssl pkcs12 -in <pfx> -cacerts -nokeys -nodes
|
|
771
|
+
* -passin pass:<passphrase>
|
|
772
|
+
* ```
|
|
773
|
+
*
|
|
774
|
+
* @returns the CA certificates in PEM format
|
|
775
|
+
* (empty string if none are present).
|
|
776
|
+
*/
|
|
777
|
+
declare function extractCACertificatesFromPFX(options: ExtractPFXOptions): Promise<string>;
|
|
778
|
+
/**
|
|
779
|
+
* Extract certificate + private key + CA certs from a PFX file
|
|
780
|
+
* in a single call.
|
|
781
|
+
*
|
|
782
|
+
* @returns an {@link ExtractPFXResult} with all PEM-encoded parts.
|
|
783
|
+
*/
|
|
784
|
+
declare function extractAllFromPFX(options: ExtractPFXOptions): Promise<ExtractPFXResult>;
|
|
785
|
+
/**
|
|
786
|
+
* Convert a PFX file to a single PEM file containing both the
|
|
787
|
+
* certificate and the private key.
|
|
788
|
+
*
|
|
789
|
+
* Wraps:
|
|
790
|
+
* ```
|
|
791
|
+
* openssl pkcs12 -in <pfx> -out <pem> -nodes
|
|
792
|
+
* -passin pass:<passphrase>
|
|
793
|
+
* ```
|
|
794
|
+
*/
|
|
795
|
+
declare function convertPFXtoPEM(pfxFile: Filename, pemFile: Filename, passphrase?: string): Promise<void>;
|
|
796
|
+
/**
|
|
797
|
+
* Dump the contents of a PFX file in human-readable form.
|
|
798
|
+
*
|
|
799
|
+
* Wraps:
|
|
800
|
+
* ```
|
|
801
|
+
* openssl pkcs12 -in <pfx> -info -noout
|
|
802
|
+
* -passin pass:<passphrase>
|
|
803
|
+
* ```
|
|
804
|
+
*
|
|
805
|
+
* @returns the human-readable dump as a string.
|
|
806
|
+
*/
|
|
807
|
+
declare function dumpPFX(pfxFile: Filename, passphrase?: string): Promise<string>;
|
|
808
|
+
|
|
370
809
|
/**
|
|
371
810
|
*
|
|
372
811
|
* return path to the openssl executable
|
|
373
812
|
*/
|
|
374
813
|
declare function install_prerequisite(): Promise<string>;
|
|
375
814
|
|
|
376
|
-
export { CertificateAuthority, type CertificateAuthorityOptions, CertificateManager, type CertificateManagerOptions, CertificateManagerState, type CertificateStatus, type CreateCertificateSigningRequestOptions, type CreateCertificateSigningRequestWithConfigOptions, type CreateSelfSignCertificateParam, type CreateSelfSignCertificateParam1, type CreateSelfSignCertificateWithConfigParam, type Filename, type KeyLength, type KeySize, type Params, type ProcessAltNamesParam, type StartDateEndDateParam, type Thumbprint, VerificationStatus, type VerifyCertificateOptions, adjustApplicationUri, adjustDate,
|
|
815
|
+
export { CertificateAuthority, type CertificateAuthorityOptions, CertificateManager, type CertificateManagerOptions, CertificateManagerState, type CertificateStatus, type CreateCertificateSigningRequestOptions, type CreateCertificateSigningRequestWithConfigOptions, type CreatePFXOptions, type CreateSelfSignCertificateParam, type CreateSelfSignCertificateParam1, type CreateSelfSignCertificateWithConfigParam, type ExtractPFXOptions, type ExtractPFXResult, type Filename, type KeyLength, type KeySize, type Params, type ProcessAltNamesParam, type StartDateEndDateParam, type Thumbprint, VerificationStatus, type VerifyCertificateOptions, adjustApplicationUri, adjustDate, convertPFXtoPEM, createPFX, dumpPFX, extractAllFromPFX, extractCACertificatesFromPFX, extractCertificateFromPFX, extractPrivateKeyFromPFX, findIssuerCertificateInChain, install_prerequisite, quote };
|