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.
- package/bin/install_prerequisite.ts +1 -1
- package/bin/pki.ts +1 -1
- package/dist/bin/install_prerequisite.d.ts +2 -0
- package/dist/bin/install_prerequisite.js +6 -0
- package/dist/bin/install_prerequisite.js.map +1 -0
- package/dist/bin/pki.d.ts +2 -0
- package/dist/bin/pki.js +4 -0
- package/dist/bin/pki.js.map +1 -0
- package/dist/lib/ca/backends/native_ca_backend.d.ts +49 -0
- package/dist/lib/ca/backends/native_ca_backend.js +365 -0
- package/dist/lib/ca/backends/native_ca_backend.js.map +1 -0
- package/dist/lib/ca/backends/openssl_ca_backend.d.ts +47 -0
- package/dist/lib/ca/backends/openssl_ca_backend.js +398 -0
- package/dist/lib/ca/backends/openssl_ca_backend.js.map +1 -0
- package/dist/lib/ca/certificate_authority.d.ts +62 -0
- package/dist/lib/ca/certificate_authority.js +91 -0
- package/dist/lib/ca/certificate_authority.js.map +1 -0
- package/dist/lib/ca/core/ca_backend.d.ts +89 -0
- package/dist/lib/ca/core/ca_backend.js +24 -0
- package/dist/lib/ca/core/ca_backend.js.map +1 -0
- package/dist/lib/ca/core/ca_database.d.ts +91 -0
- package/dist/lib/ca/core/ca_database.js +267 -0
- package/dist/lib/ca/core/ca_database.js.map +1 -0
- package/dist/{core-BwqSJPHc.d.mts → lib/ca/core/certificate_authority_core.d.ts} +45 -394
- package/dist/lib/ca/core/certificate_authority_core.js +1300 -0
- package/dist/lib/ca/core/certificate_authority_core.js.map +1 -0
- package/dist/lib/ca/core/index.d.ts +17 -0
- package/dist/lib/ca/core/index.js +25 -0
- package/dist/lib/ca/core/index.js.map +1 -0
- package/dist/lib/ca/crypto_create_CA.d.ts +1 -0
- package/dist/lib/ca/crypto_create_CA.js +821 -0
- package/dist/lib/ca/crypto_create_CA.js.map +1 -0
- package/dist/lib/ca/index.d.ts +1 -0
- package/dist/lib/ca/index.js +2 -0
- package/dist/lib/ca/index.js.map +1 -0
- package/dist/lib/ca/templates/ca_config_template.cnf.d.ts +2 -0
- package/dist/lib/ca/templates/ca_config_template.cnf.js +170 -0
- package/dist/lib/ca/templates/ca_config_template.cnf.js.map +1 -0
- package/dist/lib/core.d.ts +33 -0
- package/dist/lib/core.js +56 -0
- package/dist/lib/core.js.map +1 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.js +37 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/misc/applicationurn.d.ts +1 -0
- package/dist/lib/misc/applicationurn.js +40 -0
- package/dist/lib/misc/applicationurn.js.map +1 -0
- package/dist/lib/misc/hostname.d.ts +8 -0
- package/dist/lib/misc/hostname.js +82 -0
- package/dist/lib/misc/hostname.js.map +1 -0
- package/dist/lib/misc/subject.d.ts +2 -0
- package/dist/lib/misc/subject.js +2 -0
- package/dist/lib/misc/subject.js.map +1 -0
- package/dist/{index.d.ts → lib/pki/certificate_manager.d.ts} +24 -248
- package/dist/lib/pki/certificate_manager.js +2302 -0
- package/dist/lib/pki/certificate_manager.js.map +1 -0
- package/dist/lib/pki/templates/simple_config_template.cnf.d.ts +2 -0
- package/dist/lib/pki/templates/simple_config_template.cnf.js +74 -0
- package/dist/lib/pki/templates/simple_config_template.cnf.js.map +1 -0
- package/dist/lib/pki/toolbox_pfx.d.ts +127 -0
- package/dist/lib/pki/toolbox_pfx.js +248 -0
- package/dist/lib/pki/toolbox_pfx.js.map +1 -0
- package/dist/lib/toolbox/common.d.ts +150 -0
- package/dist/lib/toolbox/common.js +82 -0
- package/dist/lib/toolbox/common.js.map +1 -0
- package/dist/lib/toolbox/common2.d.ts +25 -0
- package/dist/lib/toolbox/common2.js +97 -0
- package/dist/lib/toolbox/common2.js.map +1 -0
- package/dist/lib/toolbox/config.d.ts +5 -0
- package/dist/lib/toolbox/config.js +28 -0
- package/dist/lib/toolbox/config.js.map +1 -0
- package/dist/lib/toolbox/debug.d.ts +5 -0
- package/dist/lib/toolbox/debug.js +35 -0
- package/dist/lib/toolbox/debug.js.map +1 -0
- package/dist/lib/toolbox/display.d.ts +4 -0
- package/dist/lib/toolbox/display.js +56 -0
- package/dist/lib/toolbox/display.js.map +1 -0
- package/dist/lib/toolbox/index.d.ts +5 -0
- package/dist/lib/toolbox/index.js +28 -0
- package/dist/lib/toolbox/index.js.map +1 -0
- package/dist/lib/toolbox/with_openssl/_create_random_file.d.ts +4 -0
- package/dist/lib/toolbox/with_openssl/_create_random_file.js +50 -0
- package/dist/lib/toolbox/with_openssl/_create_random_file.js.map +1 -0
- package/dist/lib/toolbox/with_openssl/_env.d.ts +58 -0
- package/dist/lib/toolbox/with_openssl/_env.js +126 -0
- package/dist/lib/toolbox/with_openssl/_env.js.map +1 -0
- package/dist/lib/toolbox/with_openssl/create_certificate_signing_request.d.ts +5 -0
- package/dist/lib/toolbox/with_openssl/create_certificate_signing_request.js +72 -0
- package/dist/lib/toolbox/with_openssl/create_certificate_signing_request.js.map +1 -0
- package/dist/lib/toolbox/with_openssl/create_private_key.d.ts +5 -0
- package/dist/lib/toolbox/with_openssl/create_private_key.js +92 -0
- package/dist/lib/toolbox/with_openssl/create_private_key.js.map +1 -0
- package/dist/lib/toolbox/with_openssl/create_self_signed_certificate.d.ts +5 -0
- package/dist/lib/toolbox/with_openssl/create_self_signed_certificate.js +135 -0
- package/dist/lib/toolbox/with_openssl/create_self_signed_certificate.js.map +1 -0
- package/dist/lib/toolbox/with_openssl/execute_openssl.d.ts +67 -0
- package/dist/lib/toolbox/with_openssl/execute_openssl.js +246 -0
- package/dist/lib/toolbox/with_openssl/execute_openssl.js.map +1 -0
- package/dist/lib/toolbox/with_openssl/index.d.ts +5 -0
- package/dist/lib/toolbox/with_openssl/index.js +30 -0
- package/dist/lib/toolbox/with_openssl/index.js.map +1 -0
- package/dist/lib/toolbox/with_openssl/install_prerequisite.d.ts +7 -0
- package/dist/lib/toolbox/with_openssl/install_prerequisite.js +358 -0
- package/dist/lib/toolbox/with_openssl/install_prerequisite.js.map +1 -0
- package/dist/lib/toolbox/with_openssl/toolbox.d.ts +53 -0
- package/dist/lib/toolbox/with_openssl/toolbox.js +190 -0
- package/dist/lib/toolbox/with_openssl/toolbox.js.map +1 -0
- package/dist/lib/toolbox/without_openssl/create_certificate_signing_request.d.ts +5 -0
- package/dist/lib/toolbox/without_openssl/create_certificate_signing_request.js +69 -0
- package/dist/lib/toolbox/without_openssl/create_certificate_signing_request.js.map +1 -0
- package/dist/lib/toolbox/without_openssl/create_self_signed_certificate.d.ts +3 -0
- package/dist/lib/toolbox/without_openssl/create_self_signed_certificate.js +78 -0
- package/dist/lib/toolbox/without_openssl/create_self_signed_certificate.js.map +1 -0
- package/dist/lib/toolbox/without_openssl/index.d.ts +2 -0
- package/dist/lib/toolbox/without_openssl/index.js +25 -0
- package/dist/lib/toolbox/without_openssl/index.js.map +1 -0
- package/package.json +11 -30
- package/dist/bin/install_prerequisite.mjs +0 -18
- package/dist/bin/install_prerequisite.mjs.map +0 -1
- package/dist/bin/pki.mjs +0 -5932
- package/dist/bin/pki.mjs.map +0 -1
- package/dist/chunk-EQ4DGI4M.mjs +0 -1917
- package/dist/chunk-EQ4DGI4M.mjs.map +0 -1
- package/dist/chunk-GCHH54PS.mjs +0 -30
- package/dist/chunk-GCHH54PS.mjs.map +0 -1
- package/dist/core-BwqSJPHc.d.ts +0 -1041
- package/dist/core.d.mts +0 -2
- package/dist/core.d.ts +0 -2
- package/dist/core.js +0 -1902
- package/dist/core.js.map +0 -1
- package/dist/core.mjs +0 -21
- package/dist/core.mjs.map +0 -1
- package/dist/index.d.mts +0 -1003
- package/dist/index.js +0 -5009
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -3145
- package/dist/index.mjs.map +0 -1
package/dist/index.d.mts
DELETED
|
@@ -1,1003 +0,0 @@
|
|
|
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';
|
|
5
|
-
import { EventEmitter } from 'node:events';
|
|
6
|
-
|
|
7
|
-
/**
|
|
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.
|
|
13
|
-
*/
|
|
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>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** openssl argv entries plus the env they need; merge `env` into `ExecuteOptions.env`. */
|
|
29
|
-
interface OpensslPassArg {
|
|
30
|
-
args: string[];
|
|
31
|
-
env: NodeJS.ProcessEnv;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* return path to the openssl executable
|
|
37
|
-
*/
|
|
38
|
-
declare function install_prerequisite(): Promise<string>;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Options for {@link CertificateAuthority}: the core's, except that the
|
|
42
|
-
* backend is named rather than supplied.
|
|
43
|
-
*/
|
|
44
|
-
interface CertificateAuthorityOptions extends Omit<CertificateAuthorityCoreOptions, "backend"> {
|
|
45
|
-
/**
|
|
46
|
-
* Signing backend to use.
|
|
47
|
-
*
|
|
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.
|
|
52
|
-
*
|
|
53
|
-
* Setting `signer` implies `"native"`, since the openssl CLI can only
|
|
54
|
-
* load a key from a file.
|
|
55
|
-
*
|
|
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.
|
|
60
|
-
*/
|
|
61
|
-
backend?: "openssl" | "native";
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* A Certificate Authority with a backend chosen for you.
|
|
65
|
-
*
|
|
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.
|
|
71
|
-
*/
|
|
72
|
-
declare class CertificateAuthority extends CertificateAuthorityCore {
|
|
73
|
-
constructor(options: CertificateAuthorityOptions);
|
|
74
|
-
/**
|
|
75
|
-
* @internal `-passin env:` argv + env for an openssl call that loads
|
|
76
|
-
* this CA's key (always emitted, empty when none).
|
|
77
|
-
*
|
|
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.
|
|
81
|
-
*/
|
|
82
|
-
_opensslPassin(): Promise<OpensslPassArg>;
|
|
83
|
-
/**
|
|
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.
|
|
96
|
-
*/
|
|
97
|
-
_wireRevocationEnvVars(): void;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Identifies which PKI sub-store a certificate event originated from.
|
|
102
|
-
*/
|
|
103
|
-
type CertificateStore = "trusted" | "rejected" | "issuersCerts";
|
|
104
|
-
/**
|
|
105
|
-
* Identifies which PKI sub-store a CRL event originated from.
|
|
106
|
-
*/
|
|
107
|
-
type CrlStore = "crl" | "issuersCrl";
|
|
108
|
-
/**
|
|
109
|
-
* Events emitted by {@link CertificateManager} when the
|
|
110
|
-
* file-system watchers detect certificate or CRL changes.
|
|
111
|
-
*/
|
|
112
|
-
interface CertificateManagerEvents {
|
|
113
|
-
/** A certificate file was added to a store. */
|
|
114
|
-
certificateAdded: (event: {
|
|
115
|
-
store: CertificateStore;
|
|
116
|
-
certificate: Certificate;
|
|
117
|
-
fingerprint: string;
|
|
118
|
-
filename: string;
|
|
119
|
-
}) => void;
|
|
120
|
-
/** A certificate file was removed from a store. */
|
|
121
|
-
certificateRemoved: (event: {
|
|
122
|
-
store: CertificateStore;
|
|
123
|
-
fingerprint: string;
|
|
124
|
-
filename: string;
|
|
125
|
-
}) => void;
|
|
126
|
-
/** A certificate file was modified in a store. */
|
|
127
|
-
certificateChange: (event: {
|
|
128
|
-
store: CertificateStore;
|
|
129
|
-
certificate: Certificate;
|
|
130
|
-
fingerprint: string;
|
|
131
|
-
filename: string;
|
|
132
|
-
}) => void;
|
|
133
|
-
/** A CRL file was added. */
|
|
134
|
-
crlAdded: (event: {
|
|
135
|
-
store: CrlStore;
|
|
136
|
-
filename: string;
|
|
137
|
-
}) => void;
|
|
138
|
-
/** A CRL file was removed. */
|
|
139
|
-
crlRemoved: (event: {
|
|
140
|
-
store: CrlStore;
|
|
141
|
-
filename: string;
|
|
142
|
-
}) => void;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Options controlling certificate validation in
|
|
146
|
-
* {@link CertificateManager.addTrustedCertificateFromChain}.
|
|
147
|
-
*
|
|
148
|
-
* By default all checks are **strict** (secure). Set individual
|
|
149
|
-
* flags to `true` only in test/development environments.
|
|
150
|
-
*/
|
|
151
|
-
interface AddCertificateValidationOptions {
|
|
152
|
-
/**
|
|
153
|
-
* Accept certificates whose validity period has expired
|
|
154
|
-
* or is not yet active.
|
|
155
|
-
* @defaultValue false
|
|
156
|
-
*/
|
|
157
|
-
acceptExpiredCertificate?: boolean;
|
|
158
|
-
/**
|
|
159
|
-
* Accept certificates that have been revoked by their
|
|
160
|
-
* issuer's CRL. When `false` (the default), a revoked
|
|
161
|
-
* certificate is rejected with `BadCertificateRevoked`.
|
|
162
|
-
* @defaultValue false
|
|
163
|
-
*/
|
|
164
|
-
acceptRevokedCertificate?: boolean;
|
|
165
|
-
/**
|
|
166
|
-
* Do not fail when a CRL is missing for an issuer in the
|
|
167
|
-
* chain. When `false` (the default), a missing CRL causes
|
|
168
|
-
* `BadCertificateRevocationUnknown`.
|
|
169
|
-
* @defaultValue false
|
|
170
|
-
*/
|
|
171
|
-
ignoreMissingRevocationList?: boolean;
|
|
172
|
-
/**
|
|
173
|
-
* Maximum depth of the certificate chain (leaf + issuers).
|
|
174
|
-
* The leaf certificate counts as depth 1.
|
|
175
|
-
* @defaultValue 5
|
|
176
|
-
*/
|
|
177
|
-
maxChainLength?: number;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Options for creating a {@link CertificateManager}.
|
|
181
|
-
*/
|
|
182
|
-
interface CertificateManagerOptions {
|
|
183
|
-
/**
|
|
184
|
-
* RSA key size for generated private keys.
|
|
185
|
-
* @defaultValue 2048
|
|
186
|
-
*/
|
|
187
|
-
keySize?: KeySize;
|
|
188
|
-
/** Filesystem path where the PKI directory structure is stored. */
|
|
189
|
-
location: string;
|
|
190
|
-
/**
|
|
191
|
-
* Validation options applied by
|
|
192
|
-
* {@link CertificateManager.addTrustedCertificateFromChain}.
|
|
193
|
-
*
|
|
194
|
-
* Defaults are secure — all checks enabled.
|
|
195
|
-
*/
|
|
196
|
-
addCertificateValidationOptions?: AddCertificateValidationOptions;
|
|
197
|
-
/**
|
|
198
|
-
* When `true`, the CertificateManager will **not** start
|
|
199
|
-
* chokidar file-system watchers on the PKI folders.
|
|
200
|
-
*
|
|
201
|
-
* The initial file-system scan still runs so the in-memory
|
|
202
|
-
* indexes are populated, but live change detection is
|
|
203
|
-
* disabled. This is useful in test / CI environments where
|
|
204
|
-
* many CertificateManager instances are created in parallel
|
|
205
|
-
* and the accumulated `fs.watch` handles exhaust the libuv
|
|
206
|
-
* thread-pool, causing event-loop starvation.
|
|
207
|
-
*
|
|
208
|
-
* @defaultValue false
|
|
209
|
-
*/
|
|
210
|
-
disableFileWatchers?: boolean;
|
|
211
|
-
/**
|
|
212
|
-
* Encrypt the private key at rest with this passphrase (opt-in,
|
|
213
|
-
* default off). When set:
|
|
214
|
-
* - a freshly generated key is written as encrypted PKCS#8;
|
|
215
|
-
* - an existing *plaintext* key is re-encrypted in place by
|
|
216
|
-
* {@link CertificateManager.initialize} (atomic rename, same as
|
|
217
|
-
* {@link CertificateManager.reencryptPrivateKey}), so enabling the
|
|
218
|
-
* option on an existing install never leaves the key in cleartext;
|
|
219
|
-
* - an existing encrypted key requires the same passphrase — a
|
|
220
|
-
* mismatch, or an encrypted key with no passphrase configured, fails
|
|
221
|
-
* `initialize()` closed with `PrivateKeyPassphraseRequiredError`.
|
|
222
|
-
*
|
|
223
|
-
* A function is called at most once per `CertificateManager` instance
|
|
224
|
-
* (the decrypted key is cached in memory for the instance's lifetime,
|
|
225
|
-
* see {@link CertificateManager.getPrivateKey}). Never logged.
|
|
226
|
-
*
|
|
227
|
-
* Existing consumers that read `own/private/private_key.pem` directly
|
|
228
|
-
* (e.g. node-opcua's `OPCUAServer`, or `createPFX` without its
|
|
229
|
-
* `privateKeyPassphrase` option) still expect a plaintext key — do not
|
|
230
|
-
* enable this unless every reader of that file goes through
|
|
231
|
-
* {@link CertificateManager.getPrivateKey} or is given the passphrase.
|
|
232
|
-
*/
|
|
233
|
-
privateKeyPassphrase?: PrivateKeyPassphrase;
|
|
234
|
-
/**
|
|
235
|
-
* Source the private key from somewhere other than
|
|
236
|
-
* `own/private/private_key.pem` (an HSM, a KMS, ...). When set, it
|
|
237
|
-
* overrides disk entirely for every operation that needs the private
|
|
238
|
-
* key — the on-disk file is not read, and `privateKeyPassphrase` is
|
|
239
|
-
* ignored.
|
|
240
|
-
*/
|
|
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;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Parameters for {@link createSelfSignedCertificate}.
|
|
268
|
-
* All fields from {@link CreateSelfSignCertificateParam} are required.
|
|
269
|
-
*/
|
|
270
|
-
interface CreateSelfSignCertificateParam1 extends CreateSelfSignCertificateParam {
|
|
271
|
-
/**
|
|
272
|
-
* Output path for the certificate.
|
|
273
|
-
* @defaultValue `"own/certs/self_signed_certificate.pem"`
|
|
274
|
-
*/
|
|
275
|
-
outputFile?: Filename;
|
|
276
|
-
/** X.500 subject for the certificate. */
|
|
277
|
-
subject: SubjectOptions | string;
|
|
278
|
-
/** OPC UA application URI for the SAN extension. */
|
|
279
|
-
applicationUri: string;
|
|
280
|
-
/** DNS host names to include in the SAN extension. */
|
|
281
|
-
dns: string[];
|
|
282
|
-
/** Certificate "Not Before" date. */
|
|
283
|
-
startDate: Date;
|
|
284
|
-
/** Number of days the certificate is valid. */
|
|
285
|
-
validity: number;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Options to fine-tune certificate verification behaviour.
|
|
289
|
-
* Passed to {@link CertificateManager.verifyCertificate}.
|
|
290
|
-
*
|
|
291
|
-
* Without any options, `verifyCertificate` is **strict**: only
|
|
292
|
-
* certificates that are explicitly present in the trusted store
|
|
293
|
-
* will return {@link VerificationStatus.Good}. Unknown or
|
|
294
|
-
* rejected certificates return
|
|
295
|
-
* {@link VerificationStatus.BadCertificateUntrusted} even when
|
|
296
|
-
* their issuer chain is valid.
|
|
297
|
-
*
|
|
298
|
-
* Set {@link acceptCertificateWithValidIssuerChain} to `true`
|
|
299
|
-
* to accept certificates whose issuer chain validates against
|
|
300
|
-
* a trusted CA — even if the leaf certificate itself is not
|
|
301
|
-
* in the trusted store.
|
|
302
|
-
*/
|
|
303
|
-
interface VerifyCertificateOptions {
|
|
304
|
-
/** Accept certificates whose "Not After" date has passed. */
|
|
305
|
-
acceptOutdatedCertificate?: boolean;
|
|
306
|
-
/** Accept issuer certificates whose "Not After" date has passed. */
|
|
307
|
-
acceptOutDatedIssuerCertificate?: boolean;
|
|
308
|
-
/** Do not fail when a CRL is missing for an issuer. */
|
|
309
|
-
ignoreMissingRevocationList?: boolean;
|
|
310
|
-
/** Accept certificates whose "Not Before" date is in the future. */
|
|
311
|
-
acceptPendingCertificate?: boolean;
|
|
312
|
-
/**
|
|
313
|
-
* Accept a certificate that is not in the trusted store when
|
|
314
|
-
* its issuer (CA) certificate is trusted, the signature is
|
|
315
|
-
* valid, and the certificate does not appear in the CRL.
|
|
316
|
-
*
|
|
317
|
-
* When `false` (the default), only certificates explicitly
|
|
318
|
-
* placed in the trusted store are accepted — this is the
|
|
319
|
-
* same behaviour as {@link CertificateManager.isCertificateTrusted}.
|
|
320
|
-
*
|
|
321
|
-
* @defaultValue false
|
|
322
|
-
*/
|
|
323
|
-
acceptCertificateWithValidIssuerChain?: boolean;
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* OPC UA certificate verification status codes.
|
|
327
|
-
*
|
|
328
|
-
* These mirror the OPC UA `StatusCode` values for certificate
|
|
329
|
-
* validation results.
|
|
330
|
-
*/
|
|
331
|
-
declare enum VerificationStatus {
|
|
332
|
-
/** The certificate provided as a parameter is not valid. */
|
|
333
|
-
BadCertificateInvalid = "BadCertificateInvalid",
|
|
334
|
-
/** An error occurred verifying security. */
|
|
335
|
-
BadSecurityChecksFailed = "BadSecurityChecksFailed",
|
|
336
|
-
/** The certificate does not meet the requirements of the security policy. */
|
|
337
|
-
BadCertificatePolicyCheckFailed = "BadCertificatePolicyCheckFailed",
|
|
338
|
-
/** The certificate has expired or is not yet valid. */
|
|
339
|
-
BadCertificateTimeInvalid = "BadCertificateTimeInvalid",
|
|
340
|
-
/** An issuer certificate has expired or is not yet valid. */
|
|
341
|
-
BadCertificateIssuerTimeInvalid = "BadCertificateIssuerTimeInvalid",
|
|
342
|
-
/** The HostName used to connect to a server does not match a HostName in the certificate. */
|
|
343
|
-
BadCertificateHostNameInvalid = "BadCertificateHostNameInvalid",
|
|
344
|
-
/** The URI specified in the ApplicationDescription does not match the URI in the certificate. */
|
|
345
|
-
BadCertificateUriInvalid = "BadCertificateUriInvalid",
|
|
346
|
-
/** The certificate may not be used for the requested operation. */
|
|
347
|
-
BadCertificateUseNotAllowed = "BadCertificateUseNotAllowed",
|
|
348
|
-
/** The issuer certificate may not be used for the requested operation. */
|
|
349
|
-
BadCertificateIssuerUseNotAllowed = "BadCertificateIssuerUseNotAllowed",
|
|
350
|
-
/** The certificate is not trusted. */
|
|
351
|
-
BadCertificateUntrusted = "BadCertificateUntrusted",
|
|
352
|
-
/** It was not possible to determine if the certificate has been revoked. */
|
|
353
|
-
BadCertificateRevocationUnknown = "BadCertificateRevocationUnknown",
|
|
354
|
-
/** It was not possible to determine if the issuer certificate has been revoked. */
|
|
355
|
-
BadCertificateIssuerRevocationUnknown = "BadCertificateIssuerRevocationUnknown",
|
|
356
|
-
/** The certificate has been revoked. */
|
|
357
|
-
BadCertificateRevoked = "BadCertificateRevoked",
|
|
358
|
-
/** The issuer certificate has been revoked. */
|
|
359
|
-
BadCertificateIssuerRevoked = "BadCertificateIssuerRevoked",
|
|
360
|
-
/** The certificate chain is incomplete. */
|
|
361
|
-
BadCertificateChainIncomplete = "BadCertificateChainIncomplete",
|
|
362
|
-
/** Validation OK. */
|
|
363
|
-
Good = "Good"
|
|
364
|
-
}
|
|
365
|
-
declare function coerceCertificateChain(certificate: Certificate | Certificate[]): Certificate[];
|
|
366
|
-
declare function makeFingerprint(certificate: Certificate | Certificate[] | CertificateRevocationList): string;
|
|
367
|
-
declare function toFilenameLabel(commonName: string): string;
|
|
368
|
-
declare function safeStoreJoin(folder: string, filename: string): string;
|
|
369
|
-
/**
|
|
370
|
-
* Check if the provided certificate acts as an issuer (CA)
|
|
371
|
-
* @param certificate - the DER-encoded certificate
|
|
372
|
-
* @returns true if the certificate has CA basicConstraints or keyCertSign keyUsage
|
|
373
|
-
*/
|
|
374
|
-
declare function isIssuer(certificate: Certificate): boolean;
|
|
375
|
-
/**
|
|
376
|
-
* Check if the provided certificate acts as an intermediate issuer.
|
|
377
|
-
* An intermediate issuer is a CA certificate that is not a root CA (not self-signed).
|
|
378
|
-
* @param certificate - the DER-encoded certificate
|
|
379
|
-
* @returns true if the certificate is a CA and is not self-signed
|
|
380
|
-
*/
|
|
381
|
-
declare function isIntermediateIssuer(certificate: Certificate): boolean;
|
|
382
|
-
/**
|
|
383
|
-
* Check if the provided certificate acts as a root issuer.
|
|
384
|
-
* A root issuer is a CA certificate that is self-signed.
|
|
385
|
-
* @param certificate - the DER-encoded certificate
|
|
386
|
-
* @returns true if the certificate is a CA and is self-signed
|
|
387
|
-
*/
|
|
388
|
-
declare function isRootIssuer(certificate: Certificate): boolean;
|
|
389
|
-
/**
|
|
390
|
-
* Find the issuer certificate for a given certificate within
|
|
391
|
-
* a provided certificate chain.
|
|
392
|
-
*
|
|
393
|
-
* @param certificate - the DER-encoded certificate whose issuer to find
|
|
394
|
-
* @param chain - candidate issuer certificates to search
|
|
395
|
-
* @returns the matching issuer certificate, or `null` if not found
|
|
396
|
-
*/
|
|
397
|
-
declare function findIssuerCertificateInChain(certificate: Certificate | Certificate[], chain: Certificate[]): Certificate | null;
|
|
398
|
-
/**
|
|
399
|
-
* Lifecycle state of a {@link CertificateManager} instance.
|
|
400
|
-
*/
|
|
401
|
-
declare enum CertificateManagerState {
|
|
402
|
-
Uninitialized = 0,
|
|
403
|
-
Initializing = 1,
|
|
404
|
-
Initialized = 2,
|
|
405
|
-
Disposing = 3,
|
|
406
|
-
Disposed = 4
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Manages a GDS-compliant PKI directory structure for an OPC UA
|
|
410
|
-
* application.
|
|
411
|
-
*
|
|
412
|
-
* The PKI store layout follows the OPC UA specification:
|
|
413
|
-
*
|
|
414
|
-
* ```
|
|
415
|
-
* <location>/
|
|
416
|
-
* ├── own/
|
|
417
|
-
* │ ├── certs/ Own certificate(s)
|
|
418
|
-
* │ └── private/ Own private key
|
|
419
|
-
* ├── trusted/
|
|
420
|
-
* │ ├── certs/ Trusted peer certificates
|
|
421
|
-
* │ └── crl/ CRLs for trusted certs
|
|
422
|
-
* ├── rejected/ Untrusted / rejected certificates
|
|
423
|
-
* └── issuers/
|
|
424
|
-
* ├── certs/ CA (issuer) certificates
|
|
425
|
-
* └── crl/ CRLs for issuer certificates
|
|
426
|
-
* ```
|
|
427
|
-
*
|
|
428
|
-
* File-system watchers keep the in-memory indexes in sync with
|
|
429
|
-
* on-disk changes. Call {@link dispose} when the instance is no
|
|
430
|
-
* longer needed to release watchers and allow the process to
|
|
431
|
-
* exit cleanly.
|
|
432
|
-
*
|
|
433
|
-
* ## Environment Variables
|
|
434
|
-
*
|
|
435
|
-
* - **`OPCUA_PKI_USE_POLLING`** — set to `"true"` to use
|
|
436
|
-
* polling-based file watching instead of native OS events.
|
|
437
|
-
* Useful for NFS, CIFS, Docker volumes, or other remote /
|
|
438
|
-
* virtual file systems where native events are unreliable.
|
|
439
|
-
*
|
|
440
|
-
* - **`OPCUA_PKI_POLLING_INTERVAL`** — polling interval in
|
|
441
|
-
* milliseconds (only effective when polling is enabled).
|
|
442
|
-
* Clamped to the range [100, 600 000]. Defaults to
|
|
443
|
-
* {@link folderPollingInterval} (5 000 ms).
|
|
444
|
-
*
|
|
445
|
-
* @example
|
|
446
|
-
* ```ts
|
|
447
|
-
* const cm = new CertificateManager({ location: "/var/pki" });
|
|
448
|
-
* await cm.initialize();
|
|
449
|
-
* const status = await cm.verifyCertificate(cert);
|
|
450
|
-
* await cm.dispose();
|
|
451
|
-
* ```
|
|
452
|
-
*/
|
|
453
|
-
/**
|
|
454
|
-
* Status codes returned by {@link CertificateManager.completeCertificateChain}.
|
|
455
|
-
*/
|
|
456
|
-
declare enum ChainCompletionStatus {
|
|
457
|
-
/** The chain already reached a self-signed root — no action was needed. */
|
|
458
|
-
AlreadyComplete = "AlreadyComplete",
|
|
459
|
-
/** One or more issuer certificates were successfully appended. */
|
|
460
|
-
ChainCompleted = "ChainCompleted",
|
|
461
|
-
/** The issuer for the last certificate in the chain could not be found
|
|
462
|
-
* in the issuers or trusted stores. The chain is still partial. */
|
|
463
|
-
IssuerNotFound = "IssuerNotFound",
|
|
464
|
-
/** The input chain was empty. */
|
|
465
|
-
EmptyChain = "EmptyChain",
|
|
466
|
-
/** Chain completion was stopped because the maximum depth was reached. */
|
|
467
|
-
MaxDepthReached = "MaxDepthReached"
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Result of {@link CertificateManager.completeCertificateChain}.
|
|
471
|
-
*/
|
|
472
|
-
interface ChainCompletionResult {
|
|
473
|
-
/** The (possibly completed) certificate chain, leaf first. */
|
|
474
|
-
chain: Certificate[];
|
|
475
|
-
/** Status code indicating whether completion succeeded and why/why not. */
|
|
476
|
-
status: ChainCompletionStatus;
|
|
477
|
-
/** Human-readable diagnostic message. */
|
|
478
|
-
message: string;
|
|
479
|
-
}
|
|
480
|
-
declare class CertificateManager extends EventEmitter {
|
|
481
|
-
#private;
|
|
482
|
-
/**
|
|
483
|
-
* Dispose **all** active CertificateManager instances,
|
|
484
|
-
* closing their file watchers and freeing resources.
|
|
485
|
-
*
|
|
486
|
-
* This is mainly useful in test tear-down to ensure the
|
|
487
|
-
* Node.js process can exit cleanly.
|
|
488
|
-
*/
|
|
489
|
-
static disposeAll(): Promise<void>;
|
|
490
|
-
/**
|
|
491
|
-
* Assert that all CertificateManager instances have been
|
|
492
|
-
* properly disposed. Throws an Error listing the locations
|
|
493
|
-
* of any leaked instances.
|
|
494
|
-
*
|
|
495
|
-
* Intended for use in test `afterAll()` / `afterEach()`
|
|
496
|
-
* hooks to catch missing `dispose()` calls early.
|
|
497
|
-
*
|
|
498
|
-
* @example
|
|
499
|
-
* ```ts
|
|
500
|
-
* after(() => {
|
|
501
|
-
* CertificateManager.checkAllDisposed();
|
|
502
|
-
* });
|
|
503
|
-
* ```
|
|
504
|
-
*/
|
|
505
|
-
static checkAllDisposed(): void;
|
|
506
|
-
/**
|
|
507
|
-
* When `true` (the default), any certificate that is not
|
|
508
|
-
* already in the trusted or rejected store is automatically
|
|
509
|
-
* written to the rejected folder the first time it is seen.
|
|
510
|
-
*/
|
|
511
|
-
untrustUnknownCertificate: boolean;
|
|
512
|
-
/** Current lifecycle state of this instance. */
|
|
513
|
-
state: CertificateManagerState;
|
|
514
|
-
/** @deprecated Use {@link folderPollingInterval} instead (typo fix). */
|
|
515
|
-
folderPoolingInterval: number;
|
|
516
|
-
/** Interval in milliseconds for file-system polling (when enabled). */
|
|
517
|
-
get folderPollingInterval(): number;
|
|
518
|
-
set folderPollingInterval(value: number);
|
|
519
|
-
/** RSA key size used when generating the private key. */
|
|
520
|
-
readonly keySize: KeySize;
|
|
521
|
-
/**
|
|
522
|
-
* Create a new CertificateManager.
|
|
523
|
-
*
|
|
524
|
-
* The constructor creates the root directory if it does not
|
|
525
|
-
* exist but does **not** initialise the PKI store — call
|
|
526
|
-
* {@link initialize} before using any other method.
|
|
527
|
-
*
|
|
528
|
-
* @param options - configuration options
|
|
529
|
-
*/
|
|
530
|
-
constructor(options: CertificateManagerOptions);
|
|
531
|
-
/** Path to the OpenSSL configuration file. */
|
|
532
|
-
get configFile(): string;
|
|
533
|
-
/** Root directory of the PKI store. */
|
|
534
|
-
get rootDir(): string;
|
|
535
|
-
/**
|
|
536
|
-
* Path to the private key file (`own/private/private_key.pem`).
|
|
537
|
-
*
|
|
538
|
-
* Kept for backward compatibility with code that reads the key
|
|
539
|
-
* directly from disk. When a passphrase or a `privateKeyProvider` is
|
|
540
|
-
* configured, prefer {@link getPrivateKey} instead — this getter still
|
|
541
|
-
* returns the on-disk path even if a provider is configured (there may
|
|
542
|
-
* be no meaningful file in that case).
|
|
543
|
-
*/
|
|
544
|
-
get privateKey(): string;
|
|
545
|
-
/**
|
|
546
|
-
* Resolve the private key: from `privateKeyProvider` if configured,
|
|
547
|
-
* otherwise from disk (decrypting with `privateKeyPassphrase` if the
|
|
548
|
-
* key is encrypted). Fails closed — throws
|
|
549
|
-
* `PrivateKeyPassphraseRequiredError` — if the on-disk key is encrypted
|
|
550
|
-
* and no passphrase is configured, or if the wrong passphrase is
|
|
551
|
-
* configured.
|
|
552
|
-
*
|
|
553
|
-
* The on-disk key is read and decrypted once and then cached for the
|
|
554
|
-
* lifetime of this instance, so a `privateKeyPassphrase` function is
|
|
555
|
-
* called at most once (concurrent first calls share the same read). A
|
|
556
|
-
* failed read is not cached, so a caller can fix the passphrase and
|
|
557
|
-
* retry. A `privateKeyProvider` is consulted on every call: it is the
|
|
558
|
-
* authority on what the current key is.
|
|
559
|
-
*/
|
|
560
|
-
getPrivateKey(): Promise<PrivateKey>;
|
|
561
|
-
/**
|
|
562
|
-
* True when this manager's key is opaque — configured through
|
|
563
|
-
* `keyOperations`, held by an HSM/KMS, never obtainable as material.
|
|
564
|
-
* When true, {@link getPrivateKey} throws `PrivateKeyUnavailableError`
|
|
565
|
-
* and {@link getKeyOperations} is the only way to use the key.
|
|
566
|
-
*/
|
|
567
|
-
isPrivateKeyOpaque(): boolean;
|
|
568
|
-
/**
|
|
569
|
-
* The key as an opaque {@link IKeyOperations} — the recommended way to
|
|
570
|
-
* *use* the private key regardless of where it lives.
|
|
571
|
-
*
|
|
572
|
-
* Returns the configured `keyOperations` object when the key is opaque.
|
|
573
|
-
* Otherwise returns a stable lazy wrap over {@link getPrivateKey}: its
|
|
574
|
-
* methods resolve the key on first use (disk read, passphrase,
|
|
575
|
-
* `privateKeyProvider` — all async), so the wrap offers no synchronous
|
|
576
|
-
* fast path; callers that need one resolve the key themselves and build
|
|
577
|
-
* a `LocalKeyOperations` over it. The wrap follows key rotation: a
|
|
578
|
-
* `privateKeyProvider` that starts returning a different key gets a
|
|
579
|
-
* fresh underlying `LocalKeyOperations`.
|
|
580
|
-
*/
|
|
581
|
-
getKeyOperations(): IKeyOperations;
|
|
582
|
-
/**
|
|
583
|
-
* Enable, disable, or rotate the passphrase protecting the on-disk
|
|
584
|
-
* private key: decrypt with `oldPassphrase` (omit if the key is
|
|
585
|
-
* currently unencrypted), then write back encrypted with
|
|
586
|
-
* `newPassphrase` (omit to leave it unencrypted). The write goes to a
|
|
587
|
-
* temporary file in the same directory and is atomically renamed into
|
|
588
|
-
* place, so a crash mid-rotation cannot leave a partially-written key;
|
|
589
|
-
* the temporary file is removed if anything fails, so a rotation *to*
|
|
590
|
-
* plaintext can never leave a stray cleartext copy behind. Runs under
|
|
591
|
-
* the same lock as `initialize()`.
|
|
592
|
-
*
|
|
593
|
-
* This only rewrites the on-disk file — it does not update this
|
|
594
|
-
* instance's own `privateKeyPassphrase` (set at construction), and it
|
|
595
|
-
* drops this instance's cached key so that disk stays the source of
|
|
596
|
-
* truth. Construct a new `CertificateManager` with the new passphrase to
|
|
597
|
-
* continue using it afterward.
|
|
598
|
-
*
|
|
599
|
-
* Not supported when a `privateKeyProvider` is configured (there is no
|
|
600
|
-
* disk file for this method to rewrite).
|
|
601
|
-
*/
|
|
602
|
-
reencryptPrivateKey(oldPassphrase?: PrivateKeyPassphrase, newPassphrase?: PrivateKeyPassphrase): Promise<void>;
|
|
603
|
-
/** Path to the OpenSSL random seed file. */
|
|
604
|
-
get randomFile(): string;
|
|
605
|
-
/**
|
|
606
|
-
* Move a certificate to the rejected store.
|
|
607
|
-
* If the certificate was previously trusted, it will be removed from the trusted folder.
|
|
608
|
-
* @param certificateOrChain - the DER-encoded certificate or certificate chain
|
|
609
|
-
*/
|
|
610
|
-
rejectCertificate(certificateOrChain: Certificate | Certificate[]): Promise<void>;
|
|
611
|
-
/**
|
|
612
|
-
* Move a certificate to the trusted store.
|
|
613
|
-
* If the certificate was previously rejected, it will be removed from the rejected folder.
|
|
614
|
-
* @param certificateOrChain - the DER-encoded certificate or certificate chain
|
|
615
|
-
*/
|
|
616
|
-
trustCertificate(certificateOrChain: Certificate | Certificate[]): Promise<void>;
|
|
617
|
-
/**
|
|
618
|
-
* Check whether the trusted certificate store is empty.
|
|
619
|
-
*
|
|
620
|
-
* This inspects the in-memory index, which is kept in
|
|
621
|
-
* sync with the `trusted/certs/` folder by file-system
|
|
622
|
-
* watchers after {@link initialize} has been called.
|
|
623
|
-
*/
|
|
624
|
-
isTrustListEmpty(): boolean;
|
|
625
|
-
/**
|
|
626
|
-
* Return the number of certificates currently in the
|
|
627
|
-
* trusted store.
|
|
628
|
-
*/
|
|
629
|
-
getTrustedCertificateCount(): number;
|
|
630
|
-
/** Path to the rejected certificates folder. */
|
|
631
|
-
get rejectedFolder(): string;
|
|
632
|
-
/** Path to the trusted certificates folder. */
|
|
633
|
-
get trustedFolder(): string;
|
|
634
|
-
/** Path to the trusted CRL folder. */
|
|
635
|
-
get crlFolder(): string;
|
|
636
|
-
/** Path to the issuer (CA) certificates folder. */
|
|
637
|
-
get issuersCertFolder(): string;
|
|
638
|
-
/** Path to the issuer CRL folder. */
|
|
639
|
-
get issuersCrlFolder(): string;
|
|
640
|
-
/** Path to the own certificate folder. */
|
|
641
|
-
get ownCertFolder(): string;
|
|
642
|
-
get ownPrivateFolder(): string;
|
|
643
|
-
/**
|
|
644
|
-
* Check if a certificate is in the trusted store.
|
|
645
|
-
* If the certificate is unknown and `untrustUnknownCertificate` is set,
|
|
646
|
-
* it will be written to the rejected folder.
|
|
647
|
-
* @param certificate - the DER-encoded certificate
|
|
648
|
-
* @returns `"Good"` if trusted, `"BadCertificateUntrusted"` if rejected/unknown,
|
|
649
|
-
* or `"BadCertificateInvalid"` if the certificate cannot be parsed.
|
|
650
|
-
*/
|
|
651
|
-
isCertificateTrusted(certificateOrCertificateChain: Certificate | Certificate[]): Promise<"Good" | "BadCertificateUntrusted" | "BadCertificateInvalid">;
|
|
652
|
-
/**
|
|
653
|
-
* Internal verification hook called by {@link verifyCertificate}.
|
|
654
|
-
*
|
|
655
|
-
* Subclasses can override this to inject additional validation
|
|
656
|
-
* logic (e.g. application-level policy checks) while still
|
|
657
|
-
* delegating to the default chain/CRL/trust verification.
|
|
658
|
-
*
|
|
659
|
-
* @param certificate - the DER-encoded certificate to verify
|
|
660
|
-
* @param options - verification options forwarded from the
|
|
661
|
-
* public API
|
|
662
|
-
* @returns the verification status code
|
|
663
|
-
*/
|
|
664
|
-
protected verifyCertificateAsync(certificate: Certificate | Certificate[], options: VerifyCertificateOptions): Promise<VerificationStatus>;
|
|
665
|
-
/**
|
|
666
|
-
* Verify a certificate against the PKI trust store.
|
|
667
|
-
*
|
|
668
|
-
* This performs a full validation including trust status,
|
|
669
|
-
* issuer chain, CRL revocation checks, and time validity.
|
|
670
|
-
*
|
|
671
|
-
* @param certificate - the DER-encoded certificate to verify
|
|
672
|
-
* @param options - optional flags to relax validation rules
|
|
673
|
-
* @returns the verification status code
|
|
674
|
-
*/
|
|
675
|
-
verifyCertificate(certificate: Certificate | Certificate[], options?: VerifyCertificateOptions): Promise<VerificationStatus>;
|
|
676
|
-
/**
|
|
677
|
-
* Initialize the PKI directory structure, generate the
|
|
678
|
-
* private key (if missing), and start file-system watchers.
|
|
679
|
-
*
|
|
680
|
-
* This method is idempotent — subsequent calls are no-ops.
|
|
681
|
-
* It must be called before any certificate operations.
|
|
682
|
-
*/
|
|
683
|
-
initialize(): Promise<void>;
|
|
684
|
-
/**
|
|
685
|
-
* Dispose of the CertificateManager, releasing file watchers
|
|
686
|
-
* and other resources. The instance should not be used after
|
|
687
|
-
* calling this method.
|
|
688
|
-
*/
|
|
689
|
-
dispose(): Promise<void>;
|
|
690
|
-
/**
|
|
691
|
-
* Force a full re-scan of all PKI folders, rebuilding
|
|
692
|
-
* the in-memory `_thumbs` index from scratch.
|
|
693
|
-
*
|
|
694
|
-
* Call this after external processes have modified the
|
|
695
|
-
* PKI folders (e.g. via `writeTrustList` or CLI tools)
|
|
696
|
-
* to ensure the CertificateManager sees the latest
|
|
697
|
-
* state without waiting for file-system events.
|
|
698
|
-
*/
|
|
699
|
-
reloadCertificates(): Promise<void>;
|
|
700
|
-
protected withLock2<T>(action: () => Promise<T>): Promise<T>;
|
|
701
|
-
/**
|
|
702
|
-
* Create a self-signed certificate for this PKI's private key.
|
|
703
|
-
*
|
|
704
|
-
* The certificate is written to `params.outputFile` or
|
|
705
|
-
* `own/certs/self_signed_certificate.pem` by default.
|
|
706
|
-
*
|
|
707
|
-
* @param params - certificate parameters (subject, SANs,
|
|
708
|
-
* validity, etc.)
|
|
709
|
-
*/
|
|
710
|
-
createSelfSignedCertificate(params: CreateSelfSignCertificateParam1): Promise<void>;
|
|
711
|
-
/**
|
|
712
|
-
* Create a Certificate Signing Request (CSR) using this
|
|
713
|
-
* PKI's private key and configuration.
|
|
714
|
-
*
|
|
715
|
-
* The CSR file is written to `own/certs/` with a timestamped
|
|
716
|
-
* filename.
|
|
717
|
-
*
|
|
718
|
-
* @param params - CSR parameters (subject, SANs)
|
|
719
|
-
* @returns the filesystem path to the generated CSR file
|
|
720
|
-
*/
|
|
721
|
-
createCertificateRequest(params: CreateSelfSignCertificateParam): Promise<Filename>;
|
|
722
|
-
/**
|
|
723
|
-
* Add a CA (issuer) certificate to the issuers store.
|
|
724
|
-
* If the certificate is already present, this is a no-op.
|
|
725
|
-
* @param certificate - the DER-encoded CA certificate
|
|
726
|
-
* @param validate - if `true`, verify the certificate before adding
|
|
727
|
-
* @param addInTrustList - if `true`, also add to the trusted store
|
|
728
|
-
* @returns `VerificationStatus.Good` on success
|
|
729
|
-
*/
|
|
730
|
-
addIssuer(certificate: DER, validate?: boolean, addInTrustList?: boolean): Promise<VerificationStatus>;
|
|
731
|
-
/**
|
|
732
|
-
* Add multiple CA (issuer) certificates to the issuers store.
|
|
733
|
-
* @param certificates - the DER-encoded CA certificates
|
|
734
|
-
* @param validate - if `true`, verify each certificate before adding
|
|
735
|
-
* @param addInTrustList - if `true`, also add each certificate to the trusted store
|
|
736
|
-
* @returns `VerificationStatus.Good` on success
|
|
737
|
-
*/
|
|
738
|
-
addIssuers(certificates: Certificate[], validate?: boolean, addInTrustList?: boolean): Promise<VerificationStatus>;
|
|
739
|
-
/**
|
|
740
|
-
* Add a CRL to the certificate manager.
|
|
741
|
-
* @param crl - the CRL to add
|
|
742
|
-
* @param target - "issuers" (default) writes to issuers/crl, "trusted" writes to trusted/crl
|
|
743
|
-
*/
|
|
744
|
-
addRevocationList(crl: CertificateRevocationList, target?: "issuers" | "trusted"): Promise<VerificationStatus>;
|
|
745
|
-
/**
|
|
746
|
-
* Remove all CRL files from the specified folder(s) and clear the
|
|
747
|
-
* corresponding in-memory index.
|
|
748
|
-
* @param target - "issuers" clears issuers/crl, "trusted" clears
|
|
749
|
-
* trusted/crl, "all" clears both.
|
|
750
|
-
*/
|
|
751
|
-
clearRevocationLists(target: "issuers" | "trusted" | "all"): Promise<void>;
|
|
752
|
-
/**
|
|
753
|
-
* Check whether an issuer certificate with the given thumbprint
|
|
754
|
-
* is already registered.
|
|
755
|
-
* @param thumbprint - hex-encoded SHA-1 thumbprint (lowercase)
|
|
756
|
-
*/
|
|
757
|
-
hasIssuer(thumbprint: string): Promise<boolean>;
|
|
758
|
-
/**
|
|
759
|
-
* Remove a trusted certificate identified by its SHA-1 thumbprint.
|
|
760
|
-
* Deletes the file on disk and removes the entry from the
|
|
761
|
-
* in-memory index.
|
|
762
|
-
* @param thumbprint - hex-encoded SHA-1 thumbprint (lowercase)
|
|
763
|
-
* @returns the removed certificate buffer, or `null` if not found
|
|
764
|
-
*/
|
|
765
|
-
removeTrustedCertificate(thumbprint: string): Promise<Certificate | null>;
|
|
766
|
-
/**
|
|
767
|
-
* Remove an issuer certificate identified by its SHA-1 thumbprint.
|
|
768
|
-
* Deletes the file on disk and removes the entry from the
|
|
769
|
-
* in-memory index.
|
|
770
|
-
* @param thumbprint - hex-encoded SHA-1 thumbprint (lowercase)
|
|
771
|
-
* @returns the removed certificate buffer, or `null` if not found
|
|
772
|
-
*/
|
|
773
|
-
removeIssuer(thumbprint: string): Promise<Certificate | null>;
|
|
774
|
-
/**
|
|
775
|
-
* Remove all CRL files that were issued by the given CA certificate
|
|
776
|
-
* from the specified folder (or both).
|
|
777
|
-
* @param issuerCertificate - the CA certificate whose CRLs to remove
|
|
778
|
-
* @param target - "issuers", "trusted", or "all" (default "all")
|
|
779
|
-
*/
|
|
780
|
-
removeRevocationListsForIssuer(issuerCertificate: Certificate, target?: "issuers" | "trusted" | "all"): Promise<void>;
|
|
781
|
-
/**
|
|
782
|
-
* Validate a certificate (optionally with its chain) and add
|
|
783
|
-
* the leaf certificate to the trusted store.
|
|
784
|
-
*
|
|
785
|
-
* Performs OPC UA Part 4, Table 100 validation:
|
|
786
|
-
*
|
|
787
|
-
* 1. **Certificate Structure** — parse the DER encoding.
|
|
788
|
-
* 2. **Build Certificate Chain** — walk from the leaf to a
|
|
789
|
-
* self-signed root CA, using the provided chain and the
|
|
790
|
-
* issuers store.
|
|
791
|
-
* 3. **Signature** — verify each certificate's signature
|
|
792
|
-
* against its issuer.
|
|
793
|
-
* 4. **Issuer Presence** — every issuer in the chain must
|
|
794
|
-
* already be registered in the issuers store (per GDS
|
|
795
|
-
* 7.8.2.6).
|
|
796
|
-
* 5. **Validity Period** — each certificate must be within
|
|
797
|
-
* its validity window (overridable via
|
|
798
|
-
* {@link AddCertificateValidationOptions.acceptExpiredCertificate}).
|
|
799
|
-
* 6. **Revocation Check** — each certificate is checked
|
|
800
|
-
* against its issuer's CRL (overridable via
|
|
801
|
-
* {@link AddCertificateValidationOptions.acceptRevokedCertificate}
|
|
802
|
-
* and {@link AddCertificateValidationOptions.ignoreMissingRevocationList}).
|
|
803
|
-
*
|
|
804
|
-
* Only the leaf certificate is added to the trusted store.
|
|
805
|
-
*
|
|
806
|
-
* @param certificateChain - DER-encoded certificate or chain
|
|
807
|
-
* @returns `VerificationStatus.Good` on success, or an error
|
|
808
|
-
* status indicating why the certificate was rejected.
|
|
809
|
-
*/
|
|
810
|
-
addTrustedCertificateFromChain(certificateChain: Certificate | Certificate[]): Promise<VerificationStatus>;
|
|
811
|
-
/**
|
|
812
|
-
* Check whether an issuer certificate is still needed by any
|
|
813
|
-
* certificate in the trusted store.
|
|
814
|
-
*
|
|
815
|
-
* This is used before removing an issuer to ensure that
|
|
816
|
-
* doing so would not break the chain of any trusted
|
|
817
|
-
* certificate.
|
|
818
|
-
*
|
|
819
|
-
* @param issuerCertificate - the CA certificate to check
|
|
820
|
-
* @returns `true` if at least one trusted certificate was
|
|
821
|
-
* signed by this issuer.
|
|
822
|
-
*/
|
|
823
|
-
isIssuerInUseByTrustedCertificate(issuerCertificate: Certificate): Promise<boolean>;
|
|
824
|
-
/**
|
|
825
|
-
* find the issuer certificate among the trusted issuer certificates.
|
|
826
|
-
*
|
|
827
|
-
* The findIssuerCertificate method is an asynchronous method that attempts to find
|
|
828
|
-
* the issuer certificate for a given certificate from the list of issuer certificate declared in the PKI
|
|
829
|
-
*
|
|
830
|
-
* - If the certificate is self-signed, it returns the certificate itself.
|
|
831
|
-
*
|
|
832
|
-
* - If the certificate has no extension 3, it is assumed to be generated by an old system, and a null value is returned.
|
|
833
|
-
*
|
|
834
|
-
* - the method checks both issuer and trusted certificates and returns the appropriate issuercertificate,
|
|
835
|
-
* if found. If multiple matching certificates are found, a warning is logged to the console.
|
|
836
|
-
*
|
|
837
|
-
*/
|
|
838
|
-
findIssuerCertificate(certificate: Certificate | Certificate[]): Promise<Certificate | null>;
|
|
839
|
-
/**
|
|
840
|
-
* Outcome status for {@link CertificateManager.completeCertificateChain}.
|
|
841
|
-
*/
|
|
842
|
-
static readonly ChainCompletionStatus: typeof ChainCompletionStatus;
|
|
843
|
-
/**
|
|
844
|
-
* Complete a certificate chain by walking the issuer store.
|
|
845
|
-
*
|
|
846
|
-
* Starting from the last certificate in the provided chain, this method
|
|
847
|
-
* repeatedly calls {@link findIssuerCertificate} to locate the parent
|
|
848
|
-
* certificate until it reaches a self-signed root or can no longer find
|
|
849
|
-
* an issuer.
|
|
850
|
-
*
|
|
851
|
-
* @param chain - the (potentially partial) certificate chain, leaf first
|
|
852
|
-
* @param maxDepth - maximum number of issuers to append (default: 10)
|
|
853
|
-
* @returns a {@link ChainCompletionResult} containing the (possibly completed)
|
|
854
|
-
* chain, a status code, and an optional diagnostic message.
|
|
855
|
-
*/
|
|
856
|
-
completeCertificateChain(chain: Certificate[], maxDepth?: number): Promise<ChainCompletionResult>;
|
|
857
|
-
/**
|
|
858
|
-
* Check whether a certificate has been revoked by its issuer's CRL.
|
|
859
|
-
*
|
|
860
|
-
* - Self-signed certificates are never considered revoked.
|
|
861
|
-
* - If no `issuerCertificate` is provided, the method attempts
|
|
862
|
-
* to find it via {@link findIssuerCertificate}.
|
|
863
|
-
*
|
|
864
|
-
* @param certificate - the DER-encoded certificate to check
|
|
865
|
-
* @param issuerCertificate - optional issuer certificate; looked
|
|
866
|
-
* up automatically when omitted
|
|
867
|
-
* @returns `Good` if not revoked, `BadCertificateRevoked` if the
|
|
868
|
-
* serial number appears in a CRL,
|
|
869
|
-
* `BadCertificateRevocationUnknown` if no CRL is available,
|
|
870
|
-
* or `BadCertificateChainIncomplete` if the issuer cannot be
|
|
871
|
-
* found.
|
|
872
|
-
*/
|
|
873
|
-
isCertificateRevoked(certificate: Certificate | Certificate[], issuerCertificate?: Certificate | null): Promise<VerificationStatus>;
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
/**
|
|
877
|
-
* Options for creating a PFX (PKCS#12) file.
|
|
878
|
-
*/
|
|
879
|
-
interface CreatePFXOptions {
|
|
880
|
-
/** Path to the certificate file (PEM or DER). */
|
|
881
|
-
certificateFile: Filename;
|
|
882
|
-
/** Path to the private key file (PEM, plaintext or encrypted PKCS#8). */
|
|
883
|
-
privateKeyFile: Filename;
|
|
884
|
-
/**
|
|
885
|
-
* Passphrase that decrypts `privateKeyFile` if it is an encrypted
|
|
886
|
-
* PKCS#8 key (e.g. a `CertificateManager` created with
|
|
887
|
-
* `privateKeyPassphrase`). Omit for a plaintext key. This is distinct
|
|
888
|
-
* from `passphrase`, which protects the *output* PFX bundle.
|
|
889
|
-
*/
|
|
890
|
-
privateKeyPassphrase?: string;
|
|
891
|
-
/** Output path for the generated PFX file. */
|
|
892
|
-
outputFile: Filename;
|
|
893
|
-
/**
|
|
894
|
-
* Optional passphrase to protect the PFX file.
|
|
895
|
-
* If omitted, the PFX is created without a password.
|
|
896
|
-
*/
|
|
897
|
-
passphrase?: string;
|
|
898
|
-
/**
|
|
899
|
-
* Optional path(s) to CA / intermediate certificate files
|
|
900
|
-
* to include in the PFX bundle.
|
|
901
|
-
*/
|
|
902
|
-
caCertificateFiles?: Filename[];
|
|
903
|
-
/**
|
|
904
|
-
* Optional display label stored on the bundle, the equivalent of
|
|
905
|
-
* openssl's `-name`. The Windows certificate store and `keytool` show
|
|
906
|
-
* it; {@link extractAllFromPFX} and {@link dumpPFX} report it back.
|
|
907
|
-
*/
|
|
908
|
-
friendlyName?: string;
|
|
909
|
-
}
|
|
910
|
-
/**
|
|
911
|
-
* Options for extracting data from a PFX (PKCS#12) file.
|
|
912
|
-
*/
|
|
913
|
-
interface ExtractPFXOptions {
|
|
914
|
-
/** Path to the PFX file. */
|
|
915
|
-
pfxFile: Filename;
|
|
916
|
-
/**
|
|
917
|
-
* Passphrase used when the PFX was created.
|
|
918
|
-
* Pass an empty string for unprotected PFX files.
|
|
919
|
-
*/
|
|
920
|
-
passphrase?: string;
|
|
921
|
-
}
|
|
922
|
-
/**
|
|
923
|
-
* Result of extracting data from a PFX file.
|
|
924
|
-
*/
|
|
925
|
-
interface ExtractPFXResult {
|
|
926
|
-
/** The certificate in PEM format. */
|
|
927
|
-
certificate: string;
|
|
928
|
-
/** The private key in PEM format. */
|
|
929
|
-
privateKey: string;
|
|
930
|
-
/**
|
|
931
|
-
* The CA / intermediate certificates in PEM format
|
|
932
|
-
* (empty string if none).
|
|
933
|
-
*/
|
|
934
|
-
caCertificates: string;
|
|
935
|
-
/** The display label the bundle carries, if it has one. */
|
|
936
|
-
friendlyName?: string;
|
|
937
|
-
}
|
|
938
|
-
/**
|
|
939
|
-
* Create a PFX (PKCS#12) file from a certificate and private key.
|
|
940
|
-
*
|
|
941
|
-
* The bundle is protected with PBES2 / AES-256-CBC under an SHA-256 MAC. If
|
|
942
|
-
* `certificateFile` holds more than one PEM block, the first is the
|
|
943
|
-
* identity and the rest join the issuer chain, ahead of any
|
|
944
|
-
* `caCertificateFiles`.
|
|
945
|
-
*
|
|
946
|
-
* Nothing is written unless every input reads back cleanly and the private
|
|
947
|
-
* key belongs to the certificate, so a wrong `privateKeyPassphrase` or a
|
|
948
|
-
* mismatched pair leaves no half-made file behind.
|
|
949
|
-
*
|
|
950
|
-
* @param options - see {@link CreatePFXOptions}
|
|
951
|
-
*/
|
|
952
|
-
declare function createPFX(options: CreatePFXOptions): Promise<void>;
|
|
953
|
-
/**
|
|
954
|
-
* Extract the client/server certificate from a PFX file.
|
|
955
|
-
*
|
|
956
|
-
* @returns the certificate in PEM format.
|
|
957
|
-
*/
|
|
958
|
-
declare function extractCertificateFromPFX(options: ExtractPFXOptions): Promise<string>;
|
|
959
|
-
/**
|
|
960
|
-
* Extract the private key from a PFX file.
|
|
961
|
-
*
|
|
962
|
-
* @returns the private key as unencrypted PKCS#8 PEM.
|
|
963
|
-
*/
|
|
964
|
-
declare function extractPrivateKeyFromPFX(options: ExtractPFXOptions): Promise<string>;
|
|
965
|
-
/**
|
|
966
|
-
* Extract the CA / intermediate certificates from a PFX file.
|
|
967
|
-
*
|
|
968
|
-
* @returns the CA certificates in PEM format
|
|
969
|
-
* (empty string if none are present).
|
|
970
|
-
*/
|
|
971
|
-
declare function extractCACertificatesFromPFX(options: ExtractPFXOptions): Promise<string>;
|
|
972
|
-
/**
|
|
973
|
-
* Extract certificate + private key + CA certs from a PFX file
|
|
974
|
-
* in a single call.
|
|
975
|
-
*
|
|
976
|
-
* Prefer this over the single-part helpers when you want more than one
|
|
977
|
-
* part: the file is read, decrypted and MAC-verified once here, against
|
|
978
|
-
* once per part.
|
|
979
|
-
*
|
|
980
|
-
* @returns an {@link ExtractPFXResult} with all PEM-encoded parts.
|
|
981
|
-
*/
|
|
982
|
-
declare function extractAllFromPFX(options: ExtractPFXOptions): Promise<ExtractPFXResult>;
|
|
983
|
-
/**
|
|
984
|
-
* Convert a PFX file to a single PEM file holding the private key, the
|
|
985
|
-
* certificate, and any issuer certificates the bundle carries, in that
|
|
986
|
-
* order.
|
|
987
|
-
*/
|
|
988
|
-
declare function convertPFXtoPEM(pfxFile: Filename, pemFile: Filename, passphrase?: string): Promise<void>;
|
|
989
|
-
/**
|
|
990
|
-
* Dump the contents of a PFX file in human-readable form.
|
|
991
|
-
*
|
|
992
|
-
* The layout is this package's own, not `openssl pkcs12 -info`'s: it
|
|
993
|
-
* describes the identity the bundle carries rather than the algorithms it
|
|
994
|
-
* was encrypted with, and it states outright whether the enclosed key
|
|
995
|
-
* matches the enclosed certificate - the question a bundle that will not
|
|
996
|
-
* load is usually being asked. Treat the text as something to read, not to
|
|
997
|
-
* parse; use {@link extractAllFromPFX} to get at the parts.
|
|
998
|
-
*
|
|
999
|
-
* @returns the human-readable dump as a string.
|
|
1000
|
-
*/
|
|
1001
|
-
declare function dumpPFX(pfxFile: Filename, passphrase?: string): Promise<string>;
|
|
1002
|
-
|
|
1003
|
-
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, safeStoreJoin, toFilenameLabel };
|