node-opcua-client 2.74.0 → 2.76.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alarms_and_conditions/client_alarm.d.ts +49 -45
- package/dist/alarms_and_conditions/client_alarm.js +109 -101
- package/dist/alarms_and_conditions/client_alarm.js.map +1 -1
- package/dist/alarms_and_conditions/client_alarm_list.d.ts +25 -25
- package/dist/alarms_and_conditions/client_alarm_list.js +97 -97
- package/dist/alarms_and_conditions/client_alarm_list.js.map +1 -1
- package/dist/alarms_and_conditions/client_alarm_tools.d.ts +4 -4
- package/dist/alarms_and_conditions/client_alarm_tools.js +156 -152
- package/dist/alarms_and_conditions/client_alarm_tools.js.map +1 -1
- package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.d.ts +18 -18
- package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.js +192 -190
- package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.js.map +1 -1
- package/dist/alarms_and_conditions/client_alarm_tools_dump_event.d.ts +9 -9
- package/dist/alarms_and_conditions/client_alarm_tools_dump_event.js +73 -73
- package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.d.ts +3 -8
- package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.js +118 -120
- package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.js.map +1 -1
- package/dist/alarms_and_conditions/client_tools.d.ts +7 -7
- package/dist/alarms_and_conditions/client_tools.js +180 -180
- package/dist/client_base.d.ts +277 -277
- package/dist/client_base.js +14 -14
- package/dist/client_monitored_item.d.ts +21 -21
- package/dist/client_monitored_item.js +11 -11
- package/dist/client_monitored_item_base.d.ts +39 -39
- package/dist/client_monitored_item_base.js +2 -2
- package/dist/client_monitored_item_group.d.ts +18 -18
- package/dist/client_monitored_item_group.js +13 -13
- package/dist/client_monitored_item_toolbox.d.ts +15 -15
- package/dist/client_monitored_item_toolbox.js +117 -117
- package/dist/client_session.d.ts +484 -484
- package/dist/client_session.js +10 -10
- package/dist/client_session_keepalive_manager.d.ts +34 -34
- package/dist/client_session_keepalive_manager.js +150 -150
- package/dist/client_subscription.d.ts +241 -241
- package/dist/client_subscription.js +14 -14
- package/dist/client_utils.d.ts +22 -22
- package/dist/client_utils.js +88 -88
- package/dist/common.d.ts +17 -17
- package/dist/common.js +5 -5
- package/dist/index.d.ts +55 -55
- package/dist/index.js +93 -93
- package/dist/opcua_client.d.ts +132 -132
- package/dist/opcua_client.js +33 -33
- package/dist/private/client_base_impl.d.ts +157 -157
- package/dist/private/client_base_impl.js +1337 -1337
- package/dist/private/client_monitored_item_base_impl.d.ts +3 -3
- package/dist/private/client_monitored_item_base_impl.js +4 -4
- package/dist/private/client_monitored_item_group_impl.d.ts +53 -53
- package/dist/private/client_monitored_item_group_impl.js +159 -159
- package/dist/private/client_monitored_item_impl.d.ts +93 -93
- package/dist/private/client_monitored_item_impl.js +305 -304
- package/dist/private/client_monitored_item_impl.js.map +1 -1
- package/dist/private/client_publish_engine.d.ts +62 -62
- package/dist/private/client_publish_engine.js +408 -408
- package/dist/private/client_session_impl.d.ts +621 -621
- package/dist/private/client_session_impl.js +1302 -1302
- package/dist/private/client_subscription_impl.d.ts +93 -93
- package/dist/private/client_subscription_impl.js +748 -748
- package/dist/private/i_private_client.d.ts +18 -18
- package/dist/private/i_private_client.js +2 -2
- package/dist/private/opcua_client_impl.d.ts +169 -169
- package/dist/private/opcua_client_impl.js +981 -981
- package/dist/reconnection.d.ts +9 -9
- package/dist/reconnection.js +408 -408
- package/dist/tools/findservers.d.ts +20 -20
- package/dist/tools/findservers.js +61 -61
- package/dist/tools/read_history_server_capabilities.d.ts +6 -6
- package/dist/tools/read_history_server_capabilities.js +99 -99
- package/dist/verify.d.ts +5 -5
- package/dist/verify.js +134 -134
- package/package.json +46 -46
- package/source/alarms_and_conditions/client_alarm.ts +28 -17
- package/source/alarms_and_conditions/client_alarm_list.ts +1 -0
- package/source/alarms_and_conditions/client_alarm_tools.ts +33 -23
- package/source/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.ts +10 -4
- package/source/alarms_and_conditions/client_alarm_tools_extractConditionFields.ts +11 -11
- package/source/private/client_monitored_item_impl.ts +4 -3
package/dist/verify.js
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.performCertificateSanityCheck = exports.verifyIsOPCUAValidCertificate = void 0;
|
|
13
|
-
const node_opcua_crypto_1 = require("node-opcua-crypto");
|
|
14
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
15
|
-
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
16
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
17
|
-
const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
|
|
18
|
-
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
19
|
-
function verifyIsOPCUAValidCertificate(certificate, certificateFile, type, applicationUri) {
|
|
20
|
-
var _a, _b, _c, _d, _e;
|
|
21
|
-
const certificateInfo = (0, node_opcua_crypto_1.exploreCertificate)(certificate);
|
|
22
|
-
const now = new Date();
|
|
23
|
-
if (certificateInfo.tbsCertificate.validity.notBefore.getTime() > now.getTime()) {
|
|
24
|
-
// check that certificate is active
|
|
25
|
-
// certificate is not active yet
|
|
26
|
-
warningLog(`[NODE-OPCUA-W02] The certificate is not active yet\n` +
|
|
27
|
-
`notBefore ${certificateInfo.tbsCertificate.validity.notBefore.toISOString()}\n` +
|
|
28
|
-
`certificateFile ${certificateFile}`);
|
|
29
|
-
}
|
|
30
|
-
// check that certificate has not expired
|
|
31
|
-
if (certificateInfo.tbsCertificate.validity.notAfter.getTime() <= now.getTime()) {
|
|
32
|
-
// certificate is obsolete
|
|
33
|
-
warningLog(`[NODE-OPCUA-W03] The certificate has expired\n` +
|
|
34
|
-
`Please regenerate a valid certificate\n` +
|
|
35
|
-
`notAfter = ${certificateInfo.tbsCertificate.validity.notAfter.toISOString()}\n` +
|
|
36
|
-
`certificateFile= ${certificateFile}`);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
const tenDays = 10 * 24 * 60 * 60 * 1000;
|
|
40
|
-
if (certificateInfo.tbsCertificate.validity.notAfter.getTime() <= now.getTime() + tenDays) {
|
|
41
|
-
// certificate is going to expired very soon
|
|
42
|
-
warningLog(`[NODE-OPCUA-W05] The certificate is about to expire in less than 10 days.\n` +
|
|
43
|
-
`Please regenerate a valid certificate as soon as possible\n` +
|
|
44
|
-
`notAfter = ${certificateInfo.tbsCertificate.validity.notAfter.toISOString()}\n` +
|
|
45
|
-
`certificateFile= ${certificateFile}\n`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// check that server certificate matches Application URI
|
|
49
|
-
const uniformResourceIdentifier = (_c = (_b = (_a = certificateInfo === null || certificateInfo === void 0 ? void 0 : certificateInfo.tbsCertificate) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.subjectAltName) === null || _c === void 0 ? void 0 : _c.uniformResourceIdentifier;
|
|
50
|
-
if (!uniformResourceIdentifier) {
|
|
51
|
-
warningLog(`[NODE-OPCUA-W14] The certificate subjectAltName uniformResourceIdentifier is missing.\n` +
|
|
52
|
-
`Please regenerate a specific certificate with a uniformResourceIdentifier that matches your ${type} applicationUri\n` +
|
|
53
|
-
`applicationUri = ${applicationUri}\n` +
|
|
54
|
-
`certificateFile = ${certificateFile}\n`);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
else if (uniformResourceIdentifier[0] !== applicationUri) {
|
|
58
|
-
warningLog(`[NODE-OPCUA-W06] The certificate subjectAltName does not match the ${type} applicationUri\n` +
|
|
59
|
-
`Please regenerate a specific certificate that matches your ${type} applicationUri\n` +
|
|
60
|
-
`certificate subjectAltName = ${uniformResourceIdentifier[0]}\n` +
|
|
61
|
-
`${type} applicationUri = ${applicationUri}\n` +
|
|
62
|
-
`certificateFile = ${certificateFile}\n`);
|
|
63
|
-
}
|
|
64
|
-
const keyUsage = (_d = certificateInfo.tbsCertificate.extensions) === null || _d === void 0 ? void 0 : _d.keyUsage;
|
|
65
|
-
if (!keyUsage) {
|
|
66
|
-
warningLog(`[NODE-OPCUA-W15] The certificate keyUsage is missing\n` + `certificateFile = ${certificateFile}`);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
// spec says that certificate shall include digitalSignature, nonRepudiation, keyEncipherment and dataEncipherment.
|
|
70
|
-
// Other key uses are allowed.
|
|
71
|
-
if (!keyUsage.digitalSignature || !keyUsage.nonRepudiation || !keyUsage.keyEncipherment || !keyUsage.dataEncipherment) {
|
|
72
|
-
warningLog(`[NODE-OPCUA-W16] The certificate keyUsage must include digitalSignature, nonRepudiation, keyEncipherment and dataEncipherment.\n` +
|
|
73
|
-
`see https://reference.opcfoundation.org/v104/Core/docs/Part6/6.2.2/\n` +
|
|
74
|
-
`certificateFile = ${certificateFile}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const extKeyUsage = (_e = certificateInfo.tbsCertificate.extensions) === null || _e === void 0 ? void 0 : _e.extKeyUsage;
|
|
78
|
-
if (!extKeyUsage) {
|
|
79
|
-
warningLog(`[NODE-OPCUA-W17] The certificate extKeyUsage is missing\n` + `certificateFile = ${certificateFile}`);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
// spec says that certificate shall include digitalSignature, nonRepudiation, keyEncipherment and dataEncipherment.
|
|
83
|
-
// Other key uses are allowed.
|
|
84
|
-
if (!extKeyUsage.clientAuth && !extKeyUsage.serverAuth) {
|
|
85
|
-
warningLog(`[NODE-OPCUA-W18] The certificate extKeyUsage must include clientAuth and/or serverAuth.\n` +
|
|
86
|
-
`see https://reference.opcfoundation.org/v104/Core/docs/Part6/6.2.2/\n` +
|
|
87
|
-
`certificateFile = ${certificateFile}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const keyLengthInBits = certificateInfo.tbsCertificate.subjectPublicKeyInfo.keyLength * 8;
|
|
91
|
-
if (keyLengthInBits < 1024) {
|
|
92
|
-
errorLog(`[NODE-OPCUA-W19] The public key length shall be greater than or equal to 1024 bits. key length is ${keyLengthInBits}.\n` +
|
|
93
|
-
`see https://reference.opcfoundation.org/v104/GDS/docs/7.6.3/\n` +
|
|
94
|
-
`certificateFile = ${certificateFile}`);
|
|
95
|
-
}
|
|
96
|
-
else if (keyLengthInBits < 2048) {
|
|
97
|
-
warningLog(`[NODE-OPCUA-W23] key lengths less than 2048 are considered insecure. key length is ${keyLengthInBits}\n` +
|
|
98
|
-
`see https://reference.opcfoundation.org/v104/Core/docs/Part2/6.8/\n` +
|
|
99
|
-
`certificateFile = ${certificateFile}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.verifyIsOPCUAValidCertificate = verifyIsOPCUAValidCertificate;
|
|
103
|
-
function performCertificateSanityCheck(serverOrClient, certificateManager, applicationUri) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
// verify that certificate is matching private key, and inform the developper if not
|
|
106
|
-
const certificate = this.getCertificate();
|
|
107
|
-
const privateKey = (0, node_opcua_crypto_1.convertPEMtoDER)(this.getPrivateKey());
|
|
108
|
-
//
|
|
109
|
-
if (!(0, node_opcua_crypto_1.publicKeyAndPrivateKeyMatches)(certificate, privateKey)) {
|
|
110
|
-
errorLog("[NODE-OPCUA-E01] Configuration error : the certificate and the private key do not match !");
|
|
111
|
-
errorLog(" please check the configuration of the OPCUA Server");
|
|
112
|
-
errorLog(" privateKey= ", this.privateKeyFile);
|
|
113
|
-
errorLog(" certificateManager.privateKey= ", certificateManager.privateKey);
|
|
114
|
-
errorLog(" certificateFile= ", this.certificateFile);
|
|
115
|
-
throw new Error("[NODE-OPCUA-E01] Configuration error : the certificate and the private key do not match ! please fix your configuration");
|
|
116
|
-
}
|
|
117
|
-
// verify that the certificate provided has the right key length ( at least 2048)
|
|
118
|
-
const privateKeyInfo = (0, node_opcua_crypto_1.explorePrivateKey)(privateKey);
|
|
119
|
-
const keyLengthInBits = privateKeyInfo.modulus.length * 8;
|
|
120
|
-
if (keyLengthInBits <= 1024) {
|
|
121
|
-
warningLog(`[NODE-OPCUA-W04] The public/private key pair uses a key length which is equal or lower than 1024 bits. ( key length was ${keyLengthInBits} )\n` +
|
|
122
|
-
`OPCUA version 1.04 requires that security key length are greater or equal to 2048 bits.\n` +
|
|
123
|
-
`The ${serverOrClient} is operating at risk. `);
|
|
124
|
-
}
|
|
125
|
-
// verify that the certificate has a valid date and has expected extensions fields such as DNS and IP.
|
|
126
|
-
const status1 = yield certificateManager.trustCertificate(certificate);
|
|
127
|
-
const status = yield certificateManager.verifyCertificateAsync(certificate);
|
|
128
|
-
if (status !== "Good") {
|
|
129
|
-
warningLog("[NODE-OPCUA-W04] Warning: the certificate status is = ", status, " file = ", this.certificateFile);
|
|
130
|
-
}
|
|
131
|
-
verifyIsOPCUAValidCertificate(certificate, this.certificateFile, serverOrClient, applicationUri);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
exports.performCertificateSanityCheck = performCertificateSanityCheck;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.performCertificateSanityCheck = exports.verifyIsOPCUAValidCertificate = void 0;
|
|
13
|
+
const node_opcua_crypto_1 = require("node-opcua-crypto");
|
|
14
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
15
|
+
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
16
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
17
|
+
const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
|
|
18
|
+
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
19
|
+
function verifyIsOPCUAValidCertificate(certificate, certificateFile, type, applicationUri) {
|
|
20
|
+
var _a, _b, _c, _d, _e;
|
|
21
|
+
const certificateInfo = (0, node_opcua_crypto_1.exploreCertificate)(certificate);
|
|
22
|
+
const now = new Date();
|
|
23
|
+
if (certificateInfo.tbsCertificate.validity.notBefore.getTime() > now.getTime()) {
|
|
24
|
+
// check that certificate is active
|
|
25
|
+
// certificate is not active yet
|
|
26
|
+
warningLog(`[NODE-OPCUA-W02] The certificate is not active yet\n` +
|
|
27
|
+
`notBefore ${certificateInfo.tbsCertificate.validity.notBefore.toISOString()}\n` +
|
|
28
|
+
`certificateFile ${certificateFile}`);
|
|
29
|
+
}
|
|
30
|
+
// check that certificate has not expired
|
|
31
|
+
if (certificateInfo.tbsCertificate.validity.notAfter.getTime() <= now.getTime()) {
|
|
32
|
+
// certificate is obsolete
|
|
33
|
+
warningLog(`[NODE-OPCUA-W03] The certificate has expired\n` +
|
|
34
|
+
`Please regenerate a valid certificate\n` +
|
|
35
|
+
`notAfter = ${certificateInfo.tbsCertificate.validity.notAfter.toISOString()}\n` +
|
|
36
|
+
`certificateFile= ${certificateFile}`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const tenDays = 10 * 24 * 60 * 60 * 1000;
|
|
40
|
+
if (certificateInfo.tbsCertificate.validity.notAfter.getTime() <= now.getTime() + tenDays) {
|
|
41
|
+
// certificate is going to expired very soon
|
|
42
|
+
warningLog(`[NODE-OPCUA-W05] The certificate is about to expire in less than 10 days.\n` +
|
|
43
|
+
`Please regenerate a valid certificate as soon as possible\n` +
|
|
44
|
+
`notAfter = ${certificateInfo.tbsCertificate.validity.notAfter.toISOString()}\n` +
|
|
45
|
+
`certificateFile= ${certificateFile}\n`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// check that server certificate matches Application URI
|
|
49
|
+
const uniformResourceIdentifier = (_c = (_b = (_a = certificateInfo === null || certificateInfo === void 0 ? void 0 : certificateInfo.tbsCertificate) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.subjectAltName) === null || _c === void 0 ? void 0 : _c.uniformResourceIdentifier;
|
|
50
|
+
if (!uniformResourceIdentifier) {
|
|
51
|
+
warningLog(`[NODE-OPCUA-W14] The certificate subjectAltName uniformResourceIdentifier is missing.\n` +
|
|
52
|
+
`Please regenerate a specific certificate with a uniformResourceIdentifier that matches your ${type} applicationUri\n` +
|
|
53
|
+
`applicationUri = ${applicationUri}\n` +
|
|
54
|
+
`certificateFile = ${certificateFile}\n`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
else if (uniformResourceIdentifier[0] !== applicationUri) {
|
|
58
|
+
warningLog(`[NODE-OPCUA-W06] The certificate subjectAltName does not match the ${type} applicationUri\n` +
|
|
59
|
+
`Please regenerate a specific certificate that matches your ${type} applicationUri\n` +
|
|
60
|
+
`certificate subjectAltName = ${uniformResourceIdentifier[0]}\n` +
|
|
61
|
+
`${type} applicationUri = ${applicationUri}\n` +
|
|
62
|
+
`certificateFile = ${certificateFile}\n`);
|
|
63
|
+
}
|
|
64
|
+
const keyUsage = (_d = certificateInfo.tbsCertificate.extensions) === null || _d === void 0 ? void 0 : _d.keyUsage;
|
|
65
|
+
if (!keyUsage) {
|
|
66
|
+
warningLog(`[NODE-OPCUA-W15] The certificate keyUsage is missing\n` + `certificateFile = ${certificateFile}`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// spec says that certificate shall include digitalSignature, nonRepudiation, keyEncipherment and dataEncipherment.
|
|
70
|
+
// Other key uses are allowed.
|
|
71
|
+
if (!keyUsage.digitalSignature || !keyUsage.nonRepudiation || !keyUsage.keyEncipherment || !keyUsage.dataEncipherment) {
|
|
72
|
+
warningLog(`[NODE-OPCUA-W16] The certificate keyUsage must include digitalSignature, nonRepudiation, keyEncipherment and dataEncipherment.\n` +
|
|
73
|
+
`see https://reference.opcfoundation.org/v104/Core/docs/Part6/6.2.2/\n` +
|
|
74
|
+
`certificateFile = ${certificateFile}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const extKeyUsage = (_e = certificateInfo.tbsCertificate.extensions) === null || _e === void 0 ? void 0 : _e.extKeyUsage;
|
|
78
|
+
if (!extKeyUsage) {
|
|
79
|
+
warningLog(`[NODE-OPCUA-W17] The certificate extKeyUsage is missing\n` + `certificateFile = ${certificateFile}`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// spec says that certificate shall include digitalSignature, nonRepudiation, keyEncipherment and dataEncipherment.
|
|
83
|
+
// Other key uses are allowed.
|
|
84
|
+
if (!extKeyUsage.clientAuth && !extKeyUsage.serverAuth) {
|
|
85
|
+
warningLog(`[NODE-OPCUA-W18] The certificate extKeyUsage must include clientAuth and/or serverAuth.\n` +
|
|
86
|
+
`see https://reference.opcfoundation.org/v104/Core/docs/Part6/6.2.2/\n` +
|
|
87
|
+
`certificateFile = ${certificateFile}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const keyLengthInBits = certificateInfo.tbsCertificate.subjectPublicKeyInfo.keyLength * 8;
|
|
91
|
+
if (keyLengthInBits < 1024) {
|
|
92
|
+
errorLog(`[NODE-OPCUA-W19] The public key length shall be greater than or equal to 1024 bits. key length is ${keyLengthInBits}.\n` +
|
|
93
|
+
`see https://reference.opcfoundation.org/v104/GDS/docs/7.6.3/\n` +
|
|
94
|
+
`certificateFile = ${certificateFile}`);
|
|
95
|
+
}
|
|
96
|
+
else if (keyLengthInBits < 2048) {
|
|
97
|
+
warningLog(`[NODE-OPCUA-W23] key lengths less than 2048 are considered insecure. key length is ${keyLengthInBits}\n` +
|
|
98
|
+
`see https://reference.opcfoundation.org/v104/Core/docs/Part2/6.8/\n` +
|
|
99
|
+
`certificateFile = ${certificateFile}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.verifyIsOPCUAValidCertificate = verifyIsOPCUAValidCertificate;
|
|
103
|
+
function performCertificateSanityCheck(serverOrClient, certificateManager, applicationUri) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
// verify that certificate is matching private key, and inform the developper if not
|
|
106
|
+
const certificate = this.getCertificate();
|
|
107
|
+
const privateKey = (0, node_opcua_crypto_1.convertPEMtoDER)(this.getPrivateKey());
|
|
108
|
+
//
|
|
109
|
+
if (!(0, node_opcua_crypto_1.publicKeyAndPrivateKeyMatches)(certificate, privateKey)) {
|
|
110
|
+
errorLog("[NODE-OPCUA-E01] Configuration error : the certificate and the private key do not match !");
|
|
111
|
+
errorLog(" please check the configuration of the OPCUA Server");
|
|
112
|
+
errorLog(" privateKey= ", this.privateKeyFile);
|
|
113
|
+
errorLog(" certificateManager.privateKey= ", certificateManager.privateKey);
|
|
114
|
+
errorLog(" certificateFile= ", this.certificateFile);
|
|
115
|
+
throw new Error("[NODE-OPCUA-E01] Configuration error : the certificate and the private key do not match ! please fix your configuration");
|
|
116
|
+
}
|
|
117
|
+
// verify that the certificate provided has the right key length ( at least 2048)
|
|
118
|
+
const privateKeyInfo = (0, node_opcua_crypto_1.explorePrivateKey)(privateKey);
|
|
119
|
+
const keyLengthInBits = privateKeyInfo.modulus.length * 8;
|
|
120
|
+
if (keyLengthInBits <= 1024) {
|
|
121
|
+
warningLog(`[NODE-OPCUA-W04] The public/private key pair uses a key length which is equal or lower than 1024 bits. ( key length was ${keyLengthInBits} )\n` +
|
|
122
|
+
`OPCUA version 1.04 requires that security key length are greater or equal to 2048 bits.\n` +
|
|
123
|
+
`The ${serverOrClient} is operating at risk. `);
|
|
124
|
+
}
|
|
125
|
+
// verify that the certificate has a valid date and has expected extensions fields such as DNS and IP.
|
|
126
|
+
const status1 = yield certificateManager.trustCertificate(certificate);
|
|
127
|
+
const status = yield certificateManager.verifyCertificateAsync(certificate);
|
|
128
|
+
if (status !== "Good") {
|
|
129
|
+
warningLog("[NODE-OPCUA-W04] Warning: the certificate status is = ", status, " file = ", this.certificateFile);
|
|
130
|
+
}
|
|
131
|
+
verifyIsOPCUAValidCertificate(certificate, this.certificateFile, serverOrClient, applicationUri);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
exports.performCertificateSanityCheck = performCertificateSanityCheck;
|
|
135
135
|
//# sourceMappingURL=verify.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.76.1",
|
|
4
4
|
"description": "pure nodejs OPCUA SDK - module -client",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "npx rimraf dist *.tsbuildinfo certificates",
|
|
@@ -16,62 +16,62 @@
|
|
|
16
16
|
"@ster5/global-mutex": "^1.2.0",
|
|
17
17
|
"@types/async": "^3.2.13",
|
|
18
18
|
"@types/once": "^1.4.0",
|
|
19
|
-
"@types/underscore": "^1.11.4",
|
|
20
19
|
"async": "^3.2.4",
|
|
21
20
|
"callbackify": "^1.1.0",
|
|
22
21
|
"chalk": "4.1.2",
|
|
23
|
-
"
|
|
24
|
-
"node-opcua-
|
|
25
|
-
"node-opcua-
|
|
26
|
-
"node-opcua-
|
|
27
|
-
"node-opcua-
|
|
28
|
-
"node-opcua-
|
|
29
|
-
"node-opcua-common": "2.74.0",
|
|
22
|
+
"node-opcua-assert": "2.76.0",
|
|
23
|
+
"node-opcua-basic-types": "2.76.0",
|
|
24
|
+
"node-opcua-buffer-utils": "2.76.0",
|
|
25
|
+
"node-opcua-certificate-manager": "2.76.0",
|
|
26
|
+
"node-opcua-client-dynamic-extension-object": "2.76.0",
|
|
27
|
+
"node-opcua-common": "2.76.0",
|
|
30
28
|
"node-opcua-constants": "2.74.0",
|
|
31
29
|
"node-opcua-crypto": "^1.11.0",
|
|
32
|
-
"node-opcua-data-model": "2.
|
|
33
|
-
"node-opcua-data-value": "2.
|
|
34
|
-
"node-opcua-date-time": "2.
|
|
35
|
-
"node-opcua-debug": "2.
|
|
36
|
-
"node-opcua-extension-object": "2.
|
|
37
|
-
"node-opcua-hostname": "2.
|
|
38
|
-
"node-opcua-nodeid": "2.
|
|
39
|
-
"node-opcua-object-registry": "2.
|
|
30
|
+
"node-opcua-data-model": "2.76.0",
|
|
31
|
+
"node-opcua-data-value": "2.76.0",
|
|
32
|
+
"node-opcua-date-time": "2.76.0",
|
|
33
|
+
"node-opcua-debug": "2.76.0",
|
|
34
|
+
"node-opcua-extension-object": "2.76.0",
|
|
35
|
+
"node-opcua-hostname": "2.76.0",
|
|
36
|
+
"node-opcua-nodeid": "2.76.0",
|
|
37
|
+
"node-opcua-object-registry": "2.76.0",
|
|
40
38
|
"node-opcua-pki": "^2.17.0",
|
|
41
|
-
"node-opcua-pseudo-session": "2.
|
|
42
|
-
"node-opcua-schemas": "2.
|
|
43
|
-
"node-opcua-secure-channel": "2.
|
|
44
|
-
"node-opcua-service-browse": "2.
|
|
45
|
-
"node-opcua-service-call": "2.
|
|
46
|
-
"node-opcua-service-discovery": "2.
|
|
47
|
-
"node-opcua-service-endpoints": "2.
|
|
48
|
-
"node-opcua-service-filter": "2.
|
|
49
|
-
"node-opcua-service-history": "2.
|
|
50
|
-
"node-opcua-service-query": "2.
|
|
51
|
-
"node-opcua-service-read": "2.
|
|
52
|
-
"node-opcua-service-register-node": "2.
|
|
53
|
-
"node-opcua-service-secure-channel": "2.
|
|
54
|
-
"node-opcua-service-session": "2.
|
|
55
|
-
"node-opcua-service-subscription": "2.
|
|
56
|
-
"node-opcua-service-translate-browse-path": "2.
|
|
57
|
-
"node-opcua-service-write": "2.
|
|
58
|
-
"node-opcua-status-code": "2.
|
|
59
|
-
"node-opcua-types": "2.
|
|
60
|
-
"node-opcua-utils": "2.
|
|
61
|
-
"node-opcua-variant": "2.
|
|
39
|
+
"node-opcua-pseudo-session": "2.76.0",
|
|
40
|
+
"node-opcua-schemas": "2.76.0",
|
|
41
|
+
"node-opcua-secure-channel": "2.76.0",
|
|
42
|
+
"node-opcua-service-browse": "2.76.0",
|
|
43
|
+
"node-opcua-service-call": "2.76.0",
|
|
44
|
+
"node-opcua-service-discovery": "2.76.0",
|
|
45
|
+
"node-opcua-service-endpoints": "2.76.0",
|
|
46
|
+
"node-opcua-service-filter": "2.76.0",
|
|
47
|
+
"node-opcua-service-history": "2.76.0",
|
|
48
|
+
"node-opcua-service-query": "2.76.0",
|
|
49
|
+
"node-opcua-service-read": "2.76.0",
|
|
50
|
+
"node-opcua-service-register-node": "2.76.0",
|
|
51
|
+
"node-opcua-service-secure-channel": "2.76.0",
|
|
52
|
+
"node-opcua-service-session": "2.76.0",
|
|
53
|
+
"node-opcua-service-subscription": "2.76.0",
|
|
54
|
+
"node-opcua-service-translate-browse-path": "2.76.0",
|
|
55
|
+
"node-opcua-service-write": "2.76.0",
|
|
56
|
+
"node-opcua-status-code": "2.76.0",
|
|
57
|
+
"node-opcua-types": "2.76.0",
|
|
58
|
+
"node-opcua-utils": "2.76.0",
|
|
59
|
+
"node-opcua-variant": "2.76.0",
|
|
62
60
|
"once": "^1.4.0",
|
|
63
|
-
"thenify": "^3.3.1"
|
|
64
|
-
"underscore": "^1.13.4"
|
|
61
|
+
"thenify": "^3.3.1"
|
|
65
62
|
},
|
|
66
63
|
"devDependencies": {
|
|
64
|
+
"@types/underscore": "^1.11.4",
|
|
67
65
|
"dequeue": "^1.0.5",
|
|
68
|
-
"
|
|
69
|
-
"node-opcua-
|
|
70
|
-
"node-opcua-
|
|
71
|
-
"node-opcua-
|
|
66
|
+
"mocha": "^10.0.0",
|
|
67
|
+
"node-opcua-address-space": "2.76.1",
|
|
68
|
+
"node-opcua-binary-stream": "2.76.0",
|
|
69
|
+
"node-opcua-factory": "2.76.0",
|
|
70
|
+
"node-opcua-leak-detector": "2.76.0",
|
|
72
71
|
"node-opcua-nodesets": "2.74.0",
|
|
73
72
|
"should": "^13.2.3",
|
|
74
|
-
"sinon": "^14.0.0"
|
|
73
|
+
"sinon": "^14.0.0",
|
|
74
|
+
"underscore": "^1.13.4"
|
|
75
75
|
},
|
|
76
76
|
"eslintConfig": {
|
|
77
77
|
"env": {
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"internet of things"
|
|
94
94
|
],
|
|
95
95
|
"homepage": "http://node-opcua.github.io/",
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "d87d1dc4ab8f153a442f83552e3264621f0a409b"
|
|
97
97
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
2
|
import { assert } from "node-opcua-assert";
|
|
3
|
+
import { make_warningLog } from "node-opcua-debug";
|
|
3
4
|
import { NodeId, resolveNodeId } from "node-opcua-nodeid";
|
|
4
|
-
import { StatusCode
|
|
5
|
+
import { StatusCode } from "node-opcua-status-code";
|
|
5
6
|
import { lowerFirstLetter } from "node-opcua-utils";
|
|
6
7
|
import { DataType, Variant } from "node-opcua-variant";
|
|
7
8
|
import { ClientSession } from "../client_session";
|
|
8
9
|
|
|
10
|
+
const warningLog = make_warningLog(__filename);
|
|
11
|
+
|
|
9
12
|
export interface TVariant<T> extends Variant {
|
|
10
13
|
value: T;
|
|
11
14
|
}
|
|
@@ -20,6 +23,7 @@ export interface EventStuff {
|
|
|
20
23
|
activeState: TTwoStateStatus;
|
|
21
24
|
ackedState: TTwoStateStatus;
|
|
22
25
|
confirmedState: TTwoStateStatus;
|
|
26
|
+
conditionName?: TVariant<string>;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
export interface ClientAlarm {
|
|
@@ -84,36 +88,43 @@ export class ClientAlarm extends EventEmitter {
|
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
/**
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
export function fieldsToJson(fields: string[], eventFields: Variant[], flat?: boolean): EventStuff {
|
|
95
|
+
|
|
96
|
+
function setProperty(_data: Record<string, unknown>, fieldName: string, value: Variant) {
|
|
90
97
|
let name: string;
|
|
91
98
|
if (!fieldName || value === null) {
|
|
92
99
|
return;
|
|
93
100
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
if (!flat) {
|
|
102
|
+
const f = fieldName.split(".");
|
|
103
|
+
if (f.length === 1) {
|
|
104
|
+
fieldName = lowerFirstLetter(fieldName);
|
|
105
|
+
_data[fieldName] = value;
|
|
106
|
+
} else {
|
|
107
|
+
for (let i = 0; i < f.length - 1; i++) {
|
|
108
|
+
name = lowerFirstLetter(f[i]);
|
|
109
|
+
_data[name] = _data[name] || {};
|
|
110
|
+
_data = _data[name] as Record<string, unknown>;
|
|
111
|
+
}
|
|
112
|
+
name = lowerFirstLetter(f[f.length - 1]);
|
|
113
|
+
_data[name] = value;
|
|
103
114
|
}
|
|
104
|
-
|
|
115
|
+
} else {
|
|
116
|
+
const name = fieldName.split(".").map(lowerFirstLetter).join(".");
|
|
105
117
|
_data[name] = value;
|
|
106
118
|
}
|
|
107
119
|
}
|
|
108
120
|
if (fields.length > eventFields.length) {
|
|
109
|
-
|
|
110
|
-
console.log("warning fields.length !== eventFields.length", fields.length, eventFields.length);
|
|
121
|
+
warningLog("warning fields.length !== eventFields.length", fields.length, eventFields.length);
|
|
111
122
|
}
|
|
112
123
|
const data: any = {};
|
|
113
124
|
for (let index = 0; index < fields.length; index++) {
|
|
114
125
|
const variant = eventFields[index];
|
|
115
126
|
setProperty(data, fields[index], variant);
|
|
116
127
|
}
|
|
117
|
-
|
|
128
|
+
|
|
118
129
|
return data;
|
|
119
130
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AttributeIds } from "node-opcua-data-model";
|
|
2
2
|
import { resolveNodeId } from "node-opcua-nodeid";
|
|
3
|
-
import { constructEventFilter } from "node-opcua-service-filter";
|
|
3
|
+
import { constructEventFilter, ofType } from "node-opcua-service-filter";
|
|
4
4
|
import { ReadValueIdOptions, TimestampsToReturn } from "node-opcua-service-read";
|
|
5
5
|
import { CreateSubscriptionRequestOptions, MonitoringParametersOptions } from "node-opcua-service-subscription";
|
|
6
|
-
import { Variant } from "node-opcua-variant";
|
|
7
|
-
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
|
|
6
|
+
import { DataType, Variant } from "node-opcua-variant";
|
|
7
|
+
import { checkDebugFlag, make_debugLog, make_warningLog } from "node-opcua-debug";
|
|
8
8
|
|
|
9
9
|
import { ClientMonitoredItem } from "../client_monitored_item";
|
|
10
10
|
import { ClientSubscription } from "../client_subscription";
|
|
@@ -16,6 +16,7 @@ import { callConditionRefresh } from "./client_tools";
|
|
|
16
16
|
|
|
17
17
|
const doDebug = checkDebugFlag("A&E");
|
|
18
18
|
const debugLog = make_debugLog("A&E");
|
|
19
|
+
const warningLog = make_warningLog("A&E");
|
|
19
20
|
|
|
20
21
|
function r(_key: string, o: { dataType?: unknown; value?: unknown }) {
|
|
21
22
|
if (o && o.dataType === "Null") {
|
|
@@ -67,7 +68,7 @@ export async function installAlarmMonitoring(session: ClientSession): Promise<Cl
|
|
|
67
68
|
_sessionPriv.$clientAlarmList = clientAlarmList;
|
|
68
69
|
|
|
69
70
|
const request: CreateSubscriptionRequestOptions = {
|
|
70
|
-
maxNotificationsPerPublish:
|
|
71
|
+
maxNotificationsPerPublish: 100,
|
|
71
72
|
priority: 6,
|
|
72
73
|
publishingEnabled: true,
|
|
73
74
|
requestedLifetimeCount: 10000,
|
|
@@ -84,21 +85,20 @@ export async function installAlarmMonitoring(session: ClientSession): Promise<Cl
|
|
|
84
85
|
|
|
85
86
|
const fields = await extractConditionFields(session, "AlarmConditionType");
|
|
86
87
|
|
|
87
|
-
const
|
|
88
|
+
const AcknowledgeableConditionType = resolveNodeId("AcknowledgeableConditionType");
|
|
89
|
+
|
|
90
|
+
const eventFilter = constructEventFilter(fields, ofType(AcknowledgeableConditionType));
|
|
88
91
|
|
|
89
92
|
const monitoringParameters: MonitoringParametersOptions = {
|
|
90
93
|
discardOldest: false,
|
|
91
94
|
filter: eventFilter,
|
|
92
|
-
queueSize:
|
|
95
|
+
queueSize: 1000,
|
|
93
96
|
samplingInterval: 0
|
|
94
97
|
};
|
|
95
98
|
|
|
96
99
|
// now create a event monitored Item
|
|
97
100
|
const eventMonitoringItem = await subscription.monitor(itemToMonitor, monitoringParameters, TimestampsToReturn.Both);
|
|
98
101
|
|
|
99
|
-
const RefreshStartEventType = resolveNodeId("RefreshStartEventType").toString();
|
|
100
|
-
const RefreshEndEventType = resolveNodeId("RefreshEndEventType").toString();
|
|
101
|
-
|
|
102
102
|
const queueEvent: EventStuff[] = [];
|
|
103
103
|
function flushQueue() {
|
|
104
104
|
const q = [...queueEvent];
|
|
@@ -110,17 +110,25 @@ export async function installAlarmMonitoring(session: ClientSession): Promise<Cl
|
|
|
110
110
|
|
|
111
111
|
let inInit = true;
|
|
112
112
|
eventMonitoringItem.on("changed", (eventFields: Variant[]) => {
|
|
113
|
-
|
|
114
|
-
const pojo = fieldsToJson(fields, eventFields)
|
|
113
|
+
|
|
114
|
+
const pojo = fieldsToJson(fields, eventFields);
|
|
115
|
+
const { eventType, eventId, conditionId, conditionName } = pojo;
|
|
116
|
+
|
|
117
|
+
debugLog(
|
|
118
|
+
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ---- ALARM RECEIVED " +
|
|
119
|
+
eventType.value.toString() +
|
|
120
|
+
" " +
|
|
121
|
+
eventId.value?.toString("hex")
|
|
122
|
+
);
|
|
115
123
|
try {
|
|
116
|
-
if (
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (pojo.eventType.value.toString() === RefreshEndEventType) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (!pojo.conditionId || !pojo.conditionId.value || pojo.conditionId.dataType === 0) {
|
|
124
|
+
if (!conditionId || !conditionId.value || conditionId.dataType === DataType.Null) {
|
|
123
125
|
// not a acknowledgeable condition
|
|
126
|
+
warningLog(
|
|
127
|
+
" not acknowledgeable condition ---- " + eventType.value.toString() + " ",
|
|
128
|
+
conditionId,
|
|
129
|
+
conditionName?.value,
|
|
130
|
+
" " + eventId.value?.toString("hex")
|
|
131
|
+
);
|
|
124
132
|
return;
|
|
125
133
|
}
|
|
126
134
|
queueEvent.push(pojo);
|
|
@@ -128,10 +136,8 @@ export async function installAlarmMonitoring(session: ClientSession): Promise<Cl
|
|
|
128
136
|
setTimeout(() => flushQueue(), 10);
|
|
129
137
|
}
|
|
130
138
|
} catch (err) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// tslint:disable-next-line: no-console
|
|
134
|
-
console.log("Error !!", err);
|
|
139
|
+
warningLog(JSON.stringify(pojo, r, " "));
|
|
140
|
+
warningLog("Error !!", err);
|
|
135
141
|
}
|
|
136
142
|
|
|
137
143
|
// Release 1.04 8 OPC Unified Architecture, Part 9
|
|
@@ -150,7 +156,11 @@ export async function installAlarmMonitoring(session: ClientSession): Promise<Cl
|
|
|
150
156
|
try {
|
|
151
157
|
await callConditionRefresh(subscription);
|
|
152
158
|
} catch (err) {
|
|
153
|
-
|
|
159
|
+
if ((err as Error).message.match(/BadNothingToDo/)) {
|
|
160
|
+
/** fine! nothing to do */
|
|
161
|
+
} else {
|
|
162
|
+
warningLog("Server may not implement condition refresh", (<Error>err).message);
|
|
163
|
+
}
|
|
154
164
|
}
|
|
155
165
|
_sessionPriv.$monitoredItemForAlarmList = eventMonitoringItem;
|
|
156
166
|
|