node-opcua-crypto 3.0.0 → 3.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-crypto",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Crypto tools for Node-OPCUA",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -17,16 +17,18 @@
17
17
  }
18
18
  },
19
19
  "scripts": {
20
- "compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json ./tsconfig-test.cjs.json",
20
+ "compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
21
+ "compile:test": "tsc -b ./tsconfig-test.cjs.json",
21
22
  "build:demo": "node web/esbuild.mjs",
22
23
  "build:clean": "npx rimraf ./dist ./dist-* *.tsbuildinfo",
23
24
  "build": "npm run build:clean && npm run compile && node ./scripts/prepare-package-json.mjs",
25
+ "build:test": "npm run compile:test && node ./scripts/prepare-package-json.mjs",
24
26
  "prepare": "npm run build",
25
27
  "tslint": "tslint --project . --fix",
26
28
  "lint": "eslint . --ext .ts",
27
29
  "test:esm": "mocha test -r ts-node/register -r source-map-support/register -R spec --recursive --timeout 200000 --bail",
28
30
  "test:cjs": "mocha dist-test -r source-map-support/register -R spec --recursive --timeout 200000 --bail",
29
- "test": "npm run test:esm && npm run test:cjs",
31
+ "test": "npm run build:test && npm run test:esm && npm run test:cjs",
30
32
  "makedoc": "npx typedoc -out doc",
31
33
  "cost-of-modules": "npx cost-of-modules --no-install",
32
34
  "release-it": "npx release-it",
@@ -48,11 +50,12 @@
48
50
  },
49
51
  "devDependencies": {
50
52
  "@types/mocha": "^10.0.1",
51
- "@types/node": "^20.1.4",
52
- "@typescript-eslint/eslint-plugin": "^5.59.5",
53
- "@typescript-eslint/parser": "^5.59.5",
53
+ "@types/node": "^20.2.5",
54
+ "@typescript-eslint/eslint-plugin": "^5.59.7",
55
+ "@typescript-eslint/parser": "^5.59.7",
54
56
  "crypto": "^1.0.1",
55
- "eslint": "^8.40.0",
57
+ "esbuild-plugin-polyfill-node": "^0.2.0",
58
+ "eslint": "^8.41.0",
56
59
  "eslint-config-prettier": "^8.8.0",
57
60
  "eslint-plugin-prettier": "^4.2.1",
58
61
  "lorem-ipsum": "^2.0.8",
@@ -70,7 +73,6 @@
70
73
  "assert": "^2.0.0",
71
74
  "better-assert": "^1.0.2",
72
75
  "chalk": "^4.1.2",
73
- "esbuild-plugin-polyfill-node": "^0.2.0",
74
76
  "hexy": "0.3.4",
75
77
  "jsrsasign": "^10.8.6",
76
78
  "sshpk": "^1.17.0"
package/web/esbuild.mjs DELETED
@@ -1,19 +0,0 @@
1
- // build with esbuild
2
- import { build } from "esbuild";
3
- import { polyfillNode } from "esbuild-plugin-polyfill-node";
4
-
5
- build({
6
- entryPoints: ["web/main.ts"],
7
- bundle: true,
8
- outfile: "web/bundle.js",
9
- sourcemap: true,
10
- // minify: true,
11
- plugins: [
12
- polyfillNode({
13
- polyfills: {
14
- crypto: true, // 'rollup-plugin-node-polyfills/polyfills/crypto-browserify'
15
- // Options (optional)
16
- }
17
- }),
18
- ],
19
- });
package/web/index.html DELETED
@@ -1,77 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <script src="./bundle.js" type="module"></script>
7
- <link
8
- href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css"
9
- rel="stylesheet"
10
- integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ"
11
- crossorigin="anonymous"
12
- />
13
- <title>OPCUA Certificate Maker</title>
14
- </head>
15
- <body>
16
- <div class="container">
17
- <div class="row">
18
- <form>
19
- <div class="mb-3">
20
- <label for="keySize" class="form-label">Key size</label>
21
- <select class="form-select" aria-label="Default select example" id="keySize" aria-describedby="keyizeHelp" >
22
- <option value="1024">1024</option>
23
- <option selected value="2048">2048</option>
24
- <option value="3072">3072</option>
25
- <option value="4096">4096</option>
26
- </select>
27
- <div id="keySizeHelp" class="form-text">
28
- the key-size in bits defines the strength of the public/private key pair.
29
- </div>
30
- </div>
31
- <div class="mb-3">
32
- <label for="subjet" class="form-label">Subject</label>
33
- <input type="string" class="form-control" id="subject" aria-describedby="subjectHelp" value="CN=NodeOPCUA/C=France/L=ORLEANS/O=Sterfive SAS"/>
34
- <div id="subjectHelp" class="form-text">Enter the concatenated Subject string</div>
35
- </div>
36
- <div class="mb-3">
37
- <label for="applicationUri" class="form-label">Application URI</label>
38
- <input type="string" class="form-control" id="applicationUri" aria-describedby="applicationUriHelp" value="urn:HOSTNAME:ServerDescription"/>
39
- <div id="applicationUriHelp" class="form-text"></div>
40
- </div>
41
- <div class="mb-3">
42
- <label for="dns" class="form-label" aria-describedby="dnsHelp">DNS names</label>
43
- <input type="string" class="form-control" id="dns" />
44
- <div id="dnsHelp" class="form-text">enter a list of dns name, separated with semi-columns (;)</div>
45
- </div>
46
- <div class="mb-3">
47
- <label for="ip" class="form-label" aria-describedby="ipHelp">IP Address list</label>
48
- <input type="string" class="form-control" id="ip" />
49
- <div id="applicationUriHelp" class="form-text">enter a list of ip addresses i.e. 123.456.789.012, separated with semi-columns (;)</div></div>
50
- </div>
51
- <button type="submit" class="btn btn-primary" id="generate">Generate Private key and Self-Signed Certificate</button>
52
- </form>
53
- </div>
54
- <div class="row">
55
- <div class="col col-4">
56
- <h2>PrivateKey</h2>
57
- <div id="privateKey"></div>
58
- </div>
59
- <div class="col col-4">
60
- <h2>Certificate</h2>
61
- <div id="certificate"></div>
62
- </div>
63
- <div class="col col-4" >
64
- <h2>Info</h2>
65
- <pre id="info"></pre>
66
- </div>
67
- </div>
68
- </div>
69
- <script
70
- src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"
71
- integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe"
72
- crossorigin="anonymous"
73
- ></script>
74
- <script>
75
- </script>
76
- </body>
77
- </html>
package/web/main.ts DELETED
@@ -1,90 +0,0 @@
1
- /* eslint-disable no-undef */
2
- // declare const global: any;
3
-
4
- import {
5
- generatePrivateKey,
6
- privateKeyToPEM,
7
- CertificatePurpose,
8
- createSelfSignedCertificate,
9
- exploreCertificateInfo,
10
- convertPEMtoDER,
11
- exploreCertificate,
12
- } from "..";
13
-
14
- let privateKey: CryptoKey | undefined;
15
- export async function makeSelfSignedCertificate({
16
- subject,
17
- applicationUri,
18
- dns,
19
- ip,
20
- privateKey,
21
- }: {
22
- applicationUri: string;
23
- subject: string;
24
- dns: string[];
25
- ip: string[];
26
- privateKey: CryptoKey;
27
- }) {
28
- // create a self-sign certificate
29
- const { cert } = await createSelfSignedCertificate({
30
- privateKey,
31
- notAfter: new Date(2020, 1, 1),
32
- notBefore: new Date(2019, 1, 1),
33
- subject,
34
- dns,
35
- ip,
36
- applicationUri,
37
- purpose: CertificatePurpose.ForApplication,
38
- });
39
-
40
- return { privateKey, selfSignedCertificate: cert };
41
- }
42
-
43
- console.log("Hello World! Let's create a Private key in PKCS8 PEM Format and a X509 OPCUA Self-Signed Certificate! ");
44
-
45
- declare const window: any;
46
- declare const document: any;
47
-
48
- window.addEventListener("load", (event) => {
49
- console.log("page is fully loaded");
50
- document.getElementById("generate").addEventListener("click", generate);
51
- });
52
-
53
- async function generate(event) {
54
- event.preventDefault();
55
- const keySize = document.getElementById("keySize").value;
56
- const applicationUri = document.getElementById("applicationUri").value;
57
- const subject = document.getElementById("subject").value;
58
- const dns = (document.getElementById("dns").value || "").split(";").filter((a: string) => !!a);
59
- const ip = (document.getElementById("ip").value || "").split(";").filter((a: string) => !!a);
60
- const validKeySizes = ["1024", "2048", "4096", "3072"];
61
- if (validKeySizes.indexOf(keySize) === -1) {
62
- alert(" Invalid key size " + keySize + "\n expected " + validKeySizes.join(" , "));
63
- return;
64
- }
65
- console.log("key size =", keySize);
66
- console.log("applicationUri =", applicationUri);
67
- console.log("dnsNames =", dns);
68
- console.log("ipAddresses =", ip);
69
-
70
- if (!privateKey) {
71
- privateKey = await generatePrivateKey(keySize);
72
- }
73
- const { selfSignedCertificate } = await makeSelfSignedCertificate({
74
- subject,
75
- applicationUri,
76
- dns,
77
- ip,
78
- privateKey,
79
- });
80
- const { privPem } = await privateKeyToPEM(privateKey);
81
-
82
- document.getElementById("privateKey").innerHTML = `<pre>${privPem}</pre>`;
83
- document.getElementById("certificate").innerHTML = `<pre>${selfSignedCertificate}</pre>`;
84
-
85
- const info = exploreCertificate(convertPEMtoDER(selfSignedCertificate));
86
- const subjectPublicKey = info.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey;
87
- (subjectPublicKey as any).modulus = subjectPublicKey.modulus.toString("hex");
88
-
89
- document.getElementById("info").innerHTML = `<pre>${JSON.stringify(info, null, " ")}</pre>`;
90
- }
@@ -1,20 +0,0 @@
1
- import resolve from '@rollup/plugin-node-resolve';
2
- import nodePolyfills from 'rollup-plugin-polyfill-node';
3
- import commonjs from "rollup-plugin-commonjs";
4
-
5
- export default {
6
-
7
- input: './web/main.js',
8
- output: {
9
- file: './web/bundle.js',
10
- format: 'esm'
11
- },
12
- plugins: [resolve(), nodePolyfills({
13
- include: ['crypto'],
14
- crypto: true,
15
- assert: true,
16
- }),
17
- commonjs({ sourceMap: false })
18
- ]
19
- };
20
-