node-opcua-client 2.188.1 → 2.190.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.
Files changed (67) hide show
  1. package/dist/alarms_and_conditions/client_alarm_tools.d.ts.map +1 -1
  2. package/dist/alarms_and_conditions/client_alarm_tools.js +2 -1
  3. package/dist/alarms_and_conditions/client_alarm_tools.js.map +1 -1
  4. package/dist/client_monitored_item_toolbox.d.ts.map +1 -1
  5. package/dist/client_monitored_item_toolbox.js +8 -4
  6. package/dist/client_monitored_item_toolbox.js.map +1 -1
  7. package/dist/client_session_keepalive_manager.d.ts.map +1 -1
  8. package/dist/client_session_keepalive_manager.js +18 -12
  9. package/dist/client_session_keepalive_manager.js.map +1 -1
  10. package/dist/private/client_base_impl.d.ts +10 -1
  11. package/dist/private/client_base_impl.d.ts.map +1 -1
  12. package/dist/private/client_base_impl.js +188 -77
  13. package/dist/private/client_base_impl.js.map +1 -1
  14. package/dist/private/client_monitored_item_impl.d.ts.map +1 -1
  15. package/dist/private/client_monitored_item_impl.js +2 -1
  16. package/dist/private/client_monitored_item_impl.js.map +1 -1
  17. package/dist/private/client_publish_engine.d.ts.map +1 -1
  18. package/dist/private/client_publish_engine.js +16 -8
  19. package/dist/private/client_publish_engine.js.map +1 -1
  20. package/dist/private/client_session_impl.d.ts +21 -0
  21. package/dist/private/client_session_impl.d.ts.map +1 -1
  22. package/dist/private/client_session_impl.js +122 -57
  23. package/dist/private/client_session_impl.js.map +1 -1
  24. package/dist/private/client_subscription_impl.d.ts.map +1 -1
  25. package/dist/private/client_subscription_impl.js +27 -17
  26. package/dist/private/client_subscription_impl.js.map +1 -1
  27. package/dist/private/opcua_client_impl.d.ts.map +1 -1
  28. package/dist/private/opcua_client_impl.js +307 -29
  29. package/dist/private/opcua_client_impl.js.map +1 -1
  30. package/dist/private/reconnection/client_publish_engine_reconnection.d.ts.map +1 -1
  31. package/dist/private/reconnection/client_publish_engine_reconnection.js +6 -3
  32. package/dist/private/reconnection/client_publish_engine_reconnection.js.map +1 -1
  33. package/dist/private/reconnection/client_subscription_reconnection.d.ts.map +1 -1
  34. package/dist/private/reconnection/client_subscription_reconnection.js +6 -3
  35. package/dist/private/reconnection/client_subscription_reconnection.js.map +1 -1
  36. package/dist/private/reconnection/reconnection.d.ts.map +1 -1
  37. package/dist/private/reconnection/reconnection.js +6 -4
  38. package/dist/private/reconnection/reconnection.js.map +1 -1
  39. package/dist/private/verify_server_signature.d.ts +51 -0
  40. package/dist/private/verify_server_signature.d.ts.map +1 -0
  41. package/dist/private/verify_server_signature.js +76 -0
  42. package/dist/private/verify_server_signature.js.map +1 -0
  43. package/dist/reverse/client_reverse_connect.js +2 -2
  44. package/dist/reverse/client_reverse_connect.js.map +1 -1
  45. package/dist/tools/read_history_server_capabilities.js +6 -3
  46. package/dist/tools/read_history_server_capabilities.js.map +1 -1
  47. package/dist/verify.d.ts +6 -0
  48. package/dist/verify.d.ts.map +1 -1
  49. package/dist/verify.js +32 -10
  50. package/dist/verify.js.map +1 -1
  51. package/package.json +47 -47
  52. package/source/alarms_and_conditions/client_alarm_tools.ts +2 -1
  53. package/source/client_monitored_item_toolbox.ts +8 -4
  54. package/source/client_session_keepalive_manager.ts +18 -12
  55. package/source/private/client_base_impl.ts +206 -78
  56. package/source/private/client_monitored_item_impl.ts +2 -1
  57. package/source/private/client_publish_engine.ts +16 -8
  58. package/source/private/client_session_impl.ts +122 -57
  59. package/source/private/client_subscription_impl.ts +27 -17
  60. package/source/private/opcua_client_impl.ts +383 -29
  61. package/source/private/reconnection/client_publish_engine_reconnection.ts +6 -3
  62. package/source/private/reconnection/client_subscription_reconnection.ts +6 -3
  63. package/source/private/reconnection/reconnection.ts +6 -4
  64. package/source/private/verify_server_signature.ts +109 -0
  65. package/source/reverse/client_reverse_connect.ts +2 -2
  66. package/source/tools/read_history_server_capabilities.ts +6 -3
  67. package/source/verify.ts +34 -12
@@ -10,30 +10,36 @@ import chalk from "chalk";
10
10
  import { assert } from "node-opcua-assert";
11
11
  import { getDefaultCertificateManager, type OPCUACertificateManager } from "node-opcua-certificate-manager";
12
12
  import {
13
+ getEcKeyOperationsFromProvider,
13
14
  type ICertificateStore,
14
15
  InMemoryCertificateStore,
15
16
  type IOPCUASecureObjectOptions,
16
17
  makeApplicationUrn,
17
18
  makeSubject,
18
19
  OPCUASecureObject,
19
- resolvePrivateKeyProviderIfNeeded
20
+ OpaqueCertificateKeyPairProvider,
21
+ resolvePrivateKeyProviderIfNeeded,
22
+ selfSignedCertificateStartDate
20
23
  } from "node-opcua-common";
21
24
  import { PrivateKeyPassphraseRequiredError } from "node-opcua-crypto";
22
- import { type Certificate, exploreCertificate, makeSHA1Thumbprint, split_der } from "node-opcua-crypto/web";
25
+ import { type Certificate, exploreCertificate, type IKeyOperations, makeSHA1Thumbprint, split_der } from "node-opcua-crypto/web";
23
26
  import { installPeriodicClockAdjustment, periodicClockAdjustment, uninstallPeriodicClockAdjustment } from "node-opcua-date-time";
24
27
  import { checkDebugFlag, make_debugLog, make_errorLog, make_warningLog } from "node-opcua-debug";
25
28
  import { getHostname } from "node-opcua-hostname";
26
29
  import type { IBasicTransportSettings, ResponseCallback } from "node-opcua-pseudo-session";
27
30
  import {
31
+ type ApplicationIdentity,
28
32
  ClientSecureChannelLayer,
29
33
  type ConnectionStrategy,
30
34
  type ConnectionStrategyOptions,
31
35
  coerceConnectionStrategy,
32
36
  coerceSecurityPolicy,
37
+ getAsymmetricKeyType,
38
+ getCryptoFactory,
33
39
  type PerformTransactionCallback,
34
40
  type Request as Request1,
35
41
  type Response as Response1,
36
- type SecurityPolicy,
42
+ SecurityPolicy,
37
43
  type ServiceFaultAnnotatedError
38
44
  } from "node-opcua-secure-channel";
39
45
  import {
@@ -164,7 +170,7 @@ function __findEndpoint(this: ClientBaseImpl, endpointUrl: string, params: FindE
164
170
  client.on("backoff", handler as unknown as (retryCount: number, delay: number) => void);
165
171
  });
166
172
 
167
- /* c8 ignore next */
173
+ /* c8 ignore start */
168
174
  if (doDebug) {
169
175
  client.on("backoff", (retryCount: number, delay: number) => {
170
176
  debugLog(
@@ -177,6 +183,7 @@ function __findEndpoint(this: ClientBaseImpl, endpointUrl: string, params: FindE
177
183
  );
178
184
  });
179
185
  }
186
+ /* c8 ignore stop */
180
187
 
181
188
  client.connect(endpointUrl, (err?: Error) => {
182
189
  if (err) {
@@ -202,10 +209,11 @@ function __findEndpoint(this: ClientBaseImpl, endpointUrl: string, params: FindE
202
209
  err.message = `error in getEndpoints \n${err.message}`;
203
210
  return reject(err);
204
211
  }
205
- // c8 ignore next
212
+ /* c8 ignore start */
206
213
  if (!endpoints) {
207
214
  return reject(new Error("Internal Error"));
208
215
  }
216
+ /* c8 ignore stop */
209
217
 
210
218
  for (const endpoint of endpoints) {
211
219
  if (endpoint.securityMode === securityMode && endpoint.securityPolicyUri === securityPolicy) {
@@ -246,10 +254,11 @@ function __findEndpoint(this: ClientBaseImpl, endpointUrl: string, params: FindE
246
254
  );
247
255
  }
248
256
 
249
- // c8 ignore next
257
+ /* c8 ignore start */
250
258
  if (doDebug) {
251
259
  debugLog(chalk.bgWhite.red("xxxxxxxxxxxxxxxxxxxxx => selected EndPoint = "), selectedEndpoint.toString());
252
260
  }
261
+ /* c8 ignore stop */
253
262
 
254
263
  callback(null, { endpoints: allEndpoints, selectedEndpoint });
255
264
  })
@@ -266,12 +275,13 @@ function __findEndpoint(this: ClientBaseImpl, endpointUrl: string, params: FindE
266
275
  async function _verify_serverCertificate(certificateManager: ICertificateStore, serverCertificate: Certificate) {
267
276
  const status = await certificateManager.checkCertificate(serverCertificate);
268
277
  if (!status.isGood()) {
269
- // c8 ignore next
278
+ /* c8 ignore start */
270
279
  if (doDebug) {
271
280
  // do it again for debug purposes
272
281
  const status1 = await certificateManager.verifyCertificate(serverCertificate);
273
282
  debugLog(status1);
274
283
  }
284
+ /* c8 ignore stop */
275
285
  warningLog("serverCertificate = ", makeCertificateThumbPrint(serverCertificate)?.toString("hex") || "none");
276
286
  warningLog("serverCertificate = ", serverCertificate.toString("base64"));
277
287
  throw new Error(`server Certificate verification failed with err ${status?.toString()}`);
@@ -279,18 +289,18 @@ async function _verify_serverCertificate(certificateManager: ICertificateStore,
279
289
  }
280
290
 
281
291
  const forceEndpointDiscoveryOnConnect = !!parseInt(process.env.NODEOPCUA_CLIENT_FORCE_ENDPOINT_DISCOVERY || "0", 10);
282
- // c8 ignore next
292
+ /* c8 ignore next */
283
293
  doDebug && debugLog("forceEndpointDiscoveryOnConnect = ", forceEndpointDiscoveryOnConnect);
284
294
 
285
295
  class ClockAdjustment {
286
296
  constructor() {
287
- // c8 ignore next
297
+ /* c8 ignore next */
288
298
  doDebug && debugLog("installPeriodicClockAdjustment ", periodicClockAdjustment.timerInstallationCount);
289
299
  installPeriodicClockAdjustment();
290
300
  }
291
301
  dispose() {
292
302
  uninstallPeriodicClockAdjustment();
293
- // c8 ignore next
303
+ /* c8 ignore next */
294
304
  doDebug && debugLog("uninstallPeriodicClockAdjustment ", periodicClockAdjustment.timerInstallationCount);
295
305
  }
296
306
  }
@@ -439,6 +449,16 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
439
449
  /** true when the caller supplied a certificateKeyPairProvider — the private-key resolution escape hatch. */
440
450
  #hasUserProvidedProvider = false;
441
451
 
452
+ /**
453
+ * The certificate chain and the key of this client for a security policy. It is there only
454
+ * when the client has a second certificate, for the family of key that its first certificate
455
+ * does not have: the SecureChannel then asks for the certificate of its policy. A client
456
+ * with one certificate has no such method, and nothing changes for it.
457
+ * Part of an Experimental feature: see `eccSecurityPolicies`.
458
+ * @internal
459
+ */
460
+ public getApplicationIdentity?: (securityPolicy: SecurityPolicy) => ApplicationIdentity | null;
461
+
442
462
  public isUnusable() {
443
463
  return (
444
464
  this._internalState === "disconnected" ||
@@ -473,13 +493,14 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
473
493
  // "node:events" declaration and not exported.
474
494
  // biome-ignore lint/suspicious/noExplicitAny: must match EventEmitter#emit's rest parameter
475
495
  public emit<K>(eventName: K, ...others: any[]): boolean {
476
- // c8 ignore next
496
+ /* c8 ignore start */
477
497
  if (doDebug) {
478
498
  debugLog(
479
499
  chalk.cyan(` Client ${this._instanceNumber} ${this.clientName} emitting `),
480
500
  chalk.magentaBright(eventName as string)
481
501
  );
482
502
  }
503
+ /* c8 ignore stop */
483
504
  // @ts-expect-error
484
505
  return super.emit(eventName, ...others);
485
506
  }
@@ -591,23 +612,25 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
591
612
  // _cancel_reconnection is invoked during disconnection
592
613
  // when we detect that a reconnection is in progress...
593
614
 
594
- // c8 ignore next
615
+ /* c8 ignore start */
595
616
  if (!this.isReconnecting) {
596
617
  warningLog("internal error: _cancel_reconnection should only be used when reconnecting is in progress");
597
618
  }
619
+ /* c8 ignore stop */
598
620
 
599
- // c8 ignore next
621
+ /* c8 ignore next */
600
622
  doDebug && debugLog("canceling reconnection : ", this.clientName);
601
623
 
602
624
  this._reconnectionIsCanceled = true;
603
625
 
604
- // c8 ignore next
626
+ /* c8 ignore start */
605
627
  if (!this._secureChannel) {
606
- // c8 ignore next
628
+ /* c8 ignore next */
607
629
  doDebug &&
608
630
  debugLog("_cancel_reconnection: Nothing to do for !", this.clientName, " because secure channel doesn't exist");
609
631
  return callback(); // nothing to do
610
632
  }
633
+ /* c8 ignore stop */
611
634
 
612
635
  this._secureChannel.abortConnection((/*err?: Error*/) => {
613
636
  this._secureChannel = null;
@@ -616,11 +639,11 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
616
639
  }
617
640
 
618
641
  public _recreate_secure_channel(callback: ErrorCallback): void {
619
- // c8 ignore next
642
+ /* c8 ignore next */
620
643
  doDebug && debugLog("_recreate_secure_channel... while internalState is", this._internalState);
621
644
 
622
645
  if (!this.knowsServerEndpoint) {
623
- // c8 ignore next
646
+ /* c8 ignore next */
624
647
  doDebug && debugLog("Cannot reconnect , server endpoint is unknown");
625
648
  callback(new Error("Cannot reconnect, server endpoint is unknown - this.knowsServerEndpoint = false"));
626
649
  return;
@@ -648,7 +671,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
648
671
  };
649
672
 
650
673
  const _failAndRetry = (err: Error, message: string, callback: ErrorCallback) => {
651
- // c8 ignore next
674
+ /* c8 ignore next */
652
675
  doDebug && debugLog("failAndRetry; ", message);
653
676
  if (this._reconnectionIsCanceled) {
654
677
  return _when_reconnectionIsCanceled(callback);
@@ -665,14 +688,14 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
665
688
  this.emit("after_reconnection", null); // send after callback
666
689
  assert(this._secureChannel, "expecting a secureChannel here ");
667
690
  // a new channel has be created and a new connection is established
668
- // c8 ignore next
691
+ /* c8 ignore next */
669
692
  doDebug && debugLog(chalk.bgWhite.red("ClientBaseImpl: RECONNECTED !!!"));
670
693
  this._setInternalState("reconnecting_newchannel_connected");
671
694
  return callback();
672
695
  };
673
696
 
674
697
  const _attempt_to_recreate_secure_channel = (callback: ErrorCallback) => {
675
- // c8 ignore next
698
+ /* c8 ignore next */
676
699
  doDebug && debugLog("attempt to recreate a new secure channel");
677
700
  if (this._reconnectionIsCanceled) {
678
701
  return _when_reconnectionIsCanceled(callback);
@@ -687,11 +710,12 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
687
710
 
688
711
  this._internal_create_secure_channel(infiniteConnectionRetry, (err?: Error | null) => {
689
712
  if (err) {
690
- // c8 ignore next
713
+ /* c8 ignore start */
691
714
  if (this._secureChannel) {
692
715
  const err = new Error("_internal_create_secure_channel failed, expecting this._secureChannel not to exist");
693
716
  return _when_internal_error(err, callback);
694
717
  }
718
+ /* c8 ignore stop */
695
719
 
696
720
  if (err.message.match(/ECONNREFUSED|ECONNABORTED|ETIMEDOUT/)) {
697
721
  return _failAndRetry(
@@ -778,13 +802,14 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
778
802
  assert(this._secureChannel === null);
779
803
  assert(typeof this.endpointUrl === "string");
780
804
 
781
- // c8 ignore next
805
+ /* c8 ignore start */
782
806
  doDebug &&
783
807
  debugLog(
784
808
  "_internal_create_secure_channel creating new ClientSecureChannelLayer _internalState =",
785
809
  this._internalState,
786
810
  this.clientName
787
811
  );
812
+ /* c8 ignore stop */
788
813
  const secureChannel = new ClientSecureChannelLayer({
789
814
  connectionStrategy,
790
815
  defaultSecureTokenLifetime: this.defaultSecureTokenLifetime,
@@ -814,14 +839,14 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
814
839
 
815
840
  const step2_openSecureChannel = (): Promise<void> => {
816
841
  return new Promise<void>((resolve, reject) => {
817
- // c8 ignore next
842
+ /* c8 ignore next */
818
843
  doDebug && debugLog("_internal_create_secure_channel before secureChannel.create");
819
844
 
820
845
  secureChannel.create(this.endpointUrl, (err?: Error) => {
821
- // c8 ignore next
846
+ /* c8 ignore next */
822
847
  doDebug && debugLog("_internal_create_secure_channel after secureChannel.create");
823
848
  if (!this._secureChannel) {
824
- // c8 ignore next
849
+ /* c8 ignore next */
825
850
  doDebug && debugLog("_secureChannel has been closed during the transaction !");
826
851
  return reject(new Error("Secure Channel Closed"));
827
852
  }
@@ -842,7 +867,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
842
867
 
843
868
  this.getEndpoints((err: Error | null /*, endpoints?: EndpointDescription[]*/) => {
844
869
  if (!this._secureChannel) {
845
- // c8 ignore next
870
+ /* c8 ignore next */
846
871
  doDebug && debugLog("_secureChannel has been closed during the transaction ! (while getEndpoints)");
847
872
  return reject(new Error("Secure Channel Closed"));
848
873
  }
@@ -896,21 +921,23 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
896
921
  // ip: await getIpAddresses(),
897
922
  outputFile: certificateFile,
898
923
  subject: makeSubject(applicationName, hostname),
899
- startDate: new Date(),
924
+ startDate: selfSignedCertificateStartDate(),
900
925
  validity: 365 * 10 // 10 years
901
926
  });
902
927
  }
903
- // c8 ignore next
928
+ /* c8 ignore start */
904
929
  if (!fs.existsSync(certificateFile)) {
905
930
  throw new Error(` cannot locate certificate file ${certificateFile}`);
906
931
  }
932
+ /* c8 ignore stop */
907
933
  }
908
934
 
909
935
  public async createDefaultCertificate(): Promise<void> {
910
- // c8 ignore next
936
+ /* c8 ignore start */
911
937
  if ((this as unknown as { _inCreateDefaultCertificate: boolean })._inCreateDefaultCertificate) {
912
938
  errorLog("Internal error : re-entrancy in createDefaultCertificate!");
913
939
  }
940
+ /* c8 ignore stop */
914
941
  (this as unknown as { _inCreateDefaultCertificate: boolean })._inCreateDefaultCertificate = true;
915
942
 
916
943
  if (!checkFileExistsAndIsNotEmpty(this.certificateFile)) {
@@ -927,17 +954,18 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
927
954
  this.applicationName,
928
955
  this._getBuiltApplicationUri()
929
956
  );
930
- // c8 ignore next
957
+ /* c8 ignore next */
931
958
  doDebug && debugLog("privateKey = ", this.privateKeyFile);
932
959
  if ("privateKey" in this.clientCertificateManager) {
933
- // c8 ignore next
960
+ /* c8 ignore start */
934
961
  doDebug &&
935
962
  debugLog(
936
963
  " = ",
937
964
  (this.clientCertificateManager as unknown as OPCUACertificateManager).privateKey
938
965
  );
966
+ /* c8 ignore stop */
939
967
  }
940
- // c8 ignore next
968
+ /* c8 ignore next */
941
969
  doDebug && debugLog("certificateFile = ", this.certificateFile);
942
970
  const _certificate = this.getCertificate();
943
971
  // Note: do NOT eagerly call this.getPrivateKey() here. A freshly
@@ -987,10 +1015,11 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
987
1015
  typeof (this.clientCertificateManager as { isPrivateKeyOpaque?: () => boolean }).isPrivateKeyOpaque ===
988
1016
  "function" &&
989
1017
  (this.clientCertificateManager as unknown as { isPrivateKeyOpaque: () => boolean }).isPrivateKeyOpaque();
990
- // c8 ignore next
1018
+ /* c8 ignore start */
991
1019
  if (!hasOpaqueKey && !fs.existsSync(this.privateKeyFile)) {
992
1020
  throw new Error(` cannot locate private key file ${this.privateKeyFile}`);
993
1021
  }
1022
+ /* c8 ignore stop */
994
1023
 
995
1024
  // Resolve the (possibly passphrase-encrypted) private key once,
996
1025
  // asynchronously, and install it as this client's provider — so
@@ -1018,12 +1047,96 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1018
1047
  // withLock2 internally, so an outer withLock2 would cause a deadlock
1019
1048
  // on the same file-based mutex.
1020
1049
  await performCertificateSanityCheck(this, "client", this.clientCertificateManager, this._getBuiltApplicationUri());
1050
+ await this.#prepareCertificateForSecurityPolicy();
1051
+ }
1052
+
1053
+ /**
1054
+ * The security policy of this client needs a certificate with a key of its family. When the
1055
+ * certificate of the client has a key of the other family, the certificate store gets one
1056
+ * more slot (`OPCUACertificateManager.ensureSlot`): a private key, and a self-signed
1057
+ * certificate when the slot has no certificate. The trust list is the same for both.
1058
+ *
1059
+ * Nothing is made for a client that has its key from `certificateKeyPairProvider`, or that
1060
+ * has a certificate store with no slots: the SecureChannel then says which key is missing.
1061
+ */
1062
+ async #prepareCertificateForSecurityPolicy(): Promise<void> {
1063
+ this.getApplicationIdentity = undefined;
1064
+ const cryptoFactory = this.securityPolicy === SecurityPolicy.None ? null : getCryptoFactory(this.securityPolicy);
1065
+ const cm = this.clientCertificateManager as unknown as Partial<OPCUACertificateManager>;
1066
+ if (
1067
+ !cryptoFactory ||
1068
+ this.#hasUserProvidedProvider ||
1069
+ this.certificateFile === "<in-memory>" ||
1070
+ this.certificateFile === "<unknown>" ||
1071
+ typeof cm.ensureSlot !== "function" ||
1072
+ typeof cm.getSlot !== "function"
1073
+ ) {
1074
+ return;
1075
+ }
1076
+ const family = getAsymmetricKeyType(cryptoFactory) === "ec" ? "ec" : "rsa";
1077
+ let ownFamily: "rsa" | "ec" = "rsa";
1078
+ try {
1079
+ ownFamily = getEcKeyOperationsFromProvider(this.getProvider()) ? "ec" : "rsa";
1080
+ } catch (_err) {
1081
+ // a key that cannot be read now is taken as before, as an RSA key
1082
+ }
1083
+ if (family === ownFamily) {
1084
+ return;
1085
+ }
1086
+ const slot =
1087
+ family === "ec"
1088
+ ? await cm.ensureSlot("EccNistP256")
1089
+ : (cm.getSlot("RsaSha256") ?? cm.getSlot("RsaMin") ?? (await cm.ensureSlot("RsaSha256")));
1090
+ if ((await slot.getStatus()) === "empty") {
1091
+ await withLock({ fileToLock: `${slot.certificateFile}.mutex` }, async () => {
1092
+ if ((await slot.getStatus()) !== "empty") {
1093
+ return;
1094
+ }
1095
+ const hostname = getHostname();
1096
+ await slot.createSelfSignedCertificate({
1097
+ applicationUri: this._getBuiltApplicationUri(),
1098
+ dns: [hostname],
1099
+ subject: makeSubject(this.applicationName, hostname),
1100
+ startDate: selfSignedCertificateStartDate(),
1101
+ validity: 365 * 10 // 10 years
1102
+ });
1103
+ warningLog(
1104
+ `[NODE-OPCUA-W42] a self-signed ${slot.certificateType} certificate was made for this client: ${slot.certificateFile}`
1105
+ );
1106
+ });
1107
+ }
1108
+ // the operations of the key and not the key: this is also right for a slot whose key is
1109
+ // not in this process (`keyOperations` of the slot)
1110
+ const keyOperations = slot.getKeyOperations() as unknown as IKeyOperations;
1111
+ const provider = new OpaqueCertificateKeyPairProvider({
1112
+ certificateFile: slot.certificateFile,
1113
+ keyOperations,
1114
+ keyMetadata: await keyOperations.getKeyMetadata()
1115
+ });
1116
+ // the same checks as for the first certificate: the key, the dates, the ApplicationUri
1117
+ await performCertificateSanityCheck(
1118
+ provider as unknown as OPCUASecureObject,
1119
+ "client",
1120
+ this.clientCertificateManager,
1121
+ this._getBuiltApplicationUri()
1122
+ );
1123
+ this.getApplicationIdentity = (securityPolicy: SecurityPolicy): ApplicationIdentity | null => {
1124
+ const factory = securityPolicy === SecurityPolicy.None ? null : getCryptoFactory(securityPolicy);
1125
+ if (factory && (getAsymmetricKeyType(factory) === "ec" ? "ec" : "rsa") === family) {
1126
+ return { certificateChain: provider.getCertificateChain(), keyOperations: provider.getKeyOperations() };
1127
+ }
1128
+ // no security, and the family of the first certificate
1129
+ return {
1130
+ certificateChain: this.getCertificateChain(),
1131
+ keyOperations: getEcKeyOperationsFromProvider(this.getProvider()) ?? this.getKeyOperations()
1132
+ };
1133
+ };
1021
1134
  }
1022
1135
 
1023
1136
  protected _internalState: InternalClientState = "uninitialized";
1024
1137
 
1025
1138
  protected _handleUnrecoverableConnectionFailure(err: Error, callback: ErrorCallback): void {
1026
- // c8 ignore next
1139
+ /* c8 ignore next */
1027
1140
  doDebug && debugLog(err.message);
1028
1141
  // Terminal connect failure: make sure the client is removed from the leak registry. A
1029
1142
  // synchronous throw out of _connectStep2 (e.g. an invalid SecureChannel config) lands here
@@ -1035,7 +1148,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1035
1148
  callback(err);
1036
1149
  }
1037
1150
  private _handleDisconnectionWhileConnecting(err: Error, callback: ErrorCallback) {
1038
- // c8 ignore next
1151
+ /* c8 ignore next */
1039
1152
  doDebug && debugLog(err.message);
1040
1153
  // see _handleUnrecoverableConnectionFailure: idempotent unregister guards against a leaked
1041
1154
  // client when a connect attempt fails before the error-branch unregister runs.
@@ -1045,7 +1158,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1045
1158
  callback(err);
1046
1159
  }
1047
1160
  private _handleSuccessfulConnection(callback: ErrorCallback) {
1048
- // c8 ignore next
1161
+ /* c8 ignore next */
1049
1162
  doDebug && debugLog(" Connected successfully to ", this.endpointUrl);
1050
1163
  this.emit("connected");
1051
1164
  this._setInternalState("connected");
@@ -1068,11 +1181,12 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1068
1181
  }
1069
1182
  assert(typeof endpointUrl === "string" && endpointUrl.length > 0);
1070
1183
 
1071
- // c8 ignore next
1184
+ /* c8 ignore start */
1072
1185
  if (this._internalState !== "disconnected") {
1073
1186
  callback(new Error(`client#connect failed, as invalid internal state = ${this._internalState}`));
1074
1187
  return;
1075
1188
  }
1189
+ /* c8 ignore stop */
1076
1190
 
1077
1191
  // prevent illegal call to connect
1078
1192
  if (this._secureChannel !== null) {
@@ -1085,7 +1199,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1085
1199
 
1086
1200
  this.initializeCM()
1087
1201
  .then(() => {
1088
- // c8 ignore next
1202
+ /* c8 ignore next */
1089
1203
  doDebug && debugLog("ClientBaseImpl#connect ", endpointUrl, this.clientName);
1090
1204
  if (this._internalState === "disconnecting" || this._internalState === "disconnected") {
1091
1205
  return this._handleDisconnectionWhileConnecting(new Error("premature disconnection 1"), callback);
@@ -1095,7 +1209,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1095
1209
  !this.serverCertificate &&
1096
1210
  (forceEndpointDiscoveryOnConnect || this.securityMode !== MessageSecurityMode.None)
1097
1211
  ) {
1098
- // c8 ignore next
1212
+ /* c8 ignore next */
1099
1213
  doDebug && debugLog("Fetching certificates from endpoints");
1100
1214
  this.fetchServerCertificate(endpointUrl, (err: Error | null, adjustedEndpointUrl?: string) => {
1101
1215
  if (err) {
@@ -1105,12 +1219,13 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1105
1219
  return this._handleDisconnectionWhileConnecting(new Error("premature disconnection 2"), callback);
1106
1220
  }
1107
1221
  if (forceEndpointDiscoveryOnConnect) {
1108
- // c8 ignore next
1222
+ /* c8 ignore start */
1109
1223
  doDebug &&
1110
1224
  debugLog("connecting with adjusted endpoint : ", adjustedEndpointUrl, " was =", endpointUrl);
1225
+ /* c8 ignore stop */
1111
1226
  this._connectStep2(adjustedEndpointUrl || "", callback);
1112
1227
  } else {
1113
- // c8 ignore next
1228
+ /* c8 ignore next */
1114
1229
  doDebug && debugLog("connecting with endpoint : ", endpointUrl);
1115
1230
  this._connectStep2(endpointUrl, callback);
1116
1231
  }
@@ -1142,11 +1257,12 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1142
1257
  return;
1143
1258
  }
1144
1259
 
1145
- // c8 ignore next
1260
+ /* c8 ignore start */
1146
1261
  if (this._internalState !== "disconnected") {
1147
1262
  callback(new Error(`client#connectReverse failed, as invalid internal state = ${this._internalState}`));
1148
1263
  return;
1149
1264
  }
1265
+ /* c8 ignore stop */
1150
1266
  if (this._secureChannel !== null) {
1151
1267
  setImmediate(() => callback(new Error("connect already called")));
1152
1268
  return;
@@ -1204,7 +1320,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1204
1320
 
1205
1321
  this.initializeCM()
1206
1322
  .then(() => {
1207
- // c8 ignore next
1323
+ /* c8 ignore next */
1208
1324
  doDebug && debugLog("ClientBaseImpl#connectReverse ", placeholderEndpointUrl, this.clientName);
1209
1325
  if (this._internalState === "disconnecting" || this._internalState === "disconnected") {
1210
1326
  return this._handleDisconnectionWhileConnecting(new Error("premature disconnection 1"), callback);
@@ -1229,7 +1345,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1229
1345
  this._clockAdjuster = this._clockAdjuster || new ClockAdjustment();
1230
1346
  OPCUAClientBase.registry.register(this);
1231
1347
 
1232
- // c8 ignore next
1348
+ /* c8 ignore next */
1233
1349
  doDebug && debugLog("__connectStep2 ", this._internalState);
1234
1350
 
1235
1351
  this._internal_create_secure_channel(this.connectionStrategy, (err: Error | null) => {
@@ -1241,15 +1357,15 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1241
1357
  this._clockAdjuster.dispose();
1242
1358
  this._clockAdjuster = undefined;
1243
1359
  }
1244
- // c8 ignore next
1360
+ /* c8 ignore next */
1245
1361
  doDebug && debugLog(chalk.red("SecureChannel creation has failed with error :", err.message));
1246
1362
  if (err.message.match(/ECONNABORTED/)) {
1247
- // c8 ignore next
1363
+ /* c8 ignore next */
1248
1364
  doDebug && debugLog(chalk.yellow(`- The client cannot to :${endpointUrl}. Connection has been aborted.`));
1249
1365
  err = new Error("The connection has been aborted");
1250
1366
  this._handleUnrecoverableConnectionFailure(err, callback);
1251
1367
  } else if (err.message.match(/ECONNREF/)) {
1252
- // c8 ignore next
1368
+ /* c8 ignore next */
1253
1369
  doDebug && debugLog(chalk.yellow(`- The client cannot to :${endpointUrl}. Server is not reachable.`));
1254
1370
  err = new Error(
1255
1371
  `The connection cannot be established with server ${endpointUrl} .\n` +
@@ -1398,11 +1514,12 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1398
1514
  return;
1399
1515
  }
1400
1516
  this._serverEndpoints = [];
1401
- // c8 ignore next
1517
+ /* c8 ignore start */
1402
1518
  if (!response || !(response instanceof GetEndpointsResponse)) {
1403
1519
  callback(new Error("Internal Error"));
1404
1520
  return;
1405
1521
  }
1522
+ /* c8 ignore stop */
1406
1523
  if (response?.endpoints) {
1407
1524
  this._serverEndpoints = response.endpoints;
1408
1525
  }
@@ -1447,11 +1564,12 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1447
1564
  callback(err);
1448
1565
  return;
1449
1566
  }
1450
- /* c8 ignore next */
1567
+ /* c8 ignore start */
1451
1568
  if (!response || !(response instanceof FindServersResponse)) {
1452
1569
  callback(new Error("Internal Error"));
1453
1570
  return;
1454
1571
  }
1572
+ /* c8 ignore stop */
1455
1573
  response.servers = response.servers || [];
1456
1574
 
1457
1575
  callback(null, response.servers);
@@ -1476,11 +1594,12 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1476
1594
  callback(err);
1477
1595
  return;
1478
1596
  }
1479
- /* c8 ignore next */
1597
+ /* c8 ignore start */
1480
1598
  if (!response || !(response instanceof FindServersOnNetworkResponse)) {
1481
1599
  callback(new Error("Internal Error"));
1482
1600
  return;
1483
1601
  }
1602
+ /* c8 ignore stop */
1484
1603
  response.servers = response.servers || [];
1485
1604
  callback(null, response.servers);
1486
1605
  });
@@ -1506,16 +1625,17 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1506
1625
  assert(typeof callback === "function");
1507
1626
  assert(typeof deleteSubscriptions === "boolean");
1508
1627
 
1509
- // c8 ignore next
1628
+ /* c8 ignore start */
1510
1629
  if (!this._secureChannel) {
1511
1630
  return callback(null); // new Error("no channel"));
1512
1631
  }
1632
+ /* c8 ignore stop */
1513
1633
  assert(this._secureChannel);
1514
1634
  if (!this._secureChannel.isValid()) {
1515
1635
  return callback(null);
1516
1636
  }
1517
1637
 
1518
- // c8 ignore next
1638
+ /* c8 ignore next */
1519
1639
  doDebug && debugLog(chalk.bgWhite.green("_closeSession ") + this._secureChannel.channelId);
1520
1640
 
1521
1641
  const request = new CloseSessionRequest({
@@ -1574,7 +1694,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1574
1694
  const store = this.clientCertificateManager as ICertificateStore & { dispose?: () => Promise<void> };
1575
1695
  if (typeof store.dispose !== "function") return;
1576
1696
  store.dispose().catch((err: Error) => {
1577
- // c8 ignore next
1697
+ /* c8 ignore next */
1578
1698
  doDebug && debugLog("Error disposing clientCertificateManager", err.message);
1579
1699
  });
1580
1700
  }
@@ -1614,19 +1734,19 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1614
1734
  callback();
1615
1735
  return undefined;
1616
1736
  }
1617
- // c8 ignore next
1737
+ /* c8 ignore next */
1618
1738
  doDebug && debugLog("disconnecting client! (will set reconnectionIsCanceled to true");
1619
1739
  this._reconnectionIsCanceled = true;
1620
1740
 
1621
- // c8 ignore next
1741
+ /* c8 ignore next */
1622
1742
  doDebug && debugLog("ClientBaseImpl#disconnect", this.endpointUrl);
1623
1743
 
1624
1744
  if (this.isReconnecting && !this._reconnectionIsCanceled) {
1625
- // c8 ignore next
1745
+ /* c8 ignore next */
1626
1746
  doDebug && debugLog("ClientBaseImpl#disconnect called while reconnection is in progress");
1627
1747
  // let's abort the reconnection process
1628
1748
  this._cancel_reconnection((err?: Error) => {
1629
- // c8 ignore next
1749
+ /* c8 ignore next */
1630
1750
  doDebug && debugLog("ClientBaseImpl#disconnect reconnection has been canceled", this.applicationName);
1631
1751
  assert(!err, " why would this fail ?");
1632
1752
  // sessions cannot be cancelled properly and must be discarded.
@@ -1636,7 +1756,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1636
1756
  }
1637
1757
 
1638
1758
  if (this._sessions.length && !this.keepPendingSessionsOnDisconnect) {
1639
- // c8 ignore next
1759
+ /* c8 ignore next */
1640
1760
  doDebug && debugLog("warning : disconnection : closing pending sessions");
1641
1761
  // disconnect has been called whereas living session exists
1642
1762
  // we need to close them first .... (unless keepPendingSessionsOnDisconnect)
@@ -1646,7 +1766,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1646
1766
  return undefined;
1647
1767
  }
1648
1768
 
1649
- // c8 ignore next
1769
+ /* c8 ignore next */
1650
1770
  doDebug && debugLog("Disconnecting !");
1651
1771
  this._setInternalState("disconnecting");
1652
1772
  this.#releaseCertificateManager();
@@ -1670,7 +1790,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1670
1790
  if (this._secureChannel) {
1671
1791
  let tmpChannel: ClientSecureChannelLayer | null = this._secureChannel;
1672
1792
  this._secureChannel = null;
1673
- // c8 ignore next
1793
+ /* c8 ignore next */
1674
1794
  doDebug && debugLog("Closing channel");
1675
1795
  tmpChannel.close(() => {
1676
1796
  this._secureChannel = tmpChannel;
@@ -1751,7 +1871,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1751
1871
 
1752
1872
  private fetchServerCertificate(endpointUrl: string, callback: (err: Error | null, adjustedEndpointUrl?: string) => void): void {
1753
1873
  const discoveryUrl = this.discoveryUrl.length > 0 ? this.discoveryUrl : endpointUrl;
1754
- // c8 ignore next
1874
+ /* c8 ignore next */
1755
1875
  doDebug && debugLog("OPCUAClientImpl : getting serverCertificate");
1756
1876
  // we have not been given the serverCertificate but this certificate
1757
1877
  // is required as the connection is to be secured.
@@ -1796,12 +1916,13 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1796
1916
  return;
1797
1917
  }
1798
1918
 
1799
- // c8 ignore next
1919
+ /* c8 ignore start */
1800
1920
  if (!result) {
1801
1921
  const err1 = new Error("internal error");
1802
1922
  callback(err1);
1803
1923
  return;
1804
1924
  }
1925
+ /* c8 ignore stop */
1805
1926
 
1806
1927
  const endpoint = result.selectedEndpoint;
1807
1928
  if (!endpoint) {
@@ -1891,7 +2012,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1891
2012
  this._byteRead += this._secureChannel.bytesRead;
1892
2013
  this._transactionsPerformed += this._secureChannel.transactionsPerformed;
1893
2014
  this._timedOutRequestCount += this._secureChannel.timedOutRequestCount;
1894
- // c8 ignore next
2015
+ /* c8 ignore start */
1895
2016
  if (doDebug) {
1896
2017
  const h = `Client ${this._instanceNumber} ${this.clientName}`;
1897
2018
  debugLog(chalk.cyan(`${h} byteWritten = `), this._byteWritten);
@@ -1899,11 +2020,12 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1899
2020
  debugLog(chalk.cyan(`${h} transactions = `), this._transactionsPerformed);
1900
2021
  debugLog(chalk.cyan(`${h} timedOutRequestCount = `), this._timedOutRequestCount);
1901
2022
  }
2023
+ /* c8 ignore stop */
1902
2024
  }
1903
2025
  }
1904
2026
  private _destroy_secure_channel() {
1905
2027
  if (this._secureChannel) {
1906
- // c8 ignore next
2028
+ /* c8 ignore start */
1907
2029
  if (doDebug) {
1908
2030
  debugLog(
1909
2031
  " DESTROYING SECURE CHANNEL (isTransactionInProgress ?",
@@ -1911,6 +2033,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1911
2033
  ")"
1912
2034
  );
1913
2035
  }
2036
+ /* c8 ignore stop */
1914
2037
  this._accumulate_statistics();
1915
2038
  const secureChannel = this._secureChannel;
1916
2039
  this._secureChannel = null;
@@ -1932,7 +2055,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1932
2055
  resolved = true;
1933
2056
  if (err) {
1934
2057
  const msg = session.authenticationToken ? session.authenticationToken.toString() : "";
1935
- // c8 ignore next
2058
+ /* c8 ignore next */
1936
2059
  doDebug && debugLog(` failing to close session ${msg}`);
1937
2060
  }
1938
2061
  resolve();
@@ -1943,9 +2066,9 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1943
2066
 
1944
2067
  closeAll()
1945
2068
  .then(() => {
1946
- // c8 ignore next
2069
+ /* c8 ignore start */
1947
2070
  if (this._sessions.length > 0) {
1948
- // c8 ignore next
2071
+ /* c8 ignore next */
1949
2072
  doDebug &&
1950
2073
  debugLog(
1951
2074
  this._sessions
@@ -1953,6 +2076,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
1953
2076
  .join(" ")
1954
2077
  );
1955
2078
  }
2079
+ /* c8 ignore stop */
1956
2080
  assert(this._sessions.length === 0, " failed to disconnect exiting sessions ");
1957
2081
  callback();
1958
2082
  })
@@ -2000,7 +2124,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
2000
2124
 
2001
2125
  secureChannel.on("lifetime_75", (token: ChannelSecurityToken) => {
2002
2126
  // secureChannel requests a new token
2003
- // c8 ignore next
2127
+ /* c8 ignore start */
2004
2128
  doDebug &&
2005
2129
  debugLog(
2006
2130
  "SecureChannel Security Token ",
@@ -2009,6 +2133,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
2009
2133
  token.revisedLifetime,
2010
2134
  " is about to expired , it's time to request a new token"
2011
2135
  );
2136
+ /* c8 ignore stop */
2012
2137
  // forward message to upper level
2013
2138
  this.emit("lifetime_75", token);
2014
2139
  });
@@ -2022,7 +2147,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
2022
2147
  if (err) {
2023
2148
  this._setInternalState("panic");
2024
2149
  }
2025
- // c8 ignore next
2150
+ /* c8 ignore next */
2026
2151
  doDebug && debugLog(chalk.yellow.bold(" ClientBaseImpl emitting close"), err?.message);
2027
2152
  this._destroy_secure_channel();
2028
2153
  if (!err || !this.reconnectOnFailure) {
@@ -2040,7 +2165,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
2040
2165
  this._internalState !== "reconnecting" &&
2041
2166
  this._internalState !== "reconnecting_newchannel_connected"
2042
2167
  ) {
2043
- // c8 ignore next
2168
+ /* c8 ignore next */
2044
2169
  doDebug && debugLog(" ClientBaseImpl emitting connection_lost");
2045
2170
  this._setInternalState("reconnecting");
2046
2171
  /**
@@ -2092,7 +2217,7 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
2092
2217
  private __innerRepairConnection() {
2093
2218
  if (this.isUnusable()) return;
2094
2219
 
2095
- // c8 ignore next
2220
+ /* c8 ignore next */
2096
2221
  doDebug && debugLog("Entering _repairConnection ", this._internalState);
2097
2222
  if (this.#insideRepairConnection) {
2098
2223
  errorLog(
@@ -2106,13 +2231,13 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
2106
2231
  }
2107
2232
  this.emit("repairConnectionStarted");
2108
2233
  this.#insideRepairConnection = true;
2109
- // c8 ignore next
2234
+ /* c8 ignore next */
2110
2235
  doDebug && debugLog("recreating new secure channel ", this._internalState);
2111
2236
  this._recreate_secure_channel((err1?: Error) => {
2112
- // c8 ignore next
2237
+ /* c8 ignore next */
2113
2238
  doDebug && debugLog("secureChannel#on(close) => _recreate_secure_channel returns ", err1 ? err1.message : "OK");
2114
2239
  if (err1) {
2115
- // c8 ignore next
2240
+ /* c8 ignore next */
2116
2241
  doDebug && debugLog("_recreate_secure_channel has failed: err = ", err1.message);
2117
2242
  this.emit("close", err1);
2118
2243
  this.#insideRepairConnection = false;
@@ -2127,17 +2252,19 @@ export class ClientBaseImpl<Events extends OPCUAClientBaseEvents = OPCUAClientBa
2127
2252
  if (this.isUnusable()) return;
2128
2253
  this._finalReconnectionStep((err2?: Error | null) => {
2129
2254
  if (err2) {
2130
- // c8 ignore next
2255
+ /* c8 ignore start */
2131
2256
  if (doDebug) {
2132
2257
  debugLog("connection_reestablished has failed");
2133
2258
  debugLog("err= ", err2.message);
2134
2259
  }
2260
+ /* c8 ignore stop */
2135
2261
  // we still need to retry connecting here !!!
2136
- // c8 ignore next
2262
+ /* c8 ignore start */
2137
2263
  if (doDebug) {
2138
2264
  debugLog("Disconnected following reconnection failure", err2.message);
2139
2265
  debugLog(`I will retry OPCUA client reconnection in ${OPCUAClientBase.retryDelay / 1000} seconds`);
2140
2266
  }
2267
+ /* c8 ignore stop */
2141
2268
  this.#insideRepairConnection = false;
2142
2269
  this.#shouldRepairAgain = false;
2143
2270
 
@@ -2201,14 +2328,15 @@ class TmpClient extends ClientBaseImpl {
2201
2328
  async connect(endpoint: string): Promise<void>;
2202
2329
  connect(endpoint: string, callback: ErrorCallback): void;
2203
2330
  connect(endpoint: string, callback?: ErrorCallback): Promise<void> | void {
2204
- // c8 ignore next
2331
+ /* c8 ignore next */
2205
2332
  doDebug && debugLog("connecting to TmpClient");
2206
2333
 
2207
- // c8 ignore next
2334
+ /* c8 ignore start */
2208
2335
  if (this._internalState !== "disconnected") {
2209
2336
  callback?.(new Error(`TmpClient#connect: invalid internal state = ${this._internalState}`));
2210
2337
  return;
2211
2338
  }
2339
+ /* c8 ignore stop */
2212
2340
 
2213
2341
  this._setInternalState("connecting");
2214
2342
  this._connectStep2(endpoint, (err?: Error) => {