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,250 +1,10 @@
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
-
1
+ import { type CaSigner, type PrivateKey, Subject, type SubjectOptions } from "node-opcua-crypto";
2
+ import { type Filename, type KeySize, type Params, type PrivateKeyPassphrase } from "../../toolbox/index.js";
3
+ import type { CaBackend } from "./ca_backend.js";
4
+ import { type IssuedCertificateRecord } from "./ca_database.js";
245
5
  /** 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;
6
+ export declare const defaultSubject = "/C=FR/ST=IDF/L=Paris/O=Local NODE-OPCUA Certificate Authority/CN=NodeOPCUA-CA";
7
+ export declare const configurationFileTemplate: string;
248
8
  /**
249
9
  * Escape a value for use inside a double-quoted openssl config value.
250
10
  *
@@ -256,7 +16,7 @@ declare const configurationFileTemplate: string;
256
16
  * containing `$`, backticks, `#` or spaces is safe once double-quoted with
257
17
  * `\` and `"` escaped.
258
18
  */
259
- declare function escapeOpensslConfDoubleQuoted(value: string): string;
19
+ export declare function escapeOpensslConfDoubleQuoted(value: string): string;
260
20
  /**
261
21
  * Render the CA openssl configuration for `caRootDir`. The root folder is
262
22
  * emitted forward-slashed (openssl accepts that on every platform) and
@@ -264,7 +24,7 @@ declare function escapeOpensslConfDoubleQuoted(value: string): string;
264
24
  * config syntax would otherwise interpret (`$`, backticks, `#`, quotes) is
265
25
  * taken literally.
266
26
  */
267
- declare function renderCaConfig(caRootDir: string): string;
27
+ export declare function renderCaConfig(caRootDir: string): string;
268
28
  /**
269
29
  * Result of {@link CertificateAuthority.initializeCSR}.
270
30
  *
@@ -275,7 +35,7 @@ declare function renderCaConfig(caRootDir: string): string;
275
35
  * the configured threshold). A new CSR has been generated for renewal
276
36
  * while preserving the existing private key.
277
37
  */
278
- type InitializeCSRResult = {
38
+ export type InitializeCSRResult = {
279
39
  status: "ready";
280
40
  } | {
281
41
  status: "pending";
@@ -294,7 +54,7 @@ type InitializeCSRResult = {
294
54
  * - `"success"` — the certificate was installed and CRL generated.
295
55
  * - `"error"` — the certificate was rejected (see `reason`).
296
56
  */
297
- type InstallCACertificateResult = {
57
+ export type InstallCACertificateResult = {
298
58
  status: "success";
299
59
  } | {
300
60
  status: "error";
@@ -304,7 +64,7 @@ type InstallCACertificateResult = {
304
64
  /**
305
65
  * Options for creating a {@link CertificateAuthority}.
306
66
  */
307
- interface CertificateAuthorityCoreOptions {
67
+ export interface CertificateAuthorityCoreOptions {
308
68
  /** RSA key size for the CA private key. */
309
69
  keySize: KeySize;
310
70
  /** Filesystem path where the CA directory structure is stored. */
@@ -388,14 +148,42 @@ interface CertificateAuthorityCoreOptions {
388
148
  */
389
149
  signer?: CaSigner;
390
150
  }
391
-
151
+ /**
152
+ * An OpenSSL-based Certificate Authority (CA) that can create,
153
+ * sign, and revoke X.509 certificates.
154
+ *
155
+ * The CA maintains a standard OpenSSL directory layout under
156
+ * {@link CertificateAuthority.rootDir | rootDir}:
157
+ *
158
+ * ```
159
+ * <location>/
160
+ * ├── conf/ OpenSSL configuration
161
+ * ├── private/ CA private key (cakey.pem)
162
+ * ├── public/ CA certificate (cacert.pem)
163
+ * ├── certs/ Signed certificates
164
+ * ├── crl/ Revocation lists
165
+ * ├── serial Next serial number
166
+ * ├── crlnumber Next CRL number
167
+ * └── index.txt Certificate database
168
+ * ```
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * const ca = new CertificateAuthority({
173
+ * keySize: 2048,
174
+ * location: "/var/pki/CA"
175
+ * });
176
+ * await ca.initialize();
177
+ * ```
178
+ */
179
+ export type { IssuedCertificateRecord };
392
180
  /**
393
181
  * Options for {@link CertificateAuthority.signCertificateRequestFromDER}.
394
182
  *
395
183
  * All fields are optional. When provided, they override the
396
184
  * corresponding values from the CSR.
397
185
  */
398
- interface SignCertificateOptions {
186
+ export interface SignCertificateOptions {
399
187
  /** Certificate validity in days (default: 365). */
400
188
  validity?: number;
401
189
  /**
@@ -427,7 +215,7 @@ interface SignCertificateOptions {
427
215
  *
428
216
  * @see CertificateAuthority.getCapabilities
429
217
  */
430
- interface PkiBackendCapabilities {
218
+ export interface PkiBackendCapabilities {
431
219
  /** Smallest validity this backend can issue, in milliseconds. */
432
220
  minValidityMs: number;
433
221
  /** Largest validity this backend will issue, in milliseconds. */
@@ -447,7 +235,7 @@ interface PkiBackendCapabilities {
447
235
  /**
448
236
  * Options for {@link CertificateAuthority.generateKeyPairAndSignDER}.
449
237
  */
450
- interface GenerateKeyPairAndSignOptions {
238
+ export interface GenerateKeyPairAndSignOptions {
451
239
  /** OPC UA application URI (required). */
452
240
  applicationUri: string;
453
241
  /** X.500 subject for the certificate (e.g. "CN=MyApp"). */
@@ -476,14 +264,14 @@ interface GenerateKeyPairAndSignOptions {
476
264
  * Extends the DER options with an optional `passphrase` to protect
477
265
  * the PFX bundle.
478
266
  */
479
- interface GenerateKeyPairAndSignPFXOptions extends GenerateKeyPairAndSignOptions {
267
+ export interface GenerateKeyPairAndSignPFXOptions extends GenerateKeyPairAndSignOptions {
480
268
  /**
481
269
  * Passphrase to protect the PFX file.
482
270
  * If omitted, the PFX is created without a password.
483
271
  */
484
272
  passphrase?: string;
485
273
  }
486
- declare class CertificateAuthorityCore {
274
+ export declare class CertificateAuthorityCore {
487
275
  #private;
488
276
  /** RSA key size used when generating the CA private key. */
489
277
  readonly keySize: KeySize;
@@ -902,140 +690,3 @@ declare class CertificateAuthorityCore {
902
690
  */
903
691
  verifyCertificate(certificate: Filename): Promise<void>;
904
692
  }
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 };