node-opcua-client 2.71.0 → 2.72.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 (81) hide show
  1. package/dist/alarms_and_conditions/client_alarm.d.ts +45 -43
  2. package/dist/alarms_and_conditions/client_alarm.js +101 -84
  3. package/dist/alarms_and_conditions/client_alarm.js.map +1 -1
  4. package/dist/alarms_and_conditions/client_alarm_list.d.ts +25 -21
  5. package/dist/alarms_and_conditions/client_alarm_list.js +97 -97
  6. package/dist/alarms_and_conditions/client_alarm_list.js.map +1 -1
  7. package/dist/alarms_and_conditions/client_alarm_tools.d.ts +4 -4
  8. package/dist/alarms_and_conditions/client_alarm_tools.js +152 -139
  9. package/dist/alarms_and_conditions/client_alarm_tools.js.map +1 -1
  10. package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.d.ts +18 -18
  11. package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.js +190 -190
  12. package/dist/alarms_and_conditions/client_alarm_tools_dump_event.d.ts +9 -9
  13. package/dist/alarms_and_conditions/client_alarm_tools_dump_event.js +73 -73
  14. package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.d.ts +8 -8
  15. package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.js +120 -120
  16. package/dist/alarms_and_conditions/client_tools.d.ts +7 -7
  17. package/dist/alarms_and_conditions/client_tools.js +180 -180
  18. package/dist/alarms_and_conditions/client_tools.js.map +1 -1
  19. package/dist/client_base.d.ts +294 -290
  20. package/dist/client_base.js +13 -13
  21. package/dist/client_base.js.map +1 -1
  22. package/dist/client_monitored_item.d.ts +21 -21
  23. package/dist/client_monitored_item.js +11 -11
  24. package/dist/client_monitored_item_base.d.ts +39 -39
  25. package/dist/client_monitored_item_base.js +2 -2
  26. package/dist/client_monitored_item_group.d.ts +18 -18
  27. package/dist/client_monitored_item_group.js +13 -13
  28. package/dist/client_monitored_item_toolbox.d.ts +15 -15
  29. package/dist/client_monitored_item_toolbox.js +117 -117
  30. package/dist/client_session.d.ts +484 -484
  31. package/dist/client_session.js +10 -10
  32. package/dist/client_session_keepalive_manager.d.ts +34 -34
  33. package/dist/client_session_keepalive_manager.js +150 -150
  34. package/dist/client_subscription.d.ts +241 -241
  35. package/dist/client_subscription.js +14 -14
  36. package/dist/client_utils.d.ts +22 -22
  37. package/dist/client_utils.js +88 -88
  38. package/dist/common.d.ts +17 -17
  39. package/dist/common.js +5 -5
  40. package/dist/index.d.ts +55 -55
  41. package/dist/index.js +93 -93
  42. package/dist/opcua_client.d.ts +132 -132
  43. package/dist/opcua_client.js +33 -33
  44. package/dist/opcua_client.js.map +1 -1
  45. package/dist/private/client_base_impl.d.ts +169 -169
  46. package/dist/private/client_base_impl.js +1324 -1316
  47. package/dist/private/client_base_impl.js.map +1 -1
  48. package/dist/private/client_monitored_item_base_impl.d.ts +3 -3
  49. package/dist/private/client_monitored_item_base_impl.js +4 -4
  50. package/dist/private/client_monitored_item_group_impl.d.ts +53 -53
  51. package/dist/private/client_monitored_item_group_impl.js +159 -159
  52. package/dist/private/client_monitored_item_impl.d.ts +93 -93
  53. package/dist/private/client_monitored_item_impl.js +304 -304
  54. package/dist/private/client_publish_engine.d.ts +62 -62
  55. package/dist/private/client_publish_engine.js +408 -408
  56. package/dist/private/client_session_impl.d.ts +621 -621
  57. package/dist/private/client_session_impl.js +1301 -1301
  58. package/dist/private/client_subscription_impl.d.ts +93 -93
  59. package/dist/private/client_subscription_impl.js +743 -734
  60. package/dist/private/client_subscription_impl.js.map +1 -1
  61. package/dist/private/i_private_client.d.ts +18 -18
  62. package/dist/private/i_private_client.js +2 -2
  63. package/dist/private/opcua_client_impl.d.ts +169 -169
  64. package/dist/private/opcua_client_impl.js +978 -978
  65. package/dist/reconnection.d.ts +9 -9
  66. package/dist/reconnection.js +362 -362
  67. package/dist/tools/findservers.d.ts +20 -20
  68. package/dist/tools/findservers.js +61 -61
  69. package/dist/tools/read_history_server_capabilities.d.ts +6 -6
  70. package/dist/tools/read_history_server_capabilities.js +99 -99
  71. package/dist/verify.d.ts +5 -5
  72. package/dist/verify.js +134 -134
  73. package/package.json +30 -30
  74. package/source/alarms_and_conditions/client_alarm.ts +21 -1
  75. package/source/alarms_and_conditions/client_alarm_list.ts +6 -2
  76. package/source/alarms_and_conditions/client_alarm_tools.ts +32 -15
  77. package/source/alarms_and_conditions/client_tools.ts +4 -4
  78. package/source/client_base.ts +6 -3
  79. package/source/opcua_client.ts +0 -2
  80. package/source/private/client_base_impl.ts +22 -13
  81. package/source/private/client_subscription_impl.ts +8 -0
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.71.0",
3
+ "version": "2.72.2",
4
4
  "description": "pure nodejs OPCUA SDK - module -client",
5
5
  "scripts": {
6
6
  "clean": "npx rimraf dist *.tsbuildinfo certificates",
@@ -22,52 +22,52 @@
22
22
  "chalk": "4.1.2",
23
23
  "delayed": "^2.0.0",
24
24
  "node-opcua-assert": "2.66.0",
25
- "node-opcua-basic-types": "2.71.0",
25
+ "node-opcua-basic-types": "2.72.1",
26
26
  "node-opcua-buffer-utils": "2.71.0",
27
- "node-opcua-certificate-manager": "2.71.0",
28
- "node-opcua-client-dynamic-extension-object": "2.71.0",
29
- "node-opcua-common": "2.71.0",
27
+ "node-opcua-certificate-manager": "2.72.1",
28
+ "node-opcua-client-dynamic-extension-object": "2.72.2",
29
+ "node-opcua-common": "2.72.2",
30
30
  "node-opcua-constants": "2.70.0",
31
31
  "node-opcua-crypto": "^1.11.0",
32
- "node-opcua-data-model": "2.71.0",
33
- "node-opcua-data-value": "2.71.0",
32
+ "node-opcua-data-model": "2.72.1",
33
+ "node-opcua-data-value": "2.72.2",
34
34
  "node-opcua-date-time": "2.71.0",
35
35
  "node-opcua-debug": "2.71.0",
36
- "node-opcua-extension-object": "2.71.0",
36
+ "node-opcua-extension-object": "2.72.1",
37
37
  "node-opcua-hostname": "2.67.0",
38
38
  "node-opcua-nodeid": "2.71.0",
39
39
  "node-opcua-object-registry": "2.71.0",
40
40
  "node-opcua-pki": "^2.17.0",
41
- "node-opcua-pseudo-session": "2.71.0",
42
- "node-opcua-schemas": "2.71.0",
43
- "node-opcua-secure-channel": "2.71.0",
44
- "node-opcua-service-browse": "2.71.0",
45
- "node-opcua-service-call": "2.71.0",
46
- "node-opcua-service-discovery": "2.71.0",
47
- "node-opcua-service-endpoints": "2.71.0",
48
- "node-opcua-service-filter": "2.71.0",
49
- "node-opcua-service-history": "2.71.0",
50
- "node-opcua-service-query": "2.71.0",
51
- "node-opcua-service-read": "2.71.0",
52
- "node-opcua-service-register-node": "2.71.0",
53
- "node-opcua-service-secure-channel": "2.71.0",
54
- "node-opcua-service-session": "2.71.0",
55
- "node-opcua-service-subscription": "2.71.0",
56
- "node-opcua-service-translate-browse-path": "2.71.0",
57
- "node-opcua-service-write": "2.71.0",
41
+ "node-opcua-pseudo-session": "2.72.2",
42
+ "node-opcua-schemas": "2.72.2",
43
+ "node-opcua-secure-channel": "2.72.2",
44
+ "node-opcua-service-browse": "2.72.2",
45
+ "node-opcua-service-call": "2.72.2",
46
+ "node-opcua-service-discovery": "2.72.2",
47
+ "node-opcua-service-endpoints": "2.72.2",
48
+ "node-opcua-service-filter": "2.72.2",
49
+ "node-opcua-service-history": "2.72.2",
50
+ "node-opcua-service-query": "2.72.2",
51
+ "node-opcua-service-read": "2.72.2",
52
+ "node-opcua-service-register-node": "2.72.2",
53
+ "node-opcua-service-secure-channel": "2.72.2",
54
+ "node-opcua-service-session": "2.72.2",
55
+ "node-opcua-service-subscription": "2.72.2",
56
+ "node-opcua-service-translate-browse-path": "2.72.2",
57
+ "node-opcua-service-write": "2.72.2",
58
58
  "node-opcua-status-code": "2.71.0",
59
- "node-opcua-types": "2.71.0",
59
+ "node-opcua-types": "2.72.2",
60
60
  "node-opcua-utils": "2.71.0",
61
- "node-opcua-variant": "2.71.0",
61
+ "node-opcua-variant": "2.72.2",
62
62
  "once": "^1.4.0",
63
63
  "thenify": "^3.3.1",
64
64
  "underscore": "^1.13.4"
65
65
  },
66
66
  "devDependencies": {
67
67
  "dequeue": "^1.0.5",
68
- "node-opcua-address-space": "2.71.0",
68
+ "node-opcua-address-space": "2.72.2",
69
69
  "node-opcua-binary-stream": "2.71.0",
70
- "node-opcua-factory": "2.71.0",
70
+ "node-opcua-factory": "2.72.1",
71
71
  "node-opcua-leak-detector": "2.71.0",
72
72
  "node-opcua-nodesets": "2.71.0",
73
73
  "should": "^13.2.3",
@@ -93,5 +93,5 @@
93
93
  "internet of things"
94
94
  ],
95
95
  "homepage": "http://node-opcua.github.io/",
96
- "gitHead": "10f7cc1e1cd30dfef75adad9cb709a78401fabf3"
96
+ "gitHead": "07dcdd8e8c7f2b55544c6e23023093e35674829c"
97
97
  }
@@ -3,7 +3,7 @@ import { assert } from "node-opcua-assert";
3
3
  import { NodeId, resolveNodeId } from "node-opcua-nodeid";
4
4
  import { StatusCode, StatusCodes } from "node-opcua-status-code";
5
5
  import { lowerFirstLetter } from "node-opcua-utils";
6
- import { Variant } from "node-opcua-variant";
6
+ import { DataType, Variant } from "node-opcua-variant";
7
7
  import { ClientSession } from "../client_session";
8
8
 
9
9
  export interface TVariant<T> extends Variant {
@@ -28,6 +28,7 @@ export interface ClientAlarm {
28
28
  fields: EventStuff;
29
29
  on(eventName: "changed", eventHandler: () => void): this;
30
30
  acknowledge(session: ClientSession, comment: string): Promise<StatusCode>;
31
+ getField(fieldName: string): Variant | null;
31
32
  }
32
33
 
33
34
  /**
@@ -62,6 +63,25 @@ export class ClientAlarm extends EventEmitter {
62
63
  public getRetain(): boolean {
63
64
  return this.fields.retain.value;
64
65
  }
66
+ public toString(): string {
67
+ return (
68
+ this.constructor.name +
69
+ ": " +
70
+ this.conditionId.toString() +
71
+ " " +
72
+ this.eventType.toString() +
73
+ " " +
74
+ Object.entries(this.fields)
75
+ .filter(([key, value]) => value.dataType !== DataType.Null)
76
+ .map(([key, value]) => key.padEnd(30) + "=" + value.toString())
77
+ .join("\n") +
78
+ "\n\n"
79
+ );
80
+ }
81
+
82
+ public getField(fieldName: string): Variant | null {
83
+ return (this.fields as any)[fieldName] || null;
84
+ }
65
85
  }
66
86
 
67
87
  // ------------------------------------------------------------------------------------------------------------------------------
@@ -5,8 +5,12 @@ import { ClientAlarm, EventStuff } from "./client_alarm";
5
5
 
6
6
  export interface ClientAlarmList {
7
7
  on(eventName: "alarmChanged", handler: (alarm: ClientAlarm) => void): this;
8
- // tslint:disable-next-line: unified-signatures
8
+ on(eventName: "alarmDeleted", handler: (alarm: ClientAlarm) => void): this;
9
9
  on(eventName: "newAlarm", handler: (alarm: ClientAlarm) => void): this;
10
+
11
+ emit(eventName: "alarmChanged", alarm: ClientAlarm): boolean;
12
+ emit(eventName: "newAlarm", alarm: ClientAlarm): boolean;
13
+ emit(eventName: "alarmDeleted", alarm: ClientAlarm): boolean;
10
14
  }
11
15
  // maintain a set of alarm list for a client
12
16
  export class ClientAlarmList extends EventEmitter implements Iterable<ClientAlarm> {
@@ -55,7 +59,7 @@ export class ClientAlarmList extends EventEmitter implements Iterable<ClientAlar
55
59
  const newAlarm = new ClientAlarm(eventField);
56
60
  this._map[key] = newAlarm;
57
61
  this.emit("newAlarm", newAlarm);
58
- this.emit("alarmChanged", alarm);
62
+ this.emit("alarmChanged", newAlarm);
59
63
  } else {
60
64
  alarm.update(eventField);
61
65
  this.emit("alarmChanged", alarm);
@@ -7,14 +7,15 @@ import { Variant } from "node-opcua-variant";
7
7
  import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
8
8
 
9
9
  import { ClientMonitoredItem } from "../client_monitored_item";
10
+ import { ClientSubscription } from "../client_subscription";
10
11
  import { ClientSession } from "../client_session";
11
12
  import { EventStuff, fieldsToJson } from "./client_alarm";
12
13
  import { ClientAlarmList } from "./client_alarm_list";
13
14
  import { extractConditionFields } from "./client_alarm_tools_extractConditionFields";
14
15
  import { callConditionRefresh } from "./client_tools";
15
16
 
16
- const doDebug = checkDebugFlag(__filename);
17
- const debugLog = make_debugLog(__filename);
17
+ const doDebug = checkDebugFlag("A&E");
18
+ const debugLog = make_debugLog("A&E");
18
19
 
19
20
  function r(_key: string, o: { dataType?: unknown; value?: unknown }) {
20
21
  if (o && o.dataType === "Null") {
@@ -22,10 +23,14 @@ function r(_key: string, o: { dataType?: unknown; value?: unknown }) {
22
23
  }
23
24
  return o;
24
25
  }
25
-
26
+ interface ClientSessionPriv extends ClientSession {
27
+ $clientAlarmList: ClientAlarmList | null;
28
+ $monitoredItemForAlarmList: ClientMonitoredItem | null;
29
+ $subscriptionforAlarmList: ClientSubscription | null;
30
+ }
26
31
  // ------------------------------------------------------------------------------------------------------------------------------
27
32
  export async function uninstallAlarmMonitoring(session: ClientSession): Promise<void> {
28
- const _sessionPriv = session as any;
33
+ const _sessionPriv = session as ClientSessionPriv;
29
34
  if (!_sessionPriv.$clientAlarmList) {
30
35
  return;
31
36
  }
@@ -34,7 +39,7 @@ export async function uninstallAlarmMonitoring(session: ClientSession): Promise<
34
39
  mi.removeAllListeners();
35
40
 
36
41
  _sessionPriv.$monitoredItemForAlarmList = null;
37
- await _sessionPriv.$subscriptionforAlarmList.terminate();
42
+ await _sessionPriv.$subscriptionforAlarmList!.terminate();
38
43
  _sessionPriv.$clientAlarmList = null;
39
44
  return;
40
45
  }
@@ -53,7 +58,7 @@ export async function uninstallAlarmMonitoring(session: ClientSession): Promise<
53
58
 
54
59
  // ------------------------------------------------------------------------------------------------------------------------------
55
60
  export async function installAlarmMonitoring(session: ClientSession): Promise<ClientAlarmList> {
56
- const _sessionPriv = session as any;
61
+ const _sessionPriv = session as ClientSessionPriv;
57
62
  // create
58
63
  if (_sessionPriv.$clientAlarmList) {
59
64
  return _sessionPriv.$clientAlarmList;
@@ -89,17 +94,22 @@ export async function installAlarmMonitoring(session: ClientSession): Promise<Cl
89
94
  };
90
95
 
91
96
  // now create a event monitored Item
92
- const event_monitoringItem = ClientMonitoredItem.create(
93
- subscription,
94
- itemToMonitor,
95
- monitoringParameters,
96
- TimestampsToReturn.Both
97
- );
97
+ const eventMonitoringItem = await subscription.monitor(itemToMonitor, monitoringParameters, TimestampsToReturn.Both);
98
98
 
99
99
  const RefreshStartEventType = resolveNodeId("RefreshStartEventType").toString();
100
100
  const RefreshEndEventType = resolveNodeId("RefreshEndEventType").toString();
101
101
 
102
- event_monitoringItem.on("changed", (eventFields: Variant[]) => {
102
+ const queueEvent: EventStuff[] = [];
103
+ function flushQueue() {
104
+ const q = [...queueEvent];
105
+ queueEvent.length = 0;
106
+ for (const pojo of q) {
107
+ clientAlarmList.update(pojo);
108
+ }
109
+ }
110
+
111
+ let inInit = true;
112
+ eventMonitoringItem.on("changed", (eventFields: Variant[]) => {
103
113
  debugLog("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ---- ALARM RECEIVED");
104
114
  const pojo = fieldsToJson(fields, eventFields) as EventStuff;
105
115
  try {
@@ -113,7 +123,10 @@ export async function installAlarmMonitoring(session: ClientSession): Promise<Cl
113
123
  // not a acknowledgeable condition
114
124
  return;
115
125
  }
116
- clientAlarmList.update(pojo);
126
+ queueEvent.push(pojo);
127
+ if (queueEvent.length === 1 && !inInit) {
128
+ setTimeout(() => flushQueue(), 10);
129
+ }
117
130
  } catch (err) {
118
131
  // tslint:disable-next-line: no-console
119
132
  console.log(JSON.stringify(pojo, r, " "));
@@ -139,7 +152,11 @@ export async function installAlarmMonitoring(session: ClientSession): Promise<Cl
139
152
  } catch (err) {
140
153
  console.log("Server may not implement condition refresh", (<Error>err).message);
141
154
  }
142
- _sessionPriv.$monitoredItemForAlarmList = event_monitoringItem;
155
+ _sessionPriv.$monitoredItemForAlarmList = eventMonitoringItem;
156
+
157
+ setTimeout(() => flushQueue(), 10);
158
+ inInit = false;
159
+
143
160
  // also request updates
144
161
  return clientAlarmList;
145
162
  }
@@ -20,9 +20,9 @@ import { ClientSubscription } from "../client_subscription";
20
20
  import { ClientSessionImpl } from "../private/client_session_impl";
21
21
  import { ClientSubscriptionImpl } from "../private/client_subscription_impl";
22
22
 
23
- const debugLog = make_debugLog(__filename);
24
- const doDebug = checkDebugFlag(__filename);
25
- const warningLog = make_warningLog(__filename);
23
+ const debugLog = make_debugLog("A&E");
24
+ const doDebug = checkDebugFlag("A&E");
25
+ const warningLog = make_warningLog("A&E");
26
26
 
27
27
 
28
28
  export async function callConditionRefresh(subscription: ClientSubscription): Promise<void>;
@@ -68,7 +68,7 @@ export function callConditionRefresh(subscription: ClientSubscription, callback?
68
68
  objectId: conditionTypeNodeId
69
69
  };
70
70
 
71
- doDebug && debugLog("Calling method ", methodToCall.toString());
71
+ doDebug && debugLog("Calling method ", new CallMethodRequest(methodToCall).toString());
72
72
  theSession.call(methodToCall, (err: Error | null, result?: CallMethodResult) => {
73
73
  if (err) {
74
74
  return innerCallback(err);
@@ -140,7 +140,7 @@ export interface OPCUAClientBaseOptions {
140
140
  /**
141
141
  * @advanced
142
142
  */
143
- transportSettings?: TransportSettings
143
+ transportSettings?: TransportSettings;
144
144
  }
145
145
 
146
146
  export interface GetEndpointsOptions {
@@ -164,10 +164,13 @@ export interface OPCUAClientBase extends OPCUASecureObject {
164
164
  connect(endpointUrl: string, callback: ErrorCallback): void;
165
165
 
166
166
  /***
167
- * causes client to close and disconnect the communication with server
167
+ * causes the client to close and disconnect the communication with server
168
+ *
169
+ * ### note
170
+ * > once the client has disconnected, it cannot reconnect to the server
171
+ * you'll need to recreate a new Client object to reconnect to the server.
168
172
  */
169
173
  disconnect(): Promise<void>;
170
-
171
174
  disconnect(callback: ErrorCallback): void;
172
175
 
173
176
  findEndpointForSecurity(securityMode: MessageSecurityMode, securityPolicy: SecurityPolicy): EndpointDescription | undefined;
@@ -107,11 +107,9 @@ export interface OPCUAClientOptions extends OPCUAClientBaseOptions {
107
107
 
108
108
  export interface OPCUAClient extends OPCUAClientBase {
109
109
  connect(endpointUrl: string): Promise<void>;
110
-
111
110
  connect(endpointUrl: string, callback: ErrorCallback): void;
112
111
 
113
112
  disconnect(): Promise<void>;
114
-
115
113
  disconnect(callback: ErrorCallback): void;
116
114
 
117
115
  getEndpoints(options?: GetEndpointsOptions): Promise<EndpointDescription[]>;