node-opcua-server-configuration 2.167.0 → 2.169.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clientTools/push_certificate_management_client.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/server/file_transaction_manager.d.ts +10 -0
- package/dist/server/file_transaction_manager.js +23 -0
- package/dist/server/file_transaction_manager.js.map +1 -1
- package/dist/server/{install_push_certitifate_management.d.ts → install_push_certificate_management.d.ts} +3 -2
- package/dist/server/install_push_certificate_management.js +263 -0
- package/dist/server/install_push_certificate_management.js.map +1 -0
- package/dist/server/promote_trust_list.js +154 -3
- package/dist/server/promote_trust_list.js.map +1 -1
- package/dist/server/push_certificate_manager/create_signing_request.js +19 -13
- package/dist/server/push_certificate_manager/create_signing_request.js.map +1 -1
- package/dist/server/push_certificate_manager/update_certificate.js +21 -9
- package/dist/server/push_certificate_manager/update_certificate.js.map +1 -1
- package/dist/server/push_certificate_manager_helpers.js.map +1 -1
- package/dist/server/push_certificate_manager_server_impl.js.map +1 -1
- package/dist/server/trust_list_server.js +5 -0
- package/dist/server/trust_list_server.js.map +1 -1
- package/package.json +24 -26
- package/source/clientTools/push_certificate_management_client.ts +4 -8
- package/source/index.ts +2 -1
- package/source/server/file_transaction_manager.ts +25 -0
- package/source/server/install_push_certificate_management.ts +332 -0
- package/source/server/promote_trust_list.ts +185 -9
- package/source/server/push_certificate_manager/create_signing_request.ts +27 -17
- package/source/server/push_certificate_manager/update_certificate.ts +25 -8
- package/source/server/push_certificate_manager_helpers.ts +1 -1
- package/source/server/push_certificate_manager_server_impl.ts +3 -9
- package/source/server/trust_list_server.ts +7 -2
- package/dist/server/install_push_certitifate_management.js +0 -144
- package/dist/server/install_push_certitifate_management.js.map +0 -1
- package/source/server/install_push_certitifate_management.ts +0 -193
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-server-configuration-server
|
|
3
|
-
*/
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
|
|
7
|
-
import chalk from "chalk";
|
|
8
|
-
|
|
9
|
-
import type { AddressSpace, UAServerConfiguration } from "node-opcua-address-space";
|
|
10
|
-
import { assert } from "node-opcua-assert";
|
|
11
|
-
import type { OPCUACertificateManager } from "node-opcua-certificate-manager";
|
|
12
|
-
import { type ICertificateKeyPairProvider, invalidateCachedSecrets } from "node-opcua-common";
|
|
13
|
-
import { readPrivateKey } from "node-opcua-crypto";
|
|
14
|
-
import { type Certificate, combine_der, convertPEMtoDER, type PrivateKey, split_der } from "node-opcua-crypto/web";
|
|
15
|
-
import { checkDebugFlag, make_debugLog, make_errorLog } from "node-opcua-debug";
|
|
16
|
-
import { getFullyQualifiedDomainName, getIpAddresses } from "node-opcua-hostname";
|
|
17
|
-
import type { OPCUAServer, OPCUAServerEndPoint } from "node-opcua-server";
|
|
18
|
-
import type { ApplicationDescriptionOptions } from "node-opcua-types";
|
|
19
|
-
|
|
20
|
-
import { installPushCertificateManagement } from "./push_certificate_manager_helpers.js";
|
|
21
|
-
import type { ActionQueue, PushCertificateManagerServerImpl } from "./push_certificate_manager_server_impl.js";
|
|
22
|
-
|
|
23
|
-
const debugLog = make_debugLog("ServerConfiguration");
|
|
24
|
-
const errorLog = make_errorLog("ServerConfiguration");
|
|
25
|
-
const doDebug = checkDebugFlag("ServerConfiguration");
|
|
26
|
-
|
|
27
|
-
export interface OPCUAServerPartial extends ICertificateKeyPairProvider {
|
|
28
|
-
serverInfo?: ApplicationDescriptionOptions;
|
|
29
|
-
serverCertificateManager: OPCUACertificateManager;
|
|
30
|
-
privateKeyFile: string;
|
|
31
|
-
certificateFile: string;
|
|
32
|
-
engine: { addressSpace?: AddressSpace };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getCertificateChainEP(this: OPCUAServerEndPoint): Certificate[] {
|
|
36
|
-
const certificateFile = path.join(this.certificateManager.rootDir, "own/certs/certificate.pem");
|
|
37
|
-
const certificatePEM = fs.readFileSync(certificateFile, "utf8");
|
|
38
|
-
return split_der(convertPEMtoDER(certificatePEM));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getPrivateKeyEP(this: OPCUAServerEndPoint): PrivateKey {
|
|
42
|
-
return readPrivateKey(this.certificateManager.privateKey);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function onCertificateAboutToChange(server: OPCUAServer) {
|
|
46
|
-
doDebug && debugLog(chalk.yellow(" onCertificateAboutToChange => Suspending End points"));
|
|
47
|
-
await server.suspendEndPoints();
|
|
48
|
-
doDebug && debugLog(chalk.yellow(" onCertificateAboutToChange => End points suspended"));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* onCertificateChange is called when the serverConfiguration notifies
|
|
53
|
-
* that the server certificate and/or private key has changed.
|
|
54
|
-
*
|
|
55
|
-
* This function invalidates the cached secrets so that the next
|
|
56
|
-
* getCertificate() / getPrivateKey() call re-reads from disk,
|
|
57
|
-
* then shuts down all channels and resumes endpoints.
|
|
58
|
-
*
|
|
59
|
-
* @param server
|
|
60
|
-
*/
|
|
61
|
-
async function onCertificateChange(server: OPCUAServer) {
|
|
62
|
-
doDebug && debugLog("on CertificateChanged");
|
|
63
|
-
|
|
64
|
-
// Invalidate the cached certificate chain and private key.
|
|
65
|
-
// The SecretHolder will re-read from disk on next access.
|
|
66
|
-
invalidateCachedSecrets(server);
|
|
67
|
-
|
|
68
|
-
setTimeout(async () => {
|
|
69
|
-
try {
|
|
70
|
-
doDebug && debugLog(chalk.yellow(" onCertificateChange => shutting down channels"));
|
|
71
|
-
await server.shutdownChannels();
|
|
72
|
-
doDebug && debugLog(chalk.yellow(" onCertificateChange => channels shut down"));
|
|
73
|
-
|
|
74
|
-
doDebug && debugLog(chalk.yellow(" onCertificateChange => resuming end points"));
|
|
75
|
-
await server.resumeEndPoints();
|
|
76
|
-
doDebug && debugLog(chalk.yellow(" onCertificateChange => end points resumed"));
|
|
77
|
-
|
|
78
|
-
debugLog(chalk.yellow("channels have been closed -> client should reconnect "));
|
|
79
|
-
} catch (err) {
|
|
80
|
-
errorLog("Error in CertificateChanged handler ", (err as Error).message);
|
|
81
|
-
debugLog("err = ", err);
|
|
82
|
-
}
|
|
83
|
-
}, 2000);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Install push certificate management on the server.
|
|
88
|
-
*
|
|
89
|
-
* This redirects `getCertificate`, `getCertificateChain` and
|
|
90
|
-
* `getPrivateKey` to read from the serverCertificateManager's
|
|
91
|
-
* PEM files, and wires up the push certificate management
|
|
92
|
-
* address-space nodes.
|
|
93
|
-
*/
|
|
94
|
-
async function install(this: OPCUAServerPartial): Promise<void> {
|
|
95
|
-
doDebug && debugLog("install push certificate management", this.serverCertificateManager.rootDir);
|
|
96
|
-
|
|
97
|
-
Object.defineProperty(this, "privateKeyFile", {
|
|
98
|
-
get: () => this.serverCertificateManager.privateKey,
|
|
99
|
-
configurable: true
|
|
100
|
-
});
|
|
101
|
-
Object.defineProperty(this, "certificateFile", {
|
|
102
|
-
get: () => path.join(this.serverCertificateManager.rootDir, "own/certs/certificate.pem"),
|
|
103
|
-
configurable: true
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const certificateFile = this.certificateFile;
|
|
107
|
-
if (!fs.existsSync(certificateFile)) {
|
|
108
|
-
// this is the first time server is launched
|
|
109
|
-
// let's create a default self signed certificate with limited validity
|
|
110
|
-
const fqdn = getFullyQualifiedDomainName();
|
|
111
|
-
const ipAddresses = getIpAddresses();
|
|
112
|
-
|
|
113
|
-
const applicationUri = (this.serverInfo ? this.serverInfo.applicationUri : null) || "uri:MISSING";
|
|
114
|
-
|
|
115
|
-
const options = {
|
|
116
|
-
applicationUri,
|
|
117
|
-
dns: [fqdn],
|
|
118
|
-
ip: ipAddresses,
|
|
119
|
-
subject: `/CN=${applicationUri};/L=Paris`,
|
|
120
|
-
startDate: new Date(),
|
|
121
|
-
validity: 365 * 5, // five years
|
|
122
|
-
outputFile: certificateFile
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
doDebug && debugLog("creating self signed certificate", options);
|
|
126
|
-
await this.serverCertificateManager.createSelfSignedCertificate(options);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Invalidate any previously cached secrets so that
|
|
130
|
-
// getCertificateChain() / getPrivateKey() will re-read from disk.
|
|
131
|
-
invalidateCachedSecrets(this);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
interface UAServerConfigurationEx extends UAServerConfiguration {
|
|
135
|
-
$pushCertificateManager: PushCertificateManagerServerImpl;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
type OPCUAServerEndPointEx = typeof OPCUAServerEndPoint & {
|
|
139
|
-
_certificateChain: Certificate[] | null;
|
|
140
|
-
_privateKey: PrivateKey | null;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
export async function installPushCertificateManagementOnServer(server: OPCUAServer): Promise<void> {
|
|
144
|
-
if (!server.engine || !server.engine.addressSpace) {
|
|
145
|
-
throw new Error(
|
|
146
|
-
"Server must have a valid address space." +
|
|
147
|
-
"you need to call installPushCertificateManagementOnServer after server has been initialized"
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
await install.call(server as unknown as OPCUAServerPartial);
|
|
151
|
-
|
|
152
|
-
for (const endpoint of server.endpoints) {
|
|
153
|
-
const endpointPriv: OPCUAServerEndPointEx = endpoint as unknown as OPCUAServerEndPointEx;
|
|
154
|
-
endpointPriv._certificateChain = null;
|
|
155
|
-
endpointPriv._privateKey = null;
|
|
156
|
-
|
|
157
|
-
endpoint.getCertificateChain = getCertificateChainEP;
|
|
158
|
-
endpoint.getPrivateKey = getPrivateKeyEP;
|
|
159
|
-
|
|
160
|
-
for (const e of endpoint.endpointDescriptions()) {
|
|
161
|
-
Object.defineProperty(e, "serverCertificate", {
|
|
162
|
-
get: () => combine_der(endpoint.getCertificateChain()),
|
|
163
|
-
configurable: true
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
await installPushCertificateManagement(server.engine.addressSpace, {
|
|
169
|
-
applicationGroup: server.serverCertificateManager,
|
|
170
|
-
userTokenGroup: server.userCertificateManager,
|
|
171
|
-
|
|
172
|
-
applicationUri: server.serverInfo.applicationUri || "InvalidURI"
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
const serverConfiguration = server.engine.addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
176
|
-
const serverConfigurationPriv = serverConfiguration as UAServerConfigurationEx;
|
|
177
|
-
assert(serverConfigurationPriv.$pushCertificateManager);
|
|
178
|
-
|
|
179
|
-
serverConfigurationPriv.$pushCertificateManager.on("CertificateAboutToChange", (actionQueue: ActionQueue) => {
|
|
180
|
-
actionQueue.push(async (): Promise<void> => {
|
|
181
|
-
doDebug && debugLog("CertificateAboutToChange Event received");
|
|
182
|
-
await onCertificateAboutToChange(server);
|
|
183
|
-
doDebug && debugLog("CertificateAboutToChange Event processed");
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
serverConfigurationPriv.$pushCertificateManager.on("CertificateChanged", (actionQueue: ActionQueue) => {
|
|
187
|
-
actionQueue.push(async (): Promise<void> => {
|
|
188
|
-
doDebug && debugLog("CertificateChanged Event received");
|
|
189
|
-
await onCertificateChange(server);
|
|
190
|
-
doDebug && debugLog("CertificateChanged Event processed");
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
}
|