node-opcua-server-configuration 2.70.3 → 2.71.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/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 +465 -465
- 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/push_certificate_manager_helpers.d.ts +6 -0
- package/dist/push_certificate_manager_helpers.js +221 -0
- package/dist/push_certificate_manager_helpers.js.map +1 -0
- package/dist/server/install_CertificateAlarm.d.ts +5 -5
- package/dist/server/install_CertificateAlarm.js +37 -37
- package/dist/server/install_push_certitifate_management.d.ts +15 -15
- package/dist/server/install_push_certitifate_management.js +214 -214
- 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 +7 -7
- package/dist/server/push_certificate_manager_helpers.js +306 -306
- package/dist/server/push_certificate_manager_server_impl.d.ts +49 -49
- package/dist/server/push_certificate_manager_server_impl.js +522 -522
- package/dist/server/roles_and_permissions.d.ts +3 -3
- package/dist/server/roles_and_permissions.js +40 -40
- 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 +24 -24
|
@@ -1,307 +1,307 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module node-opcua-server-configuration
|
|
4
|
-
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.installPushCertificateManagement = exports.promoteCertificateGroup = void 0;
|
|
16
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
17
|
-
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
18
|
-
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
19
|
-
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
20
|
-
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
21
|
-
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
22
|
-
const install_CertificateAlarm_1 = require("./install_CertificateAlarm");
|
|
23
|
-
const push_certificate_manager_server_impl_1 = require("./push_certificate_manager_server_impl");
|
|
24
|
-
const promote_trust_list_1 = require("./promote_trust_list");
|
|
25
|
-
const tools_1 = require("./tools");
|
|
26
|
-
const roles_and_permissions_1 = require("./roles_and_permissions");
|
|
27
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)("ServerConfiguration");
|
|
28
|
-
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("ServerConfiguration");
|
|
29
|
-
const warningLog = (0, node_opcua_debug_1.make_warningLog)("ServerConfiguration");
|
|
30
|
-
const errorLog = debugLog;
|
|
31
|
-
function expected(variant, dataType, variantArrayType) {
|
|
32
|
-
if (!variant) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
if (variant.dataType !== dataType) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
if (variant.arrayType !== variantArrayType) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
function getPushCertificateManager(method) {
|
|
44
|
-
const serverConfiguration = method.addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
45
|
-
const serverConfigurationPriv = serverConfiguration;
|
|
46
|
-
if (serverConfigurationPriv.$pushCertificateManager) {
|
|
47
|
-
return serverConfigurationPriv.$pushCertificateManager;
|
|
48
|
-
}
|
|
49
|
-
// throw new Error("Cannot find pushCertificateManager object");
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
function _createSigningRequest(inputArguments, context) {
|
|
53
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const certificateGroupIdVariant = inputArguments[0];
|
|
55
|
-
const certificateTypeIdVariant = inputArguments[1];
|
|
56
|
-
const subjectNameVariant = inputArguments[2];
|
|
57
|
-
const regeneratePrivateKeyVariant = inputArguments[3];
|
|
58
|
-
const nonceVariant = inputArguments[4];
|
|
59
|
-
if (!expected(certificateGroupIdVariant, node_opcua_variant_1.DataType.NodeId, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
60
|
-
warningLog("expecting an NodeId for certificateGroupId - 0");
|
|
61
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
62
|
-
}
|
|
63
|
-
if (!expected(certificateTypeIdVariant, node_opcua_variant_1.DataType.NodeId, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
64
|
-
warningLog("expecting an NodeId for certificateTypeId - 1");
|
|
65
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
66
|
-
}
|
|
67
|
-
if (!expected(subjectNameVariant, node_opcua_variant_1.DataType.String, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
68
|
-
warningLog("expecting an String for subjectName - 2");
|
|
69
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
70
|
-
}
|
|
71
|
-
if (!expected(regeneratePrivateKeyVariant, node_opcua_variant_1.DataType.Boolean, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
72
|
-
warningLog("expecting an Boolean for regeneratePrivateKey - 3");
|
|
73
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
74
|
-
}
|
|
75
|
-
if (!expected(nonceVariant, node_opcua_variant_1.DataType.ByteString, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
76
|
-
warningLog("expecting an ByteString for nonceVariant - 4");
|
|
77
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
78
|
-
}
|
|
79
|
-
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
80
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
81
|
-
}
|
|
82
|
-
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
83
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
84
|
-
}
|
|
85
|
-
const certificateGroupId = certificateGroupIdVariant.value;
|
|
86
|
-
const certificateTypeId = certificateTypeIdVariant.value;
|
|
87
|
-
const subjectName = subjectNameVariant.value;
|
|
88
|
-
const regeneratePrivateKey = regeneratePrivateKeyVariant.value;
|
|
89
|
-
const nonce = nonceVariant.value;
|
|
90
|
-
const pushCertificateManager = getPushCertificateManager(this);
|
|
91
|
-
if (!pushCertificateManager) {
|
|
92
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
93
|
-
}
|
|
94
|
-
const result = yield pushCertificateManager.createSigningRequest(certificateGroupId, certificateTypeId, subjectName, regeneratePrivateKey, nonce);
|
|
95
|
-
if (result.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
|
|
96
|
-
return { statusCode: result.statusCode };
|
|
97
|
-
}
|
|
98
|
-
const callMethodResult = {
|
|
99
|
-
outputArguments: [
|
|
100
|
-
{
|
|
101
|
-
dataType: node_opcua_variant_1.DataType.ByteString,
|
|
102
|
-
value: result.certificateSigningRequest
|
|
103
|
-
}
|
|
104
|
-
],
|
|
105
|
-
statusCode: result.statusCode
|
|
106
|
-
};
|
|
107
|
-
return callMethodResult;
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
function _updateCertificate(inputArguments, context) {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
const certificateGroupId = inputArguments[0].value;
|
|
113
|
-
const certificateTypeId = inputArguments[1].value;
|
|
114
|
-
const certificate = inputArguments[2].value;
|
|
115
|
-
const issuerCertificates = inputArguments[3].value;
|
|
116
|
-
const privateKeyFormat = inputArguments[4].value;
|
|
117
|
-
const privateKey = inputArguments[5].value;
|
|
118
|
-
// This Method requires an encrypted channel and that the Client provides credentials with
|
|
119
|
-
// administrative rights on the Server
|
|
120
|
-
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
121
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
122
|
-
}
|
|
123
|
-
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
124
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
125
|
-
}
|
|
126
|
-
if (privateKeyFormat && privateKeyFormat !== "" && privateKeyFormat.toLowerCase() !== "pem") {
|
|
127
|
-
errorLog("_updateCertificate: Invalid PEM format requested " + privateKeyFormat);
|
|
128
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
129
|
-
}
|
|
130
|
-
const pushCertificateManager = getPushCertificateManager(this);
|
|
131
|
-
if (!pushCertificateManager) {
|
|
132
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
133
|
-
}
|
|
134
|
-
const result = yield pushCertificateManager.updateCertificate(certificateGroupId, certificateTypeId, certificate, issuerCertificates, privateKeyFormat, privateKey);
|
|
135
|
-
// todo raise a CertificateUpdatedAuditEventType
|
|
136
|
-
if (result.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
|
|
137
|
-
return { statusCode: result.statusCode };
|
|
138
|
-
}
|
|
139
|
-
const callMethodResult = {
|
|
140
|
-
outputArguments: [
|
|
141
|
-
{
|
|
142
|
-
dataType: node_opcua_variant_1.DataType.Boolean,
|
|
143
|
-
value: !!result.applyChangesRequired
|
|
144
|
-
}
|
|
145
|
-
],
|
|
146
|
-
statusCode: result.statusCode
|
|
147
|
-
};
|
|
148
|
-
return callMethodResult;
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
function _getRejectedList(inputArguments, context) {
|
|
152
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
154
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
155
|
-
}
|
|
156
|
-
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
157
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
158
|
-
}
|
|
159
|
-
const pushCertificateManager = getPushCertificateManager(this);
|
|
160
|
-
if (!pushCertificateManager) {
|
|
161
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
162
|
-
}
|
|
163
|
-
const result = yield pushCertificateManager.getRejectedList();
|
|
164
|
-
if (result.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
|
|
165
|
-
return { statusCode: result.statusCode };
|
|
166
|
-
}
|
|
167
|
-
return {
|
|
168
|
-
outputArguments: [
|
|
169
|
-
{
|
|
170
|
-
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
171
|
-
dataType: node_opcua_variant_1.DataType.ByteString,
|
|
172
|
-
value: result.certificates
|
|
173
|
-
}
|
|
174
|
-
],
|
|
175
|
-
statusCode: node_opcua_status_code_1.StatusCodes.Good
|
|
176
|
-
};
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
function _applyChanges(inputArguments, context) {
|
|
180
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
-
// This Method requires an encrypted channel and that the Client provide credentials with
|
|
182
|
-
// administrative rights on the Server.
|
|
183
|
-
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
184
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
185
|
-
}
|
|
186
|
-
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
187
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
188
|
-
}
|
|
189
|
-
const pushCertificateManager = getPushCertificateManager(this);
|
|
190
|
-
if (!pushCertificateManager) {
|
|
191
|
-
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
192
|
-
}
|
|
193
|
-
const statusCode = yield pushCertificateManager.applyChanges();
|
|
194
|
-
return { statusCode };
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
function bindCertificateManager(addressSpace, options) {
|
|
198
|
-
const serverConfiguration = addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
199
|
-
const defaultApplicationGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultApplicationGroup");
|
|
200
|
-
if (defaultApplicationGroup) {
|
|
201
|
-
const trustList = defaultApplicationGroup.getComponentByName("TrustList");
|
|
202
|
-
if (trustList) {
|
|
203
|
-
trustList.$$certificateManager = options.applicationGroup;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
const defaultTokenGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultUserTokenGroup");
|
|
207
|
-
if (defaultTokenGroup) {
|
|
208
|
-
const trustList = defaultTokenGroup.getComponentByName("TrustList");
|
|
209
|
-
if (trustList) {
|
|
210
|
-
trustList.$$certificateManager = options.userTokenGroup;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function promoteCertificateGroup(certificateGroup) {
|
|
215
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
-
const trustList = certificateGroup.getChildByName("TrustList");
|
|
217
|
-
if (trustList) {
|
|
218
|
-
(0, promote_trust_list_1.promoteTrustList)(trustList);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
exports.promoteCertificateGroup = promoteCertificateGroup;
|
|
223
|
-
function installPushCertificateManagement(addressSpace, options) {
|
|
224
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
-
const serverConfiguration = addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
226
|
-
const serverConfigurationPriv = serverConfiguration;
|
|
227
|
-
if (serverConfigurationPriv.$pushCertificateManager) {
|
|
228
|
-
warningLog("PushCertificateManagement has already been installed");
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const accessRestrictionFlag = node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired;
|
|
232
|
-
function installAccessRestrictions(serverConfiguration) {
|
|
233
|
-
serverConfiguration.setRolePermissions(roles_and_permissions_1.rolePermissionRestricted);
|
|
234
|
-
serverConfiguration.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.None);
|
|
235
|
-
const applyName = serverConfiguration.getMethodByName("ApplyChanges");
|
|
236
|
-
applyName === null || applyName === void 0 ? void 0 : applyName.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
237
|
-
applyName === null || applyName === void 0 ? void 0 : applyName.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired);
|
|
238
|
-
const createSigningRequest = serverConfiguration.getMethodByName("CreateSigningRequest");
|
|
239
|
-
createSigningRequest === null || createSigningRequest === void 0 ? void 0 : createSigningRequest.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
240
|
-
createSigningRequest === null || createSigningRequest === void 0 ? void 0 : createSigningRequest.setAccessRestrictions(accessRestrictionFlag);
|
|
241
|
-
const getRejectedList = serverConfiguration.getMethodByName("GetRejectedList");
|
|
242
|
-
getRejectedList === null || getRejectedList === void 0 ? void 0 : getRejectedList.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
243
|
-
getRejectedList === null || getRejectedList === void 0 ? void 0 : getRejectedList.setAccessRestrictions(accessRestrictionFlag);
|
|
244
|
-
const updateCertificate = serverConfiguration.getMethodByName("UpdateCertificate");
|
|
245
|
-
updateCertificate === null || updateCertificate === void 0 ? void 0 : updateCertificate.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
246
|
-
updateCertificate === null || updateCertificate === void 0 ? void 0 : updateCertificate.setAccessRestrictions(accessRestrictionFlag);
|
|
247
|
-
const certificateGroups = serverConfiguration.getComponentByName("CertificateGroups");
|
|
248
|
-
certificateGroups.setRolePermissions(roles_and_permissions_1.rolePermissionRestricted);
|
|
249
|
-
certificateGroups.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.None);
|
|
250
|
-
function installAccessRestrictionOnGroup(group) {
|
|
251
|
-
const trustList = group.getComponentByName("TrustList");
|
|
252
|
-
if (trustList) {
|
|
253
|
-
(0, promote_trust_list_1.installAccessRestrictionOnTrustList)(trustList);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
for (const group of certificateGroups.getComponents()) {
|
|
257
|
-
group === null || group === void 0 ? void 0 : group.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
258
|
-
group === null || group === void 0 ? void 0 : group.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired);
|
|
259
|
-
if (group.nodeClass === node_opcua_data_model_1.NodeClass.Object) {
|
|
260
|
-
installAccessRestrictionOnGroup(group);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
installAccessRestrictions(serverConfiguration);
|
|
265
|
-
serverConfigurationPriv.$pushCertificateManager = new push_certificate_manager_server_impl_1.PushCertificateManagerServerImpl(options);
|
|
266
|
-
serverConfiguration.supportedPrivateKeyFormats.setValueFromSource({
|
|
267
|
-
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
268
|
-
dataType: node_opcua_variant_1.DataType.String,
|
|
269
|
-
value: ["PEM"]
|
|
270
|
-
});
|
|
271
|
-
function install_method_handle_on_type(addressSpace) {
|
|
272
|
-
const serverConfigurationType = addressSpace.findObjectType("ServerConfigurationType");
|
|
273
|
-
if (serverConfigurationType.createSigningRequest.isBound()) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
serverConfigurationType.createSigningRequest.bindMethod(_createSigningRequest);
|
|
277
|
-
serverConfigurationType.getRejectedList.bindMethod(_getRejectedList);
|
|
278
|
-
serverConfigurationType.updateCertificate.bindMethod(_updateCertificate);
|
|
279
|
-
serverConfigurationType.applyChanges.bindMethod(_applyChanges);
|
|
280
|
-
}
|
|
281
|
-
install_method_handle_on_type(addressSpace);
|
|
282
|
-
serverConfiguration.createSigningRequest.bindMethod(_createSigningRequest);
|
|
283
|
-
serverConfiguration.updateCertificate.bindMethod(_updateCertificate);
|
|
284
|
-
serverConfiguration.getRejectedList.bindMethod(_getRejectedList);
|
|
285
|
-
if (serverConfiguration.applyChanges) {
|
|
286
|
-
serverConfiguration.applyChanges.bindMethod(_applyChanges);
|
|
287
|
-
}
|
|
288
|
-
(0, install_CertificateAlarm_1.installCertificateExpirationAlarm)(addressSpace);
|
|
289
|
-
const cg = serverConfiguration.certificateGroups.getComponents();
|
|
290
|
-
const defaultApplicationGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultApplicationGroup");
|
|
291
|
-
const certificateTypes = defaultApplicationGroup.getPropertyByName("CertificateTypes");
|
|
292
|
-
certificateTypes.setValueFromSource({
|
|
293
|
-
dataType: node_opcua_variant_1.DataType.NodeId,
|
|
294
|
-
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
295
|
-
value: [(0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.ObjectTypeIds.RsaSha256ApplicationCertificateType)]
|
|
296
|
-
});
|
|
297
|
-
for (const certificateGroup of cg) {
|
|
298
|
-
if (certificateGroup.nodeClass !== node_opcua_data_model_1.NodeClass.Object) {
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
yield promoteCertificateGroup(certificateGroup);
|
|
302
|
-
}
|
|
303
|
-
yield bindCertificateManager(addressSpace, options);
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
exports.installPushCertificateManagement = installPushCertificateManagement;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-server-configuration
|
|
4
|
+
*/
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.installPushCertificateManagement = exports.promoteCertificateGroup = void 0;
|
|
16
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
17
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
18
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
19
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
20
|
+
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
21
|
+
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
22
|
+
const install_CertificateAlarm_1 = require("./install_CertificateAlarm");
|
|
23
|
+
const push_certificate_manager_server_impl_1 = require("./push_certificate_manager_server_impl");
|
|
24
|
+
const promote_trust_list_1 = require("./promote_trust_list");
|
|
25
|
+
const tools_1 = require("./tools");
|
|
26
|
+
const roles_and_permissions_1 = require("./roles_and_permissions");
|
|
27
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)("ServerConfiguration");
|
|
28
|
+
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("ServerConfiguration");
|
|
29
|
+
const warningLog = (0, node_opcua_debug_1.make_warningLog)("ServerConfiguration");
|
|
30
|
+
const errorLog = debugLog;
|
|
31
|
+
function expected(variant, dataType, variantArrayType) {
|
|
32
|
+
if (!variant) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (variant.dataType !== dataType) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (variant.arrayType !== variantArrayType) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
function getPushCertificateManager(method) {
|
|
44
|
+
const serverConfiguration = method.addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
45
|
+
const serverConfigurationPriv = serverConfiguration;
|
|
46
|
+
if (serverConfigurationPriv.$pushCertificateManager) {
|
|
47
|
+
return serverConfigurationPriv.$pushCertificateManager;
|
|
48
|
+
}
|
|
49
|
+
// throw new Error("Cannot find pushCertificateManager object");
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
function _createSigningRequest(inputArguments, context) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const certificateGroupIdVariant = inputArguments[0];
|
|
55
|
+
const certificateTypeIdVariant = inputArguments[1];
|
|
56
|
+
const subjectNameVariant = inputArguments[2];
|
|
57
|
+
const regeneratePrivateKeyVariant = inputArguments[3];
|
|
58
|
+
const nonceVariant = inputArguments[4];
|
|
59
|
+
if (!expected(certificateGroupIdVariant, node_opcua_variant_1.DataType.NodeId, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
60
|
+
warningLog("expecting an NodeId for certificateGroupId - 0");
|
|
61
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
62
|
+
}
|
|
63
|
+
if (!expected(certificateTypeIdVariant, node_opcua_variant_1.DataType.NodeId, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
64
|
+
warningLog("expecting an NodeId for certificateTypeId - 1");
|
|
65
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
66
|
+
}
|
|
67
|
+
if (!expected(subjectNameVariant, node_opcua_variant_1.DataType.String, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
68
|
+
warningLog("expecting an String for subjectName - 2");
|
|
69
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
70
|
+
}
|
|
71
|
+
if (!expected(regeneratePrivateKeyVariant, node_opcua_variant_1.DataType.Boolean, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
72
|
+
warningLog("expecting an Boolean for regeneratePrivateKey - 3");
|
|
73
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
74
|
+
}
|
|
75
|
+
if (!expected(nonceVariant, node_opcua_variant_1.DataType.ByteString, node_opcua_variant_1.VariantArrayType.Scalar)) {
|
|
76
|
+
warningLog("expecting an ByteString for nonceVariant - 4");
|
|
77
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
78
|
+
}
|
|
79
|
+
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
80
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
81
|
+
}
|
|
82
|
+
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
83
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
84
|
+
}
|
|
85
|
+
const certificateGroupId = certificateGroupIdVariant.value;
|
|
86
|
+
const certificateTypeId = certificateTypeIdVariant.value;
|
|
87
|
+
const subjectName = subjectNameVariant.value;
|
|
88
|
+
const regeneratePrivateKey = regeneratePrivateKeyVariant.value;
|
|
89
|
+
const nonce = nonceVariant.value;
|
|
90
|
+
const pushCertificateManager = getPushCertificateManager(this);
|
|
91
|
+
if (!pushCertificateManager) {
|
|
92
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
93
|
+
}
|
|
94
|
+
const result = yield pushCertificateManager.createSigningRequest(certificateGroupId, certificateTypeId, subjectName, regeneratePrivateKey, nonce);
|
|
95
|
+
if (result.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
|
|
96
|
+
return { statusCode: result.statusCode };
|
|
97
|
+
}
|
|
98
|
+
const callMethodResult = {
|
|
99
|
+
outputArguments: [
|
|
100
|
+
{
|
|
101
|
+
dataType: node_opcua_variant_1.DataType.ByteString,
|
|
102
|
+
value: result.certificateSigningRequest
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
statusCode: result.statusCode
|
|
106
|
+
};
|
|
107
|
+
return callMethodResult;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function _updateCertificate(inputArguments, context) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const certificateGroupId = inputArguments[0].value;
|
|
113
|
+
const certificateTypeId = inputArguments[1].value;
|
|
114
|
+
const certificate = inputArguments[2].value;
|
|
115
|
+
const issuerCertificates = inputArguments[3].value;
|
|
116
|
+
const privateKeyFormat = inputArguments[4].value;
|
|
117
|
+
const privateKey = inputArguments[5].value;
|
|
118
|
+
// This Method requires an encrypted channel and that the Client provides credentials with
|
|
119
|
+
// administrative rights on the Server
|
|
120
|
+
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
121
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
122
|
+
}
|
|
123
|
+
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
124
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
125
|
+
}
|
|
126
|
+
if (privateKeyFormat && privateKeyFormat !== "" && privateKeyFormat.toLowerCase() !== "pem") {
|
|
127
|
+
errorLog("_updateCertificate: Invalid PEM format requested " + privateKeyFormat);
|
|
128
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument };
|
|
129
|
+
}
|
|
130
|
+
const pushCertificateManager = getPushCertificateManager(this);
|
|
131
|
+
if (!pushCertificateManager) {
|
|
132
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
133
|
+
}
|
|
134
|
+
const result = yield pushCertificateManager.updateCertificate(certificateGroupId, certificateTypeId, certificate, issuerCertificates, privateKeyFormat, privateKey);
|
|
135
|
+
// todo raise a CertificateUpdatedAuditEventType
|
|
136
|
+
if (result.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
|
|
137
|
+
return { statusCode: result.statusCode };
|
|
138
|
+
}
|
|
139
|
+
const callMethodResult = {
|
|
140
|
+
outputArguments: [
|
|
141
|
+
{
|
|
142
|
+
dataType: node_opcua_variant_1.DataType.Boolean,
|
|
143
|
+
value: !!result.applyChangesRequired
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
statusCode: result.statusCode
|
|
147
|
+
};
|
|
148
|
+
return callMethodResult;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function _getRejectedList(inputArguments, context) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
154
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
155
|
+
}
|
|
156
|
+
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
157
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
158
|
+
}
|
|
159
|
+
const pushCertificateManager = getPushCertificateManager(this);
|
|
160
|
+
if (!pushCertificateManager) {
|
|
161
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
162
|
+
}
|
|
163
|
+
const result = yield pushCertificateManager.getRejectedList();
|
|
164
|
+
if (result.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
|
|
165
|
+
return { statusCode: result.statusCode };
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
outputArguments: [
|
|
169
|
+
{
|
|
170
|
+
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
171
|
+
dataType: node_opcua_variant_1.DataType.ByteString,
|
|
172
|
+
value: result.certificates
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
statusCode: node_opcua_status_code_1.StatusCodes.Good
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function _applyChanges(inputArguments, context) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
// This Method requires an encrypted channel and that the Client provide credentials with
|
|
182
|
+
// administrative rights on the Server.
|
|
183
|
+
if (!(0, tools_1.hasEncryptedChannel)(context)) {
|
|
184
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
|
|
185
|
+
}
|
|
186
|
+
if (!(0, tools_1.hasExpectedUserAccess)(context)) {
|
|
187
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
|
|
188
|
+
}
|
|
189
|
+
const pushCertificateManager = getPushCertificateManager(this);
|
|
190
|
+
if (!pushCertificateManager) {
|
|
191
|
+
return { statusCode: node_opcua_status_code_1.StatusCodes.BadNotImplemented };
|
|
192
|
+
}
|
|
193
|
+
const statusCode = yield pushCertificateManager.applyChanges();
|
|
194
|
+
return { statusCode };
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function bindCertificateManager(addressSpace, options) {
|
|
198
|
+
const serverConfiguration = addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
199
|
+
const defaultApplicationGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultApplicationGroup");
|
|
200
|
+
if (defaultApplicationGroup) {
|
|
201
|
+
const trustList = defaultApplicationGroup.getComponentByName("TrustList");
|
|
202
|
+
if (trustList) {
|
|
203
|
+
trustList.$$certificateManager = options.applicationGroup;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const defaultTokenGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultUserTokenGroup");
|
|
207
|
+
if (defaultTokenGroup) {
|
|
208
|
+
const trustList = defaultTokenGroup.getComponentByName("TrustList");
|
|
209
|
+
if (trustList) {
|
|
210
|
+
trustList.$$certificateManager = options.userTokenGroup;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function promoteCertificateGroup(certificateGroup) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
const trustList = certificateGroup.getChildByName("TrustList");
|
|
217
|
+
if (trustList) {
|
|
218
|
+
(0, promote_trust_list_1.promoteTrustList)(trustList);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
exports.promoteCertificateGroup = promoteCertificateGroup;
|
|
223
|
+
function installPushCertificateManagement(addressSpace, options) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
const serverConfiguration = addressSpace.rootFolder.objects.server.getChildByName("ServerConfiguration");
|
|
226
|
+
const serverConfigurationPriv = serverConfiguration;
|
|
227
|
+
if (serverConfigurationPriv.$pushCertificateManager) {
|
|
228
|
+
warningLog("PushCertificateManagement has already been installed");
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const accessRestrictionFlag = node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired;
|
|
232
|
+
function installAccessRestrictions(serverConfiguration) {
|
|
233
|
+
serverConfiguration.setRolePermissions(roles_and_permissions_1.rolePermissionRestricted);
|
|
234
|
+
serverConfiguration.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.None);
|
|
235
|
+
const applyName = serverConfiguration.getMethodByName("ApplyChanges");
|
|
236
|
+
applyName === null || applyName === void 0 ? void 0 : applyName.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
237
|
+
applyName === null || applyName === void 0 ? void 0 : applyName.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired);
|
|
238
|
+
const createSigningRequest = serverConfiguration.getMethodByName("CreateSigningRequest");
|
|
239
|
+
createSigningRequest === null || createSigningRequest === void 0 ? void 0 : createSigningRequest.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
240
|
+
createSigningRequest === null || createSigningRequest === void 0 ? void 0 : createSigningRequest.setAccessRestrictions(accessRestrictionFlag);
|
|
241
|
+
const getRejectedList = serverConfiguration.getMethodByName("GetRejectedList");
|
|
242
|
+
getRejectedList === null || getRejectedList === void 0 ? void 0 : getRejectedList.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
243
|
+
getRejectedList === null || getRejectedList === void 0 ? void 0 : getRejectedList.setAccessRestrictions(accessRestrictionFlag);
|
|
244
|
+
const updateCertificate = serverConfiguration.getMethodByName("UpdateCertificate");
|
|
245
|
+
updateCertificate === null || updateCertificate === void 0 ? void 0 : updateCertificate.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
246
|
+
updateCertificate === null || updateCertificate === void 0 ? void 0 : updateCertificate.setAccessRestrictions(accessRestrictionFlag);
|
|
247
|
+
const certificateGroups = serverConfiguration.getComponentByName("CertificateGroups");
|
|
248
|
+
certificateGroups.setRolePermissions(roles_and_permissions_1.rolePermissionRestricted);
|
|
249
|
+
certificateGroups.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.None);
|
|
250
|
+
function installAccessRestrictionOnGroup(group) {
|
|
251
|
+
const trustList = group.getComponentByName("TrustList");
|
|
252
|
+
if (trustList) {
|
|
253
|
+
(0, promote_trust_list_1.installAccessRestrictionOnTrustList)(trustList);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
for (const group of certificateGroups.getComponents()) {
|
|
257
|
+
group === null || group === void 0 ? void 0 : group.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
|
|
258
|
+
group === null || group === void 0 ? void 0 : group.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired);
|
|
259
|
+
if (group.nodeClass === node_opcua_data_model_1.NodeClass.Object) {
|
|
260
|
+
installAccessRestrictionOnGroup(group);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
installAccessRestrictions(serverConfiguration);
|
|
265
|
+
serverConfigurationPriv.$pushCertificateManager = new push_certificate_manager_server_impl_1.PushCertificateManagerServerImpl(options);
|
|
266
|
+
serverConfiguration.supportedPrivateKeyFormats.setValueFromSource({
|
|
267
|
+
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
268
|
+
dataType: node_opcua_variant_1.DataType.String,
|
|
269
|
+
value: ["PEM"]
|
|
270
|
+
});
|
|
271
|
+
function install_method_handle_on_type(addressSpace) {
|
|
272
|
+
const serverConfigurationType = addressSpace.findObjectType("ServerConfigurationType");
|
|
273
|
+
if (serverConfigurationType.createSigningRequest.isBound()) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
serverConfigurationType.createSigningRequest.bindMethod(_createSigningRequest);
|
|
277
|
+
serverConfigurationType.getRejectedList.bindMethod(_getRejectedList);
|
|
278
|
+
serverConfigurationType.updateCertificate.bindMethod(_updateCertificate);
|
|
279
|
+
serverConfigurationType.applyChanges.bindMethod(_applyChanges);
|
|
280
|
+
}
|
|
281
|
+
install_method_handle_on_type(addressSpace);
|
|
282
|
+
serverConfiguration.createSigningRequest.bindMethod(_createSigningRequest);
|
|
283
|
+
serverConfiguration.updateCertificate.bindMethod(_updateCertificate);
|
|
284
|
+
serverConfiguration.getRejectedList.bindMethod(_getRejectedList);
|
|
285
|
+
if (serverConfiguration.applyChanges) {
|
|
286
|
+
serverConfiguration.applyChanges.bindMethod(_applyChanges);
|
|
287
|
+
}
|
|
288
|
+
(0, install_CertificateAlarm_1.installCertificateExpirationAlarm)(addressSpace);
|
|
289
|
+
const cg = serverConfiguration.certificateGroups.getComponents();
|
|
290
|
+
const defaultApplicationGroup = serverConfiguration.certificateGroups.getComponentByName("DefaultApplicationGroup");
|
|
291
|
+
const certificateTypes = defaultApplicationGroup.getPropertyByName("CertificateTypes");
|
|
292
|
+
certificateTypes.setValueFromSource({
|
|
293
|
+
dataType: node_opcua_variant_1.DataType.NodeId,
|
|
294
|
+
arrayType: node_opcua_variant_1.VariantArrayType.Array,
|
|
295
|
+
value: [(0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.ObjectTypeIds.RsaSha256ApplicationCertificateType)]
|
|
296
|
+
});
|
|
297
|
+
for (const certificateGroup of cg) {
|
|
298
|
+
if (certificateGroup.nodeClass !== node_opcua_data_model_1.NodeClass.Object) {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
yield promoteCertificateGroup(certificateGroup);
|
|
302
|
+
}
|
|
303
|
+
yield bindCertificateManager(addressSpace, options);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
exports.installPushCertificateManagement = installPushCertificateManagement;
|
|
307
307
|
//# sourceMappingURL=push_certificate_manager_helpers.js.map
|