Skip to content

Commit

Permalink
update to new node-opcua-crypto & pki
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Jun 2, 2023
1 parent 0335415 commit 4c64a14
Show file tree
Hide file tree
Showing 51 changed files with 941 additions and 653 deletions.
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"eslint-fix": "eslint --fix packages/*/src/**.js packages/*/__tests__/ utils/*.js scripts/*.js",
"generate_doc": "make doc",
"generate_autodoc": "npx autodoc -o _tmp_generated_doc bin/binaryStream.js",
"ncu": "ncu -u -x mkdirp,@types/mkdirp,yargs,env-paths,cli-truncate,long,chalk,case-anything,rimraf --target=latest && lerna exec --concurrency 1 --sort --stream ncu -- -u --timeout 100000 -x mkdirp,@types/mkdirp,yargs,env-paths,cli-truncate,long,chalk,case-anything,rimraf --target=latest --packageFile package.json ",
"ncu": "ncu -u -x mkdirp,@types/mkdirp,yargs,env-paths,cli-truncate,long,chalk,case-anything,rimraf --target=latest && lerna exec --concurrency 10 --sort --stream ncu -- -u --timeout 100000 -x mkdirp,@types/mkdirp,yargs,env-paths,cli-truncate,long,chalk,case-anything,rimraf --target=latest --packageFile package.json ",
"ncu_": "npx npm-check --skip-unused -ayu && lerna exec --sort --concurrency 1 --stream -- npx npm-check --skip-unused -ayu",
"prettier-watch": "onchange \"packages/*/(src|test|source)/**/*.(js|ts)\" -v -p -- prettier --write {{changed}}",
"lebab-let": "lerna exec lebab --replace index.js --transform let && lerna exec lebab --replace test --transform let && lerna exec lebab --replace src --transform let",
Expand Down Expand Up @@ -64,14 +64,14 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/mocha": "^10.0.1",
"@types/prettier": "^2.7.2",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"@types/prettier": "^2.7.3",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"app-module-path": "^2.2.0",
"benchmark": "^2.1.4",
"bignumber.js": "^9.1.1",
"coveralls": "^3.1.1",
"csv": "^6.2.12",
"csv": "^6.3.1",
"enum": "3.0.4",
"ersatz-node-expat": "^0.1.6",
"eslint-cli": "^1.1.1",
Expand All @@ -85,20 +85,20 @@
"nyc": "^15.1.0",
"prettier": "^2.8.8",
"ts-node": "^10.9.1",
"typescript": "5.0.4"
"typescript": "5.1.3"
},
"typings": "./packages/node-opcua/node-opcua.d.ts",
"dependencies": {
"@ster5/global-mutex": "^1.2.0",
"@ster5/global-mutex": "^2.0.0",
"@types/async": "^3.2.20",
"@types/bonjour": "^3.5.10",
"@types/lodash": "4.14.194",
"@types/lodash": "4.14.195",
"@types/long": "^4.0.2",
"@types/mkdirp": "1.0.2",
"@types/node": "20.1.0",
"@types/node": "20.2.5",
"@types/rimraf": "^3.0.2",
"@types/sinon": "10.0.14",
"@types/underscore": "^1.11.4",
"@types/sinon": "10.0.15",
"@types/underscore": "^1.11.5",
"@types/wordwrap": "^1.0.1",
"@types/yargs": "17.0.24",
"async": "^3.2.4",
Expand All @@ -109,14 +109,14 @@
"chalk": "4.1.2",
"cli-table3": "^0.6.3",
"cli-truncate": "2.1.0",
"csv-parse": "5.3.10",
"csv-parse": "5.4.0",
"date-utils": "^1.2.21",
"deassertify": "^0.2.0",
"delayed": "^2.0.0",
"dequeue": "^1.0.5",
"easy-table": "^1.2.0",
"env-paths": "2.2.1",
"eslint": "8.40.0",
"eslint": "8.41.0",
"exit": "^0.1.2",
"fqdn": "^0.0.3",
"hexy": "0.3.4",
Expand All @@ -130,23 +130,23 @@
"memfs": "^3.5.1",
"mkdirp": "1.0.4",
"mocha-clean": "^1.0.0",
"node-opcua-crypto": "^2.2.0",
"node-opcua-pki": "^3.1.2",
"node-opcua-crypto": "3.0.5",
"node-opcua-pki": "4.2.0",
"object.values": "^1.1.6",
"pretty-ms": "^8.0.0",
"progress": "^2.0.3",
"rimraf": "3.0.2",
"semver": "^7.5.0",
"semver": "^7.5.1",
"set-prototype-of": "^1.0.0",
"shebang-loader": "^0.0.1",
"should": "^13.2.3",
"sinon": "^15.0.4",
"sinon": "^15.1.0",
"source-map-support": "^0.5.21",
"sprintf-js": "^1.1.2",
"sterfive-bonjour-service": "1.1.4",
"thenify": "^3.3.1",
"treeify": "^1.1.0",
"tslib": "^2.5.0",
"tslib": "^2.5.2",
"underscore": "^1.13.6",
"vorpal": "^1.12.0",
"vorpal-repl": "^1.1.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-address-space-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"node-opcua-assert": "2.98.1",
"node-opcua-basic-types": "2.99.0",
"node-opcua-constants": "2.98.1",
"node-opcua-crypto": "^2.2.0",
"node-opcua-crypto": "3.0.5",
"node-opcua-data-model": "2.102.0",
"node-opcua-data-value": "2.102.0",
"node-opcua-date-time": "2.99.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/node-opcua-address-space/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"c": "mocha --version"
},
"dependencies": {
"@types/lodash": "4.14.194",
"@types/semver": "^7.3.13",
"@types/lodash": "4.14.195",
"@types/semver": "^7.5.0",
"async": "^3.2.4",
"chalk": "4.1.2",
"dequeue": "^1.0.5",
Expand All @@ -28,7 +28,7 @@
"node-opcua-binary-stream": "2.98.1",
"node-opcua-client-dynamic-extension-object": "2.103.0",
"node-opcua-constants": "2.98.1",
"node-opcua-crypto": "^2.2.0",
"node-opcua-crypto": "3.0.5",
"node-opcua-data-access": "2.103.0",
"node-opcua-data-model": "2.102.0",
"node-opcua-data-value": "2.102.0",
Expand All @@ -52,7 +52,7 @@
"node-opcua-utils": "2.98.1",
"node-opcua-variant": "2.102.0",
"node-opcua-xml2json": "2.103.0",
"semver": "^7.5.0",
"semver": "^7.5.1",
"set-prototype-of": "^1.0.0",
"thenify": "^3.3.1",
"xml-writer": "^1.7.0"
Expand All @@ -66,7 +66,7 @@
"node-opcua-service-filter": "2.103.0",
"node-opcua-test-fixtures": "2.103.0",
"should": "^13.2.3",
"sinon": "^15.0.4",
"sinon": "^15.1.0",
"source-map-support": "^0.5.21"
},
"author": "Etienne Rossignon",
Expand Down
4 changes: 2 additions & 2 deletions packages/node-opcua-basic-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc -b",
"test": "echo none",
"test": "mocha",
"clean": "npx rimraf node_modules dist *.tsbuildinfo",
"lint": "eslint source/*.ts"
},
Expand All @@ -20,7 +20,7 @@
"node-opcua-status-code": "2.98.1"
},
"devDependencies": {
"@types/node": "20.1.0",
"@types/node": "20.2.5",
"node-opcua-benchmarker": "2.98.1",
"node-opcua-debug": "2.99.0",
"should": "^13.2.3"
Expand Down
6 changes: 4 additions & 2 deletions packages/node-opcua-certificate-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"dependencies": {
"node-opcua-pki": "4.2.0",
"node-opcua-crypto": "3.0.5",
"@types/mkdirp": "1.0.2",
"env-paths": "2.2.1",
"mkdirp": "1.0.4",
"node-opcua-assert": "2.98.1",
"node-opcua-crypto": "^2.2.0",
"node-opcua-debug": "2.99.0",
"node-opcua-object-registry": "2.99.0",
"node-opcua-pki": "^3.1.2",
"node-opcua-status-code": "2.98.1",
"thenify": "^3.3.1"
},
"peerDependencies": {
},
"devDependencies": {
"mocha": "^10.2.0",
"node-opcua-leak-detector": "2.99.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import * as path from "path";

import * as mkdirp from "mkdirp";
import envPaths from "env-paths";

import { withLock } from "@ster5/global-mutex";

import { checkDebugFlag, make_debugLog, make_errorLog } from "node-opcua-debug";

import { Certificate, makeSHA1Thumbprint, split_der } from "node-opcua-crypto";
Expand Down Expand Up @@ -176,6 +179,9 @@ export class OPCUACertificateManager extends CertificateManager implements ICert
callback!(err, err ? undefined : (StatusCodes as any)[trustedStatus!]);
});
}
public async withLock2<T>(action: () => Promise<T>): Promise<T> {
return await super.withLock2(action);
}
}

// tslint:disable:no-var-requires
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-certificate-manager/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*/
export * from "./certificate_manager";
export * from "./make_subject";
export { CertificateManager, CertificateAuthority, g_config } from "node-opcua-pki";
export { CertificateManager } from "node-opcua-pki";
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import * as path from "path";
import * as fs from "fs";
import "mocha";
import { StatusCodes } from "node-opcua-status-code";
import rimraf from "rimraf";
import should from "should";

const _should = should; // make sure should is not removed during typescript compilation
import { CertificateAuthority } from "node-opcua-pki";
import { StatusCodes } from "node-opcua-status-code";

import { Certificate, readCertificate, makeSHA1Thumbprint, readCertificateRevocationList } from "node-opcua-crypto";
import { OPCUACertificateManager, OPCUACertificateManagerOptions } from "../source";
import { CertificateAuthority, CertificateManager } from "..";
import { CertificateManager } from "..";

async function t(a: number) {
return await new Promise((resolve) => setTimeout(resolve, 1000));
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-chunkmanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"node-opcua-packet-assembler": "2.99.0"
},
"devDependencies": {
"@types/node": "20.1.0",
"@types/node": "20.2.5",
"node-opcua-debug": "2.99.0",
"should": "^13.2.3",
"source-map-support": "^0.5.21"
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-client-crawler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"devDependencies": {
"node-opcua-pseudo-session": "2.103.0",
"should": "^13.2.3",
"sinon": "^15.0.4"
"sinon": "^15.1.0"
},
"author": "Etienne Rossignon",
"license": "MIT",
Expand Down
10 changes: 5 additions & 5 deletions packages/node-opcua-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"dependencies": {
"@ster5/global-mutex": "^1.2.0",
"@ster5/global-mutex": "^2.0.0",
"@types/async": "^3.2.20",
"async": "^3.2.4",
"chalk": "4.1.2",
Expand All @@ -24,7 +24,7 @@
"node-opcua-client-dynamic-extension-object": "2.103.0",
"node-opcua-common": "2.103.0",
"node-opcua-constants": "2.98.1",
"node-opcua-crypto": "^2.2.0",
"node-opcua-crypto": "3.0.5",
"node-opcua-data-model": "2.102.0",
"node-opcua-data-value": "2.102.0",
"node-opcua-date-time": "2.99.0",
Expand All @@ -33,7 +33,7 @@
"node-opcua-hostname": "2.98.1",
"node-opcua-nodeid": "2.99.0",
"node-opcua-object-registry": "2.99.0",
"node-opcua-pki": "^3.1.2",
"node-opcua-pki": "4.2.0",
"node-opcua-pseudo-session": "2.103.0",
"node-opcua-schemas": "2.103.0",
"node-opcua-secure-channel": "2.103.0",
Expand All @@ -58,7 +58,7 @@
"thenify": "^3.3.1"
},
"devDependencies": {
"@types/underscore": "^1.11.4",
"@types/underscore": "^1.11.5",
"dequeue": "^1.0.5",
"mocha": "^10.2.0",
"node-opcua-address-space": "2.103.0",
Expand All @@ -67,7 +67,7 @@
"node-opcua-leak-detector": "2.99.0",
"node-opcua-nodesets": "2.103.0",
"should": "^13.2.3",
"sinon": "^15.0.4",
"sinon": "^15.1.0",
"underscore": "^1.13.6"
},
"eslintConfig": {
Expand Down
21 changes: 10 additions & 11 deletions packages/node-opcua-client/source/private/client_base_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as fs from "fs";
import * as path from "path";
import * as async from "async";
import chalk from "chalk";

import { withLock } from "@ster5/global-mutex";
import { assert } from "node-opcua-assert";
import { IOPCUASecureObjectOptions, OPCUASecureObject } from "node-opcua-common";
Expand Down Expand Up @@ -750,11 +749,14 @@ export class ClientBaseImpl extends OPCUASecureObject implements OPCUAClientBase
if ((this as any)._inCreateDefaultCertificate) {
errorLog("Internal error : re-entrancy in createDefaultCertificate!");
}

(this as any)._inCreateDefaultCertificate = true;
if (!fs.existsSync(this.certificateFile)) {
const lockfile = path.join(this.certificateFile + ".lock");
await withLock({ lockfile: lockfile, maxStaleDuration: 60 * 1000, retryInterval: 100 }, async () => {
await withLock({ fileToLock: this.certificateFile + ".mutex" }, async () => {
if (fs.existsSync(this.certificateFile)) {
// the file may have been created in between
return;
}
console.log("Creating default certificate ... please wait");
if (this.disconnecting) return;

await ClientBaseImpl.createCertificate(
Expand Down Expand Up @@ -797,13 +799,10 @@ export class ClientBaseImpl extends OPCUASecureObject implements OPCUAClientBase
if (!fs.existsSync(this.privateKeyFile)) {
throw new Error(" cannot locate private key file " + this.privateKeyFile);
}

if (this.disconnecting) return;

const lockfile = path.join(this.certificateFile + ".lock");
await withLock({ lockfile: lockfile, maxStaleDuration: 60 * 1000, retryInterval: 100 }, async () => {
if (this.disconnecting) return;
await performCertificateSanityCheck.call(this, "client", this.clientCertificateManager, this._getBuiltApplicationUri());
await this.clientCertificateManager.withLock2(async () => {
await performCertificateSanityCheck(this, "client", this.clientCertificateManager, this._getBuiltApplicationUri());
});
}

Expand Down Expand Up @@ -1289,12 +1288,12 @@ export class ClientBaseImpl extends OPCUASecureObject implements OPCUAClientBase
tmpChannel = null;
this._destroy_secure_channel();
this._setInternalState("disconnected");
setImmediate(callback);
callback();
});
} else {
this._setInternalState("disconnected");
// this.emit("close", null);
setImmediate(callback);
callback();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
extractPublicKeyFromCertificateSync,
Nonce,
PrivateKey,
PrivateKeyPEM,
toPem
} from "node-opcua-crypto";

Expand Down

0 comments on commit 4c64a14

Please sign in to comment.