node-opcua-crypto 1.7.4 → 1.9.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 +32 -32
- package/.prettierrc.js +6 -6
- package/LICENSE +22 -22
- package/README.md +14 -14
- package/dist/asn1.d.ts +69 -0
- package/dist/asn1.js +349 -0
- package/dist/asn1.js.map +1 -0
- package/dist/buffer_utils.d.ts +6 -0
- package/dist/buffer_utils.js +22 -0
- package/dist/buffer_utils.js.map +1 -0
- package/dist/common.d.ts +11 -0
- package/dist/common.js +3 -0
- package/dist/common.js.map +1 -0
- package/dist/crypto_explore_certificate.d.ts +95 -0
- package/dist/crypto_explore_certificate.js +547 -0
- package/dist/crypto_explore_certificate.js.map +1 -0
- package/dist/crypto_utils.d.ts +106 -0
- package/dist/crypto_utils.js +370 -0
- package/dist/crypto_utils.js.map +1 -0
- package/dist/derived_keys.d.ts +72 -0
- package/dist/derived_keys.js +247 -0
- package/dist/derived_keys.js.map +1 -0
- package/dist/explore_certificate.d.ts +30 -0
- package/dist/explore_certificate.js +44 -0
- package/dist/explore_certificate.js.map +1 -0
- package/dist/explore_certificate_revocation_list.d.ts +30 -0
- package/dist/explore_certificate_revocation_list.js +67 -0
- package/dist/explore_certificate_revocation_list.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/oid_map.d.ts +7 -0
- package/dist/oid_map.js +262 -0
- package/dist/oid_map.js.map +1 -0
- package/dist/source/asn1.d.ts +73 -73
- package/dist/source/asn1.js +359 -359
- package/dist/source/buffer_utils.d.ts +6 -5
- package/dist/source/buffer_utils.js +21 -21
- package/dist/source/common.d.ts +12 -12
- package/dist/source/common.js +2 -2
- package/dist/source/crypto_explore_certificate.d.ts +107 -107
- package/dist/source/crypto_explore_certificate.js +600 -600
- package/dist/source/crypto_utils.d.ts +78 -78
- package/dist/source/crypto_utils.js +280 -280
- package/dist/source/derived_keys.d.ts +72 -72
- package/dist/source/derived_keys.js +248 -245
- package/dist/source/derived_keys.js.map +1 -1
- 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 +44 -44
- 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 +96 -96
- package/dist/source/index.d.ts +13 -13
- package/dist/source/index.js +25 -25
- 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 +16 -16
- 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 +15 -15
- package/dist/source_nodejs/read.d.ts +29 -29
- package/dist/source_nodejs/read.js +94 -94
- 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/dist/verify_cerficate_signature.d.ts +10 -0
- package/dist/verify_cerficate_signature.js +102 -0
- package/dist/verify_cerficate_signature.js.map +1 -0
- package/index.d.ts +2 -2
- package/index.js +4 -4
- package/index_web.js +3 -3
- package/package.json +17 -17
- package/source/asn1.ts +404 -404
- package/source/buffer_utils.ts +18 -18
- package/source/common.ts +13 -13
- package/source/crypto_explore_certificate.ts +763 -763
- package/source/crypto_utils.ts +321 -321
- package/source/derived_keys.ts +287 -284
- package/source/explore_certificate.ts +66 -66
- package/source/explore_certificate_revocation_list.ts +93 -93
- package/source/explore_certificate_signing_request.ts +58 -58
- package/source/explore_private_key.ts +121 -121
- package/source/index.ts +13 -13
- package/source/oid_map.ts +310 -310
- package/source/public_private_match.ts +17 -17
- package/source/verify_certificate_signature.ts +105 -105
- package/source_nodejs/index.ts +2 -2
- package/source_nodejs/read.ts +95 -95
- 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/pnpm-lock.yaml +0 -1689
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Certificate } from "./common";
|
|
2
|
-
import { PrivateKey } from "./common";
|
|
3
|
-
export declare function publicKeyAndPrivateKeyMatches(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
1
|
+
import { Certificate } from "./common";
|
|
2
|
+
import { PrivateKey } from "./common";
|
|
3
|
+
export declare function publicKeyAndPrivateKeyMatches(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publicKeyAndPrivateKeyMatches = void 0;
|
|
4
|
-
const _1 = require(".");
|
|
5
|
-
const explore_private_key_1 = require("./explore_private_key");
|
|
6
|
-
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
7
|
-
const i = (0, _1.exploreCertificate)(certificate);
|
|
8
|
-
const j = (0, explore_private_key_1.explorePrivateKey)(privateKey);
|
|
9
|
-
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
10
|
-
const modulus2 = j.modulus;
|
|
11
|
-
if (modulus1.length != modulus2.length) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
15
|
-
}
|
|
16
|
-
exports.publicKeyAndPrivateKeyMatches = publicKeyAndPrivateKeyMatches;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.publicKeyAndPrivateKeyMatches = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const explore_private_key_1 = require("./explore_private_key");
|
|
6
|
+
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
7
|
+
const i = (0, _1.exploreCertificate)(certificate);
|
|
8
|
+
const j = (0, explore_private_key_1.explorePrivateKey)(privateKey);
|
|
9
|
+
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
10
|
+
const modulus2 = j.modulus;
|
|
11
|
+
if (modulus1.length != modulus2.length) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
15
|
+
}
|
|
16
|
+
exports.publicKeyAndPrivateKeyMatches = publicKeyAndPrivateKeyMatches;
|
|
17
17
|
//# sourceMappingURL=public_private_match.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Certificate } from "./common";
|
|
3
|
-
export declare function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean;
|
|
4
|
-
export declare function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean;
|
|
5
|
-
export declare function verifyCertificateRevocationListSignature(certificateRevocationList: Certificate, parentCertificate: Certificate): boolean;
|
|
6
|
-
export declare type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
|
|
7
|
-
export declare function verifyCertificateChain(certificateChain: Certificate[]): Promise<{
|
|
8
|
-
status: _VerifyStatus;
|
|
9
|
-
reason: string;
|
|
10
|
-
}>;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Certificate } from "./common";
|
|
3
|
+
export declare function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean;
|
|
4
|
+
export declare function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean;
|
|
5
|
+
export declare function verifyCertificateRevocationListSignature(certificateRevocationList: Certificate, parentCertificate: Certificate): boolean;
|
|
6
|
+
export declare type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
|
|
7
|
+
export declare function verifyCertificateChain(certificateChain: Certificate[]): Promise<{
|
|
8
|
+
status: _VerifyStatus;
|
|
9
|
+
reason: string;
|
|
10
|
+
}>;
|
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// tslint:disable: no-console
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.verifyCertificateChain = exports.verifyCertificateRevocationListSignature = exports.verifyCertificateSignature = exports.verifyCertificateOrClrSignature = void 0;
|
|
14
|
-
// Now that we got a hash of the original certificate,
|
|
15
|
-
// we need to verify if we can obtain the same hash by using the same hashing function
|
|
16
|
-
// (in this case SHA-384). In order to do that, we need to extract just the body of
|
|
17
|
-
// the signed certificate. Which, in our case, is everything but the signature.
|
|
18
|
-
// The start of the body is always the first digit of the second line of the following command:
|
|
19
|
-
const crypto = require("crypto");
|
|
20
|
-
const crypto_explore_certificate_1 = require("./crypto_explore_certificate");
|
|
21
|
-
const crypto_utils_1 = require("./crypto_utils");
|
|
22
|
-
const asn1_1 = require("./asn1");
|
|
23
|
-
function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
24
|
-
const block_info = (0, asn1_1.readTag)(certificateOrCrl, 0);
|
|
25
|
-
const blocks = (0, asn1_1._readStruct)(certificateOrCrl, block_info);
|
|
26
|
-
const bufferToBeSigned = certificateOrCrl.slice(block_info.position, blocks[1].position - 2);
|
|
27
|
-
//xx console.log("bufferToBeSigned = ", bufferToBeSigned.length, bufferToBeSigned.toString("hex").substr(0, 50), bufferToBeSigned.toString("hex").substr(-10));
|
|
28
|
-
const signatureAlgorithm = (0, asn1_1._readAlgorithmIdentifier)(certificateOrCrl, blocks[1]);
|
|
29
|
-
const signatureValue = (0, asn1_1._readSignatureValueBin)(certificateOrCrl, blocks[2]);
|
|
30
|
-
const p = (0, crypto_explore_certificate_1.split_der)(parentCertificate)[0];
|
|
31
|
-
//xx const publicKey = extractPublicKeyFromCertificateSync(p);
|
|
32
|
-
const certPem = (0, crypto_utils_1.toPem)(p, "CERTIFICATE");
|
|
33
|
-
const verify = crypto.createVerify(signatureAlgorithm.identifier);
|
|
34
|
-
verify.update(bufferToBeSigned);
|
|
35
|
-
verify.end();
|
|
36
|
-
return verify.verify(certPem, signatureValue);
|
|
37
|
-
}
|
|
38
|
-
exports.verifyCertificateOrClrSignature = verifyCertificateOrClrSignature;
|
|
39
|
-
function verifyCertificateSignature(certificate, parentCertificate) {
|
|
40
|
-
return verifyCertificateOrClrSignature(certificate, parentCertificate);
|
|
41
|
-
}
|
|
42
|
-
exports.verifyCertificateSignature = verifyCertificateSignature;
|
|
43
|
-
function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
|
|
44
|
-
return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
|
|
45
|
-
}
|
|
46
|
-
exports.verifyCertificateRevocationListSignature = verifyCertificateRevocationListSignature;
|
|
47
|
-
function verifyCertificateChain(certificateChain) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
// verify that all the certificate
|
|
50
|
-
// second certificate must be used for CertificateSign
|
|
51
|
-
for (let index = 1; index < certificateChain.length; index++) {
|
|
52
|
-
const cert = certificateChain[index - 1];
|
|
53
|
-
const certParent = certificateChain[index];
|
|
54
|
-
// parent child must have keyCertSign
|
|
55
|
-
const certParentInfo = (0, crypto_explore_certificate_1.exploreCertificate)(certParent);
|
|
56
|
-
const keyUsage = certParentInfo.tbsCertificate.extensions.keyUsage;
|
|
57
|
-
// istanbul ignore next
|
|
58
|
-
if (!keyUsage.keyCertSign) {
|
|
59
|
-
return {
|
|
60
|
-
status: "BadCertificateIssuerUseNotAllowed",
|
|
61
|
-
reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing",
|
|
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 = (0, crypto_explore_certificate_1.exploreCertificate)(cert);
|
|
72
|
-
// istanbul ignore next
|
|
73
|
-
if (!certInfo.tbsCertificate.extensions) {
|
|
74
|
-
return {
|
|
75
|
-
status: "BadCertificateInvalid",
|
|
76
|
-
reason: "Cannot find X409 Extension 3 in certificate",
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
// istanbul ignore next
|
|
80
|
-
if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
|
|
81
|
-
return {
|
|
82
|
-
status: "BadCertificateInvalid",
|
|
83
|
-
reason: "Cannot find X409 Extension 3 in certificate (parent)",
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
// istanbul ignore next
|
|
87
|
-
if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !==
|
|
88
|
-
certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
|
|
89
|
-
return {
|
|
90
|
-
status: "BadCertificateInvalid",
|
|
91
|
-
reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate",
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
status: "Good",
|
|
97
|
-
reason: `certificate chain is valid(length = ${certificateChain.length})`,
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
exports.verifyCertificateChain = verifyCertificateChain;
|
|
1
|
+
"use strict";
|
|
2
|
+
// tslint:disable: no-console
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.verifyCertificateChain = exports.verifyCertificateRevocationListSignature = exports.verifyCertificateSignature = exports.verifyCertificateOrClrSignature = void 0;
|
|
14
|
+
// Now that we got a hash of the original certificate,
|
|
15
|
+
// we need to verify if we can obtain the same hash by using the same hashing function
|
|
16
|
+
// (in this case SHA-384). In order to do that, we need to extract just the body of
|
|
17
|
+
// the signed certificate. Which, in our case, is everything but the signature.
|
|
18
|
+
// The start of the body is always the first digit of the second line of the following command:
|
|
19
|
+
const crypto = require("crypto");
|
|
20
|
+
const crypto_explore_certificate_1 = require("./crypto_explore_certificate");
|
|
21
|
+
const crypto_utils_1 = require("./crypto_utils");
|
|
22
|
+
const asn1_1 = require("./asn1");
|
|
23
|
+
function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
24
|
+
const block_info = (0, asn1_1.readTag)(certificateOrCrl, 0);
|
|
25
|
+
const blocks = (0, asn1_1._readStruct)(certificateOrCrl, block_info);
|
|
26
|
+
const bufferToBeSigned = certificateOrCrl.slice(block_info.position, blocks[1].position - 2);
|
|
27
|
+
//xx console.log("bufferToBeSigned = ", bufferToBeSigned.length, bufferToBeSigned.toString("hex").substr(0, 50), bufferToBeSigned.toString("hex").substr(-10));
|
|
28
|
+
const signatureAlgorithm = (0, asn1_1._readAlgorithmIdentifier)(certificateOrCrl, blocks[1]);
|
|
29
|
+
const signatureValue = (0, asn1_1._readSignatureValueBin)(certificateOrCrl, blocks[2]);
|
|
30
|
+
const p = (0, crypto_explore_certificate_1.split_der)(parentCertificate)[0];
|
|
31
|
+
//xx const publicKey = extractPublicKeyFromCertificateSync(p);
|
|
32
|
+
const certPem = (0, crypto_utils_1.toPem)(p, "CERTIFICATE");
|
|
33
|
+
const verify = crypto.createVerify(signatureAlgorithm.identifier);
|
|
34
|
+
verify.update(bufferToBeSigned);
|
|
35
|
+
verify.end();
|
|
36
|
+
return verify.verify(certPem, signatureValue);
|
|
37
|
+
}
|
|
38
|
+
exports.verifyCertificateOrClrSignature = verifyCertificateOrClrSignature;
|
|
39
|
+
function verifyCertificateSignature(certificate, parentCertificate) {
|
|
40
|
+
return verifyCertificateOrClrSignature(certificate, parentCertificate);
|
|
41
|
+
}
|
|
42
|
+
exports.verifyCertificateSignature = verifyCertificateSignature;
|
|
43
|
+
function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
|
|
44
|
+
return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
|
|
45
|
+
}
|
|
46
|
+
exports.verifyCertificateRevocationListSignature = verifyCertificateRevocationListSignature;
|
|
47
|
+
function verifyCertificateChain(certificateChain) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
// verify that all the certificate
|
|
50
|
+
// second certificate must be used for CertificateSign
|
|
51
|
+
for (let index = 1; index < certificateChain.length; index++) {
|
|
52
|
+
const cert = certificateChain[index - 1];
|
|
53
|
+
const certParent = certificateChain[index];
|
|
54
|
+
// parent child must have keyCertSign
|
|
55
|
+
const certParentInfo = (0, crypto_explore_certificate_1.exploreCertificate)(certParent);
|
|
56
|
+
const keyUsage = certParentInfo.tbsCertificate.extensions.keyUsage;
|
|
57
|
+
// istanbul ignore next
|
|
58
|
+
if (!keyUsage.keyCertSign) {
|
|
59
|
+
return {
|
|
60
|
+
status: "BadCertificateIssuerUseNotAllowed",
|
|
61
|
+
reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing",
|
|
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 = (0, crypto_explore_certificate_1.exploreCertificate)(cert);
|
|
72
|
+
// istanbul ignore next
|
|
73
|
+
if (!certInfo.tbsCertificate.extensions) {
|
|
74
|
+
return {
|
|
75
|
+
status: "BadCertificateInvalid",
|
|
76
|
+
reason: "Cannot find X409 Extension 3 in certificate",
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// istanbul ignore next
|
|
80
|
+
if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
|
|
81
|
+
return {
|
|
82
|
+
status: "BadCertificateInvalid",
|
|
83
|
+
reason: "Cannot find X409 Extension 3 in certificate (parent)",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// istanbul ignore next
|
|
87
|
+
if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !==
|
|
88
|
+
certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
|
|
89
|
+
return {
|
|
90
|
+
status: "BadCertificateInvalid",
|
|
91
|
+
reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate",
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
status: "Good",
|
|
97
|
+
reason: `certificate chain is valid(length = ${certificateChain.length})`,
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
exports.verifyCertificateChain = verifyCertificateChain;
|
|
102
102
|
//# sourceMappingURL=verify_certificate_signature.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
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";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./read"), exports);
|
|
14
|
-
__exportStar(require("./read_certificate_revocation_list"), exports);
|
|
15
|
-
__exportStar(require("./read_certificate_signing_request"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./read"), exports);
|
|
14
|
+
__exportStar(require("./read_certificate_revocation_list"), exports);
|
|
15
|
+
__exportStar(require("./read_certificate_signing_request"), exports);
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { Certificate, CertificatePEM, PrivateKey, PrivateKeyPEM, PublicKey, PublicKeyPEM } from "../source/common";
|
|
2
|
-
/**
|
|
3
|
-
* @method readKeyPem
|
|
4
|
-
* @param filename
|
|
5
|
-
*/
|
|
6
|
-
export declare function readKeyPem(filename: string): string;
|
|
7
|
-
/**
|
|
8
|
-
* read a DER or PEM certificate from file
|
|
9
|
-
*/
|
|
10
|
-
export declare function readCertificate(filename: string): Certificate;
|
|
11
|
-
/**
|
|
12
|
-
* read a DER or PEM certificate from file
|
|
13
|
-
*/
|
|
14
|
-
export declare function readPublicKey(filename: string): PublicKey;
|
|
15
|
-
/**
|
|
16
|
-
* read a DER or PEM certificate from file
|
|
17
|
-
*/
|
|
18
|
-
export declare function readPrivateKey(filename: string): PrivateKey;
|
|
19
|
-
export declare function readCertificatePEM(filename: string): CertificatePEM;
|
|
20
|
-
export declare function readPublicKeyPEM(filename: string): PublicKeyPEM;
|
|
21
|
-
export declare function readPrivateKeyPEM(filename: string): PrivateKeyPEM;
|
|
22
|
-
export declare function setCertificateStore(store: string): string;
|
|
23
|
-
export declare function read_sshkey_as_pem(filename: string): PublicKeyPEM;
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @param filename
|
|
27
|
-
*/
|
|
28
|
-
export declare function readPrivateRsaKey(filename: string): PrivateKeyPEM;
|
|
29
|
-
export declare function readPublicRsaKey(filename: string): PublicKeyPEM;
|
|
1
|
+
import { Certificate, CertificatePEM, PrivateKey, PrivateKeyPEM, PublicKey, PublicKeyPEM } from "../source/common";
|
|
2
|
+
/**
|
|
3
|
+
* @method readKeyPem
|
|
4
|
+
* @param filename
|
|
5
|
+
*/
|
|
6
|
+
export declare function readKeyPem(filename: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* read a DER or PEM certificate from file
|
|
9
|
+
*/
|
|
10
|
+
export declare function readCertificate(filename: string): Certificate;
|
|
11
|
+
/**
|
|
12
|
+
* read a DER or PEM certificate from file
|
|
13
|
+
*/
|
|
14
|
+
export declare function readPublicKey(filename: string): PublicKey;
|
|
15
|
+
/**
|
|
16
|
+
* read a DER or PEM certificate from file
|
|
17
|
+
*/
|
|
18
|
+
export declare function readPrivateKey(filename: string): PrivateKey;
|
|
19
|
+
export declare function readCertificatePEM(filename: string): CertificatePEM;
|
|
20
|
+
export declare function readPublicKeyPEM(filename: string): PublicKeyPEM;
|
|
21
|
+
export declare function readPrivateKeyPEM(filename: string): PrivateKeyPEM;
|
|
22
|
+
export declare function setCertificateStore(store: string): string;
|
|
23
|
+
export declare function read_sshkey_as_pem(filename: string): PublicKeyPEM;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param filename
|
|
27
|
+
*/
|
|
28
|
+
export declare function readPrivateRsaKey(filename: string): PrivateKeyPEM;
|
|
29
|
+
export declare function readPublicRsaKey(filename: string): PublicKeyPEM;
|
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readPublicRsaKey = exports.readPrivateRsaKey = exports.read_sshkey_as_pem = exports.setCertificateStore = exports.readPrivateKeyPEM = exports.readPublicKeyPEM = exports.readCertificatePEM = exports.readPrivateKey = exports.readPublicKey = exports.readCertificate = exports.readKeyPem = void 0;
|
|
4
|
-
const assert = require("assert");
|
|
5
|
-
const fs = require("fs");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const crypto_utils_1 = require("../source/crypto_utils");
|
|
8
|
-
const sshpk = require("sshpk");
|
|
9
|
-
/**
|
|
10
|
-
* @method readKeyPem
|
|
11
|
-
* @param filename
|
|
12
|
-
*/
|
|
13
|
-
function readKeyPem(filename) {
|
|
14
|
-
const raw_key = fs.readFileSync(filename, "utf8");
|
|
15
|
-
const pemType = (0, crypto_utils_1.identifyPemType)(raw_key);
|
|
16
|
-
assert(typeof pemType === "string"); // must have a valid pem type
|
|
17
|
-
return raw_key;
|
|
18
|
-
}
|
|
19
|
-
exports.readKeyPem = readKeyPem;
|
|
20
|
-
function _readPemFile(filename) {
|
|
21
|
-
assert(typeof filename === "string");
|
|
22
|
-
return fs.readFileSync(filename, "ascii");
|
|
23
|
-
}
|
|
24
|
-
function _readPemOrDerFileAsDER(filename) {
|
|
25
|
-
if (filename.match(/.*\.der/)) {
|
|
26
|
-
return fs.readFileSync(filename);
|
|
27
|
-
}
|
|
28
|
-
const raw_key = _readPemFile(filename);
|
|
29
|
-
return (0, crypto_utils_1.convertPEMtoDER)(raw_key);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* read a DER or PEM certificate from file
|
|
33
|
-
*/
|
|
34
|
-
function readCertificate(filename) {
|
|
35
|
-
return _readPemOrDerFileAsDER(filename);
|
|
36
|
-
}
|
|
37
|
-
exports.readCertificate = readCertificate;
|
|
38
|
-
/**
|
|
39
|
-
* read a DER or PEM certificate from file
|
|
40
|
-
*/
|
|
41
|
-
function readPublicKey(filename) {
|
|
42
|
-
return _readPemOrDerFileAsDER(filename);
|
|
43
|
-
}
|
|
44
|
-
exports.readPublicKey = readPublicKey;
|
|
45
|
-
/**
|
|
46
|
-
* read a DER or PEM certificate from file
|
|
47
|
-
*/
|
|
48
|
-
function readPrivateKey(filename) {
|
|
49
|
-
return _readPemOrDerFileAsDER(filename);
|
|
50
|
-
}
|
|
51
|
-
exports.readPrivateKey = readPrivateKey;
|
|
52
|
-
function readCertificatePEM(filename) {
|
|
53
|
-
return _readPemFile(filename);
|
|
54
|
-
}
|
|
55
|
-
exports.readCertificatePEM = readCertificatePEM;
|
|
56
|
-
function readPublicKeyPEM(filename) {
|
|
57
|
-
return _readPemFile(filename);
|
|
58
|
-
}
|
|
59
|
-
exports.readPublicKeyPEM = readPublicKeyPEM;
|
|
60
|
-
function readPrivateKeyPEM(filename) {
|
|
61
|
-
return _readPemFile(filename);
|
|
62
|
-
}
|
|
63
|
-
exports.readPrivateKeyPEM = readPrivateKeyPEM;
|
|
64
|
-
let __certificate_store = path.join(__dirname, "../../certificates/");
|
|
65
|
-
function setCertificateStore(store) {
|
|
66
|
-
const old_store = __certificate_store;
|
|
67
|
-
__certificate_store = store;
|
|
68
|
-
return old_store;
|
|
69
|
-
}
|
|
70
|
-
exports.setCertificateStore = setCertificateStore;
|
|
71
|
-
function read_sshkey_as_pem(filename) {
|
|
72
|
-
if (filename.substr(0, 1) !== ".") {
|
|
73
|
-
filename = __certificate_store + filename;
|
|
74
|
-
}
|
|
75
|
-
const key = fs.readFileSync(filename, "ascii");
|
|
76
|
-
const sshKey = sshpk.parseKey(key, "ssh");
|
|
77
|
-
return sshKey.toString("pkcs8");
|
|
78
|
-
}
|
|
79
|
-
exports.read_sshkey_as_pem = read_sshkey_as_pem;
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
82
|
-
* @param filename
|
|
83
|
-
*/
|
|
84
|
-
function readPrivateRsaKey(filename) {
|
|
85
|
-
if (filename.substr(0, 1) !== "." && !fs.existsSync(filename)) {
|
|
86
|
-
filename = __certificate_store + filename;
|
|
87
|
-
}
|
|
88
|
-
return fs.readFileSync(filename, "ascii");
|
|
89
|
-
}
|
|
90
|
-
exports.readPrivateRsaKey = readPrivateRsaKey;
|
|
91
|
-
function readPublicRsaKey(filename) {
|
|
92
|
-
return readPrivateRsaKey(filename);
|
|
93
|
-
}
|
|
94
|
-
exports.readPublicRsaKey = readPublicRsaKey;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readPublicRsaKey = exports.readPrivateRsaKey = exports.read_sshkey_as_pem = exports.setCertificateStore = exports.readPrivateKeyPEM = exports.readPublicKeyPEM = exports.readCertificatePEM = exports.readPrivateKey = exports.readPublicKey = exports.readCertificate = exports.readKeyPem = void 0;
|
|
4
|
+
const assert = require("assert");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const crypto_utils_1 = require("../source/crypto_utils");
|
|
8
|
+
const sshpk = require("sshpk");
|
|
9
|
+
/**
|
|
10
|
+
* @method readKeyPem
|
|
11
|
+
* @param filename
|
|
12
|
+
*/
|
|
13
|
+
function readKeyPem(filename) {
|
|
14
|
+
const raw_key = fs.readFileSync(filename, "utf8");
|
|
15
|
+
const pemType = (0, crypto_utils_1.identifyPemType)(raw_key);
|
|
16
|
+
assert(typeof pemType === "string"); // must have a valid pem type
|
|
17
|
+
return raw_key;
|
|
18
|
+
}
|
|
19
|
+
exports.readKeyPem = readKeyPem;
|
|
20
|
+
function _readPemFile(filename) {
|
|
21
|
+
assert(typeof filename === "string");
|
|
22
|
+
return fs.readFileSync(filename, "ascii");
|
|
23
|
+
}
|
|
24
|
+
function _readPemOrDerFileAsDER(filename) {
|
|
25
|
+
if (filename.match(/.*\.der/)) {
|
|
26
|
+
return fs.readFileSync(filename);
|
|
27
|
+
}
|
|
28
|
+
const raw_key = _readPemFile(filename);
|
|
29
|
+
return (0, crypto_utils_1.convertPEMtoDER)(raw_key);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* read a DER or PEM certificate from file
|
|
33
|
+
*/
|
|
34
|
+
function readCertificate(filename) {
|
|
35
|
+
return _readPemOrDerFileAsDER(filename);
|
|
36
|
+
}
|
|
37
|
+
exports.readCertificate = readCertificate;
|
|
38
|
+
/**
|
|
39
|
+
* read a DER or PEM certificate from file
|
|
40
|
+
*/
|
|
41
|
+
function readPublicKey(filename) {
|
|
42
|
+
return _readPemOrDerFileAsDER(filename);
|
|
43
|
+
}
|
|
44
|
+
exports.readPublicKey = readPublicKey;
|
|
45
|
+
/**
|
|
46
|
+
* read a DER or PEM certificate from file
|
|
47
|
+
*/
|
|
48
|
+
function readPrivateKey(filename) {
|
|
49
|
+
return _readPemOrDerFileAsDER(filename);
|
|
50
|
+
}
|
|
51
|
+
exports.readPrivateKey = readPrivateKey;
|
|
52
|
+
function readCertificatePEM(filename) {
|
|
53
|
+
return _readPemFile(filename);
|
|
54
|
+
}
|
|
55
|
+
exports.readCertificatePEM = readCertificatePEM;
|
|
56
|
+
function readPublicKeyPEM(filename) {
|
|
57
|
+
return _readPemFile(filename);
|
|
58
|
+
}
|
|
59
|
+
exports.readPublicKeyPEM = readPublicKeyPEM;
|
|
60
|
+
function readPrivateKeyPEM(filename) {
|
|
61
|
+
return _readPemFile(filename);
|
|
62
|
+
}
|
|
63
|
+
exports.readPrivateKeyPEM = readPrivateKeyPEM;
|
|
64
|
+
let __certificate_store = path.join(__dirname, "../../certificates/");
|
|
65
|
+
function setCertificateStore(store) {
|
|
66
|
+
const old_store = __certificate_store;
|
|
67
|
+
__certificate_store = store;
|
|
68
|
+
return old_store;
|
|
69
|
+
}
|
|
70
|
+
exports.setCertificateStore = setCertificateStore;
|
|
71
|
+
function read_sshkey_as_pem(filename) {
|
|
72
|
+
if (filename.substr(0, 1) !== ".") {
|
|
73
|
+
filename = __certificate_store + filename;
|
|
74
|
+
}
|
|
75
|
+
const key = fs.readFileSync(filename, "ascii");
|
|
76
|
+
const sshKey = sshpk.parseKey(key, "ssh");
|
|
77
|
+
return sshKey.toString("pkcs8");
|
|
78
|
+
}
|
|
79
|
+
exports.read_sshkey_as_pem = read_sshkey_as_pem;
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @param filename
|
|
83
|
+
*/
|
|
84
|
+
function readPrivateRsaKey(filename) {
|
|
85
|
+
if (filename.substr(0, 1) !== "." && !fs.existsSync(filename)) {
|
|
86
|
+
filename = __certificate_store + filename;
|
|
87
|
+
}
|
|
88
|
+
return fs.readFileSync(filename, "ascii");
|
|
89
|
+
}
|
|
90
|
+
exports.readPrivateRsaKey = readPrivateRsaKey;
|
|
91
|
+
function readPublicRsaKey(filename) {
|
|
92
|
+
return readPrivateRsaKey(filename);
|
|
93
|
+
}
|
|
94
|
+
exports.readPublicRsaKey = readPublicRsaKey;
|
|
95
95
|
//# sourceMappingURL=read.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CertificateRevocationList } from "../source/common";
|
|
2
|
-
export declare function readCertificateRevocationList(filename: string): Promise<CertificateRevocationList>;
|
|
1
|
+
import { CertificateRevocationList } from "../source/common";
|
|
2
|
+
export declare function readCertificateRevocationList(filename: string): Promise<CertificateRevocationList>;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.readCertificateRevocationList = void 0;
|
|
13
|
-
const fs = require("fs");
|
|
14
|
-
const util_1 = require("util");
|
|
15
|
-
const crypto_utils_1 = require("../source/crypto_utils");
|
|
16
|
-
function readCertificateRevocationList(filename) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const crl = yield (0, util_1.promisify)(fs.readFile)(filename);
|
|
19
|
-
if (crl[0] === 0x30 && crl[1] === 0x82) {
|
|
20
|
-
// der format
|
|
21
|
-
return crl;
|
|
22
|
-
}
|
|
23
|
-
const raw_crl = crl.toString();
|
|
24
|
-
return (0, crypto_utils_1.convertPEMtoDER)(raw_crl);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
exports.readCertificateRevocationList = readCertificateRevocationList;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.readCertificateRevocationList = void 0;
|
|
13
|
+
const fs = require("fs");
|
|
14
|
+
const util_1 = require("util");
|
|
15
|
+
const crypto_utils_1 = require("../source/crypto_utils");
|
|
16
|
+
function readCertificateRevocationList(filename) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const crl = yield (0, util_1.promisify)(fs.readFile)(filename);
|
|
19
|
+
if (crl[0] === 0x30 && crl[1] === 0x82) {
|
|
20
|
+
// der format
|
|
21
|
+
return crl;
|
|
22
|
+
}
|
|
23
|
+
const raw_crl = crl.toString();
|
|
24
|
+
return (0, crypto_utils_1.convertPEMtoDER)(raw_crl);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.readCertificateRevocationList = readCertificateRevocationList;
|
|
28
28
|
//# sourceMappingURL=read_certificate_revocation_list.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
export declare type CertificateSigningRequest = Buffer;
|
|
3
|
-
export declare function readCertificateSigningRequest(filename: string): Promise<CertificateSigningRequest>;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare type CertificateSigningRequest = Buffer;
|
|
3
|
+
export declare function readCertificateSigningRequest(filename: string): Promise<CertificateSigningRequest>;
|