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.
- package/.fossa.yml +18 -18
- package/.github/FUNDING.yml +12 -12
- package/.github/workflows/main.yml +109 -106
- package/.prettierrc.js +6 -6
- package/LICENSE +23 -23
- package/README.md +14 -14
- package/_tmp_certificate.pem +20 -0
- package/_tmp_csr.pem +17 -0
- package/_tmp_privatekey.der +0 -0
- package/_tmp_privatekey.pem +28 -0
- package/dist/source/asn1.d.ts +73 -73
- package/dist/source/asn1.js +359 -359
- package/dist/source/asn1.js.map +1 -1
- package/dist/source/buffer_utils.d.ts +5 -6
- package/dist/source/buffer_utils.js +21 -21
- package/dist/source/common.d.ts +20 -14
- package/dist/source/common.js +10 -2
- package/dist/source/common.js.map +1 -1
- package/dist/source/create_key_pair.d.ts +42 -0
- package/dist/source/create_key_pair.js +136 -0
- package/dist/source/create_key_pair.js.map +1 -0
- package/dist/source/crypto_explore_certificate.d.ts +107 -107
- package/dist/source/crypto_explore_certificate.js +601 -601
- package/dist/source/crypto_utils.d.ts +76 -76
- package/dist/source/crypto_utils.js +329 -329
- package/dist/source/derived_keys.d.ts +72 -72
- package/dist/source/derived_keys.js +248 -248
- package/dist/source/explore_certificate.d.ts +30 -30
- package/dist/source/explore_certificate.js +43 -43
- package/dist/source/explore_certificate_revocation_list.d.ts +28 -28
- package/dist/source/explore_certificate_revocation_list.js +69 -69
- package/dist/source/explore_certificate_signing_request.d.ts +13 -13
- package/dist/source/explore_certificate_signing_request.js +44 -44
- package/dist/source/explore_private_key.d.ts +29 -29
- package/dist/source/explore_private_key.js +95 -97
- package/dist/source/explore_private_key.js.map +1 -1
- package/dist/source/index.d.ts +17 -13
- package/dist/source/index.js +33 -29
- package/dist/source/index.js.map +1 -1
- package/dist/source/oid_map.d.ts +7 -7
- package/dist/source/oid_map.js +303 -303
- package/dist/source/public_private_match.d.ts +3 -3
- package/dist/source/public_private_match.js +36 -36
- package/dist/source/subject.d.ts +27 -0
- package/dist/source/subject.js +125 -0
- package/dist/source/subject.js.map +1 -0
- package/dist/source/verify_certificate_signature.d.ts +10 -10
- package/dist/source/verify_certificate_signature.js +101 -101
- package/dist/source/x509/_build_public_key.d.ts +1 -0
- package/dist/source/x509/_build_public_key.js +36 -0
- package/dist/source/x509/_build_public_key.js.map +1 -0
- package/dist/source/x509/_crypto.d.ts +3 -0
- package/dist/source/x509/_crypto.js +9 -0
- package/dist/source/x509/_crypto.js.map +1 -0
- package/dist/source/x509/_fix.d.ts +2 -0
- package/dist/source/x509/_fix.js +74 -0
- package/dist/source/x509/_fix.js.map +1 -0
- package/dist/source/x509/_get_attributes.d.ts +8 -0
- package/dist/source/x509/_get_attributes.js +56 -0
- package/dist/source/x509/_get_attributes.js.map +1 -0
- package/dist/source/x509/_internals.d.ts +0 -0
- package/dist/source/x509/_internals.js +2 -0
- package/dist/source/x509/_internals.js.map +1 -0
- package/dist/source/x509/create_certificate_signing_request.d.ts +18 -0
- package/dist/source/x509/create_certificate_signing_request.js +53 -0
- package/dist/source/x509/create_certificate_signing_request.js.map +1 -0
- package/dist/source/x509/create_key_pair.d.ts +28 -0
- package/dist/source/x509/create_key_pair.js +62 -0
- package/dist/source/x509/create_key_pair.js.map +1 -0
- package/dist/source/x509/create_self_signed_certificate.d.ts +17 -0
- package/dist/source/x509/create_self_signed_certificate.js +71 -0
- package/dist/source/x509/create_self_signed_certificate.js.map +1 -0
- package/dist/source_nodejs/generate_private_key_filename.d.ts +1 -0
- package/dist/source_nodejs/generate_private_key_filename.js +25 -0
- package/dist/source_nodejs/generate_private_key_filename.js.map +1 -0
- package/dist/source_nodejs/index.d.ts +4 -3
- package/dist/source_nodejs/index.js +20 -19
- package/dist/source_nodejs/index.js.map +1 -1
- package/dist/source_nodejs/read.d.ts +23 -23
- package/dist/source_nodejs/read.js +106 -106
- package/dist/source_nodejs/read_certificate_revocation_list.d.ts +2 -2
- package/dist/source_nodejs/read_certificate_revocation_list.js +27 -27
- package/dist/source_nodejs/read_certificate_signing_request.d.ts +3 -3
- package/dist/source_nodejs/read_certificate_signing_request.js +27 -27
- package/index.d.ts +2 -2
- package/index.js +4 -4
- package/index_web.js +3 -3
- package/package.json +15 -9
- package/source/asn1.ts +404 -404
- package/source/buffer_utils.ts +18 -18
- package/source/common.ts +7 -0
- package/source/crypto_explore_certificate.ts +764 -764
- package/source/derived_keys.ts +287 -287
- package/source/explore_certificate.ts +66 -66
- package/source/explore_certificate_revocation_list.ts +122 -122
- package/source/explore_certificate_signing_request.ts +58 -58
- package/source/explore_private_key.ts +1 -2
- package/source/index.ts +17 -13
- package/source/oid_map.ts +310 -310
- package/source/subject.ts +144 -0
- package/source/verify_certificate_signature.ts +105 -105
- package/source/x509/_build_public_key.ts +25 -0
- package/source/x509/_crypto.ts +5 -0
- package/source/x509/_get_attributes.ts +60 -0
- package/source/x509/create_certificate_signing_request.ts +64 -0
- package/source/x509/create_key_pair.ts +70 -0
- package/source/x509/create_self_signed_certificate.ts +91 -0
- package/source_nodejs/generate_private_key_filename.ts +10 -0
- package/source_nodejs/index.ts +4 -3
- package/source_nodejs/read_certificate_revocation_list.ts +14 -14
- package/source_nodejs/read_certificate_signing_request.ts +17 -17
- package/test_certificate.ts +34 -34
- package/tsconfig.json +19 -18
- package/tslint.json +34 -34
- package/dist/source/certificate_matches_private_key.d.ts +0 -2
- package/dist/source/certificate_matches_private_key.js +0 -22
- 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
|
+
}
|
package/source_nodejs/index.ts
CHANGED
|
@@ -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
|
+
}
|
package/test_certificate.ts
CHANGED
|
@@ -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
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
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,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"}
|