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/index.js
CHANGED
|
@@ -35,28 +35,9 @@ __export(node_opcua_crypto_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(node_opcua_crypto_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(node_opcua_crypto_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(node_opcua_crypto_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
|
generatePrivateKeyFile: () => generatePrivateKeyFile,
|
|
@@ -97,7 +77,6 @@ __export(node_opcua_crypto_exports, {
|
|
|
97
77
|
makePrivateKeyThumbPrint: () => makePrivateKeyThumbPrint,
|
|
98
78
|
makePseudoRandomBuffer: () => makePseudoRandomBuffer,
|
|
99
79
|
makeSHA1Thumbprint: () => makeSHA1Thumbprint,
|
|
100
|
-
parseBitString: () => parseBitString,
|
|
101
80
|
pemToPrivateKey: () => pemToPrivateKey,
|
|
102
81
|
privateDecrypt: () => privateDecrypt,
|
|
103
82
|
privateDecrypt_long: () => privateDecrypt_long,
|
|
@@ -119,7 +98,6 @@ __export(node_opcua_crypto_exports, {
|
|
|
119
98
|
readPublicKey: () => readPublicKey,
|
|
120
99
|
readPublicKeyPEM: () => readPublicKeyPEM,
|
|
121
100
|
readPublicRsaKey: () => readPublicRsaKey,
|
|
122
|
-
readTag: () => readTag,
|
|
123
101
|
readTbsCertificate: () => readTbsCertificate,
|
|
124
102
|
reduceLength: () => reduceLength,
|
|
125
103
|
removePadding: () => removePadding,
|
|
@@ -141,42 +119,6 @@ __export(node_opcua_crypto_exports, {
|
|
|
141
119
|
});
|
|
142
120
|
module.exports = __toCommonJS(node_opcua_crypto_exports);
|
|
143
121
|
|
|
144
|
-
// source/common.ts
|
|
145
|
-
var import_crypto = __toESM(require("crypto"));
|
|
146
|
-
var KeyObjectOrig = import_crypto.default.KeyObject;
|
|
147
|
-
var { createPrivateKey: createPrivateKeyFromNodeJSCrypto } = import_crypto.default;
|
|
148
|
-
function isKeyObject(mayBeKeyObject) {
|
|
149
|
-
if (KeyObjectOrig) {
|
|
150
|
-
return mayBeKeyObject instanceof KeyObjectOrig;
|
|
151
|
-
}
|
|
152
|
-
return typeof mayBeKeyObject === "object" && typeof mayBeKeyObject.type === "string";
|
|
153
|
-
}
|
|
154
|
-
var CertificatePurpose = /* @__PURE__ */ ((CertificatePurpose2) => {
|
|
155
|
-
CertificatePurpose2[CertificatePurpose2["NotSpecified"] = 0] = "NotSpecified";
|
|
156
|
-
CertificatePurpose2[CertificatePurpose2["ForCertificateAuthority"] = 1] = "ForCertificateAuthority";
|
|
157
|
-
CertificatePurpose2[CertificatePurpose2["ForApplication"] = 2] = "ForApplication";
|
|
158
|
-
CertificatePurpose2[CertificatePurpose2["ForUserAuthentication"] = 3] = "ForUserAuthentication";
|
|
159
|
-
return CertificatePurpose2;
|
|
160
|
-
})(CertificatePurpose || {});
|
|
161
|
-
|
|
162
|
-
// source/derived_keys.ts
|
|
163
|
-
var import_assert5 = __toESM(require("assert"));
|
|
164
|
-
var import_crypto3 = require("crypto");
|
|
165
|
-
|
|
166
|
-
// source/buffer_utils.ts
|
|
167
|
-
var createFastUninitializedBuffer = Buffer.allocUnsafe ? Buffer.allocUnsafe : (size) => {
|
|
168
|
-
return new Buffer(size);
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
// source/crypto_utils.ts
|
|
172
|
-
var import_constants = __toESM(require("constants"));
|
|
173
|
-
var import_assert3 = __toESM(require("assert"));
|
|
174
|
-
var import_crypto2 = require("crypto");
|
|
175
|
-
var import_hexy = __toESM(require("hexy"));
|
|
176
|
-
|
|
177
|
-
// source/crypto_explore_certificate.ts
|
|
178
|
-
var import_assert2 = __toESM(require("assert"));
|
|
179
|
-
|
|
180
122
|
// source/asn1.ts
|
|
181
123
|
var import_assert = __toESM(require("assert"));
|
|
182
124
|
|
|
@@ -244,6 +186,7 @@ var oid_map = {
|
|
|
244
186
|
"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" },
|
|
245
187
|
"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" },
|
|
246
188
|
"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)" },
|
|
189
|
+
"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" },
|
|
247
190
|
"1.3.6.1.5.5.7.3.17": { d: "1.3.6.1.5.5.7.3.17", c: "Internet Key Exchange (IKE)" },
|
|
248
191
|
"1.3.6.1.5.5.7.3.1": { d: "serverAuth", c: "PKIX key purpose" },
|
|
249
192
|
"1.3.6.1.5.5.7.3.2": { d: "clientAuth", c: "PKIX key purpose" },
|
|
@@ -503,12 +446,15 @@ var TagType = /* @__PURE__ */ ((TagType3) => {
|
|
|
503
446
|
TagType3[TagType3["BMPString"] = 30] = "BMPString";
|
|
504
447
|
TagType3[TagType3["SEQUENCE"] = 48] = "SEQUENCE";
|
|
505
448
|
TagType3[TagType3["SET"] = 49] = "SET";
|
|
506
|
-
TagType3[TagType3["
|
|
449
|
+
TagType3[TagType3["CONTEXT_SPECIFIC0"] = 160] = "CONTEXT_SPECIFIC0";
|
|
450
|
+
TagType3[TagType3["CONTEXT_SPECIFIC1"] = 161] = "CONTEXT_SPECIFIC1";
|
|
451
|
+
TagType3[TagType3["CONTEXT_SPECIFIC2"] = 162] = "CONTEXT_SPECIFIC2";
|
|
452
|
+
TagType3[TagType3["CONTEXT_SPECIFIC3"] = 163] = "CONTEXT_SPECIFIC3";
|
|
453
|
+
TagType3[TagType3["A4"] = 164] = "A4";
|
|
507
454
|
return TagType3;
|
|
508
455
|
})(TagType || {});
|
|
509
456
|
function readTag(buf, pos) {
|
|
510
|
-
|
|
511
|
-
(0, import_assert.default)(Number.isFinite(pos) && pos >= 0);
|
|
457
|
+
const start = pos;
|
|
512
458
|
if (buf.length <= pos) {
|
|
513
459
|
throw new Error("Invalid position : buf.length=" + buf.length + " pos =" + pos);
|
|
514
460
|
}
|
|
@@ -524,9 +470,9 @@ function readTag(buf, pos) {
|
|
|
524
470
|
pos += 1;
|
|
525
471
|
}
|
|
526
472
|
}
|
|
527
|
-
return { tag, position: pos, length };
|
|
473
|
+
return { start, tag, position: pos, length };
|
|
528
474
|
}
|
|
529
|
-
function
|
|
475
|
+
function readStruct(buf, blockInfo) {
|
|
530
476
|
const length = blockInfo.length;
|
|
531
477
|
let cursor = blockInfo.position;
|
|
532
478
|
const end = blockInfo.position + length;
|
|
@@ -588,9 +534,9 @@ function _readIntegerAsByteString(buffer, block) {
|
|
|
588
534
|
}
|
|
589
535
|
function _readListOfInteger(buffer) {
|
|
590
536
|
const block = readTag(buffer, 0);
|
|
591
|
-
const inner_blocks =
|
|
592
|
-
return inner_blocks.map((
|
|
593
|
-
return _readIntegerAsByteString(buffer,
|
|
537
|
+
const inner_blocks = readStruct(buffer, block);
|
|
538
|
+
return inner_blocks.map((innerBlock) => {
|
|
539
|
+
return _readIntegerAsByteString(buffer, innerBlock);
|
|
594
540
|
});
|
|
595
541
|
}
|
|
596
542
|
function parseOID(buffer, start, end) {
|
|
@@ -622,24 +568,24 @@ function _readObjectIdentifier(buffer, block) {
|
|
|
622
568
|
name: oid_map[oid] ? oid_map[oid].d : oid
|
|
623
569
|
};
|
|
624
570
|
}
|
|
625
|
-
function
|
|
626
|
-
const inner_blocks =
|
|
571
|
+
function readAlgorithmIdentifier(buffer, block) {
|
|
572
|
+
const inner_blocks = readStruct(buffer, block);
|
|
627
573
|
return {
|
|
628
574
|
identifier: _readObjectIdentifier(buffer, inner_blocks[0]).name
|
|
629
575
|
};
|
|
630
576
|
}
|
|
631
577
|
function _readECCAlgorithmIdentifier(buffer, block) {
|
|
632
|
-
const inner_blocks =
|
|
578
|
+
const inner_blocks = readStruct(buffer, block);
|
|
633
579
|
return {
|
|
634
580
|
identifier: _readObjectIdentifier(buffer, inner_blocks[1]).name
|
|
635
581
|
// difference with RSA as algorithm is second element of nested block
|
|
636
582
|
};
|
|
637
583
|
}
|
|
638
|
-
function
|
|
584
|
+
function readSignatureValueBin(buffer, block) {
|
|
639
585
|
return _readBitString(buffer, block).data;
|
|
640
586
|
}
|
|
641
|
-
function
|
|
642
|
-
return
|
|
587
|
+
function readSignatureValue(buffer, block) {
|
|
588
|
+
return readSignatureValueBin(buffer, block).toString("hex");
|
|
643
589
|
}
|
|
644
590
|
function _readLongIntegerValue(buffer, block) {
|
|
645
591
|
(0, import_assert.default)(block.tag === 2 /* INTEGER */, "expecting a INTEGER tag");
|
|
@@ -720,18 +666,15 @@ function _readValue(buffer, block) {
|
|
|
720
666
|
throw new Error("Invalid tag 0x" + block.tag.toString(16));
|
|
721
667
|
}
|
|
722
668
|
}
|
|
723
|
-
function compactDirectoryName(d) {
|
|
724
|
-
return JSON.stringify(d);
|
|
725
|
-
}
|
|
726
669
|
function _readDirectoryName(buffer, block) {
|
|
727
|
-
const set_blocks =
|
|
670
|
+
const set_blocks = readStruct(buffer, block);
|
|
728
671
|
const names = {};
|
|
729
672
|
for (const set_block of set_blocks) {
|
|
730
673
|
(0, import_assert.default)(set_block.tag === 49);
|
|
731
|
-
const blocks =
|
|
674
|
+
const blocks = readStruct(buffer, set_block);
|
|
732
675
|
(0, import_assert.default)(blocks.length === 1);
|
|
733
676
|
(0, import_assert.default)(blocks[0].tag === 48);
|
|
734
|
-
const sequenceBlock =
|
|
677
|
+
const sequenceBlock = readStruct(buffer, blocks[0]);
|
|
735
678
|
(0, import_assert.default)(sequenceBlock.length === 2);
|
|
736
679
|
const type = _readObjectIdentifier(buffer, sequenceBlock[0]);
|
|
737
680
|
names[type.name] = _readValue(buffer, sequenceBlock[1]);
|
|
@@ -749,11 +692,23 @@ function _readTime(buffer, block) {
|
|
|
749
692
|
return _readValue(buffer, block);
|
|
750
693
|
}
|
|
751
694
|
|
|
695
|
+
// source/crypto_utils.ts
|
|
696
|
+
var import_constants = __toESM(require("constants"));
|
|
697
|
+
var import_assert3 = __toESM(require("assert"));
|
|
698
|
+
var import_crypto = require("crypto");
|
|
699
|
+
var import_hexy = __toESM(require("hexy"));
|
|
700
|
+
|
|
701
|
+
// source/buffer_utils.ts
|
|
702
|
+
var createFastUninitializedBuffer = Buffer.allocUnsafe ? Buffer.allocUnsafe : (size) => {
|
|
703
|
+
return new Buffer(size);
|
|
704
|
+
};
|
|
705
|
+
|
|
752
706
|
// source/crypto_explore_certificate.ts
|
|
707
|
+
var import_assert2 = __toESM(require("assert"));
|
|
753
708
|
var doDebug = false;
|
|
754
709
|
function _readAttributeTypeAndValue(buffer, block) {
|
|
755
|
-
let inner_blocks =
|
|
756
|
-
inner_blocks =
|
|
710
|
+
let inner_blocks = readStruct(buffer, block);
|
|
711
|
+
inner_blocks = readStruct(buffer, inner_blocks[0]);
|
|
757
712
|
const data = {
|
|
758
713
|
identifier: _readObjectIdentifier(buffer, inner_blocks[0]).name,
|
|
759
714
|
value: _readValue(buffer, inner_blocks[1])
|
|
@@ -765,7 +720,7 @@ function _readAttributeTypeAndValue(buffer, block) {
|
|
|
765
720
|
return result;
|
|
766
721
|
}
|
|
767
722
|
function _readRelativeDistinguishedName(buffer, block) {
|
|
768
|
-
const inner_blocks =
|
|
723
|
+
const inner_blocks = readStruct(buffer, block);
|
|
769
724
|
const data = inner_blocks.map((block2) => _readAttributeTypeAndValue(buffer, block2));
|
|
770
725
|
const result = {};
|
|
771
726
|
for (const e of data) {
|
|
@@ -777,7 +732,7 @@ function _readName(buffer, block) {
|
|
|
777
732
|
return _readRelativeDistinguishedName(buffer, block);
|
|
778
733
|
}
|
|
779
734
|
function _readValidity(buffer, block) {
|
|
780
|
-
const inner_blocks =
|
|
735
|
+
const inner_blocks = readStruct(buffer, block);
|
|
781
736
|
return {
|
|
782
737
|
notBefore: _readTime(buffer, inner_blocks[0]),
|
|
783
738
|
notAfter: _readTime(buffer, inner_blocks[1])
|
|
@@ -785,27 +740,27 @@ function _readValidity(buffer, block) {
|
|
|
785
740
|
}
|
|
786
741
|
function _readAuthorityKeyIdentifier(buffer) {
|
|
787
742
|
const block_info = readTag(buffer, 0);
|
|
788
|
-
const blocks =
|
|
743
|
+
const blocks = readStruct(buffer, block_info);
|
|
789
744
|
const keyIdentifier_block = _findBlockAtIndex(blocks, 0);
|
|
790
745
|
const authorityCertIssuer_block = _findBlockAtIndex(blocks, 1);
|
|
791
746
|
const authorityCertSerialNumber_block = _findBlockAtIndex(blocks, 2);
|
|
792
747
|
function _readAuthorityCertIssuer(block) {
|
|
793
|
-
const inner_blocks =
|
|
748
|
+
const inner_blocks = readStruct(buffer, block);
|
|
794
749
|
const directoryName_block = _findBlockAtIndex(inner_blocks, 4);
|
|
795
750
|
if (directoryName_block) {
|
|
796
|
-
const a =
|
|
751
|
+
const a = readStruct(buffer, directoryName_block);
|
|
797
752
|
return _readDirectoryName(buffer, a[0]);
|
|
798
753
|
} else {
|
|
799
754
|
throw new Error("Invalid _readAuthorityCertIssuer");
|
|
800
755
|
}
|
|
801
756
|
}
|
|
802
757
|
function _readAuthorityCertIssuerFingerPrint(block) {
|
|
803
|
-
const inner_blocks =
|
|
758
|
+
const inner_blocks = readStruct(buffer, block);
|
|
804
759
|
const directoryName_block = _findBlockAtIndex(inner_blocks, 4);
|
|
805
760
|
if (!directoryName_block) {
|
|
806
761
|
return "";
|
|
807
762
|
}
|
|
808
|
-
const a =
|
|
763
|
+
const a = readStruct(buffer, directoryName_block);
|
|
809
764
|
if (a.length < 1) {
|
|
810
765
|
return "";
|
|
811
766
|
}
|
|
@@ -824,7 +779,7 @@ function _readAuthorityKeyIdentifier(buffer) {
|
|
|
824
779
|
}
|
|
825
780
|
function readBasicConstraint2_5_29_19(buffer, block) {
|
|
826
781
|
const block_info = readTag(buffer, 0);
|
|
827
|
-
const inner_blocks =
|
|
782
|
+
const inner_blocks = readStruct(buffer, block_info).slice(0, 2);
|
|
828
783
|
let cA = false;
|
|
829
784
|
let pathLengthConstraint = 0;
|
|
830
785
|
let breakControl = 0;
|
|
@@ -853,9 +808,10 @@ function _readGeneralNames(buffer, block) {
|
|
|
853
808
|
5: { name: "ediPartyName", type: "EDIPartyName" },
|
|
854
809
|
6: { name: "uniformResourceIdentifier", type: "IA5String" },
|
|
855
810
|
7: { name: "iPAddress", type: "OCTET_STRING" },
|
|
856
|
-
8: { name: "registeredID", type: "OBJECT_IDENTIFIER" }
|
|
811
|
+
8: { name: "registeredID", type: "OBJECT_IDENTIFIER" },
|
|
812
|
+
32: { name: "otherName", type: "AnotherName" }
|
|
857
813
|
};
|
|
858
|
-
const blocks =
|
|
814
|
+
const blocks = readStruct(buffer, block);
|
|
859
815
|
function _readFromType(buffer2, block2, type) {
|
|
860
816
|
switch (type) {
|
|
861
817
|
case "IA5String":
|
|
@@ -867,13 +823,28 @@ function _readGeneralNames(buffer, block) {
|
|
|
867
823
|
const n = {};
|
|
868
824
|
for (const block2 of blocks) {
|
|
869
825
|
(0, import_assert2.default)((block2.tag & 128) === 128);
|
|
870
|
-
const
|
|
871
|
-
const type = _data[
|
|
826
|
+
const t2 = block2.tag & 127;
|
|
827
|
+
const type = _data[t2];
|
|
872
828
|
if (!type) {
|
|
873
|
-
|
|
829
|
+
console.log("_readGeneralNames: INVALID TYPE => " + t2 + " 0x" + t2.toString(16));
|
|
830
|
+
continue;
|
|
831
|
+
}
|
|
832
|
+
if (t2 == 32) {
|
|
833
|
+
n[type.name] = n[type.name] || [];
|
|
834
|
+
const blocks2 = readStruct(buffer, block2);
|
|
835
|
+
const name = _readObjectIdentifier(buffer, blocks2[0]).name;
|
|
836
|
+
const buf = _getBlock(buffer, blocks2[1]);
|
|
837
|
+
const b = readTag(buf, 0);
|
|
838
|
+
const nn = _readValue(buf, b);
|
|
839
|
+
const data = {
|
|
840
|
+
identifier: name,
|
|
841
|
+
value: nn
|
|
842
|
+
};
|
|
843
|
+
n[type.name].push(data.value);
|
|
844
|
+
} else {
|
|
845
|
+
n[type.name] = n[type.name] || [];
|
|
846
|
+
n[type.name].push(_readFromType(buffer, block2, type.type));
|
|
874
847
|
}
|
|
875
|
-
n[type.name] = n[type.name] || [];
|
|
876
|
-
n[type.name].push(_readFromType(buffer, block2, type.type));
|
|
877
848
|
}
|
|
878
849
|
return n;
|
|
879
850
|
}
|
|
@@ -913,7 +884,7 @@ function readKeyUsage(oid, buffer) {
|
|
|
913
884
|
function readExtKeyUsage(oid, buffer) {
|
|
914
885
|
(0, import_assert2.default)(oid === "2.5.29.37");
|
|
915
886
|
const block_info = readTag(buffer, 0);
|
|
916
|
-
const inner_blocks =
|
|
887
|
+
const inner_blocks = readStruct(buffer, block_info);
|
|
917
888
|
const extKeyUsage = {
|
|
918
889
|
serverAuth: false,
|
|
919
890
|
clientAuth: false,
|
|
@@ -933,13 +904,13 @@ function readExtKeyUsage(oid, buffer) {
|
|
|
933
904
|
}
|
|
934
905
|
function _readSubjectPublicKey(buffer) {
|
|
935
906
|
const block_info = readTag(buffer, 0);
|
|
936
|
-
const blocks =
|
|
907
|
+
const blocks = readStruct(buffer, block_info);
|
|
937
908
|
return {
|
|
938
909
|
modulus: buffer.subarray(blocks[0].position + 1, blocks[0].position + blocks[0].length)
|
|
939
910
|
};
|
|
940
911
|
}
|
|
941
912
|
function _readExtension(buffer, block) {
|
|
942
|
-
const inner_blocks =
|
|
913
|
+
const inner_blocks = readStruct(buffer, block);
|
|
943
914
|
if (inner_blocks.length === 3) {
|
|
944
915
|
(0, import_assert2.default)(inner_blocks[1].tag === 1 /* BOOLEAN */);
|
|
945
916
|
inner_blocks[1] = inner_blocks[2];
|
|
@@ -979,8 +950,8 @@ function _readExtension(buffer, block) {
|
|
|
979
950
|
}
|
|
980
951
|
function _readExtensions(buffer, block) {
|
|
981
952
|
(0, import_assert2.default)(block.tag === 163);
|
|
982
|
-
let inner_blocks =
|
|
983
|
-
inner_blocks =
|
|
953
|
+
let inner_blocks = readStruct(buffer, block);
|
|
954
|
+
inner_blocks = readStruct(buffer, inner_blocks[0]);
|
|
984
955
|
const extensions = inner_blocks.map((block2) => _readExtension(buffer, block2));
|
|
985
956
|
const result = {};
|
|
986
957
|
for (const e of extensions) {
|
|
@@ -989,8 +960,8 @@ function _readExtensions(buffer, block) {
|
|
|
989
960
|
return result;
|
|
990
961
|
}
|
|
991
962
|
function _readSubjectPublicKeyInfo(buffer, block) {
|
|
992
|
-
const inner_blocks =
|
|
993
|
-
const algorithm =
|
|
963
|
+
const inner_blocks = readStruct(buffer, block);
|
|
964
|
+
const algorithm = readAlgorithmIdentifier(buffer, inner_blocks[0]);
|
|
994
965
|
const subjectPublicKey = _readBitString(buffer, inner_blocks[1]);
|
|
995
966
|
const data = subjectPublicKey.data;
|
|
996
967
|
const values = _readListOfInteger(data);
|
|
@@ -1003,7 +974,7 @@ function _readSubjectPublicKeyInfo(buffer, block) {
|
|
|
1003
974
|
};
|
|
1004
975
|
}
|
|
1005
976
|
function _readSubjectECCPublicKeyInfo(buffer, block) {
|
|
1006
|
-
const inner_blocks =
|
|
977
|
+
const inner_blocks = readStruct(buffer, block);
|
|
1007
978
|
const algorithm = _readECCAlgorithmIdentifier(buffer, inner_blocks[0]);
|
|
1008
979
|
const subjectPublicKey = _readBitString(buffer, inner_blocks[1]);
|
|
1009
980
|
const data = subjectPublicKey.data;
|
|
@@ -1016,13 +987,13 @@ function _readSubjectECCPublicKeyInfo(buffer, block) {
|
|
|
1016
987
|
};
|
|
1017
988
|
}
|
|
1018
989
|
function readTbsCertificate(buffer, block) {
|
|
1019
|
-
const blocks =
|
|
990
|
+
const blocks = readStruct(buffer, block);
|
|
1020
991
|
let version, serialNumber, signature, issuer, validity, subject, subjectFingerPrint, extensions;
|
|
1021
992
|
let subjectPublicKeyInfo;
|
|
1022
993
|
if (blocks.length === 6) {
|
|
1023
994
|
version = 1;
|
|
1024
995
|
serialNumber = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, blocks[0]));
|
|
1025
|
-
signature =
|
|
996
|
+
signature = readAlgorithmIdentifier(buffer, blocks[1]);
|
|
1026
997
|
issuer = _readName(buffer, blocks[2]);
|
|
1027
998
|
validity = _readValidity(buffer, blocks[3]);
|
|
1028
999
|
subject = _readName(buffer, blocks[4]);
|
|
@@ -1036,13 +1007,13 @@ function readTbsCertificate(buffer, block) {
|
|
|
1036
1007
|
}
|
|
1037
1008
|
version = _readVersionValue(buffer, version_block) + 1;
|
|
1038
1009
|
serialNumber = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, blocks[1]));
|
|
1039
|
-
signature =
|
|
1010
|
+
signature = readAlgorithmIdentifier(buffer, blocks[2]);
|
|
1040
1011
|
issuer = _readName(buffer, blocks[3]);
|
|
1041
1012
|
validity = _readValidity(buffer, blocks[4]);
|
|
1042
1013
|
subject = _readName(buffer, blocks[5]);
|
|
1043
1014
|
subjectFingerPrint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[5])));
|
|
1044
|
-
const inner_block =
|
|
1045
|
-
const what_type =
|
|
1015
|
+
const inner_block = readStruct(buffer, blocks[6]);
|
|
1016
|
+
const what_type = readAlgorithmIdentifier(buffer, inner_block[0]).identifier;
|
|
1046
1017
|
switch (what_type) {
|
|
1047
1018
|
case "rsaEncryption": {
|
|
1048
1019
|
subjectPublicKeyInfo = _readSubjectPublicKeyInfo(buffer, blocks[6]);
|
|
@@ -1078,11 +1049,11 @@ function exploreCertificate(certificate) {
|
|
|
1078
1049
|
(0, import_assert2.default)(certificate instanceof Buffer);
|
|
1079
1050
|
if (!certificate._exploreCertificate_cache) {
|
|
1080
1051
|
const block_info = readTag(certificate, 0);
|
|
1081
|
-
const blocks =
|
|
1052
|
+
const blocks = readStruct(certificate, block_info);
|
|
1082
1053
|
certificate._exploreCertificate_cache = {
|
|
1083
1054
|
tbsCertificate: readTbsCertificate(certificate, blocks[0]),
|
|
1084
|
-
signatureAlgorithm:
|
|
1085
|
-
signatureValue:
|
|
1055
|
+
signatureAlgorithm: readAlgorithmIdentifier(certificate, blocks[1]),
|
|
1056
|
+
signatureValue: readSignatureValue(certificate, blocks[2])
|
|
1086
1057
|
};
|
|
1087
1058
|
}
|
|
1088
1059
|
return certificate._exploreCertificate_cache;
|
|
@@ -1173,19 +1144,19 @@ function hexDump(buffer, width) {
|
|
|
1173
1144
|
}
|
|
1174
1145
|
}
|
|
1175
1146
|
function makeMessageChunkSignature(chunk, options) {
|
|
1176
|
-
const signer = (0,
|
|
1147
|
+
const signer = (0, import_crypto.createSign)(options.algorithm);
|
|
1177
1148
|
signer.update(chunk);
|
|
1178
1149
|
const signature = signer.sign(options.privateKey.hidden);
|
|
1179
1150
|
(0, import_assert3.default)(!options.signatureLength || signature.length === options.signatureLength);
|
|
1180
1151
|
return signature;
|
|
1181
1152
|
}
|
|
1182
1153
|
function verifyMessageChunkSignature(blockToVerify, signature, options) {
|
|
1183
|
-
const verify = (0,
|
|
1154
|
+
const verify = (0, import_crypto.createVerify)(options.algorithm);
|
|
1184
1155
|
verify.update(blockToVerify);
|
|
1185
1156
|
return verify.verify(options.publicKey, signature);
|
|
1186
1157
|
}
|
|
1187
1158
|
function makeSHA1Thumbprint(buffer) {
|
|
1188
|
-
return (0,
|
|
1159
|
+
return (0, import_crypto.createHash)("sha1").update(buffer).digest();
|
|
1189
1160
|
}
|
|
1190
1161
|
var RSA_PKCS1_OAEP_PADDING = import_constants.default.RSA_PKCS1_OAEP_PADDING;
|
|
1191
1162
|
var RSA_PKCS1_PADDING = import_constants.default.RSA_PKCS1_PADDING;
|
|
@@ -1200,7 +1171,7 @@ function publicEncrypt_native(buffer, publicKey, algorithm) {
|
|
|
1200
1171
|
if (algorithm === void 0) {
|
|
1201
1172
|
algorithm = 4 /* RSA_PKCS1_OAEP_PADDING */;
|
|
1202
1173
|
}
|
|
1203
|
-
return (0,
|
|
1174
|
+
return (0, import_crypto.publicEncrypt)(
|
|
1204
1175
|
{
|
|
1205
1176
|
key: publicKey,
|
|
1206
1177
|
padding: algorithm
|
|
@@ -1213,7 +1184,7 @@ function privateDecrypt_native(buffer, privateKey, algorithm) {
|
|
|
1213
1184
|
algorithm = 4 /* RSA_PKCS1_OAEP_PADDING */;
|
|
1214
1185
|
}
|
|
1215
1186
|
try {
|
|
1216
|
-
return (0,
|
|
1187
|
+
return (0, import_crypto.privateDecrypt)(
|
|
1217
1188
|
{
|
|
1218
1189
|
key: privateKey.hidden,
|
|
1219
1190
|
padding: algorithm
|
|
@@ -1295,13 +1266,192 @@ function extractPublicKeyFromCertificate(certificate, callback) {
|
|
|
1295
1266
|
});
|
|
1296
1267
|
}
|
|
1297
1268
|
|
|
1298
|
-
// source/
|
|
1269
|
+
// source/explore_private_key.ts
|
|
1270
|
+
function f(buffer, b) {
|
|
1271
|
+
return buffer.subarray(b.position + 1, b.position + b.length);
|
|
1272
|
+
}
|
|
1273
|
+
var doDebug2 = !!process.env.DEBUG;
|
|
1274
|
+
function explorePrivateKey(privateKey2) {
|
|
1275
|
+
const privateKey1 = privateKey2.hidden;
|
|
1276
|
+
const privateKey = typeof privateKey1 === "string" ? convertPEMtoDER(privateKey1) : privateKey1.export({ format: "der", type: "pkcs1" });
|
|
1277
|
+
const block_info = readTag(privateKey, 0);
|
|
1278
|
+
const blocks = readStruct(privateKey, block_info);
|
|
1279
|
+
if (blocks.length === 9) {
|
|
1280
|
+
const version2 = f(privateKey, blocks[0]);
|
|
1281
|
+
const modulus2 = f(privateKey, blocks[1]);
|
|
1282
|
+
const publicExponent2 = f(privateKey, blocks[2]);
|
|
1283
|
+
const privateExponent2 = f(privateKey, blocks[3]);
|
|
1284
|
+
const prime12 = f(privateKey, blocks[4]);
|
|
1285
|
+
const prime22 = f(privateKey, blocks[5]);
|
|
1286
|
+
const exponent12 = f(privateKey, blocks[6]);
|
|
1287
|
+
const exponent22 = f(privateKey, blocks[7]);
|
|
1288
|
+
return {
|
|
1289
|
+
version: version2,
|
|
1290
|
+
modulus: modulus2,
|
|
1291
|
+
publicExponent: publicExponent2,
|
|
1292
|
+
privateExponent: privateExponent2,
|
|
1293
|
+
prime1: prime12,
|
|
1294
|
+
prime2: prime22,
|
|
1295
|
+
exponent1: exponent12,
|
|
1296
|
+
exponent2: exponent22
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
if (doDebug2) {
|
|
1300
|
+
console.log("-------------------- private key:");
|
|
1301
|
+
console.log(block_info);
|
|
1302
|
+
console.log(
|
|
1303
|
+
blocks.map((b2) => ({
|
|
1304
|
+
tag: TagType[b2.tag] + " 0x" + b2.tag.toString(16),
|
|
1305
|
+
l: b2.length,
|
|
1306
|
+
p: b2.position,
|
|
1307
|
+
buff: privateKey.subarray(b2.position, b2.position + b2.length).toString("hex")
|
|
1308
|
+
}))
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1311
|
+
const b = blocks[2];
|
|
1312
|
+
const bb = privateKey.subarray(b.position, b.position + b.length);
|
|
1313
|
+
const block_info1 = readTag(bb, 0);
|
|
1314
|
+
const blocks1 = readStruct(bb, block_info1);
|
|
1315
|
+
if (doDebug2) {
|
|
1316
|
+
console.log(
|
|
1317
|
+
blocks1.map((b2) => ({
|
|
1318
|
+
tag: TagType[b2.tag] + " 0x" + b2.tag.toString(16),
|
|
1319
|
+
l: b2.length,
|
|
1320
|
+
p: b2.position,
|
|
1321
|
+
buff: bb.subarray(b2.position, b2.position + b2.length).toString("hex")
|
|
1322
|
+
}))
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
const version = f(bb, blocks1[0]);
|
|
1326
|
+
const modulus = f(bb, blocks1[1]);
|
|
1327
|
+
const publicExponent = f(bb, blocks1[2]);
|
|
1328
|
+
const privateExponent = f(bb, blocks1[3]);
|
|
1329
|
+
const prime1 = f(bb, blocks1[4]);
|
|
1330
|
+
const prime2 = f(bb, blocks1[5]);
|
|
1331
|
+
const exponent1 = f(bb, blocks1[6]);
|
|
1332
|
+
const exponent2 = f(bb, blocks1[7]);
|
|
1333
|
+
return {
|
|
1334
|
+
version,
|
|
1335
|
+
modulus,
|
|
1336
|
+
publicExponent,
|
|
1337
|
+
privateExponent,
|
|
1338
|
+
prime1,
|
|
1339
|
+
prime2,
|
|
1340
|
+
exponent1,
|
|
1341
|
+
exponent2
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// source/public_private_match.ts
|
|
1346
|
+
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
1347
|
+
const i = exploreCertificate(certificate);
|
|
1348
|
+
const j = explorePrivateKey(privateKey);
|
|
1349
|
+
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
1350
|
+
const modulus2 = j.modulus;
|
|
1351
|
+
if (modulus1.length != modulus2.length) {
|
|
1352
|
+
return false;
|
|
1353
|
+
}
|
|
1354
|
+
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
1355
|
+
}
|
|
1356
|
+
function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
1357
|
+
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
1358
|
+
const encryptedBuffer = publicEncrypt_long(initialBuffer, certificate, blockSize);
|
|
1359
|
+
const decryptedBuffer = privateDecrypt_long(encryptedBuffer, privateKey, blockSize);
|
|
1360
|
+
const finalString = decryptedBuffer.toString("utf-8");
|
|
1361
|
+
return initialBuffer.toString("utf-8") === finalString;
|
|
1362
|
+
}
|
|
1363
|
+
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
1364
|
+
const e = explorePrivateKey(privateKey);
|
|
1365
|
+
const blockSize = e.modulus.length;
|
|
1366
|
+
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
1367
|
+
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// source/common.ts
|
|
1371
|
+
var import_crypto2 = __toESM(require("crypto"));
|
|
1372
|
+
var KeyObjectOrig = import_crypto2.default.KeyObject;
|
|
1373
|
+
var { createPrivateKey: createPrivateKeyFromNodeJSCrypto } = import_crypto2.default;
|
|
1374
|
+
function isKeyObject(mayBeKeyObject) {
|
|
1375
|
+
if (KeyObjectOrig) {
|
|
1376
|
+
return mayBeKeyObject instanceof KeyObjectOrig;
|
|
1377
|
+
}
|
|
1378
|
+
return typeof mayBeKeyObject === "object" && typeof mayBeKeyObject.type === "string";
|
|
1379
|
+
}
|
|
1380
|
+
var CertificatePurpose = /* @__PURE__ */ ((CertificatePurpose2) => {
|
|
1381
|
+
CertificatePurpose2[CertificatePurpose2["NotSpecified"] = 0] = "NotSpecified";
|
|
1382
|
+
CertificatePurpose2[CertificatePurpose2["ForCertificateAuthority"] = 1] = "ForCertificateAuthority";
|
|
1383
|
+
CertificatePurpose2[CertificatePurpose2["ForApplication"] = 2] = "ForApplication";
|
|
1384
|
+
CertificatePurpose2[CertificatePurpose2["ForUserAuthentication"] = 3] = "ForUserAuthentication";
|
|
1385
|
+
return CertificatePurpose2;
|
|
1386
|
+
})(CertificatePurpose || {});
|
|
1387
|
+
|
|
1388
|
+
// source/crypto_utils2.ts
|
|
1299
1389
|
var import_assert4 = __toESM(require("assert"));
|
|
1390
|
+
var import_jsrsasign2 = __toESM(require("jsrsasign"));
|
|
1391
|
+
function rsaLengthPrivateKey(key) {
|
|
1392
|
+
const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
|
|
1393
|
+
const a = import_jsrsasign2.default.KEYUTIL.getKey(keyPem);
|
|
1394
|
+
return a.n.toString(16).length / 2;
|
|
1395
|
+
}
|
|
1396
|
+
function toPem2(raw_key, pem) {
|
|
1397
|
+
if (raw_key.hidden) {
|
|
1398
|
+
return toPem2(raw_key.hidden, pem);
|
|
1399
|
+
}
|
|
1400
|
+
(0, import_assert4.default)(raw_key, "expecting a key");
|
|
1401
|
+
(0, import_assert4.default)(typeof pem === "string");
|
|
1402
|
+
if (isKeyObject(raw_key)) {
|
|
1403
|
+
const _raw_key = raw_key;
|
|
1404
|
+
if (pem === "RSA PRIVATE KEY") {
|
|
1405
|
+
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs1" }).toString());
|
|
1406
|
+
} else if (pem === "PRIVATE KEY") {
|
|
1407
|
+
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs8" }).toString());
|
|
1408
|
+
} else {
|
|
1409
|
+
throw new Error("Unsupported case!");
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
return toPem(raw_key, pem);
|
|
1413
|
+
}
|
|
1414
|
+
function coercePrivateKeyPem(privateKey) {
|
|
1415
|
+
return toPem2(privateKey, "PRIVATE KEY");
|
|
1416
|
+
}
|
|
1417
|
+
function coercePublicKeyPem(publicKey) {
|
|
1418
|
+
if (isKeyObject(publicKey)) {
|
|
1419
|
+
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
1420
|
+
}
|
|
1421
|
+
(0, import_assert4.default)(typeof publicKey === "string");
|
|
1422
|
+
return publicKey;
|
|
1423
|
+
}
|
|
1424
|
+
function coerceRsaPublicKeyPem(publicKey) {
|
|
1425
|
+
if (isKeyObject(publicKey)) {
|
|
1426
|
+
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
1427
|
+
}
|
|
1428
|
+
(0, import_assert4.default)(typeof publicKey === "string");
|
|
1429
|
+
return publicKey;
|
|
1430
|
+
}
|
|
1431
|
+
function rsaLengthPublicKey(key) {
|
|
1432
|
+
key = coercePublicKeyPem(key);
|
|
1433
|
+
(0, import_assert4.default)(typeof key === "string");
|
|
1434
|
+
const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
|
|
1435
|
+
return a.n.toString(16).length / 2;
|
|
1436
|
+
}
|
|
1437
|
+
function rsaLengthRsaPublicKey(key) {
|
|
1438
|
+
key = coerceRsaPublicKeyPem(key);
|
|
1439
|
+
(0, import_assert4.default)(typeof key === "string");
|
|
1440
|
+
const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
|
|
1441
|
+
return a.n.toString(16).length / 2;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
// source/derived_keys.ts
|
|
1445
|
+
var import_assert6 = __toESM(require("assert"));
|
|
1446
|
+
var import_crypto3 = require("crypto");
|
|
1447
|
+
|
|
1448
|
+
// source/explore_certificate.ts
|
|
1449
|
+
var import_assert5 = __toESM(require("assert"));
|
|
1300
1450
|
function coerceCertificate(certificate) {
|
|
1301
1451
|
if (typeof certificate === "string") {
|
|
1302
1452
|
certificate = convertPEMtoDER(certificate);
|
|
1303
1453
|
}
|
|
1304
|
-
(0,
|
|
1454
|
+
(0, import_assert5.default)(certificate instanceof Buffer);
|
|
1305
1455
|
return certificate;
|
|
1306
1456
|
}
|
|
1307
1457
|
function exploreCertificateInfo(certificate) {
|
|
@@ -1328,8 +1478,8 @@ function plus(buf1, buf2) {
|
|
|
1328
1478
|
return Buffer.concat([buf1, buf2]);
|
|
1329
1479
|
}
|
|
1330
1480
|
function makePseudoRandomBuffer(secret, seed, minLength, sha1or256) {
|
|
1331
|
-
(0,
|
|
1332
|
-
(0,
|
|
1481
|
+
(0, import_assert6.default)(seed instanceof Buffer);
|
|
1482
|
+
(0, import_assert6.default)(sha1or256 === "SHA1" || sha1or256 === "SHA256");
|
|
1333
1483
|
const a = [];
|
|
1334
1484
|
a[0] = seed;
|
|
1335
1485
|
let index = 1;
|
|
@@ -1342,12 +1492,12 @@ function makePseudoRandomBuffer(secret, seed, minLength, sha1or256) {
|
|
|
1342
1492
|
return p_hash.subarray(0, minLength);
|
|
1343
1493
|
}
|
|
1344
1494
|
function computeDerivedKeys(secret, seed, options) {
|
|
1345
|
-
(0,
|
|
1346
|
-
(0,
|
|
1347
|
-
(0,
|
|
1348
|
-
(0,
|
|
1495
|
+
(0, import_assert6.default)(Number.isFinite(options.signatureLength));
|
|
1496
|
+
(0, import_assert6.default)(Number.isFinite(options.encryptingKeyLength));
|
|
1497
|
+
(0, import_assert6.default)(Number.isFinite(options.encryptingBlockSize));
|
|
1498
|
+
(0, import_assert6.default)(typeof options.algorithm === "string");
|
|
1349
1499
|
options.sha1or256 = options.sha1or256 || "SHA1";
|
|
1350
|
-
(0,
|
|
1500
|
+
(0, import_assert6.default)(typeof options.sha1or256 === "string");
|
|
1351
1501
|
const offset1 = options.signingKeyLength;
|
|
1352
1502
|
const offset2 = offset1 + options.encryptingKeyLength;
|
|
1353
1503
|
const minLength = offset2 + options.encryptingBlockSize;
|
|
@@ -1372,7 +1522,7 @@ function removePadding(buffer) {
|
|
|
1372
1522
|
return reduceLength(buffer, nbPaddingBytes);
|
|
1373
1523
|
}
|
|
1374
1524
|
function verifyChunkSignature(chunk, options) {
|
|
1375
|
-
(0,
|
|
1525
|
+
(0, import_assert6.default)(chunk instanceof Buffer);
|
|
1376
1526
|
let signatureLength = options.signatureLength || 0;
|
|
1377
1527
|
if (signatureLength === 0) {
|
|
1378
1528
|
const cert = exploreCertificateInfo(options.publicKey);
|
|
@@ -1383,16 +1533,16 @@ function verifyChunkSignature(chunk, options) {
|
|
|
1383
1533
|
return verifyMessageChunkSignature(block_to_verify, signature, options);
|
|
1384
1534
|
}
|
|
1385
1535
|
function computePaddingFooter(buffer, derivedKeys) {
|
|
1386
|
-
(0,
|
|
1536
|
+
(0, import_assert6.default)(Object.prototype.hasOwnProperty.call(derivedKeys, "encryptingBlockSize"));
|
|
1387
1537
|
const paddingSize = derivedKeys.encryptingBlockSize - (buffer.length + 1) % derivedKeys.encryptingBlockSize;
|
|
1388
1538
|
const padding = createFastUninitializedBuffer(paddingSize + 1);
|
|
1389
1539
|
padding.fill(paddingSize);
|
|
1390
1540
|
return padding;
|
|
1391
1541
|
}
|
|
1392
1542
|
function derivedKeys_algorithm(derivedKeys) {
|
|
1393
|
-
(0,
|
|
1543
|
+
(0, import_assert6.default)(Object.prototype.hasOwnProperty.call(derivedKeys, "algorithm"));
|
|
1394
1544
|
const algorithm = derivedKeys.algorithm || "aes-128-cbc";
|
|
1395
|
-
(0,
|
|
1545
|
+
(0, import_assert6.default)(algorithm === "aes-128-cbc" || algorithm === "aes-256-cbc");
|
|
1396
1546
|
return algorithm;
|
|
1397
1547
|
}
|
|
1398
1548
|
function encryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
@@ -1418,12 +1568,12 @@ function decryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
|
1418
1568
|
return Buffer.concat(decrypted_chunks);
|
|
1419
1569
|
}
|
|
1420
1570
|
function makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys) {
|
|
1421
|
-
(0,
|
|
1422
|
-
(0,
|
|
1423
|
-
(0,
|
|
1424
|
-
(0,
|
|
1571
|
+
(0, import_assert6.default)(message instanceof Buffer);
|
|
1572
|
+
(0, import_assert6.default)(derivedKeys.signingKey instanceof Buffer);
|
|
1573
|
+
(0, import_assert6.default)(typeof derivedKeys.sha1or256 === "string");
|
|
1574
|
+
(0, import_assert6.default)(derivedKeys.sha1or256 === "SHA1" || derivedKeys.sha1or256 === "SHA256");
|
|
1425
1575
|
const signature = (0, import_crypto3.createHmac)(derivedKeys.sha1or256, derivedKeys.signingKey).update(message).digest();
|
|
1426
|
-
(0,
|
|
1576
|
+
(0, import_assert6.default)(signature.length === derivedKeys.signatureLength);
|
|
1427
1577
|
return signature;
|
|
1428
1578
|
}
|
|
1429
1579
|
function verifyChunkSignatureWithDerivedKeys(chunk, derivedKeys) {
|
|
@@ -1433,126 +1583,31 @@ function verifyChunkSignatureWithDerivedKeys(chunk, derivedKeys) {
|
|
|
1433
1583
|
return computedSignature.toString("hex") === expectedSignature.toString("hex");
|
|
1434
1584
|
}
|
|
1435
1585
|
|
|
1436
|
-
// source/
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
const
|
|
1442
|
-
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
return toPem(raw_key, pem);
|
|
1461
|
-
}
|
|
1462
|
-
function coercePrivateKeyPem(privateKey) {
|
|
1463
|
-
return toPem2(privateKey, "PRIVATE KEY");
|
|
1464
|
-
}
|
|
1465
|
-
function coercePublicKeyPem(publicKey) {
|
|
1466
|
-
if (isKeyObject(publicKey)) {
|
|
1467
|
-
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
1468
|
-
}
|
|
1469
|
-
(0, import_assert6.default)(typeof publicKey === "string");
|
|
1470
|
-
return publicKey;
|
|
1471
|
-
}
|
|
1472
|
-
function coerceRsaPublicKeyPem(publicKey) {
|
|
1473
|
-
if (isKeyObject(publicKey)) {
|
|
1474
|
-
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
1475
|
-
}
|
|
1476
|
-
(0, import_assert6.default)(typeof publicKey === "string");
|
|
1477
|
-
return publicKey;
|
|
1478
|
-
}
|
|
1479
|
-
function rsaLengthPublicKey(key) {
|
|
1480
|
-
key = coercePublicKeyPem(key);
|
|
1481
|
-
(0, import_assert6.default)(typeof key === "string");
|
|
1482
|
-
const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
|
|
1483
|
-
return a.n.toString(16).length / 2;
|
|
1484
|
-
}
|
|
1485
|
-
function rsaLengthRsaPublicKey(key) {
|
|
1486
|
-
key = coerceRsaPublicKeyPem(key);
|
|
1487
|
-
(0, import_assert6.default)(typeof key === "string");
|
|
1488
|
-
const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
|
|
1489
|
-
return a.n.toString(16).length / 2;
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
// source/verify_certificate_signature.ts
|
|
1493
|
-
var import_crypto4 = require("crypto");
|
|
1494
|
-
function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
1495
|
-
const block_info = readTag(certificateOrCrl, 0);
|
|
1496
|
-
const blocks = _readStruct(certificateOrCrl, block_info);
|
|
1497
|
-
const bufferToBeSigned = certificateOrCrl.subarray(block_info.position, blocks[1].position - 2);
|
|
1498
|
-
const signatureAlgorithm = _readAlgorithmIdentifier(certificateOrCrl, blocks[1]);
|
|
1499
|
-
const signatureValue = _readSignatureValueBin(certificateOrCrl, blocks[2]);
|
|
1500
|
-
const p = split_der(parentCertificate)[0];
|
|
1501
|
-
const certPem = toPem(p, "CERTIFICATE");
|
|
1502
|
-
const verify = (0, import_crypto4.createVerify)(signatureAlgorithm.identifier);
|
|
1503
|
-
verify.update(bufferToBeSigned);
|
|
1504
|
-
verify.end();
|
|
1505
|
-
return verify.verify(certPem, signatureValue);
|
|
1506
|
-
}
|
|
1507
|
-
function verifyCertificateSignature(certificate, parentCertificate) {
|
|
1508
|
-
return verifyCertificateOrClrSignature(certificate, parentCertificate);
|
|
1509
|
-
}
|
|
1510
|
-
function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
|
|
1511
|
-
return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
|
|
1512
|
-
}
|
|
1513
|
-
async function verifyCertificateChain(certificateChain) {
|
|
1514
|
-
for (let index = 1; index < certificateChain.length; index++) {
|
|
1515
|
-
const cert = certificateChain[index - 1];
|
|
1516
|
-
const certParent = certificateChain[index];
|
|
1517
|
-
const certParentInfo = exploreCertificate(certParent);
|
|
1518
|
-
const keyUsage = certParentInfo.tbsCertificate.extensions.keyUsage;
|
|
1519
|
-
if (!keyUsage.keyCertSign) {
|
|
1520
|
-
return {
|
|
1521
|
-
status: "BadCertificateIssuerUseNotAllowed",
|
|
1522
|
-
reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing"
|
|
1523
|
-
};
|
|
1524
|
-
}
|
|
1525
|
-
const parentSignChild = verifyCertificateSignature(cert, certParent);
|
|
1526
|
-
if (!parentSignChild) {
|
|
1527
|
-
return {
|
|
1528
|
-
status: "BadCertificateInvalid",
|
|
1529
|
-
reason: "One of the certificate in the chain is not signing the previous certificate"
|
|
1530
|
-
};
|
|
1531
|
-
}
|
|
1532
|
-
const certInfo = exploreCertificate(cert);
|
|
1533
|
-
if (!certInfo.tbsCertificate.extensions) {
|
|
1534
|
-
return {
|
|
1535
|
-
status: "BadCertificateInvalid",
|
|
1536
|
-
reason: "Cannot find X409 Extension 3 in certificate"
|
|
1537
|
-
};
|
|
1538
|
-
}
|
|
1539
|
-
if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
|
|
1540
|
-
return {
|
|
1541
|
-
status: "BadCertificateInvalid",
|
|
1542
|
-
reason: "Cannot find X409 Extension 3 in certificate (parent)"
|
|
1543
|
-
};
|
|
1544
|
-
}
|
|
1545
|
-
if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !== certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
|
|
1546
|
-
return {
|
|
1547
|
-
status: "BadCertificateInvalid",
|
|
1548
|
-
reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate"
|
|
1549
|
-
};
|
|
1586
|
+
// source/explore_asn1.ts
|
|
1587
|
+
function t(tag) {
|
|
1588
|
+
return TagType[tag];
|
|
1589
|
+
}
|
|
1590
|
+
function bi(blockInfo, depth) {
|
|
1591
|
+
const indent = " ".repeat(depth);
|
|
1592
|
+
const hl = blockInfo.position - blockInfo.start;
|
|
1593
|
+
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)}`;
|
|
1594
|
+
}
|
|
1595
|
+
function exploreAsn1(buffer) {
|
|
1596
|
+
console.log(hexDump(buffer));
|
|
1597
|
+
function dump(offset, depth) {
|
|
1598
|
+
const blockInfo = readTag(buffer, offset);
|
|
1599
|
+
dumpBlock(blockInfo, depth);
|
|
1600
|
+
function dumpBlock(blockInfo2, depth2) {
|
|
1601
|
+
console.log(bi(blockInfo2, depth2));
|
|
1602
|
+
if (blockInfo2.tag === 48 /* SEQUENCE */ || blockInfo2.tag === 49 /* SET */ || blockInfo2.tag >= 160 /* CONTEXT_SPECIFIC0 */) {
|
|
1603
|
+
const blocks = readStruct(buffer, blockInfo2);
|
|
1604
|
+
for (const block of blocks) {
|
|
1605
|
+
dumpBlock(block, depth2 + 1);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1550
1608
|
}
|
|
1551
1609
|
}
|
|
1552
|
-
|
|
1553
|
-
status: "Good",
|
|
1554
|
-
reason: `certificate chain is valid(length = ${certificateChain.length})`
|
|
1555
|
-
};
|
|
1610
|
+
dump(0, 0);
|
|
1556
1611
|
}
|
|
1557
1612
|
|
|
1558
1613
|
// source/explore_certificate_revocation_list.ts
|
|
@@ -1560,20 +1615,20 @@ function readNameForCrl(buffer, block) {
|
|
|
1560
1615
|
return _readDirectoryName(buffer, block);
|
|
1561
1616
|
}
|
|
1562
1617
|
function _readTbsCertList(buffer, blockInfo) {
|
|
1563
|
-
const blocks =
|
|
1618
|
+
const blocks = readStruct(buffer, blockInfo);
|
|
1564
1619
|
const hasOptionalVersion = blocks[0].tag === 2 /* INTEGER */;
|
|
1565
1620
|
if (hasOptionalVersion) {
|
|
1566
1621
|
const version = _readIntegerValue(buffer, blocks[0]);
|
|
1567
|
-
const signature =
|
|
1622
|
+
const signature = readAlgorithmIdentifier(buffer, blocks[1]);
|
|
1568
1623
|
const issuer = readNameForCrl(buffer, blocks[2]);
|
|
1569
1624
|
const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[2])));
|
|
1570
1625
|
const thisUpdate = _readTime(buffer, blocks[3]);
|
|
1571
1626
|
const nextUpdate = _readTime(buffer, blocks[4]);
|
|
1572
1627
|
const revokedCertificates = [];
|
|
1573
1628
|
if (blocks[5] && blocks[5].tag < 128) {
|
|
1574
|
-
const list =
|
|
1629
|
+
const list = readStruct(buffer, blocks[5]);
|
|
1575
1630
|
for (const r of list) {
|
|
1576
|
-
const rr =
|
|
1631
|
+
const rr = readStruct(buffer, r);
|
|
1577
1632
|
const userCertificate = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, rr[0]));
|
|
1578
1633
|
const revocationDate = _readTime(buffer, rr[1]);
|
|
1579
1634
|
revokedCertificates.push({
|
|
@@ -1585,16 +1640,16 @@ function _readTbsCertList(buffer, blockInfo) {
|
|
|
1585
1640
|
const ext0 = _findBlockAtIndex(blocks, 0);
|
|
1586
1641
|
return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates };
|
|
1587
1642
|
} else {
|
|
1588
|
-
const signature =
|
|
1643
|
+
const signature = readAlgorithmIdentifier(buffer, blocks[0]);
|
|
1589
1644
|
const issuer = readNameForCrl(buffer, blocks[1]);
|
|
1590
1645
|
const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[1])));
|
|
1591
1646
|
const thisUpdate = _readTime(buffer, blocks[2]);
|
|
1592
1647
|
const nextUpdate = _readTime(buffer, blocks[3]);
|
|
1593
1648
|
const revokedCertificates = [];
|
|
1594
1649
|
if (blocks[4] && blocks[4].tag < 128) {
|
|
1595
|
-
const list =
|
|
1650
|
+
const list = readStruct(buffer, blocks[4]);
|
|
1596
1651
|
for (const r of list) {
|
|
1597
|
-
const rr =
|
|
1652
|
+
const rr = readStruct(buffer, r);
|
|
1598
1653
|
const userCertificate = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, rr[0]));
|
|
1599
1654
|
const revocationDate = _readTime(buffer, rr[1]);
|
|
1600
1655
|
revokedCertificates.push({
|
|
@@ -1608,17 +1663,17 @@ function _readTbsCertList(buffer, blockInfo) {
|
|
|
1608
1663
|
}
|
|
1609
1664
|
function exploreCertificateRevocationList(crl) {
|
|
1610
1665
|
const blockInfo = readTag(crl, 0);
|
|
1611
|
-
const blocks =
|
|
1666
|
+
const blocks = readStruct(crl, blockInfo);
|
|
1612
1667
|
const tbsCertList = _readTbsCertList(crl, blocks[0]);
|
|
1613
|
-
const signatureAlgorithm =
|
|
1614
|
-
const signatureValue =
|
|
1668
|
+
const signatureAlgorithm = readAlgorithmIdentifier(crl, blocks[1]);
|
|
1669
|
+
const signatureValue = readSignatureValueBin(crl, blocks[2]);
|
|
1615
1670
|
return { tbsCertList, signatureAlgorithm, signatureValue };
|
|
1616
1671
|
}
|
|
1617
1672
|
|
|
1618
1673
|
// source/explore_certificate_signing_request.ts
|
|
1619
1674
|
function _readExtensionRequest(buffer) {
|
|
1620
1675
|
const block = readTag(buffer, 0);
|
|
1621
|
-
const inner_blocks =
|
|
1676
|
+
const inner_blocks = readStruct(buffer, block);
|
|
1622
1677
|
const extensions = inner_blocks.map((block1) => _readExtension(buffer, block1));
|
|
1623
1678
|
const result = {};
|
|
1624
1679
|
for (const e of extensions) {
|
|
@@ -1628,204 +1683,39 @@ function _readExtensionRequest(buffer) {
|
|
|
1628
1683
|
return { basicConstraints, keyUsage, subjectAltName };
|
|
1629
1684
|
}
|
|
1630
1685
|
function readCertificationRequestInfo(buffer, block) {
|
|
1631
|
-
const blocks =
|
|
1632
|
-
if (blocks.length === 4) {
|
|
1633
|
-
const extensionRequestBlock = _findBlockAtIndex(blocks, 0);
|
|
1634
|
-
if (!extensionRequestBlock) {
|
|
1635
|
-
throw new Error("cannot find extensionRequest block");
|
|
1636
|
-
}
|
|
1637
|
-
const blocks1 =
|
|
1638
|
-
const blocks2 =
|
|
1639
|
-
const identifier = _readObjectIdentifier(buffer, blocks2[0]);
|
|
1640
|
-
if (identifier.name !== "extensionRequest") {
|
|
1641
|
-
throw new Error(" Cannot find extension Request in ASN1 block");
|
|
1642
|
-
}
|
|
1643
|
-
const buf = _getBlock(buffer, blocks2[1]);
|
|
1644
|
-
const extensionRequest = _readExtensionRequest(buf);
|
|
1645
|
-
return { extensionRequest };
|
|
1646
|
-
}
|
|
1647
|
-
throw new Error("Invalid CSR or ");
|
|
1648
|
-
}
|
|
1649
|
-
function exploreCertificateSigningRequest(crl) {
|
|
1650
|
-
const blockInfo = readTag(crl, 0);
|
|
1651
|
-
const blocks = _readStruct(crl, blockInfo);
|
|
1652
|
-
const csrInfo = readCertificationRequestInfo(crl, blocks[0]);
|
|
1653
|
-
return csrInfo;
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
// source/explore_private_key.ts
|
|
1657
|
-
function f(buffer, b) {
|
|
1658
|
-
return buffer.subarray(b.position + 1, b.position + b.length);
|
|
1659
|
-
}
|
|
1660
|
-
var doDebug2 = !!process.env.DEBUG;
|
|
1661
|
-
function explorePrivateKey(privateKey2) {
|
|
1662
|
-
const privateKey1 = privateKey2.hidden;
|
|
1663
|
-
const privateKey = typeof privateKey1 === "string" ? convertPEMtoDER(privateKey1) : privateKey1.export({ format: "der", type: "pkcs1" });
|
|
1664
|
-
const block_info = readTag(privateKey, 0);
|
|
1665
|
-
const blocks = _readStruct(privateKey, block_info);
|
|
1666
|
-
if (blocks.length === 9) {
|
|
1667
|
-
const version2 = f(privateKey, blocks[0]);
|
|
1668
|
-
const modulus2 = f(privateKey, blocks[1]);
|
|
1669
|
-
const publicExponent2 = f(privateKey, blocks[2]);
|
|
1670
|
-
const privateExponent2 = f(privateKey, blocks[3]);
|
|
1671
|
-
const prime12 = f(privateKey, blocks[4]);
|
|
1672
|
-
const prime22 = f(privateKey, blocks[5]);
|
|
1673
|
-
const exponent12 = f(privateKey, blocks[6]);
|
|
1674
|
-
const exponent22 = f(privateKey, blocks[7]);
|
|
1675
|
-
return {
|
|
1676
|
-
version: version2,
|
|
1677
|
-
modulus: modulus2,
|
|
1678
|
-
publicExponent: publicExponent2,
|
|
1679
|
-
privateExponent: privateExponent2,
|
|
1680
|
-
prime1: prime12,
|
|
1681
|
-
prime2: prime22,
|
|
1682
|
-
exponent1: exponent12,
|
|
1683
|
-
exponent2: exponent22
|
|
1684
|
-
};
|
|
1685
|
-
}
|
|
1686
|
-
if (doDebug2) {
|
|
1687
|
-
console.log("-------------------- private key:");
|
|
1688
|
-
console.log(block_info);
|
|
1689
|
-
console.log(
|
|
1690
|
-
blocks.map((b2) => ({
|
|
1691
|
-
tag: TagType[b2.tag] + " 0x" + b2.tag.toString(16),
|
|
1692
|
-
l: b2.length,
|
|
1693
|
-
p: b2.position,
|
|
1694
|
-
buff: privateKey.subarray(b2.position, b2.position + b2.length).toString("hex")
|
|
1695
|
-
}))
|
|
1696
|
-
);
|
|
1697
|
-
}
|
|
1698
|
-
const b = blocks[2];
|
|
1699
|
-
const bb = privateKey.subarray(b.position, b.position + b.length);
|
|
1700
|
-
const block_info1 = readTag(bb, 0);
|
|
1701
|
-
const blocks1 = _readStruct(bb, block_info1);
|
|
1702
|
-
if (doDebug2) {
|
|
1703
|
-
console.log(
|
|
1704
|
-
blocks1.map((b2) => ({
|
|
1705
|
-
tag: TagType[b2.tag] + " 0x" + b2.tag.toString(16),
|
|
1706
|
-
l: b2.length,
|
|
1707
|
-
p: b2.position,
|
|
1708
|
-
buff: bb.subarray(b2.position, b2.position + b2.length).toString("hex")
|
|
1709
|
-
}))
|
|
1710
|
-
);
|
|
1711
|
-
}
|
|
1712
|
-
const version = f(bb, blocks1[0]);
|
|
1713
|
-
const modulus = f(bb, blocks1[1]);
|
|
1714
|
-
const publicExponent = f(bb, blocks1[2]);
|
|
1715
|
-
const privateExponent = f(bb, blocks1[3]);
|
|
1716
|
-
const prime1 = f(bb, blocks1[4]);
|
|
1717
|
-
const prime2 = f(bb, blocks1[5]);
|
|
1718
|
-
const exponent1 = f(bb, blocks1[6]);
|
|
1719
|
-
const exponent2 = f(bb, blocks1[7]);
|
|
1720
|
-
return {
|
|
1721
|
-
version,
|
|
1722
|
-
modulus,
|
|
1723
|
-
publicExponent,
|
|
1724
|
-
privateExponent,
|
|
1725
|
-
prime1,
|
|
1726
|
-
prime2,
|
|
1727
|
-
exponent1,
|
|
1728
|
-
exponent2
|
|
1729
|
-
};
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
// source/public_private_match.ts
|
|
1733
|
-
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
1734
|
-
const i = exploreCertificate(certificate);
|
|
1735
|
-
const j = explorePrivateKey(privateKey);
|
|
1736
|
-
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
1737
|
-
const modulus2 = j.modulus;
|
|
1738
|
-
if (modulus1.length != modulus2.length) {
|
|
1739
|
-
return false;
|
|
1740
|
-
}
|
|
1741
|
-
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
1742
|
-
}
|
|
1743
|
-
function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
1744
|
-
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
1745
|
-
const encryptedBuffer = publicEncrypt_long(initialBuffer, certificate, blockSize);
|
|
1746
|
-
const decryptedBuffer = privateDecrypt_long(encryptedBuffer, privateKey, blockSize);
|
|
1747
|
-
const finalString = decryptedBuffer.toString("utf-8");
|
|
1748
|
-
return initialBuffer.toString("utf-8") === finalString;
|
|
1749
|
-
}
|
|
1750
|
-
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
1751
|
-
const e = explorePrivateKey(privateKey);
|
|
1752
|
-
const blockSize = e.modulus.length;
|
|
1753
|
-
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
1754
|
-
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
|
-
// source/x509/_crypto.ts
|
|
1758
|
-
var x509 = __toESM(require("@peculiar/x509"));
|
|
1759
|
-
var import_webcrypto = require("@peculiar/webcrypto");
|
|
1760
|
-
var import_crypto5 = __toESM(require("crypto"));
|
|
1761
|
-
var x5092 = __toESM(require("@peculiar/x509"));
|
|
1762
|
-
var doDebug3 = false;
|
|
1763
|
-
var _crypto;
|
|
1764
|
-
var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
|
|
1765
|
-
if (typeof window === "undefined") {
|
|
1766
|
-
_crypto = import_crypto5.default;
|
|
1767
|
-
if (!_crypto?.subtle || ignoreCrypto) {
|
|
1768
|
-
_crypto = new import_webcrypto.Crypto();
|
|
1769
|
-
doDebug3 && console.warn("using @peculiar/webcrypto");
|
|
1770
|
-
} else {
|
|
1771
|
-
doDebug3 && console.warn("using nodejs crypto (native)");
|
|
1772
|
-
}
|
|
1773
|
-
x509.cryptoProvider.set(_crypto);
|
|
1774
|
-
} else {
|
|
1775
|
-
doDebug3 && console.warn("using browser crypto (native)");
|
|
1776
|
-
_crypto = crypto;
|
|
1777
|
-
x509.cryptoProvider.set(crypto);
|
|
1778
|
-
}
|
|
1779
|
-
function getCrypto() {
|
|
1780
|
-
return _crypto || crypto || require("crypto");
|
|
1781
|
-
}
|
|
1782
|
-
|
|
1783
|
-
// source/x509/create_key_pair.ts
|
|
1784
|
-
async function generateKeyPair(modulusLength = 2048) {
|
|
1785
|
-
const crypto3 = getCrypto();
|
|
1786
|
-
const alg = {
|
|
1787
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
1788
|
-
hash: { name: "SHA-256" },
|
|
1789
|
-
publicExponent: new Uint8Array([1, 0, 1]),
|
|
1790
|
-
modulusLength
|
|
1791
|
-
};
|
|
1792
|
-
const keys = await crypto3.subtle.generateKey(alg, true, ["sign", "verify"]);
|
|
1793
|
-
return keys;
|
|
1794
|
-
}
|
|
1795
|
-
async function generatePrivateKey(modulusLength = 2048) {
|
|
1796
|
-
return (await generateKeyPair(modulusLength)).privateKey;
|
|
1686
|
+
const blocks = readStruct(buffer, block);
|
|
1687
|
+
if (blocks.length === 4) {
|
|
1688
|
+
const extensionRequestBlock = _findBlockAtIndex(blocks, 0);
|
|
1689
|
+
if (!extensionRequestBlock) {
|
|
1690
|
+
throw new Error("cannot find extensionRequest block");
|
|
1691
|
+
}
|
|
1692
|
+
const blocks1 = readStruct(buffer, extensionRequestBlock);
|
|
1693
|
+
const blocks2 = readStruct(buffer, blocks1[0]);
|
|
1694
|
+
const identifier = _readObjectIdentifier(buffer, blocks2[0]);
|
|
1695
|
+
if (identifier.name !== "extensionRequest") {
|
|
1696
|
+
throw new Error(" Cannot find extension Request in ASN1 block");
|
|
1697
|
+
}
|
|
1698
|
+
const buf = _getBlock(buffer, blocks2[1]);
|
|
1699
|
+
const extensionRequest = _readExtensionRequest(buf);
|
|
1700
|
+
return { extensionRequest };
|
|
1701
|
+
}
|
|
1702
|
+
throw new Error("Invalid CSR or ");
|
|
1797
1703
|
}
|
|
1798
|
-
|
|
1799
|
-
const
|
|
1800
|
-
const
|
|
1801
|
-
const
|
|
1802
|
-
return
|
|
1704
|
+
function exploreCertificateSigningRequest(crl) {
|
|
1705
|
+
const blockInfo = readTag(crl, 0);
|
|
1706
|
+
const blocks = readStruct(crl, blockInfo);
|
|
1707
|
+
const csrInfo = readCertificationRequestInfo(crl, blocks[0]);
|
|
1708
|
+
return csrInfo;
|
|
1803
1709
|
}
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
privDer,
|
|
1809
|
-
{
|
|
1810
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
1811
|
-
hash: { name: "SHA-256" }
|
|
1812
|
-
},
|
|
1813
|
-
true,
|
|
1814
|
-
[
|
|
1815
|
-
"sign"
|
|
1816
|
-
// "encrypt",
|
|
1817
|
-
// "decrypt",
|
|
1818
|
-
// "verify",
|
|
1819
|
-
// "wrapKey",
|
|
1820
|
-
// "unwrapKey",
|
|
1821
|
-
// "deriveKey",
|
|
1822
|
-
// "deriveBits"
|
|
1823
|
-
]
|
|
1824
|
-
);
|
|
1710
|
+
|
|
1711
|
+
// source/make_private_key_from_pem.ts
|
|
1712
|
+
function makePrivateKeyFromPem(privateKeyInPem) {
|
|
1713
|
+
return { hidden: privateKeyInPem };
|
|
1825
1714
|
}
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1715
|
+
|
|
1716
|
+
// source/make_private_key_thumbprint.ts
|
|
1717
|
+
function makePrivateKeyThumbPrint(privateKey) {
|
|
1718
|
+
return Buffer.alloc(0);
|
|
1829
1719
|
}
|
|
1830
1720
|
|
|
1831
1721
|
// source/subject.ts
|
|
@@ -1910,11 +1800,180 @@ var Subject = class _Subject {
|
|
|
1910
1800
|
return this.toStringInternal("/");
|
|
1911
1801
|
}
|
|
1912
1802
|
toString() {
|
|
1913
|
-
const
|
|
1914
|
-
return
|
|
1803
|
+
const t2 = this.toStringForOPCUA();
|
|
1804
|
+
return t2 ? "/" + t2 : t2;
|
|
1915
1805
|
}
|
|
1916
1806
|
};
|
|
1917
1807
|
|
|
1808
|
+
// source/verify_certificate_signature.ts
|
|
1809
|
+
var import_crypto4 = require("crypto");
|
|
1810
|
+
function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
1811
|
+
const block_info = readTag(certificateOrCrl, 0);
|
|
1812
|
+
const blocks = readStruct(certificateOrCrl, block_info);
|
|
1813
|
+
const bufferToBeSigned = certificateOrCrl.subarray(block_info.position, blocks[1].position - 2);
|
|
1814
|
+
const signatureAlgorithm = readAlgorithmIdentifier(certificateOrCrl, blocks[1]);
|
|
1815
|
+
const signatureValue = readSignatureValueBin(certificateOrCrl, blocks[2]);
|
|
1816
|
+
const p = split_der(parentCertificate)[0];
|
|
1817
|
+
const certPem = toPem(p, "CERTIFICATE");
|
|
1818
|
+
const verify = (0, import_crypto4.createVerify)(signatureAlgorithm.identifier);
|
|
1819
|
+
verify.update(bufferToBeSigned);
|
|
1820
|
+
verify.end();
|
|
1821
|
+
return verify.verify(certPem, signatureValue);
|
|
1822
|
+
}
|
|
1823
|
+
function verifyCertificateSignature(certificate, parentCertificate) {
|
|
1824
|
+
return verifyCertificateOrClrSignature(certificate, parentCertificate);
|
|
1825
|
+
}
|
|
1826
|
+
function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
|
|
1827
|
+
return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
|
|
1828
|
+
}
|
|
1829
|
+
async function verifyCertificateChain(certificateChain) {
|
|
1830
|
+
for (let index = 1; index < certificateChain.length; index++) {
|
|
1831
|
+
const cert = certificateChain[index - 1];
|
|
1832
|
+
const certParent = certificateChain[index];
|
|
1833
|
+
const certParentInfo = exploreCertificate(certParent);
|
|
1834
|
+
const keyUsage = certParentInfo.tbsCertificate.extensions.keyUsage;
|
|
1835
|
+
if (!keyUsage.keyCertSign) {
|
|
1836
|
+
return {
|
|
1837
|
+
status: "BadCertificateIssuerUseNotAllowed",
|
|
1838
|
+
reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing"
|
|
1839
|
+
};
|
|
1840
|
+
}
|
|
1841
|
+
const parentSignChild = verifyCertificateSignature(cert, certParent);
|
|
1842
|
+
if (!parentSignChild) {
|
|
1843
|
+
return {
|
|
1844
|
+
status: "BadCertificateInvalid",
|
|
1845
|
+
reason: "One of the certificate in the chain is not signing the previous certificate"
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
const certInfo = exploreCertificate(cert);
|
|
1849
|
+
if (!certInfo.tbsCertificate.extensions) {
|
|
1850
|
+
return {
|
|
1851
|
+
status: "BadCertificateInvalid",
|
|
1852
|
+
reason: "Cannot find X409 Extension 3 in certificate"
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
|
|
1856
|
+
return {
|
|
1857
|
+
status: "BadCertificateInvalid",
|
|
1858
|
+
reason: "Cannot find X409 Extension 3 in certificate (parent)"
|
|
1859
|
+
};
|
|
1860
|
+
}
|
|
1861
|
+
if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !== certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
|
|
1862
|
+
return {
|
|
1863
|
+
status: "BadCertificateInvalid",
|
|
1864
|
+
reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate"
|
|
1865
|
+
};
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
return {
|
|
1869
|
+
status: "Good",
|
|
1870
|
+
reason: `certificate chain is valid(length = ${certificateChain.length})`
|
|
1871
|
+
};
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// source/x509/_crypto.ts
|
|
1875
|
+
var x509 = __toESM(require("@peculiar/x509"));
|
|
1876
|
+
var import_webcrypto = require("@peculiar/webcrypto");
|
|
1877
|
+
var import_crypto5 = __toESM(require("crypto"));
|
|
1878
|
+
var x5092 = __toESM(require("@peculiar/x509"));
|
|
1879
|
+
var doDebug3 = false;
|
|
1880
|
+
var _crypto;
|
|
1881
|
+
var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
|
|
1882
|
+
if (typeof window === "undefined") {
|
|
1883
|
+
_crypto = import_crypto5.default;
|
|
1884
|
+
if (!_crypto?.subtle || ignoreCrypto) {
|
|
1885
|
+
_crypto = new import_webcrypto.Crypto();
|
|
1886
|
+
doDebug3 && console.warn("using @peculiar/webcrypto");
|
|
1887
|
+
} else {
|
|
1888
|
+
doDebug3 && console.warn("using nodejs crypto (native)");
|
|
1889
|
+
}
|
|
1890
|
+
x509.cryptoProvider.set(_crypto);
|
|
1891
|
+
} else {
|
|
1892
|
+
doDebug3 && console.warn("using browser crypto (native)");
|
|
1893
|
+
_crypto = crypto;
|
|
1894
|
+
x509.cryptoProvider.set(crypto);
|
|
1895
|
+
}
|
|
1896
|
+
function getCrypto() {
|
|
1897
|
+
return _crypto || crypto || require("crypto");
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
// source/x509/create_key_pair.ts
|
|
1901
|
+
async function generateKeyPair(modulusLength = 2048) {
|
|
1902
|
+
const crypto3 = getCrypto();
|
|
1903
|
+
const alg = {
|
|
1904
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
1905
|
+
hash: { name: "SHA-256" },
|
|
1906
|
+
publicExponent: new Uint8Array([1, 0, 1]),
|
|
1907
|
+
modulusLength
|
|
1908
|
+
};
|
|
1909
|
+
const keys = await crypto3.subtle.generateKey(alg, true, ["sign", "verify"]);
|
|
1910
|
+
return keys;
|
|
1911
|
+
}
|
|
1912
|
+
async function generatePrivateKey(modulusLength = 2048) {
|
|
1913
|
+
return (await generateKeyPair(modulusLength)).privateKey;
|
|
1914
|
+
}
|
|
1915
|
+
async function privateKeyToPEM(privateKey) {
|
|
1916
|
+
const crypto3 = getCrypto();
|
|
1917
|
+
const privDer = await crypto3.subtle.exportKey("pkcs8", privateKey);
|
|
1918
|
+
const privPem = x5092.PemConverter.encode(privDer, "PRIVATE KEY");
|
|
1919
|
+
return { privPem, privDer };
|
|
1920
|
+
}
|
|
1921
|
+
async function derToPrivateKey(privDer) {
|
|
1922
|
+
const crypto3 = getCrypto();
|
|
1923
|
+
return await crypto3.subtle.importKey(
|
|
1924
|
+
"pkcs8",
|
|
1925
|
+
privDer,
|
|
1926
|
+
{
|
|
1927
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
1928
|
+
hash: { name: "SHA-256" }
|
|
1929
|
+
},
|
|
1930
|
+
true,
|
|
1931
|
+
[
|
|
1932
|
+
"sign"
|
|
1933
|
+
// "encrypt",
|
|
1934
|
+
// "decrypt",
|
|
1935
|
+
// "verify",
|
|
1936
|
+
// "wrapKey",
|
|
1937
|
+
// "unwrapKey",
|
|
1938
|
+
// "deriveKey",
|
|
1939
|
+
// "deriveBits"
|
|
1940
|
+
]
|
|
1941
|
+
);
|
|
1942
|
+
}
|
|
1943
|
+
async function pemToPrivateKey(pem) {
|
|
1944
|
+
const privDer = x5092.PemConverter.decode(pem);
|
|
1945
|
+
return derToPrivateKey(privDer[0]);
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
// source/x509/coerce_private_key.ts
|
|
1949
|
+
var crypto2 = getCrypto();
|
|
1950
|
+
var doDebug4 = false;
|
|
1951
|
+
function coercePEMorDerToPrivateKey(privateKeyInDerOrPem) {
|
|
1952
|
+
if (typeof privateKeyInDerOrPem === "string") {
|
|
1953
|
+
const hidden = createPrivateKeyFromNodeJSCrypto(privateKeyInDerOrPem);
|
|
1954
|
+
return { hidden };
|
|
1955
|
+
}
|
|
1956
|
+
throw new Error("not implemented");
|
|
1957
|
+
}
|
|
1958
|
+
async function _coercePrivateKey(privateKey) {
|
|
1959
|
+
const KeyObject4 = crypto2.KeyObject;
|
|
1960
|
+
if (privateKey instanceof Buffer) {
|
|
1961
|
+
const privateKey1 = await derToPrivateKey(privateKey);
|
|
1962
|
+
return KeyObject4.from(privateKey1);
|
|
1963
|
+
} else if (typeof privateKey === "string") {
|
|
1964
|
+
try {
|
|
1965
|
+
const privateKey1 = await pemToPrivateKey(privateKey);
|
|
1966
|
+
return KeyObject4.from(privateKey1);
|
|
1967
|
+
} catch (err) {
|
|
1968
|
+
doDebug4 && console.log(privateKey);
|
|
1969
|
+
throw err;
|
|
1970
|
+
}
|
|
1971
|
+
} else if (privateKey instanceof KeyObject4) {
|
|
1972
|
+
return privateKey;
|
|
1973
|
+
}
|
|
1974
|
+
throw new Error("Invalid privateKey");
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1918
1977
|
// source/x509/_get_attributes.ts
|
|
1919
1978
|
var keyUsageApplication = x5092.KeyUsageFlags.keyEncipherment | x5092.KeyUsageFlags.nonRepudiation | x5092.KeyUsageFlags.dataEncipherment | x5092.KeyUsageFlags.keyCertSign | x5092.KeyUsageFlags.digitalSignature;
|
|
1920
1979
|
var keyUsageCA = x5092.KeyUsageFlags.keyCertSign | x5092.KeyUsageFlags.cRLSign;
|
|
@@ -5456,11 +5515,11 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
5456
5515
|
};
|
|
5457
5516
|
}
|
|
5458
5517
|
if (inputSchema.primitiveSchema && VALUE_HEX_VIEW in inputData.valueBlock) {
|
|
5459
|
-
const
|
|
5460
|
-
if (
|
|
5518
|
+
const asn12 = localFromBER(inputData.valueBlock.valueHexView);
|
|
5519
|
+
if (asn12.offset === -1) {
|
|
5461
5520
|
const _result = {
|
|
5462
5521
|
verified: false,
|
|
5463
|
-
result:
|
|
5522
|
+
result: asn12.result
|
|
5464
5523
|
};
|
|
5465
5524
|
if (inputSchema.name) {
|
|
5466
5525
|
inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
|
|
@@ -5471,7 +5530,7 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
5471
5530
|
}
|
|
5472
5531
|
return _result;
|
|
5473
5532
|
}
|
|
5474
|
-
return compareSchema(root,
|
|
5533
|
+
return compareSchema(root, asn12.result, inputSchema.primitiveSchema);
|
|
5475
5534
|
}
|
|
5476
5535
|
return {
|
|
5477
5536
|
verified: true,
|
|
@@ -5485,14 +5544,14 @@ function verifySchema(inputBuffer, inputSchema) {
|
|
|
5485
5544
|
result: { error: "Wrong ASN.1 schema type" }
|
|
5486
5545
|
};
|
|
5487
5546
|
}
|
|
5488
|
-
const
|
|
5489
|
-
if (
|
|
5547
|
+
const asn12 = localFromBER(BufferSourceConverter.toUint8Array(inputBuffer));
|
|
5548
|
+
if (asn12.offset === -1) {
|
|
5490
5549
|
return {
|
|
5491
5550
|
verified: false,
|
|
5492
|
-
result:
|
|
5551
|
+
result: asn12.result
|
|
5493
5552
|
};
|
|
5494
5553
|
}
|
|
5495
|
-
return compareSchema(
|
|
5554
|
+
return compareSchema(asn12.result, asn12.result, inputSchema);
|
|
5496
5555
|
}
|
|
5497
5556
|
|
|
5498
5557
|
// ../../node_modules/@peculiar/asn1-schema/build/es2015/enums.js
|
|
@@ -6180,53 +6239,22 @@ async function createSelfSignedCertificate({
|
|
|
6180
6239
|
return { cert: cert.toString("pem"), der: cert };
|
|
6181
6240
|
}
|
|
6182
6241
|
|
|
6183
|
-
// source/
|
|
6184
|
-
var
|
|
6185
|
-
var doDebug4 = false;
|
|
6186
|
-
function coercePEMorDerToPrivateKey(privateKeyInDerOrPem) {
|
|
6187
|
-
if (typeof privateKeyInDerOrPem === "string") {
|
|
6188
|
-
const hidden = createPrivateKeyFromNodeJSCrypto(privateKeyInDerOrPem);
|
|
6189
|
-
return { hidden };
|
|
6190
|
-
}
|
|
6191
|
-
throw new Error("not implemented");
|
|
6192
|
-
}
|
|
6193
|
-
async function _coercePrivateKey(privateKey) {
|
|
6194
|
-
const KeyObject4 = crypto2.KeyObject;
|
|
6195
|
-
if (privateKey instanceof Buffer) {
|
|
6196
|
-
const privateKey1 = await derToPrivateKey(privateKey);
|
|
6197
|
-
return KeyObject4.from(privateKey1);
|
|
6198
|
-
} else if (typeof privateKey === "string") {
|
|
6199
|
-
try {
|
|
6200
|
-
const privateKey1 = await pemToPrivateKey(privateKey);
|
|
6201
|
-
return KeyObject4.from(privateKey1);
|
|
6202
|
-
} catch (err) {
|
|
6203
|
-
doDebug4 && console.log(privateKey);
|
|
6204
|
-
throw err;
|
|
6205
|
-
}
|
|
6206
|
-
} else if (privateKey instanceof KeyObject4) {
|
|
6207
|
-
return privateKey;
|
|
6208
|
-
}
|
|
6209
|
-
throw new Error("Invalid privateKey");
|
|
6210
|
-
}
|
|
6211
|
-
|
|
6212
|
-
// source/make_private_key_from_pem.ts
|
|
6213
|
-
function makePrivateKeyFromPem(privateKeyInPem) {
|
|
6214
|
-
return { hidden: privateKeyInPem };
|
|
6215
|
-
}
|
|
6242
|
+
// source/index.ts
|
|
6243
|
+
var asn1 = { readTag, readStruct, readAlgorithmIdentifier, readSignatureValueBin };
|
|
6216
6244
|
|
|
6217
6245
|
// source_nodejs/read.ts
|
|
6218
6246
|
var import_assert7 = __toESM(require("assert"));
|
|
6219
|
-
var
|
|
6220
|
-
var
|
|
6247
|
+
var import_node_fs = __toESM(require("fs"));
|
|
6248
|
+
var import_node_path = __toESM(require("path"));
|
|
6221
6249
|
var import_crypto13 = require("crypto");
|
|
6222
6250
|
var import_sshpk = __toESM(require("sshpk"));
|
|
6223
6251
|
function _readPemFile(filename) {
|
|
6224
6252
|
(0, import_assert7.default)(typeof filename === "string");
|
|
6225
|
-
return removeTrailingLF(
|
|
6253
|
+
return removeTrailingLF(import_node_fs.default.readFileSync(filename, "utf-8"));
|
|
6226
6254
|
}
|
|
6227
6255
|
function _readPemOrDerFileAsDER(filename) {
|
|
6228
6256
|
if (filename.match(/.*\.der/)) {
|
|
6229
|
-
return
|
|
6257
|
+
return import_node_fs.default.readFileSync(filename);
|
|
6230
6258
|
}
|
|
6231
6259
|
const raw_key = _readPemFile(filename);
|
|
6232
6260
|
return convertPEMtoDER(raw_key);
|
|
@@ -6236,7 +6264,7 @@ function readCertificate(filename) {
|
|
|
6236
6264
|
}
|
|
6237
6265
|
function readPublicKey(filename) {
|
|
6238
6266
|
if (filename.match(/.*\.der/)) {
|
|
6239
|
-
const der =
|
|
6267
|
+
const der = import_node_fs.default.readFileSync(filename);
|
|
6240
6268
|
return (0, import_crypto13.createPublicKey)(der);
|
|
6241
6269
|
} else {
|
|
6242
6270
|
const raw_key = _readPemFile(filename);
|
|
@@ -6258,15 +6286,12 @@ function myCreatePrivateKey(rawKey) {
|
|
|
6258
6286
|
process.env.OPENSSL_CONF = backup;
|
|
6259
6287
|
return { hidden: retValue };
|
|
6260
6288
|
}
|
|
6261
|
-
function makePrivateKeyThumbPrint(privateKey) {
|
|
6262
|
-
return Buffer.alloc(0);
|
|
6263
|
-
}
|
|
6264
6289
|
function ensureTrailingLF(str) {
|
|
6265
6290
|
return str.match(/\n$/) ? str : str + "\n";
|
|
6266
6291
|
}
|
|
6267
6292
|
function readPrivateKey(filename) {
|
|
6268
6293
|
if (filename.match(/.*\.der/)) {
|
|
6269
|
-
const der =
|
|
6294
|
+
const der = import_node_fs.default.readFileSync(filename);
|
|
6270
6295
|
return myCreatePrivateKey(der);
|
|
6271
6296
|
} else {
|
|
6272
6297
|
const raw_key = _readPemFile(filename);
|
|
@@ -6290,7 +6315,7 @@ function setCertificateStore(store) {
|
|
|
6290
6315
|
}
|
|
6291
6316
|
function getCertificateStore() {
|
|
6292
6317
|
if (!_g_certificate_store) {
|
|
6293
|
-
_g_certificate_store =
|
|
6318
|
+
_g_certificate_store = import_node_path.default.join(__dirname, "../../certificates/");
|
|
6294
6319
|
}
|
|
6295
6320
|
return _g_certificate_store;
|
|
6296
6321
|
}
|
|
@@ -6298,30 +6323,29 @@ function readPrivateRsaKey(filename) {
|
|
|
6298
6323
|
if (!import_crypto13.createPrivateKey) {
|
|
6299
6324
|
throw new Error("createPrivateKey is not supported in this environment");
|
|
6300
6325
|
}
|
|
6301
|
-
if (filename.substring(0, 1) !== "." && !
|
|
6302
|
-
filename =
|
|
6326
|
+
if (filename.substring(0, 1) !== "." && !import_node_fs.default.existsSync(filename)) {
|
|
6327
|
+
filename = import_node_path.default.join(getCertificateStore(), filename);
|
|
6303
6328
|
}
|
|
6304
|
-
const content =
|
|
6329
|
+
const content = import_node_fs.default.readFileSync(filename, "utf8");
|
|
6305
6330
|
const sshKey = import_sshpk.default.parsePrivateKey(content, "auto");
|
|
6306
6331
|
const key = sshKey.toString("pkcs1");
|
|
6307
6332
|
const hidden = (0, import_crypto13.createPrivateKey)({ format: "pem", type: "pkcs1", key });
|
|
6308
6333
|
return { hidden };
|
|
6309
6334
|
}
|
|
6310
6335
|
function readPublicRsaKey(filename) {
|
|
6311
|
-
if (filename.substring(0, 1) !== "." && !
|
|
6312
|
-
filename =
|
|
6336
|
+
if (filename.substring(0, 1) !== "." && !import_node_fs.default.existsSync(filename)) {
|
|
6337
|
+
filename = import_node_path.default.join(getCertificateStore(), filename);
|
|
6313
6338
|
}
|
|
6314
|
-
const content =
|
|
6339
|
+
const content = import_node_fs.default.readFileSync(filename, "utf-8");
|
|
6315
6340
|
const sshKey = import_sshpk.default.parseKey(content, "ssh");
|
|
6316
6341
|
const key = sshKey.toString("pkcs1");
|
|
6317
6342
|
return (0, import_crypto13.createPublicKey)({ format: "pem", type: "pkcs1", key });
|
|
6318
6343
|
}
|
|
6319
6344
|
|
|
6320
6345
|
// source_nodejs/read_certificate_revocation_list.ts
|
|
6321
|
-
var
|
|
6322
|
-
var import_util = require("util");
|
|
6346
|
+
var import_node_fs2 = __toESM(require("fs"));
|
|
6323
6347
|
async function readCertificateRevocationList(filename) {
|
|
6324
|
-
const crl = await
|
|
6348
|
+
const crl = await import_node_fs2.default.promises.readFile(filename);
|
|
6325
6349
|
if (crl[0] === 48 && crl[1] === 130) {
|
|
6326
6350
|
return crl;
|
|
6327
6351
|
}
|
|
@@ -6330,10 +6354,9 @@ async function readCertificateRevocationList(filename) {
|
|
|
6330
6354
|
}
|
|
6331
6355
|
|
|
6332
6356
|
// source_nodejs/read_certificate_signing_request.ts
|
|
6333
|
-
var
|
|
6334
|
-
var import_util2 = require("util");
|
|
6357
|
+
var import_node_fs3 = __toESM(require("fs"));
|
|
6335
6358
|
async function readCertificateSigningRequest(filename) {
|
|
6336
|
-
const csr = await
|
|
6359
|
+
const csr = await import_node_fs3.default.promises.readFile(filename);
|
|
6337
6360
|
if (csr[0] === 48 && csr[1] === 130) {
|
|
6338
6361
|
return csr;
|
|
6339
6362
|
}
|
|
@@ -6342,12 +6365,12 @@ async function readCertificateSigningRequest(filename) {
|
|
|
6342
6365
|
}
|
|
6343
6366
|
|
|
6344
6367
|
// source_nodejs/generate_private_key_filename.ts
|
|
6345
|
-
var
|
|
6368
|
+
var import_node_fs4 = __toESM(require("fs"));
|
|
6346
6369
|
var import_jsrsasign3 = __toESM(require("jsrsasign"));
|
|
6347
6370
|
async function generatePrivateKeyFile(privateKeyFilename, modulusLength) {
|
|
6348
6371
|
const keys = await generateKeyPair(modulusLength);
|
|
6349
6372
|
const privateKeyPem = await privateKeyToPEM(keys.privateKey);
|
|
6350
|
-
await
|
|
6373
|
+
await import_node_fs4.default.promises.writeFile(privateKeyFilename, privateKeyPem.privPem, "utf-8");
|
|
6351
6374
|
privateKeyPem.privPem = "";
|
|
6352
6375
|
privateKeyPem.privDer = new Uint8Array(0);
|
|
6353
6376
|
}
|
|
@@ -6356,7 +6379,7 @@ async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength
|
|
|
6356
6379
|
const prv = kp.prvKeyObj;
|
|
6357
6380
|
const pub = kp.pubKeyObj;
|
|
6358
6381
|
const prvpem = import_jsrsasign3.default.KEYUTIL.getPEM(prv, "PKCS8PRV");
|
|
6359
|
-
await
|
|
6382
|
+
await import_node_fs4.default.promises.writeFile(privateKeyFilename, prvpem, "utf-8");
|
|
6360
6383
|
}
|
|
6361
6384
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6362
6385
|
0 && (module.exports = {
|
|
@@ -6365,28 +6388,9 @@ async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength
|
|
|
6365
6388
|
RSA_PKCS1_OAEP_PADDING,
|
|
6366
6389
|
RSA_PKCS1_PADDING,
|
|
6367
6390
|
Subject,
|
|
6368
|
-
TagType,
|
|
6369
6391
|
_coercePrivateKey,
|
|
6370
|
-
_findBlockAtIndex,
|
|
6371
|
-
_getBlock,
|
|
6372
|
-
_readAlgorithmIdentifier,
|
|
6373
|
-
_readBitString,
|
|
6374
|
-
_readBooleanValue,
|
|
6375
|
-
_readDirectoryName,
|
|
6376
|
-
_readECCAlgorithmIdentifier,
|
|
6377
6392
|
_readExtension,
|
|
6378
|
-
|
|
6379
|
-
_readIntegerValue,
|
|
6380
|
-
_readListOfInteger,
|
|
6381
|
-
_readLongIntegerValue,
|
|
6382
|
-
_readObjectIdentifier,
|
|
6383
|
-
_readOctetString,
|
|
6384
|
-
_readSignatureValue,
|
|
6385
|
-
_readSignatureValueBin,
|
|
6386
|
-
_readStruct,
|
|
6387
|
-
_readTime,
|
|
6388
|
-
_readValue,
|
|
6389
|
-
_readVersionValue,
|
|
6393
|
+
asn1,
|
|
6390
6394
|
certificateMatchesPrivateKey,
|
|
6391
6395
|
coerceCertificate,
|
|
6392
6396
|
coerceCertificatePem,
|
|
@@ -6395,7 +6399,6 @@ async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength
|
|
|
6395
6399
|
coercePublicKeyPem,
|
|
6396
6400
|
coerceRsaPublicKeyPem,
|
|
6397
6401
|
combine_der,
|
|
6398
|
-
compactDirectoryName,
|
|
6399
6402
|
computeDerivedKeys,
|
|
6400
6403
|
computePaddingFooter,
|
|
6401
6404
|
convertPEMtoDER,
|
|
@@ -6405,6 +6408,7 @@ async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength
|
|
|
6405
6408
|
decryptBufferWithDerivedKeys,
|
|
6406
6409
|
derToPrivateKey,
|
|
6407
6410
|
encryptBufferWithDerivedKeys,
|
|
6411
|
+
exploreAsn1,
|
|
6408
6412
|
exploreCertificate,
|
|
6409
6413
|
exploreCertificateInfo,
|
|
6410
6414
|
exploreCertificateRevocationList,
|
|
@@ -6412,7 +6416,6 @@ async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength
|
|
|
6412
6416
|
explorePrivateKey,
|
|
6413
6417
|
extractPublicKeyFromCertificate,
|
|
6414
6418
|
extractPublicKeyFromCertificateSync,
|
|
6415
|
-
formatBuffer2DigitHexWithColum,
|
|
6416
6419
|
generateKeyPair,
|
|
6417
6420
|
generatePrivateKey,
|
|
6418
6421
|
generatePrivateKeyFile,
|
|
@@ -6427,7 +6430,6 @@ async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength
|
|
|
6427
6430
|
makePrivateKeyThumbPrint,
|
|
6428
6431
|
makePseudoRandomBuffer,
|
|
6429
6432
|
makeSHA1Thumbprint,
|
|
6430
|
-
parseBitString,
|
|
6431
6433
|
pemToPrivateKey,
|
|
6432
6434
|
privateDecrypt,
|
|
6433
6435
|
privateDecrypt_long,
|
|
@@ -6449,7 +6451,6 @@ async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength
|
|
|
6449
6451
|
readPublicKey,
|
|
6450
6452
|
readPublicKeyPEM,
|
|
6451
6453
|
readPublicRsaKey,
|
|
6452
|
-
readTag,
|
|
6453
6454
|
readTbsCertificate,
|
|
6454
6455
|
reduceLength,
|
|
6455
6456
|
removePadding,
|