node-opcua-crypto 4.9.3 → 4.10.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 +114 -114
- package/dist/{chunk-VAMKYXNP.mjs → chunk-46EEAYVO.mjs} +37 -16
- package/dist/chunk-46EEAYVO.mjs.map +1 -0
- package/dist/{chunk-WYY6WVVJ.mjs → chunk-GNEWUC7X.mjs} +2 -2
- package/dist/chunk-GNEWUC7X.mjs.map +1 -0
- package/dist/chunk-VI4S2NM5.mjs +38 -0
- package/dist/chunk-VI4S2NM5.mjs.map +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +69 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -3
- package/dist/index_web.d.mts +2 -1
- package/dist/index_web.d.ts +2 -1
- package/dist/index_web.js +69 -19
- package/dist/index_web.js.map +1 -1
- package/dist/index_web.mjs +5 -2
- package/dist/source/index.d.mts +6 -521
- package/dist/source/index.d.ts +6 -521
- package/dist/source/index.js +69 -19
- package/dist/source/index.js.map +1 -1
- package/dist/source/index.mjs +5 -2
- package/dist/source/index_web.d.mts +528 -4
- package/dist/source/index_web.d.ts +528 -4
- package/dist/source/index_web.js +36 -15
- package/dist/source/index_web.js.map +1 -1
- package/dist/source/index_web.mjs +1 -1
- package/dist/source_nodejs/index.js +6 -6
- package/dist/source_nodejs/index.js.map +1 -1
- package/dist/source_nodejs/index.mjs +3 -3
- package/index.mjs +1 -1
- package/index_web.ts +1 -1
- package/package.json +4 -4
- package/dist/chunk-5NV4OKIV.mjs +0 -1
- package/dist/chunk-5NV4OKIV.mjs.map +0 -1
- package/dist/chunk-VAMKYXNP.mjs.map +0 -1
- package/dist/chunk-WYY6WVVJ.mjs.map +0 -1
package/dist/source/index.js
CHANGED
|
@@ -75,6 +75,7 @@ __export(source_exports, {
|
|
|
75
75
|
decryptBufferWithDerivedKeys: () => decryptBufferWithDerivedKeys,
|
|
76
76
|
derToPrivateKey: () => derToPrivateKey,
|
|
77
77
|
encryptBufferWithDerivedKeys: () => encryptBufferWithDerivedKeys,
|
|
78
|
+
exploreAsn1: () => exploreAsn1,
|
|
78
79
|
exploreCertificate: () => exploreCertificate,
|
|
79
80
|
exploreCertificateInfo: () => exploreCertificateInfo,
|
|
80
81
|
exploreCertificateRevocationList: () => exploreCertificateRevocationList,
|
|
@@ -229,6 +230,7 @@ var oid_map = {
|
|
|
229
230
|
"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
231
|
"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
232
|
"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)" },
|
|
233
|
+
"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
234
|
"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
235
|
"1.3.6.1.5.5.7.3.1": { d: "serverAuth", c: "PKIX key purpose" },
|
|
234
236
|
"1.3.6.1.5.5.7.3.2": { d: "clientAuth", c: "PKIX key purpose" },
|
|
@@ -488,12 +490,15 @@ var TagType = /* @__PURE__ */ ((TagType3) => {
|
|
|
488
490
|
TagType3[TagType3["BMPString"] = 30] = "BMPString";
|
|
489
491
|
TagType3[TagType3["SEQUENCE"] = 48] = "SEQUENCE";
|
|
490
492
|
TagType3[TagType3["SET"] = 49] = "SET";
|
|
491
|
-
TagType3[TagType3["
|
|
493
|
+
TagType3[TagType3["CONTEXT_SPECIFIC0"] = 160] = "CONTEXT_SPECIFIC0";
|
|
494
|
+
TagType3[TagType3["CONTEXT_SPECIFIC1"] = 161] = "CONTEXT_SPECIFIC1";
|
|
495
|
+
TagType3[TagType3["CONTEXT_SPECIFIC2"] = 162] = "CONTEXT_SPECIFIC2";
|
|
496
|
+
TagType3[TagType3["CONTEXT_SPECIFIC3"] = 163] = "CONTEXT_SPECIFIC3";
|
|
497
|
+
TagType3[TagType3["A4"] = 164] = "A4";
|
|
492
498
|
return TagType3;
|
|
493
499
|
})(TagType || {});
|
|
494
500
|
function readTag(buf, pos) {
|
|
495
|
-
|
|
496
|
-
(0, import_assert.default)(Number.isFinite(pos) && pos >= 0);
|
|
501
|
+
const start = pos;
|
|
497
502
|
if (buf.length <= pos) {
|
|
498
503
|
throw new Error("Invalid position : buf.length=" + buf.length + " pos =" + pos);
|
|
499
504
|
}
|
|
@@ -509,7 +514,7 @@ function readTag(buf, pos) {
|
|
|
509
514
|
pos += 1;
|
|
510
515
|
}
|
|
511
516
|
}
|
|
512
|
-
return { tag, position: pos, length };
|
|
517
|
+
return { start, tag, position: pos, length };
|
|
513
518
|
}
|
|
514
519
|
function _readStruct(buf, blockInfo) {
|
|
515
520
|
const length = blockInfo.length;
|
|
@@ -574,8 +579,8 @@ function _readIntegerAsByteString(buffer, block) {
|
|
|
574
579
|
function _readListOfInteger(buffer) {
|
|
575
580
|
const block = readTag(buffer, 0);
|
|
576
581
|
const inner_blocks = _readStruct(buffer, block);
|
|
577
|
-
return inner_blocks.map((
|
|
578
|
-
return _readIntegerAsByteString(buffer,
|
|
582
|
+
return inner_blocks.map((innerBlock) => {
|
|
583
|
+
return _readIntegerAsByteString(buffer, innerBlock);
|
|
579
584
|
});
|
|
580
585
|
}
|
|
581
586
|
function parseOID(buffer, start, end) {
|
|
@@ -838,7 +843,8 @@ function _readGeneralNames(buffer, block) {
|
|
|
838
843
|
5: { name: "ediPartyName", type: "EDIPartyName" },
|
|
839
844
|
6: { name: "uniformResourceIdentifier", type: "IA5String" },
|
|
840
845
|
7: { name: "iPAddress", type: "OCTET_STRING" },
|
|
841
|
-
8: { name: "registeredID", type: "OBJECT_IDENTIFIER" }
|
|
846
|
+
8: { name: "registeredID", type: "OBJECT_IDENTIFIER" },
|
|
847
|
+
32: { name: "otherName", type: "AnotherName" }
|
|
842
848
|
};
|
|
843
849
|
const blocks = _readStruct(buffer, block);
|
|
844
850
|
function _readFromType(buffer2, block2, type) {
|
|
@@ -852,13 +858,28 @@ function _readGeneralNames(buffer, block) {
|
|
|
852
858
|
const n = {};
|
|
853
859
|
for (const block2 of blocks) {
|
|
854
860
|
(0, import_assert2.default)((block2.tag & 128) === 128);
|
|
855
|
-
const
|
|
856
|
-
const type = _data[
|
|
861
|
+
const t2 = block2.tag & 127;
|
|
862
|
+
const type = _data[t2];
|
|
857
863
|
if (!type) {
|
|
858
|
-
|
|
864
|
+
console.log("_readGeneralNames: INVALID TYPE => " + t2 + " 0x" + t2.toString(16));
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
if (t2 == 32) {
|
|
868
|
+
n[type.name] = n[type.name] || [];
|
|
869
|
+
const blocks2 = _readStruct(buffer, block2);
|
|
870
|
+
const name = _readObjectIdentifier(buffer, blocks2[0]).name;
|
|
871
|
+
const buf = _getBlock(buffer, blocks2[1]);
|
|
872
|
+
const b = readTag(buf, 0);
|
|
873
|
+
const nn = _readValue(buf, b);
|
|
874
|
+
const data = {
|
|
875
|
+
identifier: name,
|
|
876
|
+
value: nn
|
|
877
|
+
};
|
|
878
|
+
n[type.name].push(data.value);
|
|
879
|
+
} else {
|
|
880
|
+
n[type.name] = n[type.name] || [];
|
|
881
|
+
n[type.name].push(_readFromType(buffer, block2, type.type));
|
|
859
882
|
}
|
|
860
|
-
n[type.name] = n[type.name] || [];
|
|
861
|
-
n[type.name].push(_readFromType(buffer, block2, type.type));
|
|
862
883
|
}
|
|
863
884
|
return n;
|
|
864
885
|
}
|
|
@@ -1744,19 +1765,20 @@ var x509 = __toESM(require("@peculiar/x509"));
|
|
|
1744
1765
|
var import_webcrypto = require("@peculiar/webcrypto");
|
|
1745
1766
|
var import_crypto5 = __toESM(require("crypto"));
|
|
1746
1767
|
var x5092 = __toESM(require("@peculiar/x509"));
|
|
1768
|
+
var doDebug3 = false;
|
|
1747
1769
|
var _crypto;
|
|
1748
1770
|
var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
|
|
1749
1771
|
if (typeof window === "undefined") {
|
|
1750
1772
|
_crypto = import_crypto5.default;
|
|
1751
1773
|
if (!_crypto?.subtle || ignoreCrypto) {
|
|
1752
1774
|
_crypto = new import_webcrypto.Crypto();
|
|
1753
|
-
console.warn("using @peculiar/webcrypto");
|
|
1775
|
+
doDebug3 && console.warn("using @peculiar/webcrypto");
|
|
1754
1776
|
} else {
|
|
1755
|
-
console.warn("using nodejs crypto (native)");
|
|
1777
|
+
doDebug3 && console.warn("using nodejs crypto (native)");
|
|
1756
1778
|
}
|
|
1757
1779
|
x509.cryptoProvider.set(_crypto);
|
|
1758
1780
|
} else {
|
|
1759
|
-
console.warn("using browser crypto (native)");
|
|
1781
|
+
doDebug3 && console.warn("using browser crypto (native)");
|
|
1760
1782
|
_crypto = crypto;
|
|
1761
1783
|
x509.cryptoProvider.set(crypto);
|
|
1762
1784
|
}
|
|
@@ -1894,8 +1916,8 @@ var Subject = class _Subject {
|
|
|
1894
1916
|
return this.toStringInternal("/");
|
|
1895
1917
|
}
|
|
1896
1918
|
toString() {
|
|
1897
|
-
const
|
|
1898
|
-
return
|
|
1919
|
+
const t2 = this.toStringForOPCUA();
|
|
1920
|
+
return t2 ? "/" + t2 : t2;
|
|
1899
1921
|
}
|
|
1900
1922
|
};
|
|
1901
1923
|
|
|
@@ -6166,7 +6188,7 @@ async function createSelfSignedCertificate({
|
|
|
6166
6188
|
|
|
6167
6189
|
// source/x509/coerce_private_key.ts
|
|
6168
6190
|
var crypto2 = getCrypto();
|
|
6169
|
-
var
|
|
6191
|
+
var doDebug4 = false;
|
|
6170
6192
|
function coercePEMorDerToPrivateKey(privateKeyInDerOrPem) {
|
|
6171
6193
|
if (typeof privateKeyInDerOrPem === "string") {
|
|
6172
6194
|
const hidden = createPrivateKeyFromNodeJSCrypto(privateKeyInDerOrPem);
|
|
@@ -6184,7 +6206,7 @@ async function _coercePrivateKey(privateKey) {
|
|
|
6184
6206
|
const privateKey1 = await pemToPrivateKey(privateKey);
|
|
6185
6207
|
return KeyObject4.from(privateKey1);
|
|
6186
6208
|
} catch (err) {
|
|
6187
|
-
|
|
6209
|
+
doDebug4 && console.log(privateKey);
|
|
6188
6210
|
throw err;
|
|
6189
6211
|
}
|
|
6190
6212
|
} else if (privateKey instanceof KeyObject4) {
|
|
@@ -6193,6 +6215,33 @@ async function _coercePrivateKey(privateKey) {
|
|
|
6193
6215
|
throw new Error("Invalid privateKey");
|
|
6194
6216
|
}
|
|
6195
6217
|
|
|
6218
|
+
// source/explore_asn1.ts
|
|
6219
|
+
function t(tag) {
|
|
6220
|
+
return TagType[tag];
|
|
6221
|
+
}
|
|
6222
|
+
function bi(blockInfo, depth) {
|
|
6223
|
+
const indent = " ".repeat(depth);
|
|
6224
|
+
const hl = blockInfo.position - blockInfo.start;
|
|
6225
|
+
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)}`;
|
|
6226
|
+
}
|
|
6227
|
+
function exploreAsn1(buffer) {
|
|
6228
|
+
console.log(hexDump(buffer));
|
|
6229
|
+
function dump(offset, depth) {
|
|
6230
|
+
const blockInfo = readTag(buffer, offset);
|
|
6231
|
+
dumpBlock(blockInfo, depth);
|
|
6232
|
+
function dumpBlock(blockInfo2, depth2) {
|
|
6233
|
+
console.log(bi(blockInfo2, depth2));
|
|
6234
|
+
if (blockInfo2.tag === 48 /* SEQUENCE */ || blockInfo2.tag === 49 /* SET */ || blockInfo2.tag >= 160 /* CONTEXT_SPECIFIC0 */) {
|
|
6235
|
+
const blocks = _readStruct(buffer, blockInfo2);
|
|
6236
|
+
for (const block of blocks) {
|
|
6237
|
+
dumpBlock(block, depth2 + 1);
|
|
6238
|
+
}
|
|
6239
|
+
}
|
|
6240
|
+
}
|
|
6241
|
+
}
|
|
6242
|
+
dump(0, 0);
|
|
6243
|
+
}
|
|
6244
|
+
|
|
6196
6245
|
// source/make_private_key_from_pem.ts
|
|
6197
6246
|
function makePrivateKeyFromPem(privateKeyInPem) {
|
|
6198
6247
|
return { hidden: privateKeyInPem };
|
|
@@ -6244,6 +6293,7 @@ function makePrivateKeyFromPem(privateKeyInPem) {
|
|
|
6244
6293
|
decryptBufferWithDerivedKeys,
|
|
6245
6294
|
derToPrivateKey,
|
|
6246
6295
|
encryptBufferWithDerivedKeys,
|
|
6296
|
+
exploreAsn1,
|
|
6247
6297
|
exploreCertificate,
|
|
6248
6298
|
exploreCertificateInfo,
|
|
6249
6299
|
exploreCertificateRevocationList,
|