node-opcua-server-configuration 2.97.0 → 2.98.1
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/index.d.ts +1 -1
- package/dist/clientTools/index.js +17 -17
- package/dist/clientTools/push_certificate_management_client.d.ts +176 -176
- package/dist/clientTools/push_certificate_management_client.js +463 -463
- package/dist/clientTools/push_certificate_management_client.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.js +27 -27
- package/dist/push_certificate_manager.d.ts +141 -141
- package/dist/push_certificate_manager.js +2 -2
- package/dist/server/install_certificate_file_watcher.d.ts +5 -5
- package/dist/server/install_certificate_file_watcher.js +23 -23
- package/dist/server/install_push_certitifate_management.d.ts +19 -19
- package/dist/server/install_push_certitifate_management.js +215 -215
- package/dist/server/promote_trust_list.d.ts +6 -6
- package/dist/server/promote_trust_list.js +175 -175
- package/dist/server/push_certificate_manager_helpers.d.ts +4 -4
- package/dist/server/push_certificate_manager_helpers.js +411 -411
- package/dist/server/push_certificate_manager_server_impl.d.ts +47 -47
- package/dist/server/push_certificate_manager_server_impl.js +525 -525
- package/dist/server/roles_and_permissions.d.ts +3 -3
- package/dist/server/roles_and_permissions.js +38 -38
- package/dist/server/tools.d.ts +3 -3
- package/dist/server/tools.js +19 -19
- package/dist/server/trust_list_server.d.ts +13 -13
- package/dist/server/trust_list_server.js +89 -89
- package/dist/standard_certificate_types.d.ts +6 -6
- package/dist/standard_certificate_types.js +13 -13
- package/dist/trust_list.d.ts +79 -79
- package/dist/trust_list.js +2 -2
- package/dist/trust_list_impl.js +25 -25
- package/package.json +32 -28
- package/bin/configurator.ts +0 -304
|
@@ -1,412 +1,412 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.installPushCertificateManagement = exports.promoteCertificateGroup = void 0;
|
|
13
|
-
/**
|
|
14
|
-
* @module node-opcua-server-configuration
|
|
15
|
-
*/
|
|
16
|
-
const path = require("path");
|
|
17
|
-
const fs = require("fs");
|
|
18
|
-
const node_opcua_address_space_1 = require("node-opcua-address-space");
|
|
19
|
-
const node_opcua_address_space_base_1 = require("node-opcua-address-space-base");
|
|
20
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
21
|
-
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
22
|
-
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
23
|
-
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
24
|
-
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
25
|
-
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
26
|
-
const node_opcua_crypto_1 = require("node-opcua-crypto");
|
|
27
|
-
const push_certificate_manager_server_impl_1 = require("./push_certificate_manager_server_impl");
|
|
28
|
-
const promote_trust_list_1 = require("./promote_trust_list");
|
|
29
|
-
const tools_1 = require("./tools");
|
|
30
|
-
const roles_and_permissions_1 = require("./roles_and_permissions");
|
|
31
|
-
const install_certificate_file_watcher_1 = require("./install_certificate_file_watcher");
|
|
32
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)("ServerConfiguration");
|
|
33
|
-
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("ServerConfiguration");
|
|
34
|
-
const warningLog = (0, node_opcua_debug_1.make_warningLog)("ServerConfiguration");
|
|
35
|
-
const errorLog = debugLog;
|
|
36
|
-
function expected(variant, dataType, variantArrayType) {
|
|
37
|
-
if (!variant) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
if (variant.dataType !== dataType) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
if (variant.arrayType !== variantArrayType) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
function getPushCertificateManager(method) {
|
|
49
|
-
const serverConfiguration = method.addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
50
|
-
const serverConfigurationPriv = serverConfiguration;
|
|
51
|
-
if (serverConfigurationPriv.$pushCertificateManager) {
|
|
52
|
-
return serverConfigurationPriv.$pushCertificateManager;
|
|
53
|
-
}
|
|
54
|
-
// throw new Error("Cannot find pushCertificateManager object");
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
function _createSigningRequest(inputArguments, context) {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const certificateGroupIdVariant = inputArguments[0];
|
|
60
|
-
const certificateTypeIdVariant = inputArguments[1];
|
|
61
|
-
const subjectNameVariant = inputArguments[2];
|
|
62
|
-
const regeneratePrivateKeyVariant = inputArguments[3];
|
|
63
|
-
const nonceVariant = inputArguments[4];
|
|
64
|
-
if (!expected(certificateGroupIdVariant, node_opcua_variant_1.DataType.NodeId, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
65
|
-
warningLog("expecting an NodeId for certificateGroupId - 0");
|
|
66
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
67
|
-
}
|
|
68
|
-
if (!expected(certificateTypeIdVariant, node_opcua_variant_1.DataType.NodeId, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
69
|
-
warningLog("expecting an NodeId for certificateTypeId - 1");
|
|
70
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
71
|
-
}
|
|
72
|
-
if (!expected(subjectNameVariant, node_opcua_variant_1.DataType.String, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
73
|
-
warningLog("expecting an String for subjectName - 2");
|
|
74
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
75
|
-
}
|
|
76
|
-
if (!expected(regeneratePrivateKeyVariant, node_opcua_variant_1.DataType.Boolean, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
77
|
-
warningLog("expecting an Boolean for regeneratePrivateKey - 3");
|
|
78
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
79
|
-
}
|
|
80
|
-
if (!expected(nonceVariant, node_opcua_variant_1.DataType.ByteString, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
81
|
-
warningLog("expecting an ByteString for nonceVariant - 4");
|
|
82
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
83
|
-
}
|
|
84
|
-
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
85
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
86
|
-
}
|
|
87
|
-
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
88
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
89
|
-
}
|
|
90
|
-
const certificateGroupId = certificateGroupIdVariant.value;
|
|
91
|
-
const certificateTypeId = certificateTypeIdVariant.value;
|
|
92
|
-
const subjectName = subjectNameVariant.value;
|
|
93
|
-
const regeneratePrivateKey = regeneratePrivateKeyVariant.value;
|
|
94
|
-
const nonce = nonceVariant.value;
|
|
95
|
-
const pushCertificateManager = getPushCertificateManager(this);
|
|
96
|
-
if (!pushCertificateManager) {
|
|
97
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
98
|
-
}
|
|
99
|
-
const result = yield pushCertificateManager.createSigningRequest(certificateGroupId, certificateTypeId, subjectName, regeneratePrivateKey, nonce);
|
|
100
|
-
if (result.statusCode.isNotGood()) {
|
|
101
|
-
return { statusCode: result.statusCode };
|
|
102
|
-
}
|
|
103
|
-
const callMethodResult = {
|
|
104
|
-
outputArguments: [
|
|
105
|
-
{
|
|
106
|
-
dataType: node_opcua_variant_1.DataType.ByteString,
|
|
107
|
-
value: result.certificateSigningRequest
|
|
108
|
-
}
|
|
109
|
-
],
|
|
110
|
-
statusCode: result.statusCode
|
|
111
|
-
};
|
|
112
|
-
return callMethodResult;
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
function _updateCertificate(inputArguments, context) {
|
|
116
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
const certificateGroupId = inputArguments[0].value;
|
|
118
|
-
const certificateTypeId = inputArguments[1].value;
|
|
119
|
-
const certificate = inputArguments[2].value;
|
|
120
|
-
const issuerCertificates = inputArguments[3].value;
|
|
121
|
-
const privateKeyFormat = inputArguments[4].value;
|
|
122
|
-
const privateKey = inputArguments[5].value;
|
|
123
|
-
// This Method requires an encrypted channel and that the Client provides credentials with
|
|
124
|
-
// administrative rights on the Server
|
|
125
|
-
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
126
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
127
|
-
}
|
|
128
|
-
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
129
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
130
|
-
}
|
|
131
|
-
if (privateKeyFormat && privateKeyFormat !== "" && privateKeyFormat.toLowerCase() !== "pem") {
|
|
132
|
-
errorLog("_updateCertificate: Invalid PEM format requested " + privateKeyFormat);
|
|
133
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
134
|
-
}
|
|
135
|
-
const pushCertificateManager = getPushCertificateManager(this);
|
|
136
|
-
if (!pushCertificateManager) {
|
|
137
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
138
|
-
}
|
|
139
|
-
const result = yield pushCertificateManager.updateCertificate(certificateGroupId, certificateTypeId, certificate, issuerCertificates, privateKeyFormat, privateKey);
|
|
140
|
-
// todo raise a CertificateUpdatedAuditEventType
|
|
141
|
-
if (result.statusCode.isNotGood()) {
|
|
142
|
-
return { statusCode: result.statusCode };
|
|
143
|
-
}
|
|
144
|
-
const callMethodResult = {
|
|
145
|
-
outputArguments: [
|
|
146
|
-
{
|
|
147
|
-
dataType: node_opcua_variant_1.DataType.Boolean,
|
|
148
|
-
value: !!result.applyChangesRequired
|
|
149
|
-
}
|
|
150
|
-
],
|
|
151
|
-
statusCode: result.statusCode
|
|
152
|
-
};
|
|
153
|
-
return callMethodResult;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
function _getRejectedList(inputArguments, context) {
|
|
157
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
159
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
160
|
-
}
|
|
161
|
-
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
162
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
163
|
-
}
|
|
164
|
-
const pushCertificateManager = getPushCertificateManager(this);
|
|
165
|
-
if (!pushCertificateManager) {
|
|
166
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
167
|
-
}
|
|
168
|
-
const result = yield pushCertificateManager.getRejectedList();
|
|
169
|
-
if (result.statusCode.isNotGood()) {
|
|
170
|
-
return { statusCode: result.statusCode };
|
|
171
|
-
}
|
|
172
|
-
return {
|
|
173
|
-
outputArguments: [
|
|
174
|
-
{
|
|
175
|
-
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
176
|
-
dataType: node_opcua_variant_1.DataType.ByteString,
|
|
177
|
-
value: result.certificates
|
|
178
|
-
}
|
|
179
|
-
],
|
|
180
|
-
statusCode: node_opcua_status_code_1.StatusCodes.Good
|
|
181
|
-
};
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
function _applyChanges(inputArguments, context) {
|
|
185
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
// This Method requires an encrypted channel and that the Client provide credentials with
|
|
187
|
-
// administrative rights on the Server.
|
|
188
|
-
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
189
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
190
|
-
}
|
|
191
|
-
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
192
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
193
|
-
}
|
|
194
|
-
const pushCertificateManager = getPushCertificateManager(this);
|
|
195
|
-
if (!pushCertificateManager) {
|
|
196
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
197
|
-
}
|
|
198
|
-
const statusCode = yield pushCertificateManager.applyChanges();
|
|
199
|
-
return { statusCode };
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
function getCertificateFilename(certificateManager) {
|
|
203
|
-
return path.join(certificateManager.rootDir, "own/certs/certificate.pem"); // to do , find a better way
|
|
204
|
-
}
|
|
205
|
-
function getCertificate(certificateManager) {
|
|
206
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
-
try {
|
|
208
|
-
const certificateFile = getCertificateFilename(certificateManager);
|
|
209
|
-
if (fs.existsSync(certificateFile)) {
|
|
210
|
-
const certificate = yield (0, node_opcua_crypto_1.readCertificate)(certificateFile);
|
|
211
|
-
return certificate;
|
|
212
|
-
}
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
catch (err) {
|
|
216
|
-
warningLog("getCertificate Error", err.message);
|
|
217
|
-
return null;
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
function bindCertificateGroup(certificateGroup, certificateManager) {
|
|
222
|
-
if (certificateManager) {
|
|
223
|
-
const certificateFile = getCertificateFilename(certificateManager);
|
|
224
|
-
const changeDetector = (0, install_certificate_file_watcher_1.installCertificateFileWatcher)(certificateGroup, certificateFile);
|
|
225
|
-
changeDetector.on("certificateChange", () => {
|
|
226
|
-
debugLog("detecting certificate change", certificateFile);
|
|
227
|
-
updateCertificateAlarm();
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
function updateCertificateAlarm() {
|
|
231
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
-
try {
|
|
233
|
-
debugLog("updateCertificateAlarm", certificateGroup.browseName.toString());
|
|
234
|
-
const certificateExpired = certificateGroup.getComponentByName("CertificateExpired");
|
|
235
|
-
if (certificateExpired && certificateManager) {
|
|
236
|
-
const certificateExpiredEx = certificateExpired;
|
|
237
|
-
const certificate = yield getCertificate(certificateManager);
|
|
238
|
-
certificateExpiredEx.setCertificate(certificate);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
catch (err) {
|
|
242
|
-
warningLog("updateCertificateAlarm Error", err.message);
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
const addressSpace = certificateGroup.addressSpace;
|
|
247
|
-
if (!certificateManager) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
const trustList = certificateGroup.getComponentByName("TrustList");
|
|
251
|
-
if (trustList) {
|
|
252
|
-
trustList.$$certificateManager = certificateManager;
|
|
253
|
-
}
|
|
254
|
-
const certificateExpired = certificateGroup.getComponentByName("CertificateExpired");
|
|
255
|
-
if (certificateExpired) {
|
|
256
|
-
certificateExpired.$$certificateManager = certificateManager;
|
|
257
|
-
// install alarm handling
|
|
258
|
-
const timerId = setInterval(updateCertificateAlarm, 60 * 1000);
|
|
259
|
-
addressSpace.registerShutdownTask(() => clearInterval(timerId));
|
|
260
|
-
updateCertificateAlarm();
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
function bindCertificateManager(addressSpace, options) {
|
|
264
|
-
const serverConfiguration = addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
265
|
-
const defaultApplicationGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultApplicationGroup");
|
|
266
|
-
if (defaultApplicationGroup) {
|
|
267
|
-
bindCertificateGroup(defaultApplicationGroup, options.applicationGroup);
|
|
268
|
-
}
|
|
269
|
-
const defaultTokenGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultUserTokenGroup");
|
|
270
|
-
if (defaultTokenGroup) {
|
|
271
|
-
bindCertificateGroup(defaultTokenGroup, options.userTokenGroup);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
function setNotifierOfChain(childObject) {
|
|
275
|
-
if (!childObject) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
const parentObject = childObject.parent;
|
|
279
|
-
if (!parentObject) {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
const notifierOf = childObject.findReferencesEx("HasNotifier", node_opcua_data_model_1.BrowseDirection.Inverse);
|
|
283
|
-
if (notifierOf.length === 0) {
|
|
284
|
-
const notifierOfNode = childObject.addReference({
|
|
285
|
-
referenceType: "HasNotifier",
|
|
286
|
-
nodeId: parentObject.nodeId,
|
|
287
|
-
isForward: false
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
parentObject.setEventNotifier(parentObject.eventNotifier | node_opcua_address_space_base_1.EventNotifierFlags.SubscribeToEvents);
|
|
291
|
-
if (parentObject.nodeId.namespace === 0 && parentObject.nodeId.value === node_opcua_constants_1.ObjectIds.Server) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
setNotifierOfChain(parentObject);
|
|
295
|
-
}
|
|
296
|
-
function promoteCertificateGroup(certificateGroup) {
|
|
297
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
298
|
-
const trustList = certificateGroup.getChildByName("TrustList");
|
|
299
|
-
if (trustList) {
|
|
300
|
-
yield (0, promote_trust_list_1.promoteTrustList)(trustList);
|
|
301
|
-
}
|
|
302
|
-
if (!certificateGroup.certificateExpired) {
|
|
303
|
-
const namespace = certificateGroup.addressSpace.getOwnNamespace();
|
|
304
|
-
// certificateGroup.
|
|
305
|
-
(0, node_opcua_address_space_1.instantiateCertificateExpirationAlarm)(namespace, "CertificateExpirationAlarmType", {
|
|
306
|
-
browseName: (0, node_opcua_data_model_1.coerceQualifiedName)("0:CertificateExpired"),
|
|
307
|
-
componentOf: certificateGroup,
|
|
308
|
-
conditionSource: null,
|
|
309
|
-
conditionOf: certificateGroup,
|
|
310
|
-
inputNode: node_opcua_nodeid_1.NodeId.nullNodeId,
|
|
311
|
-
normalState: node_opcua_nodeid_1.NodeId.nullNodeId,
|
|
312
|
-
optionals: ["ExpirationLimit"],
|
|
313
|
-
conditionName: "CertificateExpired",
|
|
314
|
-
conditionClass: (0, node_opcua_nodeid_1.resolveNodeId)("CertificateExpirationAlarmType"),
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
certificateGroup.setEventNotifier(node_opcua_address_space_base_1.EventNotifierFlags.SubscribeToEvents);
|
|
318
|
-
setNotifierOfChain(certificateGroup);
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
exports.promoteCertificateGroup = promoteCertificateGroup;
|
|
322
|
-
;
|
|
323
|
-
function installPushCertificateManagement(addressSpace, options) {
|
|
324
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
325
|
-
addressSpace.installAlarmsAndConditionsService();
|
|
326
|
-
const serverConfiguration = addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
327
|
-
const serverConfigurationPriv = serverConfiguration;
|
|
328
|
-
if (serverConfigurationPriv.$pushCertificateManager) {
|
|
329
|
-
warningLog("PushCertificateManagement has already been installed");
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
const accessRestrictionFlag = node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired;
|
|
333
|
-
function installAccessRestrictions(serverConfiguration) {
|
|
334
|
-
serverConfiguration.setRolePermissions(roles_and_permissions_1.rolePermissionRestricted);
|
|
335
|
-
serverConfiguration.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.None);
|
|
336
|
-
const applyName = serverConfiguration.getMethodByName("ApplyChanges");
|
|
337
|
-
applyName === null || applyName === void 0 ? void 0 : applyName.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
338
|
-
applyName === null || applyName === void 0 ? void 0 : applyName.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired);
|
|
339
|
-
const createSigningRequest = serverConfiguration.getMethodByName("CreateSigningRequest");
|
|
340
|
-
createSigningRequest === null || createSigningRequest === void 0 ? void 0 : createSigningRequest.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
341
|
-
createSigningRequest === null || createSigningRequest === void 0 ? void 0 : createSigningRequest.setAccessRestrictions(accessRestrictionFlag);
|
|
342
|
-
const getRejectedList = serverConfiguration.getMethodByName("GetRejectedList");
|
|
343
|
-
getRejectedList === null || getRejectedList === void 0 ? void 0 : getRejectedList.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
344
|
-
getRejectedList === null || getRejectedList === void 0 ? void 0 : getRejectedList.setAccessRestrictions(accessRestrictionFlag);
|
|
345
|
-
const updateCertificate = serverConfiguration.getMethodByName("UpdateCertificate");
|
|
346
|
-
updateCertificate === null || updateCertificate === void 0 ? void 0 : updateCertificate.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
347
|
-
updateCertificate === null || updateCertificate === void 0 ? void 0 : updateCertificate.setAccessRestrictions(accessRestrictionFlag);
|
|
348
|
-
const certificateGroups = serverConfiguration.getComponentByName("CertificateGroups");
|
|
349
|
-
certificateGroups.setRolePermissions(roles_and_permissions_1.rolePermissionRestricted);
|
|
350
|
-
certificateGroups.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.None);
|
|
351
|
-
function installAccessRestrictionOnGroup(group) {
|
|
352
|
-
const trustList = group.getComponentByName("TrustList");
|
|
353
|
-
if (trustList) {
|
|
354
|
-
(0, promote_trust_list_1.installAccessRestrictionOnTrustList)(trustList);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
for (const group of certificateGroups.getComponents()) {
|
|
358
|
-
group.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
359
|
-
group.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired);
|
|
360
|
-
if (group.nodeClass === node_opcua_data_model_1.NodeClass.Object) {
|
|
361
|
-
installAccessRestrictionOnGroup(group);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
installAccessRestrictions(serverConfiguration);
|
|
366
|
-
serverConfigurationPriv.$pushCertificateManager = new push_certificate_manager_server_impl_1.PushCertificateManagerServerImpl(options);
|
|
367
|
-
serverConfiguration.supportedPrivateKeyFormats.setValueFromSource({
|
|
368
|
-
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
369
|
-
dataType: node_opcua_variant_1.DataType.String,
|
|
370
|
-
value: ["PEM"]
|
|
371
|
-
});
|
|
372
|
-
function install_method_handle_on_type(addressSpace) {
|
|
373
|
-
const serverConfigurationType = addressSpace.findObjectType("ServerConfigurationType");
|
|
374
|
-
if (serverConfigurationType.createSigningRequest.isBound()) {
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
serverConfigurationType.createSigningRequest.bindMethod(_createSigningRequest);
|
|
378
|
-
serverConfigurationType.getRejectedList.bindMethod(_getRejectedList);
|
|
379
|
-
serverConfigurationType.updateCertificate.bindMethod(_updateCertificate);
|
|
380
|
-
serverConfigurationType.applyChanges.bindMethod(_applyChanges);
|
|
381
|
-
}
|
|
382
|
-
install_method_handle_on_type(addressSpace);
|
|
383
|
-
serverConfiguration.createSigningRequest.bindMethod(_createSigningRequest);
|
|
384
|
-
serverConfiguration.updateCertificate.bindMethod(_updateCertificate);
|
|
385
|
-
serverConfiguration.getRejectedList.bindMethod(_getRejectedList);
|
|
386
|
-
if (serverConfiguration.applyChanges) {
|
|
387
|
-
serverConfiguration.applyChanges.bindMethod(_applyChanges);
|
|
388
|
-
}
|
|
389
|
-
const cg = serverConfiguration.certificateGroups.getComponents();
|
|
390
|
-
const defaultApplicationGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultApplicationGroup");
|
|
391
|
-
const certificateTypes = defaultApplicationGroup.getPropertyByName("CertificateTypes");
|
|
392
|
-
certificateTypes.setValueFromSource({
|
|
393
|
-
dataType: node_opcua_variant_1.DataType.NodeId,
|
|
394
|
-
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
395
|
-
value: [(0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.ObjectTypeIds.RsaSha256ApplicationCertificateType)]
|
|
396
|
-
});
|
|
397
|
-
const certificateGroupType = addressSpace.findObjectType("CertificateGroupType");
|
|
398
|
-
for (const certificateGroup of cg) {
|
|
399
|
-
if (certificateGroup.nodeClass !== node_opcua_data_model_1.NodeClass.Object) {
|
|
400
|
-
continue;
|
|
401
|
-
}
|
|
402
|
-
const o = certificateGroup;
|
|
403
|
-
if (!o.typeDefinitionObj.isSubtypeOf(certificateGroupType)) {
|
|
404
|
-
continue;
|
|
405
|
-
}
|
|
406
|
-
yield promoteCertificateGroup(certificateGroup);
|
|
407
|
-
}
|
|
408
|
-
yield bindCertificateManager(addressSpace, options);
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
exports.installPushCertificateManagement = installPushCertificateManagement;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.installPushCertificateManagement = exports.promoteCertificateGroup = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* @module node-opcua-server-configuration
|
|
15
|
+
*/
|
|
16
|
+
const path = require("path");
|
|
17
|
+
const fs = require("fs");
|
|
18
|
+
const node_opcua_address_space_1 = require("node-opcua-address-space");
|
|
19
|
+
const node_opcua_address_space_base_1 = require("node-opcua-address-space-base");
|
|
20
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
21
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
22
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
23
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
24
|
+
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
25
|
+
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
26
|
+
const node_opcua_crypto_1 = require("node-opcua-crypto");
|
|
27
|
+
const push_certificate_manager_server_impl_1 = require("./push_certificate_manager_server_impl");
|
|
28
|
+
const promote_trust_list_1 = require("./promote_trust_list");
|
|
29
|
+
const tools_1 = require("./tools");
|
|
30
|
+
const roles_and_permissions_1 = require("./roles_and_permissions");
|
|
31
|
+
const install_certificate_file_watcher_1 = require("./install_certificate_file_watcher");
|
|
32
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)("ServerConfiguration");
|
|
33
|
+
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("ServerConfiguration");
|
|
34
|
+
const warningLog = (0, node_opcua_debug_1.make_warningLog)("ServerConfiguration");
|
|
35
|
+
const errorLog = debugLog;
|
|
36
|
+
function expected(variant, dataType, variantArrayType) {
|
|
37
|
+
if (!variant) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (variant.dataType !== dataType) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (variant.arrayType !== variantArrayType) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
function getPushCertificateManager(method) {
|
|
49
|
+
const serverConfiguration = method.addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
50
|
+
const serverConfigurationPriv = serverConfiguration;
|
|
51
|
+
if (serverConfigurationPriv.$pushCertificateManager) {
|
|
52
|
+
return serverConfigurationPriv.$pushCertificateManager;
|
|
53
|
+
}
|
|
54
|
+
// throw new Error("Cannot find pushCertificateManager object");
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
function _createSigningRequest(inputArguments, context) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const certificateGroupIdVariant = inputArguments[0];
|
|
60
|
+
const certificateTypeIdVariant = inputArguments[1];
|
|
61
|
+
const subjectNameVariant = inputArguments[2];
|
|
62
|
+
const regeneratePrivateKeyVariant = inputArguments[3];
|
|
63
|
+
const nonceVariant = inputArguments[4];
|
|
64
|
+
if (!expected(certificateGroupIdVariant, node_opcua_variant_1.DataType.NodeId, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
65
|
+
warningLog("expecting an NodeId for certificateGroupId - 0");
|
|
66
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
67
|
+
}
|
|
68
|
+
if (!expected(certificateTypeIdVariant, node_opcua_variant_1.DataType.NodeId, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
69
|
+
warningLog("expecting an NodeId for certificateTypeId - 1");
|
|
70
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
71
|
+
}
|
|
72
|
+
if (!expected(subjectNameVariant, node_opcua_variant_1.DataType.String, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
73
|
+
warningLog("expecting an String for subjectName - 2");
|
|
74
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
75
|
+
}
|
|
76
|
+
if (!expected(regeneratePrivateKeyVariant, node_opcua_variant_1.DataType.Boolean, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
77
|
+
warningLog("expecting an Boolean for regeneratePrivateKey - 3");
|
|
78
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
79
|
+
}
|
|
80
|
+
if (!expected(nonceVariant, node_opcua_variant_1.DataType.ByteString, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
81
|
+
warningLog("expecting an ByteString for nonceVariant - 4");
|
|
82
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
83
|
+
}
|
|
84
|
+
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
85
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
86
|
+
}
|
|
87
|
+
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
88
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
89
|
+
}
|
|
90
|
+
const certificateGroupId = certificateGroupIdVariant.value;
|
|
91
|
+
const certificateTypeId = certificateTypeIdVariant.value;
|
|
92
|
+
const subjectName = subjectNameVariant.value;
|
|
93
|
+
const regeneratePrivateKey = regeneratePrivateKeyVariant.value;
|
|
94
|
+
const nonce = nonceVariant.value;
|
|
95
|
+
const pushCertificateManager = getPushCertificateManager(this);
|
|
96
|
+
if (!pushCertificateManager) {
|
|
97
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
98
|
+
}
|
|
99
|
+
const result = yield pushCertificateManager.createSigningRequest(certificateGroupId, certificateTypeId, subjectName, regeneratePrivateKey, nonce);
|
|
100
|
+
if (result.statusCode.isNotGood()) {
|
|
101
|
+
return { statusCode: result.statusCode };
|
|
102
|
+
}
|
|
103
|
+
const callMethodResult = {
|
|
104
|
+
outputArguments: [
|
|
105
|
+
{
|
|
106
|
+
dataType: node_opcua_variant_1.DataType.ByteString,
|
|
107
|
+
value: result.certificateSigningRequest
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
statusCode: result.statusCode
|
|
111
|
+
};
|
|
112
|
+
return callMethodResult;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function _updateCertificate(inputArguments, context) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const certificateGroupId = inputArguments[0].value;
|
|
118
|
+
const certificateTypeId = inputArguments[1].value;
|
|
119
|
+
const certificate = inputArguments[2].value;
|
|
120
|
+
const issuerCertificates = inputArguments[3].value;
|
|
121
|
+
const privateKeyFormat = inputArguments[4].value;
|
|
122
|
+
const privateKey = inputArguments[5].value;
|
|
123
|
+
// This Method requires an encrypted channel and that the Client provides credentials with
|
|
124
|
+
// administrative rights on the Server
|
|
125
|
+
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
126
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
127
|
+
}
|
|
128
|
+
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
129
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
130
|
+
}
|
|
131
|
+
if (privateKeyFormat && privateKeyFormat !== "" && privateKeyFormat.toLowerCase() !== "pem") {
|
|
132
|
+
errorLog("_updateCertificate: Invalid PEM format requested " + privateKeyFormat);
|
|
133
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
134
|
+
}
|
|
135
|
+
const pushCertificateManager = getPushCertificateManager(this);
|
|
136
|
+
if (!pushCertificateManager) {
|
|
137
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
138
|
+
}
|
|
139
|
+
const result = yield pushCertificateManager.updateCertificate(certificateGroupId, certificateTypeId, certificate, issuerCertificates, privateKeyFormat, privateKey);
|
|
140
|
+
// todo raise a CertificateUpdatedAuditEventType
|
|
141
|
+
if (result.statusCode.isNotGood()) {
|
|
142
|
+
return { statusCode: result.statusCode };
|
|
143
|
+
}
|
|
144
|
+
const callMethodResult = {
|
|
145
|
+
outputArguments: [
|
|
146
|
+
{
|
|
147
|
+
dataType: node_opcua_variant_1.DataType.Boolean,
|
|
148
|
+
value: !!result.applyChangesRequired
|
|
149
|
+
}
|
|
150
|
+
],
|
|
151
|
+
statusCode: result.statusCode
|
|
152
|
+
};
|
|
153
|
+
return callMethodResult;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function _getRejectedList(inputArguments, context) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
159
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
160
|
+
}
|
|
161
|
+
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
162
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
163
|
+
}
|
|
164
|
+
const pushCertificateManager = getPushCertificateManager(this);
|
|
165
|
+
if (!pushCertificateManager) {
|
|
166
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
167
|
+
}
|
|
168
|
+
const result = yield pushCertificateManager.getRejectedList();
|
|
169
|
+
if (result.statusCode.isNotGood()) {
|
|
170
|
+
return { statusCode: result.statusCode };
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
outputArguments: [
|
|
174
|
+
{
|
|
175
|
+
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
176
|
+
dataType: node_opcua_variant_1.DataType.ByteString,
|
|
177
|
+
value: result.certificates
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
statusCode: node_opcua_status_code_1.StatusCodes.Good
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function _applyChanges(inputArguments, context) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
// This Method requires an encrypted channel and that the Client provide credentials with
|
|
187
|
+
// administrative rights on the Server.
|
|
188
|
+
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
189
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
190
|
+
}
|
|
191
|
+
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
192
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
193
|
+
}
|
|
194
|
+
const pushCertificateManager = getPushCertificateManager(this);
|
|
195
|
+
if (!pushCertificateManager) {
|
|
196
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
197
|
+
}
|
|
198
|
+
const statusCode = yield pushCertificateManager.applyChanges();
|
|
199
|
+
return { statusCode };
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function getCertificateFilename(certificateManager) {
|
|
203
|
+
return path.join(certificateManager.rootDir, "own/certs/certificate.pem"); // to do , find a better way
|
|
204
|
+
}
|
|
205
|
+
function getCertificate(certificateManager) {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
try {
|
|
208
|
+
const certificateFile = getCertificateFilename(certificateManager);
|
|
209
|
+
if (fs.existsSync(certificateFile)) {
|
|
210
|
+
const certificate = yield (0, node_opcua_crypto_1.readCertificate)(certificateFile);
|
|
211
|
+
return certificate;
|
|
212
|
+
}
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
warningLog("getCertificate Error", err.message);
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function bindCertificateGroup(certificateGroup, certificateManager) {
|
|
222
|
+
if (certificateManager) {
|
|
223
|
+
const certificateFile = getCertificateFilename(certificateManager);
|
|
224
|
+
const changeDetector = (0, install_certificate_file_watcher_1.installCertificateFileWatcher)(certificateGroup, certificateFile);
|
|
225
|
+
changeDetector.on("certificateChange", () => {
|
|
226
|
+
debugLog("detecting certificate change", certificateFile);
|
|
227
|
+
updateCertificateAlarm();
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function updateCertificateAlarm() {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
try {
|
|
233
|
+
debugLog("updateCertificateAlarm", certificateGroup.browseName.toString());
|
|
234
|
+
const certificateExpired = certificateGroup.getComponentByName("CertificateExpired");
|
|
235
|
+
if (certificateExpired && certificateManager) {
|
|
236
|
+
const certificateExpiredEx = certificateExpired;
|
|
237
|
+
const certificate = yield getCertificate(certificateManager);
|
|
238
|
+
certificateExpiredEx.setCertificate(certificate);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (err) {
|
|
242
|
+
warningLog("updateCertificateAlarm Error", err.message);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
const addressSpace = certificateGroup.addressSpace;
|
|
247
|
+
if (!certificateManager) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const trustList = certificateGroup.getComponentByName("TrustList");
|
|
251
|
+
if (trustList) {
|
|
252
|
+
trustList.$$certificateManager = certificateManager;
|
|
253
|
+
}
|
|
254
|
+
const certificateExpired = certificateGroup.getComponentByName("CertificateExpired");
|
|
255
|
+
if (certificateExpired) {
|
|
256
|
+
certificateExpired.$$certificateManager = certificateManager;
|
|
257
|
+
// install alarm handling
|
|
258
|
+
const timerId = setInterval(updateCertificateAlarm, 60 * 1000);
|
|
259
|
+
addressSpace.registerShutdownTask(() => clearInterval(timerId));
|
|
260
|
+
updateCertificateAlarm();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function bindCertificateManager(addressSpace, options) {
|
|
264
|
+
const serverConfiguration = addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
265
|
+
const defaultApplicationGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultApplicationGroup");
|
|
266
|
+
if (defaultApplicationGroup) {
|
|
267
|
+
bindCertificateGroup(defaultApplicationGroup, options.applicationGroup);
|
|
268
|
+
}
|
|
269
|
+
const defaultTokenGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultUserTokenGroup");
|
|
270
|
+
if (defaultTokenGroup) {
|
|
271
|
+
bindCertificateGroup(defaultTokenGroup, options.userTokenGroup);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function setNotifierOfChain(childObject) {
|
|
275
|
+
if (!childObject) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const parentObject = childObject.parent;
|
|
279
|
+
if (!parentObject) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const notifierOf = childObject.findReferencesEx("HasNotifier", node_opcua_data_model_1.BrowseDirection.Inverse);
|
|
283
|
+
if (notifierOf.length === 0) {
|
|
284
|
+
const notifierOfNode = childObject.addReference({
|
|
285
|
+
referenceType: "HasNotifier",
|
|
286
|
+
nodeId: parentObject.nodeId,
|
|
287
|
+
isForward: false
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
parentObject.setEventNotifier(parentObject.eventNotifier | node_opcua_address_space_base_1.EventNotifierFlags.SubscribeToEvents);
|
|
291
|
+
if (parentObject.nodeId.namespace === 0 && parentObject.nodeId.value === node_opcua_constants_1.ObjectIds.Server) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
setNotifierOfChain(parentObject);
|
|
295
|
+
}
|
|
296
|
+
function promoteCertificateGroup(certificateGroup) {
|
|
297
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
298
|
+
const trustList = certificateGroup.getChildByName("TrustList");
|
|
299
|
+
if (trustList) {
|
|
300
|
+
yield (0, promote_trust_list_1.promoteTrustList)(trustList);
|
|
301
|
+
}
|
|
302
|
+
if (!certificateGroup.certificateExpired) {
|
|
303
|
+
const namespace = certificateGroup.addressSpace.getOwnNamespace();
|
|
304
|
+
// certificateGroup.
|
|
305
|
+
(0, node_opcua_address_space_1.instantiateCertificateExpirationAlarm)(namespace, "CertificateExpirationAlarmType", {
|
|
306
|
+
browseName: (0, node_opcua_data_model_1.coerceQualifiedName)("0:CertificateExpired"),
|
|
307
|
+
componentOf: certificateGroup,
|
|
308
|
+
conditionSource: null,
|
|
309
|
+
conditionOf: certificateGroup,
|
|
310
|
+
inputNode: node_opcua_nodeid_1.NodeId.nullNodeId,
|
|
311
|
+
normalState: node_opcua_nodeid_1.NodeId.nullNodeId,
|
|
312
|
+
optionals: ["ExpirationLimit"],
|
|
313
|
+
conditionName: "CertificateExpired",
|
|
314
|
+
conditionClass: (0, node_opcua_nodeid_1.resolveNodeId)("CertificateExpirationAlarmType"),
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
certificateGroup.setEventNotifier(node_opcua_address_space_base_1.EventNotifierFlags.SubscribeToEvents);
|
|
318
|
+
setNotifierOfChain(certificateGroup);
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
exports.promoteCertificateGroup = promoteCertificateGroup;
|
|
322
|
+
;
|
|
323
|
+
function installPushCertificateManagement(addressSpace, options) {
|
|
324
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
325
|
+
addressSpace.installAlarmsAndConditionsService();
|
|
326
|
+
const serverConfiguration = addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
327
|
+
const serverConfigurationPriv = serverConfiguration;
|
|
328
|
+
if (serverConfigurationPriv.$pushCertificateManager) {
|
|
329
|
+
warningLog("PushCertificateManagement has already been installed");
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const accessRestrictionFlag = node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired;
|
|
333
|
+
function installAccessRestrictions(serverConfiguration) {
|
|
334
|
+
serverConfiguration.setRolePermissions(roles_and_permissions_1.rolePermissionRestricted);
|
|
335
|
+
serverConfiguration.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.None);
|
|
336
|
+
const applyName = serverConfiguration.getMethodByName("ApplyChanges");
|
|
337
|
+
applyName === null || applyName === void 0 ? void 0 : applyName.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
338
|
+
applyName === null || applyName === void 0 ? void 0 : applyName.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired);
|
|
339
|
+
const createSigningRequest = serverConfiguration.getMethodByName("CreateSigningRequest");
|
|
340
|
+
createSigningRequest === null || createSigningRequest === void 0 ? void 0 : createSigningRequest.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
341
|
+
createSigningRequest === null || createSigningRequest === void 0 ? void 0 : createSigningRequest.setAccessRestrictions(accessRestrictionFlag);
|
|
342
|
+
const getRejectedList = serverConfiguration.getMethodByName("GetRejectedList");
|
|
343
|
+
getRejectedList === null || getRejectedList === void 0 ? void 0 : getRejectedList.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
344
|
+
getRejectedList === null || getRejectedList === void 0 ? void 0 : getRejectedList.setAccessRestrictions(accessRestrictionFlag);
|
|
345
|
+
const updateCertificate = serverConfiguration.getMethodByName("UpdateCertificate");
|
|
346
|
+
updateCertificate === null || updateCertificate === void 0 ? void 0 : updateCertificate.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
347
|
+
updateCertificate === null || updateCertificate === void 0 ? void 0 : updateCertificate.setAccessRestrictions(accessRestrictionFlag);
|
|
348
|
+
const certificateGroups = serverConfiguration.getComponentByName("CertificateGroups");
|
|
349
|
+
certificateGroups.setRolePermissions(roles_and_permissions_1.rolePermissionRestricted);
|
|
350
|
+
certificateGroups.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.None);
|
|
351
|
+
function installAccessRestrictionOnGroup(group) {
|
|
352
|
+
const trustList = group.getComponentByName("TrustList");
|
|
353
|
+
if (trustList) {
|
|
354
|
+
(0, promote_trust_list_1.installAccessRestrictionOnTrustList)(trustList);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
for (const group of certificateGroups.getComponents()) {
|
|
358
|
+
group.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
359
|
+
group.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired);
|
|
360
|
+
if (group.nodeClass === node_opcua_data_model_1.NodeClass.Object) {
|
|
361
|
+
installAccessRestrictionOnGroup(group);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
installAccessRestrictions(serverConfiguration);
|
|
366
|
+
serverConfigurationPriv.$pushCertificateManager = new push_certificate_manager_server_impl_1.PushCertificateManagerServerImpl(options);
|
|
367
|
+
serverConfiguration.supportedPrivateKeyFormats.setValueFromSource({
|
|
368
|
+
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
369
|
+
dataType: node_opcua_variant_1.DataType.String,
|
|
370
|
+
value: ["PEM"]
|
|
371
|
+
});
|
|
372
|
+
function install_method_handle_on_type(addressSpace) {
|
|
373
|
+
const serverConfigurationType = addressSpace.findObjectType("ServerConfigurationType");
|
|
374
|
+
if (serverConfigurationType.createSigningRequest.isBound()) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
serverConfigurationType.createSigningRequest.bindMethod(_createSigningRequest);
|
|
378
|
+
serverConfigurationType.getRejectedList.bindMethod(_getRejectedList);
|
|
379
|
+
serverConfigurationType.updateCertificate.bindMethod(_updateCertificate);
|
|
380
|
+
serverConfigurationType.applyChanges.bindMethod(_applyChanges);
|
|
381
|
+
}
|
|
382
|
+
install_method_handle_on_type(addressSpace);
|
|
383
|
+
serverConfiguration.createSigningRequest.bindMethod(_createSigningRequest);
|
|
384
|
+
serverConfiguration.updateCertificate.bindMethod(_updateCertificate);
|
|
385
|
+
serverConfiguration.getRejectedList.bindMethod(_getRejectedList);
|
|
386
|
+
if (serverConfiguration.applyChanges) {
|
|
387
|
+
serverConfiguration.applyChanges.bindMethod(_applyChanges);
|
|
388
|
+
}
|
|
389
|
+
const cg = serverConfiguration.certificateGroups.getComponents();
|
|
390
|
+
const defaultApplicationGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultApplicationGroup");
|
|
391
|
+
const certificateTypes = defaultApplicationGroup.getPropertyByName("CertificateTypes");
|
|
392
|
+
certificateTypes.setValueFromSource({
|
|
393
|
+
dataType: node_opcua_variant_1.DataType.NodeId,
|
|
394
|
+
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
395
|
+
value: [(0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.ObjectTypeIds.RsaSha256ApplicationCertificateType)]
|
|
396
|
+
});
|
|
397
|
+
const certificateGroupType = addressSpace.findObjectType("CertificateGroupType");
|
|
398
|
+
for (const certificateGroup of cg) {
|
|
399
|
+
if (certificateGroup.nodeClass !== node_opcua_data_model_1.NodeClass.Object) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
const o = certificateGroup;
|
|
403
|
+
if (!o.typeDefinitionObj.isSubtypeOf(certificateGroupType)) {
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
yield promoteCertificateGroup(certificateGroup);
|
|
407
|
+
}
|
|
408
|
+
yield bindCertificateManager(addressSpace, options);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
exports.installPushCertificateManagement = installPushCertificateManagement;
|
|
412
412
|
//# sourceMappingURL=push_certificate_manager_helpers.js.map
|