node-opcua-crypto 2.1.2 → 3.0.0-beta.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 (117) hide show
  1. package/.fossa.yml +18 -18
  2. package/.github/FUNDING.yml +12 -12
  3. package/.github/workflows/main.yml +109 -106
  4. package/.prettierrc.js +6 -6
  5. package/LICENSE +23 -23
  6. package/README.md +14 -14
  7. package/_tmp_certificate.pem +20 -0
  8. package/_tmp_csr.pem +17 -0
  9. package/_tmp_privatekey.der +0 -0
  10. package/_tmp_privatekey.pem +28 -0
  11. package/dist/source/asn1.d.ts +73 -73
  12. package/dist/source/asn1.js +359 -359
  13. package/dist/source/asn1.js.map +1 -1
  14. package/dist/source/buffer_utils.d.ts +5 -6
  15. package/dist/source/buffer_utils.js +21 -21
  16. package/dist/source/common.d.ts +20 -14
  17. package/dist/source/common.js +10 -2
  18. package/dist/source/common.js.map +1 -1
  19. package/dist/source/create_key_pair.d.ts +42 -0
  20. package/dist/source/create_key_pair.js +136 -0
  21. package/dist/source/create_key_pair.js.map +1 -0
  22. package/dist/source/crypto_explore_certificate.d.ts +107 -107
  23. package/dist/source/crypto_explore_certificate.js +601 -601
  24. package/dist/source/crypto_utils.d.ts +76 -76
  25. package/dist/source/crypto_utils.js +329 -329
  26. package/dist/source/derived_keys.d.ts +72 -72
  27. package/dist/source/derived_keys.js +248 -248
  28. package/dist/source/explore_certificate.d.ts +30 -30
  29. package/dist/source/explore_certificate.js +43 -43
  30. package/dist/source/explore_certificate_revocation_list.d.ts +28 -28
  31. package/dist/source/explore_certificate_revocation_list.js +69 -69
  32. package/dist/source/explore_certificate_signing_request.d.ts +13 -13
  33. package/dist/source/explore_certificate_signing_request.js +44 -44
  34. package/dist/source/explore_private_key.d.ts +29 -29
  35. package/dist/source/explore_private_key.js +95 -97
  36. package/dist/source/explore_private_key.js.map +1 -1
  37. package/dist/source/index.d.ts +17 -13
  38. package/dist/source/index.js +33 -29
  39. package/dist/source/index.js.map +1 -1
  40. package/dist/source/oid_map.d.ts +7 -7
  41. package/dist/source/oid_map.js +303 -303
  42. package/dist/source/public_private_match.d.ts +3 -3
  43. package/dist/source/public_private_match.js +36 -36
  44. package/dist/source/subject.d.ts +27 -0
  45. package/dist/source/subject.js +125 -0
  46. package/dist/source/subject.js.map +1 -0
  47. package/dist/source/verify_certificate_signature.d.ts +10 -10
  48. package/dist/source/verify_certificate_signature.js +101 -101
  49. package/dist/source/x509/_build_public_key.d.ts +1 -0
  50. package/dist/source/x509/_build_public_key.js +36 -0
  51. package/dist/source/x509/_build_public_key.js.map +1 -0
  52. package/dist/source/x509/_crypto.d.ts +3 -0
  53. package/dist/source/x509/_crypto.js +9 -0
  54. package/dist/source/x509/_crypto.js.map +1 -0
  55. package/dist/source/x509/_fix.d.ts +2 -0
  56. package/dist/source/x509/_fix.js +74 -0
  57. package/dist/source/x509/_fix.js.map +1 -0
  58. package/dist/source/x509/_get_attributes.d.ts +8 -0
  59. package/dist/source/x509/_get_attributes.js +56 -0
  60. package/dist/source/x509/_get_attributes.js.map +1 -0
  61. package/dist/source/x509/_internals.d.ts +0 -0
  62. package/dist/source/x509/_internals.js +2 -0
  63. package/dist/source/x509/_internals.js.map +1 -0
  64. package/dist/source/x509/create_certificate_signing_request.d.ts +18 -0
  65. package/dist/source/x509/create_certificate_signing_request.js +53 -0
  66. package/dist/source/x509/create_certificate_signing_request.js.map +1 -0
  67. package/dist/source/x509/create_key_pair.d.ts +28 -0
  68. package/dist/source/x509/create_key_pair.js +62 -0
  69. package/dist/source/x509/create_key_pair.js.map +1 -0
  70. package/dist/source/x509/create_self_signed_certificate.d.ts +17 -0
  71. package/dist/source/x509/create_self_signed_certificate.js +71 -0
  72. package/dist/source/x509/create_self_signed_certificate.js.map +1 -0
  73. package/dist/source_nodejs/generate_private_key_filename.d.ts +1 -0
  74. package/dist/source_nodejs/generate_private_key_filename.js +25 -0
  75. package/dist/source_nodejs/generate_private_key_filename.js.map +1 -0
  76. package/dist/source_nodejs/index.d.ts +4 -3
  77. package/dist/source_nodejs/index.js +20 -19
  78. package/dist/source_nodejs/index.js.map +1 -1
  79. package/dist/source_nodejs/read.d.ts +23 -23
  80. package/dist/source_nodejs/read.js +106 -106
  81. package/dist/source_nodejs/read_certificate_revocation_list.d.ts +2 -2
  82. package/dist/source_nodejs/read_certificate_revocation_list.js +27 -27
  83. package/dist/source_nodejs/read_certificate_signing_request.d.ts +3 -3
  84. package/dist/source_nodejs/read_certificate_signing_request.js +27 -27
  85. package/index.d.ts +2 -2
  86. package/index.js +4 -4
  87. package/index_web.js +3 -3
  88. package/package.json +15 -9
  89. package/source/asn1.ts +404 -404
  90. package/source/buffer_utils.ts +18 -18
  91. package/source/common.ts +7 -0
  92. package/source/crypto_explore_certificate.ts +764 -764
  93. package/source/derived_keys.ts +287 -287
  94. package/source/explore_certificate.ts +66 -66
  95. package/source/explore_certificate_revocation_list.ts +122 -122
  96. package/source/explore_certificate_signing_request.ts +58 -58
  97. package/source/explore_private_key.ts +1 -2
  98. package/source/index.ts +17 -13
  99. package/source/oid_map.ts +310 -310
  100. package/source/subject.ts +144 -0
  101. package/source/verify_certificate_signature.ts +105 -105
  102. package/source/x509/_build_public_key.ts +25 -0
  103. package/source/x509/_crypto.ts +5 -0
  104. package/source/x509/_get_attributes.ts +60 -0
  105. package/source/x509/create_certificate_signing_request.ts +64 -0
  106. package/source/x509/create_key_pair.ts +70 -0
  107. package/source/x509/create_self_signed_certificate.ts +91 -0
  108. package/source_nodejs/generate_private_key_filename.ts +10 -0
  109. package/source_nodejs/index.ts +4 -3
  110. package/source_nodejs/read_certificate_revocation_list.ts +14 -14
  111. package/source_nodejs/read_certificate_signing_request.ts +17 -17
  112. package/test_certificate.ts +34 -34
  113. package/tsconfig.json +19 -18
  114. package/tslint.json +34 -34
  115. package/dist/source/certificate_matches_private_key.d.ts +0 -2
  116. package/dist/source/certificate_matches_private_key.js +0 -22
  117. package/dist/source/certificate_matches_private_key.js.map +0 -1
@@ -0,0 +1,10 @@
1
+ import * as fs from "fs";
2
+ import { generateKeyPair, privateKeyToPEM } from "../source";
3
+
4
+ export async function generatePrivateKeyFile(privateKeyFilename: string, modulusLength: 1024 |2048| 3072| 4096) {
5
+ const keys = await generateKeyPair(modulusLength);
6
+ const privateKeyPem = await privateKeyToPEM(keys.privateKey);
7
+ await fs.promises.writeFile(privateKeyFilename, privateKeyPem.privPem);
8
+ privateKeyPem.privPem = "";
9
+ privateKeyPem.privDer = new Uint8Array(0);
10
+ }
@@ -1,3 +1,4 @@
1
- export * from "./read";
2
- export * from "./read_certificate_revocation_list";
3
- export * from "./read_certificate_signing_request";
1
+ export * from "./read";
2
+ export * from "./read_certificate_revocation_list";
3
+ export * from "./read_certificate_signing_request";
4
+ export * from "./generate_private_key_filename";
@@ -1,14 +1,14 @@
1
- import * as fs from "fs";
2
- import { promisify } from "util";
3
- import { convertPEMtoDER } from "../source/crypto_utils";
4
- import { CertificateRevocationList } from "../source/common";
5
-
6
- export async function readCertificateRevocationList(filename: string): Promise<CertificateRevocationList> {
7
- const crl = await promisify(fs.readFile)(filename);
8
- if (crl[0] === 0x30 && crl[1] === 0x82) {
9
- // der format
10
- return crl as CertificateRevocationList;
11
- }
12
- const raw_crl = crl.toString();
13
- return convertPEMtoDER(raw_crl);
14
- }
1
+ import * as fs from "fs";
2
+ import { promisify } from "util";
3
+ import { convertPEMtoDER } from "../source/crypto_utils";
4
+ import { CertificateRevocationList } from "../source/common";
5
+
6
+ export async function readCertificateRevocationList(filename: string): Promise<CertificateRevocationList> {
7
+ const crl = await promisify(fs.readFile)(filename);
8
+ if (crl[0] === 0x30 && crl[1] === 0x82) {
9
+ // der format
10
+ return crl as CertificateRevocationList;
11
+ }
12
+ const raw_crl = crl.toString();
13
+ return convertPEMtoDER(raw_crl);
14
+ }
@@ -1,17 +1,17 @@
1
- import * as fs from "fs";
2
- import { promisify } from "util";
3
- import { convertPEMtoDER } from "../source/crypto_utils";
4
- import { CertificateRevocationList } from "../source/common";
5
- import { assert } from "console";
6
-
7
- export type CertificateSigningRequest = Buffer;
8
-
9
- export async function readCertificateSigningRequest(filename: string): Promise<CertificateSigningRequest> {
10
- const csr = await promisify(fs.readFile)(filename);
11
- if (csr[0] === 0x30 && csr[1] === 0x82) {
12
- // der format
13
- return csr as CertificateRevocationList;
14
- }
15
- const raw_crl = csr.toString();
16
- return convertPEMtoDER(raw_crl);
17
- }
1
+ import * as fs from "fs";
2
+ import { promisify } from "util";
3
+ import { convertPEMtoDER } from "../source/crypto_utils";
4
+ import { CertificateRevocationList } from "../source/common";
5
+ import { assert } from "console";
6
+
7
+ export type CertificateSigningRequest = Buffer;
8
+
9
+ export async function readCertificateSigningRequest(filename: string): Promise<CertificateSigningRequest> {
10
+ const csr = await promisify(fs.readFile)(filename);
11
+ if (csr[0] === 0x30 && csr[1] === 0x82) {
12
+ // der format
13
+ return csr as CertificateRevocationList;
14
+ }
15
+ const raw_crl = csr.toString();
16
+ return convertPEMtoDER(raw_crl);
17
+ }
@@ -1,34 +1,34 @@
1
- // tslint:disable: no-console
2
- import * as fs from "fs";
3
- import { exploreCertificate, readCertificate } from ".";
4
-
5
- async function testCertificate(filename: string): Promise<void> {
6
- const cert1 = await readCertificate(filename);
7
- try {
8
- const info = exploreCertificate(cert1);
9
- // console.log(info);
10
- } catch (err) {
11
- console.log(filename, "err = ", err.message);
12
- }
13
- }
14
- async function testCertificate1(filename: string): Promise<void> {
15
- const cert1 = fs.readFileSync(filename);
16
- try {
17
- const info = exploreCertificate(cert1);
18
- // console.log(info);
19
- } catch (err) {
20
- console.log(filename, "err = ", err.message);
21
- console.log(err);
22
- throw err;
23
- }
24
- }
25
-
26
- (async () => {
27
- try {
28
- testCertificate1("./read.cer");
29
- testCertificate1("./unsol.cer");
30
- testCertificate1("./write.cer");
31
- } catch (err) {
32
- console.log("???? ERR !!!! ", err.message);
33
- }
34
- })();
1
+ // tslint:disable: no-console
2
+ import * as fs from "fs";
3
+ import { exploreCertificate, readCertificate } from ".";
4
+
5
+ async function testCertificate(filename: string): Promise<void> {
6
+ const cert1 = await readCertificate(filename);
7
+ try {
8
+ const info = exploreCertificate(cert1);
9
+ // console.log(info);
10
+ } catch (err) {
11
+ console.log(filename, "err = ", err.message);
12
+ }
13
+ }
14
+ async function testCertificate1(filename: string): Promise<void> {
15
+ const cert1 = fs.readFileSync(filename);
16
+ try {
17
+ const info = exploreCertificate(cert1);
18
+ // console.log(info);
19
+ } catch (err) {
20
+ console.log(filename, "err = ", err.message);
21
+ console.log(err);
22
+ throw err;
23
+ }
24
+ }
25
+
26
+ (async () => {
27
+ try {
28
+ testCertificate1("./read.cer");
29
+ testCertificate1("./unsol.cer");
30
+ testCertificate1("./write.cer");
31
+ } catch (err) {
32
+ console.log("???? ERR !!!! ", err.message);
33
+ }
34
+ })();
package/tsconfig.json CHANGED
@@ -1,18 +1,19 @@
1
- {
2
- "compilerOptions": {
3
- "skipLibCheck": true,
4
- "target": "es6",
5
- "moduleResolution": "node",
6
- "module": "commonjs",
7
- "declaration": true,
8
- "outDir": "./dist",
9
- "sourceMap": true,
10
- "strict": true,
11
- "listFiles": false,
12
- "traceResolution": false,
13
- "incremental": true,
14
- "types": ["node", "mocha", "should"],
15
- "rootDir": "."
16
- },
17
- "files": ["source/index.ts", "source_nodejs/index.ts"]
18
- }
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "target": "es6",
6
+ "moduleResolution": "node",
7
+ "module": "commonjs",
8
+ "declaration": true,
9
+ "outDir": "./dist",
10
+ "sourceMap": true,
11
+ "strict": true,
12
+ "listFiles": false,
13
+ "traceResolution": false,
14
+ "incremental": true,
15
+ "types": ["node", "mocha", "should"],
16
+ "rootDir": "."
17
+ },
18
+ "include": ["./source/*.ts", "./source_nodejs/*.ts", "source/x509/*.ts" ]
19
+ }
package/tslint.json CHANGED
@@ -1,35 +1,35 @@
1
- {
2
- "extends": [
3
- "tslint:recommended",
4
- "tslint-config-prettier"
5
- ],
6
- "jsRules": {},
7
- "rules": {
8
- "interface-name": [
9
- false,
10
- "never-prefix"
11
- ],
12
- "interface-over-type-literal": true,
13
- "variable-name": [
14
- true,
15
- "ban-keywords",
16
- "allow-leading-underscore"
17
- ],
18
- "trailing-comma": [
19
- false
20
- ],
21
- "object-literal-sort-keys": false,
22
- "comment-format": [
23
- false
24
- ],
25
- "no-var-requires": false,
26
- "max-line-length": [
27
- false,
28
- 120
29
- ],
30
- "one-variable-per-declaration": [
31
- false
32
- ]
33
- },
34
- "rulesDirectory": []
1
+ {
2
+ "extends": [
3
+ "tslint:recommended",
4
+ "tslint-config-prettier"
5
+ ],
6
+ "jsRules": {},
7
+ "rules": {
8
+ "interface-name": [
9
+ false,
10
+ "never-prefix"
11
+ ],
12
+ "interface-over-type-literal": true,
13
+ "variable-name": [
14
+ true,
15
+ "ban-keywords",
16
+ "allow-leading-underscore"
17
+ ],
18
+ "trailing-comma": [
19
+ false
20
+ ],
21
+ "object-literal-sort-keys": false,
22
+ "comment-format": [
23
+ false
24
+ ],
25
+ "no-var-requires": false,
26
+ "max-line-length": [
27
+ false,
28
+ 120
29
+ ],
30
+ "one-variable-per-declaration": [
31
+ false
32
+ ]
33
+ },
34
+ "rulesDirectory": []
35
35
  }
@@ -1,2 +0,0 @@
1
- import { Certificate, PrivateKey } from "./common";
2
- export declare function certificateMatchesPrivateKey(certificate: Certificate, privateKey: PrivateKey): boolean;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.certificateMatchesPrivateKey = void 0;
4
- const crypto_utils_1 = require("./crypto_utils");
5
- /**
6
- * check that the given certificate matches the given private key
7
- * @param certificate
8
- * @param privateKey
9
- */
10
- function certificateMatchesPrivateKeyPEM(certificate, privateKey) {
11
- const initialBuffer = Buffer.from("Lorem Ipsum");
12
- const encryptedBuffer = (0, crypto_utils_1.publicEncrypt_long)(initialBuffer, certificate, 256, 11);
13
- const decryptedBuffer = (0, crypto_utils_1.privateDecrypt_long)(encryptedBuffer, privateKey, 256);
14
- return initialBuffer.toString("utf-8") === decryptedBuffer.toString("utf-8");
15
- }
16
- function certificateMatchesPrivateKey(certificate, privateKey) {
17
- const certificatePEM = (0, crypto_utils_1.toPem)(certificate, "CERTIFICATE");
18
- const privateKeyPEM = (0, crypto_utils_1.toPem)(privateKey, "RSA PRIVATE KEY");
19
- return certificateMatchesPrivateKeyPEM(certificatePEM, privateKeyPEM);
20
- }
21
- exports.certificateMatchesPrivateKey = certificateMatchesPrivateKey;
22
- //# sourceMappingURL=certificate_matches_private_key.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"certificate_matches_private_key.js","sourceRoot":"","sources":["../../source/certificate_matches_private_key.ts"],"names":[],"mappings":";;;AACA,iDAAgF;AAEhF;;;;GAIG;AACH,SAAS,+BAA+B,CAAC,WAA2B,EAAE,UAAyB;IAC3F,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACjD,MAAM,eAAe,GAAG,IAAA,iCAAkB,EAAC,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IAChF,MAAM,eAAe,GAAG,IAAA,kCAAmB,EAAC,eAAe,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAC9E,OAAO,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACjF,CAAC;AAED,SAAgB,4BAA4B,CAAC,WAAwB,EAAE,UAAsB;IACzF,MAAM,cAAc,GAAG,IAAA,oBAAK,EAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IACzD,MAAM,aAAa,GAAG,IAAA,oBAAK,EAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IAC3D,OAAO,+BAA+B,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;AAC1E,CAAC;AAJD,oEAIC"}