node-opcua-crypto 2.2.0 → 3.0.0-beta.1
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/{dist → dist-cjs}/source/asn1.js +95 -151
- package/dist-cjs/source/asn1.js.map +1 -0
- package/dist-cjs/source/buffer_utils.js +9 -0
- package/dist-cjs/source/buffer_utils.js.map +1 -0
- package/dist-cjs/source/common.js +11 -0
- package/dist-cjs/source/common.js.map +1 -0
- package/dist-cjs/source/crypto_explore_certificate.js +367 -0
- package/dist-cjs/source/crypto_explore_certificate.js.map +1 -0
- package/{dist → dist-cjs}/source/crypto_utils.js +80 -141
- package/dist-cjs/source/crypto_utils.js.map +1 -0
- package/dist-cjs/source/derived_keys.js +133 -0
- package/dist-cjs/source/derived_keys.js.map +1 -0
- package/{dist → dist-cjs}/source/explore_certificate.js +10 -17
- package/dist-cjs/source/explore_certificate.js.map +1 -0
- package/dist-cjs/source/explore_certificate_revocation_list.js +69 -0
- package/dist-cjs/source/explore_certificate_revocation_list.js.map +1 -0
- package/dist-cjs/source/explore_certificate_signing_request.js +45 -0
- package/dist-cjs/source/explore_certificate_signing_request.js.map +1 -0
- package/dist-cjs/source/explore_private_key.js +75 -0
- package/dist-cjs/source/explore_private_key.js.map +1 -0
- package/dist-cjs/source/index.js +32 -0
- package/dist-cjs/source/index.js.map +1 -0
- package/{dist → dist-cjs}/source/oid_map.js +0 -4
- package/dist-cjs/source/oid_map.js.map +1 -0
- package/dist-cjs/source/public_private_match.js +32 -0
- package/dist-cjs/source/public_private_match.js.map +1 -0
- package/dist-cjs/source/subject.js +92 -0
- package/dist-cjs/source/subject.js.map +1 -0
- package/dist-cjs/source/verify_certificate_signature.js +120 -0
- package/dist-cjs/source/verify_certificate_signature.js.map +1 -0
- package/dist-cjs/source/x509/_build_public_key.js +69 -0
- package/dist-cjs/source/x509/_build_public_key.js.map +1 -0
- package/dist-cjs/source/x509/_crypto.js +50 -0
- package/dist-cjs/source/x509/_crypto.js.map +1 -0
- package/dist-cjs/source/x509/_get_attributes.js +35 -0
- package/dist-cjs/source/x509/_get_attributes.js.map +1 -0
- package/dist-cjs/source/x509/create_certificate_signing_request.js +92 -0
- package/dist-cjs/source/x509/create_certificate_signing_request.js.map +1 -0
- package/dist-cjs/source/x509/create_key_pair.js +123 -0
- package/dist-cjs/source/x509/create_key_pair.js.map +1 -0
- package/dist-cjs/source/x509/create_self_signed_certificate.js +102 -0
- package/dist-cjs/source/x509/create_self_signed_certificate.js.map +1 -0
- package/dist-cjs/source_nodejs/generate_private_key_filename.js +67 -0
- package/dist-cjs/source_nodejs/generate_private_key_filename.js.map +1 -0
- package/{dist → dist-cjs}/source_nodejs/index.js +4 -3
- package/{dist → dist-cjs}/source_nodejs/index.js.map +1 -1
- package/{dist → dist-cjs}/source_nodejs/read.js +32 -43
- package/dist-cjs/source_nodejs/read.js.map +1 -0
- package/dist-cjs/source_nodejs/read_certificate_revocation_list.js +64 -0
- package/dist-cjs/source_nodejs/read_certificate_revocation_list.js.map +1 -0
- package/dist-cjs/source_nodejs/read_certificate_signing_request.js +64 -0
- package/dist-cjs/source_nodejs/read_certificate_signing_request.js.map +1 -0
- package/dist-esm/source/asn1.js +275 -0
- package/dist-esm/source/asn1.js.map +1 -0
- package/dist-esm/source/buffer_utils.js +6 -0
- package/dist-esm/source/buffer_utils.js.map +1 -0
- package/dist-esm/source/common.js +8 -0
- package/dist-esm/source/common.js.map +1 -0
- package/dist-esm/source/crypto_explore_certificate.js +356 -0
- package/dist-esm/source/crypto_explore_certificate.js.map +1 -0
- package/dist-esm/source/crypto_utils.js +242 -0
- package/dist-esm/source/crypto_utils.js.map +1 -0
- package/dist-esm/source/derived_keys.js +117 -0
- package/dist-esm/source/derived_keys.js.map +1 -0
- package/dist-esm/source/explore_certificate.js +29 -0
- package/dist-esm/source/explore_certificate.js.map +1 -0
- package/dist-esm/source/explore_certificate_revocation_list.js +64 -0
- package/dist-esm/source/explore_certificate_revocation_list.js.map +1 -0
- package/dist-esm/source/explore_certificate_signing_request.js +40 -0
- package/dist-esm/source/explore_certificate_signing_request.js.map +1 -0
- package/dist-esm/source/explore_private_key.js +71 -0
- package/dist-esm/source/explore_private_key.js.map +1 -0
- package/dist-esm/source/index.js +16 -0
- package/dist-esm/source/index.js.map +1 -0
- package/{source/oid_map.ts → dist-esm/source/oid_map.js} +2 -15
- package/dist-esm/source/oid_map.js.map +1 -0
- package/dist-esm/source/public_private_match.js +27 -0
- package/dist-esm/source/public_private_match.js.map +1 -0
- package/dist-esm/source/subject.js +89 -0
- package/dist-esm/source/subject.js.map +1 -0
- package/dist-esm/source/verify_certificate_signature.js +110 -0
- package/dist-esm/source/verify_certificate_signature.js.map +1 -0
- package/dist-esm/source/x509/_build_public_key.js +65 -0
- package/dist-esm/source/x509/_build_public_key.js.map +1 -0
- package/dist-esm/source/x509/_crypto.js +23 -0
- package/dist-esm/source/x509/_crypto.js.map +1 -0
- package/dist-esm/source/x509/_get_attributes.js +31 -0
- package/dist-esm/source/x509/_get_attributes.js.map +1 -0
- package/dist-esm/source/x509/create_certificate_signing_request.js +88 -0
- package/dist-esm/source/x509/create_certificate_signing_request.js.map +1 -0
- package/dist-esm/source/x509/create_key_pair.js +115 -0
- package/dist-esm/source/x509/create_key_pair.js.map +1 -0
- package/dist-esm/source/x509/create_self_signed_certificate.js +98 -0
- package/dist-esm/source/x509/create_self_signed_certificate.js.map +1 -0
- package/dist-esm/source_nodejs/generate_private_key_filename.js +60 -0
- package/dist-esm/source_nodejs/generate_private_key_filename.js.map +1 -0
- package/dist-esm/source_nodejs/index.js +5 -0
- package/dist-esm/source_nodejs/index.js.map +1 -0
- package/dist-esm/source_nodejs/read.js +81 -0
- package/dist-esm/source_nodejs/read.js.map +1 -0
- package/dist-esm/source_nodejs/read_certificate_revocation_list.js +57 -0
- package/dist-esm/source_nodejs/read_certificate_revocation_list.js.map +1 -0
- package/dist-esm/source_nodejs/read_certificate_signing_request.js +57 -0
- package/dist-esm/source_nodejs/read_certificate_signing_request.js.map +1 -0
- package/{dist → dist-types}/source/common.d.ts +6 -0
- package/{dist → dist-types}/source/crypto_explore_certificate.d.ts +3 -3
- package/{dist → dist-types}/source/crypto_utils.d.ts +2 -2
- package/{dist → dist-types}/source/derived_keys.d.ts +2 -2
- package/{dist → dist-types}/source/explore_certificate.d.ts +3 -6
- package/{dist → dist-types}/source/explore_certificate_revocation_list.d.ts +2 -2
- package/{dist → dist-types}/source/explore_certificate_signing_request.d.ts +2 -2
- package/{dist → dist-types}/source/explore_private_key.d.ts +1 -1
- package/dist-types/source/index.d.ts +18 -0
- package/{dist → dist-types}/source/public_private_match.d.ts +1 -1
- package/dist-types/source/subject.d.ts +27 -0
- package/{dist → dist-types}/source/verify_certificate_signature.d.ts +1 -1
- package/dist-types/source/x509/_build_public_key.d.ts +1 -0
- package/dist-types/source/x509/_crypto.d.ts +2 -0
- package/dist-types/source/x509/_get_attributes.d.ts +8 -0
- package/dist-types/source/x509/create_certificate_signing_request.d.ts +18 -0
- package/dist-types/source/x509/create_key_pair.d.ts +8 -0
- package/dist-types/source/x509/create_self_signed_certificate.d.ts +17 -0
- package/dist-types/source_nodejs/generate_private_key_filename.d.ts +1 -0
- package/dist-types/source_nodejs/index.d.ts +4 -0
- package/{dist → dist-types}/source_nodejs/read.d.ts +1 -1
- package/{dist → dist-types}/source_nodejs/read_certificate_revocation_list.d.ts +1 -1
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/index_web.d.ts +1 -0
- package/index_web.js +1 -1
- package/package.json +31 -7
- package/web/esbuild.mjs +15 -0
- package/web/index.html +9 -0
- package/web/main.js +28 -0
- package/web/rollup.config.mjs +20 -0
- package/.fossa.yml +0 -18
- package/.github/FUNDING.yml +0 -12
- package/.github/workflows/main.yml +0 -106
- package/.prettierrc.js +0 -7
- package/dist/source/asn1.js.map +0 -1
- package/dist/source/buffer_utils.js +0 -22
- package/dist/source/buffer_utils.js.map +0 -1
- package/dist/source/common.js +0 -3
- package/dist/source/common.js.map +0 -1
- package/dist/source/crypto_explore_certificate.js +0 -602
- package/dist/source/crypto_explore_certificate.js.map +0 -1
- package/dist/source/crypto_utils.js.map +0 -1
- package/dist/source/derived_keys.js +0 -249
- package/dist/source/derived_keys.js.map +0 -1
- package/dist/source/explore_certificate.js.map +0 -1
- package/dist/source/explore_certificate_revocation_list.js +0 -70
- package/dist/source/explore_certificate_revocation_list.js.map +0 -1
- package/dist/source/explore_certificate_signing_request.js +0 -45
- package/dist/source/explore_certificate_signing_request.js.map +0 -1
- package/dist/source/explore_private_key.js +0 -98
- package/dist/source/explore_private_key.js.map +0 -1
- package/dist/source/index.d.ts +0 -13
- package/dist/source/index.js +0 -30
- package/dist/source/index.js.map +0 -1
- package/dist/source/oid_map.js.map +0 -1
- package/dist/source/public_private_match.js +0 -37
- package/dist/source/public_private_match.js.map +0 -1
- package/dist/source/verify_certificate_signature.js +0 -102
- package/dist/source/verify_certificate_signature.js.map +0 -1
- package/dist/source_nodejs/index.d.ts +0 -3
- package/dist/source_nodejs/read.js.map +0 -1
- package/dist/source_nodejs/read_certificate_revocation_list.js +0 -28
- package/dist/source_nodejs/read_certificate_revocation_list.js.map +0 -1
- package/dist/source_nodejs/read_certificate_signing_request.js +0 -28
- package/dist/source_nodejs/read_certificate_signing_request.js.map +0 -1
- package/source/asn1.ts +0 -404
- package/source/buffer_utils.ts +0 -18
- package/source/common.ts +0 -15
- package/source/crypto_explore_certificate.ts +0 -764
- package/source/crypto_utils.ts +0 -376
- package/source/derived_keys.ts +0 -287
- package/source/explore_certificate.ts +0 -66
- package/source/explore_certificate_revocation_list.ts +0 -122
- package/source/explore_certificate_signing_request.ts +0 -58
- package/source/explore_private_key.ts +0 -119
- package/source/index.ts +0 -13
- package/source/public_private_match.ts +0 -37
- package/source/verify_certificate_signature.ts +0 -105
- package/source_nodejs/index.ts +0 -3
- package/source_nodejs/read.ts +0 -105
- package/source_nodejs/read_certificate_revocation_list.ts +0 -14
- package/source_nodejs/read_certificate_signing_request.ts +0 -17
- package/test_certificate.ts +0 -34
- package/tsconfig.json +0 -18
- package/tslint.json +0 -35
- /package/{dist → dist-types}/source/asn1.d.ts +0 -0
- /package/{dist → dist-types}/source/buffer_utils.d.ts +0 -0
- /package/{dist → dist-types}/source/oid_map.d.ts +0 -0
- /package/{dist → dist-types}/source_nodejs/read_certificate_signing_request.d.ts +0 -0
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.certificateMatchesPrivateKey = exports.publicKeyAndPrivateKeyMatches = void 0;
|
|
4
|
-
const explore_private_key_1 = require("./explore_private_key");
|
|
5
|
-
const crypto_utils_1 = require("./crypto_utils");
|
|
6
|
-
const crypto_explore_certificate_1 = require("./crypto_explore_certificate");
|
|
7
|
-
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
8
|
-
const i = (0, crypto_explore_certificate_1.exploreCertificate)(certificate);
|
|
9
|
-
const j = (0, explore_private_key_1.explorePrivateKey)(privateKey);
|
|
10
|
-
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
11
|
-
const modulus2 = j.modulus;
|
|
12
|
-
if (modulus1.length != modulus2.length) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
16
|
-
}
|
|
17
|
-
exports.publicKeyAndPrivateKeyMatches = publicKeyAndPrivateKeyMatches;
|
|
18
|
-
/**
|
|
19
|
-
* check that the given certificate matches the given private key
|
|
20
|
-
* @param certificate
|
|
21
|
-
* @param privateKey
|
|
22
|
-
*/
|
|
23
|
-
function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
24
|
-
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
25
|
-
const encryptedBuffer = (0, crypto_utils_1.publicEncrypt_long)(initialBuffer, certificate, blockSize, 11);
|
|
26
|
-
const decryptedBuffer = (0, crypto_utils_1.privateDecrypt_long)(encryptedBuffer, privateKey, blockSize);
|
|
27
|
-
const finalString = decryptedBuffer.toString("utf-8");
|
|
28
|
-
return initialBuffer.toString("utf-8") === finalString;
|
|
29
|
-
}
|
|
30
|
-
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
31
|
-
const e = (0, explore_private_key_1.explorePrivateKey)(privateKey);
|
|
32
|
-
const blockSize = e.modulus.length;
|
|
33
|
-
const certificatePEM = (0, crypto_utils_1.toPem)(certificate, "CERTIFICATE");
|
|
34
|
-
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
35
|
-
}
|
|
36
|
-
exports.certificateMatchesPrivateKey = certificateMatchesPrivateKey;
|
|
37
|
-
//# sourceMappingURL=public_private_match.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"public_private_match.js","sourceRoot":"","sources":["../../source/public_private_match.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAE1D,iDAAgF;AAChF,6EAAkE;AAElE,SAAgB,6BAA6B,CAAC,WAAwB,EAAE,UAAsB;IAC1F,MAAM,CAAC,GAAG,IAAA,+CAAkB,EAAC,WAAW,CAAC,CAAC;IAC1C,MAAM,CAAC,GAAG,IAAA,uCAAiB,EAAC,UAAU,CAAC,CAAC;IAExC,MAAM,QAAQ,GAAG,CAAC,CAAC,cAAc,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,OAAO,CAAC;IAChF,MAAM,QAAQ,GAAG,CAAC,CAAC,OAAO,CAAC;IAE3B,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,EAAE;QACpC,OAAO,KAAK,CAAC;KAChB;IACD,OAAO,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC;AAXD,sEAWC;AAED;;;;GAIG;AACH,SAAS,+BAA+B,CAAC,WAA2B,EAAE,UAAsB,EAAE,SAAiB;IAC3G,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACjD,MAAM,eAAe,GAAG,IAAA,iCAAkB,EAAC,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;IACtF,MAAM,eAAe,GAAG,IAAA,kCAAmB,EAAC,eAAe,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IACpF,MAAM,WAAW,GAAG,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACtD,OAAO,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,WAAW,CAAC;AAC3D,CAAC;AAED,SAAgB,4BAA4B,CAAC,WAAwB,EAAE,UAAsB;IACzF,MAAM,CAAC,GAAG,IAAA,uCAAiB,EAAC,UAAU,CAAC,CAAC;IACxC,MAAM,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACnC,MAAM,cAAc,GAAG,IAAA,oBAAK,EAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IACzD,OAAO,+BAA+B,CAAC,cAAc,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;AAClF,CAAC;AALD,oEAKC"}
|
|
@@ -1,102 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=verify_certificate_signature.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"verify_certificate_signature.js","sourceRoot":"","sources":["../../source/verify_certificate_signature.ts"],"names":[],"mappings":";AAAA,6BAA6B;;;;;;;;;;;;AAE7B,sDAAsD;AACtD,sFAAsF;AACtF,mFAAmF;AACnF,+EAA+E;AAC/E,+FAA+F;AAC/F,iCAAiC;AAGjC,6EAA6E;AAC7E,iDAAuC;AACvC,iCAAoH;AAEpH,SAAgB,+BAA+B,CAAC,gBAAwB,EAAE,iBAA8B;IACpG,MAAM,UAAU,GAAG,IAAA,cAAO,EAAC,gBAAgB,E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e,EAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;AAClE,CAAC;AARD,4CAQC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=read_certificate_revocation_list.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"read_certificate_revocation_list.js","sourceRoot":"","sources":["../../source_nodejs/read_certificate_revocation_list.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yBAAyB;AACzB,+BAAiC;AACjC,yDAAyD;AAGzD,SAAsB,6BAA6B,CAAC,QAAgB;;QAChE,MAAM,GAAG,GAAG,MAAM,IAAA,gBAAS,EAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC;QACnD,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE;YACpC,aAAa;YACb,OAAO,GAAgC,CAAC;SAC3C;QACD,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC/B,OAAO,IAAA,8BAAe,EAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CAAA;AARD,sEAQC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
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.readCertificateSigningRequest = void 0;
|
|
13
|
-
const fs = require("fs");
|
|
14
|
-
const util_1 = require("util");
|
|
15
|
-
const crypto_utils_1 = require("../source/crypto_utils");
|
|
16
|
-
function readCertificateSigningRequest(filename) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const csr = yield (0, util_1.promisify)(fs.readFile)(filename);
|
|
19
|
-
if (csr[0] === 0x30 && csr[1] === 0x82) {
|
|
20
|
-
// der format
|
|
21
|
-
return csr;
|
|
22
|
-
}
|
|
23
|
-
const raw_crl = csr.toString();
|
|
24
|
-
return (0, crypto_utils_1.convertPEMtoDER)(raw_crl);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
exports.readCertificateSigningRequest = readCertificateSigningRequest;
|
|
28
|
-
//# sourceMappingURL=read_certificate_signing_request.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"read_certificate_signing_request.js","sourceRoot":"","sources":["../../source_nodejs/read_certificate_signing_request.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yBAAyB;AACzB,+BAAiC;AACjC,yDAAyD;AAMzD,SAAsB,6BAA6B,CAAC,QAAgB;;QAChE,MAAM,GAAG,GAAG,MAAM,IAAA,gBAAS,EAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC;QACnD,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE;YACpC,aAAa;YACb,OAAO,GAAgC,CAAC;SAC3C;QACD,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC/B,OAAO,IAAA,8BAAe,EAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CAAA;AARD,sEAQC"}
|
package/source/asn1.ts
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
import * as assert from "assert";
|
|
2
|
-
import { oid_map } from "./oid_map";
|
|
3
|
-
|
|
4
|
-
// https://github.com/lapo-luchini/asn1js/blob/master/asn1.js
|
|
5
|
-
export enum TagType {
|
|
6
|
-
BOOLEAN = 0x01,
|
|
7
|
-
INTEGER = 0x02,
|
|
8
|
-
BIT_STRING = 0x03,
|
|
9
|
-
OCTET_STRING = 0x04,
|
|
10
|
-
NULL = 0x05,
|
|
11
|
-
OBJECT_IDENTIFIER = 0x06,
|
|
12
|
-
UTF8String = 0x0c,
|
|
13
|
-
NumericString = 0x12,
|
|
14
|
-
PrintableString = 0x13,
|
|
15
|
-
TeletexString = 0x14,
|
|
16
|
-
IA5String = 0x16,
|
|
17
|
-
UTCTime = 0x17,
|
|
18
|
-
GeneralizedTime = 0x18,
|
|
19
|
-
GraphicString = 0x19,
|
|
20
|
-
VisibleString = 0x1a,
|
|
21
|
-
GeneralString = 0x1b,
|
|
22
|
-
UniversalString = 0x1c,
|
|
23
|
-
BMPString = 0x1e,
|
|
24
|
-
|
|
25
|
-
SEQUENCE = 0x30,
|
|
26
|
-
SET = 0x31,
|
|
27
|
-
|
|
28
|
-
A3 = 0xA3
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface BlockInfo {
|
|
32
|
-
tag: TagType | number;
|
|
33
|
-
position: number;
|
|
34
|
-
length: number;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function readTag(buf: Buffer, pos: number): BlockInfo {
|
|
38
|
-
assert(buf instanceof Buffer);
|
|
39
|
-
assert(Number.isFinite(pos) && pos >= 0);
|
|
40
|
-
// istanbul ignore next
|
|
41
|
-
if (buf.length <= pos) {
|
|
42
|
-
throw new Error("Invalid position : buf.length=" + buf.length + " pos =" + pos);
|
|
43
|
-
}
|
|
44
|
-
const tag = buf.readUInt8(pos);
|
|
45
|
-
pos += 1;
|
|
46
|
-
|
|
47
|
-
let length = buf.readUInt8(pos);
|
|
48
|
-
pos += 1;
|
|
49
|
-
|
|
50
|
-
// tslint:disable:no-bitwise
|
|
51
|
-
if (length > 127) {
|
|
52
|
-
const nbBytes = length & 0x7f;
|
|
53
|
-
length = 0;
|
|
54
|
-
for (let i = 0; i < nbBytes; i++) {
|
|
55
|
-
length = length * 256 + buf.readUInt8(pos);
|
|
56
|
-
pos += 1;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return { tag, position: pos, length };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function _readStruct(buf: Buffer, blockInfo: BlockInfo): BlockInfo[] {
|
|
63
|
-
const length = blockInfo.length;
|
|
64
|
-
let cursor = blockInfo.position;
|
|
65
|
-
const end = blockInfo.position + length;
|
|
66
|
-
const blocks: BlockInfo[] = [];
|
|
67
|
-
while (cursor < end) {
|
|
68
|
-
const inner = readTag(buf, cursor);
|
|
69
|
-
cursor = inner.position + inner.length;
|
|
70
|
-
blocks.push(inner);
|
|
71
|
-
}
|
|
72
|
-
return blocks;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function parseBitString(buffer: Buffer, start: number, end: number, maxLength: number): string {
|
|
76
|
-
const unusedBit = buffer.readUInt8(start),
|
|
77
|
-
lenBit = ((end - start - 1) << 3) - unusedBit,
|
|
78
|
-
intro = "(" + lenBit + " bit)\n";
|
|
79
|
-
|
|
80
|
-
let s = "",
|
|
81
|
-
skip = unusedBit;
|
|
82
|
-
|
|
83
|
-
for (let i = end - 1; i > start; --i) {
|
|
84
|
-
const b = buffer.readUInt8(i);
|
|
85
|
-
|
|
86
|
-
for (let j = skip; j < 8; ++j) {
|
|
87
|
-
// noinspection JSBitwiseOperatorUsage
|
|
88
|
-
s += (b >> j) & 1 ? "1" : "0";
|
|
89
|
-
}
|
|
90
|
-
skip = 0;
|
|
91
|
-
assert(s.length <= maxLength);
|
|
92
|
-
}
|
|
93
|
-
return intro + s;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export interface BitString {
|
|
97
|
-
lengthInBits: number;
|
|
98
|
-
lengthInBytes: number;
|
|
99
|
-
data: Buffer;
|
|
100
|
-
debug?: any;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function _readBitString(buffer: Buffer, block: BlockInfo): BitString {
|
|
104
|
-
assert(block.tag === TagType.BIT_STRING);
|
|
105
|
-
const data = _getBlock(buffer, block);
|
|
106
|
-
// number of skipped bits
|
|
107
|
-
const ignore_bits = data.readUInt8(0);
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
lengthInBits: data.length * 8 - ignore_bits,
|
|
111
|
-
lengthInBytes: data.length - 1,
|
|
112
|
-
data: data.slice(1),
|
|
113
|
-
debug: parseBitString(buffer, block.position, block.length + block.position, 5000),
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function formatBuffer2DigitHexWithColum(buffer: Buffer): string {
|
|
118
|
-
const value: string[] = [];
|
|
119
|
-
for (let i = 0; i < buffer.length; i++) {
|
|
120
|
-
value.push(("00" + buffer.readUInt8(i).toString(16)).substr(-2, 2));
|
|
121
|
-
}
|
|
122
|
-
// remove leading 00
|
|
123
|
-
return value
|
|
124
|
-
.join(":")
|
|
125
|
-
.toUpperCase()
|
|
126
|
-
.replace(/^(00:)*/, "");
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function _readOctetString(buffer: Buffer, block: BlockInfo): Buffer {
|
|
130
|
-
assert(block.tag === TagType.OCTET_STRING);
|
|
131
|
-
const tag = readTag(buffer, block.position);
|
|
132
|
-
assert(tag.tag === TagType.OCTET_STRING);
|
|
133
|
-
|
|
134
|
-
const nbBytes = tag.length;
|
|
135
|
-
const pos = tag.position;
|
|
136
|
-
const b = buffer.slice(pos, pos + nbBytes);
|
|
137
|
-
return b;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function _getBlock(buffer: Buffer, block: BlockInfo): Buffer {
|
|
141
|
-
const start = block.position;
|
|
142
|
-
const end = block.position + block.length;
|
|
143
|
-
return buffer.slice(start, end);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export interface AlgorithmIdentifier {
|
|
147
|
-
identifier: string;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export function _readIntegerAsByteString(buffer: Buffer, block: BlockInfo): Buffer {
|
|
151
|
-
return _getBlock(buffer, block);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function _readListOfInteger(buffer: Buffer): Buffer[] {
|
|
155
|
-
const block = readTag(buffer, 0);
|
|
156
|
-
const inner_blocks = _readStruct(buffer, block);
|
|
157
|
-
return inner_blocks.map((bblock: BlockInfo) => {
|
|
158
|
-
return _readIntegerAsByteString(buffer, bblock);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function parseOID(buffer: Buffer, start: number, end: number): string {
|
|
163
|
-
// ASN.1 JavaScript decoder
|
|
164
|
-
// Copyright (c) 2008-2014 Lapo Luchini <lapo@lapo.it>
|
|
165
|
-
let s = "",
|
|
166
|
-
n = 0,
|
|
167
|
-
bits = 0;
|
|
168
|
-
for (let i = start; i < end; ++i) {
|
|
169
|
-
const v = buffer.readUInt8(i);
|
|
170
|
-
|
|
171
|
-
// tslint:disable-next-line: no-bitwise
|
|
172
|
-
n = n * 128 + (v & 0x7f);
|
|
173
|
-
bits += 7;
|
|
174
|
-
|
|
175
|
-
// noinspection JSBitwiseOperatorUsage
|
|
176
|
-
// tslint:disable-next-line: no-bitwise
|
|
177
|
-
if (!(v & 0x80)) {
|
|
178
|
-
// finished
|
|
179
|
-
if (s === "") {
|
|
180
|
-
const m = n < 80 ? (n < 40 ? 0 : 1) : 2;
|
|
181
|
-
s = m + "." + (n - m * 40);
|
|
182
|
-
} else {
|
|
183
|
-
s += "." + n.toString();
|
|
184
|
-
}
|
|
185
|
-
n = 0;
|
|
186
|
-
bits = 0;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
assert(bits === 0); // if (bits > 0) { s += ".incomplete"; }
|
|
190
|
-
return s;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function _readObjectIdentifier(buffer: Buffer, block: BlockInfo): { oid: string; name: string } {
|
|
194
|
-
assert(block.tag === TagType.OBJECT_IDENTIFIER);
|
|
195
|
-
const b = buffer.slice(block.position, block.position + block.length);
|
|
196
|
-
const oid = parseOID(b, 0, block.length);
|
|
197
|
-
return {
|
|
198
|
-
oid,
|
|
199
|
-
name: oid_map[oid] ? oid_map[oid].d : oid,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export function _readAlgorithmIdentifier(buffer: Buffer, block: BlockInfo): AlgorithmIdentifier {
|
|
204
|
-
const inner_blocks = _readStruct(buffer, block);
|
|
205
|
-
return {
|
|
206
|
-
identifier: _readObjectIdentifier(buffer, inner_blocks[0]).name,
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
export function _readECCAlgorithmIdentifier(buffer: Buffer, block: BlockInfo): AlgorithmIdentifier {
|
|
211
|
-
const inner_blocks = _readStruct(buffer, block);
|
|
212
|
-
return {
|
|
213
|
-
identifier: _readObjectIdentifier(buffer, inner_blocks[1]).name, // difference with RSA as algorithm is second element of nested block
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
export type SignatureValue = string;
|
|
218
|
-
|
|
219
|
-
export function _readSignatureValueBin(buffer: Buffer, block: BlockInfo): Buffer {
|
|
220
|
-
return _readBitString(buffer, block).data;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function _readSignatureValue(buffer: Buffer, block: BlockInfo): SignatureValue {
|
|
224
|
-
return _readSignatureValueBin(buffer, block).toString("hex");
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export function _readLongIntegerValue(buffer: Buffer, block: BlockInfo): Buffer {
|
|
228
|
-
assert(block.tag === TagType.INTEGER, "expecting a INTEGER tag");
|
|
229
|
-
const pos = block.position;
|
|
230
|
-
const nbBytes = block.length;
|
|
231
|
-
const buf = buffer.slice(pos, pos + nbBytes);
|
|
232
|
-
return buf;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export function _readIntegerValue(buffer: Buffer, block: BlockInfo): number {
|
|
236
|
-
assert(block.tag === TagType.INTEGER, "expecting a INTEGER tag");
|
|
237
|
-
let pos = block.position;
|
|
238
|
-
const nbBytes = block.length;
|
|
239
|
-
assert(nbBytes < 4);
|
|
240
|
-
let value = 0;
|
|
241
|
-
for (let i = 0; i < nbBytes; i++) {
|
|
242
|
-
value = value * 256 + buffer.readUInt8(pos);
|
|
243
|
-
pos += 1;
|
|
244
|
-
}
|
|
245
|
-
return value;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export function _readBooleanValue(buffer: Buffer, block: BlockInfo): boolean {
|
|
249
|
-
assert(block.tag === TagType.BOOLEAN, "expecting a BOOLEAN tag. got " + TagType[block.tag]);
|
|
250
|
-
const pos = block.position;
|
|
251
|
-
const nbBytes = block.length;
|
|
252
|
-
assert(nbBytes < 4);
|
|
253
|
-
const value = buffer.readUInt8(pos) ? true : false;
|
|
254
|
-
return value as boolean;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export function _readVersionValue(buffer: Buffer, block: BlockInfo): number {
|
|
258
|
-
block = readTag(buffer, block.position);
|
|
259
|
-
return _readIntegerValue(buffer, block);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/*
|
|
263
|
-
4.1.2.5.2 GeneralizedTime
|
|
264
|
-
|
|
265
|
-
The generalized time type, GeneralizedTime, is a standard ASN.1 type
|
|
266
|
-
for variable precision representation of time. Optionally, the
|
|
267
|
-
GeneralizedTime field can include a representation of the time
|
|
268
|
-
differential between local and Greenwich Mean Time.
|
|
269
|
-
|
|
270
|
-
For the purposes of this profile, GeneralizedTime values MUST be
|
|
271
|
-
expressed Greenwich Mean Time (Zulu) and MUST include seconds (i.e.,
|
|
272
|
-
times are YYYYMMDDHHMMSSZ), even where the number of seconds is zero.
|
|
273
|
-
GeneralizedTime values MUST NOT include fractional seconds.
|
|
274
|
-
|
|
275
|
-
*/
|
|
276
|
-
function convertGeneralizedTime(str: string): Date {
|
|
277
|
-
const year = parseInt(str.substr(0, 4), 10);
|
|
278
|
-
const month = parseInt(str.substr(4, 2), 10) - 1;
|
|
279
|
-
const day = parseInt(str.substr(6, 2), 10);
|
|
280
|
-
const hours = parseInt(str.substr(8, 2), 10);
|
|
281
|
-
const mins = parseInt(str.substr(10, 2), 10);
|
|
282
|
-
const secs = parseInt(str.substr(12, 2), 10);
|
|
283
|
-
|
|
284
|
-
return new Date(Date.UTC(year, month, day, hours, mins, secs));
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
function _readBMPString(buffer: Buffer, block: BlockInfo): string {
|
|
288
|
-
const strBuff = _getBlock(buffer, block);
|
|
289
|
-
let str = "";
|
|
290
|
-
for (let i = 0; i < strBuff.length; i += 2) {
|
|
291
|
-
const word = strBuff.readUInt16BE(i);
|
|
292
|
-
str += String.fromCharCode(word);
|
|
293
|
-
}
|
|
294
|
-
return str;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/*
|
|
298
|
-
http://tools.ietf.org/html/rfc5280
|
|
299
|
-
|
|
300
|
-
4.1.2.5. Validity
|
|
301
|
-
[...]
|
|
302
|
-
As conforming to this profile MUST always encode certificate
|
|
303
|
-
validity dates through the year 2049 as UTCTime; certificate validity
|
|
304
|
-
dates in 2050 or later MUST be encoded as GeneralizedTime.
|
|
305
|
-
Conforming applications MUST be able to process validity dates that
|
|
306
|
-
are encoded in either UTCTime or GeneralizedTime.
|
|
307
|
-
[...]
|
|
308
|
-
|
|
309
|
-
4.1.2.5.1 UTCTime
|
|
310
|
-
|
|
311
|
-
The universal time type, UTCTime, is a standard ASN.1 type intended
|
|
312
|
-
for representation of dates and time. UTCTime specifies the year
|
|
313
|
-
through the two low order digits and time is specified to the
|
|
314
|
-
precision of one minute or one second. UTCTime includes either Z
|
|
315
|
-
(for Zulu, or Greenwich Mean Time) or a time differential.
|
|
316
|
-
|
|
317
|
-
For the purposes of this profile, UTCTime values MUST be expressed
|
|
318
|
-
Greenwich Mean Time (Zulu) and MUST include seconds (i.e., times are
|
|
319
|
-
YYMMDDHHMMSSZ), even where the number of seconds is zero. Conforming
|
|
320
|
-
systems MUST interpret the year field (YY) as follows:
|
|
321
|
-
|
|
322
|
-
Where YY is greater than or equal to 50, the year SHALL be
|
|
323
|
-
interpreted as 19YY; and
|
|
324
|
-
|
|
325
|
-
Where YY is less than 50, the year SHALL be interpreted as 20YY.
|
|
326
|
-
*/
|
|
327
|
-
function convertUTCTime(str: string): Date {
|
|
328
|
-
let year = parseInt(str.substr(0, 2), 10);
|
|
329
|
-
const month = parseInt(str.substr(2, 2), 10) - 1;
|
|
330
|
-
const day = parseInt(str.substr(4, 2), 10);
|
|
331
|
-
const hours = parseInt(str.substr(6, 2), 10);
|
|
332
|
-
const mins = parseInt(str.substr(8, 2), 10);
|
|
333
|
-
const secs = parseInt(str.substr(10, 2), 10);
|
|
334
|
-
|
|
335
|
-
year += year >= 50 ? 1900 : 2000;
|
|
336
|
-
return new Date(Date.UTC(year, month, day, hours, mins, secs));
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
export function _readValue(buffer: Buffer, block: BlockInfo): any {
|
|
340
|
-
switch (block.tag) {
|
|
341
|
-
case TagType.BOOLEAN:
|
|
342
|
-
return _readBooleanValue(buffer, block);
|
|
343
|
-
case TagType.BMPString:
|
|
344
|
-
return _readBMPString(buffer, block);
|
|
345
|
-
case TagType.PrintableString:
|
|
346
|
-
case TagType.TeletexString:
|
|
347
|
-
case TagType.UTF8String:
|
|
348
|
-
case TagType.NumericString:
|
|
349
|
-
case TagType.IA5String:
|
|
350
|
-
return _getBlock(buffer, block).toString("ascii");
|
|
351
|
-
case TagType.UTCTime:
|
|
352
|
-
return convertUTCTime(_getBlock(buffer, block).toString("ascii"));
|
|
353
|
-
case TagType.GeneralizedTime:
|
|
354
|
-
return convertGeneralizedTime(_getBlock(buffer, block).toString("ascii"));
|
|
355
|
-
default:
|
|
356
|
-
throw new Error("Invalid tag 0x" + block.tag.toString(16) + "");
|
|
357
|
-
//xx return " ??? <" + block.tag + ">";
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
export interface DirectoryName {
|
|
362
|
-
stateOrProvinceName?: string;
|
|
363
|
-
localityName?: string;
|
|
364
|
-
organizationName?: string;
|
|
365
|
-
organizationUnitName?: string;
|
|
366
|
-
commonName?: string;
|
|
367
|
-
countryName?: string;
|
|
368
|
-
}
|
|
369
|
-
export function compactDirectoryName(d: DirectoryName): string {
|
|
370
|
-
return JSON.stringify(d);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export function _readDirectoryName(buffer: Buffer, block: BlockInfo): DirectoryName {
|
|
374
|
-
// AttributeTypeAndValue ::= SEQUENCE {
|
|
375
|
-
// type ATTRIBUTE.&id({SupportedAttributes}),
|
|
376
|
-
// value ATTRIBUTE.&Type({SupportedAttributes}{@type}),
|
|
377
|
-
const set_blocks = _readStruct(buffer, block);
|
|
378
|
-
const names: DirectoryName = {};
|
|
379
|
-
for (const set_block of set_blocks) {
|
|
380
|
-
assert(set_block.tag === 0x31);
|
|
381
|
-
const blocks = _readStruct(buffer, set_block);
|
|
382
|
-
assert(blocks.length === 1);
|
|
383
|
-
assert(blocks[0].tag === 0x30);
|
|
384
|
-
|
|
385
|
-
const sequenceBlock = _readStruct(buffer, blocks[0]);
|
|
386
|
-
assert(sequenceBlock.length === 2);
|
|
387
|
-
|
|
388
|
-
const type = _readObjectIdentifier(buffer, sequenceBlock[0]);
|
|
389
|
-
(names as any)[type.name] = _readValue(buffer, sequenceBlock[1]);
|
|
390
|
-
}
|
|
391
|
-
return names;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
export function _findBlockAtIndex(blocks: BlockInfo[], index: number): BlockInfo | null {
|
|
395
|
-
const tmp = blocks.filter((b: BlockInfo) => b.tag === 0xa0 + index || b.tag === 0x80 + index);
|
|
396
|
-
if (tmp.length === 0) {
|
|
397
|
-
return null;
|
|
398
|
-
}
|
|
399
|
-
return tmp[0];
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
export function _readTime(buffer: Buffer, block: BlockInfo): any {
|
|
403
|
-
return _readValue(buffer, block);
|
|
404
|
-
}
|
package/source/buffer_utils.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// note: new Buffer(size)# is deprecated since: v6.0. and is replaced with Buffer.allocUnsafe
|
|
3
|
-
// to ensure backward compatibility we have to replace
|
|
4
|
-
// new Buffer(size) with createFastUninitializedBuffer(size)
|
|
5
|
-
//
|
|
6
|
-
// Buffer.alloc and Buffer.allocUnsafe have been introduced in nodejs 5.1.0
|
|
7
|
-
// in node 0.11 new Buffer
|
|
8
|
-
//
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
* @private
|
|
12
|
-
*/
|
|
13
|
-
export const createFastUninitializedBuffer = Buffer.allocUnsafe
|
|
14
|
-
? Buffer.allocUnsafe
|
|
15
|
-
: (size: number): Buffer => {
|
|
16
|
-
// istanbul ignore next
|
|
17
|
-
return new Buffer(size);
|
|
18
|
-
};
|
package/source/common.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { KeyObject } from "node:crypto";
|
|
2
|
-
|
|
3
|
-
export type PrivateKey = KeyObject;
|
|
4
|
-
export type PublicKey = KeyObject;
|
|
5
|
-
|
|
6
|
-
export type Nonce = Buffer;
|
|
7
|
-
export type PEM = string;
|
|
8
|
-
export type DER = Buffer;
|
|
9
|
-
export type Certificate = DER;
|
|
10
|
-
export type CertificatePEM = PEM; // certificate as a PEM string
|
|
11
|
-
export type PrivateKeyPEM = PEM;
|
|
12
|
-
export type PublicKeyPEM = PEM;
|
|
13
|
-
|
|
14
|
-
export type Signature = Buffer;
|
|
15
|
-
export type CertificateRevocationList = Buffer;
|