node-opcua-pki 6.22.1 → 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.
Files changed (137) hide show
  1. package/bin/install_prerequisite.ts +1 -1
  2. package/bin/pki.ts +1 -1
  3. package/dist/bin/install_prerequisite.d.ts +2 -0
  4. package/dist/bin/install_prerequisite.js +6 -0
  5. package/dist/bin/install_prerequisite.js.map +1 -0
  6. package/dist/bin/pki.d.ts +2 -0
  7. package/dist/bin/pki.js +4 -0
  8. package/dist/bin/pki.js.map +1 -0
  9. package/dist/lib/ca/backends/native_ca_backend.d.ts +49 -0
  10. package/dist/lib/ca/backends/native_ca_backend.js +365 -0
  11. package/dist/lib/ca/backends/native_ca_backend.js.map +1 -0
  12. package/dist/lib/ca/backends/openssl_ca_backend.d.ts +47 -0
  13. package/dist/lib/ca/backends/openssl_ca_backend.js +398 -0
  14. package/dist/lib/ca/backends/openssl_ca_backend.js.map +1 -0
  15. package/dist/lib/ca/certificate_authority.d.ts +62 -0
  16. package/dist/lib/ca/certificate_authority.js +91 -0
  17. package/dist/lib/ca/certificate_authority.js.map +1 -0
  18. package/dist/lib/ca/core/ca_backend.d.ts +89 -0
  19. package/dist/lib/ca/core/ca_backend.js +24 -0
  20. package/dist/lib/ca/core/ca_backend.js.map +1 -0
  21. package/dist/lib/ca/core/ca_database.d.ts +91 -0
  22. package/dist/lib/ca/core/ca_database.js +267 -0
  23. package/dist/lib/ca/core/ca_database.js.map +1 -0
  24. package/dist/{core-BwqSJPHc.d.mts → lib/ca/core/certificate_authority_core.d.ts} +45 -394
  25. package/dist/lib/ca/core/certificate_authority_core.js +1300 -0
  26. package/dist/lib/ca/core/certificate_authority_core.js.map +1 -0
  27. package/dist/lib/ca/core/index.d.ts +17 -0
  28. package/dist/lib/ca/core/index.js +25 -0
  29. package/dist/lib/ca/core/index.js.map +1 -0
  30. package/dist/lib/ca/crypto_create_CA.d.ts +1 -0
  31. package/dist/lib/ca/crypto_create_CA.js +821 -0
  32. package/dist/lib/ca/crypto_create_CA.js.map +1 -0
  33. package/dist/lib/ca/index.d.ts +1 -0
  34. package/dist/lib/ca/index.js +2 -0
  35. package/dist/lib/ca/index.js.map +1 -0
  36. package/dist/lib/ca/templates/ca_config_template.cnf.d.ts +2 -0
  37. package/dist/lib/ca/templates/ca_config_template.cnf.js +170 -0
  38. package/dist/lib/ca/templates/ca_config_template.cnf.js.map +1 -0
  39. package/dist/lib/core.d.ts +33 -0
  40. package/dist/lib/core.js +56 -0
  41. package/dist/lib/core.js.map +1 -0
  42. package/dist/lib/index.d.ts +11 -0
  43. package/dist/lib/index.js +37 -0
  44. package/dist/lib/index.js.map +1 -0
  45. package/dist/lib/misc/applicationurn.d.ts +1 -0
  46. package/dist/lib/misc/applicationurn.js +40 -0
  47. package/dist/lib/misc/applicationurn.js.map +1 -0
  48. package/dist/lib/misc/hostname.d.ts +8 -0
  49. package/dist/lib/misc/hostname.js +82 -0
  50. package/dist/lib/misc/hostname.js.map +1 -0
  51. package/dist/lib/misc/subject.d.ts +2 -0
  52. package/dist/lib/misc/subject.js +2 -0
  53. package/dist/lib/misc/subject.js.map +1 -0
  54. package/dist/{index.d.ts → lib/pki/certificate_manager.d.ts} +24 -248
  55. package/dist/lib/pki/certificate_manager.js +2302 -0
  56. package/dist/lib/pki/certificate_manager.js.map +1 -0
  57. package/dist/lib/pki/templates/simple_config_template.cnf.d.ts +2 -0
  58. package/dist/lib/pki/templates/simple_config_template.cnf.js +74 -0
  59. package/dist/lib/pki/templates/simple_config_template.cnf.js.map +1 -0
  60. package/dist/lib/pki/toolbox_pfx.d.ts +127 -0
  61. package/dist/lib/pki/toolbox_pfx.js +248 -0
  62. package/dist/lib/pki/toolbox_pfx.js.map +1 -0
  63. package/dist/lib/toolbox/common.d.ts +150 -0
  64. package/dist/lib/toolbox/common.js +82 -0
  65. package/dist/lib/toolbox/common.js.map +1 -0
  66. package/dist/lib/toolbox/common2.d.ts +25 -0
  67. package/dist/lib/toolbox/common2.js +97 -0
  68. package/dist/lib/toolbox/common2.js.map +1 -0
  69. package/dist/lib/toolbox/config.d.ts +5 -0
  70. package/dist/lib/toolbox/config.js +28 -0
  71. package/dist/lib/toolbox/config.js.map +1 -0
  72. package/dist/lib/toolbox/debug.d.ts +5 -0
  73. package/dist/lib/toolbox/debug.js +35 -0
  74. package/dist/lib/toolbox/debug.js.map +1 -0
  75. package/dist/lib/toolbox/display.d.ts +4 -0
  76. package/dist/lib/toolbox/display.js +56 -0
  77. package/dist/lib/toolbox/display.js.map +1 -0
  78. package/dist/lib/toolbox/index.d.ts +5 -0
  79. package/dist/lib/toolbox/index.js +28 -0
  80. package/dist/lib/toolbox/index.js.map +1 -0
  81. package/dist/lib/toolbox/with_openssl/_create_random_file.d.ts +4 -0
  82. package/dist/lib/toolbox/with_openssl/_create_random_file.js +50 -0
  83. package/dist/lib/toolbox/with_openssl/_create_random_file.js.map +1 -0
  84. package/dist/lib/toolbox/with_openssl/_env.d.ts +58 -0
  85. package/dist/lib/toolbox/with_openssl/_env.js +126 -0
  86. package/dist/lib/toolbox/with_openssl/_env.js.map +1 -0
  87. package/dist/lib/toolbox/with_openssl/create_certificate_signing_request.d.ts +5 -0
  88. package/dist/lib/toolbox/with_openssl/create_certificate_signing_request.js +72 -0
  89. package/dist/lib/toolbox/with_openssl/create_certificate_signing_request.js.map +1 -0
  90. package/dist/lib/toolbox/with_openssl/create_private_key.d.ts +5 -0
  91. package/dist/lib/toolbox/with_openssl/create_private_key.js +92 -0
  92. package/dist/lib/toolbox/with_openssl/create_private_key.js.map +1 -0
  93. package/dist/lib/toolbox/with_openssl/create_self_signed_certificate.d.ts +5 -0
  94. package/dist/lib/toolbox/with_openssl/create_self_signed_certificate.js +135 -0
  95. package/dist/lib/toolbox/with_openssl/create_self_signed_certificate.js.map +1 -0
  96. package/dist/lib/toolbox/with_openssl/execute_openssl.d.ts +67 -0
  97. package/dist/lib/toolbox/with_openssl/execute_openssl.js +246 -0
  98. package/dist/lib/toolbox/with_openssl/execute_openssl.js.map +1 -0
  99. package/dist/lib/toolbox/with_openssl/index.d.ts +5 -0
  100. package/dist/lib/toolbox/with_openssl/index.js +30 -0
  101. package/dist/lib/toolbox/with_openssl/index.js.map +1 -0
  102. package/dist/lib/toolbox/with_openssl/install_prerequisite.d.ts +7 -0
  103. package/dist/lib/toolbox/with_openssl/install_prerequisite.js +358 -0
  104. package/dist/lib/toolbox/with_openssl/install_prerequisite.js.map +1 -0
  105. package/dist/lib/toolbox/with_openssl/toolbox.d.ts +53 -0
  106. package/dist/lib/toolbox/with_openssl/toolbox.js +190 -0
  107. package/dist/lib/toolbox/with_openssl/toolbox.js.map +1 -0
  108. package/dist/lib/toolbox/without_openssl/create_certificate_signing_request.d.ts +5 -0
  109. package/dist/lib/toolbox/without_openssl/create_certificate_signing_request.js +69 -0
  110. package/dist/lib/toolbox/without_openssl/create_certificate_signing_request.js.map +1 -0
  111. package/dist/lib/toolbox/without_openssl/create_self_signed_certificate.d.ts +3 -0
  112. package/dist/lib/toolbox/without_openssl/create_self_signed_certificate.js +78 -0
  113. package/dist/lib/toolbox/without_openssl/create_self_signed_certificate.js.map +1 -0
  114. package/dist/lib/toolbox/without_openssl/index.d.ts +2 -0
  115. package/dist/lib/toolbox/without_openssl/index.js +25 -0
  116. package/dist/lib/toolbox/without_openssl/index.js.map +1 -0
  117. package/package.json +11 -30
  118. package/dist/bin/install_prerequisite.mjs +0 -18
  119. package/dist/bin/install_prerequisite.mjs.map +0 -1
  120. package/dist/bin/pki.mjs +0 -5932
  121. package/dist/bin/pki.mjs.map +0 -1
  122. package/dist/chunk-EQ4DGI4M.mjs +0 -1917
  123. package/dist/chunk-EQ4DGI4M.mjs.map +0 -1
  124. package/dist/chunk-GCHH54PS.mjs +0 -30
  125. package/dist/chunk-GCHH54PS.mjs.map +0 -1
  126. package/dist/core-BwqSJPHc.d.ts +0 -1041
  127. package/dist/core.d.mts +0 -2
  128. package/dist/core.d.ts +0 -2
  129. package/dist/core.js +0 -1902
  130. package/dist/core.js.map +0 -1
  131. package/dist/core.mjs +0 -21
  132. package/dist/core.mjs.map +0 -1
  133. package/dist/index.d.mts +0 -1003
  134. package/dist/index.js +0 -5009
  135. package/dist/index.js.map +0 -1
  136. package/dist/index.mjs +0 -3145
  137. package/dist/index.mjs.map +0 -1
@@ -1,1041 +0,0 @@
1
- import { SubjectOptions, PrivateKey, CaSigner, CertificatePurpose, Subject } from 'node-opcua-crypto';
2
-
3
- /** RSA key size in bits. */
4
- type KeySize = 1024 | 2048 | 3072 | 4096;
5
- /** Hex-encoded SHA-1 certificate thumbprint. */
6
- type Thumbprint = string;
7
- /** A filesystem path to a file. */
8
- type Filename = string;
9
- /** Status of a certificate in the trust store. */
10
- type CertificateStatus = "unknown" | "trusted" | "rejected";
11
-
12
- /**
13
- * @deprecated Use {@link KeySize} instead.
14
- */
15
- type KeyLength = 1024 | 2048 | 3072 | 4096;
16
- declare function quote(str?: string): string;
17
- /**
18
- * Subject Alternative Name (SAN) parameters for certificate
19
- * generation.
20
- */
21
- interface ProcessAltNamesParam {
22
- /** DNS host names to include in the SAN extension. */
23
- dns?: string[];
24
- /** IP addresses to include in the SAN extension. */
25
- ip?: string[];
26
- /** OPC UA application URI for the SAN extension. */
27
- applicationUri?: string;
28
- }
29
- /**
30
- * Options for creating a Certificate Signing Request (CSR).
31
- */
32
- interface CreateCertificateSigningRequestOptions extends ProcessAltNamesParam {
33
- /** X.500 subject for the certificate. */
34
- subject?: SubjectOptions | string;
35
- }
36
- /**
37
- * Extended CSR options that include filesystem paths and
38
- * certificate purpose — used internally by the OpenSSL toolbox.
39
- */
40
- interface CreateCertificateSigningRequestWithConfigOptions extends CreateCertificateSigningRequestOptions {
41
- /** Root directory of the PKI store. */
42
- rootDir: Filename;
43
- /** Path to the OpenSSL configuration file. */
44
- configFile: Filename;
45
- /**
46
- * The private key: a filesystem path to a PEM file (unencrypted;
47
- * the historical behavior), an already-resolved in-memory
48
- * {@link PrivateKey}, or an opaque {@link CaSigner} (HSM/KMS-held key;
49
- * only the openssl-free toolbox supports it — openssl needs a key file)
50
- * — see {@link CreateSelfSignCertificateWithConfigParam.privateKey}.
51
- */
52
- privateKey: Filename | PrivateKey | CaSigner;
53
- /** Intended purpose of the certificate. */
54
- purpose: CertificatePurpose;
55
- }
56
- /**
57
- * Narrows the `privateKey` union of the toolbox options: a {@link CaSigner}
58
- * is the only member that carries a `sign` method — a path is a string and
59
- * a {@link PrivateKey} envelope has only `hidden`.
60
- */
61
- declare function isOpaqueSigner(privateKey: Filename | PrivateKey | CaSigner): privateKey is CaSigner;
62
- /**
63
- * Validity period parameters for certificate generation.
64
- */
65
- interface StartDateEndDateParam {
66
- /** Certificate "Not Before" date. Defaults to now. */
67
- startDate?: Date;
68
- /** Certificate "Not After" date (computed from validity). */
69
- endDate?: Date;
70
- /** Number of days the certificate is valid. @defaultValue 365 */
71
- validity?: number;
72
- /**
73
- * Certificate validity in milliseconds.
74
- *
75
- * When provided, takes precedence over {@link validity} and enables
76
- * sub-day validity (X.509 supports second precision per RFC 5280
77
- * §4.1.2.5; OpenSSL is invoked with `-startdate`/`-enddate` already).
78
- *
79
- * Typical use is short-lived certificates for demos or for renewal
80
- * cycle testing. Existing day-based callers are unaffected.
81
- */
82
- validityMs?: number;
83
- }
84
- /**
85
- * Parameters for creating a self-signed certificate.
86
- */
87
- interface CreateSelfSignCertificateParam extends ProcessAltNamesParam, StartDateEndDateParam {
88
- /** X.500 subject for the certificate. */
89
- subject?: SubjectOptions | string;
90
- }
91
- /**
92
- * Extended self-signed certificate options that include
93
- * filesystem paths and purpose — used internally.
94
- */
95
- interface CreateSelfSignCertificateWithConfigParam extends CreateSelfSignCertificateParam {
96
- /** Root directory of the PKI store. */
97
- rootDir: Filename;
98
- /** Path to the OpenSSL configuration file. */
99
- configFile: Filename;
100
- /**
101
- * The private key: a filesystem path to a PEM file (unencrypted;
102
- * the historical behavior), an already-resolved in-memory
103
- * {@link PrivateKey} — used when the key is passphrase-protected on
104
- * disk, so the decrypted key material is never written back out in
105
- * cleartext — or an opaque {@link CaSigner} (HSM/KMS-held key; only
106
- * the openssl-free toolbox supports it — openssl needs a key file).
107
- */
108
- privateKey: Filename | PrivateKey | CaSigner;
109
- /** Intended purpose of the certificate. */
110
- purpose: CertificatePurpose;
111
- }
112
- /**
113
- * A passphrase, or a function resolving one — called lazily, and at most
114
- * once per `CertificateManager` / `CertificateAuthority` instance (the
115
- * result is cached in memory). Never logged.
116
- */
117
- type PrivateKeyPassphrase = string | (() => Promise<string>);
118
- /**
119
- * Sources a {@link PrivateKey} from somewhere other than the local
120
- * filesystem (an HSM, a KMS, ...). When configured on `CertificateManager`,
121
- * it overrides disk entirely — the on-disk `own/private/private_key.pem` is
122
- * neither generated nor read. `CertificateAuthority` does not support a
123
- * provider (its signing paths are openssl reading a key file); it does
124
- * support `privateKeyPassphrase`.
125
- */
126
- interface PrivateKeyProvider {
127
- getPrivateKey(): Promise<PrivateKey>;
128
- }
129
- /** Resolve a {@link PrivateKeyPassphrase}, if configured. */
130
- declare function resolvePrivateKeyPassphrase(passphrase: PrivateKeyPassphrase | undefined): Promise<string | undefined>;
131
- /**
132
- * General-purpose parameters passed to CA operations such as
133
- * {@link CertificateAuthority.signCertificateRequest} and
134
- * {@link CertificateAuthority.revokeCertificate}.
135
- */
136
- interface Params extends ProcessAltNamesParam, StartDateEndDateParam {
137
- /** X.500 subject for the certificate. */
138
- subject?: SubjectOptions | string;
139
- /** Path to the private key file. */
140
- privateKey?: string;
141
- /** Path to the OpenSSL configuration file. */
142
- configFile?: string;
143
- /** Root directory of the PKI store. */
144
- rootDir?: string;
145
- /** Output filename for the generated certificate. */
146
- outputFile?: string;
147
- /** CRL revocation reason (e.g. `"keyCompromise"`). */
148
- reason?: string;
149
- }
150
- declare function adjustDate(params: StartDateEndDateParam): void;
151
- declare function adjustApplicationUri(params: Params): void;
152
-
153
- /**
154
- * A record from the OpenSSL CA certificate database (`index.txt`).
155
- */
156
- interface IssuedCertificateRecord {
157
- /** Hex-encoded serial number (e.g. `"1000"`). */
158
- serial: string;
159
- /** Certificate status. */
160
- status: "valid" | "revoked" | "expired";
161
- /** X.500 subject string (slash-delimited). */
162
- subject: string;
163
- /** Certificate expiry date as ISO-8601 string. */
164
- expiryDate: string;
165
- /**
166
- * Revocation date as ISO-8601 string.
167
- * Only present when `status === "revoked"`.
168
- */
169
- revocationDate?: string;
170
- /**
171
- * CRL revocation reason (e.g. `"keyCompromise"`), as stored after the
172
- * comma in the revocation-date field. Only present when
173
- * `status === "revoked"` and a reason was recorded.
174
- */
175
- reason?: string;
176
- }
177
- /**
178
- * Read and write access to a CA's OpenSSL-format certificate database
179
- * (`index.txt`, `serial`, `crlnumber`, `certs/<SERIAL>.pem`).
180
- *
181
- * This is the format `openssl ca` itself writes and reads; every mutating
182
- * method here (`nextSerial`, `nextCrlNumber`, `appendIssued`, `markRevoked`,
183
- * `storeCertificate`) exists so a native (non-openssl) signing backend can
184
- * write the exact same on-disk format `openssl ca` does, so an install can
185
- * move between backends and external `openssl` tooling keeps working on the
186
- * same directory. Callers are responsible for serializing access — every
187
- * mutating call must happen under the owning CA's directory lock
188
- * (`CertificateAuthority._withCaDirectoryLock`), the same guarantee
189
- * `OpenSslCaBackend` gets from the lock around each `openssl ca` /
190
- * `openssl x509 -CAserial` invocation.
191
- */
192
- declare class CaDatabase {
193
- #private;
194
- constructor(rootDir: string);
195
- /** Path to the OpenSSL certificate database file (`index.txt`). */
196
- get indexFile(): string;
197
- /**
198
- * Parse the OpenSSL `index.txt` certificate database.
199
- *
200
- * Each line has tab-separated fields:
201
- * ```
202
- * status expiry [revocationDate] serial unknown subject
203
- * ```
204
- *
205
- * - status: `V` (valid), `R` (revoked), `E` (expired)
206
- * - expiry: `YYMMDDHHmmssZ`
207
- * - revocationDate: present only for revoked certs
208
- * - serial: hex string
209
- * - unknown: always `"unknown"`
210
- * - subject: X.500 slash-delimited string
211
- */
212
- readIndex(): IssuedCertificateRecord[];
213
- /** Look up one record by serial number (case-insensitive). */
214
- findBySerial(serial: string): IssuedCertificateRecord | undefined;
215
- /**
216
- * Read a specific issued certificate by serial number.
217
- *
218
- * OpenSSL stores signed certificates in the `certs/` directory using
219
- * the naming convention `<SERIAL>.pem`.
220
- *
221
- * @param serial - hex-encoded serial number (e.g. `"1000"`)
222
- * @returns the DER buffer, or `undefined` if not found
223
- */
224
- getCertificateBySerial(serial: string): Buffer | undefined;
225
- /** Hand out the next certificate serial number, bumping the `serial` file. */
226
- nextSerial(): string;
227
- /** Hand out the next CRL number, bumping the `crlnumber` file. */
228
- nextCrlNumber(): string;
229
- /** Append a newly-issued certificate's `V` (valid) row to `index.txt`. */
230
- appendIssued(record: {
231
- serial: string;
232
- expiryDate: Date;
233
- subject: string;
234
- }): void;
235
- /**
236
- * Rewrite a certificate's `index.txt` row from `V` to `R` (revoked).
237
- * Throws if the serial is not found, or is already revoked — the same
238
- * "already revoked" case `openssl ca -revoke` itself rejects.
239
- */
240
- markRevoked(serial: string, revocationDate: Date, reason: string): void;
241
- /** Store a signed certificate's PEM under `certs/<SERIAL>.pem`, as `openssl ca` does. */
242
- storeCertificate(serial: string, pem: string): void;
243
- }
244
-
245
- /** Default X.500 subject used when no custom subject is provided. */
246
- declare const defaultSubject = "/C=FR/ST=IDF/L=Paris/O=Local NODE-OPCUA Certificate Authority/CN=NodeOPCUA-CA";
247
- declare const configurationFileTemplate: string;
248
- /**
249
- * Escape a value for use inside a double-quoted openssl config value.
250
- *
251
- * openssl's config parser (crypto/conf/conf_def.c) treats an unquoted value
252
- * specially: `$var` / `${var}` / `$(var)` are expanded, and `'`, `"` and the
253
- * backtick are all quote characters (a backtick pair is silently removed).
254
- * Inside a double-quoted value none of that applies: characters are copied
255
- * verbatim except a backslash, which escapes the next character. So a path
256
- * containing `$`, backticks, `#` or spaces is safe once double-quoted with
257
- * `\` and `"` escaped.
258
- */
259
- declare function escapeOpensslConfDoubleQuoted(value: string): string;
260
- /**
261
- * Render the CA openssl configuration for `caRootDir`. The root folder is
262
- * emitted forward-slashed (openssl accepts that on every platform) and
263
- * double-quoted, so a CA `location` containing characters that openssl's
264
- * config syntax would otherwise interpret (`$`, backticks, `#`, quotes) is
265
- * taken literally.
266
- */
267
- declare function renderCaConfig(caRootDir: string): string;
268
- /**
269
- * Result of {@link CertificateAuthority.initializeCSR}.
270
- *
271
- * - `"ready"` — the CA certificate already exists and is valid.
272
- * - `"pending"` — key + CSR exist but no cert; waiting for external signing.
273
- * - `"created"` — a fresh key + CSR were just generated.
274
- * - `"expired"` — the CA certificate has expired (or will expire within
275
- * the configured threshold). A new CSR has been generated for renewal
276
- * while preserving the existing private key.
277
- */
278
- type InitializeCSRResult = {
279
- status: "ready";
280
- } | {
281
- status: "pending";
282
- csrPath: string;
283
- } | {
284
- status: "created";
285
- csrPath: string;
286
- } | {
287
- status: "expired";
288
- csrPath: string;
289
- expiryDate: Date;
290
- };
291
- /**
292
- * Result of {@link CertificateAuthority.installCACertificate}.
293
- *
294
- * - `"success"` — the certificate was installed and CRL generated.
295
- * - `"error"` — the certificate was rejected (see `reason`).
296
- */
297
- type InstallCACertificateResult = {
298
- status: "success";
299
- } | {
300
- status: "error";
301
- reason: string;
302
- message: string;
303
- };
304
- /**
305
- * Options for creating a {@link CertificateAuthority}.
306
- */
307
- interface CertificateAuthorityCoreOptions {
308
- /** RSA key size for the CA private key. */
309
- keySize: KeySize;
310
- /** Filesystem path where the CA directory structure is stored. */
311
- location: string;
312
- /**
313
- * X.500 subject for the CA certificate.
314
- * Accepts a slash-delimited string (e.g. `"/CN=My CA/O=Acme"`) or
315
- * a structured {@link SubjectOptions} object.
316
- *
317
- * @defaultValue {@link defaultSubject}
318
- */
319
- subject?: string | SubjectOptions;
320
- /**
321
- * Parent CA that will sign this CA's certificate.
322
- * If omitted, the CA is self-signed (root CA).
323
- * The parent CA must be initialized before this CA.
324
- */
325
- issuerCA?: CertificateAuthorityCore;
326
- /**
327
- * Public URL (http/https) where the CRL produced by this CA is
328
- * reachable. When set, every issued certificate carries an
329
- * X.509v3 `crlDistributionPoints` extension pointing at this URL.
330
- *
331
- * Leave undefined to omit the extension entirely (opt-in — see
332
- * US-202). Validated synchronously at construction / setter call.
333
- */
334
- crlDistributionUrl?: string;
335
- /**
336
- * Public URL of the OCSP responder. When set, every issued cert
337
- * carries an `authorityInfoAccess` extension with an `OCSP` leg
338
- * pointing at this URL. Leave undefined to omit (US-202).
339
- */
340
- ocspResponderUrl?: string;
341
- /**
342
- * Public URL where the issuer's certificate can be fetched.
343
- * When set, the `authorityInfoAccess` extension on every issued
344
- * cert carries a `caIssuers` leg pointing at this URL (chain
345
- * repair). Leave undefined to omit (US-202).
346
- */
347
- caIssuersUrl?: string;
348
- /**
349
- * Encrypt the CA private key (`private/cakey.pem`) at rest with this
350
- * passphrase (opt-in, default off). When set:
351
- * - a freshly generated CA key is written as encrypted PKCS#8;
352
- * - an existing *plaintext* CA key is encrypted in place by
353
- * {@link CertificateAuthority.initialize} / `initializeCSR()`;
354
- * - every `openssl` invocation that loads the CA key (CSR, self-sign,
355
- * sign, revoke, CRL generation) receives it via `-passin env:`, never
356
- * in argv; a missing or wrong passphrase fails `initialize()` closed.
357
- *
358
- * A function is called at most once per instance; the resolved
359
- * passphrase is kept in memory for the instance's lifetime because the
360
- * CA hands it to each openssl child. Never logged.
361
- *
362
- * A subordinate CA (`issuerCA` set) uses the *issuer's* passphrase for
363
- * the issuer's key: construct the parent with its own option.
364
- */
365
- privateKeyPassphrase?: PrivateKeyPassphrase;
366
- /**
367
- * Who actually signs, and writes the certificate database. Supplying it
368
- * is the whole point of this class: nothing here names a concrete
369
- * backend, so a program that only ever uses the native one never
370
- * references - and never has to ship - the openssl one.
371
- *
372
- * {@link CertificateAuthority} is the batteries-included subclass that
373
- * picks a backend for you from a `"openssl" | "native"` option.
374
- */
375
- backend: CaBackend;
376
- /**
377
- * Sign with an external key that never leaves its holder - an HSM or a
378
- * cloud KMS - instead of `private/cakey.pem`. The signer exposes only
379
- * `getPublicKey()` and `sign(tbs)`; this class builds the to-be-signed
380
- * bytes locally and asks the signer for the signature.
381
- *
382
- * Setting this implies `backend: "native"` (the openssl CLI can only
383
- * load a key from a file, so it cannot honour a signer); combining it
384
- * with an explicit `backend: "openssl"` is a constructor error. No
385
- * `private/cakey.pem` is generated, and the key-file operations that
386
- * cannot apply - {@link CertificateAuthority.getPrivateKey} and
387
- * {@link CertificateAuthority.reencryptPrivateKey} - throw.
388
- */
389
- signer?: CaSigner;
390
- }
391
-
392
- /**
393
- * Options for {@link CertificateAuthority.signCertificateRequestFromDER}.
394
- *
395
- * All fields are optional. When provided, they override the
396
- * corresponding values from the CSR.
397
- */
398
- interface SignCertificateOptions {
399
- /** Certificate validity in days (default: 365). */
400
- validity?: number;
401
- /**
402
- * Certificate validity in milliseconds.
403
- *
404
- * When provided, takes precedence over {@link validity} and enables
405
- * sub-day validity (e.g. 10-minute certificates for renewal demos).
406
- */
407
- validityMs?: number;
408
- /** Override the certificate start date. */
409
- startDate?: Date;
410
- /** Override DNS SANs. */
411
- dns?: string[];
412
- /** Override IP SANs. */
413
- ip?: string[];
414
- /** Override the application URI SAN. */
415
- applicationUri?: string;
416
- /** Override the X.500 subject. */
417
- subject?: SubjectOptions | string;
418
- }
419
- /**
420
- * Capabilities advertised by a PKI backend (or by this
421
- * {@link CertificateAuthority}) so consumers can clamp requested
422
- * validity to the limits the backend can actually honor.
423
- *
424
- * Useful for the GDS Pull / Push management flows, where the CA may
425
- * be supplied by an external service (step-ca, EJBCA, …) with its
426
- * own minimum / maximum / granularity constraints.
427
- *
428
- * @see CertificateAuthority.getCapabilities
429
- */
430
- interface PkiBackendCapabilities {
431
- /** Smallest validity this backend can issue, in milliseconds. */
432
- minValidityMs: number;
433
- /** Largest validity this backend will issue, in milliseconds. */
434
- maxValidityMs: number;
435
- /**
436
- * Validity is rounded up to the nearest multiple of this many
437
- * milliseconds. For `node-opcua-pki`'s OpenSSL-based CA this is
438
- * 1 000 ms (one second — the X.509 floor per RFC 5280 §4.1.2.5).
439
- */
440
- validityGranularityMs: number;
441
- /**
442
- * Native unit the backend works in. Diagnostic only — callers
443
- * always pass `validityMs` (US-208 / US-210).
444
- */
445
- nativeUnit: "second" | "minute" | "hour" | "day";
446
- }
447
- /**
448
- * Options for {@link CertificateAuthority.generateKeyPairAndSignDER}.
449
- */
450
- interface GenerateKeyPairAndSignOptions {
451
- /** OPC UA application URI (required). */
452
- applicationUri: string;
453
- /** X.500 subject for the certificate (e.g. "CN=MyApp"). */
454
- subject?: SubjectOptions | string;
455
- /** DNS host names for the SAN extension. */
456
- dns?: string[];
457
- /** IP addresses for the SAN extension. */
458
- ip?: string[];
459
- /** Certificate validity in days (default: 365). */
460
- validity?: number;
461
- /**
462
- * Certificate validity in milliseconds.
463
- *
464
- * When provided, takes precedence over {@link validity} and enables
465
- * sub-day validity (e.g. 10-minute certificates for renewal demos).
466
- */
467
- validityMs?: number;
468
- /** Certificate start date (default: now). */
469
- startDate?: Date;
470
- /** RSA key size in bits (default: 2048). */
471
- keySize?: KeySize;
472
- }
473
- /**
474
- * Options for {@link CertificateAuthority.generateKeyPairAndSignPFX}.
475
- *
476
- * Extends the DER options with an optional `passphrase` to protect
477
- * the PFX bundle.
478
- */
479
- interface GenerateKeyPairAndSignPFXOptions extends GenerateKeyPairAndSignOptions {
480
- /**
481
- * Passphrase to protect the PFX file.
482
- * If omitted, the PFX is created without a password.
483
- */
484
- passphrase?: string;
485
- }
486
- declare class CertificateAuthorityCore {
487
- #private;
488
- /** RSA key size used when generating the CA private key. */
489
- readonly keySize: KeySize;
490
- /** Root filesystem path of the CA directory structure. */
491
- readonly location: string;
492
- /** X.500 subject of the CA certificate. */
493
- readonly subject: Subject;
494
- /** @internal Parent CA (undefined for root CAs). */
495
- readonly _issuerCA?: CertificateAuthorityCore;
496
- /** @internal Configured CDP / AIA URLs (US-202). */
497
- private _crlDistributionUrl?;
498
- private _ocspResponderUrl?;
499
- private _caIssuersUrl?;
500
- constructor(options: CertificateAuthorityCoreOptions);
501
- /**
502
- * Public URL where the CRL produced by this CA is reachable, or
503
- * `undefined` if no CDP extension should be emitted on issued certs.
504
- */
505
- get crlDistributionUrl(): string | undefined;
506
- /**
507
- * Public URL of the OCSP responder, or `undefined` if no AIA OCSP
508
- * leg should be emitted on issued certs.
509
- */
510
- get ocspResponderUrl(): string | undefined;
511
- /**
512
- * Public URL where the issuer's certificate can be fetched, or
513
- * `undefined` if no AIA caIssuers leg should be emitted.
514
- */
515
- get caIssuersUrl(): string | undefined;
516
- /**
517
- * Configure the URL embedded as `crlDistributionPoints` in every
518
- * subsequently-issued certificate. Pass `undefined` to disable
519
- * the extension entirely. Validated synchronously — throws on
520
- * empty string, non-http(s) protocol, missing path. Warns (does
521
- * not throw) when the URL points at loopback.
522
- *
523
- * @see US-202
524
- */
525
- setCrlDistributionUrl(url: string | undefined): void;
526
- /**
527
- * Configure the OCSP responder URL embedded as the `OCSP` leg of
528
- * the `authorityInfoAccess` extension on every subsequently-issued
529
- * certificate. Pass `undefined` to disable.
530
- *
531
- * @see US-202
532
- */
533
- setOcspResponderUrl(url: string | undefined): void;
534
- /**
535
- * Configure the caIssuers URL embedded as the `caIssuers` leg of
536
- * the `authorityInfoAccess` extension on every subsequently-issued
537
- * certificate. Pass `undefined` to disable.
538
- *
539
- * @see US-202
540
- */
541
- setCaIssuersUrl(url: string | undefined): void;
542
- /** Absolute path to the CA root directory (alias for {@link location}). */
543
- get rootDir(): string;
544
- /** Path to the OpenSSL configuration file (`conf/caconfig.cnf`). */
545
- get configFile(): string;
546
- /** Path to the CA private key (`private/cakey.pem`); may be passphrase-encrypted, see {@link getPrivateKey}. */
547
- get privateKey(): string;
548
- /**
549
- * The CA private key, decrypted with the configured `privateKeyPassphrase`
550
- * if it is encrypted. Fails closed (`PrivateKeyPassphraseRequiredError`)
551
- * on an encrypted key with no or the wrong passphrase.
552
- */
553
- getPrivateKey(): Promise<PrivateKey>;
554
- /**
555
- * True when this CA signs with an external {@link CaSigner} (HSM/KMS)
556
- * rather than with `private/cakey.pem`. There is then no private key
557
- * file on disk, and never was one.
558
- */
559
- get hasExternalSigner(): boolean;
560
- /**
561
- * @internal The key every signing operation goes through. An injected
562
- * {@link CaSigner} is returned as-is; otherwise the on-disk key is read
563
- * (and decrypted) and handed over as a plain `CryptoKey`. Both are
564
- * accepted by the `node-opcua-crypto` signing primitives, so callers
565
- * never branch on which one they got.
566
- */
567
- _getSigningKey(): Promise<CryptoKey | CaSigner>;
568
- /**
569
- * Enable, disable, or rotate the passphrase protecting `private/cakey.pem`
570
- * (temp file + atomic rename, temp file removed on failure). Only
571
- * rewrites the file: construct a new `CertificateAuthority` with the new
572
- * passphrase to continue using it.
573
- */
574
- reencryptPrivateKey(oldPassphrase?: PrivateKeyPassphrase, newPassphrase?: PrivateKeyPassphrase): Promise<void>;
575
- /** @internal resolve the configured passphrase, at most once per instance */
576
- _privateKeyPassphrase(): Promise<string | undefined>;
577
- /**
578
- * @internal On an existing key: encrypt it in place if a passphrase is
579
- * configured and it is still plaintext (secure by default: the option
580
- * means "protect this key", not "ignore me"), then read it back so a
581
- * wrong or missing passphrase fails initialize() closed rather than the
582
- * first signing operation.
583
- */
584
- _ensurePrivateKeyProtection(): Promise<void>;
585
- /**
586
- * @internal Run `action` under this CA's directory lock. For the one
587
- * legitimate cross-instance use: a subordinate CA's bootstrap signs its
588
- * certificate with `openssl x509 -CAserial`, which read-increment-writes
589
- * THIS issuer's `serial` file, and must therefore hold this issuer's
590
- * lock (ordering is always subordinate -> issuer, so no cycle).
591
- */
592
- _withCaDirectoryLock<T>(action: () => Promise<T>): Promise<T>;
593
- /** Path to the CA certificate in PEM format (`public/cacert.pem`). */
594
- get caCertificate(): string;
595
- /**
596
- * Path to the issuer certificate chain (`public/issuer_chain.pem`).
597
- *
598
- * This file is created by {@link installCACertificate} when the
599
- * provided cert file contains additional issuer certificates
600
- * (e.g. intermediate + root). It is appended to signed certs
601
- * by {@link constructCertificateChain} to produce a full chain
602
- * per OPC UA Part 6 §6.2.6.
603
- */
604
- get issuerCertificateChain(): string;
605
- /**
606
- * Path to the current Certificate Revocation List in DER format.
607
- * (`crl/revocation_list.der`)
608
- */
609
- get revocationListDER(): string;
610
- /**
611
- * Path to the current Certificate Revocation List in PEM format.
612
- * (`crl/revocation_list.crl`)
613
- */
614
- get revocationList(): string;
615
- /**
616
- * Path to the concatenated CA certificate + CRL file.
617
- * Used by OpenSSL for CRL-based verification.
618
- */
619
- get caCertificateWithCrl(): string;
620
- /**
621
- * Return the CA certificate as a DER-encoded buffer.
622
- *
623
- * @throws if the CA certificate file does not exist
624
- * (call {@link initialize} first).
625
- */
626
- getCACertificateDER(): Buffer;
627
- /**
628
- * Return the CA certificate as a PEM-encoded string.
629
- *
630
- * @throws if the CA certificate file does not exist
631
- * (call {@link initialize} first).
632
- */
633
- getCACertificatePEM(): string;
634
- /**
635
- * Return the current Certificate Revocation List as a
636
- * DER-encoded buffer.
637
- *
638
- * Returns an empty buffer if no CRL has been generated yet.
639
- */
640
- getCRLDER(): Buffer;
641
- /**
642
- * Return the current Certificate Revocation List as a
643
- * PEM-encoded string.
644
- *
645
- * Returns an empty string if no CRL has been generated yet.
646
- */
647
- getCRLPEM(): string;
648
- /**
649
- * Return a list of all issued certificates recorded in the
650
- * OpenSSL `index.txt` database.
651
- *
652
- * Each entry includes the serial number, subject, status,
653
- * expiry date, and (for revoked certs) the revocation date.
654
- */
655
- getIssuedCertificates(): IssuedCertificateRecord[];
656
- /**
657
- * Return the total number of certificates recorded in
658
- * `index.txt`.
659
- */
660
- getIssuedCertificateCount(): number;
661
- /**
662
- * Return the status of a certificate by its serial number.
663
- *
664
- * @param serial - hex-encoded serial number (e.g. `"1000"`)
665
- * @returns `"valid"`, `"revoked"`, `"expired"`, or
666
- * `undefined` if not found
667
- */
668
- getCertificateStatus(serial: string): "valid" | "revoked" | "expired" | undefined;
669
- /**
670
- * Read a specific issued certificate by serial number and
671
- * return its content as a DER-encoded buffer.
672
- *
673
- * OpenSSL stores signed certificates in the `certs/`
674
- * directory using the naming convention `<SERIAL>.pem`.
675
- *
676
- * @param serial - hex-encoded serial number (e.g. `"1000"`)
677
- * @returns the DER buffer, or `undefined` if not found
678
- */
679
- getCertificateBySerial(serial: string): Buffer | undefined;
680
- /**
681
- * Path to the OpenSSL certificate database file.
682
- */
683
- get indexFile(): string;
684
- /**
685
- * Sign a DER-encoded Certificate Signing Request and return
686
- * the signed certificate as a DER buffer.
687
- *
688
- * This method handles temp-file creation and cleanup
689
- * internally so that callers can work with in-memory
690
- * buffers only.
691
- *
692
- * The CA can override fields from the CSR by passing
693
- * `options.dns`, `options.ip`, `options.applicationUri`,
694
- * `options.startDate`, or `options.subject`.
695
- *
696
- * @param csrDer - the CSR as a DER-encoded buffer
697
- * @param options - signing options and CA overrides
698
- * @returns the signed certificate as a DER-encoded buffer
699
- */
700
- signCertificateRequestFromDER(csrDer: Buffer, options?: SignCertificateOptions): Promise<Buffer>;
701
- /**
702
- * Advertise the validity limits this CA can honor.
703
- *
704
- * Consumers (notably the GDS server in [`cert_auth.ts`](https://github.com/sterfive/node-opcua-gds))
705
- * clamp a requested validity against these bounds before calling
706
- * {@link signCertificateRequestFromDER}, so a misconfigured
707
- * `defaultCertValidity` cannot ask the CA for something it cannot
708
- * produce.
709
- *
710
- * Defaults match the OpenSSL-backed implementation:
711
- * - `minValidityMs = 60_000` (1 minute) — practical floor; the
712
- * X.509 spec floor is 1 second but very short certs are rarely
713
- * useful and pathological for any real deployment.
714
- * - `maxValidityMs = 10 * 365 * 86_400_000` (≈ 10 years) — long
715
- * enough for root CAs.
716
- * - `validityGranularityMs = 1_000` (1 second) — RFC 5280 §4.1.2.5
717
- * floor on `notBefore` / `notAfter`.
718
- * - `nativeUnit = "second"` — what `x509Date()` actually encodes.
719
- *
720
- * @see US-208 — the consumer-side capability story.
721
- */
722
- getCapabilities(): PkiBackendCapabilities;
723
- generateKeyPairAndSignDER(options: GenerateKeyPairAndSignOptions): Promise<{
724
- certificateDer: Buffer;
725
- privateKey: PrivateKey;
726
- }>;
727
- /**
728
- * Generate a new RSA key pair, create an internal CSR, sign it
729
- * with this CA, and return the result as a PKCS#12 (PFX)
730
- * buffer bundling the certificate, private key, and CA chain.
731
- *
732
- * The private key is **never stored** by the CA — it exists only
733
- * in a temporary directory that is cleaned up after the operation.
734
- *
735
- * @param options - key generation, certificate, and PFX options
736
- * @returns the PFX as a `Buffer`
737
- */
738
- generateKeyPairAndSignPFX(options: GenerateKeyPairAndSignPFXOptions): Promise<Buffer>;
739
- /**
740
- * Revoke a DER-encoded certificate and regenerate the CRL.
741
- *
742
- * Extracts the serial number from the certificate, then
743
- * uses the stored cert file at `certs/<serial>.pem` for
744
- * revocation — avoiding temp-file PEM format mismatches.
745
- *
746
- * @param certDer - the certificate as a DER-encoded buffer
747
- * @param reason - CRL reason code
748
- * (default: `"keyCompromise"`)
749
- * @throws if the certificate's serial is not found in the CA
750
- */
751
- revokeCertificateDER(certDer: Buffer, reason?: string): Promise<void>;
752
- /**
753
- * Initialize the CA directory structure, generate the CA
754
- * private key and self-signed certificate if they do not
755
- * already exist.
756
- */
757
- initialize(): Promise<void>;
758
- /**
759
- * Initialize the CA directory structure and generate the
760
- * private key + CSR **without signing**.
761
- *
762
- * Use this when the CA certificate will be signed by an
763
- * external (third-party) root CA. After receiving the signed
764
- * certificate, call {@link installCACertificate} to complete
765
- * the setup.
766
- *
767
- * **Idempotent / restart-safe:**
768
- * - If the CA certificate exists and is valid → `{ status: "ready" }`
769
- * - If the CA certificate has expired → `{ status: "expired", csrPath, expiryDate }`
770
- * (a new CSR is generated, preserving the existing private key)
771
- * - If key + CSR exist but no cert (restart before install) →
772
- * `{ status: "pending", csrPath }` without regenerating
773
- * - Otherwise → generates key + CSR → `{ status: "created", csrPath }`
774
- *
775
- * @returns an {@link InitializeCSRResult} describing the CA state
776
- */
777
- initializeCSR(): Promise<InitializeCSRResult>;
778
- /**
779
- * Check whether the CA certificate needs renewal and, if so,
780
- * generate a new CSR for re-signing by the external root CA.
781
- *
782
- * Use this while the CA is running to detect upcoming expiry
783
- * **before** it actually expires. The existing private key is
784
- * preserved so previously issued certs remain valid.
785
- *
786
- * @param thresholdDays - number of days before expiry at which
787
- * to trigger renewal (default: 30)
788
- * @returns an {@link InitializeCSRResult} — `"expired"` if
789
- * renewal is needed, `"ready"` if the cert is still valid
790
- */
791
- renewCSR(thresholdDays?: number): Promise<InitializeCSRResult>;
792
- /**
793
- * Generate a CSR using the existing private key.
794
- * Must be called under {@link #withCaLock} — the lock is taken by the
795
- * public callers (`initializeCSR`, `renewCSR`), not here, so that
796
- * `initializeCSR` can hold one lock across key generation AND CSR
797
- * generation without the non-reentrant file lock deadlocking.
798
- * @internal
799
- */
800
- private _generateCSR;
801
- /**
802
- * Install an externally-signed CA certificate and generate
803
- * the initial CRL.
804
- *
805
- * Call this after {@link initializeCSR} once the external
806
- * root CA has signed the CSR.
807
- *
808
- * **Safety checks:**
809
- * - Verifies that the certificate's public key matches the
810
- * CA private key before installing.
811
- *
812
- * @param signedCertFile - path to the PEM-encoded signed
813
- * CA certificate (issued by the external root CA)
814
- * @returns an {@link InstallCACertificateResult} with
815
- * `status: "success"` or `status: "error"` and a `reason`
816
- */
817
- installCACertificate(signedCertFile: string): Promise<InstallCACertificateResult>;
818
- /**
819
- * Sign a CSR with CA extensions (`v3_ca`), producing a
820
- * subordinate CA certificate.
821
- *
822
- * Unlike {@link signCertificateRequest} which signs with
823
- * end-entity extensions (SANs, etc.), this method signs
824
- * with `basicConstraints = CA:TRUE` and `keyUsage =
825
- * keyCertSign, cRLSign`.
826
- *
827
- * @param certFile - output path for the signed CA cert (PEM)
828
- * @param csrFile - path to the subordinate CA's CSR
829
- * @param params - signing parameters
830
- */
831
- signCACertificateRequest(certFile: string, csrFile: string, params: {
832
- validity?: number;
833
- }): Promise<void>;
834
- /**
835
- * Rebuild the combined CA certificate + CRL file.
836
- *
837
- * This concatenates the CA certificate with the current
838
- * revocation list so that OpenSSL can verify certificates
839
- * with CRL checking enabled.
840
- */
841
- constructCACertificateWithCRL(): Promise<void>;
842
- /**
843
- * Append the CA certificate to a signed certificate file,
844
- * creating a PEM certificate chain.
845
- *
846
- * @param certificate - path to the certificate file to extend
847
- */
848
- constructCertificateChain(certificate: Filename): Promise<void>;
849
- /**
850
- * Create a self-signed certificate using OpenSSL.
851
- *
852
- * @param certificateFile - output path for the signed certificate
853
- * @param privateKey - path to the private key file
854
- * @param params - certificate parameters (subject, validity, SANs)
855
- */
856
- createSelfSignedCertificate(certificateFile: Filename, privateKey: Filename, params: Params): Promise<void>;
857
- /**
858
- * Regenerate `crl/revocation_list.{crl,der}` from the current database
859
- * state, without changing any certificate's status. Normally
860
- * unnecessary — `revokeCertificate` already regenerates the CRL as
861
- * part of revoking — but useful to force a refresh (e.g. after
862
- * switching a CA's `backend` between `"openssl"` and `"native"`).
863
- */
864
- regenerateCrl(): Promise<void>;
865
- /**
866
- * Revoke a certificate and regenerate the CRL.
867
- *
868
- * @param certificate - path to the certificate file to revoke
869
- * @param params - revocation parameters
870
- * @param params.reason - CRL reason code
871
- * (default `"keyCompromise"`)
872
- */
873
- revokeCertificate(certificate: Filename, params: Params): Promise<void>;
874
- /**
875
- * Sign a Certificate Signing Request (CSR) with this CA.
876
- *
877
- * The signed certificate is written to `certificate`, and the
878
- * CA certificate chain plus CRL are appended to form a
879
- * complete certificate chain.
880
- *
881
- * @param certificate - output path for the signed certificate
882
- * @param certificateSigningRequestFilename - path to the CSR
883
- * @param params1 - signing parameters (validity, dates, SANs)
884
- * @returns the path to the signed certificate
885
- */
886
- signCertificateRequest(certificate: Filename, certificateSigningRequestFilename: Filename, params1: Params): Promise<Filename>;
887
- /**
888
- * Check that `certificate` really was signed by this CA, and throw if it
889
- * was not.
890
- *
891
- * This used to do nothing: `openssl verify` crashes on Windows, so the
892
- * check was left as a placeholder. It no longer needs a subprocess -
893
- * `verifyCertificateSignature` does it in pure JS, the same way
894
- * {@link CertificateManager} already validates a chain - so the check
895
- * that `signCertificateRequest` always claimed to perform now actually
896
- * happens on every issuance, whichever backend did the signing.
897
- *
898
- * Only the leading certificate is examined: the file may be a chain,
899
- * and the rest of it is this CA's own certificate and its issuers.
900
- *
901
- * @param certificate - path to the certificate (or chain) to verify
902
- */
903
- verifyCertificate(certificate: Filename): Promise<void>;
904
- }
905
-
906
- /**
907
- * Everything a {@link CertificateAuthorityCore} delegates to a signing backend:
908
- * the operations that need the CA's private key, or that mutate the CA's
909
- * certificate database (`index.txt`, `serial`, `crlnumber`,
910
- * `certs/<SERIAL>.pem`, `crl/revocation_list.*`). Everything else — directory
911
- * layout, PEM/DER file concatenation, `index.txt` *reading*, URL validation,
912
- * passphrase handling, `initializeCSR`'s state machine — stays in
913
- * {@link CertificateAuthorityCore} and is shared by every backend.
914
- *
915
- * Two implementations exist. `OpenSslCaBackend` shells out to the `openssl`
916
- * CLI exactly as `CertificateAuthority` always has, and remains the default.
917
- * `NativeCaBackend` does the same work in pure JS, which is what allows a
918
- * CA key held by an HSM or KMS - one that only signs and never exposes key
919
- * material - to be used at all: the openssl CLI can only load a key from a
920
- * file. Both write the same on-disk database format, so an install can move
921
- * between them and external `openssl` tooling keeps working either way.
922
- */
923
- interface CaBackend {
924
- /**
925
- * Whether this backend can sign with an external {@link CaSigner} - an
926
- * HSM or KMS key that only signs and never exposes key material.
927
- * `false` for a backend that can only load a key from a file, so the
928
- * CA can refuse the combination up front instead of failing later.
929
- */
930
- readonly supportsExternalSigner: boolean;
931
- /**
932
- * Check whatever this backend needs before it can do any work, and
933
- * throw if it is missing. `CertificateAuthority` calls it before
934
- * delegating, so a missing prerequisite is reported once, up front,
935
- * rather than as a failure part-way through an operation.
936
- *
937
- * This exists because the requirement is the backend's, not the CA's:
938
- * the openssl backend needs the `openssl` executable on PATH, and the
939
- * native one needs nothing at all. Asking the CA to know that is what
940
- * made a `backend: "native"` CA refuse to issue a certificate on a
941
- * machine without openssl installed.
942
- */
943
- preflight(): Promise<void>;
944
- /**
945
- * Generate the CA's private key (if missing) and its certificate:
946
- * self-signed for a root CA, signed by `ca._issuerCA` for a subordinate.
947
- * Also produces the initial CRL. Called once, from
948
- * {@link CertificateAuthority.initialize}.
949
- */
950
- bootstrap(ca: CertificateAuthorityCore): Promise<void>;
951
- /**
952
- * Generate a CSR for the CA's own key (`[v3_ca_req]` profile) — used by
953
- * `initializeCSR`/`renewCSR` when the CA certificate is signed
954
- * externally.
955
- */
956
- generateCaCsr(ca: CertificateAuthorityCore, caRootDir: string, privateKeyFile: string, csrFile: string): Promise<void>;
957
- /**
958
- * Sign a subordinate CA's CSR with this CA's key (`[v3_ca]` profile).
959
- * Used by {@link CertificateAuthority.signCACertificateRequest}.
960
- */
961
- signSubordinateCsr(ca: CertificateAuthorityCore, csrFile: string, certFile: string, validityDays: number): Promise<void>;
962
- /**
963
- * Sign an end-entity CSR with this CA's key (`[usr_cert]` profile via
964
- * `openssl ca`) — the certificate database (`index.txt`, `serial`,
965
- * `certs/<SERIAL>.pem`) is updated as a side effect. Used by
966
- * {@link CertificateAuthority.signCertificateRequest}.
967
- *
968
- * `sanOverride` is the applicationUri/dns/ip the caller already
969
- * re-derived from the CSR itself (SANs are not copied by `openssl ca`
970
- * — see the comment at the call site), so the backend can render the
971
- * `subjectAltName` extension without re-parsing the CSR.
972
- */
973
- signEndEntityCsr(ca: CertificateAuthorityCore, certificate: string, csr: string, params: Params, sanOverride: Required<ProcessAltNamesParam>): Promise<void>;
974
- /**
975
- * Mark a certificate revoked in the database and regenerate the CRL.
976
- * Used by {@link CertificateAuthority.revokeCertificate}.
977
- */
978
- revoke(ca: CertificateAuthorityCore, certificate: string, reason: string): Promise<void>;
979
- /**
980
- * Regenerate `crl/revocation_list.{crl,der}` from the current database
981
- * state, without changing any certificate's status. Used after
982
- * {@link CertificateAuthority.installCACertificate} installs an
983
- * externally-signed CA certificate.
984
- */
985
- regenerateCrl(ca: CertificateAuthorityCore): Promise<void>;
986
- /**
987
- * Legacy CLI self-signed certificate creation (`openssl req` +
988
- * `openssl ca -selfsign`). Used by
989
- * {@link CertificateAuthority.createSelfSignedCertificate}.
990
- */
991
- createSelfSignedCertificate(ca: CertificateAuthorityCore, certificateFile: string, privateKeyFile: string, params: Params): Promise<void>;
992
- }
993
-
994
- /**
995
- * A native (pure-JS, no `openssl` child process) {@link CaBackend}: it
996
- * bootstraps a CA, signs end-entity and subordinate-CA requests, revokes,
997
- * and builds CRLs entirely through `node-opcua-crypto`'s signing
998
- * primitives and {@link CaDatabase}'s write path, so the resulting
999
- * `index.txt`/`serial`/`crlnumber`/`certs/` are the same on-disk format
1000
- * `openssl ca` produces and an install can move between backends.
1001
- *
1002
- * The signing key reaches every operation through
1003
- * `CertificateAuthority._getSigningKey()`, which yields either the on-disk
1004
- * key or an external `CaSigner`. Nothing below can tell the difference,
1005
- * which is the point: a CA whose key lives in an HSM never has a
1006
- * `private/cakey.pem` and never needs one.
1007
- *
1008
- * Two deliberate differences from the openssl backend, both improvements:
1009
- * a subordinate CA's certificate is recorded in the issuer's `index.txt`
1010
- * (`openssl x509 -CAserial` bumps the serial file but records nothing),
1011
- * and a subordinate's SAN is taken from its own CSR rather than being
1012
- * stamped with the issuer's.
1013
- */
1014
- declare class NativeCaBackend implements CaBackend {
1015
- #private;
1016
- /** Nothing to check: this backend spawns no process and needs no tool on PATH. */
1017
- /** Signing goes through `ca._getSigningKey()`, which may be an external signer. */
1018
- readonly supportsExternalSigner = true;
1019
- preflight(): Promise<void>;
1020
- /**
1021
- * Write a CSR for the CA's own key, the `[v3_ca_req]` equivalent. The
1022
- * key comes from the CA rather than from `privateKeyFile`: on a
1023
- * signer-backed CA that file does not exist.
1024
- */
1025
- generateCaCsr(ca: CertificateAuthorityCore, _caRootDir: string, _privateKeyFile: string, csrFile: string): Promise<void>;
1026
- bootstrap(ca: CertificateAuthorityCore): Promise<void>;
1027
- /** Sign a subordinate CA's request with this CA's key, the `[v3_ca]` equivalent. */
1028
- signSubordinateCsr(ca: CertificateAuthorityCore, csrFile: string, certFile: string, validityDays: number): Promise<void>;
1029
- /**
1030
- * Self-sign a certificate with a caller-supplied key file and record it
1031
- * in this CA's database: the native equivalent of `openssl req -new`
1032
- * followed by `openssl ca -selfsign`, which likewise applies the
1033
- * end-entity profile and updates `index.txt`.
1034
- */
1035
- createSelfSignedCertificate(ca: CertificateAuthorityCore, certificateFile: string, privateKeyFile: string, params: Params): Promise<void>;
1036
- signEndEntityCsr(ca: CertificateAuthorityCore, certificate: string, csr: string, params: Params, sanOverride: Required<ProcessAltNamesParam>): Promise<void>;
1037
- regenerateCrl(ca: CertificateAuthorityCore): Promise<void>;
1038
- revoke(ca: CertificateAuthorityCore, certificate: string, reason: string): Promise<void>;
1039
- }
1040
-
1041
- export { type CaBackend as C, type Filename as F, type GenerateKeyPairAndSignOptions as G, type InitializeCSRResult as I, type KeySize as K, NativeCaBackend as N, type Params as P, type SignCertificateOptions as S, type Thumbprint as T, CertificateAuthorityCore as a, type ProcessAltNamesParam as b, type CertificateAuthorityCoreOptions as c, type PrivateKeyPassphrase as d, type PrivateKeyProvider as e, type CreateSelfSignCertificateParam as f, type CertificateStatus as g, type CreateCertificateSigningRequestOptions as h, type CreateCertificateSigningRequestWithConfigOptions as i, type CreateSelfSignCertificateWithConfigParam as j, type GenerateKeyPairAndSignPFXOptions as k, type InstallCACertificateResult as l, type KeyLength as m, type PkiBackendCapabilities as n, type StartDateEndDateParam as o, adjustApplicationUri as p, adjustDate as q, isOpaqueSigner as r, quote as s, resolvePrivateKeyPassphrase as t, CaDatabase as u, type IssuedCertificateRecord as v, configurationFileTemplate as w, defaultSubject as x, escapeOpensslConfDoubleQuoted as y, renderCaConfig as z };