node-opcua-server 2.85.0 → 2.86.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -108,7 +108,7 @@ function _validate_parameters(monitoringParameters: any) {
108
108
  function statusCodeHasChanged(newDataValue: DataValue, oldDataValue: DataValue): boolean {
109
109
  assert(newDataValue instanceof DataValue);
110
110
  assert(oldDataValue instanceof DataValue);
111
- return newDataValue.statusCode !== oldDataValue.statusCode;
111
+ return newDataValue.statusCode.value !== oldDataValue.statusCode.value;
112
112
  }
113
113
 
114
114
  function valueHasChanged(
@@ -145,7 +145,6 @@ function valueHasChanged(
145
145
  // DataChange if (absolute value of (last cached value - current value) >
146
146
  // (deadbandValue/100.0) * ((high-low) of EURange)))
147
147
  //
148
- // Specifying a deadbandValue outside of this range will be rejected and reported with the
149
148
  // StatusCode BadDeadbandFilterInvalid (see Table 27).
150
149
  // If the Value of the MonitoredItem is an array, then the deadband calculation logic shall be applied to
151
150
  // each element of the array. If an element that requires a DataChange is found, then no further
@@ -180,10 +179,6 @@ function timestampHasChanged(t1: DateTime, t2: DateTime): boolean {
180
179
  return (t1 as Date).getTime() !== (t2 as Date).getTime();
181
180
  }
182
181
 
183
- function isGoodish(statusCode: StatusCode): boolean {
184
- return statusCode.value < 0x10000000;
185
- }
186
-
187
182
  function apply_dataChange_filter(this: MonitoredItem, newDataValue: DataValue, oldDataValue: DataValue): boolean {
188
183
  /* istanbul ignore next */
189
184
  if (!this.filter || !(this.filter instanceof DataChangeFilter)) {
@@ -993,7 +988,7 @@ export class MonitoredItem extends EventEmitter {
993
988
  return callback(new Error("Invalid "));
994
989
  }
995
990
  const variable = (this.node as UAVariable);
996
- if (!this.oldDataValue || this.oldDataValue.statusCode == StatusCodes.BadDataUnavailable) {
991
+ if (!this.oldDataValue || this.oldDataValue.statusCode.value == StatusCodes.BadDataUnavailable.value) {
997
992
  variable.readValueAsync(sessionContext, (err: Error | null, dataValue?: DataValue) => {
998
993
  callback(err, dataValue);
999
994
  });
@@ -1198,7 +1193,7 @@ export class MonitoredItem extends EventEmitter {
1198
1193
 
1199
1194
  assert(dataValue instanceof DataValue);
1200
1195
  // lets verify that, if status code is good then we have a valid Variant in the dataValue
1201
- assert(!isGoodish(dataValue.statusCode) || dataValue.value instanceof Variant);
1196
+ assert(!dataValue.statusCode.isGoodish() || dataValue.value instanceof Variant);
1202
1197
  // xx assert(isGoodish(dataValue.statusCode) || util.isNullOrUndefined(dataValue.value) );
1203
1198
  // let's check that data Value is really a different object
1204
1199
  // we may end up with corrupted queue if dataValue are recycled and stored as is in notifications
@@ -1580,16 +1580,17 @@ export class OPCUAServer extends OPCUABaseServer {
1580
1580
  }
1581
1581
  }
1582
1582
  if (
1583
- StatusCodes.BadCertificateUntrusted === certificateStatus ||
1584
- StatusCodes.BadCertificateTimeInvalid === certificateStatus ||
1585
- StatusCodes.BadCertificateIssuerTimeInvalid === certificateStatus ||
1586
- StatusCodes.BadCertificateIssuerUseNotAllowed === certificateStatus ||
1587
- StatusCodes.BadCertificateIssuerRevocationUnknown === certificateStatus ||
1588
- StatusCodes.BadCertificateRevocationUnknown === certificateStatus ||
1589
- StatusCodes.BadCertificateRevoked === certificateStatus ||
1590
- StatusCodes.BadCertificateUseNotAllowed === certificateStatus ||
1591
- StatusCodes.BadSecurityChecksFailed === certificateStatus ||
1592
- StatusCodes.Good !== certificateStatus
1583
+ certificateStatus &&
1584
+ (StatusCodes.BadCertificateUntrusted.equals(certificateStatus) ||
1585
+ StatusCodes.BadCertificateTimeInvalid.equals(certificateStatus) ||
1586
+ StatusCodes.BadCertificateIssuerTimeInvalid.equals(certificateStatus) ||
1587
+ StatusCodes.BadCertificateIssuerUseNotAllowed.equals(certificateStatus) ||
1588
+ StatusCodes.BadCertificateIssuerRevocationUnknown.equals(certificateStatus) ||
1589
+ StatusCodes.BadCertificateRevocationUnknown.equals(certificateStatus) ||
1590
+ StatusCodes.BadCertificateRevoked.equals(certificateStatus) ||
1591
+ StatusCodes.BadCertificateUseNotAllowed.equals(certificateStatus) ||
1592
+ StatusCodes.BadSecurityChecksFailed.equals(certificateStatus) ||
1593
+ !StatusCodes.Good.equals(certificateStatus))
1593
1594
  ) {
1594
1595
  debugLog("isValidX509IdentityToken => certificateStatus = ", certificateStatus?.toString());
1595
1596
 
@@ -2032,7 +2033,7 @@ export class OPCUAServer extends OPCUABaseServer {
2032
2033
  const session = this.getSession(authenticationToken);
2033
2034
 
2034
2035
  function rejectConnection(server: OPCUAServer, statusCode: StatusCode): void {
2035
- if (statusCode === StatusCodes.BadSessionIdInvalid) {
2036
+ if (statusCode.equals(StatusCodes.BadSessionIdInvalid)) {
2036
2037
  server.engine.incrementRejectedSessionCount();
2037
2038
  } else {
2038
2039
  server.engine.incrementRejectedSessionCount();
@@ -2128,7 +2129,7 @@ export class OPCUAServer extends OPCUABaseServer {
2128
2129
  request.userTokenSignature,
2129
2130
  session.endpoint!,
2130
2131
  (err: Error | null, statusCode?: StatusCode) => {
2131
- if (statusCode !== StatusCodes.Good) {
2132
+ if (!statusCode || statusCode.isNotGood()) {
2132
2133
  /* istanbul ignore next */
2133
2134
  if (!(statusCode && statusCode instanceof StatusCode)) {
2134
2135
  return rejectConnection(this, StatusCodes.BadCertificateInvalid);
@@ -2286,7 +2287,7 @@ export class OPCUAServer extends OPCUABaseServer {
2286
2287
  return sendResponse(response);
2287
2288
  }
2288
2289
 
2289
- assert(message.session_statusCode === StatusCodes.Good);
2290
+ assert(message.session_statusCode.isGood());
2290
2291
 
2291
2292
  // OPC UA Specification 1.02 part 4 page 26
2292
2293
  // When a Session is terminated, all outstanding requests on the Session are aborted and
@@ -3173,7 +3174,7 @@ export class OPCUAServer extends OPCUABaseServer {
3173
3174
  linksToAdd,
3174
3175
  linksToRemove
3175
3176
  );
3176
- if (statusCode !== StatusCodes.Good) {
3177
+ if (statusCode.isNotGood()) {
3177
3178
  const response = new ServiceFault({ responseHeader: { serviceResult: statusCode } });
3178
3179
  sendResponse(response);
3179
3180
  } else {
@@ -10,7 +10,7 @@ import * as async from "async";
10
10
 
11
11
  import { assert } from "node-opcua-assert";
12
12
  import { ICertificateManager, OPCUACertificateManager } from "node-opcua-certificate-manager";
13
- import { Certificate, convertPEMtoDER, makeSHA1Thumbprint, PrivateKeyPEM, split_der } from "node-opcua-crypto";
13
+ import { Certificate, convertPEMtoDER, makeSHA1Thumbprint, PrivateKey, PrivateKeyPEM, split_der } from "node-opcua-crypto";
14
14
  import { checkDebugFlag, make_debugLog, make_errorLog, make_warningLog } from "node-opcua-debug";
15
15
  import { getFullyQualifiedDomainName, resolveFullyQualifiedDomainName } from "node-opcua-hostname";
16
16
  import {
@@ -112,7 +112,7 @@ function dumpChannelInfo(channels: ServerSecureChannelLayer[]): void {
112
112
  }
113
113
 
114
114
  const emptyCertificate = Buffer.alloc(0);
115
- const emptyPrivateKeyPEM = "";
115
+ const emptyPrivateKey = null as any as PrivateKey;
116
116
 
117
117
  let OPCUAServerEndPointCounter = 0;
118
118
 
@@ -129,7 +129,7 @@ export interface OPCUAServerEndPointOptions {
129
129
  /**
130
130
  * privateKey
131
131
  */
132
- privateKey: PrivateKeyPEM;
132
+ privateKey: PrivateKey;
133
133
 
134
134
  certificateManager: OPCUACertificateManager;
135
135
 
@@ -169,7 +169,7 @@ export interface AddStandardEndpointDescriptionsParam {
169
169
  allowAnonymous?: boolean;
170
170
  disableDiscovery?: boolean;
171
171
  securityModes?: MessageSecurityMode[];
172
-
172
+
173
173
  restricted?: boolean;
174
174
  allowUnsecurePassword?: boolean;
175
175
  resourcePath?: string;
@@ -225,7 +225,7 @@ export class OPCUAServerEndPoint extends EventEmitter implements ServerSecureCha
225
225
  public _on_openSecureChannelFailure?: (socketData: any, channelData: any) => void;
226
226
 
227
227
  private _certificateChain: Certificate;
228
- private _privateKey: PrivateKeyPEM;
228
+ private _privateKey: PrivateKey;
229
229
  private _channels: { [key: string]: ServerSecureChannelLayer };
230
230
  private _server?: Server;
231
231
  private _endpoints: EndpointDescription[];
@@ -277,7 +277,7 @@ export class OPCUAServerEndPoint extends EventEmitter implements ServerSecureCha
277
277
 
278
278
  public dispose(): void {
279
279
  this._certificateChain = emptyCertificate;
280
- this._privateKey = emptyPrivateKeyPEM;
280
+ this._privateKey = emptyPrivateKey;
281
281
 
282
282
  assert(Object.keys(this._channels).length === 0, "OPCUAServerEndPoint channels must have been deleted");
283
283
 
@@ -295,7 +295,7 @@ export class OPCUAServerEndPoint extends EventEmitter implements ServerSecureCha
295
295
  }
296
296
 
297
297
  public toString(): string {
298
- const privateKey1 = convertPEMtoDER(this.getPrivateKey());
298
+ const privateKey1 = this.getPrivateKey().export({ format: "der", type: "pkcs1" });
299
299
 
300
300
  const txt =
301
301
  " end point" +
@@ -332,7 +332,7 @@ export class OPCUAServerEndPoint extends EventEmitter implements ServerSecureCha
332
332
  /**
333
333
  * the private key
334
334
  */
335
- public getPrivateKey(): PrivateKeyPEM {
335
+ public getPrivateKey(): PrivateKey {
336
336
  return this._privateKey;
337
337
  }
338
338
 
@@ -439,12 +439,11 @@ export class OPCUAServerEndPoint extends EventEmitter implements ServerSecureCha
439
439
  options.userTokenTypes = options.userTokenTypes || defaultUserTokenTypes;
440
440
 
441
441
  options.allowAnonymous = options.allowAnonymous === undefined ? true : options.allowAnonymous;
442
- // make sure we do not have anonymous
442
+ // make sure we do not have anonymous
443
443
  if (!options.allowAnonymous) {
444
444
  options.userTokenTypes = options.userTokenTypes.filter((r) => r !== UserTokenType.Anonymous);
445
445
  }
446
446
 
447
-
448
447
  const defaultHostname = options.hostname || getFullyQualifiedDomainName();
449
448
 
450
449
  let hostnames: string[] = [defaultHostname];
@@ -961,7 +961,7 @@ export class Subscription extends EventEmitter {
961
961
  );
962
962
 
963
963
  // TODO if attributeId === AttributeIds.Value : sampling interval required here
964
- if (dataValueSamplingInterval.statusCode === StatusCodes.Good) {
964
+ if (dataValueSamplingInterval.statusCode.isGood()) {
965
965
  // node provides a Minimum sampling interval ...
966
966
  samplingInterval = dataValueSamplingInterval.value.value;
967
967
  assert(samplingInterval >= 0 && samplingInterval <= MonitoredItem.maximumSamplingInterval);
@@ -1056,7 +1056,7 @@ export class Subscription extends EventEmitter {
1056
1056
 
1057
1057
  const createResult = this._createMonitoredItemStep2(timestampsToReturn, monitoredItemCreateRequest, node);
1058
1058
 
1059
- assert(createResult.statusCode === StatusCodes.Good);
1059
+ assert(createResult.statusCode.isGood());
1060
1060
 
1061
1061
  const monitoredItem = this.getMonitoredItem(createResult.monitoredItemId);
1062
1062
  // istanbul ignore next
@@ -57,7 +57,7 @@ function __validateDataChangeFilter(filter: DataChangeFilter, itemToMonitor: Rea
57
57
  }
58
58
 
59
59
  // node must also have a valid euRange
60
- if (!(node as any).euRange) {
60
+ if (!node.getChildByName("EURange", 0)) {
61
61
  // tslint:disable:no-console
62
62
  console.log(" node has no euRange ! Dead band Percent cannot be used on node " + node.nodeId.toString());
63
63
  return StatusCodes.BadMonitoredItemFilterUnsupported;