node-opcua-crypto 2.1.1 → 2.2.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 +106 -106
- package/.prettierrc.js +6 -6
- package/LICENSE +23 -23
- package/README.md +14 -14
- package/dist/source/asn1.d.ts +73 -73
- package/dist/source/asn1.js +359 -359
- package/dist/source/buffer_utils.d.ts +6 -6
- package/dist/source/buffer_utils.js +21 -21
- package/dist/source/common.d.ts +14 -14
- package/dist/source/common.js +2 -2
- 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/crypto_utils.js.map +1 -1
- 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 +97 -97
- package/dist/source/index.d.ts +13 -13
- package/dist/source/index.js +29 -29
- 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/verify_certificate_signature.d.ts +10 -10
- package/dist/source/verify_certificate_signature.js +101 -101
- package/dist/source_nodejs/index.d.ts +3 -3
- package/dist/source_nodejs/index.js +19 -19
- 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 +9 -9
- package/source/asn1.ts +404 -404
- package/source/buffer_utils.ts +18 -18
- package/source/crypto_explore_certificate.ts +764 -764
- package/source/crypto_utils.ts +1 -1
- 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/index.ts +13 -13
- package/source/oid_map.ts +310 -310
- package/source/verify_certificate_signature.ts +105 -105
- package/source_nodejs/index.ts +2 -2
- 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 +18 -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
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
// tslint:disable: no-console
|
|
2
|
-
|
|
3
|
-
// Now that we got a hash of the original certificate,
|
|
4
|
-
// we need to verify if we can obtain the same hash by using the same hashing function
|
|
5
|
-
// (in this case SHA-384). In order to do that, we need to extract just the body of
|
|
6
|
-
// the signed certificate. Which, in our case, is everything but the signature.
|
|
7
|
-
// The start of the body is always the first digit of the second line of the following command:
|
|
8
|
-
import * as crypto from "crypto";
|
|
9
|
-
|
|
10
|
-
import { Certificate, PrivateKey } from "./common";
|
|
11
|
-
import { split_der, exploreCertificate } from "./crypto_explore_certificate";
|
|
12
|
-
import { toPem } from "./crypto_utils";
|
|
13
|
-
import { _readAlgorithmIdentifier, _readSignatureValueBin, TagType, readTag, _readStruct, _getBlock } from "./asn1";
|
|
14
|
-
|
|
15
|
-
export function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean {
|
|
16
|
-
const block_info = readTag(certificateOrCrl, 0);
|
|
17
|
-
const blocks = _readStruct(certificateOrCrl, block_info);
|
|
18
|
-
const bufferToBeSigned = certificateOrCrl.slice(block_info.position, blocks[1].position - 2);
|
|
19
|
-
|
|
20
|
-
//xx console.log("bufferToBeSigned = ", bufferToBeSigned.length, bufferToBeSigned.toString("hex").substr(0, 50), bufferToBeSigned.toString("hex").substr(-10));
|
|
21
|
-
const signatureAlgorithm = _readAlgorithmIdentifier(certificateOrCrl, blocks[1]);
|
|
22
|
-
const signatureValue = _readSignatureValueBin(certificateOrCrl, blocks[2]);
|
|
23
|
-
|
|
24
|
-
const p = split_der(parentCertificate)[0];
|
|
25
|
-
//xx const publicKey = extractPublicKeyFromCertificateSync(p);
|
|
26
|
-
const certPem = toPem(p, "CERTIFICATE");
|
|
27
|
-
const verify = crypto.createVerify(signatureAlgorithm.identifier);
|
|
28
|
-
verify.update(bufferToBeSigned);
|
|
29
|
-
verify.end();
|
|
30
|
-
return verify.verify(certPem, signatureValue);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean {
|
|
34
|
-
return verifyCertificateOrClrSignature(certificate, parentCertificate);
|
|
35
|
-
}
|
|
36
|
-
export function verifyCertificateRevocationListSignature(
|
|
37
|
-
certificateRevocationList: Certificate,
|
|
38
|
-
parentCertificate: Certificate
|
|
39
|
-
): boolean {
|
|
40
|
-
return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
|
|
44
|
-
export async function verifyCertificateChain(certificateChain: Certificate[]): Promise<{ status: _VerifyStatus; reason: string }> {
|
|
45
|
-
// verify that all the certificate
|
|
46
|
-
// second certificate must be used for CertificateSign
|
|
47
|
-
|
|
48
|
-
for (let index = 1; index < certificateChain.length; index++) {
|
|
49
|
-
const cert = certificateChain[index - 1];
|
|
50
|
-
const certParent = certificateChain[index];
|
|
51
|
-
|
|
52
|
-
// parent child must have keyCertSign
|
|
53
|
-
const certParentInfo = exploreCertificate(certParent);
|
|
54
|
-
const keyUsage = certParentInfo.tbsCertificate.extensions!.keyUsage!;
|
|
55
|
-
|
|
56
|
-
// istanbul ignore next
|
|
57
|
-
if (!keyUsage.keyCertSign) {
|
|
58
|
-
return {
|
|
59
|
-
status: "BadCertificateIssuerUseNotAllowed",
|
|
60
|
-
reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing",
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const parentSignChild = verifyCertificateSignature(cert, certParent);
|
|
65
|
-
if (!parentSignChild) {
|
|
66
|
-
return {
|
|
67
|
-
status: "BadCertificateInvalid",
|
|
68
|
-
reason: "One of the certificate in the chain is not signing the previous certificate",
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
const certInfo = exploreCertificate(cert);
|
|
72
|
-
|
|
73
|
-
// istanbul ignore next
|
|
74
|
-
if (!certInfo.tbsCertificate.extensions) {
|
|
75
|
-
return {
|
|
76
|
-
status: "BadCertificateInvalid",
|
|
77
|
-
reason: "Cannot find X409 Extension 3 in certificate",
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// istanbul ignore next
|
|
82
|
-
if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
|
|
83
|
-
return {
|
|
84
|
-
status: "BadCertificateInvalid",
|
|
85
|
-
reason: "Cannot find X409 Extension 3 in certificate (parent)",
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// istanbul ignore next
|
|
90
|
-
if (
|
|
91
|
-
certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !==
|
|
92
|
-
certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier
|
|
93
|
-
) {
|
|
94
|
-
return {
|
|
95
|
-
status: "BadCertificateInvalid",
|
|
96
|
-
reason:
|
|
97
|
-
"subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate",
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
status: "Good",
|
|
103
|
-
reason: `certificate chain is valid(length = ${certificateChain.length})`,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
1
|
+
// tslint:disable: no-console
|
|
2
|
+
|
|
3
|
+
// Now that we got a hash of the original certificate,
|
|
4
|
+
// we need to verify if we can obtain the same hash by using the same hashing function
|
|
5
|
+
// (in this case SHA-384). In order to do that, we need to extract just the body of
|
|
6
|
+
// the signed certificate. Which, in our case, is everything but the signature.
|
|
7
|
+
// The start of the body is always the first digit of the second line of the following command:
|
|
8
|
+
import * as crypto from "crypto";
|
|
9
|
+
|
|
10
|
+
import { Certificate, PrivateKey } from "./common";
|
|
11
|
+
import { split_der, exploreCertificate } from "./crypto_explore_certificate";
|
|
12
|
+
import { toPem } from "./crypto_utils";
|
|
13
|
+
import { _readAlgorithmIdentifier, _readSignatureValueBin, TagType, readTag, _readStruct, _getBlock } from "./asn1";
|
|
14
|
+
|
|
15
|
+
export function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean {
|
|
16
|
+
const block_info = readTag(certificateOrCrl, 0);
|
|
17
|
+
const blocks = _readStruct(certificateOrCrl, block_info);
|
|
18
|
+
const bufferToBeSigned = certificateOrCrl.slice(block_info.position, blocks[1].position - 2);
|
|
19
|
+
|
|
20
|
+
//xx console.log("bufferToBeSigned = ", bufferToBeSigned.length, bufferToBeSigned.toString("hex").substr(0, 50), bufferToBeSigned.toString("hex").substr(-10));
|
|
21
|
+
const signatureAlgorithm = _readAlgorithmIdentifier(certificateOrCrl, blocks[1]);
|
|
22
|
+
const signatureValue = _readSignatureValueBin(certificateOrCrl, blocks[2]);
|
|
23
|
+
|
|
24
|
+
const p = split_der(parentCertificate)[0];
|
|
25
|
+
//xx const publicKey = extractPublicKeyFromCertificateSync(p);
|
|
26
|
+
const certPem = toPem(p, "CERTIFICATE");
|
|
27
|
+
const verify = crypto.createVerify(signatureAlgorithm.identifier);
|
|
28
|
+
verify.update(bufferToBeSigned);
|
|
29
|
+
verify.end();
|
|
30
|
+
return verify.verify(certPem, signatureValue);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean {
|
|
34
|
+
return verifyCertificateOrClrSignature(certificate, parentCertificate);
|
|
35
|
+
}
|
|
36
|
+
export function verifyCertificateRevocationListSignature(
|
|
37
|
+
certificateRevocationList: Certificate,
|
|
38
|
+
parentCertificate: Certificate
|
|
39
|
+
): boolean {
|
|
40
|
+
return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
|
|
44
|
+
export async function verifyCertificateChain(certificateChain: Certificate[]): Promise<{ status: _VerifyStatus; reason: string }> {
|
|
45
|
+
// verify that all the certificate
|
|
46
|
+
// second certificate must be used for CertificateSign
|
|
47
|
+
|
|
48
|
+
for (let index = 1; index < certificateChain.length; index++) {
|
|
49
|
+
const cert = certificateChain[index - 1];
|
|
50
|
+
const certParent = certificateChain[index];
|
|
51
|
+
|
|
52
|
+
// parent child must have keyCertSign
|
|
53
|
+
const certParentInfo = exploreCertificate(certParent);
|
|
54
|
+
const keyUsage = certParentInfo.tbsCertificate.extensions!.keyUsage!;
|
|
55
|
+
|
|
56
|
+
// istanbul ignore next
|
|
57
|
+
if (!keyUsage.keyCertSign) {
|
|
58
|
+
return {
|
|
59
|
+
status: "BadCertificateIssuerUseNotAllowed",
|
|
60
|
+
reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing",
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const parentSignChild = verifyCertificateSignature(cert, certParent);
|
|
65
|
+
if (!parentSignChild) {
|
|
66
|
+
return {
|
|
67
|
+
status: "BadCertificateInvalid",
|
|
68
|
+
reason: "One of the certificate in the chain is not signing the previous certificate",
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const certInfo = exploreCertificate(cert);
|
|
72
|
+
|
|
73
|
+
// istanbul ignore next
|
|
74
|
+
if (!certInfo.tbsCertificate.extensions) {
|
|
75
|
+
return {
|
|
76
|
+
status: "BadCertificateInvalid",
|
|
77
|
+
reason: "Cannot find X409 Extension 3 in certificate",
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// istanbul ignore next
|
|
82
|
+
if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
|
|
83
|
+
return {
|
|
84
|
+
status: "BadCertificateInvalid",
|
|
85
|
+
reason: "Cannot find X409 Extension 3 in certificate (parent)",
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// istanbul ignore next
|
|
90
|
+
if (
|
|
91
|
+
certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !==
|
|
92
|
+
certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier
|
|
93
|
+
) {
|
|
94
|
+
return {
|
|
95
|
+
status: "BadCertificateInvalid",
|
|
96
|
+
reason:
|
|
97
|
+
"subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate",
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
status: "Good",
|
|
103
|
+
reason: `certificate chain is valid(length = ${certificateChain.length})`,
|
|
104
|
+
};
|
|
105
|
+
}
|
package/source_nodejs/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./read";
|
|
2
|
-
export * from "./read_certificate_revocation_list";
|
|
1
|
+
export * from "./read";
|
|
2
|
+
export * from "./read_certificate_revocation_list";
|
|
3
3
|
export * from "./read_certificate_signing_request";
|
|
@@ -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,18 @@
|
|
|
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
|
+
"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
|
+
}
|
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"}
|