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.
Files changed (32) hide show
  1. package/dist/clientTools/index.d.ts +1 -1
  2. package/dist/clientTools/index.js +17 -17
  3. package/dist/clientTools/push_certificate_management_client.d.ts +176 -176
  4. package/dist/clientTools/push_certificate_management_client.js +463 -463
  5. package/dist/clientTools/push_certificate_management_client.js.map +1 -1
  6. package/dist/index.d.ts +10 -10
  7. package/dist/index.js +27 -27
  8. package/dist/push_certificate_manager.d.ts +141 -141
  9. package/dist/push_certificate_manager.js +2 -2
  10. package/dist/server/install_certificate_file_watcher.d.ts +5 -5
  11. package/dist/server/install_certificate_file_watcher.js +23 -23
  12. package/dist/server/install_push_certitifate_management.d.ts +19 -19
  13. package/dist/server/install_push_certitifate_management.js +215 -215
  14. package/dist/server/promote_trust_list.d.ts +6 -6
  15. package/dist/server/promote_trust_list.js +175 -175
  16. package/dist/server/push_certificate_manager_helpers.d.ts +4 -4
  17. package/dist/server/push_certificate_manager_helpers.js +411 -411
  18. package/dist/server/push_certificate_manager_server_impl.d.ts +47 -47
  19. package/dist/server/push_certificate_manager_server_impl.js +525 -525
  20. package/dist/server/roles_and_permissions.d.ts +3 -3
  21. package/dist/server/roles_and_permissions.js +38 -38
  22. package/dist/server/tools.d.ts +3 -3
  23. package/dist/server/tools.js +19 -19
  24. package/dist/server/trust_list_server.d.ts +13 -13
  25. package/dist/server/trust_list_server.js +89 -89
  26. package/dist/standard_certificate_types.d.ts +6 -6
  27. package/dist/standard_certificate_types.js +13 -13
  28. package/dist/trust_list.d.ts +79 -79
  29. package/dist/trust_list.js +2 -2
  30. package/dist/trust_list_impl.js +25 -25
  31. package/package.json +32 -28
  32. package/bin/configurator.ts +0 -304
@@ -1,176 +1,176 @@
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.installAccessRestrictionOnTrustList = exports.promoteTrustList = void 0;
16
- const memfs_1 = require("memfs");
17
- const node_opcua_debug_1 = require("node-opcua-debug");
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_file_transfer_1 = require("node-opcua-file-transfer");
22
- const node_opcua_crypto_1 = require("node-opcua-crypto");
23
- const trust_list_server_1 = require("./trust_list_server");
24
- const tools_1 = require("./tools");
25
- const roles_and_permissions_1 = require("./roles_and_permissions");
26
- const debugLog = (0, node_opcua_debug_1.make_debugLog)("ServerConfiguration");
27
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("ServerConfiguration");
28
- const warningLog = (0, node_opcua_debug_1.make_warningLog)("ServerConfiguration");
29
- const errorLog = debugLog;
30
- function trustListIsAlreadyOpened(trustList) {
31
- return false; // to do...
32
- }
33
- function _closeAndUpdate(inputArguments, context) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- return { statusCode: node_opcua_status_code_1.StatusCodes.Good };
36
- });
37
- }
38
- // in TrustList
39
- function _addCertificate(inputArguments, context) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- // If the Certificate is issued by a CA then the Client shall provide the entire
42
- // chain in the certificate argument (see OPC 10000-6). After validating the Certificate,
43
- // the Server shall add the CA Certificates to the Issuers list in the Trust List.
44
- // The leaf Certificate is added to the list specified by the isTrustedCertificate argument.
45
- if (!(0, tools_1.hasEncryptedChannel)(context)) {
46
- return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
47
- }
48
- if (!(0, tools_1.hasExpectedUserAccess)(context)) {
49
- return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
50
- }
51
- const trustList = context.object;
52
- const cm = trustList.$$certificateManager || null;
53
- // The trust list must have been bound
54
- if (!cm) {
55
- return { statusCode: node_opcua_status_code_1.StatusCodes.BadInternalError };
56
- }
57
- // This method cannot be called if the file object is open.
58
- if (trustListIsAlreadyOpened(trustList)) {
59
- return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidState };
60
- }
61
- const certificateChain = inputArguments[0].value;
62
- const isTrustedCertificate = inputArguments[1].value;
63
- const certificates = (0, node_opcua_crypto_1.split_der)(certificateChain);
64
- // validate certificate first
65
- const r = yield (0, node_opcua_crypto_1.verifyCertificateChain)(certificates);
66
- if (r.status !== "Good") {
67
- warningLog("Invalid certificate ", r.status, r.reason);
68
- return { statusCode: node_opcua_status_code_1.StatusCodes.BadCertificateInvalid };
69
- }
70
- for (let i = 0; i < certificates.length; i++) {
71
- const certificate = certificates[i];
72
- if (i === certificates.length - 1 && isTrustedCertificate) {
73
- yield cm.trustCertificate(certificate);
74
- }
75
- else {
76
- yield cm.addIssuer(certificate);
77
- }
78
- }
79
- debugLog("_addCertificate - done isTrustedCertificate= ", isTrustedCertificate);
80
- return { statusCode: node_opcua_status_code_1.StatusCodes.Good };
81
- });
82
- }
83
- function _removeCertificate(inputArguments, context) {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- if (!(0, tools_1.hasEncryptedChannel)(context)) {
86
- return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
87
- }
88
- if (!(0, tools_1.hasExpectedUserAccess)(context)) {
89
- return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
90
- }
91
- return { statusCode: node_opcua_status_code_1.StatusCodes.Good };
92
- });
93
- }
94
- let counter = 0;
95
- function promoteTrustList(trustList) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- const filename = `/tmpFile${counter}`;
98
- counter += 1;
99
- (0, node_opcua_file_transfer_1.installFileType)(trustList, { filename, fileSystem: memfs_1.fs });
100
- // we need to change the default open method
101
- const open = trustList.getChildByName("Open");
102
- const _open_asyncExecutionFunction = open._asyncExecutionFunction;
103
- // ... and bind the extended methods as well.
104
- const closeAndUpdate = trustList.getChildByName("CloseAndUpdate");
105
- const openWithMasks = trustList.getChildByName("OpenWithMasks");
106
- const addCertificate = trustList.getChildByName("AddCertificate");
107
- const removeCertificate = trustList.getChildByName("RemoveCertificate");
108
- function _openTrustList(trustMask, inputArgs, context, callback) {
109
- if (trustListIsAlreadyOpened(trustList)) {
110
- return callback(null, { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidState });
111
- }
112
- // if (trustList.isOpened) {
113
- // warningLog("TrustList is already opened")
114
- // return { statusCode: StatusCodes.BadInvalidState};
115
- // }
116
- // The Open Method shall not support modes other than Read (0x01) and the Write + EraseExisting (0x06).
117
- const openMask = inputArgs[0].value;
118
- if (openMask !== node_opcua_file_transfer_1.OpenFileMode.Read && openMask !== node_opcua_file_transfer_1.OpenFileMode.WriteEraseExisting) {
119
- return callback(null, { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument });
120
- }
121
- // possible statusCode: Bad_UserAccessDenied The current user does not have the rights required.
122
- const certificateManager = trustList.$$certificateManager || undefined;
123
- if (certificateManager) {
124
- (0, trust_list_server_1.writeTrustList)(memfs_1.fs, filename, trustMask, certificateManager)
125
- .then(() => {
126
- // trustList.isOpened = true;
127
- _open_asyncExecutionFunction.call(this, inputArgs, context, callback);
128
- })
129
- .catch((err) => {
130
- errorLog(err);
131
- callback(err, { statusCode: node_opcua_status_code_1.StatusCodes.BadInternalError });
132
- });
133
- }
134
- else {
135
- warningLog("certificateManager is not defined on trustlist do something to update the document before we open it");
136
- return _open_asyncExecutionFunction.call(this, inputArgs, context, callback);
137
- }
138
- }
139
- function _openCallback(inputArgs, context, callback) {
140
- _openTrustList.call(this, trust_list_server_1.TrustListMasks.All, inputArgs, context, callback);
141
- }
142
- open.bindMethod(_openCallback);
143
- function _openWithMaskCallback(inputArgs, context, callback) {
144
- const trustListMask = inputArgs[0].value;
145
- inputArgs[0] = new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.Byte, value: node_opcua_file_transfer_1.OpenFileMode.Read });
146
- _openTrustList.call(this, trustListMask, inputArgs, context, callback);
147
- }
148
- // The OpenWithMasks Method allows a Client to read only the portion of the Trust List.
149
- // This Method can only be used to read the Trust List.
150
- openWithMasks.bindMethod(_openWithMaskCallback);
151
- addCertificate.bindMethod(_addCertificate);
152
- removeCertificate.bindMethod(_removeCertificate);
153
- closeAndUpdate === null || closeAndUpdate === void 0 ? void 0 : closeAndUpdate.bindMethod(_closeAndUpdate);
154
- function install_method_handle_on_TrustListType(addressSpace) {
155
- const fileType = addressSpace.findObjectType("TrustListType");
156
- if (!fileType || fileType.addCertificate.isBound()) {
157
- return;
158
- }
159
- fileType.open && fileType.open.bindMethod(_openCallback);
160
- fileType.addCertificate.bindMethod(_addCertificate);
161
- fileType.removeCertificate.bindMethod(_removeCertificate);
162
- fileType.openWithMasks && fileType.openWithMasks.bindMethod(_openWithMaskCallback);
163
- fileType.closeAndUpdate && fileType.closeAndUpdate.bindMethod(_closeAndUpdate);
164
- }
165
- install_method_handle_on_TrustListType(trustList.addressSpace);
166
- });
167
- }
168
- exports.promoteTrustList = promoteTrustList;
169
- function installAccessRestrictionOnTrustList(trustList) {
170
- for (const m of trustList.getComponents()) {
171
- m === null || m === void 0 ? void 0 : m.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
172
- m === null || m === void 0 ? void 0 : m.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired);
173
- }
174
- }
175
- exports.installAccessRestrictionOnTrustList = installAccessRestrictionOnTrustList;
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.installAccessRestrictionOnTrustList = exports.promoteTrustList = void 0;
16
+ const memfs_1 = require("memfs");
17
+ const node_opcua_debug_1 = require("node-opcua-debug");
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_file_transfer_1 = require("node-opcua-file-transfer");
22
+ const node_opcua_crypto_1 = require("node-opcua-crypto");
23
+ const trust_list_server_1 = require("./trust_list_server");
24
+ const tools_1 = require("./tools");
25
+ const roles_and_permissions_1 = require("./roles_and_permissions");
26
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)("ServerConfiguration");
27
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("ServerConfiguration");
28
+ const warningLog = (0, node_opcua_debug_1.make_warningLog)("ServerConfiguration");
29
+ const errorLog = debugLog;
30
+ function trustListIsAlreadyOpened(trustList) {
31
+ return false; // to do...
32
+ }
33
+ function _closeAndUpdate(inputArguments, context) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return { statusCode: node_opcua_status_code_1.StatusCodes.Good };
36
+ });
37
+ }
38
+ // in TrustList
39
+ function _addCertificate(inputArguments, context) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ // If the Certificate is issued by a CA then the Client shall provide the entire
42
+ // chain in the certificate argument (see OPC 10000-6). After validating the Certificate,
43
+ // the Server shall add the CA Certificates to the Issuers list in the Trust List.
44
+ // The leaf Certificate is added to the list specified by the isTrustedCertificate argument.
45
+ if (!(0, tools_1.hasEncryptedChannel)(context)) {
46
+ return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
47
+ }
48
+ if (!(0, tools_1.hasExpectedUserAccess)(context)) {
49
+ return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
50
+ }
51
+ const trustList = context.object;
52
+ const cm = trustList.$$certificateManager || null;
53
+ // The trust list must have been bound
54
+ if (!cm) {
55
+ return { statusCode: node_opcua_status_code_1.StatusCodes.BadInternalError };
56
+ }
57
+ // This method cannot be called if the file object is open.
58
+ if (trustListIsAlreadyOpened(trustList)) {
59
+ return { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidState };
60
+ }
61
+ const certificateChain = inputArguments[0].value;
62
+ const isTrustedCertificate = inputArguments[1].value;
63
+ const certificates = (0, node_opcua_crypto_1.split_der)(certificateChain);
64
+ // validate certificate first
65
+ const r = yield (0, node_opcua_crypto_1.verifyCertificateChain)(certificates);
66
+ if (r.status !== "Good") {
67
+ warningLog("Invalid certificate ", r.status, r.reason);
68
+ return { statusCode: node_opcua_status_code_1.StatusCodes.BadCertificateInvalid };
69
+ }
70
+ for (let i = 0; i < certificates.length; i++) {
71
+ const certificate = certificates[i];
72
+ if (i === certificates.length - 1 && isTrustedCertificate) {
73
+ yield cm.trustCertificate(certificate);
74
+ }
75
+ else {
76
+ yield cm.addIssuer(certificate);
77
+ }
78
+ }
79
+ debugLog("_addCertificate - done isTrustedCertificate= ", isTrustedCertificate);
80
+ return { statusCode: node_opcua_status_code_1.StatusCodes.Good };
81
+ });
82
+ }
83
+ function _removeCertificate(inputArguments, context) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ if (!(0, tools_1.hasEncryptedChannel)(context)) {
86
+ return { statusCode: node_opcua_status_code_1.StatusCodes.BadSecurityModeInsufficient };
87
+ }
88
+ if (!(0, tools_1.hasExpectedUserAccess)(context)) {
89
+ return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied };
90
+ }
91
+ return { statusCode: node_opcua_status_code_1.StatusCodes.Good };
92
+ });
93
+ }
94
+ let counter = 0;
95
+ function promoteTrustList(trustList) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ const filename = `/tmpFile${counter}`;
98
+ counter += 1;
99
+ (0, node_opcua_file_transfer_1.installFileType)(trustList, { filename, fileSystem: memfs_1.fs });
100
+ // we need to change the default open method
101
+ const open = trustList.getChildByName("Open");
102
+ const _open_asyncExecutionFunction = open._asyncExecutionFunction;
103
+ // ... and bind the extended methods as well.
104
+ const closeAndUpdate = trustList.getChildByName("CloseAndUpdate");
105
+ const openWithMasks = trustList.getChildByName("OpenWithMasks");
106
+ const addCertificate = trustList.getChildByName("AddCertificate");
107
+ const removeCertificate = trustList.getChildByName("RemoveCertificate");
108
+ function _openTrustList(trustMask, inputArgs, context, callback) {
109
+ if (trustListIsAlreadyOpened(trustList)) {
110
+ return callback(null, { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidState });
111
+ }
112
+ // if (trustList.isOpened) {
113
+ // warningLog("TrustList is already opened")
114
+ // return { statusCode: StatusCodes.BadInvalidState};
115
+ // }
116
+ // The Open Method shall not support modes other than Read (0x01) and the Write + EraseExisting (0x06).
117
+ const openMask = inputArgs[0].value;
118
+ if (openMask !== node_opcua_file_transfer_1.OpenFileMode.Read && openMask !== node_opcua_file_transfer_1.OpenFileMode.WriteEraseExisting) {
119
+ return callback(null, { statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument });
120
+ }
121
+ // possible statusCode: Bad_UserAccessDenied The current user does not have the rights required.
122
+ const certificateManager = trustList.$$certificateManager || undefined;
123
+ if (certificateManager) {
124
+ (0, trust_list_server_1.writeTrustList)(memfs_1.fs, filename, trustMask, certificateManager)
125
+ .then(() => {
126
+ // trustList.isOpened = true;
127
+ _open_asyncExecutionFunction.call(this, inputArgs, context, callback);
128
+ })
129
+ .catch((err) => {
130
+ errorLog(err);
131
+ callback(err, { statusCode: node_opcua_status_code_1.StatusCodes.BadInternalError });
132
+ });
133
+ }
134
+ else {
135
+ warningLog("certificateManager is not defined on trustlist do something to update the document before we open it");
136
+ return _open_asyncExecutionFunction.call(this, inputArgs, context, callback);
137
+ }
138
+ }
139
+ function _openCallback(inputArgs, context, callback) {
140
+ _openTrustList.call(this, trust_list_server_1.TrustListMasks.All, inputArgs, context, callback);
141
+ }
142
+ open.bindMethod(_openCallback);
143
+ function _openWithMaskCallback(inputArgs, context, callback) {
144
+ const trustListMask = inputArgs[0].value;
145
+ inputArgs[0] = new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.Byte, value: node_opcua_file_transfer_1.OpenFileMode.Read });
146
+ _openTrustList.call(this, trustListMask, inputArgs, context, callback);
147
+ }
148
+ // The OpenWithMasks Method allows a Client to read only the portion of the Trust List.
149
+ // This Method can only be used to read the Trust List.
150
+ openWithMasks.bindMethod(_openWithMaskCallback);
151
+ addCertificate.bindMethod(_addCertificate);
152
+ removeCertificate.bindMethod(_removeCertificate);
153
+ closeAndUpdate === null || closeAndUpdate === void 0 ? void 0 : closeAndUpdate.bindMethod(_closeAndUpdate);
154
+ function install_method_handle_on_TrustListType(addressSpace) {
155
+ const fileType = addressSpace.findObjectType("TrustListType");
156
+ if (!fileType || fileType.addCertificate.isBound()) {
157
+ return;
158
+ }
159
+ fileType.open && fileType.open.bindMethod(_openCallback);
160
+ fileType.addCertificate.bindMethod(_addCertificate);
161
+ fileType.removeCertificate.bindMethod(_removeCertificate);
162
+ fileType.openWithMasks && fileType.openWithMasks.bindMethod(_openWithMaskCallback);
163
+ fileType.closeAndUpdate && fileType.closeAndUpdate.bindMethod(_closeAndUpdate);
164
+ }
165
+ install_method_handle_on_TrustListType(trustList.addressSpace);
166
+ });
167
+ }
168
+ exports.promoteTrustList = promoteTrustList;
169
+ function installAccessRestrictionOnTrustList(trustList) {
170
+ for (const m of trustList.getComponents()) {
171
+ m === null || m === void 0 ? void 0 : m.setRolePermissions(roles_and_permissions_1.rolePermissionAdminOnly);
172
+ m === null || m === void 0 ? void 0 : m.setAccessRestrictions(node_opcua_data_model_1.AccessRestrictionsFlag.SigningRequired | node_opcua_data_model_1.AccessRestrictionsFlag.EncryptionRequired);
173
+ }
174
+ }
175
+ exports.installAccessRestrictionOnTrustList = installAccessRestrictionOnTrustList;
176
176
  //# sourceMappingURL=promote_trust_list.js.map
@@ -1,4 +1,4 @@
1
- import { AddressSpace, UACertificateGroup } from "node-opcua-address-space";
2
- import { PushCertificateManagerServerOptions } from "./push_certificate_manager_server_impl";
3
- export declare function promoteCertificateGroup(certificateGroup: UACertificateGroup): Promise<void>;
4
- export declare function installPushCertificateManagement(addressSpace: AddressSpace, options: PushCertificateManagerServerOptions): Promise<void>;
1
+ import { AddressSpace, UACertificateGroup } from "node-opcua-address-space";
2
+ import { PushCertificateManagerServerOptions } from "./push_certificate_manager_server_impl";
3
+ export declare function promoteCertificateGroup(certificateGroup: UACertificateGroup): Promise<void>;
4
+ export declare function installPushCertificateManagement(addressSpace: AddressSpace, options: PushCertificateManagerServerOptions): Promise<void>;