node-opcua-crypto 5.1.0 → 5.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/dist/{source/index.js → chunk-ERHE4VFS.cjs} +466 -484
- package/dist/chunk-ERHE4VFS.cjs.map +1 -0
- package/dist/{chunk-ULG5CYBT.mjs → chunk-KCVNMSLI.js} +330 -252
- package/dist/chunk-KCVNMSLI.js.map +1 -0
- package/dist/chunk-LCGIBEY5.cjs +168 -0
- package/dist/chunk-LCGIBEY5.cjs.map +1 -0
- package/dist/{chunk-UXPULF3W.mjs → chunk-WXGEXWZG.js} +2 -2
- package/dist/index.cjs +185 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +96 -6673
- package/dist/index.js.map +1 -1
- package/dist/source/index_web.cjs +155 -0
- package/dist/source/index_web.cjs.map +1 -0
- package/dist/source/{index_web.d.mts → index_web.d.cts} +184 -159
- package/dist/source/index_web.d.ts +183 -158
- package/dist/source/index_web.js +80 -6517
- package/dist/source/index_web.js.map +1 -1
- package/dist/source_nodejs/index.cjs +34 -0
- package/dist/source_nodejs/index.cjs.map +1 -0
- package/dist/source_nodejs/{index.d.mts → index.d.cts} +1 -1
- package/dist/source_nodejs/index.js +19 -4141
- package/dist/source_nodejs/index.js.map +1 -1
- package/package.json +35 -16
- package/dist/chunk-RQA4DO2Z.mjs +0 -1
- package/dist/chunk-RQA4DO2Z.mjs.map +0 -1
- package/dist/chunk-ULG5CYBT.mjs.map +0 -1
- package/dist/index.d.mts +0 -5
- package/dist/index.mjs +0 -184
- package/dist/index.mjs.map +0 -1
- package/dist/source/index.d.mts +0 -4
- package/dist/source/index.d.ts +0 -4
- package/dist/source/index.js.map +0 -1
- package/dist/source/index.mjs +0 -154
- package/dist/source/index.mjs.map +0 -1
- package/dist/source/index_web.mjs +0 -153
- package/dist/source/index_web.mjs.map +0 -1
- package/dist/source_nodejs/index.mjs +0 -35
- package/dist/source_nodejs/index.mjs.map +0 -1
- /package/dist/{chunk-UXPULF3W.mjs.map → chunk-WXGEXWZG.js.map} +0 -0
- /package/dist/{common-DxHkx4Pv.d.mts → common-DxHkx4Pv.d.cts} +0 -0
|
@@ -1,116 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
|
|
8
2
|
var __export = (target, all) => {
|
|
9
3
|
for (var name in all)
|
|
10
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
5
|
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// source/index.ts
|
|
31
|
-
var source_exports = {};
|
|
32
|
-
__export(source_exports, {
|
|
33
|
-
CertificatePurpose: () => CertificatePurpose,
|
|
34
|
-
PaddingAlgorithm: () => PaddingAlgorithm,
|
|
35
|
-
RSA_PKCS1_OAEP_PADDING: () => RSA_PKCS1_OAEP_PADDING,
|
|
36
|
-
RSA_PKCS1_PADDING: () => RSA_PKCS1_PADDING,
|
|
37
|
-
Subject: () => Subject,
|
|
38
|
-
_coercePrivateKey: () => _coercePrivateKey,
|
|
39
|
-
asn1: () => asn1,
|
|
40
|
-
certificateMatchesPrivateKey: () => certificateMatchesPrivateKey,
|
|
41
|
-
coerceCertificate: () => coerceCertificate,
|
|
42
|
-
coerceCertificatePem: () => coerceCertificatePem,
|
|
43
|
-
coercePEMorDerToPrivateKey: () => coercePEMorDerToPrivateKey,
|
|
44
|
-
coercePrivateKeyPem: () => coercePrivateKeyPem,
|
|
45
|
-
coercePublicKeyPem: () => coercePublicKeyPem,
|
|
46
|
-
coerceRsaPublicKeyPem: () => coerceRsaPublicKeyPem,
|
|
47
|
-
combine_der: () => combine_der,
|
|
48
|
-
computeDerivedKeys: () => computeDerivedKeys,
|
|
49
|
-
computePaddingFooter: () => computePaddingFooter,
|
|
50
|
-
convertPEMtoDER: () => convertPEMtoDER,
|
|
51
|
-
createCertificateSigningRequest: () => createCertificateSigningRequest,
|
|
52
|
-
createPrivateKeyFromNodeJSCrypto: () => createPrivateKeyFromNodeJSCrypto,
|
|
53
|
-
createSelfSignedCertificate: () => createSelfSignedCertificate,
|
|
54
|
-
decryptBufferWithDerivedKeys: () => decryptBufferWithDerivedKeys,
|
|
55
|
-
derToPrivateKey: () => derToPrivateKey,
|
|
56
|
-
encryptBufferWithDerivedKeys: () => encryptBufferWithDerivedKeys,
|
|
57
|
-
exploreAsn1: () => exploreAsn1,
|
|
58
|
-
exploreCertificate: () => exploreCertificate,
|
|
59
|
-
exploreCertificateInfo: () => exploreCertificateInfo,
|
|
60
|
-
exploreCertificateRevocationList: () => exploreCertificateRevocationList,
|
|
61
|
-
exploreCertificateSigningRequest: () => exploreCertificateSigningRequest,
|
|
62
|
-
explorePrivateKey: () => explorePrivateKey,
|
|
63
|
-
extractPublicKeyFromCertificate: () => extractPublicKeyFromCertificate,
|
|
64
|
-
extractPublicKeyFromCertificateSync: () => extractPublicKeyFromCertificateSync,
|
|
65
|
-
generateKeyPair: () => generateKeyPair,
|
|
66
|
-
generatePrivateKey: () => generatePrivateKey,
|
|
67
|
-
hexDump: () => hexDump,
|
|
68
|
-
identifyPemType: () => identifyPemType,
|
|
69
|
-
isCrlIssuedByCertificate: () => isCrlIssuedByCertificate,
|
|
70
|
-
isKeyObject: () => isKeyObject,
|
|
71
|
-
makeMessageChunkSignature: () => makeMessageChunkSignature,
|
|
72
|
-
makeMessageChunkSignatureWithDerivedKeys: () => makeMessageChunkSignatureWithDerivedKeys,
|
|
73
|
-
makePrivateKeyFromPem: () => makePrivateKeyFromPem,
|
|
74
|
-
makePrivateKeyThumbPrint: () => makePrivateKeyThumbPrint,
|
|
75
|
-
makePseudoRandomBuffer: () => makePseudoRandomBuffer,
|
|
76
|
-
makeSHA1Thumbprint: () => makeSHA1Thumbprint,
|
|
77
|
-
pemToPrivateKey: () => pemToPrivateKey,
|
|
78
|
-
privateDecrypt: () => privateDecrypt,
|
|
79
|
-
privateDecrypt_long: () => privateDecrypt_long,
|
|
80
|
-
privateDecrypt_native: () => privateDecrypt_native,
|
|
81
|
-
privateKeyToPEM: () => privateKeyToPEM,
|
|
82
|
-
publicEncrypt: () => publicEncrypt,
|
|
83
|
-
publicEncrypt_long: () => publicEncrypt_long,
|
|
84
|
-
publicEncrypt_native: () => publicEncrypt_native,
|
|
85
|
-
publicKeyAndPrivateKeyMatches: () => publicKeyAndPrivateKeyMatches,
|
|
86
|
-
readCertificationRequestInfo: () => readCertificationRequestInfo,
|
|
87
|
-
readExtension: () => readExtension,
|
|
88
|
-
readNameForCrl: () => readNameForCrl,
|
|
89
|
-
readTbsCertificate: () => readTbsCertificate,
|
|
90
|
-
reduceLength: () => reduceLength,
|
|
91
|
-
removePadding: () => removePadding,
|
|
92
|
-
removeTrailingLF: () => removeTrailingLF,
|
|
93
|
-
rsaLengthPrivateKey: () => rsaLengthPrivateKey,
|
|
94
|
-
rsaLengthPublicKey: () => rsaLengthPublicKey,
|
|
95
|
-
rsaLengthRsaPublicKey: () => rsaLengthRsaPublicKey,
|
|
96
|
-
split_der: () => split_der,
|
|
97
|
-
toPem: () => toPem,
|
|
98
|
-
toPem2: () => toPem2,
|
|
99
|
-
verifyCertificateChain: () => verifyCertificateChain,
|
|
100
|
-
verifyCertificateOrClrSignature: () => verifyCertificateOrClrSignature,
|
|
101
|
-
verifyCertificateRevocationListSignature: () => verifyCertificateRevocationListSignature,
|
|
102
|
-
verifyCertificateSignature: () => verifyCertificateSignature,
|
|
103
|
-
verifyChunkSignature: () => verifyChunkSignature,
|
|
104
|
-
verifyChunkSignatureWithDerivedKeys: () => verifyChunkSignatureWithDerivedKeys,
|
|
105
|
-
verifyCrlIssuedByCertificate: () => verifyCrlIssuedByCertificate,
|
|
106
|
-
verifyMessageChunkSignature: () => verifyMessageChunkSignature
|
|
107
|
-
});
|
|
108
|
-
module.exports = __toCommonJS(source_exports);
|
|
109
6
|
|
|
110
7
|
// source/common.ts
|
|
111
|
-
var
|
|
112
|
-
var KeyObjectOrig =
|
|
113
|
-
var { createPrivateKey: createPrivateKeyFromNodeJSCrypto } =
|
|
8
|
+
var _crypto2 = require('crypto'); var _crypto3 = _interopRequireDefault(_crypto2);
|
|
9
|
+
var KeyObjectOrig = _crypto3.default.KeyObject;
|
|
10
|
+
var { createPrivateKey: createPrivateKeyFromNodeJSCrypto } = _crypto3.default;
|
|
114
11
|
function isKeyObject(mayBeKeyObject) {
|
|
115
12
|
if (KeyObjectOrig) {
|
|
116
13
|
return mayBeKeyObject instanceof KeyObjectOrig;
|
|
@@ -126,10 +23,10 @@ var CertificatePurpose = /* @__PURE__ */ ((CertificatePurpose2) => {
|
|
|
126
23
|
})(CertificatePurpose || {});
|
|
127
24
|
|
|
128
25
|
// source/crypto_explore_certificate.ts
|
|
129
|
-
var
|
|
26
|
+
var _assert = require('assert'); var _assert2 = _interopRequireDefault(_assert);
|
|
130
27
|
|
|
131
28
|
// source/asn1.ts
|
|
132
|
-
|
|
29
|
+
|
|
133
30
|
|
|
134
31
|
// source/oid_map.ts
|
|
135
32
|
var oid_map = {
|
|
@@ -503,12 +400,12 @@ function parseBitString(buffer, start, end, maxLength) {
|
|
|
503
400
|
s += b >> j & 1 ? "1" : "0";
|
|
504
401
|
}
|
|
505
402
|
skip = 0;
|
|
506
|
-
(0,
|
|
403
|
+
_assert2.default.call(void 0, s.length <= maxLength);
|
|
507
404
|
}
|
|
508
405
|
return intro + s;
|
|
509
406
|
}
|
|
510
407
|
function readBitString(buffer, block) {
|
|
511
|
-
(0,
|
|
408
|
+
_assert2.default.call(void 0, block.tag === 3 /* BIT_STRING */);
|
|
512
409
|
const data = getBlock(buffer, block);
|
|
513
410
|
const ignore_bits = data.readUInt8(0);
|
|
514
411
|
return {
|
|
@@ -526,9 +423,9 @@ function formatBuffer2DigitHexWithColum(buffer) {
|
|
|
526
423
|
return value.join(":").toUpperCase().replace(/^(00:)*/, "");
|
|
527
424
|
}
|
|
528
425
|
function readOctetString(buffer, block) {
|
|
529
|
-
(0,
|
|
426
|
+
_assert2.default.call(void 0, block.tag === 4 /* OCTET_STRING */);
|
|
530
427
|
const tag = readTag(buffer, block.position);
|
|
531
|
-
(0,
|
|
428
|
+
_assert2.default.call(void 0, tag.tag === 4 /* OCTET_STRING */);
|
|
532
429
|
const nbBytes = tag.length;
|
|
533
430
|
const pos = tag.position;
|
|
534
431
|
const b = buffer.subarray(pos, pos + nbBytes);
|
|
@@ -566,11 +463,11 @@ function parseOID(buffer, start, end) {
|
|
|
566
463
|
bits = 0;
|
|
567
464
|
}
|
|
568
465
|
}
|
|
569
|
-
(0,
|
|
466
|
+
_assert2.default.call(void 0, bits === 0);
|
|
570
467
|
return s;
|
|
571
468
|
}
|
|
572
469
|
function readObjectIdentifier(buffer, block) {
|
|
573
|
-
(0,
|
|
470
|
+
_assert2.default.call(void 0, block.tag === 6 /* OBJECT_IDENTIFIER */);
|
|
574
471
|
const b = buffer.subarray(block.position, block.position + block.length);
|
|
575
472
|
const oid = parseOID(b, 0, block.length);
|
|
576
473
|
return {
|
|
@@ -598,17 +495,17 @@ function readSignatureValue(buffer, block) {
|
|
|
598
495
|
return readSignatureValueBin(buffer, block).toString("hex");
|
|
599
496
|
}
|
|
600
497
|
function readLongIntegerValue(buffer, block) {
|
|
601
|
-
(0,
|
|
498
|
+
_assert2.default.call(void 0, block.tag === 2 /* INTEGER */, "expecting a INTEGER tag");
|
|
602
499
|
const pos = block.position;
|
|
603
500
|
const nbBytes = block.length;
|
|
604
501
|
const buf = buffer.subarray(pos, pos + nbBytes);
|
|
605
502
|
return buf;
|
|
606
503
|
}
|
|
607
504
|
function readIntegerValue(buffer, block) {
|
|
608
|
-
(0,
|
|
505
|
+
_assert2.default.call(void 0, block.tag === 2 /* INTEGER */, "expecting a INTEGER tag");
|
|
609
506
|
let pos = block.position;
|
|
610
507
|
const nbBytes = block.length;
|
|
611
|
-
(0,
|
|
508
|
+
_assert2.default.call(void 0, nbBytes < 4);
|
|
612
509
|
let value = 0;
|
|
613
510
|
for (let i = 0; i < nbBytes; i++) {
|
|
614
511
|
value = value * 256 + buffer.readUInt8(pos);
|
|
@@ -617,10 +514,10 @@ function readIntegerValue(buffer, block) {
|
|
|
617
514
|
return value;
|
|
618
515
|
}
|
|
619
516
|
function readBooleanValue(buffer, block) {
|
|
620
|
-
(0,
|
|
517
|
+
_assert2.default.call(void 0, block.tag === 1 /* BOOLEAN */, `expecting a BOOLEAN tag. got ${TagType[block.tag]}`);
|
|
621
518
|
const pos = block.position;
|
|
622
519
|
const nbBytes = block.length;
|
|
623
|
-
(0,
|
|
520
|
+
_assert2.default.call(void 0, nbBytes < 4);
|
|
624
521
|
const value = !!buffer.readUInt8(pos);
|
|
625
522
|
return value;
|
|
626
523
|
}
|
|
@@ -688,9 +585,16 @@ function readTime(buffer, block) {
|
|
|
688
585
|
}
|
|
689
586
|
|
|
690
587
|
// source/crypto_utils.ts
|
|
691
|
-
|
|
692
|
-
var
|
|
693
|
-
|
|
588
|
+
|
|
589
|
+
var _constants = require('constants'); var _constants2 = _interopRequireDefault(_constants);
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
694
598
|
|
|
695
599
|
// source/buffer_utils.ts
|
|
696
600
|
var createFastUninitializedBuffer = Buffer.allocUnsafe ? Buffer.allocUnsafe : (size) => {
|
|
@@ -707,9 +611,9 @@ function hexy(buffer, { width, format } = {}) {
|
|
|
707
611
|
const regexTwos = new RegExp(`.{1,${2}}`, "g");
|
|
708
612
|
let fullHex = buffer.toString("hex");
|
|
709
613
|
if (format === "twos") {
|
|
710
|
-
fullHex = fullHex.match(regexTwos)
|
|
614
|
+
fullHex = _optionalChain([fullHex, 'access', _ => _.match, 'call', _2 => _2(regexTwos), 'optionalAccess', _3 => _3.join, 'call', _4 => _4(" ")]) || "";
|
|
711
615
|
}
|
|
712
|
-
return fullHex.match(regex)
|
|
616
|
+
return _optionalChain([fullHex, 'access', _5 => _5.match, 'call', _6 => _6(regex), 'optionalAccess', _7 => _7.join, 'call', _8 => _8("\n")]) || "";
|
|
713
617
|
}
|
|
714
618
|
|
|
715
619
|
// source/crypto_utils.ts
|
|
@@ -727,14 +631,14 @@ function removeTrailingLF(str) {
|
|
|
727
631
|
return tmp;
|
|
728
632
|
}
|
|
729
633
|
function toPem(raw_key, pem) {
|
|
730
|
-
(0,
|
|
731
|
-
(0,
|
|
634
|
+
_assert2.default.call(void 0, raw_key, "expecting a key");
|
|
635
|
+
_assert2.default.call(void 0, typeof pem === "string");
|
|
732
636
|
let pemType = identifyPemType(raw_key);
|
|
733
637
|
if (pemType) {
|
|
734
638
|
return Buffer.isBuffer(raw_key) ? removeTrailingLF(raw_key.toString("utf8")) : removeTrailingLF(raw_key);
|
|
735
639
|
} else {
|
|
736
640
|
pemType = pem;
|
|
737
|
-
(0,
|
|
641
|
+
_assert2.default.call(void 0, ["CERTIFICATE REQUEST", "CERTIFICATE", "RSA PRIVATE KEY", "PUBLIC KEY", "X509 CRL"].indexOf(pemType) >= 0);
|
|
738
642
|
let b = raw_key.toString("base64");
|
|
739
643
|
let str = `-----BEGIN ${pemType}-----
|
|
740
644
|
`;
|
|
@@ -776,34 +680,34 @@ function hexDump(buffer, width) {
|
|
|
776
680
|
}
|
|
777
681
|
}
|
|
778
682
|
function makeMessageChunkSignature(chunk, options) {
|
|
779
|
-
const signer = (0,
|
|
683
|
+
const signer = _crypto2.createSign.call(void 0, options.algorithm);
|
|
780
684
|
signer.update(chunk);
|
|
781
685
|
const signature = signer.sign(options.privateKey.hidden);
|
|
782
|
-
(0,
|
|
686
|
+
_assert2.default.call(void 0, !options.signatureLength || signature.length === options.signatureLength);
|
|
783
687
|
return signature;
|
|
784
688
|
}
|
|
785
689
|
function verifyMessageChunkSignature(blockToVerify, signature, options) {
|
|
786
|
-
const verify = (0,
|
|
690
|
+
const verify = _crypto2.createVerify.call(void 0, options.algorithm);
|
|
787
691
|
verify.update(blockToVerify);
|
|
788
692
|
return verify.verify(options.publicKey, signature);
|
|
789
693
|
}
|
|
790
694
|
function makeSHA1Thumbprint(buffer) {
|
|
791
|
-
return (0,
|
|
695
|
+
return _crypto2.createHash.call(void 0, "sha1").update(buffer).digest();
|
|
792
696
|
}
|
|
793
|
-
var RSA_PKCS1_OAEP_PADDING =
|
|
794
|
-
var RSA_PKCS1_PADDING =
|
|
697
|
+
var RSA_PKCS1_OAEP_PADDING = _constants2.default.RSA_PKCS1_OAEP_PADDING;
|
|
698
|
+
var RSA_PKCS1_PADDING = _constants2.default.RSA_PKCS1_PADDING;
|
|
795
699
|
var PaddingAlgorithm = /* @__PURE__ */ ((PaddingAlgorithm2) => {
|
|
796
700
|
PaddingAlgorithm2[PaddingAlgorithm2["RSA_PKCS1_OAEP_PADDING"] = 4] = "RSA_PKCS1_OAEP_PADDING";
|
|
797
701
|
PaddingAlgorithm2[PaddingAlgorithm2["RSA_PKCS1_PADDING"] = 1] = "RSA_PKCS1_PADDING";
|
|
798
702
|
return PaddingAlgorithm2;
|
|
799
703
|
})(PaddingAlgorithm || {});
|
|
800
|
-
(0,
|
|
801
|
-
(0,
|
|
704
|
+
_assert2.default.call(void 0, 4 /* RSA_PKCS1_OAEP_PADDING */ === _constants2.default.RSA_PKCS1_OAEP_PADDING);
|
|
705
|
+
_assert2.default.call(void 0, 1 /* RSA_PKCS1_PADDING */ === _constants2.default.RSA_PKCS1_PADDING);
|
|
802
706
|
function publicEncrypt_native(buffer, publicKey, algorithm) {
|
|
803
707
|
if (algorithm === void 0) {
|
|
804
708
|
algorithm = 4 /* RSA_PKCS1_OAEP_PADDING */;
|
|
805
709
|
}
|
|
806
|
-
return (0,
|
|
710
|
+
return _crypto2.publicEncrypt.call(void 0,
|
|
807
711
|
{
|
|
808
712
|
key: publicKey,
|
|
809
713
|
padding: algorithm
|
|
@@ -816,7 +720,7 @@ function privateDecrypt_native(buffer, privateKey, algorithm) {
|
|
|
816
720
|
algorithm = 4 /* RSA_PKCS1_OAEP_PADDING */;
|
|
817
721
|
}
|
|
818
722
|
try {
|
|
819
|
-
return (0,
|
|
723
|
+
return _crypto2.privateDecrypt.call(void 0,
|
|
820
724
|
{
|
|
821
725
|
key: privateKey.hidden,
|
|
822
726
|
padding: algorithm
|
|
@@ -875,14 +779,14 @@ function coerceCertificatePem(certificate) {
|
|
|
875
779
|
if (Buffer.isBuffer(certificate)) {
|
|
876
780
|
certificate = toPem(certificate, "CERTIFICATE");
|
|
877
781
|
}
|
|
878
|
-
(0,
|
|
782
|
+
_assert2.default.call(void 0, typeof certificate === "string");
|
|
879
783
|
return certificate;
|
|
880
784
|
}
|
|
881
785
|
function extractPublicKeyFromCertificateSync(certificate) {
|
|
882
786
|
certificate = coerceCertificatePem(certificate);
|
|
883
|
-
const publicKeyObject = (0,
|
|
787
|
+
const publicKeyObject = _crypto2.createPublicKey.call(void 0, certificate);
|
|
884
788
|
const publicKeyAsPem = publicKeyObject.export({ format: "pem", type: "spki" }).toString();
|
|
885
|
-
(0,
|
|
789
|
+
_assert2.default.call(void 0, typeof publicKeyAsPem === "string");
|
|
886
790
|
return publicKeyAsPem;
|
|
887
791
|
}
|
|
888
792
|
function extractPublicKeyFromCertificate(certificate, callback) {
|
|
@@ -899,17 +803,17 @@ function extractPublicKeyFromCertificate(certificate, callback) {
|
|
|
899
803
|
}
|
|
900
804
|
|
|
901
805
|
// source/directory_name.ts
|
|
902
|
-
|
|
806
|
+
|
|
903
807
|
function readDirectoryName(buffer, block) {
|
|
904
808
|
const set_blocks = readStruct(buffer, block);
|
|
905
809
|
const names = {};
|
|
906
810
|
for (const set_block of set_blocks) {
|
|
907
|
-
(0,
|
|
811
|
+
_assert2.default.call(void 0, set_block.tag === 49);
|
|
908
812
|
const blocks = readStruct(buffer, set_block);
|
|
909
|
-
(0,
|
|
910
|
-
(0,
|
|
813
|
+
_assert2.default.call(void 0, blocks.length === 1);
|
|
814
|
+
_assert2.default.call(void 0, blocks[0].tag === 48);
|
|
911
815
|
const sequenceBlock = readStruct(buffer, blocks[0]);
|
|
912
|
-
(0,
|
|
816
|
+
_assert2.default.call(void 0, sequenceBlock.length === 2);
|
|
913
817
|
const type = readObjectIdentifier(buffer, sequenceBlock[0]);
|
|
914
818
|
names[type.name] = readValue(buffer, sequenceBlock[1]);
|
|
915
819
|
}
|
|
@@ -1034,7 +938,7 @@ function _readGeneralNames(buffer, block) {
|
|
|
1034
938
|
}
|
|
1035
939
|
const n = {};
|
|
1036
940
|
for (const block2 of blocks) {
|
|
1037
|
-
(0,
|
|
941
|
+
_assert2.default.call(void 0, (block2.tag & 128) === 128);
|
|
1038
942
|
const t2 = block2.tag & 127;
|
|
1039
943
|
const type = _data[t2];
|
|
1040
944
|
if (!type) {
|
|
@@ -1094,7 +998,7 @@ function readKeyUsage(_oid, buffer) {
|
|
|
1094
998
|
};
|
|
1095
999
|
}
|
|
1096
1000
|
function readExtKeyUsage(oid, buffer) {
|
|
1097
|
-
(0,
|
|
1001
|
+
_assert2.default.call(void 0, oid === "2.5.29.37");
|
|
1098
1002
|
const block_info = readTag(buffer, 0);
|
|
1099
1003
|
const inner_blocks = readStruct(buffer, block_info);
|
|
1100
1004
|
const extKeyUsage = {
|
|
@@ -1124,7 +1028,7 @@ function _readSubjectPublicKey(buffer) {
|
|
|
1124
1028
|
function readExtension(buffer, block) {
|
|
1125
1029
|
const inner_blocks = readStruct(buffer, block);
|
|
1126
1030
|
if (inner_blocks.length === 3) {
|
|
1127
|
-
(0,
|
|
1031
|
+
_assert2.default.call(void 0, inner_blocks[1].tag === 1 /* BOOLEAN */);
|
|
1128
1032
|
inner_blocks[1] = inner_blocks[2];
|
|
1129
1033
|
}
|
|
1130
1034
|
const identifier = readObjectIdentifier(buffer, inner_blocks[0]);
|
|
@@ -1161,7 +1065,7 @@ function readExtension(buffer, block) {
|
|
|
1161
1065
|
};
|
|
1162
1066
|
}
|
|
1163
1067
|
function _readExtensions(buffer, block) {
|
|
1164
|
-
(0,
|
|
1068
|
+
_assert2.default.call(void 0, block.tag === 163);
|
|
1165
1069
|
let inner_blocks = readStruct(buffer, block);
|
|
1166
1070
|
inner_blocks = readStruct(buffer, inner_blocks[0]);
|
|
1167
1071
|
const extensions = inner_blocks.map((block2) => readExtension(buffer, block2));
|
|
@@ -1239,7 +1143,7 @@ function readTbsCertificate(buffer, block) {
|
|
|
1239
1143
|
break;
|
|
1240
1144
|
}
|
|
1241
1145
|
default: {
|
|
1242
|
-
(0,
|
|
1146
|
+
_assert2.default.call(void 0, what_type === "ecPublicKey");
|
|
1243
1147
|
subjectPublicKeyInfo = _readSubjectECCPublicKeyInfo(buffer, blocks[6]);
|
|
1244
1148
|
break;
|
|
1245
1149
|
}
|
|
@@ -1265,7 +1169,7 @@ function readTbsCertificate(buffer, block) {
|
|
|
1265
1169
|
};
|
|
1266
1170
|
}
|
|
1267
1171
|
function exploreCertificate(certificate) {
|
|
1268
|
-
(0,
|
|
1172
|
+
_assert2.default.call(void 0, Buffer.isBuffer(certificate));
|
|
1269
1173
|
const certificate_priv = certificate;
|
|
1270
1174
|
if (!certificate_priv._exploreCertificate_cache) {
|
|
1271
1175
|
const block_info = readTag(certificate, 0);
|
|
@@ -1295,10 +1199,10 @@ function combine_der(certificates) {
|
|
|
1295
1199
|
let sum = 0;
|
|
1296
1200
|
b.forEach((block) => {
|
|
1297
1201
|
const block_info = readTag(block, 0);
|
|
1298
|
-
(0,
|
|
1202
|
+
_assert2.default.call(void 0, block_info.position + block_info.length === block.length);
|
|
1299
1203
|
sum += block.length;
|
|
1300
1204
|
});
|
|
1301
|
-
(0,
|
|
1205
|
+
_assert2.default.call(void 0, sum === cert.length);
|
|
1302
1206
|
}
|
|
1303
1207
|
return Buffer.concat(certificates);
|
|
1304
1208
|
}
|
|
@@ -1364,7 +1268,7 @@ function exploreCertificateRevocationList(crl) {
|
|
|
1364
1268
|
}
|
|
1365
1269
|
|
|
1366
1270
|
// source/verify_certificate_signature.ts
|
|
1367
|
-
|
|
1271
|
+
|
|
1368
1272
|
function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
1369
1273
|
const block_info = readTag(certificateOrCrl, 0);
|
|
1370
1274
|
const blocks = readStruct(certificateOrCrl, block_info);
|
|
@@ -1373,7 +1277,7 @@ function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
|
1373
1277
|
const signatureValue = readSignatureValueBin(certificateOrCrl, blocks[2]);
|
|
1374
1278
|
const p = split_der(parentCertificate)[0];
|
|
1375
1279
|
const certPem = toPem(p, "CERTIFICATE");
|
|
1376
|
-
const verify = (0,
|
|
1280
|
+
const verify = _crypto2.createVerify.call(void 0, signatureAlgorithm.identifier);
|
|
1377
1281
|
verify.update(bufferToBeSigned);
|
|
1378
1282
|
verify.end();
|
|
1379
1283
|
return verify.verify(certPem, signatureValue);
|
|
@@ -1389,7 +1293,7 @@ async function verifyCertificateChain(certificateChain) {
|
|
|
1389
1293
|
const cert = certificateChain[index - 1];
|
|
1390
1294
|
const certParent = certificateChain[index];
|
|
1391
1295
|
const certParentInfo = exploreCertificate(certParent);
|
|
1392
|
-
const keyUsage = certParentInfo.tbsCertificate.extensions
|
|
1296
|
+
const keyUsage = _optionalChain([certParentInfo, 'access', _9 => _9.tbsCertificate, 'access', _10 => _10.extensions, 'optionalAccess', _11 => _11.keyUsage]);
|
|
1393
1297
|
if (!keyUsage || !keyUsage.keyCertSign) {
|
|
1394
1298
|
return {
|
|
1395
1299
|
status: "BadCertificateIssuerUseNotAllowed",
|
|
@@ -1442,79 +1346,40 @@ function verifyCrlIssuedByCertificate(crl, certificate) {
|
|
|
1442
1346
|
return verifyCertificateRevocationListSignature(crl, certificate);
|
|
1443
1347
|
}
|
|
1444
1348
|
|
|
1445
|
-
// source/
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
function rsaLengthPrivateKey(key) {
|
|
1449
|
-
const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
|
|
1450
|
-
const keyObject = (0, import_node_crypto4.createPrivateKey)(keyPem);
|
|
1451
|
-
const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
|
|
1452
|
-
(0, import_node_assert5.default)(modulusLength, "Cannot determine modulus length from private key");
|
|
1453
|
-
return modulusLength / 8;
|
|
1454
|
-
}
|
|
1455
|
-
function toPem2(raw_key, pem) {
|
|
1456
|
-
if (raw_key.hidden) {
|
|
1457
|
-
return toPem2(raw_key.hidden, pem);
|
|
1458
|
-
}
|
|
1459
|
-
(0, import_node_assert5.default)(raw_key, "expecting a key");
|
|
1460
|
-
(0, import_node_assert5.default)(typeof pem === "string");
|
|
1461
|
-
if (isKeyObject(raw_key)) {
|
|
1462
|
-
const _raw_key = raw_key;
|
|
1463
|
-
if (pem === "RSA PRIVATE KEY") {
|
|
1464
|
-
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs1" }).toString());
|
|
1465
|
-
} else if (pem === "PRIVATE KEY") {
|
|
1466
|
-
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs8" }).toString());
|
|
1467
|
-
} else {
|
|
1468
|
-
throw new Error("Unsupported case!");
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
return toPem(raw_key, pem);
|
|
1472
|
-
}
|
|
1473
|
-
function coercePrivateKeyPem(privateKey) {
|
|
1474
|
-
return toPem2(privateKey, "PRIVATE KEY");
|
|
1349
|
+
// source/explore_asn1.ts
|
|
1350
|
+
function t(tag) {
|
|
1351
|
+
return TagType[tag];
|
|
1475
1352
|
}
|
|
1476
|
-
function
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
}
|
|
1480
|
-
(0, import_node_assert5.default)(typeof publicKey === "string");
|
|
1481
|
-
return publicKey;
|
|
1353
|
+
function bi(blockInfo, depth) {
|
|
1354
|
+
const indent = " ".repeat(depth);
|
|
1355
|
+
const hl = blockInfo.position - blockInfo.start;
|
|
1356
|
+
return `${blockInfo.start.toString().padStart(5, " ")}:d=${depth} hl=${hl.toString().padEnd(3, " ")} l=${blockInfo.length.toString().padStart(6, " ")} ${blockInfo.tag.toString(16).padEnd(2, " ")} ${indent} ${t(blockInfo.tag)}`;
|
|
1482
1357
|
}
|
|
1483
|
-
function
|
|
1484
|
-
|
|
1485
|
-
|
|
1358
|
+
function exploreAsn1(buffer) {
|
|
1359
|
+
console.log(hexDump(buffer));
|
|
1360
|
+
function dump(offset, depth) {
|
|
1361
|
+
const blockInfo = readTag(buffer, offset);
|
|
1362
|
+
dumpBlock(blockInfo, depth);
|
|
1363
|
+
function dumpBlock(blockInfo2, depth2) {
|
|
1364
|
+
console.log(bi(blockInfo2, depth2));
|
|
1365
|
+
if (blockInfo2.tag === 48 /* SEQUENCE */ || blockInfo2.tag === 49 /* SET */ || blockInfo2.tag >= 160 /* CONTEXT_SPECIFIC0 */) {
|
|
1366
|
+
const blocks = readStruct(buffer, blockInfo2);
|
|
1367
|
+
for (const block of blocks) {
|
|
1368
|
+
dumpBlock(block, depth2 + 1);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1486
1372
|
}
|
|
1487
|
-
(0,
|
|
1488
|
-
return publicKey;
|
|
1489
|
-
}
|
|
1490
|
-
function rsaLengthPublicKey(key) {
|
|
1491
|
-
key = coercePublicKeyPem(key);
|
|
1492
|
-
(0, import_node_assert5.default)(typeof key === "string");
|
|
1493
|
-
const keyObject = (0, import_node_crypto4.createPublicKey)(key);
|
|
1494
|
-
const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
|
|
1495
|
-
(0, import_node_assert5.default)(modulusLength, "Cannot determine modulus length from public key");
|
|
1496
|
-
return modulusLength / 8;
|
|
1497
|
-
}
|
|
1498
|
-
function rsaLengthRsaPublicKey(key) {
|
|
1499
|
-
key = coerceRsaPublicKeyPem(key);
|
|
1500
|
-
(0, import_node_assert5.default)(typeof key === "string");
|
|
1501
|
-
const keyObject = (0, import_node_crypto4.createPublicKey)(key);
|
|
1502
|
-
const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
|
|
1503
|
-
(0, import_node_assert5.default)(modulusLength, "Cannot determine modulus length from public key");
|
|
1504
|
-
return modulusLength / 8;
|
|
1373
|
+
dump(0, 0);
|
|
1505
1374
|
}
|
|
1506
1375
|
|
|
1507
|
-
// source/derived_keys.ts
|
|
1508
|
-
var import_node_assert7 = __toESM(require("assert"));
|
|
1509
|
-
var import_node_crypto5 = require("crypto");
|
|
1510
|
-
|
|
1511
1376
|
// source/explore_certificate.ts
|
|
1512
|
-
|
|
1377
|
+
|
|
1513
1378
|
function coerceCertificate(certificate) {
|
|
1514
1379
|
if (typeof certificate === "string") {
|
|
1515
1380
|
certificate = convertPEMtoDER(certificate);
|
|
1516
1381
|
}
|
|
1517
|
-
(0,
|
|
1382
|
+
_assert2.default.call(void 0, Buffer.isBuffer(certificate));
|
|
1518
1383
|
return certificate;
|
|
1519
1384
|
}
|
|
1520
1385
|
function exploreCertificateInfo(certificate) {
|
|
@@ -1533,146 +1398,6 @@ function exploreCertificateInfo(certificate) {
|
|
|
1533
1398
|
return data;
|
|
1534
1399
|
}
|
|
1535
1400
|
|
|
1536
|
-
// source/derived_keys.ts
|
|
1537
|
-
function HMAC_HASH(sha1or256, secret, message) {
|
|
1538
|
-
return (0, import_node_crypto5.createHmac)(sha1or256, secret).update(message).digest();
|
|
1539
|
-
}
|
|
1540
|
-
function plus(buf1, buf2) {
|
|
1541
|
-
return Buffer.concat([buf1, buf2]);
|
|
1542
|
-
}
|
|
1543
|
-
function makePseudoRandomBuffer(secret, seed, minLength, sha1or256) {
|
|
1544
|
-
(0, import_node_assert7.default)(Buffer.isBuffer(seed));
|
|
1545
|
-
(0, import_node_assert7.default)(sha1or256 === "SHA1" || sha1or256 === "SHA256");
|
|
1546
|
-
const a = [];
|
|
1547
|
-
a[0] = seed;
|
|
1548
|
-
let index = 1;
|
|
1549
|
-
let p_hash = createFastUninitializedBuffer(0);
|
|
1550
|
-
while (p_hash.length <= minLength) {
|
|
1551
|
-
a[index] = HMAC_HASH(sha1or256, secret, a[index - 1]);
|
|
1552
|
-
p_hash = plus(p_hash, HMAC_HASH(sha1or256, secret, plus(a[index], seed)));
|
|
1553
|
-
index += 1;
|
|
1554
|
-
}
|
|
1555
|
-
return p_hash.subarray(0, minLength);
|
|
1556
|
-
}
|
|
1557
|
-
function computeDerivedKeys(secret, seed, options) {
|
|
1558
|
-
(0, import_node_assert7.default)(Number.isFinite(options.signatureLength));
|
|
1559
|
-
(0, import_node_assert7.default)(Number.isFinite(options.encryptingKeyLength));
|
|
1560
|
-
(0, import_node_assert7.default)(Number.isFinite(options.encryptingBlockSize));
|
|
1561
|
-
(0, import_node_assert7.default)(typeof options.algorithm === "string");
|
|
1562
|
-
options.sha1or256 = options.sha1or256 || "SHA1";
|
|
1563
|
-
(0, import_node_assert7.default)(typeof options.sha1or256 === "string");
|
|
1564
|
-
const offset1 = options.signingKeyLength;
|
|
1565
|
-
const offset2 = offset1 + options.encryptingKeyLength;
|
|
1566
|
-
const minLength = offset2 + options.encryptingBlockSize;
|
|
1567
|
-
const buf = makePseudoRandomBuffer(secret, seed, minLength, options.sha1or256);
|
|
1568
|
-
return {
|
|
1569
|
-
signatureLength: options.signatureLength,
|
|
1570
|
-
signingKeyLength: options.signingKeyLength,
|
|
1571
|
-
encryptingKeyLength: options.encryptingKeyLength,
|
|
1572
|
-
encryptingBlockSize: options.encryptingBlockSize,
|
|
1573
|
-
algorithm: options.algorithm,
|
|
1574
|
-
sha1or256: options.sha1or256,
|
|
1575
|
-
signingKey: buf.subarray(0, offset1),
|
|
1576
|
-
encryptingKey: buf.subarray(offset1, offset2),
|
|
1577
|
-
initializationVector: buf.subarray(offset2, minLength)
|
|
1578
|
-
};
|
|
1579
|
-
}
|
|
1580
|
-
function reduceLength(buffer, byteToRemove) {
|
|
1581
|
-
return buffer.subarray(0, buffer.length - byteToRemove);
|
|
1582
|
-
}
|
|
1583
|
-
function removePadding(buffer) {
|
|
1584
|
-
const nbPaddingBytes = buffer.readUInt8(buffer.length - 1) + 1;
|
|
1585
|
-
return reduceLength(buffer, nbPaddingBytes);
|
|
1586
|
-
}
|
|
1587
|
-
function verifyChunkSignature(chunk, options) {
|
|
1588
|
-
(0, import_node_assert7.default)(Buffer.isBuffer(chunk));
|
|
1589
|
-
let signatureLength = options.signatureLength || 0;
|
|
1590
|
-
if (signatureLength === 0) {
|
|
1591
|
-
const cert = exploreCertificateInfo(options.publicKey);
|
|
1592
|
-
signatureLength = cert.publicKeyLength || 0;
|
|
1593
|
-
}
|
|
1594
|
-
const block_to_verify = chunk.subarray(0, chunk.length - signatureLength);
|
|
1595
|
-
const signature = chunk.subarray(chunk.length - signatureLength);
|
|
1596
|
-
return verifyMessageChunkSignature(block_to_verify, signature, options);
|
|
1597
|
-
}
|
|
1598
|
-
function computePaddingFooter(buffer, derivedKeys) {
|
|
1599
|
-
(0, import_node_assert7.default)(Object.hasOwn(derivedKeys, "encryptingBlockSize"));
|
|
1600
|
-
const paddingSize = derivedKeys.encryptingBlockSize - (buffer.length + 1) % derivedKeys.encryptingBlockSize;
|
|
1601
|
-
const padding = createFastUninitializedBuffer(paddingSize + 1);
|
|
1602
|
-
padding.fill(paddingSize);
|
|
1603
|
-
return padding;
|
|
1604
|
-
}
|
|
1605
|
-
function derivedKeys_algorithm(derivedKeys) {
|
|
1606
|
-
(0, import_node_assert7.default)(Object.hasOwn(derivedKeys, "algorithm"));
|
|
1607
|
-
const algorithm = derivedKeys.algorithm || "aes-128-cbc";
|
|
1608
|
-
(0, import_node_assert7.default)(algorithm === "aes-128-cbc" || algorithm === "aes-256-cbc");
|
|
1609
|
-
return algorithm;
|
|
1610
|
-
}
|
|
1611
|
-
function encryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
1612
|
-
const algorithm = derivedKeys_algorithm(derivedKeys);
|
|
1613
|
-
const key = derivedKeys.encryptingKey;
|
|
1614
|
-
const initVector = derivedKeys.initializationVector;
|
|
1615
|
-
const cipher = (0, import_node_crypto5.createCipheriv)(algorithm, key, initVector);
|
|
1616
|
-
cipher.setAutoPadding(false);
|
|
1617
|
-
const encrypted_chunks = [];
|
|
1618
|
-
encrypted_chunks.push(cipher.update(buffer));
|
|
1619
|
-
encrypted_chunks.push(cipher.final());
|
|
1620
|
-
return Buffer.concat(encrypted_chunks);
|
|
1621
|
-
}
|
|
1622
|
-
function decryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
1623
|
-
const algorithm = derivedKeys_algorithm(derivedKeys);
|
|
1624
|
-
const key = derivedKeys.encryptingKey;
|
|
1625
|
-
const initVector = derivedKeys.initializationVector;
|
|
1626
|
-
const cipher = (0, import_node_crypto5.createDecipheriv)(algorithm, key, initVector);
|
|
1627
|
-
cipher.setAutoPadding(false);
|
|
1628
|
-
const decrypted_chunks = [];
|
|
1629
|
-
decrypted_chunks.push(cipher.update(buffer));
|
|
1630
|
-
decrypted_chunks.push(cipher.final());
|
|
1631
|
-
return Buffer.concat(decrypted_chunks);
|
|
1632
|
-
}
|
|
1633
|
-
function makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys) {
|
|
1634
|
-
(0, import_node_assert7.default)(Buffer.isBuffer(message));
|
|
1635
|
-
(0, import_node_assert7.default)(Buffer.isBuffer(derivedKeys.signingKey));
|
|
1636
|
-
(0, import_node_assert7.default)(typeof derivedKeys.sha1or256 === "string");
|
|
1637
|
-
(0, import_node_assert7.default)(derivedKeys.sha1or256 === "SHA1" || derivedKeys.sha1or256 === "SHA256");
|
|
1638
|
-
const signature = (0, import_node_crypto5.createHmac)(derivedKeys.sha1or256, derivedKeys.signingKey).update(message).digest();
|
|
1639
|
-
(0, import_node_assert7.default)(signature.length === derivedKeys.signatureLength);
|
|
1640
|
-
return signature;
|
|
1641
|
-
}
|
|
1642
|
-
function verifyChunkSignatureWithDerivedKeys(chunk, derivedKeys) {
|
|
1643
|
-
const message = chunk.subarray(0, chunk.length - derivedKeys.signatureLength);
|
|
1644
|
-
const expectedSignature = chunk.subarray(chunk.length - derivedKeys.signatureLength);
|
|
1645
|
-
const computedSignature = makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys);
|
|
1646
|
-
return computedSignature.toString("hex") === expectedSignature.toString("hex");
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
// source/explore_asn1.ts
|
|
1650
|
-
function t(tag) {
|
|
1651
|
-
return TagType[tag];
|
|
1652
|
-
}
|
|
1653
|
-
function bi(blockInfo, depth) {
|
|
1654
|
-
const indent = " ".repeat(depth);
|
|
1655
|
-
const hl = blockInfo.position - blockInfo.start;
|
|
1656
|
-
return `${blockInfo.start.toString().padStart(5, " ")}:d=${depth} hl=${hl.toString().padEnd(3, " ")} l=${blockInfo.length.toString().padStart(6, " ")} ${blockInfo.tag.toString(16).padEnd(2, " ")} ${indent} ${t(blockInfo.tag)}`;
|
|
1657
|
-
}
|
|
1658
|
-
function exploreAsn1(buffer) {
|
|
1659
|
-
console.log(hexDump(buffer));
|
|
1660
|
-
function dump(offset, depth) {
|
|
1661
|
-
const blockInfo = readTag(buffer, offset);
|
|
1662
|
-
dumpBlock(blockInfo, depth);
|
|
1663
|
-
function dumpBlock(blockInfo2, depth2) {
|
|
1664
|
-
console.log(bi(blockInfo2, depth2));
|
|
1665
|
-
if (blockInfo2.tag === 48 /* SEQUENCE */ || blockInfo2.tag === 49 /* SET */ || blockInfo2.tag >= 160 /* CONTEXT_SPECIFIC0 */) {
|
|
1666
|
-
const blocks = readStruct(buffer, blockInfo2);
|
|
1667
|
-
for (const block of blocks) {
|
|
1668
|
-
dumpBlock(block, depth2 + 1);
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
dump(0, 0);
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
1401
|
// source/explore_certificate_signing_request.ts
|
|
1677
1402
|
function _readExtensionRequest(buffer) {
|
|
1678
1403
|
const block = readTag(buffer, 0);
|
|
@@ -1798,39 +1523,76 @@ function explorePrivateKey(privateKey2) {
|
|
|
1798
1523
|
};
|
|
1799
1524
|
}
|
|
1800
1525
|
|
|
1801
|
-
// source/
|
|
1802
|
-
function
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1526
|
+
// source/identify_der.ts
|
|
1527
|
+
function identifyDERContent(buffer) {
|
|
1528
|
+
if (!Buffer.isBuffer(buffer) || buffer.length < 2) {
|
|
1529
|
+
return "Unknown";
|
|
1530
|
+
}
|
|
1531
|
+
try {
|
|
1532
|
+
const outer = readTag(buffer, 0);
|
|
1533
|
+
if (outer.tag !== 48 /* SEQUENCE */) {
|
|
1534
|
+
return "Unknown";
|
|
1535
|
+
}
|
|
1536
|
+
const outerEnd = outer.position + outer.length;
|
|
1537
|
+
if (outerEnd < buffer.length) {
|
|
1538
|
+
const next = readTag(buffer, outerEnd);
|
|
1539
|
+
if (next.tag === 48 /* SEQUENCE */) {
|
|
1540
|
+
return "X509CertificateChain";
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
const blocks = readStruct(buffer, outer);
|
|
1544
|
+
if (blocks.length < 2) {
|
|
1545
|
+
return "Unknown";
|
|
1546
|
+
}
|
|
1547
|
+
if (blocks[0].tag === 2 /* INTEGER */) {
|
|
1548
|
+
const versionByte = buffer[blocks[0].position];
|
|
1549
|
+
if (blocks[0].length === 1 && versionByte === 3) {
|
|
1550
|
+
return "PKCS12";
|
|
1551
|
+
}
|
|
1552
|
+
if (blocks[0].length === 1 && versionByte === 0) {
|
|
1553
|
+
return "PrivateKey";
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
if (blocks[0].tag !== 48 /* SEQUENCE */) {
|
|
1557
|
+
return "Unknown";
|
|
1558
|
+
}
|
|
1559
|
+
const tbsBlocks = readStruct(buffer, blocks[0]);
|
|
1560
|
+
if (tbsBlocks.length === 0) {
|
|
1561
|
+
return "Unknown";
|
|
1562
|
+
}
|
|
1563
|
+
if (tbsBlocks[0].tag === 160 /* CONTEXT_SPECIFIC0 */) {
|
|
1564
|
+
return "X509Certificate";
|
|
1565
|
+
}
|
|
1566
|
+
if (tbsBlocks[0].tag === 2 /* INTEGER */) {
|
|
1567
|
+
const intLen = tbsBlocks[0].length;
|
|
1568
|
+
const intVal = intLen === 1 ? buffer[tbsBlocks[0].position] : -1;
|
|
1569
|
+
if (intVal === 0 && tbsBlocks.length >= 4) {
|
|
1570
|
+
if (tbsBlocks[3].tag === 160 /* CONTEXT_SPECIFIC0 */) {
|
|
1571
|
+
return "CertificateSigningRequest";
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
if (intVal === 1 && tbsBlocks.length >= 4) {
|
|
1575
|
+
const tag3 = tbsBlocks[3].tag;
|
|
1576
|
+
if (tag3 === 23 /* UTCTime */ || tag3 === 24 /* GeneralizedTime */) {
|
|
1577
|
+
return "CertificateRevocationList";
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
if (tbsBlocks.length >= 6) {
|
|
1581
|
+
if (tbsBlocks[3].tag === 48 /* SEQUENCE */) {
|
|
1582
|
+
return "X509Certificate";
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
if (tbsBlocks[0].tag === 48 /* SEQUENCE */ && tbsBlocks.length >= 3) {
|
|
1587
|
+
const tag2 = tbsBlocks[2].tag;
|
|
1588
|
+
if (tag2 === 23 /* UTCTime */ || tag2 === 24 /* GeneralizedTime */) {
|
|
1589
|
+
return "CertificateRevocationList";
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
return "Unknown";
|
|
1593
|
+
} catch (e2) {
|
|
1594
|
+
return "Unknown";
|
|
1819
1595
|
}
|
|
1820
|
-
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
1821
|
-
}
|
|
1822
|
-
function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
1823
|
-
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
1824
|
-
const encryptedBuffer = publicEncrypt_long(initialBuffer, certificate, blockSize);
|
|
1825
|
-
const decryptedBuffer = privateDecrypt_long(encryptedBuffer, privateKey, blockSize);
|
|
1826
|
-
const finalString = decryptedBuffer.toString("utf-8");
|
|
1827
|
-
return initialBuffer.toString("utf-8") === finalString;
|
|
1828
|
-
}
|
|
1829
|
-
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
1830
|
-
const e = explorePrivateKey(privateKey);
|
|
1831
|
-
const blockSize = e.modulus.length;
|
|
1832
|
-
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
1833
|
-
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
1834
1596
|
}
|
|
1835
1597
|
|
|
1836
1598
|
// source/subject.ts
|
|
@@ -1854,6 +1616,13 @@ var unquote2 = (str) => {
|
|
|
1854
1616
|
return m ? m[1] : str;
|
|
1855
1617
|
};
|
|
1856
1618
|
var Subject = class _Subject {
|
|
1619
|
+
|
|
1620
|
+
|
|
1621
|
+
|
|
1622
|
+
|
|
1623
|
+
|
|
1624
|
+
|
|
1625
|
+
|
|
1857
1626
|
constructor(options) {
|
|
1858
1627
|
if (typeof options === "string") {
|
|
1859
1628
|
options = _Subject.parse(options);
|
|
@@ -1921,17 +1690,17 @@ var Subject = class _Subject {
|
|
|
1921
1690
|
};
|
|
1922
1691
|
|
|
1923
1692
|
// source/x509/_crypto.ts
|
|
1924
|
-
|
|
1925
|
-
var
|
|
1926
|
-
var
|
|
1927
|
-
|
|
1693
|
+
|
|
1694
|
+
var _webcrypto = require('@peculiar/webcrypto');
|
|
1695
|
+
var _x509 = require('@peculiar/x509'); var x509 = _interopRequireWildcard(_x509); var x5092 = _interopRequireWildcard(_x509);
|
|
1696
|
+
|
|
1928
1697
|
var doDebug3 = false;
|
|
1929
1698
|
var _crypto;
|
|
1930
1699
|
var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
|
|
1931
1700
|
if (typeof window === "undefined") {
|
|
1932
|
-
_crypto =
|
|
1933
|
-
if (!_crypto
|
|
1934
|
-
_crypto = new
|
|
1701
|
+
_crypto = _crypto3.default;
|
|
1702
|
+
if (!_optionalChain([_crypto, 'optionalAccess', _12 => _12.subtle]) || ignoreCrypto) {
|
|
1703
|
+
_crypto = new (0, _webcrypto.Crypto)();
|
|
1935
1704
|
doDebug3 && console.warn("using @peculiar/webcrypto");
|
|
1936
1705
|
} else {
|
|
1937
1706
|
doDebug3 && console.warn("using nodejs crypto (native)");
|
|
@@ -1943,7 +1712,7 @@ if (typeof window === "undefined") {
|
|
|
1943
1712
|
x509.cryptoProvider.set(crypto);
|
|
1944
1713
|
}
|
|
1945
1714
|
function getCrypto() {
|
|
1946
|
-
return _crypto || crypto ||
|
|
1715
|
+
return _crypto || crypto || _crypto3.default;
|
|
1947
1716
|
}
|
|
1948
1717
|
|
|
1949
1718
|
// source/x509/create_key_pair.ts
|
|
@@ -2099,10 +1868,10 @@ async function createCertificateSigningRequest({
|
|
|
2099
1868
|
publicKey
|
|
2100
1869
|
};
|
|
2101
1870
|
const alternativeNameExtensions = [];
|
|
2102
|
-
for (const d of dns
|
|
1871
|
+
for (const d of _nullishCoalesce(dns, () => ( []))) {
|
|
2103
1872
|
alternativeNameExtensions.push({ type: "dns", value: d });
|
|
2104
1873
|
}
|
|
2105
|
-
for (const d of ip
|
|
1874
|
+
for (const d of _nullishCoalesce(ip, () => ( []))) {
|
|
2106
1875
|
alternativeNameExtensions.push({ type: "ip", value: d });
|
|
2107
1876
|
}
|
|
2108
1877
|
if (applicationUri) {
|
|
@@ -3743,7 +3512,7 @@ var OctetString = class extends BaseBlock {
|
|
|
3743
3512
|
this.valueBlock.value = [asn.result];
|
|
3744
3513
|
}
|
|
3745
3514
|
}
|
|
3746
|
-
} catch {
|
|
3515
|
+
} catch (e3) {
|
|
3747
3516
|
}
|
|
3748
3517
|
}
|
|
3749
3518
|
return super.fromBER(inputBuffer, inputOffset, inputLength);
|
|
@@ -3832,7 +3601,7 @@ var LocalBitStringValueBlock = class extends HexBlock(LocalConstructedValueBlock
|
|
|
3832
3601
|
this.value = [asn.result];
|
|
3833
3602
|
}
|
|
3834
3603
|
}
|
|
3835
|
-
} catch {
|
|
3604
|
+
} catch (e4) {
|
|
3836
3605
|
}
|
|
3837
3606
|
}
|
|
3838
3607
|
this.valueHexView = intBuffer.subarray(1);
|
|
@@ -6053,7 +5822,7 @@ var AsnParser = class {
|
|
|
6053
5822
|
return elementsToProcess.filter((el) => el && el.valueBlock).map((el) => {
|
|
6054
5823
|
try {
|
|
6055
5824
|
return converter.fromASN(el);
|
|
6056
|
-
} catch {
|
|
5825
|
+
} catch (e5) {
|
|
6057
5826
|
return void 0;
|
|
6058
5827
|
}
|
|
6059
5828
|
}).filter((v) => v !== void 0);
|
|
@@ -6061,7 +5830,7 @@ var AsnParser = class {
|
|
|
6061
5830
|
return elementsToProcess.filter((el) => el && el.valueBlock).map((el) => {
|
|
6062
5831
|
try {
|
|
6063
5832
|
return this.fromASN(el, schemaItem.type);
|
|
6064
|
-
} catch {
|
|
5833
|
+
} catch (e6) {
|
|
6065
5834
|
return void 0;
|
|
6066
5835
|
}
|
|
6067
5836
|
}).filter((v) => v !== void 0);
|
|
@@ -6442,85 +6211,298 @@ async function createSelfSignedCertificate({
|
|
|
6442
6211
|
return { cert: cert.toString("pem"), der: cert };
|
|
6443
6212
|
}
|
|
6444
6213
|
|
|
6214
|
+
// source/crypto_utils2.ts
|
|
6215
|
+
|
|
6216
|
+
|
|
6217
|
+
function rsaLengthPrivateKey(key) {
|
|
6218
|
+
const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
|
|
6219
|
+
const keyObject = _crypto2.createPrivateKey.call(void 0, keyPem);
|
|
6220
|
+
const modulusLength = _optionalChain([keyObject, 'access', _13 => _13.asymmetricKeyDetails, 'optionalAccess', _14 => _14.modulusLength]);
|
|
6221
|
+
_assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from private key");
|
|
6222
|
+
return modulusLength / 8;
|
|
6223
|
+
}
|
|
6224
|
+
function toPem2(raw_key, pem) {
|
|
6225
|
+
if (raw_key.hidden) {
|
|
6226
|
+
return toPem2(raw_key.hidden, pem);
|
|
6227
|
+
}
|
|
6228
|
+
_assert2.default.call(void 0, raw_key, "expecting a key");
|
|
6229
|
+
_assert2.default.call(void 0, typeof pem === "string");
|
|
6230
|
+
if (isKeyObject(raw_key)) {
|
|
6231
|
+
const _raw_key = raw_key;
|
|
6232
|
+
if (pem === "RSA PRIVATE KEY") {
|
|
6233
|
+
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs1" }).toString());
|
|
6234
|
+
} else if (pem === "PRIVATE KEY") {
|
|
6235
|
+
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs8" }).toString());
|
|
6236
|
+
} else {
|
|
6237
|
+
throw new Error("Unsupported case!");
|
|
6238
|
+
}
|
|
6239
|
+
}
|
|
6240
|
+
return toPem(raw_key, pem);
|
|
6241
|
+
}
|
|
6242
|
+
function coercePrivateKeyPem(privateKey) {
|
|
6243
|
+
return toPem2(privateKey, "PRIVATE KEY");
|
|
6244
|
+
}
|
|
6245
|
+
function coercePublicKeyPem(publicKey) {
|
|
6246
|
+
if (isKeyObject(publicKey)) {
|
|
6247
|
+
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
6248
|
+
}
|
|
6249
|
+
_assert2.default.call(void 0, typeof publicKey === "string");
|
|
6250
|
+
return publicKey;
|
|
6251
|
+
}
|
|
6252
|
+
function coerceRsaPublicKeyPem(publicKey) {
|
|
6253
|
+
if (isKeyObject(publicKey)) {
|
|
6254
|
+
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
6255
|
+
}
|
|
6256
|
+
_assert2.default.call(void 0, typeof publicKey === "string");
|
|
6257
|
+
return publicKey;
|
|
6258
|
+
}
|
|
6259
|
+
function rsaLengthPublicKey(key) {
|
|
6260
|
+
key = coercePublicKeyPem(key);
|
|
6261
|
+
_assert2.default.call(void 0, typeof key === "string");
|
|
6262
|
+
const keyObject = _crypto2.createPublicKey.call(void 0, key);
|
|
6263
|
+
const modulusLength = _optionalChain([keyObject, 'access', _15 => _15.asymmetricKeyDetails, 'optionalAccess', _16 => _16.modulusLength]);
|
|
6264
|
+
_assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
|
|
6265
|
+
return modulusLength / 8;
|
|
6266
|
+
}
|
|
6267
|
+
function rsaLengthRsaPublicKey(key) {
|
|
6268
|
+
key = coerceRsaPublicKeyPem(key);
|
|
6269
|
+
_assert2.default.call(void 0, typeof key === "string");
|
|
6270
|
+
const keyObject = _crypto2.createPublicKey.call(void 0, key);
|
|
6271
|
+
const modulusLength = _optionalChain([keyObject, 'access', _17 => _17.asymmetricKeyDetails, 'optionalAccess', _18 => _18.modulusLength]);
|
|
6272
|
+
_assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
|
|
6273
|
+
return modulusLength / 8;
|
|
6274
|
+
}
|
|
6275
|
+
|
|
6276
|
+
// source/derived_keys.ts
|
|
6277
|
+
|
|
6278
|
+
|
|
6279
|
+
function HMAC_HASH(sha1or256, secret, message) {
|
|
6280
|
+
return _crypto2.createHmac.call(void 0, sha1or256, secret).update(message).digest();
|
|
6281
|
+
}
|
|
6282
|
+
function plus(buf1, buf2) {
|
|
6283
|
+
return Buffer.concat([buf1, buf2]);
|
|
6284
|
+
}
|
|
6285
|
+
function makePseudoRandomBuffer(secret, seed, minLength, sha1or256) {
|
|
6286
|
+
_assert2.default.call(void 0, Buffer.isBuffer(seed));
|
|
6287
|
+
_assert2.default.call(void 0, sha1or256 === "SHA1" || sha1or256 === "SHA256");
|
|
6288
|
+
const a = [];
|
|
6289
|
+
a[0] = seed;
|
|
6290
|
+
let index = 1;
|
|
6291
|
+
let p_hash = createFastUninitializedBuffer(0);
|
|
6292
|
+
while (p_hash.length <= minLength) {
|
|
6293
|
+
a[index] = HMAC_HASH(sha1or256, secret, a[index - 1]);
|
|
6294
|
+
p_hash = plus(p_hash, HMAC_HASH(sha1or256, secret, plus(a[index], seed)));
|
|
6295
|
+
index += 1;
|
|
6296
|
+
}
|
|
6297
|
+
return p_hash.subarray(0, minLength);
|
|
6298
|
+
}
|
|
6299
|
+
function computeDerivedKeys(secret, seed, options) {
|
|
6300
|
+
_assert2.default.call(void 0, Number.isFinite(options.signatureLength));
|
|
6301
|
+
_assert2.default.call(void 0, Number.isFinite(options.encryptingKeyLength));
|
|
6302
|
+
_assert2.default.call(void 0, Number.isFinite(options.encryptingBlockSize));
|
|
6303
|
+
_assert2.default.call(void 0, typeof options.algorithm === "string");
|
|
6304
|
+
options.sha1or256 = options.sha1or256 || "SHA1";
|
|
6305
|
+
_assert2.default.call(void 0, typeof options.sha1or256 === "string");
|
|
6306
|
+
const offset1 = options.signingKeyLength;
|
|
6307
|
+
const offset2 = offset1 + options.encryptingKeyLength;
|
|
6308
|
+
const minLength = offset2 + options.encryptingBlockSize;
|
|
6309
|
+
const buf = makePseudoRandomBuffer(secret, seed, minLength, options.sha1or256);
|
|
6310
|
+
return {
|
|
6311
|
+
signatureLength: options.signatureLength,
|
|
6312
|
+
signingKeyLength: options.signingKeyLength,
|
|
6313
|
+
encryptingKeyLength: options.encryptingKeyLength,
|
|
6314
|
+
encryptingBlockSize: options.encryptingBlockSize,
|
|
6315
|
+
algorithm: options.algorithm,
|
|
6316
|
+
sha1or256: options.sha1or256,
|
|
6317
|
+
signingKey: buf.subarray(0, offset1),
|
|
6318
|
+
encryptingKey: buf.subarray(offset1, offset2),
|
|
6319
|
+
initializationVector: buf.subarray(offset2, minLength)
|
|
6320
|
+
};
|
|
6321
|
+
}
|
|
6322
|
+
function reduceLength(buffer, byteToRemove) {
|
|
6323
|
+
return buffer.subarray(0, buffer.length - byteToRemove);
|
|
6324
|
+
}
|
|
6325
|
+
function removePadding(buffer) {
|
|
6326
|
+
const nbPaddingBytes = buffer.readUInt8(buffer.length - 1) + 1;
|
|
6327
|
+
return reduceLength(buffer, nbPaddingBytes);
|
|
6328
|
+
}
|
|
6329
|
+
function verifyChunkSignature(chunk, options) {
|
|
6330
|
+
_assert2.default.call(void 0, Buffer.isBuffer(chunk));
|
|
6331
|
+
let signatureLength = options.signatureLength || 0;
|
|
6332
|
+
if (signatureLength === 0) {
|
|
6333
|
+
const cert = exploreCertificateInfo(options.publicKey);
|
|
6334
|
+
signatureLength = cert.publicKeyLength || 0;
|
|
6335
|
+
}
|
|
6336
|
+
const block_to_verify = chunk.subarray(0, chunk.length - signatureLength);
|
|
6337
|
+
const signature = chunk.subarray(chunk.length - signatureLength);
|
|
6338
|
+
return verifyMessageChunkSignature(block_to_verify, signature, options);
|
|
6339
|
+
}
|
|
6340
|
+
function computePaddingFooter(buffer, derivedKeys) {
|
|
6341
|
+
_assert2.default.call(void 0, Object.hasOwn(derivedKeys, "encryptingBlockSize"));
|
|
6342
|
+
const paddingSize = derivedKeys.encryptingBlockSize - (buffer.length + 1) % derivedKeys.encryptingBlockSize;
|
|
6343
|
+
const padding = createFastUninitializedBuffer(paddingSize + 1);
|
|
6344
|
+
padding.fill(paddingSize);
|
|
6345
|
+
return padding;
|
|
6346
|
+
}
|
|
6347
|
+
function derivedKeys_algorithm(derivedKeys) {
|
|
6348
|
+
_assert2.default.call(void 0, Object.hasOwn(derivedKeys, "algorithm"));
|
|
6349
|
+
const algorithm = derivedKeys.algorithm || "aes-128-cbc";
|
|
6350
|
+
_assert2.default.call(void 0, algorithm === "aes-128-cbc" || algorithm === "aes-256-cbc");
|
|
6351
|
+
return algorithm;
|
|
6352
|
+
}
|
|
6353
|
+
function encryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
6354
|
+
const algorithm = derivedKeys_algorithm(derivedKeys);
|
|
6355
|
+
const key = derivedKeys.encryptingKey;
|
|
6356
|
+
const initVector = derivedKeys.initializationVector;
|
|
6357
|
+
const cipher = _crypto2.createCipheriv.call(void 0, algorithm, key, initVector);
|
|
6358
|
+
cipher.setAutoPadding(false);
|
|
6359
|
+
const encrypted_chunks = [];
|
|
6360
|
+
encrypted_chunks.push(cipher.update(buffer));
|
|
6361
|
+
encrypted_chunks.push(cipher.final());
|
|
6362
|
+
return Buffer.concat(encrypted_chunks);
|
|
6363
|
+
}
|
|
6364
|
+
function decryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
6365
|
+
const algorithm = derivedKeys_algorithm(derivedKeys);
|
|
6366
|
+
const key = derivedKeys.encryptingKey;
|
|
6367
|
+
const initVector = derivedKeys.initializationVector;
|
|
6368
|
+
const cipher = _crypto2.createDecipheriv.call(void 0, algorithm, key, initVector);
|
|
6369
|
+
cipher.setAutoPadding(false);
|
|
6370
|
+
const decrypted_chunks = [];
|
|
6371
|
+
decrypted_chunks.push(cipher.update(buffer));
|
|
6372
|
+
decrypted_chunks.push(cipher.final());
|
|
6373
|
+
return Buffer.concat(decrypted_chunks);
|
|
6374
|
+
}
|
|
6375
|
+
function makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys) {
|
|
6376
|
+
_assert2.default.call(void 0, Buffer.isBuffer(message));
|
|
6377
|
+
_assert2.default.call(void 0, Buffer.isBuffer(derivedKeys.signingKey));
|
|
6378
|
+
_assert2.default.call(void 0, typeof derivedKeys.sha1or256 === "string");
|
|
6379
|
+
_assert2.default.call(void 0, derivedKeys.sha1or256 === "SHA1" || derivedKeys.sha1or256 === "SHA256");
|
|
6380
|
+
const signature = _crypto2.createHmac.call(void 0, derivedKeys.sha1or256, derivedKeys.signingKey).update(message).digest();
|
|
6381
|
+
_assert2.default.call(void 0, signature.length === derivedKeys.signatureLength);
|
|
6382
|
+
return signature;
|
|
6383
|
+
}
|
|
6384
|
+
function verifyChunkSignatureWithDerivedKeys(chunk, derivedKeys) {
|
|
6385
|
+
const message = chunk.subarray(0, chunk.length - derivedKeys.signatureLength);
|
|
6386
|
+
const expectedSignature = chunk.subarray(chunk.length - derivedKeys.signatureLength);
|
|
6387
|
+
const computedSignature = makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys);
|
|
6388
|
+
return computedSignature.toString("hex") === expectedSignature.toString("hex");
|
|
6389
|
+
}
|
|
6390
|
+
|
|
6391
|
+
// source/make_private_key_from_pem.ts
|
|
6392
|
+
function makePrivateKeyFromPem(privateKeyInPem) {
|
|
6393
|
+
return { hidden: privateKeyInPem };
|
|
6394
|
+
}
|
|
6395
|
+
|
|
6396
|
+
// source/make_private_key_thumbprint.ts
|
|
6397
|
+
function makePrivateKeyThumbPrint(_privateKey) {
|
|
6398
|
+
return Buffer.alloc(0);
|
|
6399
|
+
}
|
|
6400
|
+
|
|
6401
|
+
// source/public_private_match.ts
|
|
6402
|
+
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
6403
|
+
const i = exploreCertificate(certificate);
|
|
6404
|
+
const j = explorePrivateKey(privateKey);
|
|
6405
|
+
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
6406
|
+
const modulus2 = j.modulus;
|
|
6407
|
+
if (modulus1.length !== modulus2.length) {
|
|
6408
|
+
return false;
|
|
6409
|
+
}
|
|
6410
|
+
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
6411
|
+
}
|
|
6412
|
+
function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
6413
|
+
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
6414
|
+
const encryptedBuffer = publicEncrypt_long(initialBuffer, certificate, blockSize);
|
|
6415
|
+
const decryptedBuffer = privateDecrypt_long(encryptedBuffer, privateKey, blockSize);
|
|
6416
|
+
const finalString = decryptedBuffer.toString("utf-8");
|
|
6417
|
+
return initialBuffer.toString("utf-8") === finalString;
|
|
6418
|
+
}
|
|
6419
|
+
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
6420
|
+
const e = explorePrivateKey(privateKey);
|
|
6421
|
+
const blockSize = e.modulus.length;
|
|
6422
|
+
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
6423
|
+
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
6424
|
+
}
|
|
6425
|
+
|
|
6445
6426
|
// source/index_web.ts
|
|
6446
6427
|
var asn1 = { readDirectoryName, readTag, readStruct, readAlgorithmIdentifier, readSignatureValueBin };
|
|
6447
|
-
|
|
6448
|
-
|
|
6449
|
-
|
|
6450
|
-
|
|
6451
|
-
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
|
|
6487
|
-
|
|
6488
|
-
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
|
|
6506
|
-
|
|
6507
|
-
|
|
6508
|
-
|
|
6509
|
-
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6428
|
+
|
|
6429
|
+
|
|
6430
|
+
|
|
6431
|
+
|
|
6432
|
+
|
|
6433
|
+
|
|
6434
|
+
|
|
6435
|
+
|
|
6436
|
+
|
|
6437
|
+
|
|
6438
|
+
|
|
6439
|
+
|
|
6440
|
+
|
|
6441
|
+
|
|
6442
|
+
|
|
6443
|
+
|
|
6444
|
+
|
|
6445
|
+
|
|
6446
|
+
|
|
6447
|
+
|
|
6448
|
+
|
|
6449
|
+
|
|
6450
|
+
|
|
6451
|
+
|
|
6452
|
+
|
|
6453
|
+
|
|
6454
|
+
|
|
6455
|
+
|
|
6456
|
+
|
|
6457
|
+
|
|
6458
|
+
|
|
6459
|
+
|
|
6460
|
+
|
|
6461
|
+
|
|
6462
|
+
|
|
6463
|
+
|
|
6464
|
+
|
|
6465
|
+
|
|
6466
|
+
|
|
6467
|
+
|
|
6468
|
+
|
|
6469
|
+
|
|
6470
|
+
|
|
6471
|
+
|
|
6472
|
+
|
|
6473
|
+
|
|
6474
|
+
|
|
6475
|
+
|
|
6476
|
+
|
|
6477
|
+
|
|
6478
|
+
|
|
6479
|
+
|
|
6480
|
+
|
|
6481
|
+
|
|
6482
|
+
|
|
6483
|
+
|
|
6484
|
+
|
|
6485
|
+
|
|
6486
|
+
|
|
6487
|
+
|
|
6488
|
+
|
|
6489
|
+
|
|
6490
|
+
|
|
6491
|
+
|
|
6492
|
+
|
|
6493
|
+
|
|
6494
|
+
|
|
6495
|
+
|
|
6496
|
+
|
|
6497
|
+
|
|
6498
|
+
|
|
6499
|
+
|
|
6500
|
+
|
|
6501
|
+
|
|
6502
|
+
|
|
6503
|
+
|
|
6504
|
+
|
|
6505
|
+
exports.createPrivateKeyFromNodeJSCrypto = createPrivateKeyFromNodeJSCrypto; exports.isKeyObject = isKeyObject; exports.CertificatePurpose = CertificatePurpose; exports.identifyPemType = identifyPemType; exports.removeTrailingLF = removeTrailingLF; exports.toPem = toPem; exports.convertPEMtoDER = convertPEMtoDER; exports.hexDump = hexDump; exports.makeMessageChunkSignature = makeMessageChunkSignature; exports.verifyMessageChunkSignature = verifyMessageChunkSignature; exports.makeSHA1Thumbprint = makeSHA1Thumbprint; exports.RSA_PKCS1_OAEP_PADDING = RSA_PKCS1_OAEP_PADDING; exports.RSA_PKCS1_PADDING = RSA_PKCS1_PADDING; exports.PaddingAlgorithm = PaddingAlgorithm; exports.publicEncrypt_native = publicEncrypt_native; exports.privateDecrypt_native = privateDecrypt_native; exports.publicEncrypt = publicEncrypt; exports.privateDecrypt = privateDecrypt; exports.publicEncrypt_long = publicEncrypt_long; exports.privateDecrypt_long = privateDecrypt_long; exports.coerceCertificatePem = coerceCertificatePem; exports.extractPublicKeyFromCertificateSync = extractPublicKeyFromCertificateSync; exports.extractPublicKeyFromCertificate = extractPublicKeyFromCertificate; exports.readExtension = readExtension; exports.readTbsCertificate = readTbsCertificate; exports.exploreCertificate = exploreCertificate; exports.split_der = split_der; exports.combine_der = combine_der; exports.readNameForCrl = readNameForCrl; exports.exploreCertificateRevocationList = exploreCertificateRevocationList; exports.verifyCertificateOrClrSignature = verifyCertificateOrClrSignature; exports.verifyCertificateSignature = verifyCertificateSignature; exports.verifyCertificateRevocationListSignature = verifyCertificateRevocationListSignature; exports.verifyCertificateChain = verifyCertificateChain; exports.isCrlIssuedByCertificate = isCrlIssuedByCertificate; exports.verifyCrlIssuedByCertificate = verifyCrlIssuedByCertificate; exports.exploreAsn1 = exploreAsn1; exports.coerceCertificate = coerceCertificate; exports.exploreCertificateInfo = exploreCertificateInfo; exports.readCertificationRequestInfo = readCertificationRequestInfo; exports.exploreCertificateSigningRequest = exploreCertificateSigningRequest; exports.explorePrivateKey = explorePrivateKey; exports.identifyDERContent = identifyDERContent; exports.Subject = Subject; exports.generateKeyPair = generateKeyPair; exports.generatePrivateKey = generatePrivateKey; exports.privateKeyToPEM = privateKeyToPEM; exports.derToPrivateKey = derToPrivateKey; exports.pemToPrivateKey = pemToPrivateKey; exports.coercePEMorDerToPrivateKey = coercePEMorDerToPrivateKey; exports._coercePrivateKey = _coercePrivateKey; exports.createCertificateSigningRequest = createCertificateSigningRequest; exports.createSelfSignedCertificate = createSelfSignedCertificate; exports.rsaLengthPrivateKey = rsaLengthPrivateKey; exports.toPem2 = toPem2; exports.coercePrivateKeyPem = coercePrivateKeyPem; exports.coercePublicKeyPem = coercePublicKeyPem; exports.coerceRsaPublicKeyPem = coerceRsaPublicKeyPem; exports.rsaLengthPublicKey = rsaLengthPublicKey; exports.rsaLengthRsaPublicKey = rsaLengthRsaPublicKey; exports.makePseudoRandomBuffer = makePseudoRandomBuffer; exports.computeDerivedKeys = computeDerivedKeys; exports.reduceLength = reduceLength; exports.removePadding = removePadding; exports.verifyChunkSignature = verifyChunkSignature; exports.computePaddingFooter = computePaddingFooter; exports.encryptBufferWithDerivedKeys = encryptBufferWithDerivedKeys; exports.decryptBufferWithDerivedKeys = decryptBufferWithDerivedKeys; exports.makeMessageChunkSignatureWithDerivedKeys = makeMessageChunkSignatureWithDerivedKeys; exports.verifyChunkSignatureWithDerivedKeys = verifyChunkSignatureWithDerivedKeys; exports.makePrivateKeyFromPem = makePrivateKeyFromPem; exports.makePrivateKeyThumbPrint = makePrivateKeyThumbPrint; exports.publicKeyAndPrivateKeyMatches = publicKeyAndPrivateKeyMatches; exports.certificateMatchesPrivateKey = certificateMatchesPrivateKey; exports.asn1 = asn1;
|
|
6524
6506
|
/*! Bundled license information:
|
|
6525
6507
|
|
|
6526
6508
|
pvtsutils/build/index.es.js:
|
|
@@ -6589,4 +6571,4 @@ asn1js/build/index.es.js:
|
|
|
6589
6571
|
*
|
|
6590
6572
|
*)
|
|
6591
6573
|
*/
|
|
6592
|
-
//# sourceMappingURL=
|
|
6574
|
+
//# sourceMappingURL=chunk-ERHE4VFS.cjs.map
|