node-opcua-server-configuration 2.98.0 → 2.98.2

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 (47) hide show
  1. package/dist/clientTools/index.d.ts +1 -0
  2. package/dist/clientTools/index.js +18 -0
  3. package/dist/clientTools/index.js.map +1 -0
  4. package/dist/clientTools/push_certificate_management_client.d.ts +176 -0
  5. package/dist/clientTools/push_certificate_management_client.js +464 -0
  6. package/dist/clientTools/push_certificate_management_client.js.map +1 -0
  7. package/dist/index.d.ts +10 -0
  8. package/dist/index.js +28 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/push_certificate_manager.d.ts +141 -0
  11. package/dist/push_certificate_manager.js +3 -0
  12. package/dist/push_certificate_manager.js.map +1 -0
  13. package/dist/server/install_certificate_file_watcher.d.ts +5 -0
  14. package/dist/server/install_certificate_file_watcher.js +24 -0
  15. package/dist/server/install_certificate_file_watcher.js.map +1 -0
  16. package/dist/server/install_push_certitifate_management.d.ts +19 -0
  17. package/dist/server/install_push_certitifate_management.js +216 -0
  18. package/dist/server/install_push_certitifate_management.js.map +1 -0
  19. package/dist/server/promote_trust_list.d.ts +6 -0
  20. package/dist/server/promote_trust_list.js +176 -0
  21. package/dist/server/promote_trust_list.js.map +1 -0
  22. package/dist/server/push_certificate_manager_helpers.d.ts +4 -0
  23. package/dist/server/push_certificate_manager_helpers.js +412 -0
  24. package/dist/server/push_certificate_manager_helpers.js.map +1 -0
  25. package/dist/server/push_certificate_manager_server_impl.d.ts +47 -0
  26. package/dist/server/push_certificate_manager_server_impl.js +526 -0
  27. package/dist/server/push_certificate_manager_server_impl.js.map +1 -0
  28. package/dist/server/roles_and_permissions.d.ts +3 -0
  29. package/dist/server/roles_and_permissions.js +39 -0
  30. package/dist/server/roles_and_permissions.js.map +1 -0
  31. package/dist/server/tools.d.ts +3 -0
  32. package/dist/server/tools.js +20 -0
  33. package/dist/server/tools.js.map +1 -0
  34. package/dist/server/trust_list_server.d.ts +13 -0
  35. package/dist/server/trust_list_server.js +90 -0
  36. package/dist/server/trust_list_server.js.map +1 -0
  37. package/dist/standard_certificate_types.d.ts +6 -0
  38. package/dist/standard_certificate_types.js +14 -0
  39. package/dist/standard_certificate_types.js.map +1 -0
  40. package/dist/trust_list.d.ts +79 -0
  41. package/dist/trust_list.js +3 -0
  42. package/dist/trust_list.js.map +1 -0
  43. package/dist/trust_list_impl.d.ts +0 -0
  44. package/dist/trust_list_impl.js +26 -0
  45. package/dist/trust_list_impl.js.map +1 -0
  46. package/package.json +31 -27
  47. package/bin/configurator.ts +0 -304
@@ -0,0 +1,47 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /**
4
+ * @module node-opcua-server-configuration-server
5
+ */
6
+ import { EventEmitter } from "events";
7
+ import { SubjectOptions } from "node-opcua-pki";
8
+ import { ByteString } from "node-opcua-basic-types";
9
+ import { DirectoryName } from "node-opcua-crypto/dist/source/asn1";
10
+ import { NodeId } from "node-opcua-nodeid";
11
+ import { CertificateManager } from "node-opcua-certificate-manager";
12
+ import { StatusCode } from "node-opcua-status-code";
13
+ import { CreateSigningRequestResult, GetRejectedListResult, PushCertificateManager, UpdateCertificateResult } from "../push_certificate_manager";
14
+ export interface PushCertificateManagerServerOptions {
15
+ applicationGroup?: CertificateManager;
16
+ userTokenGroup?: CertificateManager;
17
+ httpsGroup?: CertificateManager;
18
+ applicationUri: string;
19
+ }
20
+ export declare function copyFile(source: string, dest: string): Promise<void>;
21
+ export declare function deleteFile(file: string): Promise<void>;
22
+ export declare function moveFile(source: string, dest: string): Promise<void>;
23
+ export declare function moveFileWithBackup(source: string, dest: string): Promise<void>;
24
+ export declare function subjectToString(subject: SubjectOptions & DirectoryName): string;
25
+ export type ActionQueue = (() => Promise<void>)[];
26
+ export declare class PushCertificateManagerServerImpl extends EventEmitter implements PushCertificateManager {
27
+ applicationGroup?: CertificateManager;
28
+ userTokenGroup?: CertificateManager;
29
+ httpsGroup?: CertificateManager;
30
+ private readonly _map;
31
+ private readonly _pendingTasks;
32
+ private _tmpCertificateManager?;
33
+ private $$actionQueue;
34
+ private applicationUri;
35
+ constructor(options: PushCertificateManagerServerOptions);
36
+ initialize(): Promise<void>;
37
+ get supportedPrivateKeyFormats(): string[];
38
+ getSupportedPrivateKeyFormats(): Promise<string[]>;
39
+ createSigningRequest(certificateGroupId: NodeId | string, certificateTypeId: NodeId | string, subjectName: string | SubjectOptions | null, regeneratePrivateKey?: boolean, nonce?: Buffer): Promise<CreateSigningRequestResult>;
40
+ getRejectedList(): Promise<GetRejectedListResult>;
41
+ updateCertificate(certificateGroupId: NodeId | string, certificateTypeId: NodeId | string, certificate: Buffer, issuerCertificates: ByteString[]): Promise<UpdateCertificateResult>;
42
+ applyChanges(): Promise<StatusCode>;
43
+ private getCertificateManager;
44
+ private addPendingTask;
45
+ private applyPendingTasks;
46
+ private flushActionQueue;
47
+ }
@@ -0,0 +1,526 @@
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
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
12
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
+ var m = o[Symbol.asyncIterator], i;
14
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.PushCertificateManagerServerImpl = exports.subjectToString = exports.moveFileWithBackup = exports.moveFile = exports.deleteFile = exports.copyFile = void 0;
20
+ /**
21
+ * @module node-opcua-server-configuration-server
22
+ */
23
+ const events_1 = require("events");
24
+ const fs = require("fs");
25
+ const path = require("path");
26
+ const crypto_1 = require("crypto");
27
+ const util_1 = require("util");
28
+ const rimraf = require("rimraf");
29
+ const node_opcua_assert_1 = require("node-opcua-assert");
30
+ const node_opcua_basic_types_1 = require("node-opcua-basic-types");
31
+ const node_opcua_crypto_1 = require("node-opcua-crypto");
32
+ const node_opcua_debug_1 = require("node-opcua-debug");
33
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
34
+ const node_opcua_certificate_manager_1 = require("node-opcua-certificate-manager");
35
+ // node 14 onward : import { readFile, writeFile, readdir } from "fs/promises";
36
+ const { readFile, writeFile, readdir } = fs.promises;
37
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)("ServerConfiguration");
38
+ const errorLog = (0, node_opcua_debug_1.make_errorLog)("ServerConfiguration");
39
+ const warningLog = (0, node_opcua_debug_1.make_warningLog)("ServerConfiguration");
40
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("ServerConfiguration");
41
+ const defaultApplicationGroup = (0, node_opcua_nodeid_1.resolveNodeId)("ServerConfiguration_CertificateGroups_DefaultApplicationGroup");
42
+ const defaultHttpsGroup = (0, node_opcua_nodeid_1.resolveNodeId)("ServerConfiguration_CertificateGroups_DefaultHttpsGroup");
43
+ const defaultUserTokenGroup = (0, node_opcua_nodeid_1.resolveNodeId)("ServerConfiguration_CertificateGroups_DefaultUserTokenGroup");
44
+ function findCertificateGroupName(certificateGroupNodeId) {
45
+ if (typeof certificateGroupNodeId === "string") {
46
+ return certificateGroupNodeId;
47
+ }
48
+ if ((0, node_opcua_nodeid_1.sameNodeId)(certificateGroupNodeId, node_opcua_nodeid_1.NodeId.nullNodeId) || (0, node_opcua_nodeid_1.sameNodeId)(certificateGroupNodeId, defaultApplicationGroup)) {
49
+ return "DefaultApplicationGroup";
50
+ }
51
+ if ((0, node_opcua_nodeid_1.sameNodeId)(certificateGroupNodeId, defaultHttpsGroup)) {
52
+ return "DefaultHttpsGroup";
53
+ }
54
+ if ((0, node_opcua_nodeid_1.sameNodeId)(certificateGroupNodeId, defaultUserTokenGroup)) {
55
+ return "DefaultUserTokenGroup";
56
+ }
57
+ return "";
58
+ }
59
+ function copyFile(source, dest) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ try {
62
+ debugLog("copying file \n source ", source, "\n =>\n dest ", dest);
63
+ const sourceExist = fs.existsSync(source);
64
+ if (sourceExist) {
65
+ yield fs.promises.copyFile(source, dest);
66
+ }
67
+ }
68
+ catch (err) {
69
+ errorLog(err);
70
+ }
71
+ });
72
+ }
73
+ exports.copyFile = copyFile;
74
+ function deleteFile(file) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ try {
77
+ const exists = yield fs.existsSync(file);
78
+ if (exists) {
79
+ debugLog("deleting file ", file);
80
+ yield fs.promises.unlink(file);
81
+ }
82
+ }
83
+ catch (err) {
84
+ errorLog(err);
85
+ }
86
+ });
87
+ }
88
+ exports.deleteFile = deleteFile;
89
+ function moveFile(source, dest) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ debugLog("moving file file \n source ", source, "\n =>\n dest ", dest);
92
+ try {
93
+ yield copyFile(source, dest);
94
+ yield deleteFile(source);
95
+ }
96
+ catch (err) {
97
+ errorLog(err);
98
+ }
99
+ });
100
+ }
101
+ exports.moveFile = moveFile;
102
+ function moveFileWithBackup(source, dest) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ // let make a copy of the destination file
105
+ debugLog("moveFileWithBackup file \n source ", source, "\n =>\n dest ", dest);
106
+ yield copyFile(dest, dest + "_old");
107
+ yield moveFile(source, dest);
108
+ });
109
+ }
110
+ exports.moveFileWithBackup = moveFileWithBackup;
111
+ function subjectToString(subject) {
112
+ let s = "";
113
+ subject.commonName && (s += `/CN=${subject.commonName}`);
114
+ subject.country && (s += `/C=${subject.country}`);
115
+ subject.countryName && (s += `/C=${subject.countryName}`);
116
+ subject.domainComponent && (s += `/DC=${subject.domainComponent}`);
117
+ subject.locality && (s += `/L=${subject.locality}`);
118
+ subject.localityName && (s += `/L=${subject.localityName}`);
119
+ subject.organization && (s += `/O=${subject.organization}`);
120
+ subject.organizationName && (s += `/O=${subject.organizationName}`);
121
+ subject.organizationUnitName && (s += `/OU=${subject.organizationUnitName}`);
122
+ subject.state && (s += `/ST=${subject.state}`);
123
+ subject.stateOrProvinceName && (s += `/ST=${subject.stateOrProvinceName}`);
124
+ return s;
125
+ }
126
+ exports.subjectToString = subjectToString;
127
+ let fileCounter = 0;
128
+ class PushCertificateManagerServerImpl extends events_1.EventEmitter {
129
+ constructor(options) {
130
+ super();
131
+ this._map = {};
132
+ this._pendingTasks = [];
133
+ this.$$actionQueue = [];
134
+ this.applicationUri = options ? options.applicationUri : "";
135
+ if (options) {
136
+ this.applicationGroup = options.applicationGroup;
137
+ this.userTokenGroup = options.userTokenGroup;
138
+ this.httpsGroup = options.httpsGroup;
139
+ if (this.userTokenGroup) {
140
+ this._map.DefaultUserTokenGroup = this.userTokenGroup;
141
+ // istanbul ignore next
142
+ if (!(this.userTokenGroup instanceof node_opcua_certificate_manager_1.CertificateManager)) {
143
+ errorLog("Expecting this.userTokenGroup to be instanceof CertificateManager :", this.userTokenGroup.constructor.name);
144
+ throw new Error("Expecting this.userTokenGroup to be instanceof CertificateManager ");
145
+ }
146
+ }
147
+ if (this.applicationGroup) {
148
+ this._map.DefaultApplicationGroup = this.applicationGroup;
149
+ (0, node_opcua_assert_1.assert)(this.applicationGroup instanceof node_opcua_certificate_manager_1.CertificateManager);
150
+ }
151
+ if (this.httpsGroup) {
152
+ this._map.DefaultHttpsGroup = this.httpsGroup;
153
+ (0, node_opcua_assert_1.assert)(this.httpsGroup instanceof node_opcua_certificate_manager_1.CertificateManager);
154
+ }
155
+ }
156
+ }
157
+ initialize() {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ if (this.applicationGroup) {
160
+ yield this.applicationGroup.initialize();
161
+ }
162
+ if (this.userTokenGroup) {
163
+ yield this.userTokenGroup.initialize();
164
+ }
165
+ if (this.httpsGroup) {
166
+ yield this.httpsGroup.initialize();
167
+ }
168
+ });
169
+ }
170
+ get supportedPrivateKeyFormats() {
171
+ return ["PEM"];
172
+ }
173
+ getSupportedPrivateKeyFormats() {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ return this.supportedPrivateKeyFormats;
176
+ });
177
+ }
178
+ createSigningRequest(certificateGroupId, certificateTypeId, subjectName, regeneratePrivateKey, nonce) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ let certificateManager = this.getCertificateManager(certificateGroupId);
181
+ if (!certificateManager) {
182
+ debugLog(" cannot find group ", certificateGroupId);
183
+ return {
184
+ statusCode: node_opcua_basic_types_1.StatusCodes.BadInvalidArgument
185
+ };
186
+ }
187
+ if (!subjectName) {
188
+ // reuse existing subjectName
189
+ const currentCertificateFilename = path.join(certificateManager.rootDir, "own/certs/certificate.pem");
190
+ if (!fs.existsSync(currentCertificateFilename)) {
191
+ errorLog("Cannot find existing certificate to extract subjectName", currentCertificateFilename);
192
+ return {
193
+ statusCode: node_opcua_basic_types_1.StatusCodes.BadInvalidState
194
+ };
195
+ }
196
+ const certificate = (0, node_opcua_crypto_1.readCertificate)(currentCertificateFilename);
197
+ const e = (0, node_opcua_crypto_1.exploreCertificate)(certificate);
198
+ subjectName = subjectToString(e.tbsCertificate.subject);
199
+ warningLog("reusing existing certificate subjectAltName = ", subjectName);
200
+ }
201
+ // todo : at this time regenerate PrivateKey is not supported
202
+ if (regeneratePrivateKey) {
203
+ // The Server shall create a new Private Key which it stores until the
204
+ // matching signed Certificate is uploaded with the UpdateCertificate Method.
205
+ // Previously created Private Keys may be discarded if UpdateCertificate was not
206
+ // called before calling this method again.
207
+ // Additional entropy which the caller shall provide if regeneratePrivateKey is TRUE.
208
+ // It shall be at least 32 bytes long
209
+ if (!nonce || nonce.length < 32) {
210
+ (0, node_opcua_debug_1.make_warningLog)(" nonce should be provided when regeneratePrivateKey is set, and length shall be greater than 32 bytes");
211
+ return {
212
+ statusCode: node_opcua_basic_types_1.StatusCodes.BadInvalidArgument
213
+ };
214
+ }
215
+ const location = path.join(certificateManager.rootDir, "tmp");
216
+ if (fs.existsSync(location)) {
217
+ yield (0, util_1.promisify)(rimraf)(path.join(location));
218
+ }
219
+ if (!fs.existsSync(location)) {
220
+ yield fs.promises.mkdir(location);
221
+ }
222
+ const destCertificateManager = certificateManager;
223
+ const keySize = certificateManager.keySize; // because keySize is private !
224
+ certificateManager = new node_opcua_certificate_manager_1.CertificateManager({
225
+ keySize,
226
+ location
227
+ });
228
+ debugLog("generating a new private key ...");
229
+ yield certificateManager.initialize();
230
+ this._tmpCertificateManager = certificateManager;
231
+ this.addPendingTask(() => __awaiter(this, void 0, void 0, function* () {
232
+ yield moveFileWithBackup(certificateManager.privateKey, destCertificateManager.privateKey);
233
+ }));
234
+ this.addPendingTask(() => __awaiter(this, void 0, void 0, function* () {
235
+ yield (0, util_1.promisify)(rimraf)(path.join(location));
236
+ }));
237
+ }
238
+ else {
239
+ // The Server uses its existing Private Key
240
+ }
241
+ if (typeof subjectName !== "string") {
242
+ return { statusCode: node_opcua_basic_types_1.StatusCodes.BadInternalError };
243
+ }
244
+ const options = {
245
+ applicationUri: this.applicationUri,
246
+ subject: subjectName
247
+ };
248
+ yield certificateManager.initialize();
249
+ const csrFile = yield certificateManager.createCertificateRequest(options);
250
+ const csrPEM = yield readFile(csrFile, "utf8");
251
+ const certificateSigningRequest = (0, node_opcua_crypto_1.convertPEMtoDER)(csrPEM);
252
+ this.addPendingTask(() => deleteFile(csrFile));
253
+ return {
254
+ certificateSigningRequest,
255
+ statusCode: node_opcua_basic_types_1.StatusCodes.Good
256
+ };
257
+ });
258
+ }
259
+ getRejectedList() {
260
+ return __awaiter(this, void 0, void 0, function* () {
261
+ // rejectedList comes from each group
262
+ function extractRejectedList(group, certificateList) {
263
+ return __awaiter(this, void 0, void 0, function* () {
264
+ if (!group) {
265
+ return;
266
+ }
267
+ const rejectedFolder = path.join(group.rootDir, "rejected");
268
+ const files = yield readdir(rejectedFolder);
269
+ const stat = fs.promises.stat;
270
+ const promises1 = [];
271
+ for (const certFile of files) {
272
+ // read date
273
+ promises1.push(stat(path.join(rejectedFolder, certFile)));
274
+ }
275
+ const stats = yield Promise.all(promises1);
276
+ for (let i = 0; i < stats.length; i++) {
277
+ certificateList.push({
278
+ filename: path.join(rejectedFolder, files[i]),
279
+ stat: stats[i]
280
+ });
281
+ }
282
+ });
283
+ }
284
+ const list = [];
285
+ yield extractRejectedList(this.applicationGroup, list);
286
+ yield extractRejectedList(this.userTokenGroup, list);
287
+ yield extractRejectedList(this.httpsGroup, list);
288
+ // now sort list from newer file to older file
289
+ list.sort((a, b) => b.stat.mtime.getTime() - a.stat.mtime.getTime());
290
+ const promises = [];
291
+ for (const item of list) {
292
+ promises.push(readFile(item.filename, "utf8"));
293
+ }
294
+ const certificatesPEM = yield Promise.all(promises);
295
+ const certificates = certificatesPEM.map(node_opcua_crypto_1.convertPEMtoDER);
296
+ return {
297
+ certificates,
298
+ statusCode: node_opcua_basic_types_1.StatusCodes.Good
299
+ };
300
+ });
301
+ }
302
+ // eslint-disable-next-line max-statements
303
+ updateCertificate(certificateGroupId, certificateTypeId, certificate, issuerCertificates, privateKeyFormat, privateKey) {
304
+ return __awaiter(this, void 0, void 0, function* () {
305
+ // Result Code Description
306
+ // BadInvalidArgument The certificateTypeId or certificateGroupId is not valid.
307
+ // BadCertificateInvalid The Certificate is invalid or the format is not supported.
308
+ // BadNotSupported The PrivateKey is invalid or the format is not supported.
309
+ // BadUserAccessDenied The current user does not have the rights required.
310
+ // BadSecurityChecksFailed Some failure occurred verifying the integrity of the Certificate.
311
+ const certificateManager = this.getCertificateManager(certificateGroupId);
312
+ if (!certificateManager) {
313
+ debugLog(" cannot find group ", certificateGroupId);
314
+ return {
315
+ statusCode: node_opcua_basic_types_1.StatusCodes.BadInvalidArgument
316
+ };
317
+ }
318
+ function preInstallCertificate(self) {
319
+ return __awaiter(this, void 0, void 0, function* () {
320
+ const certFolder = path.join(certificateManager.rootDir, "own/certs");
321
+ const certificateFileDER = path.join(certFolder, `_pending_certificate${fileCounter++}.der`);
322
+ const certificateFilePEM = path.join(certFolder, `_pending_certificate${fileCounter++}.pem`);
323
+ yield writeFile(certificateFileDER, certificate, "binary");
324
+ yield writeFile(certificateFilePEM, (0, node_opcua_crypto_1.toPem)(certificate, "CERTIFICATE"));
325
+ const destDER = path.join(certFolder, "certificate.der");
326
+ const destPEM = path.join(certFolder, "certificate.pem");
327
+ // put existing file in security by backing them up
328
+ self.addPendingTask(() => moveFileWithBackup(certificateFileDER, destDER));
329
+ self.addPendingTask(() => moveFileWithBackup(certificateFilePEM, destPEM));
330
+ });
331
+ }
332
+ function preInstallPrivateKey(self) {
333
+ return __awaiter(this, void 0, void 0, function* () {
334
+ (0, node_opcua_assert_1.assert)(privateKeyFormat.toUpperCase() === "PEM");
335
+ const ownPrivateFolder = path.join(certificateManager.rootDir, "own/private");
336
+ const privateKeyFilePEM = path.join(ownPrivateFolder, `_pending_private_key${fileCounter++}.pem`);
337
+ const privateKeyPEM = (0, node_opcua_crypto_1.toPem)(privateKey, "RSA PRIVATE KEY");
338
+ yield writeFile(privateKeyFilePEM, privateKeyPEM, "utf-8");
339
+ self.addPendingTask(() => moveFileWithBackup(privateKeyFilePEM, certificateManager.privateKey));
340
+ });
341
+ }
342
+ // OPC Unified Architecture, Part 12 42 Release 1.04:
343
+ //
344
+ // UpdateCertificate is used to update a Certificate for a Server.
345
+ // There are the following three use cases for this Method:
346
+ //
347
+ // - The new Certificate was created based on a signing request created with the Method
348
+ // In this case there is no privateKey provided.
349
+ // - A new privateKey and Certificate was created outside the Server and both are updated
350
+ // with this Method.
351
+ // - A new Certificate was created and signed with the information from the old Certificate.
352
+ // In this case there is no privateKey provided.
353
+ // The Server shall do all normal integrity checks on the Certificate and all of the issuer
354
+ // Certificates. If errors occur the BadSecurityChecksFailed error is returned.
355
+ // todo : all normal integrity check on the certificate
356
+ const certInfo = (0, node_opcua_crypto_1.exploreCertificate)(certificate);
357
+ const now = new Date();
358
+ if (certInfo.tbsCertificate.validity.notBefore.getTime() > now.getTime()) {
359
+ // certificate is not yet valid
360
+ warningLog("Certificate is not yet valid : not before ", certInfo.tbsCertificate.validity.notBefore.toISOString(), "now = ", now.toISOString());
361
+ return { statusCode: node_opcua_basic_types_1.StatusCodes.BadSecurityChecksFailed };
362
+ }
363
+ if (certInfo.tbsCertificate.validity.notAfter.getTime() < now.getTime()) {
364
+ // certificate is already out of date
365
+ warningLog("Certificate is already out of date : not after ", certInfo.tbsCertificate.validity.notAfter.toISOString(), "now = ", now.toISOString());
366
+ return { statusCode: node_opcua_basic_types_1.StatusCodes.BadSecurityChecksFailed };
367
+ }
368
+ // If the Server returns applyChangesRequired=FALSE then it is indicating that it is able to
369
+ // satisfy the requirements specified for the ApplyChanges Method.
370
+ debugLog(" updateCertificate ", (0, node_opcua_crypto_1.makeSHA1Thumbprint)(certificate).toString("hex"));
371
+ if (!privateKeyFormat || !privateKey) {
372
+ // first of all we need to find the future private key;
373
+ // this one may have been created during the creation of the certficate signing request
374
+ // but is not active yet
375
+ const privateKeyDER = (0, node_opcua_crypto_1.readPrivateKey)(this._tmpCertificateManager ? this._tmpCertificateManager.privateKey : certificateManager.privateKey);
376
+ // The Server shall report an error if the public key does not match the existing Certificate and
377
+ // the privateKey was not provided.
378
+ // privateKey is not provided, so check that the public key matches the existing certificate
379
+ if (!(0, node_opcua_crypto_1.certificateMatchesPrivateKey)(certificate, privateKeyDER)) {
380
+ // certificate doesn't match privateKey
381
+ warningLog("certificate doesn't match privateKey");
382
+ /* debug code */
383
+ const certificatePEM = (0, node_opcua_crypto_1.toPem)(certificate, "CERTIFICATE");
384
+ const privateKeyPEM = (0, node_opcua_crypto_1.toPem)(privateKeyDER, "RSA PRIVATE KEY");
385
+ const initialBuffer = Buffer.from("Lorem Ipsum");
386
+ const encryptedBuffer = (0, node_opcua_crypto_1.publicEncrypt_long)(initialBuffer, certificatePEM, 256, 11);
387
+ const decryptedBuffer = (0, node_opcua_crypto_1.privateDecrypt_long)(encryptedBuffer, privateKeyPEM, 256);
388
+ console.log(certificatePEM);
389
+ console.log(privateKeyPEM);
390
+ console.log("decrypted buffer", decryptedBuffer.toString("utf-8"));
391
+ return { statusCode: node_opcua_basic_types_1.StatusCodes.BadSecurityChecksFailed };
392
+ }
393
+ // a new certificate is provided for us,
394
+ // we keep our private key
395
+ // we do this in two stages
396
+ yield preInstallCertificate(this);
397
+ return {
398
+ statusCode: node_opcua_basic_types_1.StatusCodes.Good
399
+ };
400
+ }
401
+ else if (privateKey) {
402
+ // a private key has been provided by the caller !
403
+ if (!privateKeyFormat) {
404
+ warningLog("the privateKeyFormat must be specified " + privateKeyFormat);
405
+ return { statusCode: node_opcua_basic_types_1.StatusCodes.BadNotSupported };
406
+ }
407
+ if (privateKeyFormat !== "PEM" && privateKeyFormat !== "PFX") {
408
+ warningLog(" the private key format is invalid privateKeyFormat =" + privateKeyFormat);
409
+ return { statusCode: node_opcua_basic_types_1.StatusCodes.BadNotSupported };
410
+ }
411
+ if (privateKeyFormat !== "PEM") {
412
+ warningLog("in NodeOPCUA we only support PEM for the moment privateKeyFormat =" + privateKeyFormat);
413
+ return { statusCode: node_opcua_basic_types_1.StatusCodes.BadNotSupported };
414
+ }
415
+ if (privateKey instanceof Buffer || typeof privateKey === "string") {
416
+ privateKey = (0, crypto_1.createPrivateKey)(privateKey);
417
+ }
418
+ // privateKey is provided, so check that the public key matches provided private key
419
+ if (!(0, node_opcua_crypto_1.certificateMatchesPrivateKey)(certificate, privateKey)) {
420
+ // certificate doesn't match privateKey
421
+ warningLog("certificate doesn't match privateKey");
422
+ return { statusCode: node_opcua_basic_types_1.StatusCodes.BadSecurityChecksFailed };
423
+ }
424
+ yield preInstallPrivateKey(this);
425
+ yield preInstallCertificate(this);
426
+ return {
427
+ statusCode: node_opcua_basic_types_1.StatusCodes.Good
428
+ };
429
+ }
430
+ else {
431
+ // todo !
432
+ return {
433
+ statusCode: node_opcua_basic_types_1.StatusCodes.BadNotSupported
434
+ };
435
+ }
436
+ });
437
+ }
438
+ applyChanges() {
439
+ return __awaiter(this, void 0, void 0, function* () {
440
+ // ApplyChanges is used to tell the Server to apply any security changes.
441
+ // This Method should only be called if a previous call to a Method that changed the
442
+ // configuration returns applyChangesRequired=true.
443
+ //
444
+ // If the Server Certificate has changed, Secure Channels using the old Certificate will
445
+ // eventually be interrupted.
446
+ this.emit("CertificateAboutToChange", this.$$actionQueue);
447
+ yield this.flushActionQueue();
448
+ try {
449
+ yield this.applyPendingTasks();
450
+ }
451
+ catch (err) {
452
+ debugLog("err ", err);
453
+ return node_opcua_basic_types_1.StatusCodes.BadInternalError;
454
+ }
455
+ this.emit("CertificateChanged", this.$$actionQueue);
456
+ yield this.flushActionQueue();
457
+ // The only leeway the Server has is with the timing.
458
+ // In the best case, the Server can close the TransportConnections for the affected Endpoints and leave any
459
+ // Subscriptions intact. This should appear no different than a network interruption from the
460
+ // perspective of the Client. The Client should be prepared to deal with Certificate changes
461
+ // during its reconnect logic. In the worst case, a full shutdown which affects all connected
462
+ // Clients will be necessary. In the latter case, the Server shall advertise its intent to interrupt
463
+ // connections by setting the SecondsTillShutdown and ShutdownReason Properties in the
464
+ // ServerStatus Variable.
465
+ // If the Secure Channel being used to call this Method will be affected by the Certificate change
466
+ // then the Server shall introduce a delay long enough to allow the caller to receive a reply.
467
+ return node_opcua_basic_types_1.StatusCodes.Good;
468
+ });
469
+ }
470
+ getCertificateManager(certificateGroupId) {
471
+ const groupName = findCertificateGroupName(certificateGroupId);
472
+ return this._map[groupName] || null;
473
+ }
474
+ addPendingTask(functor) {
475
+ this._pendingTasks.push(functor);
476
+ }
477
+ applyPendingTasks() {
478
+ var _a, e_1, _b, _c;
479
+ return __awaiter(this, void 0, void 0, function* () {
480
+ debugLog("start applyPendingTasks");
481
+ const promises = [];
482
+ const t = this._pendingTasks.splice(0);
483
+ if (false) {
484
+ try {
485
+ // node 10.2 and above
486
+ for (var _d = true, t_1 = __asyncValues(t), t_1_1; t_1_1 = yield t_1.next(), _a = t_1_1.done, !_a;) {
487
+ _c = t_1_1.value;
488
+ _d = false;
489
+ try {
490
+ const task = _c;
491
+ yield task();
492
+ }
493
+ finally {
494
+ _d = true;
495
+ }
496
+ }
497
+ }
498
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
499
+ finally {
500
+ try {
501
+ if (!_d && !_a && (_b = t_1.return)) yield _b.call(t_1);
502
+ }
503
+ finally { if (e_1) throw e_1.error; }
504
+ }
505
+ }
506
+ else {
507
+ while (t.length) {
508
+ const task = t.shift();
509
+ yield task();
510
+ }
511
+ }
512
+ yield Promise.all(promises);
513
+ debugLog("end applyPendingTasks");
514
+ });
515
+ }
516
+ flushActionQueue() {
517
+ return __awaiter(this, void 0, void 0, function* () {
518
+ while (this.$$actionQueue.length) {
519
+ const first = this.$$actionQueue.pop();
520
+ yield first();
521
+ }
522
+ });
523
+ }
524
+ }
525
+ exports.PushCertificateManagerServerImpl = PushCertificateManagerServerImpl;
526
+ //# sourceMappingURL=push_certificate_manager_server_impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push_certificate_manager_server_impl.js","sourceRoot":"","sources":["../../source/server/push_certificate_manager_server_impl.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,mCAAsC;AACtC,yBAAyB;AACzB,6BAA6B;AAC7B,mCAAqD;AACrD,+BAAiC;AAEjC,iCAAiC;AAEjC,yDAA2C;AAC3C,mEAAiE;AACjE,yDAW2B;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MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC5B,QAAQ,CAAC,uBAAuB,CAAC,CAAC;;KACrC;IAEa,gBAAgB;;YAC1B,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE;gBAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,EAAG,CAAC;gBACxC,MAAM,KAAM,EAAE,CAAC;aAClB;QACL,CAAC;KAAA;CACJ;AA5cD,4EA4cC"}
@@ -0,0 +1,3 @@
1
+ import { RolePermissionTypeOptions } from "node-opcua-address-space";
2
+ export declare const rolePermissionRestricted: RolePermissionTypeOptions[];
3
+ export declare const rolePermissionAdminOnly: RolePermissionTypeOptions[];
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rolePermissionAdminOnly = exports.rolePermissionRestricted = void 0;
4
+ const node_opcua_address_space_1 = require("node-opcua-address-space");
5
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
6
+ exports.rolePermissionRestricted = [
7
+ {
8
+ roleId: node_opcua_address_space_1.WellKnownRoles.Anonymous,
9
+ permissions: node_opcua_address_space_1.PermissionType.Browse,
10
+ },
11
+ {
12
+ roleId: node_opcua_address_space_1.WellKnownRoles.AuthenticatedUser,
13
+ permissions: node_opcua_address_space_1.PermissionType.Browse,
14
+ },
15
+ {
16
+ roleId: node_opcua_address_space_1.WellKnownRoles.ConfigureAdmin,
17
+ permissions: (0, node_opcua_data_model_1.makePermissionFlag)("Browse | ReadRolePermissions | Read | ReadHistory | ReceiveEvents")
18
+ },
19
+ {
20
+ roleId: node_opcua_address_space_1.WellKnownRoles.SecurityAdmin,
21
+ permissions: node_opcua_data_model_1.allPermissions
22
+ },
23
+ ];
24
+ exports.rolePermissionAdminOnly = [
25
+ {
26
+ roleId: node_opcua_address_space_1.WellKnownRoles.SecurityAdmin,
27
+ permissions: node_opcua_data_model_1.allPermissions
28
+ },
29
+ /* {
30
+ roleId: WellKnownRoles.Anonymous,
31
+ permissions: PermissionType.Browse
32
+ },
33
+ {
34
+ roleId: WellKnownRoles.AuthenticatedUser,
35
+ permissions: PermissionType.Browse
36
+ }
37
+ */
38
+ ];
39
+ //# sourceMappingURL=roles_and_permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles_and_permissions.js","sourceRoot":"","sources":["../../source/server/roles_and_permissions.ts"],"names":[],"mappings":";;;AAAA,uEAAqG;AACrG,iEAA2E;AAE9D,QAAA,wBAAwB,GAAgC;IAEjE;QACI,MAAM,EAAE,yCAAc,CAAC,SAAS;QAChC,WAAW,EAAE,yCAAc,CAAC,MAAM;KACrC;IACD;QACI,MAAM,EAAE,yCAAc,CAAC,iBAAiB;QACxC,WAAW,EAAE,yCAAc,CAAC,MAAM;KACrC;IACD;QACI,MAAM,EAAE,yCAAc,CAAC,cAAc;QACrC,WAAW,EAAE,IAAA,0CAAkB,EAAC,mEAAmE,CAAC;KACvG;IACD;QACI,MAAM,EAAE,yCAAc,CAAC,aAAa;QACpC,WAAW,EAAE,sCAAc;KAC9B;CACJ,CAAC;AACW,QAAA,uBAAuB,GAAgC;IAChE;QACI,MAAM,EAAE,yCAAc,CAAC,aAAa;QACpC,WAAW,EAAE,sCAAc;KAC9B;IACJ;;;;;;;;MAQE;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ISessionContext } from "node-opcua-address-space";
2
+ export declare function hasExpectedUserAccess(context: ISessionContext): boolean;
3
+ export declare function hasEncryptedChannel(context: ISessionContext): boolean;