node-opcua-client 2.107.0 → 2.109.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.
@@ -1,19 +1,14 @@
1
1
  /**
2
2
  * @module node-opcua-client-private
3
3
  */
4
- // tslint:disable:variable-name
5
- // tslint:disable:no-console
6
- // tslint:disable:no-empty
7
-
8
- import * as crypto from "crypto";
9
- import { createPublicKey } from "crypto";
10
4
  import { callbackify } from "util";
5
+ import { randomBytes, createPublicKey } from "crypto";
11
6
  import * as async from "async";
12
7
  import chalk from "chalk";
13
8
 
14
9
  import { assert } from "node-opcua-assert";
15
10
  import { createFastUninitializedBuffer } from "node-opcua-buffer-utils";
16
- import { Certificate, exploreCertificate, extractPublicKeyFromCertificateSync, Nonce, PrivateKey, toPem } from "node-opcua-crypto";
11
+ import { Certificate, exploreCertificate, extractPublicKeyFromCertificateSync, makePrivateKeyFromPem, PrivateKey, Nonce, toPem } from "node-opcua-crypto";
17
12
 
18
13
  import { LocalizedText } from "node-opcua-data-model";
19
14
  import { checkDebugFlag, make_debugLog, make_errorLog, make_warningLog } from "node-opcua-debug";
@@ -312,7 +307,7 @@ function _adjustRevisedSessionTimeout(revisedSessionTimeout: number, requestedTi
312
307
  */
313
308
  export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
314
309
  public static minimumRevisedSessionTimeout = 100.0;
315
- private _retryCreateSessionTimer?: NodeJS.Timer;
310
+ private _retryCreateSessionTimer?: NodeJS.Timeout;
316
311
 
317
312
  public static create(options: OPCUAClientOptions): OPCUAClient {
318
313
  return new OPCUAClientImpl(options);
@@ -849,7 +844,7 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
849
844
 
850
845
  // note : do not confuse CreateSessionRequest.clientNonce with OpenSecureChannelRequest.clientNonce
851
846
  // which are two different nonce, with different size (although they share the same name )
852
- this.clientNonce = crypto.randomBytes(32);
847
+ this.clientNonce = randomBytes(32);
853
848
 
854
849
  // recycle session name if already exists
855
850
  const sessionName = session.name;
@@ -1262,7 +1257,7 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
1262
1257
 
1263
1258
  case UserTokenType.Certificate: {
1264
1259
  const certificate = userIdentityInfo.certificateData;
1265
- const privateKey = crypto.createPrivateKey(userIdentityInfo.privateKey);
1260
+ const privateKey = makePrivateKeyFromPem(userIdentityInfo.privateKey);
1266
1261
  ({ userIdentityToken, userTokenSignature } = createX509IdentityToken(context, certificate, privateKey));
1267
1262
  break;
1268
1263
  }
@@ -475,10 +475,11 @@ export function repair_client_session(client: IClientBase, session: ClientSessio
475
475
  return;
476
476
  }
477
477
 
478
- console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DELETE ME");
479
478
  privateSession._reconnecting.reconnecting = false;
480
- errorLog("Session has been restored");
479
+
480
+ // warningLog("Session has been restored");
481
481
  doDebug && debugLog(chalk.yellow("session has been restored"), session.sessionId.toString());
482
+
482
483
  session.emit("session_restored");
483
484
  const otherCallbacks = privateSession._reconnecting.pendingCallbacks;
484
485
  privateSession._reconnecting.pendingCallbacks = [];
package/source/verify.ts CHANGED
@@ -1,15 +1,14 @@
1
- import { createPrivateKey } from "crypto";
2
1
  import { OPCUACertificateManager } from "node-opcua-certificate-manager";
3
2
  import { OPCUASecureObject } from "node-opcua-common";
4
3
 
5
4
  import {
6
5
  Certificate,
7
- convertPEMtoDER,
8
6
  exploreCertificate,
9
7
  explorePrivateKey,
10
8
  publicKeyAndPrivateKeyMatches
11
9
  } from "node-opcua-crypto";
12
10
  import { checkDebugFlag, make_debugLog, make_errorLog, make_warningLog } from "node-opcua-debug";
11
+ import { VerifyCertificateOptions } from "node-opcua-pki";
13
12
 
14
13
  const doDebug = checkDebugFlag(__filename);
15
14
  const debugLog = make_debugLog(__filename);
@@ -152,7 +151,14 @@ export async function performCertificateSanityCheck(
152
151
  }
153
152
  // verify that the certificate has a valid date and has expected extensions fields such as DNS and IP.
154
153
  const status1 = await certificateManager.trustCertificate(certificate);
155
- const status = await certificateManager.verifyCertificateAsync(certificate);
154
+
155
+ const options: VerifyCertificateOptions = {
156
+ acceptOutdatedCertificate: false,
157
+ acceptOutDatedIssuerCertificate: false,
158
+ acceptPendingCertificate: false,
159
+ };
160
+
161
+ const status = await certificateManager.verifyCertificate(certificate, options);
156
162
 
157
163
  if (status !== "Good") {
158
164
  warningLog("[NODE-OPCUA-W04] Warning: the certificate status is = ", status, " file = ", secureObject.certificateFile);