node-opcua-pki 6.20.0 → 6.22.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/dist/bin/pki.mjs +1627 -821
- package/dist/bin/pki.mjs.map +1 -1
- package/dist/chunk-EQ4DGI4M.mjs +1917 -0
- package/dist/chunk-EQ4DGI4M.mjs.map +1 -0
- package/dist/core-BwqSJPHc.d.mts +1041 -0
- package/dist/core-BwqSJPHc.d.ts +1041 -0
- package/dist/core.d.mts +2 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.js +1902 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +21 -0
- package/dist/core.mjs.map +1 -0
- package/dist/index.d.mts +136 -833
- package/dist/index.d.ts +136 -833
- package/dist/index.js +1890 -1086
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +890 -1922
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,147 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { PrivateKeyPassphraseRequiredError, Subject, SubjectOptions } from 'node-opcua-crypto';
|
|
1
|
+
import { IKeyOperations, PrivateKey, Certificate, SubjectOptions, DER, CertificateRevocationList } from 'node-opcua-crypto';
|
|
2
|
+
export { AsymmetricDecryptParams, AsymmetricSignParams, IKeyOperations, KeyMetadata, PrivateKeyPassphraseRequiredError, PrivateKeyUnavailableError, Subject, SubjectOptions } from 'node-opcua-crypto';
|
|
3
|
+
import { C as CaBackend, a as CertificateAuthorityCore, P as Params, b as ProcessAltNamesParam, c as CertificateAuthorityCoreOptions, K as KeySize, d as PrivateKeyPassphrase, e as PrivateKeyProvider, f as CreateSelfSignCertificateParam, F as Filename } from './core-BwqSJPHc.mjs';
|
|
4
|
+
export { g as CertificateStatus, h as CreateCertificateSigningRequestOptions, i as CreateCertificateSigningRequestWithConfigOptions, j as CreateSelfSignCertificateWithConfigParam, G as GenerateKeyPairAndSignOptions, k as GenerateKeyPairAndSignPFXOptions, I as InitializeCSRResult, l as InstallCACertificateResult, m as KeyLength, N as NativeCaBackend, n as PkiBackendCapabilities, S as SignCertificateOptions, o as StartDateEndDateParam, T as Thumbprint, p as adjustApplicationUri, q as adjustDate, r as isOpaqueSigner, s as quote, t as resolvePrivateKeyPassphrase } from './core-BwqSJPHc.mjs';
|
|
3
5
|
import { EventEmitter } from 'node:events';
|
|
4
6
|
|
|
5
|
-
/** RSA key size in bits. */
|
|
6
|
-
type KeySize = 1024 | 2048 | 3072 | 4096;
|
|
7
|
-
/** Hex-encoded SHA-1 certificate thumbprint. */
|
|
8
|
-
type Thumbprint = string;
|
|
9
|
-
/** A filesystem path to a file. */
|
|
10
|
-
type Filename = string;
|
|
11
|
-
/** Status of a certificate in the trust store. */
|
|
12
|
-
type CertificateStatus = "unknown" | "trusted" | "rejected";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated Use {@link KeySize} instead.
|
|
16
|
-
*/
|
|
17
|
-
type KeyLength = 1024 | 2048 | 3072 | 4096;
|
|
18
|
-
declare function quote(str?: string): string;
|
|
19
|
-
/**
|
|
20
|
-
* Subject Alternative Name (SAN) parameters for certificate
|
|
21
|
-
* generation.
|
|
22
|
-
*/
|
|
23
|
-
interface ProcessAltNamesParam {
|
|
24
|
-
/** DNS host names to include in the SAN extension. */
|
|
25
|
-
dns?: string[];
|
|
26
|
-
/** IP addresses to include in the SAN extension. */
|
|
27
|
-
ip?: string[];
|
|
28
|
-
/** OPC UA application URI for the SAN extension. */
|
|
29
|
-
applicationUri?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Options for creating a Certificate Signing Request (CSR).
|
|
33
|
-
*/
|
|
34
|
-
interface CreateCertificateSigningRequestOptions extends ProcessAltNamesParam {
|
|
35
|
-
/** X.500 subject for the certificate. */
|
|
36
|
-
subject?: SubjectOptions | string;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Extended CSR options that include filesystem paths and
|
|
40
|
-
* certificate purpose — used internally by the OpenSSL toolbox.
|
|
41
|
-
*/
|
|
42
|
-
interface CreateCertificateSigningRequestWithConfigOptions extends CreateCertificateSigningRequestOptions {
|
|
43
|
-
/** Root directory of the PKI store. */
|
|
44
|
-
rootDir: Filename;
|
|
45
|
-
/** Path to the OpenSSL configuration file. */
|
|
46
|
-
configFile: Filename;
|
|
47
|
-
/**
|
|
48
|
-
* The private key: either a filesystem path to a PEM file (unencrypted;
|
|
49
|
-
* the historical behavior), or an already-resolved in-memory
|
|
50
|
-
* {@link PrivateKey} — see {@link CreateSelfSignCertificateWithConfigParam.privateKey}.
|
|
51
|
-
*/
|
|
52
|
-
privateKey: Filename | PrivateKey;
|
|
53
|
-
/** Intended purpose of the certificate. */
|
|
54
|
-
purpose: CertificatePurpose;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Validity period parameters for certificate generation.
|
|
58
|
-
*/
|
|
59
|
-
interface StartDateEndDateParam {
|
|
60
|
-
/** Certificate "Not Before" date. Defaults to now. */
|
|
61
|
-
startDate?: Date;
|
|
62
|
-
/** Certificate "Not After" date (computed from validity). */
|
|
63
|
-
endDate?: Date;
|
|
64
|
-
/** Number of days the certificate is valid. @defaultValue 365 */
|
|
65
|
-
validity?: number;
|
|
66
|
-
/**
|
|
67
|
-
* Certificate validity in milliseconds.
|
|
68
|
-
*
|
|
69
|
-
* When provided, takes precedence over {@link validity} and enables
|
|
70
|
-
* sub-day validity (X.509 supports second precision per RFC 5280
|
|
71
|
-
* §4.1.2.5; OpenSSL is invoked with `-startdate`/`-enddate` already).
|
|
72
|
-
*
|
|
73
|
-
* Typical use is short-lived certificates for demos or for renewal
|
|
74
|
-
* cycle testing. Existing day-based callers are unaffected.
|
|
75
|
-
*/
|
|
76
|
-
validityMs?: number;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Parameters for creating a self-signed certificate.
|
|
80
|
-
*/
|
|
81
|
-
interface CreateSelfSignCertificateParam extends ProcessAltNamesParam, StartDateEndDateParam {
|
|
82
|
-
/** X.500 subject for the certificate. */
|
|
83
|
-
subject?: SubjectOptions | string;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Extended self-signed certificate options that include
|
|
87
|
-
* filesystem paths and purpose — used internally.
|
|
88
|
-
*/
|
|
89
|
-
interface CreateSelfSignCertificateWithConfigParam extends CreateSelfSignCertificateParam {
|
|
90
|
-
/** Root directory of the PKI store. */
|
|
91
|
-
rootDir: Filename;
|
|
92
|
-
/** Path to the OpenSSL configuration file. */
|
|
93
|
-
configFile: Filename;
|
|
94
|
-
/**
|
|
95
|
-
* The private key: either a filesystem path to a PEM file (unencrypted;
|
|
96
|
-
* the historical behavior), or an already-resolved in-memory
|
|
97
|
-
* {@link PrivateKey} — used when the key is passphrase-protected on
|
|
98
|
-
* disk, so the decrypted key material is never written back out in
|
|
99
|
-
* cleartext.
|
|
100
|
-
*/
|
|
101
|
-
privateKey: Filename | PrivateKey;
|
|
102
|
-
/** Intended purpose of the certificate. */
|
|
103
|
-
purpose: CertificatePurpose;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* A passphrase, or a function resolving one — called lazily, and at most
|
|
107
|
-
* once per `CertificateManager` / `CertificateAuthority` instance (the
|
|
108
|
-
* result is cached in memory). Never logged.
|
|
109
|
-
*/
|
|
110
|
-
type PrivateKeyPassphrase = string | (() => Promise<string>);
|
|
111
|
-
/**
|
|
112
|
-
* Sources a {@link PrivateKey} from somewhere other than the local
|
|
113
|
-
* filesystem (an HSM, a KMS, ...). When configured on `CertificateManager`,
|
|
114
|
-
* it overrides disk entirely — the on-disk `own/private/private_key.pem` is
|
|
115
|
-
* neither generated nor read. `CertificateAuthority` does not support a
|
|
116
|
-
* provider (its signing paths are openssl reading a key file); it does
|
|
117
|
-
* support `privateKeyPassphrase`.
|
|
118
|
-
*/
|
|
119
|
-
interface PrivateKeyProvider {
|
|
120
|
-
getPrivateKey(): Promise<PrivateKey>;
|
|
121
|
-
}
|
|
122
|
-
/** Resolve a {@link PrivateKeyPassphrase}, if configured. */
|
|
123
|
-
declare function resolvePrivateKeyPassphrase(passphrase: PrivateKeyPassphrase | undefined): Promise<string | undefined>;
|
|
124
7
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
8
|
+
* The default {@link CaBackend}: shells out to the `openssl` CLI, exactly as
|
|
9
|
+
* `CertificateAuthority` always has — this is a pure code move (plus a lock
|
|
10
|
+
* around every database-mutating operation, temp-config cleanup, and
|
|
11
|
+
* explicit `envOverrides` on every config render) with no change in the
|
|
12
|
+
* openssl commands issued or the files produced.
|
|
128
13
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
reason?: string;
|
|
14
|
+
declare class OpenSslCaBackend implements CaBackend {
|
|
15
|
+
#private;
|
|
16
|
+
/** The openssl CLI loads its key from a file, so it cannot call out to an HSM. */
|
|
17
|
+
readonly supportsExternalSigner = false;
|
|
18
|
+
preflight(): Promise<void>;
|
|
19
|
+
generateCaCsr(ca: CertificateAuthorityCore, _caRootDir: string, privateKeyFile: string, csrFile: string): Promise<void>;
|
|
20
|
+
bootstrap(ca: CertificateAuthorityCore): Promise<void>;
|
|
21
|
+
regenerateCrl(ca: CertificateAuthorityCore): Promise<void>;
|
|
22
|
+
signSubordinateCsr(ca: CertificateAuthorityCore, csrFile: string, certFile: string, validityDays: number): Promise<void>;
|
|
23
|
+
signEndEntityCsr(ca: CertificateAuthorityCore, certificate: string, csr: string, params1: Params, sanOverride: Required<ProcessAltNamesParam>): Promise<void>;
|
|
24
|
+
revoke(ca: CertificateAuthorityCore, certificate: string, reason: string): Promise<void>;
|
|
25
|
+
createSelfSignedCertificate(ca: CertificateAuthorityCore, certificateFile: string, privateKeyFile: string, params: Params): Promise<void>;
|
|
142
26
|
}
|
|
143
|
-
declare function adjustDate(params: StartDateEndDateParam): void;
|
|
144
|
-
declare function adjustApplicationUri(params: Params): void;
|
|
145
27
|
|
|
146
28
|
/** openssl argv entries plus the env they need; merge `env` into `ExecuteOptions.env`. */
|
|
147
29
|
interface OpensslPassArg {
|
|
@@ -156,660 +38,63 @@ interface OpensslPassArg {
|
|
|
156
38
|
declare function install_prerequisite(): Promise<string>;
|
|
157
39
|
|
|
158
40
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* - `"ready"` — the CA certificate already exists and is valid.
|
|
162
|
-
* - `"pending"` — key + CSR exist but no cert; waiting for external signing.
|
|
163
|
-
* - `"created"` — a fresh key + CSR were just generated.
|
|
164
|
-
* - `"expired"` — the CA certificate has expired (or will expire within
|
|
165
|
-
* the configured threshold). A new CSR has been generated for renewal
|
|
166
|
-
* while preserving the existing private key.
|
|
167
|
-
*/
|
|
168
|
-
type InitializeCSRResult = {
|
|
169
|
-
status: "ready";
|
|
170
|
-
} | {
|
|
171
|
-
status: "pending";
|
|
172
|
-
csrPath: string;
|
|
173
|
-
} | {
|
|
174
|
-
status: "created";
|
|
175
|
-
csrPath: string;
|
|
176
|
-
} | {
|
|
177
|
-
status: "expired";
|
|
178
|
-
csrPath: string;
|
|
179
|
-
expiryDate: Date;
|
|
180
|
-
};
|
|
181
|
-
/**
|
|
182
|
-
* Result of {@link CertificateAuthority.installCACertificate}.
|
|
183
|
-
*
|
|
184
|
-
* - `"success"` — the certificate was installed and CRL generated.
|
|
185
|
-
* - `"error"` — the certificate was rejected (see `reason`).
|
|
186
|
-
*/
|
|
187
|
-
type InstallCACertificateResult = {
|
|
188
|
-
status: "success";
|
|
189
|
-
} | {
|
|
190
|
-
status: "error";
|
|
191
|
-
reason: string;
|
|
192
|
-
message: string;
|
|
193
|
-
};
|
|
194
|
-
/**
|
|
195
|
-
* Options for creating a {@link CertificateAuthority}.
|
|
41
|
+
* Options for {@link CertificateAuthority}: the core's, except that the
|
|
42
|
+
* backend is named rather than supplied.
|
|
196
43
|
*/
|
|
197
|
-
interface CertificateAuthorityOptions {
|
|
198
|
-
/** RSA key size for the CA private key. */
|
|
199
|
-
keySize: KeySize;
|
|
200
|
-
/** Filesystem path where the CA directory structure is stored. */
|
|
201
|
-
location: string;
|
|
202
|
-
/**
|
|
203
|
-
* X.500 subject for the CA certificate.
|
|
204
|
-
* Accepts a slash-delimited string (e.g. `"/CN=My CA/O=Acme"`) or
|
|
205
|
-
* a structured {@link SubjectOptions} object.
|
|
206
|
-
*
|
|
207
|
-
* @defaultValue {@link defaultSubject}
|
|
208
|
-
*/
|
|
209
|
-
subject?: string | SubjectOptions;
|
|
210
|
-
/**
|
|
211
|
-
* Parent CA that will sign this CA's certificate.
|
|
212
|
-
* If omitted, the CA is self-signed (root CA).
|
|
213
|
-
* The parent CA must be initialized before this CA.
|
|
214
|
-
*/
|
|
215
|
-
issuerCA?: CertificateAuthority;
|
|
44
|
+
interface CertificateAuthorityOptions extends Omit<CertificateAuthorityCoreOptions, "backend"> {
|
|
216
45
|
/**
|
|
217
|
-
*
|
|
218
|
-
* reachable. When set, every issued certificate carries an
|
|
219
|
-
* X.509v3 `crlDistributionPoints` extension pointing at this URL.
|
|
220
|
-
*
|
|
221
|
-
* Leave undefined to omit the extension entirely (opt-in — see
|
|
222
|
-
* US-202). Validated synchronously at construction / setter call.
|
|
223
|
-
*/
|
|
224
|
-
crlDistributionUrl?: string;
|
|
225
|
-
/**
|
|
226
|
-
* Public URL of the OCSP responder. When set, every issued cert
|
|
227
|
-
* carries an `authorityInfoAccess` extension with an `OCSP` leg
|
|
228
|
-
* pointing at this URL. Leave undefined to omit (US-202).
|
|
229
|
-
*/
|
|
230
|
-
ocspResponderUrl?: string;
|
|
231
|
-
/**
|
|
232
|
-
* Public URL where the issuer's certificate can be fetched.
|
|
233
|
-
* When set, the `authorityInfoAccess` extension on every issued
|
|
234
|
-
* cert carries a `caIssuers` leg pointing at this URL (chain
|
|
235
|
-
* repair). Leave undefined to omit (US-202).
|
|
236
|
-
*/
|
|
237
|
-
caIssuersUrl?: string;
|
|
238
|
-
/**
|
|
239
|
-
* Encrypt the CA private key (`private/cakey.pem`) at rest with this
|
|
240
|
-
* passphrase (opt-in, default off). When set:
|
|
241
|
-
* - a freshly generated CA key is written as encrypted PKCS#8;
|
|
242
|
-
* - an existing *plaintext* CA key is encrypted in place by
|
|
243
|
-
* {@link CertificateAuthority.initialize} / `initializeCSR()`;
|
|
244
|
-
* - every `openssl` invocation that loads the CA key (CSR, self-sign,
|
|
245
|
-
* sign, revoke, CRL generation) receives it via `-passin env:`, never
|
|
246
|
-
* in argv; a missing or wrong passphrase fails `initialize()` closed.
|
|
247
|
-
*
|
|
248
|
-
* A function is called at most once per instance; the resolved
|
|
249
|
-
* passphrase is kept in memory for the instance's lifetime because the
|
|
250
|
-
* CA hands it to each openssl child. Never logged.
|
|
46
|
+
* Signing backend to use.
|
|
251
47
|
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* An OpenSSL-based Certificate Authority (CA) that can create,
|
|
259
|
-
* sign, and revoke X.509 certificates.
|
|
260
|
-
*
|
|
261
|
-
* The CA maintains a standard OpenSSL directory layout under
|
|
262
|
-
* {@link CertificateAuthority.rootDir | rootDir}:
|
|
263
|
-
*
|
|
264
|
-
* ```
|
|
265
|
-
* <location>/
|
|
266
|
-
* ├── conf/ OpenSSL configuration
|
|
267
|
-
* ├── private/ CA private key (cakey.pem)
|
|
268
|
-
* ├── public/ CA certificate (cacert.pem)
|
|
269
|
-
* ├── certs/ Signed certificates
|
|
270
|
-
* ├── crl/ Revocation lists
|
|
271
|
-
* ├── serial Next serial number
|
|
272
|
-
* ├── crlnumber Next CRL number
|
|
273
|
-
* └── index.txt Certificate database
|
|
274
|
-
* ```
|
|
275
|
-
*
|
|
276
|
-
* @example
|
|
277
|
-
* ```ts
|
|
278
|
-
* const ca = new CertificateAuthority({
|
|
279
|
-
* keySize: 2048,
|
|
280
|
-
* location: "/var/pki/CA"
|
|
281
|
-
* });
|
|
282
|
-
* await ca.initialize();
|
|
283
|
-
* ```
|
|
284
|
-
*/
|
|
285
|
-
/**
|
|
286
|
-
* A record from the OpenSSL CA certificate database
|
|
287
|
-
* (`index.txt`).
|
|
288
|
-
*/
|
|
289
|
-
interface IssuedCertificateRecord {
|
|
290
|
-
/** Hex-encoded serial number (e.g. `"1000"`). */
|
|
291
|
-
serial: string;
|
|
292
|
-
/** Certificate status. */
|
|
293
|
-
status: "valid" | "revoked" | "expired";
|
|
294
|
-
/** X.500 subject string (slash-delimited). */
|
|
295
|
-
subject: string;
|
|
296
|
-
/** Certificate expiry date as ISO-8601 string. */
|
|
297
|
-
expiryDate: string;
|
|
298
|
-
/**
|
|
299
|
-
* Revocation date as ISO-8601 string.
|
|
300
|
-
* Only present when `status === "revoked"`.
|
|
301
|
-
*/
|
|
302
|
-
revocationDate?: string;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Options for {@link CertificateAuthority.signCertificateRequestFromDER}.
|
|
306
|
-
*
|
|
307
|
-
* All fields are optional. When provided, they override the
|
|
308
|
-
* corresponding values from the CSR.
|
|
309
|
-
*/
|
|
310
|
-
interface SignCertificateOptions {
|
|
311
|
-
/** Certificate validity in days (default: 365). */
|
|
312
|
-
validity?: number;
|
|
313
|
-
/**
|
|
314
|
-
* Certificate validity in milliseconds.
|
|
48
|
+
* - `"openssl"` (default): shells out to the `openssl` CLI, as this
|
|
49
|
+
* class always has.
|
|
50
|
+
* - `"native"`: signs in pure JS via `node-opcua-crypto`, writing the
|
|
51
|
+
* same on-disk database format, and needs no `openssl` executable.
|
|
315
52
|
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*/
|
|
319
|
-
validityMs?: number;
|
|
320
|
-
/** Override the certificate start date. */
|
|
321
|
-
startDate?: Date;
|
|
322
|
-
/** Override DNS SANs. */
|
|
323
|
-
dns?: string[];
|
|
324
|
-
/** Override IP SANs. */
|
|
325
|
-
ip?: string[];
|
|
326
|
-
/** Override the application URI SAN. */
|
|
327
|
-
applicationUri?: string;
|
|
328
|
-
/** Override the X.500 subject. */
|
|
329
|
-
subject?: SubjectOptions | string;
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Capabilities advertised by a PKI backend (or by this
|
|
333
|
-
* {@link CertificateAuthority}) so consumers can clamp requested
|
|
334
|
-
* validity to the limits the backend can actually honor.
|
|
335
|
-
*
|
|
336
|
-
* Useful for the GDS Pull / Push management flows, where the CA may
|
|
337
|
-
* be supplied by an external service (step-ca, EJBCA, …) with its
|
|
338
|
-
* own minimum / maximum / granularity constraints.
|
|
339
|
-
*
|
|
340
|
-
* @see CertificateAuthority.getCapabilities
|
|
341
|
-
*/
|
|
342
|
-
interface PkiBackendCapabilities {
|
|
343
|
-
/** Smallest validity this backend can issue, in milliseconds. */
|
|
344
|
-
minValidityMs: number;
|
|
345
|
-
/** Largest validity this backend will issue, in milliseconds. */
|
|
346
|
-
maxValidityMs: number;
|
|
347
|
-
/**
|
|
348
|
-
* Validity is rounded up to the nearest multiple of this many
|
|
349
|
-
* milliseconds. For `node-opcua-pki`'s OpenSSL-based CA this is
|
|
350
|
-
* 1 000 ms (one second — the X.509 floor per RFC 5280 §4.1.2.5).
|
|
351
|
-
*/
|
|
352
|
-
validityGranularityMs: number;
|
|
353
|
-
/**
|
|
354
|
-
* Native unit the backend works in. Diagnostic only — callers
|
|
355
|
-
* always pass `validityMs` (US-208 / US-210).
|
|
356
|
-
*/
|
|
357
|
-
nativeUnit: "second" | "minute" | "hour" | "day";
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* Options for {@link CertificateAuthority.generateKeyPairAndSignDER}.
|
|
361
|
-
*/
|
|
362
|
-
interface GenerateKeyPairAndSignOptions {
|
|
363
|
-
/** OPC UA application URI (required). */
|
|
364
|
-
applicationUri: string;
|
|
365
|
-
/** X.500 subject for the certificate (e.g. "CN=MyApp"). */
|
|
366
|
-
subject?: SubjectOptions | string;
|
|
367
|
-
/** DNS host names for the SAN extension. */
|
|
368
|
-
dns?: string[];
|
|
369
|
-
/** IP addresses for the SAN extension. */
|
|
370
|
-
ip?: string[];
|
|
371
|
-
/** Certificate validity in days (default: 365). */
|
|
372
|
-
validity?: number;
|
|
373
|
-
/**
|
|
374
|
-
* Certificate validity in milliseconds.
|
|
53
|
+
* Setting `signer` implies `"native"`, since the openssl CLI can only
|
|
54
|
+
* load a key from a file.
|
|
375
55
|
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
56
|
+
* To supply a backend instance directly - including one of your own -
|
|
57
|
+
* use {@link CertificateAuthorityCore}, which is also the class to
|
|
58
|
+
* build against when you do not want the openssl backend in your
|
|
59
|
+
* bundle at all.
|
|
378
60
|
*/
|
|
379
|
-
|
|
380
|
-
/** Certificate start date (default: now). */
|
|
381
|
-
startDate?: Date;
|
|
382
|
-
/** RSA key size in bits (default: 2048). */
|
|
383
|
-
keySize?: KeySize;
|
|
61
|
+
backend?: "openssl" | "native";
|
|
384
62
|
}
|
|
385
63
|
/**
|
|
386
|
-
*
|
|
64
|
+
* A Certificate Authority with a backend chosen for you.
|
|
387
65
|
*
|
|
388
|
-
*
|
|
389
|
-
* the
|
|
66
|
+
* This is {@link CertificateAuthorityCore} plus the convenience that made
|
|
67
|
+
* it the historical API: name a backend, or name nothing and get openssl.
|
|
68
|
+
* Because it resolves the name, it necessarily references both backends,
|
|
69
|
+
* which is why the core exists separately - a program that never imports
|
|
70
|
+
* this class never pulls the openssl backend into its bundle.
|
|
390
71
|
*/
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Passphrase to protect the PFX file.
|
|
394
|
-
* If omitted, the PFX is created without a password.
|
|
395
|
-
*/
|
|
396
|
-
passphrase?: string;
|
|
397
|
-
}
|
|
398
|
-
declare class CertificateAuthority {
|
|
399
|
-
#private;
|
|
400
|
-
/** RSA key size used when generating the CA private key. */
|
|
401
|
-
readonly keySize: KeySize;
|
|
402
|
-
/** Root filesystem path of the CA directory structure. */
|
|
403
|
-
readonly location: string;
|
|
404
|
-
/** X.500 subject of the CA certificate. */
|
|
405
|
-
readonly subject: Subject;
|
|
406
|
-
/** @internal Parent CA (undefined for root CAs). */
|
|
407
|
-
readonly _issuerCA?: CertificateAuthority;
|
|
408
|
-
/** @internal Configured CDP / AIA URLs (US-202). */
|
|
409
|
-
private _crlDistributionUrl?;
|
|
410
|
-
private _ocspResponderUrl?;
|
|
411
|
-
private _caIssuersUrl?;
|
|
72
|
+
declare class CertificateAuthority extends CertificateAuthorityCore {
|
|
412
73
|
constructor(options: CertificateAuthorityOptions);
|
|
413
74
|
/**
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*/
|
|
417
|
-
get crlDistributionUrl(): string | undefined;
|
|
418
|
-
/**
|
|
419
|
-
* Public URL of the OCSP responder, or `undefined` if no AIA OCSP
|
|
420
|
-
* leg should be emitted on issued certs.
|
|
421
|
-
*/
|
|
422
|
-
get ocspResponderUrl(): string | undefined;
|
|
423
|
-
/**
|
|
424
|
-
* Public URL where the issuer's certificate can be fetched, or
|
|
425
|
-
* `undefined` if no AIA caIssuers leg should be emitted.
|
|
426
|
-
*/
|
|
427
|
-
get caIssuersUrl(): string | undefined;
|
|
428
|
-
/**
|
|
429
|
-
* Configure the URL embedded as `crlDistributionPoints` in every
|
|
430
|
-
* subsequently-issued certificate. Pass `undefined` to disable
|
|
431
|
-
* the extension entirely. Validated synchronously — throws on
|
|
432
|
-
* empty string, non-http(s) protocol, missing path. Warns (does
|
|
433
|
-
* not throw) when the URL points at loopback.
|
|
75
|
+
* @internal `-passin env:` argv + env for an openssl call that loads
|
|
76
|
+
* this CA's key (always emitted, empty when none).
|
|
434
77
|
*
|
|
435
|
-
*
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Configure the OCSP responder URL embedded as the `OCSP` leg of
|
|
440
|
-
* the `authorityInfoAccess` extension on every subsequently-issued
|
|
441
|
-
* certificate. Pass `undefined` to disable.
|
|
442
|
-
*
|
|
443
|
-
* @see US-202
|
|
444
|
-
*/
|
|
445
|
-
setOcspResponderUrl(url: string | undefined): void;
|
|
446
|
-
/**
|
|
447
|
-
* Configure the caIssuers URL embedded as the `caIssuers` leg of
|
|
448
|
-
* the `authorityInfoAccess` extension on every subsequently-issued
|
|
449
|
-
* certificate. Pass `undefined` to disable.
|
|
450
|
-
*
|
|
451
|
-
* @see US-202
|
|
452
|
-
*/
|
|
453
|
-
setCaIssuersUrl(url: string | undefined): void;
|
|
454
|
-
/**
|
|
455
|
-
* @internal
|
|
456
|
-
* Populate the OpenSSL config substitution env vars (`CDP_URL` and
|
|
457
|
-
* `AIA_VALUE`) from the configured URLs, or unset them so the
|
|
458
|
-
* matching `{{#KEY}}...{{/KEY}}` blocks in the templates are
|
|
459
|
-
* stripped. MUST be called before every `generateStaticConfig`
|
|
460
|
-
* invocation that signs a certificate.
|
|
461
|
-
*/
|
|
462
|
-
_wireRevocationEnvVars(): void;
|
|
463
|
-
/** Absolute path to the CA root directory (alias for {@link location}). */
|
|
464
|
-
get rootDir(): string;
|
|
465
|
-
/** Path to the OpenSSL configuration file (`conf/caconfig.cnf`). */
|
|
466
|
-
get configFile(): string;
|
|
467
|
-
/** Path to the CA private key (`private/cakey.pem`); may be passphrase-encrypted, see {@link getPrivateKey}. */
|
|
468
|
-
get privateKey(): string;
|
|
469
|
-
/**
|
|
470
|
-
* The CA private key, decrypted with the configured `privateKeyPassphrase`
|
|
471
|
-
* if it is encrypted. Fails closed (`PrivateKeyPassphraseRequiredError`)
|
|
472
|
-
* on an encrypted key with no or the wrong passphrase.
|
|
473
|
-
*/
|
|
474
|
-
getPrivateKey(): Promise<PrivateKey>;
|
|
475
|
-
/**
|
|
476
|
-
* Enable, disable, or rotate the passphrase protecting `private/cakey.pem`
|
|
477
|
-
* (temp file + atomic rename, temp file removed on failure). Only
|
|
478
|
-
* rewrites the file: construct a new `CertificateAuthority` with the new
|
|
479
|
-
* passphrase to continue using it.
|
|
78
|
+
* The openssl backend builds its own now; this remains so that external
|
|
79
|
+
* code calling it keeps working, and lives here rather than on the core
|
|
80
|
+
* because the flag means nothing to a backend that spawns nothing.
|
|
480
81
|
*/
|
|
481
|
-
reencryptPrivateKey(oldPassphrase?: PrivateKeyPassphrase, newPassphrase?: PrivateKeyPassphrase): Promise<void>;
|
|
482
|
-
/** @internal resolve the configured passphrase, at most once per instance */
|
|
483
|
-
_privateKeyPassphrase(): Promise<string | undefined>;
|
|
484
|
-
/** @internal `-passin env:` argv + env for every openssl call that loads this CA's key (always emitted, empty when none) */
|
|
485
82
|
_opensslPassin(): Promise<OpensslPassArg>;
|
|
486
83
|
/**
|
|
487
|
-
* @internal On an existing key: encrypt it in place if a passphrase is
|
|
488
|
-
* configured and it is still plaintext (secure by default: the option
|
|
489
|
-
* means "protect this key", not "ignore me"), then read it back so a
|
|
490
|
-
* wrong or missing passphrase fails initialize() closed rather than the
|
|
491
|
-
* first signing operation.
|
|
492
|
-
*/
|
|
493
|
-
_ensurePrivateKeyProtection(): Promise<void>;
|
|
494
|
-
/** Path to the CA certificate in PEM format (`public/cacert.pem`). */
|
|
495
|
-
get caCertificate(): string;
|
|
496
|
-
/**
|
|
497
|
-
* Path to the issuer certificate chain (`public/issuer_chain.pem`).
|
|
498
|
-
*
|
|
499
|
-
* This file is created by {@link installCACertificate} when the
|
|
500
|
-
* provided cert file contains additional issuer certificates
|
|
501
|
-
* (e.g. intermediate + root). It is appended to signed certs
|
|
502
|
-
* by {@link constructCertificateChain} to produce a full chain
|
|
503
|
-
* per OPC UA Part 6 §6.2.6.
|
|
504
|
-
*/
|
|
505
|
-
get issuerCertificateChain(): string;
|
|
506
|
-
/**
|
|
507
|
-
* Path to the current Certificate Revocation List in DER format.
|
|
508
|
-
* (`crl/revocation_list.der`)
|
|
509
|
-
*/
|
|
510
|
-
get revocationListDER(): string;
|
|
511
|
-
/**
|
|
512
|
-
* Path to the current Certificate Revocation List in PEM format.
|
|
513
|
-
* (`crl/revocation_list.crl`)
|
|
514
|
-
*/
|
|
515
|
-
get revocationList(): string;
|
|
516
|
-
/**
|
|
517
|
-
* Path to the concatenated CA certificate + CRL file.
|
|
518
|
-
* Used by OpenSSL for CRL-based verification.
|
|
519
|
-
*/
|
|
520
|
-
get caCertificateWithCrl(): string;
|
|
521
|
-
/**
|
|
522
|
-
* Return the CA certificate as a DER-encoded buffer.
|
|
523
|
-
*
|
|
524
|
-
* @throws if the CA certificate file does not exist
|
|
525
|
-
* (call {@link initialize} first).
|
|
526
|
-
*/
|
|
527
|
-
getCACertificateDER(): Buffer;
|
|
528
|
-
/**
|
|
529
|
-
* Return the CA certificate as a PEM-encoded string.
|
|
530
|
-
*
|
|
531
|
-
* @throws if the CA certificate file does not exist
|
|
532
|
-
* (call {@link initialize} first).
|
|
533
|
-
*/
|
|
534
|
-
getCACertificatePEM(): string;
|
|
535
|
-
/**
|
|
536
|
-
* Return the current Certificate Revocation List as a
|
|
537
|
-
* DER-encoded buffer.
|
|
538
|
-
*
|
|
539
|
-
* Returns an empty buffer if no CRL has been generated yet.
|
|
540
|
-
*/
|
|
541
|
-
getCRLDER(): Buffer;
|
|
542
|
-
/**
|
|
543
|
-
* Return the current Certificate Revocation List as a
|
|
544
|
-
* PEM-encoded string.
|
|
545
|
-
*
|
|
546
|
-
* Returns an empty string if no CRL has been generated yet.
|
|
547
|
-
*/
|
|
548
|
-
getCRLPEM(): string;
|
|
549
|
-
/**
|
|
550
|
-
* Return a list of all issued certificates recorded in the
|
|
551
|
-
* OpenSSL `index.txt` database.
|
|
552
|
-
*
|
|
553
|
-
* Each entry includes the serial number, subject, status,
|
|
554
|
-
* expiry date, and (for revoked certs) the revocation date.
|
|
555
|
-
*/
|
|
556
|
-
getIssuedCertificates(): IssuedCertificateRecord[];
|
|
557
|
-
/**
|
|
558
|
-
* Return the total number of certificates recorded in
|
|
559
|
-
* `index.txt`.
|
|
560
|
-
*/
|
|
561
|
-
getIssuedCertificateCount(): number;
|
|
562
|
-
/**
|
|
563
|
-
* Return the status of a certificate by its serial number.
|
|
564
|
-
*
|
|
565
|
-
* @param serial - hex-encoded serial number (e.g. `"1000"`)
|
|
566
|
-
* @returns `"valid"`, `"revoked"`, `"expired"`, or
|
|
567
|
-
* `undefined` if not found
|
|
568
|
-
*/
|
|
569
|
-
getCertificateStatus(serial: string): "valid" | "revoked" | "expired" | undefined;
|
|
570
|
-
/**
|
|
571
|
-
* Read a specific issued certificate by serial number and
|
|
572
|
-
* return its content as a DER-encoded buffer.
|
|
573
|
-
*
|
|
574
|
-
* OpenSSL stores signed certificates in the `certs/`
|
|
575
|
-
* directory using the naming convention `<SERIAL>.pem`.
|
|
576
|
-
*
|
|
577
|
-
* @param serial - hex-encoded serial number (e.g. `"1000"`)
|
|
578
|
-
* @returns the DER buffer, or `undefined` if not found
|
|
579
|
-
*/
|
|
580
|
-
getCertificateBySerial(serial: string): Buffer | undefined;
|
|
581
|
-
/**
|
|
582
|
-
* Path to the OpenSSL certificate database file.
|
|
583
|
-
*/
|
|
584
|
-
get indexFile(): string;
|
|
585
|
-
/**
|
|
586
|
-
* Parse the OpenSSL `index.txt` certificate database.
|
|
587
|
-
*
|
|
588
|
-
* Each line has tab-separated fields:
|
|
589
|
-
* ```
|
|
590
|
-
* status expiry [revocationDate] serial unknown subject
|
|
591
|
-
* ```
|
|
592
|
-
*
|
|
593
|
-
* - status: `V` (valid), `R` (revoked), `E` (expired)
|
|
594
|
-
* - expiry: `YYMMDDHHmmssZ`
|
|
595
|
-
* - revocationDate: present only for revoked certs
|
|
596
|
-
* - serial: hex string
|
|
597
|
-
* - unknown: always `"unknown"`
|
|
598
|
-
* - subject: X.500 slash-delimited string
|
|
599
|
-
*/
|
|
600
|
-
private _parseIndexTxt;
|
|
601
|
-
/**
|
|
602
|
-
* Sign a DER-encoded Certificate Signing Request and return
|
|
603
|
-
* the signed certificate as a DER buffer.
|
|
604
|
-
*
|
|
605
|
-
* This method handles temp-file creation and cleanup
|
|
606
|
-
* internally so that callers can work with in-memory
|
|
607
|
-
* buffers only.
|
|
608
|
-
*
|
|
609
|
-
* The CA can override fields from the CSR by passing
|
|
610
|
-
* `options.dns`, `options.ip`, `options.applicationUri`,
|
|
611
|
-
* `options.startDate`, or `options.subject`.
|
|
612
|
-
*
|
|
613
|
-
* @param csrDer - the CSR as a DER-encoded buffer
|
|
614
|
-
* @param options - signing options and CA overrides
|
|
615
|
-
* @returns the signed certificate as a DER-encoded buffer
|
|
616
|
-
*/
|
|
617
|
-
signCertificateRequestFromDER(csrDer: Buffer, options?: SignCertificateOptions): Promise<Buffer>;
|
|
618
|
-
/**
|
|
619
|
-
* Advertise the validity limits this CA can honor.
|
|
620
|
-
*
|
|
621
|
-
* Consumers (notably the GDS server in [`cert_auth.ts`](https://github.com/sterfive/node-opcua-gds))
|
|
622
|
-
* clamp a requested validity against these bounds before calling
|
|
623
|
-
* {@link signCertificateRequestFromDER}, so a misconfigured
|
|
624
|
-
* `defaultCertValidity` cannot ask the CA for something it cannot
|
|
625
|
-
* produce.
|
|
626
|
-
*
|
|
627
|
-
* Defaults match the OpenSSL-backed implementation:
|
|
628
|
-
* - `minValidityMs = 60_000` (1 minute) — practical floor; the
|
|
629
|
-
* X.509 spec floor is 1 second but very short certs are rarely
|
|
630
|
-
* useful and pathological for any real deployment.
|
|
631
|
-
* - `maxValidityMs = 10 * 365 * 86_400_000` (≈ 10 years) — long
|
|
632
|
-
* enough for root CAs.
|
|
633
|
-
* - `validityGranularityMs = 1_000` (1 second) — RFC 5280 §4.1.2.5
|
|
634
|
-
* floor on `notBefore` / `notAfter`.
|
|
635
|
-
* - `nativeUnit = "second"` — what `x509Date()` actually encodes.
|
|
636
|
-
*
|
|
637
|
-
* @see US-208 — the consumer-side capability story.
|
|
638
|
-
*/
|
|
639
|
-
getCapabilities(): PkiBackendCapabilities;
|
|
640
|
-
/**
|
|
641
|
-
* Generate a new RSA key pair, create an internal CSR, sign it
|
|
642
|
-
* with this CA, and return both the certificate and private key
|
|
643
|
-
* as DER-encoded buffers.
|
|
644
|
-
*
|
|
645
|
-
* The private key is **never stored** by the CA — it exists only
|
|
646
|
-
* in a temporary directory that is cleaned up after the operation.
|
|
647
|
-
*
|
|
648
|
-
* This is used by `StartNewKeyPairRequest` (OPC UA Part 12) for
|
|
649
|
-
* constrained devices that cannot generate their own keys.
|
|
650
|
-
*
|
|
651
|
-
* @param options - key generation and certificate parameters
|
|
652
|
-
* @returns `{ certificateDer, privateKey }` — certificate as DER,
|
|
653
|
-
* private key as a branded `PrivateKey` buffer
|
|
654
|
-
*/
|
|
655
|
-
generateKeyPairAndSignDER(options: GenerateKeyPairAndSignOptions): Promise<{
|
|
656
|
-
certificateDer: Buffer;
|
|
657
|
-
privateKey: PrivateKey;
|
|
658
|
-
}>;
|
|
659
|
-
/**
|
|
660
|
-
* Generate a new RSA key pair, create an internal CSR, sign it
|
|
661
|
-
* with this CA, and return the result as a PKCS#12 (PFX)
|
|
662
|
-
* buffer bundling the certificate, private key, and CA chain.
|
|
663
|
-
*
|
|
664
|
-
* The private key is **never stored** by the CA — it exists only
|
|
665
|
-
* in a temporary directory that is cleaned up after the operation.
|
|
666
|
-
*
|
|
667
|
-
* @param options - key generation, certificate, and PFX options
|
|
668
|
-
* @returns the PFX as a `Buffer`
|
|
669
|
-
*/
|
|
670
|
-
generateKeyPairAndSignPFX(options: GenerateKeyPairAndSignPFXOptions): Promise<Buffer>;
|
|
671
|
-
/**
|
|
672
|
-
* Revoke a DER-encoded certificate and regenerate the CRL.
|
|
673
|
-
*
|
|
674
|
-
* Extracts the serial number from the certificate, then
|
|
675
|
-
* uses the stored cert file at `certs/<serial>.pem` for
|
|
676
|
-
* revocation — avoiding temp-file PEM format mismatches.
|
|
677
|
-
*
|
|
678
|
-
* @param certDer - the certificate as a DER-encoded buffer
|
|
679
|
-
* @param reason - CRL reason code
|
|
680
|
-
* (default: `"keyCompromise"`)
|
|
681
|
-
* @throws if the certificate's serial is not found in the CA
|
|
682
|
-
*/
|
|
683
|
-
revokeCertificateDER(certDer: Buffer, reason?: string): Promise<void>;
|
|
684
|
-
/**
|
|
685
|
-
* Initialize the CA directory structure, generate the CA
|
|
686
|
-
* private key and self-signed certificate if they do not
|
|
687
|
-
* already exist.
|
|
688
|
-
*/
|
|
689
|
-
initialize(): Promise<void>;
|
|
690
|
-
/**
|
|
691
|
-
* Initialize the CA directory structure and generate the
|
|
692
|
-
* private key + CSR **without signing**.
|
|
693
|
-
*
|
|
694
|
-
* Use this when the CA certificate will be signed by an
|
|
695
|
-
* external (third-party) root CA. After receiving the signed
|
|
696
|
-
* certificate, call {@link installCACertificate} to complete
|
|
697
|
-
* the setup.
|
|
698
|
-
*
|
|
699
|
-
* **Idempotent / restart-safe:**
|
|
700
|
-
* - If the CA certificate exists and is valid → `{ status: "ready" }`
|
|
701
|
-
* - If the CA certificate has expired → `{ status: "expired", csrPath, expiryDate }`
|
|
702
|
-
* (a new CSR is generated, preserving the existing private key)
|
|
703
|
-
* - If key + CSR exist but no cert (restart before install) →
|
|
704
|
-
* `{ status: "pending", csrPath }` without regenerating
|
|
705
|
-
* - Otherwise → generates key + CSR → `{ status: "created", csrPath }`
|
|
706
|
-
*
|
|
707
|
-
* @returns an {@link InitializeCSRResult} describing the CA state
|
|
708
|
-
*/
|
|
709
|
-
initializeCSR(): Promise<InitializeCSRResult>;
|
|
710
|
-
/**
|
|
711
|
-
* Check whether the CA certificate needs renewal and, if so,
|
|
712
|
-
* generate a new CSR for re-signing by the external root CA.
|
|
713
|
-
*
|
|
714
|
-
* Use this while the CA is running to detect upcoming expiry
|
|
715
|
-
* **before** it actually expires. The existing private key is
|
|
716
|
-
* preserved so previously issued certs remain valid.
|
|
717
|
-
*
|
|
718
|
-
* @param thresholdDays - number of days before expiry at which
|
|
719
|
-
* to trigger renewal (default: 30)
|
|
720
|
-
* @returns an {@link InitializeCSRResult} — `"expired"` if
|
|
721
|
-
* renewal is needed, `"ready"` if the cert is still valid
|
|
722
|
-
*/
|
|
723
|
-
renewCSR(thresholdDays?: number): Promise<InitializeCSRResult>;
|
|
724
|
-
/**
|
|
725
|
-
* Generate a CSR using the existing private key.
|
|
726
84
|
* @internal
|
|
85
|
+
* Legacy shim: publish the `CDP_URL` / `AIA_VALUE` config substitution
|
|
86
|
+
* values to the shared env registry, or unset them so the matching
|
|
87
|
+
* `{{#KEY}}...{{/KEY}}` blocks are stripped. Nothing in this package
|
|
88
|
+
* reads the registry any more - every openssl config render receives
|
|
89
|
+
* these values explicitly, from the same {@link caConfigEnvOverrides}
|
|
90
|
+
* builder this delegates to, so the two cannot drift - kept only for
|
|
91
|
+
* external code that renders openssl config templates against the
|
|
92
|
+
* registry directly.
|
|
93
|
+
*
|
|
94
|
+
* It lives on this class rather than the core because it is meaningful
|
|
95
|
+
* only to the openssl backend.
|
|
727
96
|
*/
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* Install an externally-signed CA certificate and generate
|
|
731
|
-
* the initial CRL.
|
|
732
|
-
*
|
|
733
|
-
* Call this after {@link initializeCSR} once the external
|
|
734
|
-
* root CA has signed the CSR.
|
|
735
|
-
*
|
|
736
|
-
* **Safety checks:**
|
|
737
|
-
* - Verifies that the certificate's public key matches the
|
|
738
|
-
* CA private key before installing.
|
|
739
|
-
*
|
|
740
|
-
* @param signedCertFile - path to the PEM-encoded signed
|
|
741
|
-
* CA certificate (issued by the external root CA)
|
|
742
|
-
* @returns an {@link InstallCACertificateResult} with
|
|
743
|
-
* `status: "success"` or `status: "error"` and a `reason`
|
|
744
|
-
*/
|
|
745
|
-
installCACertificate(signedCertFile: string): Promise<InstallCACertificateResult>;
|
|
746
|
-
/**
|
|
747
|
-
* Sign a CSR with CA extensions (`v3_ca`), producing a
|
|
748
|
-
* subordinate CA certificate.
|
|
749
|
-
*
|
|
750
|
-
* Unlike {@link signCertificateRequest} which signs with
|
|
751
|
-
* end-entity extensions (SANs, etc.), this method signs
|
|
752
|
-
* with `basicConstraints = CA:TRUE` and `keyUsage =
|
|
753
|
-
* keyCertSign, cRLSign`.
|
|
754
|
-
*
|
|
755
|
-
* @param certFile - output path for the signed CA cert (PEM)
|
|
756
|
-
* @param csrFile - path to the subordinate CA's CSR
|
|
757
|
-
* @param params - signing parameters
|
|
758
|
-
*/
|
|
759
|
-
signCACertificateRequest(certFile: string, csrFile: string, params: {
|
|
760
|
-
validity?: number;
|
|
761
|
-
}): Promise<void>;
|
|
762
|
-
/**
|
|
763
|
-
* Rebuild the combined CA certificate + CRL file.
|
|
764
|
-
*
|
|
765
|
-
* This concatenates the CA certificate with the current
|
|
766
|
-
* revocation list so that OpenSSL can verify certificates
|
|
767
|
-
* with CRL checking enabled.
|
|
768
|
-
*/
|
|
769
|
-
constructCACertificateWithCRL(): Promise<void>;
|
|
770
|
-
/**
|
|
771
|
-
* Append the CA certificate to a signed certificate file,
|
|
772
|
-
* creating a PEM certificate chain.
|
|
773
|
-
*
|
|
774
|
-
* @param certificate - path to the certificate file to extend
|
|
775
|
-
*/
|
|
776
|
-
constructCertificateChain(certificate: Filename): Promise<void>;
|
|
777
|
-
/**
|
|
778
|
-
* Create a self-signed certificate using OpenSSL.
|
|
779
|
-
*
|
|
780
|
-
* @param certificateFile - output path for the signed certificate
|
|
781
|
-
* @param privateKey - path to the private key file
|
|
782
|
-
* @param params - certificate parameters (subject, validity, SANs)
|
|
783
|
-
*/
|
|
784
|
-
createSelfSignedCertificate(certificateFile: Filename, privateKey: Filename, params: Params): Promise<void>;
|
|
785
|
-
/**
|
|
786
|
-
* Revoke a certificate and regenerate the CRL.
|
|
787
|
-
*
|
|
788
|
-
* @param certificate - path to the certificate file to revoke
|
|
789
|
-
* @param params - revocation parameters
|
|
790
|
-
* @param params.reason - CRL reason code
|
|
791
|
-
* (default `"keyCompromise"`)
|
|
792
|
-
*/
|
|
793
|
-
revokeCertificate(certificate: Filename, params: Params): Promise<void>;
|
|
794
|
-
/**
|
|
795
|
-
* Sign a Certificate Signing Request (CSR) with this CA.
|
|
796
|
-
*
|
|
797
|
-
* The signed certificate is written to `certificate`, and the
|
|
798
|
-
* CA certificate chain plus CRL are appended to form a
|
|
799
|
-
* complete certificate chain.
|
|
800
|
-
*
|
|
801
|
-
* @param certificate - output path for the signed certificate
|
|
802
|
-
* @param certificateSigningRequestFilename - path to the CSR
|
|
803
|
-
* @param params1 - signing parameters (validity, dates, SANs)
|
|
804
|
-
* @returns the path to the signed certificate
|
|
805
|
-
*/
|
|
806
|
-
signCertificateRequest(certificate: Filename, certificateSigningRequestFilename: Filename, params1: Params): Promise<Filename>;
|
|
807
|
-
/**
|
|
808
|
-
* Verify a certificate against this CA.
|
|
809
|
-
*
|
|
810
|
-
* @param certificate - path to the certificate file to verify
|
|
811
|
-
*/
|
|
812
|
-
verifyCertificate(certificate: Filename): Promise<void>;
|
|
97
|
+
_wireRevocationEnvVars(): void;
|
|
813
98
|
}
|
|
814
99
|
|
|
815
100
|
/**
|
|
@@ -954,6 +239,29 @@ interface CertificateManagerOptions {
|
|
|
954
239
|
* ignored.
|
|
955
240
|
*/
|
|
956
241
|
privateKeyProvider?: PrivateKeyProvider;
|
|
242
|
+
/**
|
|
243
|
+
* Use a private key this manager can never read: an opaque
|
|
244
|
+
* {@link IKeyOperations} provider (HSM, KMS, TPM, OS keystore, ...).
|
|
245
|
+
*
|
|
246
|
+
* The distinction with `privateKeyProvider` matters: a
|
|
247
|
+
* `privateKeyProvider` *sources raw key material* from elsewhere and
|
|
248
|
+
* hands it back; `keyOperations` never reveals the key — only sign and
|
|
249
|
+
* decrypt operations on it. Prefer `keyOperations` whenever the key
|
|
250
|
+
* does not need to be exportable.
|
|
251
|
+
*
|
|
252
|
+
* When set:
|
|
253
|
+
* - {@link CertificateManager.getPrivateKey} and
|
|
254
|
+
* {@link CertificateManager.reencryptPrivateKey} throw
|
|
255
|
+
* `PrivateKeyUnavailableError` — there is no key material to return
|
|
256
|
+
* or rewrite, and no on-disk key is generated or expected;
|
|
257
|
+
* - {@link CertificateManager.getKeyOperations} returns this object;
|
|
258
|
+
* - `initialize()` fails closed if the provider cannot answer
|
|
259
|
+
* `getKeyMetadata()` (unreachable HSM, misconfiguration);
|
|
260
|
+
* - mutually exclusive with `privateKeyProvider` and
|
|
261
|
+
* `privateKeyPassphrase` — both describe key *material*, which an
|
|
262
|
+
* opaque configuration does not have.
|
|
263
|
+
*/
|
|
264
|
+
keyOperations?: IKeyOperations;
|
|
957
265
|
}
|
|
958
266
|
/**
|
|
959
267
|
* Parameters for {@link createSelfSignedCertificate}.
|
|
@@ -1248,6 +556,27 @@ declare class CertificateManager extends EventEmitter {
|
|
|
1248
556
|
* authority on what the current key is.
|
|
1249
557
|
*/
|
|
1250
558
|
getPrivateKey(): Promise<PrivateKey>;
|
|
559
|
+
/**
|
|
560
|
+
* True when this manager's key is opaque — configured through
|
|
561
|
+
* `keyOperations`, held by an HSM/KMS, never obtainable as material.
|
|
562
|
+
* When true, {@link getPrivateKey} throws `PrivateKeyUnavailableError`
|
|
563
|
+
* and {@link getKeyOperations} is the only way to use the key.
|
|
564
|
+
*/
|
|
565
|
+
isPrivateKeyOpaque(): boolean;
|
|
566
|
+
/**
|
|
567
|
+
* The key as an opaque {@link IKeyOperations} — the recommended way to
|
|
568
|
+
* *use* the private key regardless of where it lives.
|
|
569
|
+
*
|
|
570
|
+
* Returns the configured `keyOperations` object when the key is opaque.
|
|
571
|
+
* Otherwise returns a stable lazy wrap over {@link getPrivateKey}: its
|
|
572
|
+
* methods resolve the key on first use (disk read, passphrase,
|
|
573
|
+
* `privateKeyProvider` — all async), so the wrap offers no synchronous
|
|
574
|
+
* fast path; callers that need one resolve the key themselves and build
|
|
575
|
+
* a `LocalKeyOperations` over it. The wrap follows key rotation: a
|
|
576
|
+
* `privateKeyProvider` that starts returning a different key gets a
|
|
577
|
+
* fresh underlying `LocalKeyOperations`.
|
|
578
|
+
*/
|
|
579
|
+
getKeyOperations(): IKeyOperations;
|
|
1251
580
|
/**
|
|
1252
581
|
* Enable, disable, or rotate the passphrase protecting the on-disk
|
|
1253
582
|
* private key: decrypt with `oldPassphrase` (omit if the key is
|
|
@@ -1569,6 +898,12 @@ interface CreatePFXOptions {
|
|
|
1569
898
|
* to include in the PFX bundle.
|
|
1570
899
|
*/
|
|
1571
900
|
caCertificateFiles?: Filename[];
|
|
901
|
+
/**
|
|
902
|
+
* Optional display label stored on the bundle, the equivalent of
|
|
903
|
+
* openssl's `-name`. The Windows certificate store and `keytool` show
|
|
904
|
+
* it; {@link extractAllFromPFX} and {@link dumpPFX} report it back.
|
|
905
|
+
*/
|
|
906
|
+
friendlyName?: string;
|
|
1572
907
|
}
|
|
1573
908
|
/**
|
|
1574
909
|
* Options for extracting data from a PFX (PKCS#12) file.
|
|
@@ -1595,67 +930,39 @@ interface ExtractPFXResult {
|
|
|
1595
930
|
* (empty string if none).
|
|
1596
931
|
*/
|
|
1597
932
|
caCertificates: string;
|
|
933
|
+
/** The display label the bundle carries, if it has one. */
|
|
934
|
+
friendlyName?: string;
|
|
1598
935
|
}
|
|
1599
936
|
/**
|
|
1600
937
|
* Create a PFX (PKCS#12) file from a certificate and private key.
|
|
1601
938
|
*
|
|
1602
|
-
*
|
|
1603
|
-
*
|
|
1604
|
-
*
|
|
1605
|
-
*
|
|
1606
|
-
*
|
|
1607
|
-
*
|
|
1608
|
-
*
|
|
1609
|
-
*
|
|
1610
|
-
* ```
|
|
1611
|
-
* Both passphrases are passed via per-invocation environment variables,
|
|
1612
|
-
* never placed in argv — see {@link ExecuteOptions.env}.
|
|
1613
|
-
* `-passin` is always present (empty when the key is plaintext) so that an
|
|
1614
|
-
* encrypted key without a `privateKeyPassphrase` fails fast rather than
|
|
1615
|
-
* leaving openssl waiting on a terminal prompt that never comes.
|
|
939
|
+
* The bundle is protected with PBES2 / AES-256-CBC under an SHA-256 MAC. If
|
|
940
|
+
* `certificateFile` holds more than one PEM block, the first is the
|
|
941
|
+
* identity and the rest join the issuer chain, ahead of any
|
|
942
|
+
* `caCertificateFiles`.
|
|
943
|
+
*
|
|
944
|
+
* Nothing is written unless every input reads back cleanly and the private
|
|
945
|
+
* key belongs to the certificate, so a wrong `privateKeyPassphrase` or a
|
|
946
|
+
* mismatched pair leaves no half-made file behind.
|
|
1616
947
|
*
|
|
1617
|
-
* @param options
|
|
948
|
+
* @param options - see {@link CreatePFXOptions}
|
|
1618
949
|
*/
|
|
1619
950
|
declare function createPFX(options: CreatePFXOptions): Promise<void>;
|
|
1620
951
|
/**
|
|
1621
952
|
* Extract the client/server certificate from a PFX file.
|
|
1622
953
|
*
|
|
1623
|
-
* Wraps:
|
|
1624
|
-
* ```
|
|
1625
|
-
* openssl pkcs12 -in <pfx> -clcerts -nokeys
|
|
1626
|
-
* -passin env:NODE_OPCUA_PKI_OPENSSL_PASSIN
|
|
1627
|
-
* ```
|
|
1628
|
-
* The passphrase is passed via a per-invocation environment variable, never
|
|
1629
|
-
* placed in argv — see {@link ExecuteOptions.env}.
|
|
1630
|
-
*
|
|
1631
954
|
* @returns the certificate in PEM format.
|
|
1632
955
|
*/
|
|
1633
956
|
declare function extractCertificateFromPFX(options: ExtractPFXOptions): Promise<string>;
|
|
1634
957
|
/**
|
|
1635
958
|
* Extract the private key from a PFX file.
|
|
1636
959
|
*
|
|
1637
|
-
*
|
|
1638
|
-
* ```
|
|
1639
|
-
* openssl pkcs12 -in <pfx> -nocerts -nodes
|
|
1640
|
-
* -passin env:NODE_OPCUA_PKI_OPENSSL_PASSIN
|
|
1641
|
-
* ```
|
|
1642
|
-
* The passphrase is passed via a per-invocation environment variable, never
|
|
1643
|
-
* placed in argv — see {@link ExecuteOptions.env}.
|
|
1644
|
-
*
|
|
1645
|
-
* @returns the private key in PEM format.
|
|
960
|
+
* @returns the private key as unencrypted PKCS#8 PEM.
|
|
1646
961
|
*/
|
|
1647
962
|
declare function extractPrivateKeyFromPFX(options: ExtractPFXOptions): Promise<string>;
|
|
1648
963
|
/**
|
|
1649
964
|
* Extract the CA / intermediate certificates from a PFX file.
|
|
1650
965
|
*
|
|
1651
|
-
* Wraps:
|
|
1652
|
-
* ```
|
|
1653
|
-
* openssl pkcs12 -in <pfx> -cacerts -nokeys -nodes
|
|
1654
|
-
* -passin env:NODE_OPCUA_PKI_OPENSSL_PASSIN
|
|
1655
|
-
* ```
|
|
1656
|
-
* The passphrase is passed via a per-invocation environment variable, never
|
|
1657
|
-
* placed in argv — see {@link ExecuteOptions.env}.
|
|
1658
|
-
*
|
|
1659
966
|
* @returns the CA certificates in PEM format
|
|
1660
967
|
* (empty string if none are present).
|
|
1661
968
|
*/
|
|
@@ -1664,35 +971,31 @@ declare function extractCACertificatesFromPFX(options: ExtractPFXOptions): Promi
|
|
|
1664
971
|
* Extract certificate + private key + CA certs from a PFX file
|
|
1665
972
|
* in a single call.
|
|
1666
973
|
*
|
|
974
|
+
* Prefer this over the single-part helpers when you want more than one
|
|
975
|
+
* part: the file is read, decrypted and MAC-verified once here, against
|
|
976
|
+
* once per part.
|
|
977
|
+
*
|
|
1667
978
|
* @returns an {@link ExtractPFXResult} with all PEM-encoded parts.
|
|
1668
979
|
*/
|
|
1669
980
|
declare function extractAllFromPFX(options: ExtractPFXOptions): Promise<ExtractPFXResult>;
|
|
1670
981
|
/**
|
|
1671
|
-
* Convert a PFX file to a single PEM file
|
|
1672
|
-
* certificate and the
|
|
1673
|
-
*
|
|
1674
|
-
* Wraps:
|
|
1675
|
-
* ```
|
|
1676
|
-
* openssl pkcs12 -in <pfx> -out <pem> -nodes
|
|
1677
|
-
* -passin env:NODE_OPCUA_PKI_OPENSSL_PASSIN
|
|
1678
|
-
* ```
|
|
1679
|
-
* The passphrase is passed via a per-invocation environment variable, never
|
|
1680
|
-
* placed in argv — see {@link ExecuteOptions.env}.
|
|
982
|
+
* Convert a PFX file to a single PEM file holding the private key, the
|
|
983
|
+
* certificate, and any issuer certificates the bundle carries, in that
|
|
984
|
+
* order.
|
|
1681
985
|
*/
|
|
1682
986
|
declare function convertPFXtoPEM(pfxFile: Filename, pemFile: Filename, passphrase?: string): Promise<void>;
|
|
1683
987
|
/**
|
|
1684
988
|
* Dump the contents of a PFX file in human-readable form.
|
|
1685
989
|
*
|
|
1686
|
-
*
|
|
1687
|
-
*
|
|
1688
|
-
*
|
|
1689
|
-
*
|
|
1690
|
-
*
|
|
1691
|
-
*
|
|
1692
|
-
* placed in argv — see {@link ExecuteOptions.env}.
|
|
990
|
+
* The layout is this package's own, not `openssl pkcs12 -info`'s: it
|
|
991
|
+
* describes the identity the bundle carries rather than the algorithms it
|
|
992
|
+
* was encrypted with, and it states outright whether the enclosed key
|
|
993
|
+
* matches the enclosed certificate - the question a bundle that will not
|
|
994
|
+
* load is usually being asked. Treat the text as something to read, not to
|
|
995
|
+
* parse; use {@link extractAllFromPFX} to get at the parts.
|
|
1693
996
|
*
|
|
1694
997
|
* @returns the human-readable dump as a string.
|
|
1695
998
|
*/
|
|
1696
999
|
declare function dumpPFX(pfxFile: Filename, passphrase?: string): Promise<string>;
|
|
1697
1000
|
|
|
1698
|
-
export { type AddCertificateValidationOptions, CertificateAuthority, type CertificateAuthorityOptions, CertificateManager, type CertificateManagerEvents, type CertificateManagerOptions, CertificateManagerState, type
|
|
1001
|
+
export { type AddCertificateValidationOptions, CaBackend, CertificateAuthority, CertificateAuthorityCore, CertificateAuthorityCoreOptions, type CertificateAuthorityOptions, CertificateManager, type CertificateManagerEvents, type CertificateManagerOptions, CertificateManagerState, type CertificateStore, type ChainCompletionResult, ChainCompletionStatus, type CreatePFXOptions, CreateSelfSignCertificateParam, type CreateSelfSignCertificateParam1, type CrlStore, type ExtractPFXOptions, type ExtractPFXResult, Filename, KeySize, OpenSslCaBackend, Params, PrivateKeyPassphrase, PrivateKeyProvider, ProcessAltNamesParam, VerificationStatus, type VerifyCertificateOptions, coerceCertificateChain, convertPFXtoPEM, createPFX, dumpPFX, extractAllFromPFX, extractCACertificatesFromPFX, extractCertificateFromPFX, extractPrivateKeyFromPFX, findIssuerCertificateInChain, install_prerequisite, isIntermediateIssuer, isIssuer, isRootIssuer, makeFingerprint };
|