node-opcua-crypto 4.9.4 → 4.11.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/LICENSE +23 -23
- package/README.md +119 -114
- package/dist/{chunk-WLW5XUML.mjs → chunk-2RCYFHGG.mjs} +755 -724
- package/dist/chunk-2RCYFHGG.mjs.map +1 -0
- package/dist/chunk-C7PROBPE.mjs +14 -0
- package/dist/chunk-C7PROBPE.mjs.map +1 -0
- package/dist/{chunk-UEV3YRUV.mjs → chunk-UH5AT3JE.mjs} +9 -15
- package/dist/chunk-UH5AT3JE.mjs.map +1 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +553 -552
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -52
- package/dist/index_web-C5Oeu9mq.d.mts +503 -0
- package/dist/index_web-D1qc4UN2.d.ts +503 -0
- package/dist/source/index.d.mts +11 -516
- package/dist/source/index.d.ts +11 -516
- package/dist/source/index.js +537 -529
- package/dist/source/index.js.map +1 -1
- package/dist/source/index.mjs +9 -50
- package/dist/source/index_web.d.mts +1 -1
- package/dist/source/index_web.d.ts +1 -1
- package/dist/source/index_web.js +525 -522
- package/dist/source/index_web.js.map +1 -1
- package/dist/source/index_web.mjs +5 -49
- package/dist/source_nodejs/index.d.mts +1 -2
- package/dist/source_nodejs/index.d.ts +1 -2
- package/dist/source_nodejs/index.js +33 -41
- package/dist/source_nodejs/index.js.map +1 -1
- package/dist/source_nodejs/index.mjs +3 -5
- package/package.json +9 -4
- package/dist/chunk-5NV4OKIV.mjs +0 -1
- package/dist/chunk-5NV4OKIV.mjs.map +0 -1
- package/dist/chunk-UEV3YRUV.mjs.map +0 -1
- package/dist/chunk-WLW5XUML.mjs.map +0 -1
- package/dist/index_web.d.mts +0 -4
- package/dist/index_web.d.ts +0 -4
- package/dist/index_web.js +0 -6365
- package/dist/index_web.js.map +0 -1
- package/dist/index_web.mjs +0 -192
- package/dist/index_web.mjs.map +0 -1
- package/index.mjs +0 -1
- package/index_web.ts +0 -1
- package/web.d.ts +0 -1
- package/web.mjs +0 -1
package/dist/source/index.js
CHANGED
|
@@ -35,28 +35,9 @@ __export(source_exports, {
|
|
|
35
35
|
RSA_PKCS1_OAEP_PADDING: () => RSA_PKCS1_OAEP_PADDING,
|
|
36
36
|
RSA_PKCS1_PADDING: () => RSA_PKCS1_PADDING,
|
|
37
37
|
Subject: () => Subject,
|
|
38
|
-
TagType: () => TagType,
|
|
39
38
|
_coercePrivateKey: () => _coercePrivateKey,
|
|
40
|
-
_findBlockAtIndex: () => _findBlockAtIndex,
|
|
41
|
-
_getBlock: () => _getBlock,
|
|
42
|
-
_readAlgorithmIdentifier: () => _readAlgorithmIdentifier,
|
|
43
|
-
_readBitString: () => _readBitString,
|
|
44
|
-
_readBooleanValue: () => _readBooleanValue,
|
|
45
|
-
_readDirectoryName: () => _readDirectoryName,
|
|
46
|
-
_readECCAlgorithmIdentifier: () => _readECCAlgorithmIdentifier,
|
|
47
39
|
_readExtension: () => _readExtension,
|
|
48
|
-
|
|
49
|
-
_readIntegerValue: () => _readIntegerValue,
|
|
50
|
-
_readListOfInteger: () => _readListOfInteger,
|
|
51
|
-
_readLongIntegerValue: () => _readLongIntegerValue,
|
|
52
|
-
_readObjectIdentifier: () => _readObjectIdentifier,
|
|
53
|
-
_readOctetString: () => _readOctetString,
|
|
54
|
-
_readSignatureValue: () => _readSignatureValue,
|
|
55
|
-
_readSignatureValueBin: () => _readSignatureValueBin,
|
|
56
|
-
_readStruct: () => _readStruct,
|
|
57
|
-
_readTime: () => _readTime,
|
|
58
|
-
_readValue: () => _readValue,
|
|
59
|
-
_readVersionValue: () => _readVersionValue,
|
|
40
|
+
asn1: () => asn1,
|
|
60
41
|
certificateMatchesPrivateKey: () => certificateMatchesPrivateKey,
|
|
61
42
|
coerceCertificate: () => coerceCertificate,
|
|
62
43
|
coerceCertificatePem: () => coerceCertificatePem,
|
|
@@ -65,7 +46,6 @@ __export(source_exports, {
|
|
|
65
46
|
coercePublicKeyPem: () => coercePublicKeyPem,
|
|
66
47
|
coerceRsaPublicKeyPem: () => coerceRsaPublicKeyPem,
|
|
67
48
|
combine_der: () => combine_der,
|
|
68
|
-
compactDirectoryName: () => compactDirectoryName,
|
|
69
49
|
computeDerivedKeys: () => computeDerivedKeys,
|
|
70
50
|
computePaddingFooter: () => computePaddingFooter,
|
|
71
51
|
convertPEMtoDER: () => convertPEMtoDER,
|
|
@@ -75,6 +55,7 @@ __export(source_exports, {
|
|
|
75
55
|
decryptBufferWithDerivedKeys: () => decryptBufferWithDerivedKeys,
|
|
76
56
|
derToPrivateKey: () => derToPrivateKey,
|
|
77
57
|
encryptBufferWithDerivedKeys: () => encryptBufferWithDerivedKeys,
|
|
58
|
+
exploreAsn1: () => exploreAsn1,
|
|
78
59
|
exploreCertificate: () => exploreCertificate,
|
|
79
60
|
exploreCertificateInfo: () => exploreCertificateInfo,
|
|
80
61
|
exploreCertificateRevocationList: () => exploreCertificateRevocationList,
|
|
@@ -82,7 +63,6 @@ __export(source_exports, {
|
|
|
82
63
|
explorePrivateKey: () => explorePrivateKey,
|
|
83
64
|
extractPublicKeyFromCertificate: () => extractPublicKeyFromCertificate,
|
|
84
65
|
extractPublicKeyFromCertificateSync: () => extractPublicKeyFromCertificateSync,
|
|
85
|
-
formatBuffer2DigitHexWithColum: () => formatBuffer2DigitHexWithColum,
|
|
86
66
|
generateKeyPair: () => generateKeyPair,
|
|
87
67
|
generatePrivateKey: () => generatePrivateKey,
|
|
88
68
|
hexDump: () => hexDump,
|
|
@@ -91,9 +71,9 @@ __export(source_exports, {
|
|
|
91
71
|
makeMessageChunkSignature: () => makeMessageChunkSignature,
|
|
92
72
|
makeMessageChunkSignatureWithDerivedKeys: () => makeMessageChunkSignatureWithDerivedKeys,
|
|
93
73
|
makePrivateKeyFromPem: () => makePrivateKeyFromPem,
|
|
74
|
+
makePrivateKeyThumbPrint: () => makePrivateKeyThumbPrint,
|
|
94
75
|
makePseudoRandomBuffer: () => makePseudoRandomBuffer,
|
|
95
76
|
makeSHA1Thumbprint: () => makeSHA1Thumbprint,
|
|
96
|
-
parseBitString: () => parseBitString,
|
|
97
77
|
pemToPrivateKey: () => pemToPrivateKey,
|
|
98
78
|
privateDecrypt: () => privateDecrypt,
|
|
99
79
|
privateDecrypt_long: () => privateDecrypt_long,
|
|
@@ -105,7 +85,6 @@ __export(source_exports, {
|
|
|
105
85
|
publicKeyAndPrivateKeyMatches: () => publicKeyAndPrivateKeyMatches,
|
|
106
86
|
readCertificationRequestInfo: () => readCertificationRequestInfo,
|
|
107
87
|
readNameForCrl: () => readNameForCrl,
|
|
108
|
-
readTag: () => readTag,
|
|
109
88
|
readTbsCertificate: () => readTbsCertificate,
|
|
110
89
|
reduceLength: () => reduceLength,
|
|
111
90
|
removePadding: () => removePadding,
|
|
@@ -126,42 +105,6 @@ __export(source_exports, {
|
|
|
126
105
|
});
|
|
127
106
|
module.exports = __toCommonJS(source_exports);
|
|
128
107
|
|
|
129
|
-
// source/common.ts
|
|
130
|
-
var import_crypto = __toESM(require("crypto"));
|
|
131
|
-
var KeyObjectOrig = import_crypto.default.KeyObject;
|
|
132
|
-
var { createPrivateKey: createPrivateKeyFromNodeJSCrypto } = import_crypto.default;
|
|
133
|
-
function isKeyObject(mayBeKeyObject) {
|
|
134
|
-
if (KeyObjectOrig) {
|
|
135
|
-
return mayBeKeyObject instanceof KeyObjectOrig;
|
|
136
|
-
}
|
|
137
|
-
return typeof mayBeKeyObject === "object" && typeof mayBeKeyObject.type === "string";
|
|
138
|
-
}
|
|
139
|
-
var CertificatePurpose = /* @__PURE__ */ ((CertificatePurpose2) => {
|
|
140
|
-
CertificatePurpose2[CertificatePurpose2["NotSpecified"] = 0] = "NotSpecified";
|
|
141
|
-
CertificatePurpose2[CertificatePurpose2["ForCertificateAuthority"] = 1] = "ForCertificateAuthority";
|
|
142
|
-
CertificatePurpose2[CertificatePurpose2["ForApplication"] = 2] = "ForApplication";
|
|
143
|
-
CertificatePurpose2[CertificatePurpose2["ForUserAuthentication"] = 3] = "ForUserAuthentication";
|
|
144
|
-
return CertificatePurpose2;
|
|
145
|
-
})(CertificatePurpose || {});
|
|
146
|
-
|
|
147
|
-
// source/derived_keys.ts
|
|
148
|
-
var import_assert5 = __toESM(require("assert"));
|
|
149
|
-
var import_crypto3 = require("crypto");
|
|
150
|
-
|
|
151
|
-
// source/buffer_utils.ts
|
|
152
|
-
var createFastUninitializedBuffer = Buffer.allocUnsafe ? Buffer.allocUnsafe : (size) => {
|
|
153
|
-
return new Buffer(size);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// source/crypto_utils.ts
|
|
157
|
-
var import_constants = __toESM(require("constants"));
|
|
158
|
-
var import_assert3 = __toESM(require("assert"));
|
|
159
|
-
var import_crypto2 = require("crypto");
|
|
160
|
-
var import_hexy = __toESM(require("hexy"));
|
|
161
|
-
|
|
162
|
-
// source/crypto_explore_certificate.ts
|
|
163
|
-
var import_assert2 = __toESM(require("assert"));
|
|
164
|
-
|
|
165
108
|
// source/asn1.ts
|
|
166
109
|
var import_assert = __toESM(require("assert"));
|
|
167
110
|
|
|
@@ -229,6 +172,7 @@ var oid_map = {
|
|
|
229
172
|
"1.3.6.1.4.1.311.2.1.22": { d: "1.3.6.1.4.1.311.2.1.22", c: "SPC_COMMERCIAL_SP_KEY_PURPOSE_OBJID" },
|
|
230
173
|
"1.3.6.1.4.1.311.10.3.1": { d: "1.3.6.1.4.1.311.10.3.1", c: "Signer of CTLs -- szOID_KP_CTL_USAGE_SIGNING" },
|
|
231
174
|
"1.3.6.1.4.1.311.10.3.4": { d: "1.3.6.1.4.1.311.10.3.4", c: "szOID_EFS_RECOVERY (Encryption File System)" },
|
|
175
|
+
"1.3.6.1.4.1.311.20.2.3": { d: "1.3.6.1.4.1.311.20.2.3", c: "id-on-personalData" },
|
|
232
176
|
"1.3.6.1.5.5.7.3.17": { d: "1.3.6.1.5.5.7.3.17", c: "Internet Key Exchange (IKE)" },
|
|
233
177
|
"1.3.6.1.5.5.7.3.1": { d: "serverAuth", c: "PKIX key purpose" },
|
|
234
178
|
"1.3.6.1.5.5.7.3.2": { d: "clientAuth", c: "PKIX key purpose" },
|
|
@@ -488,12 +432,15 @@ var TagType = /* @__PURE__ */ ((TagType3) => {
|
|
|
488
432
|
TagType3[TagType3["BMPString"] = 30] = "BMPString";
|
|
489
433
|
TagType3[TagType3["SEQUENCE"] = 48] = "SEQUENCE";
|
|
490
434
|
TagType3[TagType3["SET"] = 49] = "SET";
|
|
491
|
-
TagType3[TagType3["
|
|
435
|
+
TagType3[TagType3["CONTEXT_SPECIFIC0"] = 160] = "CONTEXT_SPECIFIC0";
|
|
436
|
+
TagType3[TagType3["CONTEXT_SPECIFIC1"] = 161] = "CONTEXT_SPECIFIC1";
|
|
437
|
+
TagType3[TagType3["CONTEXT_SPECIFIC2"] = 162] = "CONTEXT_SPECIFIC2";
|
|
438
|
+
TagType3[TagType3["CONTEXT_SPECIFIC3"] = 163] = "CONTEXT_SPECIFIC3";
|
|
439
|
+
TagType3[TagType3["A4"] = 164] = "A4";
|
|
492
440
|
return TagType3;
|
|
493
441
|
})(TagType || {});
|
|
494
442
|
function readTag(buf, pos) {
|
|
495
|
-
|
|
496
|
-
(0, import_assert.default)(Number.isFinite(pos) && pos >= 0);
|
|
443
|
+
const start = pos;
|
|
497
444
|
if (buf.length <= pos) {
|
|
498
445
|
throw new Error("Invalid position : buf.length=" + buf.length + " pos =" + pos);
|
|
499
446
|
}
|
|
@@ -509,9 +456,9 @@ function readTag(buf, pos) {
|
|
|
509
456
|
pos += 1;
|
|
510
457
|
}
|
|
511
458
|
}
|
|
512
|
-
return { tag, position: pos, length };
|
|
459
|
+
return { start, tag, position: pos, length };
|
|
513
460
|
}
|
|
514
|
-
function
|
|
461
|
+
function readStruct(buf, blockInfo) {
|
|
515
462
|
const length = blockInfo.length;
|
|
516
463
|
let cursor = blockInfo.position;
|
|
517
464
|
const end = blockInfo.position + length;
|
|
@@ -573,9 +520,9 @@ function _readIntegerAsByteString(buffer, block) {
|
|
|
573
520
|
}
|
|
574
521
|
function _readListOfInteger(buffer) {
|
|
575
522
|
const block = readTag(buffer, 0);
|
|
576
|
-
const inner_blocks =
|
|
577
|
-
return inner_blocks.map((
|
|
578
|
-
return _readIntegerAsByteString(buffer,
|
|
523
|
+
const inner_blocks = readStruct(buffer, block);
|
|
524
|
+
return inner_blocks.map((innerBlock) => {
|
|
525
|
+
return _readIntegerAsByteString(buffer, innerBlock);
|
|
579
526
|
});
|
|
580
527
|
}
|
|
581
528
|
function parseOID(buffer, start, end) {
|
|
@@ -607,24 +554,24 @@ function _readObjectIdentifier(buffer, block) {
|
|
|
607
554
|
name: oid_map[oid] ? oid_map[oid].d : oid
|
|
608
555
|
};
|
|
609
556
|
}
|
|
610
|
-
function
|
|
611
|
-
const inner_blocks =
|
|
557
|
+
function readAlgorithmIdentifier(buffer, block) {
|
|
558
|
+
const inner_blocks = readStruct(buffer, block);
|
|
612
559
|
return {
|
|
613
560
|
identifier: _readObjectIdentifier(buffer, inner_blocks[0]).name
|
|
614
561
|
};
|
|
615
562
|
}
|
|
616
563
|
function _readECCAlgorithmIdentifier(buffer, block) {
|
|
617
|
-
const inner_blocks =
|
|
564
|
+
const inner_blocks = readStruct(buffer, block);
|
|
618
565
|
return {
|
|
619
566
|
identifier: _readObjectIdentifier(buffer, inner_blocks[1]).name
|
|
620
567
|
// difference with RSA as algorithm is second element of nested block
|
|
621
568
|
};
|
|
622
569
|
}
|
|
623
|
-
function
|
|
570
|
+
function readSignatureValueBin(buffer, block) {
|
|
624
571
|
return _readBitString(buffer, block).data;
|
|
625
572
|
}
|
|
626
|
-
function
|
|
627
|
-
return
|
|
573
|
+
function readSignatureValue(buffer, block) {
|
|
574
|
+
return readSignatureValueBin(buffer, block).toString("hex");
|
|
628
575
|
}
|
|
629
576
|
function _readLongIntegerValue(buffer, block) {
|
|
630
577
|
(0, import_assert.default)(block.tag === 2 /* INTEGER */, "expecting a INTEGER tag");
|
|
@@ -705,18 +652,15 @@ function _readValue(buffer, block) {
|
|
|
705
652
|
throw new Error("Invalid tag 0x" + block.tag.toString(16));
|
|
706
653
|
}
|
|
707
654
|
}
|
|
708
|
-
function compactDirectoryName(d) {
|
|
709
|
-
return JSON.stringify(d);
|
|
710
|
-
}
|
|
711
655
|
function _readDirectoryName(buffer, block) {
|
|
712
|
-
const set_blocks =
|
|
656
|
+
const set_blocks = readStruct(buffer, block);
|
|
713
657
|
const names = {};
|
|
714
658
|
for (const set_block of set_blocks) {
|
|
715
659
|
(0, import_assert.default)(set_block.tag === 49);
|
|
716
|
-
const blocks =
|
|
660
|
+
const blocks = readStruct(buffer, set_block);
|
|
717
661
|
(0, import_assert.default)(blocks.length === 1);
|
|
718
662
|
(0, import_assert.default)(blocks[0].tag === 48);
|
|
719
|
-
const sequenceBlock =
|
|
663
|
+
const sequenceBlock = readStruct(buffer, blocks[0]);
|
|
720
664
|
(0, import_assert.default)(sequenceBlock.length === 2);
|
|
721
665
|
const type = _readObjectIdentifier(buffer, sequenceBlock[0]);
|
|
722
666
|
names[type.name] = _readValue(buffer, sequenceBlock[1]);
|
|
@@ -734,11 +678,23 @@ function _readTime(buffer, block) {
|
|
|
734
678
|
return _readValue(buffer, block);
|
|
735
679
|
}
|
|
736
680
|
|
|
681
|
+
// source/crypto_utils.ts
|
|
682
|
+
var import_constants = __toESM(require("constants"));
|
|
683
|
+
var import_assert3 = __toESM(require("assert"));
|
|
684
|
+
var import_crypto = require("crypto");
|
|
685
|
+
var import_hexy = __toESM(require("hexy"));
|
|
686
|
+
|
|
687
|
+
// source/buffer_utils.ts
|
|
688
|
+
var createFastUninitializedBuffer = Buffer.allocUnsafe ? Buffer.allocUnsafe : (size) => {
|
|
689
|
+
return new Buffer(size);
|
|
690
|
+
};
|
|
691
|
+
|
|
737
692
|
// source/crypto_explore_certificate.ts
|
|
693
|
+
var import_assert2 = __toESM(require("assert"));
|
|
738
694
|
var doDebug = false;
|
|
739
695
|
function _readAttributeTypeAndValue(buffer, block) {
|
|
740
|
-
let inner_blocks =
|
|
741
|
-
inner_blocks =
|
|
696
|
+
let inner_blocks = readStruct(buffer, block);
|
|
697
|
+
inner_blocks = readStruct(buffer, inner_blocks[0]);
|
|
742
698
|
const data = {
|
|
743
699
|
identifier: _readObjectIdentifier(buffer, inner_blocks[0]).name,
|
|
744
700
|
value: _readValue(buffer, inner_blocks[1])
|
|
@@ -750,7 +706,7 @@ function _readAttributeTypeAndValue(buffer, block) {
|
|
|
750
706
|
return result;
|
|
751
707
|
}
|
|
752
708
|
function _readRelativeDistinguishedName(buffer, block) {
|
|
753
|
-
const inner_blocks =
|
|
709
|
+
const inner_blocks = readStruct(buffer, block);
|
|
754
710
|
const data = inner_blocks.map((block2) => _readAttributeTypeAndValue(buffer, block2));
|
|
755
711
|
const result = {};
|
|
756
712
|
for (const e of data) {
|
|
@@ -762,7 +718,7 @@ function _readName(buffer, block) {
|
|
|
762
718
|
return _readRelativeDistinguishedName(buffer, block);
|
|
763
719
|
}
|
|
764
720
|
function _readValidity(buffer, block) {
|
|
765
|
-
const inner_blocks =
|
|
721
|
+
const inner_blocks = readStruct(buffer, block);
|
|
766
722
|
return {
|
|
767
723
|
notBefore: _readTime(buffer, inner_blocks[0]),
|
|
768
724
|
notAfter: _readTime(buffer, inner_blocks[1])
|
|
@@ -770,27 +726,27 @@ function _readValidity(buffer, block) {
|
|
|
770
726
|
}
|
|
771
727
|
function _readAuthorityKeyIdentifier(buffer) {
|
|
772
728
|
const block_info = readTag(buffer, 0);
|
|
773
|
-
const blocks =
|
|
729
|
+
const blocks = readStruct(buffer, block_info);
|
|
774
730
|
const keyIdentifier_block = _findBlockAtIndex(blocks, 0);
|
|
775
731
|
const authorityCertIssuer_block = _findBlockAtIndex(blocks, 1);
|
|
776
732
|
const authorityCertSerialNumber_block = _findBlockAtIndex(blocks, 2);
|
|
777
733
|
function _readAuthorityCertIssuer(block) {
|
|
778
|
-
const inner_blocks =
|
|
734
|
+
const inner_blocks = readStruct(buffer, block);
|
|
779
735
|
const directoryName_block = _findBlockAtIndex(inner_blocks, 4);
|
|
780
736
|
if (directoryName_block) {
|
|
781
|
-
const a =
|
|
737
|
+
const a = readStruct(buffer, directoryName_block);
|
|
782
738
|
return _readDirectoryName(buffer, a[0]);
|
|
783
739
|
} else {
|
|
784
740
|
throw new Error("Invalid _readAuthorityCertIssuer");
|
|
785
741
|
}
|
|
786
742
|
}
|
|
787
743
|
function _readAuthorityCertIssuerFingerPrint(block) {
|
|
788
|
-
const inner_blocks =
|
|
744
|
+
const inner_blocks = readStruct(buffer, block);
|
|
789
745
|
const directoryName_block = _findBlockAtIndex(inner_blocks, 4);
|
|
790
746
|
if (!directoryName_block) {
|
|
791
747
|
return "";
|
|
792
748
|
}
|
|
793
|
-
const a =
|
|
749
|
+
const a = readStruct(buffer, directoryName_block);
|
|
794
750
|
if (a.length < 1) {
|
|
795
751
|
return "";
|
|
796
752
|
}
|
|
@@ -809,7 +765,7 @@ function _readAuthorityKeyIdentifier(buffer) {
|
|
|
809
765
|
}
|
|
810
766
|
function readBasicConstraint2_5_29_19(buffer, block) {
|
|
811
767
|
const block_info = readTag(buffer, 0);
|
|
812
|
-
const inner_blocks =
|
|
768
|
+
const inner_blocks = readStruct(buffer, block_info).slice(0, 2);
|
|
813
769
|
let cA = false;
|
|
814
770
|
let pathLengthConstraint = 0;
|
|
815
771
|
let breakControl = 0;
|
|
@@ -838,9 +794,10 @@ function _readGeneralNames(buffer, block) {
|
|
|
838
794
|
5: { name: "ediPartyName", type: "EDIPartyName" },
|
|
839
795
|
6: { name: "uniformResourceIdentifier", type: "IA5String" },
|
|
840
796
|
7: { name: "iPAddress", type: "OCTET_STRING" },
|
|
841
|
-
8: { name: "registeredID", type: "OBJECT_IDENTIFIER" }
|
|
797
|
+
8: { name: "registeredID", type: "OBJECT_IDENTIFIER" },
|
|
798
|
+
32: { name: "otherName", type: "AnotherName" }
|
|
842
799
|
};
|
|
843
|
-
const blocks =
|
|
800
|
+
const blocks = readStruct(buffer, block);
|
|
844
801
|
function _readFromType(buffer2, block2, type) {
|
|
845
802
|
switch (type) {
|
|
846
803
|
case "IA5String":
|
|
@@ -852,13 +809,28 @@ function _readGeneralNames(buffer, block) {
|
|
|
852
809
|
const n = {};
|
|
853
810
|
for (const block2 of blocks) {
|
|
854
811
|
(0, import_assert2.default)((block2.tag & 128) === 128);
|
|
855
|
-
const
|
|
856
|
-
const type = _data[
|
|
812
|
+
const t2 = block2.tag & 127;
|
|
813
|
+
const type = _data[t2];
|
|
857
814
|
if (!type) {
|
|
858
|
-
|
|
815
|
+
console.log("_readGeneralNames: INVALID TYPE => " + t2 + " 0x" + t2.toString(16));
|
|
816
|
+
continue;
|
|
817
|
+
}
|
|
818
|
+
if (t2 == 32) {
|
|
819
|
+
n[type.name] = n[type.name] || [];
|
|
820
|
+
const blocks2 = readStruct(buffer, block2);
|
|
821
|
+
const name = _readObjectIdentifier(buffer, blocks2[0]).name;
|
|
822
|
+
const buf = _getBlock(buffer, blocks2[1]);
|
|
823
|
+
const b = readTag(buf, 0);
|
|
824
|
+
const nn = _readValue(buf, b);
|
|
825
|
+
const data = {
|
|
826
|
+
identifier: name,
|
|
827
|
+
value: nn
|
|
828
|
+
};
|
|
829
|
+
n[type.name].push(data.value);
|
|
830
|
+
} else {
|
|
831
|
+
n[type.name] = n[type.name] || [];
|
|
832
|
+
n[type.name].push(_readFromType(buffer, block2, type.type));
|
|
859
833
|
}
|
|
860
|
-
n[type.name] = n[type.name] || [];
|
|
861
|
-
n[type.name].push(_readFromType(buffer, block2, type.type));
|
|
862
834
|
}
|
|
863
835
|
return n;
|
|
864
836
|
}
|
|
@@ -898,7 +870,7 @@ function readKeyUsage(oid, buffer) {
|
|
|
898
870
|
function readExtKeyUsage(oid, buffer) {
|
|
899
871
|
(0, import_assert2.default)(oid === "2.5.29.37");
|
|
900
872
|
const block_info = readTag(buffer, 0);
|
|
901
|
-
const inner_blocks =
|
|
873
|
+
const inner_blocks = readStruct(buffer, block_info);
|
|
902
874
|
const extKeyUsage = {
|
|
903
875
|
serverAuth: false,
|
|
904
876
|
clientAuth: false,
|
|
@@ -918,13 +890,13 @@ function readExtKeyUsage(oid, buffer) {
|
|
|
918
890
|
}
|
|
919
891
|
function _readSubjectPublicKey(buffer) {
|
|
920
892
|
const block_info = readTag(buffer, 0);
|
|
921
|
-
const blocks =
|
|
893
|
+
const blocks = readStruct(buffer, block_info);
|
|
922
894
|
return {
|
|
923
895
|
modulus: buffer.subarray(blocks[0].position + 1, blocks[0].position + blocks[0].length)
|
|
924
896
|
};
|
|
925
897
|
}
|
|
926
898
|
function _readExtension(buffer, block) {
|
|
927
|
-
const inner_blocks =
|
|
899
|
+
const inner_blocks = readStruct(buffer, block);
|
|
928
900
|
if (inner_blocks.length === 3) {
|
|
929
901
|
(0, import_assert2.default)(inner_blocks[1].tag === 1 /* BOOLEAN */);
|
|
930
902
|
inner_blocks[1] = inner_blocks[2];
|
|
@@ -964,8 +936,8 @@ function _readExtension(buffer, block) {
|
|
|
964
936
|
}
|
|
965
937
|
function _readExtensions(buffer, block) {
|
|
966
938
|
(0, import_assert2.default)(block.tag === 163);
|
|
967
|
-
let inner_blocks =
|
|
968
|
-
inner_blocks =
|
|
939
|
+
let inner_blocks = readStruct(buffer, block);
|
|
940
|
+
inner_blocks = readStruct(buffer, inner_blocks[0]);
|
|
969
941
|
const extensions = inner_blocks.map((block2) => _readExtension(buffer, block2));
|
|
970
942
|
const result = {};
|
|
971
943
|
for (const e of extensions) {
|
|
@@ -974,8 +946,8 @@ function _readExtensions(buffer, block) {
|
|
|
974
946
|
return result;
|
|
975
947
|
}
|
|
976
948
|
function _readSubjectPublicKeyInfo(buffer, block) {
|
|
977
|
-
const inner_blocks =
|
|
978
|
-
const algorithm =
|
|
949
|
+
const inner_blocks = readStruct(buffer, block);
|
|
950
|
+
const algorithm = readAlgorithmIdentifier(buffer, inner_blocks[0]);
|
|
979
951
|
const subjectPublicKey = _readBitString(buffer, inner_blocks[1]);
|
|
980
952
|
const data = subjectPublicKey.data;
|
|
981
953
|
const values = _readListOfInteger(data);
|
|
@@ -988,7 +960,7 @@ function _readSubjectPublicKeyInfo(buffer, block) {
|
|
|
988
960
|
};
|
|
989
961
|
}
|
|
990
962
|
function _readSubjectECCPublicKeyInfo(buffer, block) {
|
|
991
|
-
const inner_blocks =
|
|
963
|
+
const inner_blocks = readStruct(buffer, block);
|
|
992
964
|
const algorithm = _readECCAlgorithmIdentifier(buffer, inner_blocks[0]);
|
|
993
965
|
const subjectPublicKey = _readBitString(buffer, inner_blocks[1]);
|
|
994
966
|
const data = subjectPublicKey.data;
|
|
@@ -1001,13 +973,13 @@ function _readSubjectECCPublicKeyInfo(buffer, block) {
|
|
|
1001
973
|
};
|
|
1002
974
|
}
|
|
1003
975
|
function readTbsCertificate(buffer, block) {
|
|
1004
|
-
const blocks =
|
|
976
|
+
const blocks = readStruct(buffer, block);
|
|
1005
977
|
let version, serialNumber, signature, issuer, validity, subject, subjectFingerPrint, extensions;
|
|
1006
978
|
let subjectPublicKeyInfo;
|
|
1007
979
|
if (blocks.length === 6) {
|
|
1008
980
|
version = 1;
|
|
1009
981
|
serialNumber = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, blocks[0]));
|
|
1010
|
-
signature =
|
|
982
|
+
signature = readAlgorithmIdentifier(buffer, blocks[1]);
|
|
1011
983
|
issuer = _readName(buffer, blocks[2]);
|
|
1012
984
|
validity = _readValidity(buffer, blocks[3]);
|
|
1013
985
|
subject = _readName(buffer, blocks[4]);
|
|
@@ -1021,13 +993,13 @@ function readTbsCertificate(buffer, block) {
|
|
|
1021
993
|
}
|
|
1022
994
|
version = _readVersionValue(buffer, version_block) + 1;
|
|
1023
995
|
serialNumber = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, blocks[1]));
|
|
1024
|
-
signature =
|
|
996
|
+
signature = readAlgorithmIdentifier(buffer, blocks[2]);
|
|
1025
997
|
issuer = _readName(buffer, blocks[3]);
|
|
1026
998
|
validity = _readValidity(buffer, blocks[4]);
|
|
1027
999
|
subject = _readName(buffer, blocks[5]);
|
|
1028
1000
|
subjectFingerPrint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[5])));
|
|
1029
|
-
const inner_block =
|
|
1030
|
-
const what_type =
|
|
1001
|
+
const inner_block = readStruct(buffer, blocks[6]);
|
|
1002
|
+
const what_type = readAlgorithmIdentifier(buffer, inner_block[0]).identifier;
|
|
1031
1003
|
switch (what_type) {
|
|
1032
1004
|
case "rsaEncryption": {
|
|
1033
1005
|
subjectPublicKeyInfo = _readSubjectPublicKeyInfo(buffer, blocks[6]);
|
|
@@ -1063,11 +1035,11 @@ function exploreCertificate(certificate) {
|
|
|
1063
1035
|
(0, import_assert2.default)(certificate instanceof Buffer);
|
|
1064
1036
|
if (!certificate._exploreCertificate_cache) {
|
|
1065
1037
|
const block_info = readTag(certificate, 0);
|
|
1066
|
-
const blocks =
|
|
1038
|
+
const blocks = readStruct(certificate, block_info);
|
|
1067
1039
|
certificate._exploreCertificate_cache = {
|
|
1068
1040
|
tbsCertificate: readTbsCertificate(certificate, blocks[0]),
|
|
1069
|
-
signatureAlgorithm:
|
|
1070
|
-
signatureValue:
|
|
1041
|
+
signatureAlgorithm: readAlgorithmIdentifier(certificate, blocks[1]),
|
|
1042
|
+
signatureValue: readSignatureValue(certificate, blocks[2])
|
|
1071
1043
|
};
|
|
1072
1044
|
}
|
|
1073
1045
|
return certificate._exploreCertificate_cache;
|
|
@@ -1158,19 +1130,19 @@ function hexDump(buffer, width) {
|
|
|
1158
1130
|
}
|
|
1159
1131
|
}
|
|
1160
1132
|
function makeMessageChunkSignature(chunk, options) {
|
|
1161
|
-
const signer = (0,
|
|
1133
|
+
const signer = (0, import_crypto.createSign)(options.algorithm);
|
|
1162
1134
|
signer.update(chunk);
|
|
1163
1135
|
const signature = signer.sign(options.privateKey.hidden);
|
|
1164
1136
|
(0, import_assert3.default)(!options.signatureLength || signature.length === options.signatureLength);
|
|
1165
1137
|
return signature;
|
|
1166
1138
|
}
|
|
1167
1139
|
function verifyMessageChunkSignature(blockToVerify, signature, options) {
|
|
1168
|
-
const verify = (0,
|
|
1140
|
+
const verify = (0, import_crypto.createVerify)(options.algorithm);
|
|
1169
1141
|
verify.update(blockToVerify);
|
|
1170
1142
|
return verify.verify(options.publicKey, signature);
|
|
1171
1143
|
}
|
|
1172
1144
|
function makeSHA1Thumbprint(buffer) {
|
|
1173
|
-
return (0,
|
|
1145
|
+
return (0, import_crypto.createHash)("sha1").update(buffer).digest();
|
|
1174
1146
|
}
|
|
1175
1147
|
var RSA_PKCS1_OAEP_PADDING = import_constants.default.RSA_PKCS1_OAEP_PADDING;
|
|
1176
1148
|
var RSA_PKCS1_PADDING = import_constants.default.RSA_PKCS1_PADDING;
|
|
@@ -1185,7 +1157,7 @@ function publicEncrypt_native(buffer, publicKey, algorithm) {
|
|
|
1185
1157
|
if (algorithm === void 0) {
|
|
1186
1158
|
algorithm = 4 /* RSA_PKCS1_OAEP_PADDING */;
|
|
1187
1159
|
}
|
|
1188
|
-
return (0,
|
|
1160
|
+
return (0, import_crypto.publicEncrypt)(
|
|
1189
1161
|
{
|
|
1190
1162
|
key: publicKey,
|
|
1191
1163
|
padding: algorithm
|
|
@@ -1198,7 +1170,7 @@ function privateDecrypt_native(buffer, privateKey, algorithm) {
|
|
|
1198
1170
|
algorithm = 4 /* RSA_PKCS1_OAEP_PADDING */;
|
|
1199
1171
|
}
|
|
1200
1172
|
try {
|
|
1201
|
-
return (0,
|
|
1173
|
+
return (0, import_crypto.privateDecrypt)(
|
|
1202
1174
|
{
|
|
1203
1175
|
key: privateKey.hidden,
|
|
1204
1176
|
padding: algorithm
|
|
@@ -1280,13 +1252,192 @@ function extractPublicKeyFromCertificate(certificate, callback) {
|
|
|
1280
1252
|
});
|
|
1281
1253
|
}
|
|
1282
1254
|
|
|
1283
|
-
// source/
|
|
1255
|
+
// source/explore_private_key.ts
|
|
1256
|
+
function f(buffer, b) {
|
|
1257
|
+
return buffer.subarray(b.position + 1, b.position + b.length);
|
|
1258
|
+
}
|
|
1259
|
+
var doDebug2 = !!process.env.DEBUG;
|
|
1260
|
+
function explorePrivateKey(privateKey2) {
|
|
1261
|
+
const privateKey1 = privateKey2.hidden;
|
|
1262
|
+
const privateKey = typeof privateKey1 === "string" ? convertPEMtoDER(privateKey1) : privateKey1.export({ format: "der", type: "pkcs1" });
|
|
1263
|
+
const block_info = readTag(privateKey, 0);
|
|
1264
|
+
const blocks = readStruct(privateKey, block_info);
|
|
1265
|
+
if (blocks.length === 9) {
|
|
1266
|
+
const version2 = f(privateKey, blocks[0]);
|
|
1267
|
+
const modulus2 = f(privateKey, blocks[1]);
|
|
1268
|
+
const publicExponent2 = f(privateKey, blocks[2]);
|
|
1269
|
+
const privateExponent2 = f(privateKey, blocks[3]);
|
|
1270
|
+
const prime12 = f(privateKey, blocks[4]);
|
|
1271
|
+
const prime22 = f(privateKey, blocks[5]);
|
|
1272
|
+
const exponent12 = f(privateKey, blocks[6]);
|
|
1273
|
+
const exponent22 = f(privateKey, blocks[7]);
|
|
1274
|
+
return {
|
|
1275
|
+
version: version2,
|
|
1276
|
+
modulus: modulus2,
|
|
1277
|
+
publicExponent: publicExponent2,
|
|
1278
|
+
privateExponent: privateExponent2,
|
|
1279
|
+
prime1: prime12,
|
|
1280
|
+
prime2: prime22,
|
|
1281
|
+
exponent1: exponent12,
|
|
1282
|
+
exponent2: exponent22
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
if (doDebug2) {
|
|
1286
|
+
console.log("-------------------- private key:");
|
|
1287
|
+
console.log(block_info);
|
|
1288
|
+
console.log(
|
|
1289
|
+
blocks.map((b2) => ({
|
|
1290
|
+
tag: TagType[b2.tag] + " 0x" + b2.tag.toString(16),
|
|
1291
|
+
l: b2.length,
|
|
1292
|
+
p: b2.position,
|
|
1293
|
+
buff: privateKey.subarray(b2.position, b2.position + b2.length).toString("hex")
|
|
1294
|
+
}))
|
|
1295
|
+
);
|
|
1296
|
+
}
|
|
1297
|
+
const b = blocks[2];
|
|
1298
|
+
const bb = privateKey.subarray(b.position, b.position + b.length);
|
|
1299
|
+
const block_info1 = readTag(bb, 0);
|
|
1300
|
+
const blocks1 = readStruct(bb, block_info1);
|
|
1301
|
+
if (doDebug2) {
|
|
1302
|
+
console.log(
|
|
1303
|
+
blocks1.map((b2) => ({
|
|
1304
|
+
tag: TagType[b2.tag] + " 0x" + b2.tag.toString(16),
|
|
1305
|
+
l: b2.length,
|
|
1306
|
+
p: b2.position,
|
|
1307
|
+
buff: bb.subarray(b2.position, b2.position + b2.length).toString("hex")
|
|
1308
|
+
}))
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1311
|
+
const version = f(bb, blocks1[0]);
|
|
1312
|
+
const modulus = f(bb, blocks1[1]);
|
|
1313
|
+
const publicExponent = f(bb, blocks1[2]);
|
|
1314
|
+
const privateExponent = f(bb, blocks1[3]);
|
|
1315
|
+
const prime1 = f(bb, blocks1[4]);
|
|
1316
|
+
const prime2 = f(bb, blocks1[5]);
|
|
1317
|
+
const exponent1 = f(bb, blocks1[6]);
|
|
1318
|
+
const exponent2 = f(bb, blocks1[7]);
|
|
1319
|
+
return {
|
|
1320
|
+
version,
|
|
1321
|
+
modulus,
|
|
1322
|
+
publicExponent,
|
|
1323
|
+
privateExponent,
|
|
1324
|
+
prime1,
|
|
1325
|
+
prime2,
|
|
1326
|
+
exponent1,
|
|
1327
|
+
exponent2
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
// source/public_private_match.ts
|
|
1332
|
+
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
1333
|
+
const i = exploreCertificate(certificate);
|
|
1334
|
+
const j = explorePrivateKey(privateKey);
|
|
1335
|
+
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
1336
|
+
const modulus2 = j.modulus;
|
|
1337
|
+
if (modulus1.length != modulus2.length) {
|
|
1338
|
+
return false;
|
|
1339
|
+
}
|
|
1340
|
+
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
1341
|
+
}
|
|
1342
|
+
function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
1343
|
+
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
1344
|
+
const encryptedBuffer = publicEncrypt_long(initialBuffer, certificate, blockSize);
|
|
1345
|
+
const decryptedBuffer = privateDecrypt_long(encryptedBuffer, privateKey, blockSize);
|
|
1346
|
+
const finalString = decryptedBuffer.toString("utf-8");
|
|
1347
|
+
return initialBuffer.toString("utf-8") === finalString;
|
|
1348
|
+
}
|
|
1349
|
+
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
1350
|
+
const e = explorePrivateKey(privateKey);
|
|
1351
|
+
const blockSize = e.modulus.length;
|
|
1352
|
+
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
1353
|
+
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// source/common.ts
|
|
1357
|
+
var import_crypto2 = __toESM(require("crypto"));
|
|
1358
|
+
var KeyObjectOrig = import_crypto2.default.KeyObject;
|
|
1359
|
+
var { createPrivateKey: createPrivateKeyFromNodeJSCrypto } = import_crypto2.default;
|
|
1360
|
+
function isKeyObject(mayBeKeyObject) {
|
|
1361
|
+
if (KeyObjectOrig) {
|
|
1362
|
+
return mayBeKeyObject instanceof KeyObjectOrig;
|
|
1363
|
+
}
|
|
1364
|
+
return typeof mayBeKeyObject === "object" && typeof mayBeKeyObject.type === "string";
|
|
1365
|
+
}
|
|
1366
|
+
var CertificatePurpose = /* @__PURE__ */ ((CertificatePurpose2) => {
|
|
1367
|
+
CertificatePurpose2[CertificatePurpose2["NotSpecified"] = 0] = "NotSpecified";
|
|
1368
|
+
CertificatePurpose2[CertificatePurpose2["ForCertificateAuthority"] = 1] = "ForCertificateAuthority";
|
|
1369
|
+
CertificatePurpose2[CertificatePurpose2["ForApplication"] = 2] = "ForApplication";
|
|
1370
|
+
CertificatePurpose2[CertificatePurpose2["ForUserAuthentication"] = 3] = "ForUserAuthentication";
|
|
1371
|
+
return CertificatePurpose2;
|
|
1372
|
+
})(CertificatePurpose || {});
|
|
1373
|
+
|
|
1374
|
+
// source/crypto_utils2.ts
|
|
1284
1375
|
var import_assert4 = __toESM(require("assert"));
|
|
1376
|
+
var import_jsrsasign2 = __toESM(require("jsrsasign"));
|
|
1377
|
+
function rsaLengthPrivateKey(key) {
|
|
1378
|
+
const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
|
|
1379
|
+
const a = import_jsrsasign2.default.KEYUTIL.getKey(keyPem);
|
|
1380
|
+
return a.n.toString(16).length / 2;
|
|
1381
|
+
}
|
|
1382
|
+
function toPem2(raw_key, pem) {
|
|
1383
|
+
if (raw_key.hidden) {
|
|
1384
|
+
return toPem2(raw_key.hidden, pem);
|
|
1385
|
+
}
|
|
1386
|
+
(0, import_assert4.default)(raw_key, "expecting a key");
|
|
1387
|
+
(0, import_assert4.default)(typeof pem === "string");
|
|
1388
|
+
if (isKeyObject(raw_key)) {
|
|
1389
|
+
const _raw_key = raw_key;
|
|
1390
|
+
if (pem === "RSA PRIVATE KEY") {
|
|
1391
|
+
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs1" }).toString());
|
|
1392
|
+
} else if (pem === "PRIVATE KEY") {
|
|
1393
|
+
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs8" }).toString());
|
|
1394
|
+
} else {
|
|
1395
|
+
throw new Error("Unsupported case!");
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
return toPem(raw_key, pem);
|
|
1399
|
+
}
|
|
1400
|
+
function coercePrivateKeyPem(privateKey) {
|
|
1401
|
+
return toPem2(privateKey, "PRIVATE KEY");
|
|
1402
|
+
}
|
|
1403
|
+
function coercePublicKeyPem(publicKey) {
|
|
1404
|
+
if (isKeyObject(publicKey)) {
|
|
1405
|
+
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
1406
|
+
}
|
|
1407
|
+
(0, import_assert4.default)(typeof publicKey === "string");
|
|
1408
|
+
return publicKey;
|
|
1409
|
+
}
|
|
1410
|
+
function coerceRsaPublicKeyPem(publicKey) {
|
|
1411
|
+
if (isKeyObject(publicKey)) {
|
|
1412
|
+
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
1413
|
+
}
|
|
1414
|
+
(0, import_assert4.default)(typeof publicKey === "string");
|
|
1415
|
+
return publicKey;
|
|
1416
|
+
}
|
|
1417
|
+
function rsaLengthPublicKey(key) {
|
|
1418
|
+
key = coercePublicKeyPem(key);
|
|
1419
|
+
(0, import_assert4.default)(typeof key === "string");
|
|
1420
|
+
const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
|
|
1421
|
+
return a.n.toString(16).length / 2;
|
|
1422
|
+
}
|
|
1423
|
+
function rsaLengthRsaPublicKey(key) {
|
|
1424
|
+
key = coerceRsaPublicKeyPem(key);
|
|
1425
|
+
(0, import_assert4.default)(typeof key === "string");
|
|
1426
|
+
const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
|
|
1427
|
+
return a.n.toString(16).length / 2;
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
// source/derived_keys.ts
|
|
1431
|
+
var import_assert6 = __toESM(require("assert"));
|
|
1432
|
+
var import_crypto3 = require("crypto");
|
|
1433
|
+
|
|
1434
|
+
// source/explore_certificate.ts
|
|
1435
|
+
var import_assert5 = __toESM(require("assert"));
|
|
1285
1436
|
function coerceCertificate(certificate) {
|
|
1286
1437
|
if (typeof certificate === "string") {
|
|
1287
1438
|
certificate = convertPEMtoDER(certificate);
|
|
1288
1439
|
}
|
|
1289
|
-
(0,
|
|
1440
|
+
(0, import_assert5.default)(certificate instanceof Buffer);
|
|
1290
1441
|
return certificate;
|
|
1291
1442
|
}
|
|
1292
1443
|
function exploreCertificateInfo(certificate) {
|
|
@@ -1313,8 +1464,8 @@ function plus(buf1, buf2) {
|
|
|
1313
1464
|
return Buffer.concat([buf1, buf2]);
|
|
1314
1465
|
}
|
|
1315
1466
|
function makePseudoRandomBuffer(secret, seed, minLength, sha1or256) {
|
|
1316
|
-
(0,
|
|
1317
|
-
(0,
|
|
1467
|
+
(0, import_assert6.default)(seed instanceof Buffer);
|
|
1468
|
+
(0, import_assert6.default)(sha1or256 === "SHA1" || sha1or256 === "SHA256");
|
|
1318
1469
|
const a = [];
|
|
1319
1470
|
a[0] = seed;
|
|
1320
1471
|
let index = 1;
|
|
@@ -1327,12 +1478,12 @@ function makePseudoRandomBuffer(secret, seed, minLength, sha1or256) {
|
|
|
1327
1478
|
return p_hash.subarray(0, minLength);
|
|
1328
1479
|
}
|
|
1329
1480
|
function computeDerivedKeys(secret, seed, options) {
|
|
1330
|
-
(0,
|
|
1331
|
-
(0,
|
|
1332
|
-
(0,
|
|
1333
|
-
(0,
|
|
1481
|
+
(0, import_assert6.default)(Number.isFinite(options.signatureLength));
|
|
1482
|
+
(0, import_assert6.default)(Number.isFinite(options.encryptingKeyLength));
|
|
1483
|
+
(0, import_assert6.default)(Number.isFinite(options.encryptingBlockSize));
|
|
1484
|
+
(0, import_assert6.default)(typeof options.algorithm === "string");
|
|
1334
1485
|
options.sha1or256 = options.sha1or256 || "SHA1";
|
|
1335
|
-
(0,
|
|
1486
|
+
(0, import_assert6.default)(typeof options.sha1or256 === "string");
|
|
1336
1487
|
const offset1 = options.signingKeyLength;
|
|
1337
1488
|
const offset2 = offset1 + options.encryptingKeyLength;
|
|
1338
1489
|
const minLength = offset2 + options.encryptingBlockSize;
|
|
@@ -1357,7 +1508,7 @@ function removePadding(buffer) {
|
|
|
1357
1508
|
return reduceLength(buffer, nbPaddingBytes);
|
|
1358
1509
|
}
|
|
1359
1510
|
function verifyChunkSignature(chunk, options) {
|
|
1360
|
-
(0,
|
|
1511
|
+
(0, import_assert6.default)(chunk instanceof Buffer);
|
|
1361
1512
|
let signatureLength = options.signatureLength || 0;
|
|
1362
1513
|
if (signatureLength === 0) {
|
|
1363
1514
|
const cert = exploreCertificateInfo(options.publicKey);
|
|
@@ -1368,16 +1519,16 @@ function verifyChunkSignature(chunk, options) {
|
|
|
1368
1519
|
return verifyMessageChunkSignature(block_to_verify, signature, options);
|
|
1369
1520
|
}
|
|
1370
1521
|
function computePaddingFooter(buffer, derivedKeys) {
|
|
1371
|
-
(0,
|
|
1522
|
+
(0, import_assert6.default)(Object.prototype.hasOwnProperty.call(derivedKeys, "encryptingBlockSize"));
|
|
1372
1523
|
const paddingSize = derivedKeys.encryptingBlockSize - (buffer.length + 1) % derivedKeys.encryptingBlockSize;
|
|
1373
1524
|
const padding = createFastUninitializedBuffer(paddingSize + 1);
|
|
1374
1525
|
padding.fill(paddingSize);
|
|
1375
1526
|
return padding;
|
|
1376
1527
|
}
|
|
1377
1528
|
function derivedKeys_algorithm(derivedKeys) {
|
|
1378
|
-
(0,
|
|
1529
|
+
(0, import_assert6.default)(Object.prototype.hasOwnProperty.call(derivedKeys, "algorithm"));
|
|
1379
1530
|
const algorithm = derivedKeys.algorithm || "aes-128-cbc";
|
|
1380
|
-
(0,
|
|
1531
|
+
(0, import_assert6.default)(algorithm === "aes-128-cbc" || algorithm === "aes-256-cbc");
|
|
1381
1532
|
return algorithm;
|
|
1382
1533
|
}
|
|
1383
1534
|
function encryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
@@ -1403,12 +1554,12 @@ function decryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
|
1403
1554
|
return Buffer.concat(decrypted_chunks);
|
|
1404
1555
|
}
|
|
1405
1556
|
function makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys) {
|
|
1406
|
-
(0,
|
|
1407
|
-
(0,
|
|
1408
|
-
(0,
|
|
1409
|
-
(0,
|
|
1557
|
+
(0, import_assert6.default)(message instanceof Buffer);
|
|
1558
|
+
(0, import_assert6.default)(derivedKeys.signingKey instanceof Buffer);
|
|
1559
|
+
(0, import_assert6.default)(typeof derivedKeys.sha1or256 === "string");
|
|
1560
|
+
(0, import_assert6.default)(derivedKeys.sha1or256 === "SHA1" || derivedKeys.sha1or256 === "SHA256");
|
|
1410
1561
|
const signature = (0, import_crypto3.createHmac)(derivedKeys.sha1or256, derivedKeys.signingKey).update(message).digest();
|
|
1411
|
-
(0,
|
|
1562
|
+
(0, import_assert6.default)(signature.length === derivedKeys.signatureLength);
|
|
1412
1563
|
return signature;
|
|
1413
1564
|
}
|
|
1414
1565
|
function verifyChunkSignatureWithDerivedKeys(chunk, derivedKeys) {
|
|
@@ -1418,126 +1569,31 @@ function verifyChunkSignatureWithDerivedKeys(chunk, derivedKeys) {
|
|
|
1418
1569
|
return computedSignature.toString("hex") === expectedSignature.toString("hex");
|
|
1419
1570
|
}
|
|
1420
1571
|
|
|
1421
|
-
// source/
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
const
|
|
1427
|
-
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
return toPem(raw_key, pem);
|
|
1446
|
-
}
|
|
1447
|
-
function coercePrivateKeyPem(privateKey) {
|
|
1448
|
-
return toPem2(privateKey, "PRIVATE KEY");
|
|
1449
|
-
}
|
|
1450
|
-
function coercePublicKeyPem(publicKey) {
|
|
1451
|
-
if (isKeyObject(publicKey)) {
|
|
1452
|
-
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
1453
|
-
}
|
|
1454
|
-
(0, import_assert6.default)(typeof publicKey === "string");
|
|
1455
|
-
return publicKey;
|
|
1456
|
-
}
|
|
1457
|
-
function coerceRsaPublicKeyPem(publicKey) {
|
|
1458
|
-
if (isKeyObject(publicKey)) {
|
|
1459
|
-
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
1460
|
-
}
|
|
1461
|
-
(0, import_assert6.default)(typeof publicKey === "string");
|
|
1462
|
-
return publicKey;
|
|
1463
|
-
}
|
|
1464
|
-
function rsaLengthPublicKey(key) {
|
|
1465
|
-
key = coercePublicKeyPem(key);
|
|
1466
|
-
(0, import_assert6.default)(typeof key === "string");
|
|
1467
|
-
const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
|
|
1468
|
-
return a.n.toString(16).length / 2;
|
|
1469
|
-
}
|
|
1470
|
-
function rsaLengthRsaPublicKey(key) {
|
|
1471
|
-
key = coerceRsaPublicKeyPem(key);
|
|
1472
|
-
(0, import_assert6.default)(typeof key === "string");
|
|
1473
|
-
const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
|
|
1474
|
-
return a.n.toString(16).length / 2;
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
// source/verify_certificate_signature.ts
|
|
1478
|
-
var import_crypto4 = require("crypto");
|
|
1479
|
-
function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
1480
|
-
const block_info = readTag(certificateOrCrl, 0);
|
|
1481
|
-
const blocks = _readStruct(certificateOrCrl, block_info);
|
|
1482
|
-
const bufferToBeSigned = certificateOrCrl.subarray(block_info.position, blocks[1].position - 2);
|
|
1483
|
-
const signatureAlgorithm = _readAlgorithmIdentifier(certificateOrCrl, blocks[1]);
|
|
1484
|
-
const signatureValue = _readSignatureValueBin(certificateOrCrl, blocks[2]);
|
|
1485
|
-
const p = split_der(parentCertificate)[0];
|
|
1486
|
-
const certPem = toPem(p, "CERTIFICATE");
|
|
1487
|
-
const verify = (0, import_crypto4.createVerify)(signatureAlgorithm.identifier);
|
|
1488
|
-
verify.update(bufferToBeSigned);
|
|
1489
|
-
verify.end();
|
|
1490
|
-
return verify.verify(certPem, signatureValue);
|
|
1491
|
-
}
|
|
1492
|
-
function verifyCertificateSignature(certificate, parentCertificate) {
|
|
1493
|
-
return verifyCertificateOrClrSignature(certificate, parentCertificate);
|
|
1494
|
-
}
|
|
1495
|
-
function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
|
|
1496
|
-
return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
|
|
1497
|
-
}
|
|
1498
|
-
async function verifyCertificateChain(certificateChain) {
|
|
1499
|
-
for (let index = 1; index < certificateChain.length; index++) {
|
|
1500
|
-
const cert = certificateChain[index - 1];
|
|
1501
|
-
const certParent = certificateChain[index];
|
|
1502
|
-
const certParentInfo = exploreCertificate(certParent);
|
|
1503
|
-
const keyUsage = certParentInfo.tbsCertificate.extensions.keyUsage;
|
|
1504
|
-
if (!keyUsage.keyCertSign) {
|
|
1505
|
-
return {
|
|
1506
|
-
status: "BadCertificateIssuerUseNotAllowed",
|
|
1507
|
-
reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing"
|
|
1508
|
-
};
|
|
1509
|
-
}
|
|
1510
|
-
const parentSignChild = verifyCertificateSignature(cert, certParent);
|
|
1511
|
-
if (!parentSignChild) {
|
|
1512
|
-
return {
|
|
1513
|
-
status: "BadCertificateInvalid",
|
|
1514
|
-
reason: "One of the certificate in the chain is not signing the previous certificate"
|
|
1515
|
-
};
|
|
1516
|
-
}
|
|
1517
|
-
const certInfo = exploreCertificate(cert);
|
|
1518
|
-
if (!certInfo.tbsCertificate.extensions) {
|
|
1519
|
-
return {
|
|
1520
|
-
status: "BadCertificateInvalid",
|
|
1521
|
-
reason: "Cannot find X409 Extension 3 in certificate"
|
|
1522
|
-
};
|
|
1523
|
-
}
|
|
1524
|
-
if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
|
|
1525
|
-
return {
|
|
1526
|
-
status: "BadCertificateInvalid",
|
|
1527
|
-
reason: "Cannot find X409 Extension 3 in certificate (parent)"
|
|
1528
|
-
};
|
|
1529
|
-
}
|
|
1530
|
-
if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !== certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
|
|
1531
|
-
return {
|
|
1532
|
-
status: "BadCertificateInvalid",
|
|
1533
|
-
reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate"
|
|
1534
|
-
};
|
|
1572
|
+
// source/explore_asn1.ts
|
|
1573
|
+
function t(tag) {
|
|
1574
|
+
return TagType[tag];
|
|
1575
|
+
}
|
|
1576
|
+
function bi(blockInfo, depth) {
|
|
1577
|
+
const indent = " ".repeat(depth);
|
|
1578
|
+
const hl = blockInfo.position - blockInfo.start;
|
|
1579
|
+
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)}`;
|
|
1580
|
+
}
|
|
1581
|
+
function exploreAsn1(buffer) {
|
|
1582
|
+
console.log(hexDump(buffer));
|
|
1583
|
+
function dump(offset, depth) {
|
|
1584
|
+
const blockInfo = readTag(buffer, offset);
|
|
1585
|
+
dumpBlock(blockInfo, depth);
|
|
1586
|
+
function dumpBlock(blockInfo2, depth2) {
|
|
1587
|
+
console.log(bi(blockInfo2, depth2));
|
|
1588
|
+
if (blockInfo2.tag === 48 /* SEQUENCE */ || blockInfo2.tag === 49 /* SET */ || blockInfo2.tag >= 160 /* CONTEXT_SPECIFIC0 */) {
|
|
1589
|
+
const blocks = readStruct(buffer, blockInfo2);
|
|
1590
|
+
for (const block of blocks) {
|
|
1591
|
+
dumpBlock(block, depth2 + 1);
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1535
1594
|
}
|
|
1536
1595
|
}
|
|
1537
|
-
|
|
1538
|
-
status: "Good",
|
|
1539
|
-
reason: `certificate chain is valid(length = ${certificateChain.length})`
|
|
1540
|
-
};
|
|
1596
|
+
dump(0, 0);
|
|
1541
1597
|
}
|
|
1542
1598
|
|
|
1543
1599
|
// source/explore_certificate_revocation_list.ts
|
|
@@ -1545,20 +1601,20 @@ function readNameForCrl(buffer, block) {
|
|
|
1545
1601
|
return _readDirectoryName(buffer, block);
|
|
1546
1602
|
}
|
|
1547
1603
|
function _readTbsCertList(buffer, blockInfo) {
|
|
1548
|
-
const blocks =
|
|
1604
|
+
const blocks = readStruct(buffer, blockInfo);
|
|
1549
1605
|
const hasOptionalVersion = blocks[0].tag === 2 /* INTEGER */;
|
|
1550
1606
|
if (hasOptionalVersion) {
|
|
1551
1607
|
const version = _readIntegerValue(buffer, blocks[0]);
|
|
1552
|
-
const signature =
|
|
1608
|
+
const signature = readAlgorithmIdentifier(buffer, blocks[1]);
|
|
1553
1609
|
const issuer = readNameForCrl(buffer, blocks[2]);
|
|
1554
1610
|
const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[2])));
|
|
1555
1611
|
const thisUpdate = _readTime(buffer, blocks[3]);
|
|
1556
1612
|
const nextUpdate = _readTime(buffer, blocks[4]);
|
|
1557
1613
|
const revokedCertificates = [];
|
|
1558
1614
|
if (blocks[5] && blocks[5].tag < 128) {
|
|
1559
|
-
const list =
|
|
1615
|
+
const list = readStruct(buffer, blocks[5]);
|
|
1560
1616
|
for (const r of list) {
|
|
1561
|
-
const rr =
|
|
1617
|
+
const rr = readStruct(buffer, r);
|
|
1562
1618
|
const userCertificate = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, rr[0]));
|
|
1563
1619
|
const revocationDate = _readTime(buffer, rr[1]);
|
|
1564
1620
|
revokedCertificates.push({
|
|
@@ -1570,16 +1626,16 @@ function _readTbsCertList(buffer, blockInfo) {
|
|
|
1570
1626
|
const ext0 = _findBlockAtIndex(blocks, 0);
|
|
1571
1627
|
return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates };
|
|
1572
1628
|
} else {
|
|
1573
|
-
const signature =
|
|
1629
|
+
const signature = readAlgorithmIdentifier(buffer, blocks[0]);
|
|
1574
1630
|
const issuer = readNameForCrl(buffer, blocks[1]);
|
|
1575
1631
|
const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[1])));
|
|
1576
1632
|
const thisUpdate = _readTime(buffer, blocks[2]);
|
|
1577
1633
|
const nextUpdate = _readTime(buffer, blocks[3]);
|
|
1578
1634
|
const revokedCertificates = [];
|
|
1579
1635
|
if (blocks[4] && blocks[4].tag < 128) {
|
|
1580
|
-
const list =
|
|
1636
|
+
const list = readStruct(buffer, blocks[4]);
|
|
1581
1637
|
for (const r of list) {
|
|
1582
|
-
const rr =
|
|
1638
|
+
const rr = readStruct(buffer, r);
|
|
1583
1639
|
const userCertificate = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, rr[0]));
|
|
1584
1640
|
const revocationDate = _readTime(buffer, rr[1]);
|
|
1585
1641
|
revokedCertificates.push({
|
|
@@ -1593,224 +1649,59 @@ function _readTbsCertList(buffer, blockInfo) {
|
|
|
1593
1649
|
}
|
|
1594
1650
|
function exploreCertificateRevocationList(crl) {
|
|
1595
1651
|
const blockInfo = readTag(crl, 0);
|
|
1596
|
-
const blocks =
|
|
1652
|
+
const blocks = readStruct(crl, blockInfo);
|
|
1597
1653
|
const tbsCertList = _readTbsCertList(crl, blocks[0]);
|
|
1598
|
-
const signatureAlgorithm =
|
|
1599
|
-
const signatureValue =
|
|
1654
|
+
const signatureAlgorithm = readAlgorithmIdentifier(crl, blocks[1]);
|
|
1655
|
+
const signatureValue = readSignatureValueBin(crl, blocks[2]);
|
|
1600
1656
|
return { tbsCertList, signatureAlgorithm, signatureValue };
|
|
1601
1657
|
}
|
|
1602
1658
|
|
|
1603
1659
|
// source/explore_certificate_signing_request.ts
|
|
1604
1660
|
function _readExtensionRequest(buffer) {
|
|
1605
1661
|
const block = readTag(buffer, 0);
|
|
1606
|
-
const inner_blocks =
|
|
1662
|
+
const inner_blocks = readStruct(buffer, block);
|
|
1607
1663
|
const extensions = inner_blocks.map((block1) => _readExtension(buffer, block1));
|
|
1608
1664
|
const result = {};
|
|
1609
1665
|
for (const e of extensions) {
|
|
1610
1666
|
result[e.identifier.name] = e.value;
|
|
1611
1667
|
}
|
|
1612
1668
|
const { basicConstraints, keyUsage, subjectAltName } = result;
|
|
1613
|
-
return { basicConstraints, keyUsage, subjectAltName };
|
|
1614
|
-
}
|
|
1615
|
-
function readCertificationRequestInfo(buffer, block) {
|
|
1616
|
-
const blocks = _readStruct(buffer, block);
|
|
1617
|
-
if (blocks.length === 4) {
|
|
1618
|
-
const extensionRequestBlock = _findBlockAtIndex(blocks, 0);
|
|
1619
|
-
if (!extensionRequestBlock) {
|
|
1620
|
-
throw new Error("cannot find extensionRequest block");
|
|
1621
|
-
}
|
|
1622
|
-
const blocks1 = _readStruct(buffer, extensionRequestBlock);
|
|
1623
|
-
const blocks2 = _readStruct(buffer, blocks1[0]);
|
|
1624
|
-
const identifier = _readObjectIdentifier(buffer, blocks2[0]);
|
|
1625
|
-
if (identifier.name !== "extensionRequest") {
|
|
1626
|
-
throw new Error(" Cannot find extension Request in ASN1 block");
|
|
1627
|
-
}
|
|
1628
|
-
const buf = _getBlock(buffer, blocks2[1]);
|
|
1629
|
-
const extensionRequest = _readExtensionRequest(buf);
|
|
1630
|
-
return { extensionRequest };
|
|
1631
|
-
}
|
|
1632
|
-
throw new Error("Invalid CSR or ");
|
|
1633
|
-
}
|
|
1634
|
-
function exploreCertificateSigningRequest(crl) {
|
|
1635
|
-
const blockInfo = readTag(crl, 0);
|
|
1636
|
-
const blocks = _readStruct(crl, blockInfo);
|
|
1637
|
-
const csrInfo = readCertificationRequestInfo(crl, blocks[0]);
|
|
1638
|
-
return csrInfo;
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
// source/explore_private_key.ts
|
|
1642
|
-
function f(buffer, b) {
|
|
1643
|
-
return buffer.subarray(b.position + 1, b.position + b.length);
|
|
1644
|
-
}
|
|
1645
|
-
var doDebug2 = !!process.env.DEBUG;
|
|
1646
|
-
function explorePrivateKey(privateKey2) {
|
|
1647
|
-
const privateKey1 = privateKey2.hidden;
|
|
1648
|
-
const privateKey = typeof privateKey1 === "string" ? convertPEMtoDER(privateKey1) : privateKey1.export({ format: "der", type: "pkcs1" });
|
|
1649
|
-
const block_info = readTag(privateKey, 0);
|
|
1650
|
-
const blocks = _readStruct(privateKey, block_info);
|
|
1651
|
-
if (blocks.length === 9) {
|
|
1652
|
-
const version2 = f(privateKey, blocks[0]);
|
|
1653
|
-
const modulus2 = f(privateKey, blocks[1]);
|
|
1654
|
-
const publicExponent2 = f(privateKey, blocks[2]);
|
|
1655
|
-
const privateExponent2 = f(privateKey, blocks[3]);
|
|
1656
|
-
const prime12 = f(privateKey, blocks[4]);
|
|
1657
|
-
const prime22 = f(privateKey, blocks[5]);
|
|
1658
|
-
const exponent12 = f(privateKey, blocks[6]);
|
|
1659
|
-
const exponent22 = f(privateKey, blocks[7]);
|
|
1660
|
-
return {
|
|
1661
|
-
version: version2,
|
|
1662
|
-
modulus: modulus2,
|
|
1663
|
-
publicExponent: publicExponent2,
|
|
1664
|
-
privateExponent: privateExponent2,
|
|
1665
|
-
prime1: prime12,
|
|
1666
|
-
prime2: prime22,
|
|
1667
|
-
exponent1: exponent12,
|
|
1668
|
-
exponent2: exponent22
|
|
1669
|
-
};
|
|
1670
|
-
}
|
|
1671
|
-
if (doDebug2) {
|
|
1672
|
-
console.log("-------------------- private key:");
|
|
1673
|
-
console.log(block_info);
|
|
1674
|
-
console.log(
|
|
1675
|
-
blocks.map((b2) => ({
|
|
1676
|
-
tag: TagType[b2.tag] + " 0x" + b2.tag.toString(16),
|
|
1677
|
-
l: b2.length,
|
|
1678
|
-
p: b2.position,
|
|
1679
|
-
buff: privateKey.subarray(b2.position, b2.position + b2.length).toString("hex")
|
|
1680
|
-
}))
|
|
1681
|
-
);
|
|
1682
|
-
}
|
|
1683
|
-
const b = blocks[2];
|
|
1684
|
-
const bb = privateKey.subarray(b.position, b.position + b.length);
|
|
1685
|
-
const block_info1 = readTag(bb, 0);
|
|
1686
|
-
const blocks1 = _readStruct(bb, block_info1);
|
|
1687
|
-
if (doDebug2) {
|
|
1688
|
-
console.log(
|
|
1689
|
-
blocks1.map((b2) => ({
|
|
1690
|
-
tag: TagType[b2.tag] + " 0x" + b2.tag.toString(16),
|
|
1691
|
-
l: b2.length,
|
|
1692
|
-
p: b2.position,
|
|
1693
|
-
buff: bb.subarray(b2.position, b2.position + b2.length).toString("hex")
|
|
1694
|
-
}))
|
|
1695
|
-
);
|
|
1696
|
-
}
|
|
1697
|
-
const version = f(bb, blocks1[0]);
|
|
1698
|
-
const modulus = f(bb, blocks1[1]);
|
|
1699
|
-
const publicExponent = f(bb, blocks1[2]);
|
|
1700
|
-
const privateExponent = f(bb, blocks1[3]);
|
|
1701
|
-
const prime1 = f(bb, blocks1[4]);
|
|
1702
|
-
const prime2 = f(bb, blocks1[5]);
|
|
1703
|
-
const exponent1 = f(bb, blocks1[6]);
|
|
1704
|
-
const exponent2 = f(bb, blocks1[7]);
|
|
1705
|
-
return {
|
|
1706
|
-
version,
|
|
1707
|
-
modulus,
|
|
1708
|
-
publicExponent,
|
|
1709
|
-
privateExponent,
|
|
1710
|
-
prime1,
|
|
1711
|
-
prime2,
|
|
1712
|
-
exponent1,
|
|
1713
|
-
exponent2
|
|
1714
|
-
};
|
|
1715
|
-
}
|
|
1716
|
-
|
|
1717
|
-
// source/public_private_match.ts
|
|
1718
|
-
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
1719
|
-
const i = exploreCertificate(certificate);
|
|
1720
|
-
const j = explorePrivateKey(privateKey);
|
|
1721
|
-
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
1722
|
-
const modulus2 = j.modulus;
|
|
1723
|
-
if (modulus1.length != modulus2.length) {
|
|
1724
|
-
return false;
|
|
1725
|
-
}
|
|
1726
|
-
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
1727
|
-
}
|
|
1728
|
-
function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
1729
|
-
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
1730
|
-
const encryptedBuffer = publicEncrypt_long(initialBuffer, certificate, blockSize);
|
|
1731
|
-
const decryptedBuffer = privateDecrypt_long(encryptedBuffer, privateKey, blockSize);
|
|
1732
|
-
const finalString = decryptedBuffer.toString("utf-8");
|
|
1733
|
-
return initialBuffer.toString("utf-8") === finalString;
|
|
1734
|
-
}
|
|
1735
|
-
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
1736
|
-
const e = explorePrivateKey(privateKey);
|
|
1737
|
-
const blockSize = e.modulus.length;
|
|
1738
|
-
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
1739
|
-
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
1740
|
-
}
|
|
1741
|
-
|
|
1742
|
-
// source/x509/_crypto.ts
|
|
1743
|
-
var x509 = __toESM(require("@peculiar/x509"));
|
|
1744
|
-
var import_webcrypto = require("@peculiar/webcrypto");
|
|
1745
|
-
var import_crypto5 = __toESM(require("crypto"));
|
|
1746
|
-
var x5092 = __toESM(require("@peculiar/x509"));
|
|
1747
|
-
var doDebug3 = false;
|
|
1748
|
-
var _crypto;
|
|
1749
|
-
var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
|
|
1750
|
-
if (typeof window === "undefined") {
|
|
1751
|
-
_crypto = import_crypto5.default;
|
|
1752
|
-
if (!_crypto?.subtle || ignoreCrypto) {
|
|
1753
|
-
_crypto = new import_webcrypto.Crypto();
|
|
1754
|
-
doDebug3 && console.warn("using @peculiar/webcrypto");
|
|
1755
|
-
} else {
|
|
1756
|
-
doDebug3 && console.warn("using nodejs crypto (native)");
|
|
1757
|
-
}
|
|
1758
|
-
x509.cryptoProvider.set(_crypto);
|
|
1759
|
-
} else {
|
|
1760
|
-
doDebug3 && console.warn("using browser crypto (native)");
|
|
1761
|
-
_crypto = crypto;
|
|
1762
|
-
x509.cryptoProvider.set(crypto);
|
|
1763
|
-
}
|
|
1764
|
-
function getCrypto() {
|
|
1765
|
-
return _crypto || crypto || require("crypto");
|
|
1766
|
-
}
|
|
1767
|
-
|
|
1768
|
-
// source/x509/create_key_pair.ts
|
|
1769
|
-
async function generateKeyPair(modulusLength = 2048) {
|
|
1770
|
-
const crypto3 = getCrypto();
|
|
1771
|
-
const alg = {
|
|
1772
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
1773
|
-
hash: { name: "SHA-256" },
|
|
1774
|
-
publicExponent: new Uint8Array([1, 0, 1]),
|
|
1775
|
-
modulusLength
|
|
1776
|
-
};
|
|
1777
|
-
const keys = await crypto3.subtle.generateKey(alg, true, ["sign", "verify"]);
|
|
1778
|
-
return keys;
|
|
1669
|
+
return { basicConstraints, keyUsage, subjectAltName };
|
|
1779
1670
|
}
|
|
1780
|
-
|
|
1781
|
-
|
|
1671
|
+
function readCertificationRequestInfo(buffer, block) {
|
|
1672
|
+
const blocks = readStruct(buffer, block);
|
|
1673
|
+
if (blocks.length === 4) {
|
|
1674
|
+
const extensionRequestBlock = _findBlockAtIndex(blocks, 0);
|
|
1675
|
+
if (!extensionRequestBlock) {
|
|
1676
|
+
throw new Error("cannot find extensionRequest block");
|
|
1677
|
+
}
|
|
1678
|
+
const blocks1 = readStruct(buffer, extensionRequestBlock);
|
|
1679
|
+
const blocks2 = readStruct(buffer, blocks1[0]);
|
|
1680
|
+
const identifier = _readObjectIdentifier(buffer, blocks2[0]);
|
|
1681
|
+
if (identifier.name !== "extensionRequest") {
|
|
1682
|
+
throw new Error(" Cannot find extension Request in ASN1 block");
|
|
1683
|
+
}
|
|
1684
|
+
const buf = _getBlock(buffer, blocks2[1]);
|
|
1685
|
+
const extensionRequest = _readExtensionRequest(buf);
|
|
1686
|
+
return { extensionRequest };
|
|
1687
|
+
}
|
|
1688
|
+
throw new Error("Invalid CSR or ");
|
|
1782
1689
|
}
|
|
1783
|
-
|
|
1784
|
-
const
|
|
1785
|
-
const
|
|
1786
|
-
const
|
|
1787
|
-
return
|
|
1690
|
+
function exploreCertificateSigningRequest(crl) {
|
|
1691
|
+
const blockInfo = readTag(crl, 0);
|
|
1692
|
+
const blocks = readStruct(crl, blockInfo);
|
|
1693
|
+
const csrInfo = readCertificationRequestInfo(crl, blocks[0]);
|
|
1694
|
+
return csrInfo;
|
|
1788
1695
|
}
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
privDer,
|
|
1794
|
-
{
|
|
1795
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
1796
|
-
hash: { name: "SHA-256" }
|
|
1797
|
-
},
|
|
1798
|
-
true,
|
|
1799
|
-
[
|
|
1800
|
-
"sign"
|
|
1801
|
-
// "encrypt",
|
|
1802
|
-
// "decrypt",
|
|
1803
|
-
// "verify",
|
|
1804
|
-
// "wrapKey",
|
|
1805
|
-
// "unwrapKey",
|
|
1806
|
-
// "deriveKey",
|
|
1807
|
-
// "deriveBits"
|
|
1808
|
-
]
|
|
1809
|
-
);
|
|
1696
|
+
|
|
1697
|
+
// source/make_private_key_from_pem.ts
|
|
1698
|
+
function makePrivateKeyFromPem(privateKeyInPem) {
|
|
1699
|
+
return { hidden: privateKeyInPem };
|
|
1810
1700
|
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1701
|
+
|
|
1702
|
+
// source/make_private_key_thumbprint.ts
|
|
1703
|
+
function makePrivateKeyThumbPrint(privateKey) {
|
|
1704
|
+
return Buffer.alloc(0);
|
|
1814
1705
|
}
|
|
1815
1706
|
|
|
1816
1707
|
// source/subject.ts
|
|
@@ -1895,11 +1786,180 @@ var Subject = class _Subject {
|
|
|
1895
1786
|
return this.toStringInternal("/");
|
|
1896
1787
|
}
|
|
1897
1788
|
toString() {
|
|
1898
|
-
const
|
|
1899
|
-
return
|
|
1789
|
+
const t2 = this.toStringForOPCUA();
|
|
1790
|
+
return t2 ? "/" + t2 : t2;
|
|
1900
1791
|
}
|
|
1901
1792
|
};
|
|
1902
1793
|
|
|
1794
|
+
// source/verify_certificate_signature.ts
|
|
1795
|
+
var import_crypto4 = require("crypto");
|
|
1796
|
+
function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
1797
|
+
const block_info = readTag(certificateOrCrl, 0);
|
|
1798
|
+
const blocks = readStruct(certificateOrCrl, block_info);
|
|
1799
|
+
const bufferToBeSigned = certificateOrCrl.subarray(block_info.position, blocks[1].position - 2);
|
|
1800
|
+
const signatureAlgorithm = readAlgorithmIdentifier(certificateOrCrl, blocks[1]);
|
|
1801
|
+
const signatureValue = readSignatureValueBin(certificateOrCrl, blocks[2]);
|
|
1802
|
+
const p = split_der(parentCertificate)[0];
|
|
1803
|
+
const certPem = toPem(p, "CERTIFICATE");
|
|
1804
|
+
const verify = (0, import_crypto4.createVerify)(signatureAlgorithm.identifier);
|
|
1805
|
+
verify.update(bufferToBeSigned);
|
|
1806
|
+
verify.end();
|
|
1807
|
+
return verify.verify(certPem, signatureValue);
|
|
1808
|
+
}
|
|
1809
|
+
function verifyCertificateSignature(certificate, parentCertificate) {
|
|
1810
|
+
return verifyCertificateOrClrSignature(certificate, parentCertificate);
|
|
1811
|
+
}
|
|
1812
|
+
function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
|
|
1813
|
+
return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
|
|
1814
|
+
}
|
|
1815
|
+
async function verifyCertificateChain(certificateChain) {
|
|
1816
|
+
for (let index = 1; index < certificateChain.length; index++) {
|
|
1817
|
+
const cert = certificateChain[index - 1];
|
|
1818
|
+
const certParent = certificateChain[index];
|
|
1819
|
+
const certParentInfo = exploreCertificate(certParent);
|
|
1820
|
+
const keyUsage = certParentInfo.tbsCertificate.extensions.keyUsage;
|
|
1821
|
+
if (!keyUsage.keyCertSign) {
|
|
1822
|
+
return {
|
|
1823
|
+
status: "BadCertificateIssuerUseNotAllowed",
|
|
1824
|
+
reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing"
|
|
1825
|
+
};
|
|
1826
|
+
}
|
|
1827
|
+
const parentSignChild = verifyCertificateSignature(cert, certParent);
|
|
1828
|
+
if (!parentSignChild) {
|
|
1829
|
+
return {
|
|
1830
|
+
status: "BadCertificateInvalid",
|
|
1831
|
+
reason: "One of the certificate in the chain is not signing the previous certificate"
|
|
1832
|
+
};
|
|
1833
|
+
}
|
|
1834
|
+
const certInfo = exploreCertificate(cert);
|
|
1835
|
+
if (!certInfo.tbsCertificate.extensions) {
|
|
1836
|
+
return {
|
|
1837
|
+
status: "BadCertificateInvalid",
|
|
1838
|
+
reason: "Cannot find X409 Extension 3 in certificate"
|
|
1839
|
+
};
|
|
1840
|
+
}
|
|
1841
|
+
if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
|
|
1842
|
+
return {
|
|
1843
|
+
status: "BadCertificateInvalid",
|
|
1844
|
+
reason: "Cannot find X409 Extension 3 in certificate (parent)"
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1847
|
+
if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !== certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
|
|
1848
|
+
return {
|
|
1849
|
+
status: "BadCertificateInvalid",
|
|
1850
|
+
reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate"
|
|
1851
|
+
};
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
return {
|
|
1855
|
+
status: "Good",
|
|
1856
|
+
reason: `certificate chain is valid(length = ${certificateChain.length})`
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
// source/x509/_crypto.ts
|
|
1861
|
+
var x509 = __toESM(require("@peculiar/x509"));
|
|
1862
|
+
var import_webcrypto = require("@peculiar/webcrypto");
|
|
1863
|
+
var import_crypto5 = __toESM(require("crypto"));
|
|
1864
|
+
var x5092 = __toESM(require("@peculiar/x509"));
|
|
1865
|
+
var doDebug3 = false;
|
|
1866
|
+
var _crypto;
|
|
1867
|
+
var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
|
|
1868
|
+
if (typeof window === "undefined") {
|
|
1869
|
+
_crypto = import_crypto5.default;
|
|
1870
|
+
if (!_crypto?.subtle || ignoreCrypto) {
|
|
1871
|
+
_crypto = new import_webcrypto.Crypto();
|
|
1872
|
+
doDebug3 && console.warn("using @peculiar/webcrypto");
|
|
1873
|
+
} else {
|
|
1874
|
+
doDebug3 && console.warn("using nodejs crypto (native)");
|
|
1875
|
+
}
|
|
1876
|
+
x509.cryptoProvider.set(_crypto);
|
|
1877
|
+
} else {
|
|
1878
|
+
doDebug3 && console.warn("using browser crypto (native)");
|
|
1879
|
+
_crypto = crypto;
|
|
1880
|
+
x509.cryptoProvider.set(crypto);
|
|
1881
|
+
}
|
|
1882
|
+
function getCrypto() {
|
|
1883
|
+
return _crypto || crypto || require("crypto");
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
// source/x509/create_key_pair.ts
|
|
1887
|
+
async function generateKeyPair(modulusLength = 2048) {
|
|
1888
|
+
const crypto3 = getCrypto();
|
|
1889
|
+
const alg = {
|
|
1890
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
1891
|
+
hash: { name: "SHA-256" },
|
|
1892
|
+
publicExponent: new Uint8Array([1, 0, 1]),
|
|
1893
|
+
modulusLength
|
|
1894
|
+
};
|
|
1895
|
+
const keys = await crypto3.subtle.generateKey(alg, true, ["sign", "verify"]);
|
|
1896
|
+
return keys;
|
|
1897
|
+
}
|
|
1898
|
+
async function generatePrivateKey(modulusLength = 2048) {
|
|
1899
|
+
return (await generateKeyPair(modulusLength)).privateKey;
|
|
1900
|
+
}
|
|
1901
|
+
async function privateKeyToPEM(privateKey) {
|
|
1902
|
+
const crypto3 = getCrypto();
|
|
1903
|
+
const privDer = await crypto3.subtle.exportKey("pkcs8", privateKey);
|
|
1904
|
+
const privPem = x5092.PemConverter.encode(privDer, "PRIVATE KEY");
|
|
1905
|
+
return { privPem, privDer };
|
|
1906
|
+
}
|
|
1907
|
+
async function derToPrivateKey(privDer) {
|
|
1908
|
+
const crypto3 = getCrypto();
|
|
1909
|
+
return await crypto3.subtle.importKey(
|
|
1910
|
+
"pkcs8",
|
|
1911
|
+
privDer,
|
|
1912
|
+
{
|
|
1913
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
1914
|
+
hash: { name: "SHA-256" }
|
|
1915
|
+
},
|
|
1916
|
+
true,
|
|
1917
|
+
[
|
|
1918
|
+
"sign"
|
|
1919
|
+
// "encrypt",
|
|
1920
|
+
// "decrypt",
|
|
1921
|
+
// "verify",
|
|
1922
|
+
// "wrapKey",
|
|
1923
|
+
// "unwrapKey",
|
|
1924
|
+
// "deriveKey",
|
|
1925
|
+
// "deriveBits"
|
|
1926
|
+
]
|
|
1927
|
+
);
|
|
1928
|
+
}
|
|
1929
|
+
async function pemToPrivateKey(pem) {
|
|
1930
|
+
const privDer = x5092.PemConverter.decode(pem);
|
|
1931
|
+
return derToPrivateKey(privDer[0]);
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
// source/x509/coerce_private_key.ts
|
|
1935
|
+
var crypto2 = getCrypto();
|
|
1936
|
+
var doDebug4 = false;
|
|
1937
|
+
function coercePEMorDerToPrivateKey(privateKeyInDerOrPem) {
|
|
1938
|
+
if (typeof privateKeyInDerOrPem === "string") {
|
|
1939
|
+
const hidden = createPrivateKeyFromNodeJSCrypto(privateKeyInDerOrPem);
|
|
1940
|
+
return { hidden };
|
|
1941
|
+
}
|
|
1942
|
+
throw new Error("not implemented");
|
|
1943
|
+
}
|
|
1944
|
+
async function _coercePrivateKey(privateKey) {
|
|
1945
|
+
const KeyObject4 = crypto2.KeyObject;
|
|
1946
|
+
if (privateKey instanceof Buffer) {
|
|
1947
|
+
const privateKey1 = await derToPrivateKey(privateKey);
|
|
1948
|
+
return KeyObject4.from(privateKey1);
|
|
1949
|
+
} else if (typeof privateKey === "string") {
|
|
1950
|
+
try {
|
|
1951
|
+
const privateKey1 = await pemToPrivateKey(privateKey);
|
|
1952
|
+
return KeyObject4.from(privateKey1);
|
|
1953
|
+
} catch (err) {
|
|
1954
|
+
doDebug4 && console.log(privateKey);
|
|
1955
|
+
throw err;
|
|
1956
|
+
}
|
|
1957
|
+
} else if (privateKey instanceof KeyObject4) {
|
|
1958
|
+
return privateKey;
|
|
1959
|
+
}
|
|
1960
|
+
throw new Error("Invalid privateKey");
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1903
1963
|
// source/x509/_get_attributes.ts
|
|
1904
1964
|
var keyUsageApplication = x5092.KeyUsageFlags.keyEncipherment | x5092.KeyUsageFlags.nonRepudiation | x5092.KeyUsageFlags.dataEncipherment | x5092.KeyUsageFlags.keyCertSign | x5092.KeyUsageFlags.digitalSignature;
|
|
1905
1965
|
var keyUsageCA = x5092.KeyUsageFlags.keyCertSign | x5092.KeyUsageFlags.cRLSign;
|
|
@@ -5441,11 +5501,11 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
5441
5501
|
};
|
|
5442
5502
|
}
|
|
5443
5503
|
if (inputSchema.primitiveSchema && VALUE_HEX_VIEW in inputData.valueBlock) {
|
|
5444
|
-
const
|
|
5445
|
-
if (
|
|
5504
|
+
const asn12 = localFromBER(inputData.valueBlock.valueHexView);
|
|
5505
|
+
if (asn12.offset === -1) {
|
|
5446
5506
|
const _result = {
|
|
5447
5507
|
verified: false,
|
|
5448
|
-
result:
|
|
5508
|
+
result: asn12.result
|
|
5449
5509
|
};
|
|
5450
5510
|
if (inputSchema.name) {
|
|
5451
5511
|
inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
|
|
@@ -5456,7 +5516,7 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
5456
5516
|
}
|
|
5457
5517
|
return _result;
|
|
5458
5518
|
}
|
|
5459
|
-
return compareSchema(root,
|
|
5519
|
+
return compareSchema(root, asn12.result, inputSchema.primitiveSchema);
|
|
5460
5520
|
}
|
|
5461
5521
|
return {
|
|
5462
5522
|
verified: true,
|
|
@@ -5470,14 +5530,14 @@ function verifySchema(inputBuffer, inputSchema) {
|
|
|
5470
5530
|
result: { error: "Wrong ASN.1 schema type" }
|
|
5471
5531
|
};
|
|
5472
5532
|
}
|
|
5473
|
-
const
|
|
5474
|
-
if (
|
|
5533
|
+
const asn12 = localFromBER(BufferSourceConverter.toUint8Array(inputBuffer));
|
|
5534
|
+
if (asn12.offset === -1) {
|
|
5475
5535
|
return {
|
|
5476
5536
|
verified: false,
|
|
5477
|
-
result:
|
|
5537
|
+
result: asn12.result
|
|
5478
5538
|
};
|
|
5479
5539
|
}
|
|
5480
|
-
return compareSchema(
|
|
5540
|
+
return compareSchema(asn12.result, asn12.result, inputSchema);
|
|
5481
5541
|
}
|
|
5482
5542
|
|
|
5483
5543
|
// ../../node_modules/@peculiar/asn1-schema/build/es2015/enums.js
|
|
@@ -6165,39 +6225,8 @@ async function createSelfSignedCertificate({
|
|
|
6165
6225
|
return { cert: cert.toString("pem"), der: cert };
|
|
6166
6226
|
}
|
|
6167
6227
|
|
|
6168
|
-
// source/
|
|
6169
|
-
var
|
|
6170
|
-
var doDebug4 = false;
|
|
6171
|
-
function coercePEMorDerToPrivateKey(privateKeyInDerOrPem) {
|
|
6172
|
-
if (typeof privateKeyInDerOrPem === "string") {
|
|
6173
|
-
const hidden = createPrivateKeyFromNodeJSCrypto(privateKeyInDerOrPem);
|
|
6174
|
-
return { hidden };
|
|
6175
|
-
}
|
|
6176
|
-
throw new Error("not implemented");
|
|
6177
|
-
}
|
|
6178
|
-
async function _coercePrivateKey(privateKey) {
|
|
6179
|
-
const KeyObject4 = crypto2.KeyObject;
|
|
6180
|
-
if (privateKey instanceof Buffer) {
|
|
6181
|
-
const privateKey1 = await derToPrivateKey(privateKey);
|
|
6182
|
-
return KeyObject4.from(privateKey1);
|
|
6183
|
-
} else if (typeof privateKey === "string") {
|
|
6184
|
-
try {
|
|
6185
|
-
const privateKey1 = await pemToPrivateKey(privateKey);
|
|
6186
|
-
return KeyObject4.from(privateKey1);
|
|
6187
|
-
} catch (err) {
|
|
6188
|
-
doDebug4 && console.log(privateKey);
|
|
6189
|
-
throw err;
|
|
6190
|
-
}
|
|
6191
|
-
} else if (privateKey instanceof KeyObject4) {
|
|
6192
|
-
return privateKey;
|
|
6193
|
-
}
|
|
6194
|
-
throw new Error("Invalid privateKey");
|
|
6195
|
-
}
|
|
6196
|
-
|
|
6197
|
-
// source/make_private_key_from_pem.ts
|
|
6198
|
-
function makePrivateKeyFromPem(privateKeyInPem) {
|
|
6199
|
-
return { hidden: privateKeyInPem };
|
|
6200
|
-
}
|
|
6228
|
+
// source/index.ts
|
|
6229
|
+
var asn1 = { readTag, readStruct, readAlgorithmIdentifier, readSignatureValueBin };
|
|
6201
6230
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6202
6231
|
0 && (module.exports = {
|
|
6203
6232
|
CertificatePurpose,
|
|
@@ -6205,28 +6234,9 @@ function makePrivateKeyFromPem(privateKeyInPem) {
|
|
|
6205
6234
|
RSA_PKCS1_OAEP_PADDING,
|
|
6206
6235
|
RSA_PKCS1_PADDING,
|
|
6207
6236
|
Subject,
|
|
6208
|
-
TagType,
|
|
6209
6237
|
_coercePrivateKey,
|
|
6210
|
-
_findBlockAtIndex,
|
|
6211
|
-
_getBlock,
|
|
6212
|
-
_readAlgorithmIdentifier,
|
|
6213
|
-
_readBitString,
|
|
6214
|
-
_readBooleanValue,
|
|
6215
|
-
_readDirectoryName,
|
|
6216
|
-
_readECCAlgorithmIdentifier,
|
|
6217
6238
|
_readExtension,
|
|
6218
|
-
|
|
6219
|
-
_readIntegerValue,
|
|
6220
|
-
_readListOfInteger,
|
|
6221
|
-
_readLongIntegerValue,
|
|
6222
|
-
_readObjectIdentifier,
|
|
6223
|
-
_readOctetString,
|
|
6224
|
-
_readSignatureValue,
|
|
6225
|
-
_readSignatureValueBin,
|
|
6226
|
-
_readStruct,
|
|
6227
|
-
_readTime,
|
|
6228
|
-
_readValue,
|
|
6229
|
-
_readVersionValue,
|
|
6239
|
+
asn1,
|
|
6230
6240
|
certificateMatchesPrivateKey,
|
|
6231
6241
|
coerceCertificate,
|
|
6232
6242
|
coerceCertificatePem,
|
|
@@ -6235,7 +6245,6 @@ function makePrivateKeyFromPem(privateKeyInPem) {
|
|
|
6235
6245
|
coercePublicKeyPem,
|
|
6236
6246
|
coerceRsaPublicKeyPem,
|
|
6237
6247
|
combine_der,
|
|
6238
|
-
compactDirectoryName,
|
|
6239
6248
|
computeDerivedKeys,
|
|
6240
6249
|
computePaddingFooter,
|
|
6241
6250
|
convertPEMtoDER,
|
|
@@ -6245,6 +6254,7 @@ function makePrivateKeyFromPem(privateKeyInPem) {
|
|
|
6245
6254
|
decryptBufferWithDerivedKeys,
|
|
6246
6255
|
derToPrivateKey,
|
|
6247
6256
|
encryptBufferWithDerivedKeys,
|
|
6257
|
+
exploreAsn1,
|
|
6248
6258
|
exploreCertificate,
|
|
6249
6259
|
exploreCertificateInfo,
|
|
6250
6260
|
exploreCertificateRevocationList,
|
|
@@ -6252,7 +6262,6 @@ function makePrivateKeyFromPem(privateKeyInPem) {
|
|
|
6252
6262
|
explorePrivateKey,
|
|
6253
6263
|
extractPublicKeyFromCertificate,
|
|
6254
6264
|
extractPublicKeyFromCertificateSync,
|
|
6255
|
-
formatBuffer2DigitHexWithColum,
|
|
6256
6265
|
generateKeyPair,
|
|
6257
6266
|
generatePrivateKey,
|
|
6258
6267
|
hexDump,
|
|
@@ -6261,9 +6270,9 @@ function makePrivateKeyFromPem(privateKeyInPem) {
|
|
|
6261
6270
|
makeMessageChunkSignature,
|
|
6262
6271
|
makeMessageChunkSignatureWithDerivedKeys,
|
|
6263
6272
|
makePrivateKeyFromPem,
|
|
6273
|
+
makePrivateKeyThumbPrint,
|
|
6264
6274
|
makePseudoRandomBuffer,
|
|
6265
6275
|
makeSHA1Thumbprint,
|
|
6266
|
-
parseBitString,
|
|
6267
6276
|
pemToPrivateKey,
|
|
6268
6277
|
privateDecrypt,
|
|
6269
6278
|
privateDecrypt_long,
|
|
@@ -6275,7 +6284,6 @@ function makePrivateKeyFromPem(privateKeyInPem) {
|
|
|
6275
6284
|
publicKeyAndPrivateKeyMatches,
|
|
6276
6285
|
readCertificationRequestInfo,
|
|
6277
6286
|
readNameForCrl,
|
|
6278
|
-
readTag,
|
|
6279
6287
|
readTbsCertificate,
|
|
6280
6288
|
reduceLength,
|
|
6281
6289
|
removePadding,
|