node-opcua-crypto 5.1.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-7GWSCCWS.cjs +208 -0
- package/dist/chunk-7GWSCCWS.cjs.map +1 -0
- package/dist/{source/index.js → chunk-ERHE4VFS.cjs} +466 -484
- package/dist/chunk-ERHE4VFS.cjs.map +1 -0
- package/dist/{chunk-ULG5CYBT.mjs → chunk-KCVNMSLI.js} +330 -252
- package/dist/chunk-KCVNMSLI.js.map +1 -0
- package/dist/{chunk-UXPULF3W.mjs → chunk-QGNXSXUU.js} +42 -2
- package/dist/chunk-QGNXSXUU.js.map +1 -0
- package/dist/index.cjs +197 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +108 -6673
- package/dist/index.js.map +1 -1
- package/dist/source/index_web.cjs +155 -0
- package/dist/source/index_web.cjs.map +1 -0
- package/dist/source/{index_web.d.mts → index_web.d.cts} +184 -159
- package/dist/source/index_web.d.ts +183 -158
- package/dist/source/index_web.js +80 -6517
- package/dist/source/index_web.js.map +1 -1
- package/dist/source_nodejs/index.cjs +46 -0
- package/dist/source_nodejs/index.cjs.map +1 -0
- package/dist/source_nodejs/{index.d.mts → index.d.cts} +29 -2
- package/dist/source_nodejs/index.d.ts +28 -1
- package/dist/source_nodejs/index.js +31 -4141
- package/dist/source_nodejs/index.js.map +1 -1
- package/package.json +35 -16
- package/dist/chunk-RQA4DO2Z.mjs +0 -1
- package/dist/chunk-RQA4DO2Z.mjs.map +0 -1
- package/dist/chunk-ULG5CYBT.mjs.map +0 -1
- package/dist/chunk-UXPULF3W.mjs.map +0 -1
- package/dist/index.d.mts +0 -5
- package/dist/index.mjs +0 -184
- package/dist/index.mjs.map +0 -1
- package/dist/source/index.d.mts +0 -4
- package/dist/source/index.d.ts +0 -4
- package/dist/source/index.js.map +0 -1
- package/dist/source/index.mjs +0 -154
- package/dist/source/index.mjs.map +0 -1
- package/dist/source/index_web.mjs +0 -153
- package/dist/source/index_web.mjs.map +0 -1
- package/dist/source_nodejs/index.mjs +0 -35
- package/dist/source_nodejs/index.mjs.map +0 -1
- /package/dist/{common-DxHkx4Pv.d.mts → common-DxHkx4Pv.d.cts} +0 -0
|
@@ -1353,79 +1353,40 @@ function verifyCrlIssuedByCertificate(crl, certificate) {
|
|
|
1353
1353
|
return verifyCertificateRevocationListSignature(crl, certificate);
|
|
1354
1354
|
}
|
|
1355
1355
|
|
|
1356
|
-
// source/
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
function rsaLengthPrivateKey(key) {
|
|
1360
|
-
const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
|
|
1361
|
-
const keyObject = createPrivateKey(keyPem);
|
|
1362
|
-
const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
|
|
1363
|
-
assert5(modulusLength, "Cannot determine modulus length from private key");
|
|
1364
|
-
return modulusLength / 8;
|
|
1365
|
-
}
|
|
1366
|
-
function toPem2(raw_key, pem) {
|
|
1367
|
-
if (raw_key.hidden) {
|
|
1368
|
-
return toPem2(raw_key.hidden, pem);
|
|
1369
|
-
}
|
|
1370
|
-
assert5(raw_key, "expecting a key");
|
|
1371
|
-
assert5(typeof pem === "string");
|
|
1372
|
-
if (isKeyObject(raw_key)) {
|
|
1373
|
-
const _raw_key = raw_key;
|
|
1374
|
-
if (pem === "RSA PRIVATE KEY") {
|
|
1375
|
-
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs1" }).toString());
|
|
1376
|
-
} else if (pem === "PRIVATE KEY") {
|
|
1377
|
-
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs8" }).toString());
|
|
1378
|
-
} else {
|
|
1379
|
-
throw new Error("Unsupported case!");
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
return toPem(raw_key, pem);
|
|
1383
|
-
}
|
|
1384
|
-
function coercePrivateKeyPem(privateKey) {
|
|
1385
|
-
return toPem2(privateKey, "PRIVATE KEY");
|
|
1356
|
+
// source/explore_asn1.ts
|
|
1357
|
+
function t(tag) {
|
|
1358
|
+
return TagType[tag];
|
|
1386
1359
|
}
|
|
1387
|
-
function
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
}
|
|
1391
|
-
assert5(typeof publicKey === "string");
|
|
1392
|
-
return publicKey;
|
|
1360
|
+
function bi(blockInfo, depth) {
|
|
1361
|
+
const indent = " ".repeat(depth);
|
|
1362
|
+
const hl = blockInfo.position - blockInfo.start;
|
|
1363
|
+
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)}`;
|
|
1393
1364
|
}
|
|
1394
|
-
function
|
|
1395
|
-
|
|
1396
|
-
|
|
1365
|
+
function exploreAsn1(buffer) {
|
|
1366
|
+
console.log(hexDump(buffer));
|
|
1367
|
+
function dump(offset, depth) {
|
|
1368
|
+
const blockInfo = readTag(buffer, offset);
|
|
1369
|
+
dumpBlock(blockInfo, depth);
|
|
1370
|
+
function dumpBlock(blockInfo2, depth2) {
|
|
1371
|
+
console.log(bi(blockInfo2, depth2));
|
|
1372
|
+
if (blockInfo2.tag === 48 /* SEQUENCE */ || blockInfo2.tag === 49 /* SET */ || blockInfo2.tag >= 160 /* CONTEXT_SPECIFIC0 */) {
|
|
1373
|
+
const blocks = readStruct(buffer, blockInfo2);
|
|
1374
|
+
for (const block of blocks) {
|
|
1375
|
+
dumpBlock(block, depth2 + 1);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1397
1379
|
}
|
|
1398
|
-
|
|
1399
|
-
return publicKey;
|
|
1400
|
-
}
|
|
1401
|
-
function rsaLengthPublicKey(key) {
|
|
1402
|
-
key = coercePublicKeyPem(key);
|
|
1403
|
-
assert5(typeof key === "string");
|
|
1404
|
-
const keyObject = createPublicKey2(key);
|
|
1405
|
-
const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
|
|
1406
|
-
assert5(modulusLength, "Cannot determine modulus length from public key");
|
|
1407
|
-
return modulusLength / 8;
|
|
1408
|
-
}
|
|
1409
|
-
function rsaLengthRsaPublicKey(key) {
|
|
1410
|
-
key = coerceRsaPublicKeyPem(key);
|
|
1411
|
-
assert5(typeof key === "string");
|
|
1412
|
-
const keyObject = createPublicKey2(key);
|
|
1413
|
-
const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
|
|
1414
|
-
assert5(modulusLength, "Cannot determine modulus length from public key");
|
|
1415
|
-
return modulusLength / 8;
|
|
1380
|
+
dump(0, 0);
|
|
1416
1381
|
}
|
|
1417
1382
|
|
|
1418
|
-
// source/derived_keys.ts
|
|
1419
|
-
import assert7 from "assert";
|
|
1420
|
-
import { createCipheriv, createDecipheriv, createHmac } from "crypto";
|
|
1421
|
-
|
|
1422
1383
|
// source/explore_certificate.ts
|
|
1423
|
-
import
|
|
1384
|
+
import assert5 from "assert";
|
|
1424
1385
|
function coerceCertificate(certificate) {
|
|
1425
1386
|
if (typeof certificate === "string") {
|
|
1426
1387
|
certificate = convertPEMtoDER(certificate);
|
|
1427
1388
|
}
|
|
1428
|
-
|
|
1389
|
+
assert5(Buffer.isBuffer(certificate));
|
|
1429
1390
|
return certificate;
|
|
1430
1391
|
}
|
|
1431
1392
|
function exploreCertificateInfo(certificate) {
|
|
@@ -1444,146 +1405,6 @@ function exploreCertificateInfo(certificate) {
|
|
|
1444
1405
|
return data;
|
|
1445
1406
|
}
|
|
1446
1407
|
|
|
1447
|
-
// source/derived_keys.ts
|
|
1448
|
-
function HMAC_HASH(sha1or256, secret, message) {
|
|
1449
|
-
return createHmac(sha1or256, secret).update(message).digest();
|
|
1450
|
-
}
|
|
1451
|
-
function plus(buf1, buf2) {
|
|
1452
|
-
return Buffer.concat([buf1, buf2]);
|
|
1453
|
-
}
|
|
1454
|
-
function makePseudoRandomBuffer(secret, seed, minLength, sha1or256) {
|
|
1455
|
-
assert7(Buffer.isBuffer(seed));
|
|
1456
|
-
assert7(sha1or256 === "SHA1" || sha1or256 === "SHA256");
|
|
1457
|
-
const a = [];
|
|
1458
|
-
a[0] = seed;
|
|
1459
|
-
let index = 1;
|
|
1460
|
-
let p_hash = createFastUninitializedBuffer(0);
|
|
1461
|
-
while (p_hash.length <= minLength) {
|
|
1462
|
-
a[index] = HMAC_HASH(sha1or256, secret, a[index - 1]);
|
|
1463
|
-
p_hash = plus(p_hash, HMAC_HASH(sha1or256, secret, plus(a[index], seed)));
|
|
1464
|
-
index += 1;
|
|
1465
|
-
}
|
|
1466
|
-
return p_hash.subarray(0, minLength);
|
|
1467
|
-
}
|
|
1468
|
-
function computeDerivedKeys(secret, seed, options) {
|
|
1469
|
-
assert7(Number.isFinite(options.signatureLength));
|
|
1470
|
-
assert7(Number.isFinite(options.encryptingKeyLength));
|
|
1471
|
-
assert7(Number.isFinite(options.encryptingBlockSize));
|
|
1472
|
-
assert7(typeof options.algorithm === "string");
|
|
1473
|
-
options.sha1or256 = options.sha1or256 || "SHA1";
|
|
1474
|
-
assert7(typeof options.sha1or256 === "string");
|
|
1475
|
-
const offset1 = options.signingKeyLength;
|
|
1476
|
-
const offset2 = offset1 + options.encryptingKeyLength;
|
|
1477
|
-
const minLength = offset2 + options.encryptingBlockSize;
|
|
1478
|
-
const buf = makePseudoRandomBuffer(secret, seed, minLength, options.sha1or256);
|
|
1479
|
-
return {
|
|
1480
|
-
signatureLength: options.signatureLength,
|
|
1481
|
-
signingKeyLength: options.signingKeyLength,
|
|
1482
|
-
encryptingKeyLength: options.encryptingKeyLength,
|
|
1483
|
-
encryptingBlockSize: options.encryptingBlockSize,
|
|
1484
|
-
algorithm: options.algorithm,
|
|
1485
|
-
sha1or256: options.sha1or256,
|
|
1486
|
-
signingKey: buf.subarray(0, offset1),
|
|
1487
|
-
encryptingKey: buf.subarray(offset1, offset2),
|
|
1488
|
-
initializationVector: buf.subarray(offset2, minLength)
|
|
1489
|
-
};
|
|
1490
|
-
}
|
|
1491
|
-
function reduceLength(buffer, byteToRemove) {
|
|
1492
|
-
return buffer.subarray(0, buffer.length - byteToRemove);
|
|
1493
|
-
}
|
|
1494
|
-
function removePadding(buffer) {
|
|
1495
|
-
const nbPaddingBytes = buffer.readUInt8(buffer.length - 1) + 1;
|
|
1496
|
-
return reduceLength(buffer, nbPaddingBytes);
|
|
1497
|
-
}
|
|
1498
|
-
function verifyChunkSignature(chunk, options) {
|
|
1499
|
-
assert7(Buffer.isBuffer(chunk));
|
|
1500
|
-
let signatureLength = options.signatureLength || 0;
|
|
1501
|
-
if (signatureLength === 0) {
|
|
1502
|
-
const cert = exploreCertificateInfo(options.publicKey);
|
|
1503
|
-
signatureLength = cert.publicKeyLength || 0;
|
|
1504
|
-
}
|
|
1505
|
-
const block_to_verify = chunk.subarray(0, chunk.length - signatureLength);
|
|
1506
|
-
const signature = chunk.subarray(chunk.length - signatureLength);
|
|
1507
|
-
return verifyMessageChunkSignature(block_to_verify, signature, options);
|
|
1508
|
-
}
|
|
1509
|
-
function computePaddingFooter(buffer, derivedKeys) {
|
|
1510
|
-
assert7(Object.hasOwn(derivedKeys, "encryptingBlockSize"));
|
|
1511
|
-
const paddingSize = derivedKeys.encryptingBlockSize - (buffer.length + 1) % derivedKeys.encryptingBlockSize;
|
|
1512
|
-
const padding = createFastUninitializedBuffer(paddingSize + 1);
|
|
1513
|
-
padding.fill(paddingSize);
|
|
1514
|
-
return padding;
|
|
1515
|
-
}
|
|
1516
|
-
function derivedKeys_algorithm(derivedKeys) {
|
|
1517
|
-
assert7(Object.hasOwn(derivedKeys, "algorithm"));
|
|
1518
|
-
const algorithm = derivedKeys.algorithm || "aes-128-cbc";
|
|
1519
|
-
assert7(algorithm === "aes-128-cbc" || algorithm === "aes-256-cbc");
|
|
1520
|
-
return algorithm;
|
|
1521
|
-
}
|
|
1522
|
-
function encryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
1523
|
-
const algorithm = derivedKeys_algorithm(derivedKeys);
|
|
1524
|
-
const key = derivedKeys.encryptingKey;
|
|
1525
|
-
const initVector = derivedKeys.initializationVector;
|
|
1526
|
-
const cipher = createCipheriv(algorithm, key, initVector);
|
|
1527
|
-
cipher.setAutoPadding(false);
|
|
1528
|
-
const encrypted_chunks = [];
|
|
1529
|
-
encrypted_chunks.push(cipher.update(buffer));
|
|
1530
|
-
encrypted_chunks.push(cipher.final());
|
|
1531
|
-
return Buffer.concat(encrypted_chunks);
|
|
1532
|
-
}
|
|
1533
|
-
function decryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
1534
|
-
const algorithm = derivedKeys_algorithm(derivedKeys);
|
|
1535
|
-
const key = derivedKeys.encryptingKey;
|
|
1536
|
-
const initVector = derivedKeys.initializationVector;
|
|
1537
|
-
const cipher = createDecipheriv(algorithm, key, initVector);
|
|
1538
|
-
cipher.setAutoPadding(false);
|
|
1539
|
-
const decrypted_chunks = [];
|
|
1540
|
-
decrypted_chunks.push(cipher.update(buffer));
|
|
1541
|
-
decrypted_chunks.push(cipher.final());
|
|
1542
|
-
return Buffer.concat(decrypted_chunks);
|
|
1543
|
-
}
|
|
1544
|
-
function makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys) {
|
|
1545
|
-
assert7(Buffer.isBuffer(message));
|
|
1546
|
-
assert7(Buffer.isBuffer(derivedKeys.signingKey));
|
|
1547
|
-
assert7(typeof derivedKeys.sha1or256 === "string");
|
|
1548
|
-
assert7(derivedKeys.sha1or256 === "SHA1" || derivedKeys.sha1or256 === "SHA256");
|
|
1549
|
-
const signature = createHmac(derivedKeys.sha1or256, derivedKeys.signingKey).update(message).digest();
|
|
1550
|
-
assert7(signature.length === derivedKeys.signatureLength);
|
|
1551
|
-
return signature;
|
|
1552
|
-
}
|
|
1553
|
-
function verifyChunkSignatureWithDerivedKeys(chunk, derivedKeys) {
|
|
1554
|
-
const message = chunk.subarray(0, chunk.length - derivedKeys.signatureLength);
|
|
1555
|
-
const expectedSignature = chunk.subarray(chunk.length - derivedKeys.signatureLength);
|
|
1556
|
-
const computedSignature = makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys);
|
|
1557
|
-
return computedSignature.toString("hex") === expectedSignature.toString("hex");
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
// source/explore_asn1.ts
|
|
1561
|
-
function t(tag) {
|
|
1562
|
-
return TagType[tag];
|
|
1563
|
-
}
|
|
1564
|
-
function bi(blockInfo, depth) {
|
|
1565
|
-
const indent = " ".repeat(depth);
|
|
1566
|
-
const hl = blockInfo.position - blockInfo.start;
|
|
1567
|
-
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)}`;
|
|
1568
|
-
}
|
|
1569
|
-
function exploreAsn1(buffer) {
|
|
1570
|
-
console.log(hexDump(buffer));
|
|
1571
|
-
function dump(offset, depth) {
|
|
1572
|
-
const blockInfo = readTag(buffer, offset);
|
|
1573
|
-
dumpBlock(blockInfo, depth);
|
|
1574
|
-
function dumpBlock(blockInfo2, depth2) {
|
|
1575
|
-
console.log(bi(blockInfo2, depth2));
|
|
1576
|
-
if (blockInfo2.tag === 48 /* SEQUENCE */ || blockInfo2.tag === 49 /* SET */ || blockInfo2.tag >= 160 /* CONTEXT_SPECIFIC0 */) {
|
|
1577
|
-
const blocks = readStruct(buffer, blockInfo2);
|
|
1578
|
-
for (const block of blocks) {
|
|
1579
|
-
dumpBlock(block, depth2 + 1);
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
dump(0, 0);
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
1408
|
// source/explore_certificate_signing_request.ts
|
|
1588
1409
|
function _readExtensionRequest(buffer) {
|
|
1589
1410
|
const block = readTag(buffer, 0);
|
|
@@ -1709,39 +1530,76 @@ function explorePrivateKey(privateKey2) {
|
|
|
1709
1530
|
};
|
|
1710
1531
|
}
|
|
1711
1532
|
|
|
1712
|
-
// source/
|
|
1713
|
-
function
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1533
|
+
// source/identify_der.ts
|
|
1534
|
+
function identifyDERContent(buffer) {
|
|
1535
|
+
if (!Buffer.isBuffer(buffer) || buffer.length < 2) {
|
|
1536
|
+
return "Unknown";
|
|
1537
|
+
}
|
|
1538
|
+
try {
|
|
1539
|
+
const outer = readTag(buffer, 0);
|
|
1540
|
+
if (outer.tag !== 48 /* SEQUENCE */) {
|
|
1541
|
+
return "Unknown";
|
|
1542
|
+
}
|
|
1543
|
+
const outerEnd = outer.position + outer.length;
|
|
1544
|
+
if (outerEnd < buffer.length) {
|
|
1545
|
+
const next = readTag(buffer, outerEnd);
|
|
1546
|
+
if (next.tag === 48 /* SEQUENCE */) {
|
|
1547
|
+
return "X509CertificateChain";
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
const blocks = readStruct(buffer, outer);
|
|
1551
|
+
if (blocks.length < 2) {
|
|
1552
|
+
return "Unknown";
|
|
1553
|
+
}
|
|
1554
|
+
if (blocks[0].tag === 2 /* INTEGER */) {
|
|
1555
|
+
const versionByte = buffer[blocks[0].position];
|
|
1556
|
+
if (blocks[0].length === 1 && versionByte === 3) {
|
|
1557
|
+
return "PKCS12";
|
|
1558
|
+
}
|
|
1559
|
+
if (blocks[0].length === 1 && versionByte === 0) {
|
|
1560
|
+
return "PrivateKey";
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
if (blocks[0].tag !== 48 /* SEQUENCE */) {
|
|
1564
|
+
return "Unknown";
|
|
1565
|
+
}
|
|
1566
|
+
const tbsBlocks = readStruct(buffer, blocks[0]);
|
|
1567
|
+
if (tbsBlocks.length === 0) {
|
|
1568
|
+
return "Unknown";
|
|
1569
|
+
}
|
|
1570
|
+
if (tbsBlocks[0].tag === 160 /* CONTEXT_SPECIFIC0 */) {
|
|
1571
|
+
return "X509Certificate";
|
|
1572
|
+
}
|
|
1573
|
+
if (tbsBlocks[0].tag === 2 /* INTEGER */) {
|
|
1574
|
+
const intLen = tbsBlocks[0].length;
|
|
1575
|
+
const intVal = intLen === 1 ? buffer[tbsBlocks[0].position] : -1;
|
|
1576
|
+
if (intVal === 0 && tbsBlocks.length >= 4) {
|
|
1577
|
+
if (tbsBlocks[3].tag === 160 /* CONTEXT_SPECIFIC0 */) {
|
|
1578
|
+
return "CertificateSigningRequest";
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
if (intVal === 1 && tbsBlocks.length >= 4) {
|
|
1582
|
+
const tag3 = tbsBlocks[3].tag;
|
|
1583
|
+
if (tag3 === 23 /* UTCTime */ || tag3 === 24 /* GeneralizedTime */) {
|
|
1584
|
+
return "CertificateRevocationList";
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
if (tbsBlocks.length >= 6) {
|
|
1588
|
+
if (tbsBlocks[3].tag === 48 /* SEQUENCE */) {
|
|
1589
|
+
return "X509Certificate";
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
if (tbsBlocks[0].tag === 48 /* SEQUENCE */ && tbsBlocks.length >= 3) {
|
|
1594
|
+
const tag2 = tbsBlocks[2].tag;
|
|
1595
|
+
if (tag2 === 23 /* UTCTime */ || tag2 === 24 /* GeneralizedTime */) {
|
|
1596
|
+
return "CertificateRevocationList";
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
return "Unknown";
|
|
1600
|
+
} catch {
|
|
1601
|
+
return "Unknown";
|
|
1730
1602
|
}
|
|
1731
|
-
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
1732
|
-
}
|
|
1733
|
-
function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
1734
|
-
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
1735
|
-
const encryptedBuffer = publicEncrypt_long(initialBuffer, certificate, blockSize);
|
|
1736
|
-
const decryptedBuffer = privateDecrypt_long(encryptedBuffer, privateKey, blockSize);
|
|
1737
|
-
const finalString = decryptedBuffer.toString("utf-8");
|
|
1738
|
-
return initialBuffer.toString("utf-8") === finalString;
|
|
1739
|
-
}
|
|
1740
|
-
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
1741
|
-
const e = explorePrivateKey(privateKey);
|
|
1742
|
-
const blockSize = e.modulus.length;
|
|
1743
|
-
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
1744
|
-
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
1745
1603
|
}
|
|
1746
1604
|
|
|
1747
1605
|
// source/subject.ts
|
|
@@ -1765,6 +1623,13 @@ var unquote2 = (str) => {
|
|
|
1765
1623
|
return m ? m[1] : str;
|
|
1766
1624
|
};
|
|
1767
1625
|
var Subject = class _Subject {
|
|
1626
|
+
commonName;
|
|
1627
|
+
organization;
|
|
1628
|
+
organizationalUnit;
|
|
1629
|
+
locality;
|
|
1630
|
+
state;
|
|
1631
|
+
country;
|
|
1632
|
+
domainComponent;
|
|
1768
1633
|
constructor(options) {
|
|
1769
1634
|
if (typeof options === "string") {
|
|
1770
1635
|
options = _Subject.parse(options);
|
|
@@ -6353,6 +6218,218 @@ async function createSelfSignedCertificate({
|
|
|
6353
6218
|
return { cert: cert.toString("pem"), der: cert };
|
|
6354
6219
|
}
|
|
6355
6220
|
|
|
6221
|
+
// source/crypto_utils2.ts
|
|
6222
|
+
import assert6 from "assert";
|
|
6223
|
+
import { createPrivateKey, createPublicKey as createPublicKey2 } from "crypto";
|
|
6224
|
+
function rsaLengthPrivateKey(key) {
|
|
6225
|
+
const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
|
|
6226
|
+
const keyObject = createPrivateKey(keyPem);
|
|
6227
|
+
const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
|
|
6228
|
+
assert6(modulusLength, "Cannot determine modulus length from private key");
|
|
6229
|
+
return modulusLength / 8;
|
|
6230
|
+
}
|
|
6231
|
+
function toPem2(raw_key, pem) {
|
|
6232
|
+
if (raw_key.hidden) {
|
|
6233
|
+
return toPem2(raw_key.hidden, pem);
|
|
6234
|
+
}
|
|
6235
|
+
assert6(raw_key, "expecting a key");
|
|
6236
|
+
assert6(typeof pem === "string");
|
|
6237
|
+
if (isKeyObject(raw_key)) {
|
|
6238
|
+
const _raw_key = raw_key;
|
|
6239
|
+
if (pem === "RSA PRIVATE KEY") {
|
|
6240
|
+
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs1" }).toString());
|
|
6241
|
+
} else if (pem === "PRIVATE KEY") {
|
|
6242
|
+
return removeTrailingLF(_raw_key.export({ format: "pem", type: "pkcs8" }).toString());
|
|
6243
|
+
} else {
|
|
6244
|
+
throw new Error("Unsupported case!");
|
|
6245
|
+
}
|
|
6246
|
+
}
|
|
6247
|
+
return toPem(raw_key, pem);
|
|
6248
|
+
}
|
|
6249
|
+
function coercePrivateKeyPem(privateKey) {
|
|
6250
|
+
return toPem2(privateKey, "PRIVATE KEY");
|
|
6251
|
+
}
|
|
6252
|
+
function coercePublicKeyPem(publicKey) {
|
|
6253
|
+
if (isKeyObject(publicKey)) {
|
|
6254
|
+
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
6255
|
+
}
|
|
6256
|
+
assert6(typeof publicKey === "string");
|
|
6257
|
+
return publicKey;
|
|
6258
|
+
}
|
|
6259
|
+
function coerceRsaPublicKeyPem(publicKey) {
|
|
6260
|
+
if (isKeyObject(publicKey)) {
|
|
6261
|
+
return publicKey.export({ format: "pem", type: "spki" }).toString();
|
|
6262
|
+
}
|
|
6263
|
+
assert6(typeof publicKey === "string");
|
|
6264
|
+
return publicKey;
|
|
6265
|
+
}
|
|
6266
|
+
function rsaLengthPublicKey(key) {
|
|
6267
|
+
key = coercePublicKeyPem(key);
|
|
6268
|
+
assert6(typeof key === "string");
|
|
6269
|
+
const keyObject = createPublicKey2(key);
|
|
6270
|
+
const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
|
|
6271
|
+
assert6(modulusLength, "Cannot determine modulus length from public key");
|
|
6272
|
+
return modulusLength / 8;
|
|
6273
|
+
}
|
|
6274
|
+
function rsaLengthRsaPublicKey(key) {
|
|
6275
|
+
key = coerceRsaPublicKeyPem(key);
|
|
6276
|
+
assert6(typeof key === "string");
|
|
6277
|
+
const keyObject = createPublicKey2(key);
|
|
6278
|
+
const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
|
|
6279
|
+
assert6(modulusLength, "Cannot determine modulus length from public key");
|
|
6280
|
+
return modulusLength / 8;
|
|
6281
|
+
}
|
|
6282
|
+
|
|
6283
|
+
// source/derived_keys.ts
|
|
6284
|
+
import assert7 from "assert";
|
|
6285
|
+
import { createCipheriv, createDecipheriv, createHmac } from "crypto";
|
|
6286
|
+
function HMAC_HASH(sha1or256, secret, message) {
|
|
6287
|
+
return createHmac(sha1or256, secret).update(message).digest();
|
|
6288
|
+
}
|
|
6289
|
+
function plus(buf1, buf2) {
|
|
6290
|
+
return Buffer.concat([buf1, buf2]);
|
|
6291
|
+
}
|
|
6292
|
+
function makePseudoRandomBuffer(secret, seed, minLength, sha1or256) {
|
|
6293
|
+
assert7(Buffer.isBuffer(seed));
|
|
6294
|
+
assert7(sha1or256 === "SHA1" || sha1or256 === "SHA256");
|
|
6295
|
+
const a = [];
|
|
6296
|
+
a[0] = seed;
|
|
6297
|
+
let index = 1;
|
|
6298
|
+
let p_hash = createFastUninitializedBuffer(0);
|
|
6299
|
+
while (p_hash.length <= minLength) {
|
|
6300
|
+
a[index] = HMAC_HASH(sha1or256, secret, a[index - 1]);
|
|
6301
|
+
p_hash = plus(p_hash, HMAC_HASH(sha1or256, secret, plus(a[index], seed)));
|
|
6302
|
+
index += 1;
|
|
6303
|
+
}
|
|
6304
|
+
return p_hash.subarray(0, minLength);
|
|
6305
|
+
}
|
|
6306
|
+
function computeDerivedKeys(secret, seed, options) {
|
|
6307
|
+
assert7(Number.isFinite(options.signatureLength));
|
|
6308
|
+
assert7(Number.isFinite(options.encryptingKeyLength));
|
|
6309
|
+
assert7(Number.isFinite(options.encryptingBlockSize));
|
|
6310
|
+
assert7(typeof options.algorithm === "string");
|
|
6311
|
+
options.sha1or256 = options.sha1or256 || "SHA1";
|
|
6312
|
+
assert7(typeof options.sha1or256 === "string");
|
|
6313
|
+
const offset1 = options.signingKeyLength;
|
|
6314
|
+
const offset2 = offset1 + options.encryptingKeyLength;
|
|
6315
|
+
const minLength = offset2 + options.encryptingBlockSize;
|
|
6316
|
+
const buf = makePseudoRandomBuffer(secret, seed, minLength, options.sha1or256);
|
|
6317
|
+
return {
|
|
6318
|
+
signatureLength: options.signatureLength,
|
|
6319
|
+
signingKeyLength: options.signingKeyLength,
|
|
6320
|
+
encryptingKeyLength: options.encryptingKeyLength,
|
|
6321
|
+
encryptingBlockSize: options.encryptingBlockSize,
|
|
6322
|
+
algorithm: options.algorithm,
|
|
6323
|
+
sha1or256: options.sha1or256,
|
|
6324
|
+
signingKey: buf.subarray(0, offset1),
|
|
6325
|
+
encryptingKey: buf.subarray(offset1, offset2),
|
|
6326
|
+
initializationVector: buf.subarray(offset2, minLength)
|
|
6327
|
+
};
|
|
6328
|
+
}
|
|
6329
|
+
function reduceLength(buffer, byteToRemove) {
|
|
6330
|
+
return buffer.subarray(0, buffer.length - byteToRemove);
|
|
6331
|
+
}
|
|
6332
|
+
function removePadding(buffer) {
|
|
6333
|
+
const nbPaddingBytes = buffer.readUInt8(buffer.length - 1) + 1;
|
|
6334
|
+
return reduceLength(buffer, nbPaddingBytes);
|
|
6335
|
+
}
|
|
6336
|
+
function verifyChunkSignature(chunk, options) {
|
|
6337
|
+
assert7(Buffer.isBuffer(chunk));
|
|
6338
|
+
let signatureLength = options.signatureLength || 0;
|
|
6339
|
+
if (signatureLength === 0) {
|
|
6340
|
+
const cert = exploreCertificateInfo(options.publicKey);
|
|
6341
|
+
signatureLength = cert.publicKeyLength || 0;
|
|
6342
|
+
}
|
|
6343
|
+
const block_to_verify = chunk.subarray(0, chunk.length - signatureLength);
|
|
6344
|
+
const signature = chunk.subarray(chunk.length - signatureLength);
|
|
6345
|
+
return verifyMessageChunkSignature(block_to_verify, signature, options);
|
|
6346
|
+
}
|
|
6347
|
+
function computePaddingFooter(buffer, derivedKeys) {
|
|
6348
|
+
assert7(Object.hasOwn(derivedKeys, "encryptingBlockSize"));
|
|
6349
|
+
const paddingSize = derivedKeys.encryptingBlockSize - (buffer.length + 1) % derivedKeys.encryptingBlockSize;
|
|
6350
|
+
const padding = createFastUninitializedBuffer(paddingSize + 1);
|
|
6351
|
+
padding.fill(paddingSize);
|
|
6352
|
+
return padding;
|
|
6353
|
+
}
|
|
6354
|
+
function derivedKeys_algorithm(derivedKeys) {
|
|
6355
|
+
assert7(Object.hasOwn(derivedKeys, "algorithm"));
|
|
6356
|
+
const algorithm = derivedKeys.algorithm || "aes-128-cbc";
|
|
6357
|
+
assert7(algorithm === "aes-128-cbc" || algorithm === "aes-256-cbc");
|
|
6358
|
+
return algorithm;
|
|
6359
|
+
}
|
|
6360
|
+
function encryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
6361
|
+
const algorithm = derivedKeys_algorithm(derivedKeys);
|
|
6362
|
+
const key = derivedKeys.encryptingKey;
|
|
6363
|
+
const initVector = derivedKeys.initializationVector;
|
|
6364
|
+
const cipher = createCipheriv(algorithm, key, initVector);
|
|
6365
|
+
cipher.setAutoPadding(false);
|
|
6366
|
+
const encrypted_chunks = [];
|
|
6367
|
+
encrypted_chunks.push(cipher.update(buffer));
|
|
6368
|
+
encrypted_chunks.push(cipher.final());
|
|
6369
|
+
return Buffer.concat(encrypted_chunks);
|
|
6370
|
+
}
|
|
6371
|
+
function decryptBufferWithDerivedKeys(buffer, derivedKeys) {
|
|
6372
|
+
const algorithm = derivedKeys_algorithm(derivedKeys);
|
|
6373
|
+
const key = derivedKeys.encryptingKey;
|
|
6374
|
+
const initVector = derivedKeys.initializationVector;
|
|
6375
|
+
const cipher = createDecipheriv(algorithm, key, initVector);
|
|
6376
|
+
cipher.setAutoPadding(false);
|
|
6377
|
+
const decrypted_chunks = [];
|
|
6378
|
+
decrypted_chunks.push(cipher.update(buffer));
|
|
6379
|
+
decrypted_chunks.push(cipher.final());
|
|
6380
|
+
return Buffer.concat(decrypted_chunks);
|
|
6381
|
+
}
|
|
6382
|
+
function makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys) {
|
|
6383
|
+
assert7(Buffer.isBuffer(message));
|
|
6384
|
+
assert7(Buffer.isBuffer(derivedKeys.signingKey));
|
|
6385
|
+
assert7(typeof derivedKeys.sha1or256 === "string");
|
|
6386
|
+
assert7(derivedKeys.sha1or256 === "SHA1" || derivedKeys.sha1or256 === "SHA256");
|
|
6387
|
+
const signature = createHmac(derivedKeys.sha1or256, derivedKeys.signingKey).update(message).digest();
|
|
6388
|
+
assert7(signature.length === derivedKeys.signatureLength);
|
|
6389
|
+
return signature;
|
|
6390
|
+
}
|
|
6391
|
+
function verifyChunkSignatureWithDerivedKeys(chunk, derivedKeys) {
|
|
6392
|
+
const message = chunk.subarray(0, chunk.length - derivedKeys.signatureLength);
|
|
6393
|
+
const expectedSignature = chunk.subarray(chunk.length - derivedKeys.signatureLength);
|
|
6394
|
+
const computedSignature = makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys);
|
|
6395
|
+
return computedSignature.toString("hex") === expectedSignature.toString("hex");
|
|
6396
|
+
}
|
|
6397
|
+
|
|
6398
|
+
// source/make_private_key_from_pem.ts
|
|
6399
|
+
function makePrivateKeyFromPem(privateKeyInPem) {
|
|
6400
|
+
return { hidden: privateKeyInPem };
|
|
6401
|
+
}
|
|
6402
|
+
|
|
6403
|
+
// source/make_private_key_thumbprint.ts
|
|
6404
|
+
function makePrivateKeyThumbPrint(_privateKey) {
|
|
6405
|
+
return Buffer.alloc(0);
|
|
6406
|
+
}
|
|
6407
|
+
|
|
6408
|
+
// source/public_private_match.ts
|
|
6409
|
+
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
6410
|
+
const i = exploreCertificate(certificate);
|
|
6411
|
+
const j = explorePrivateKey(privateKey);
|
|
6412
|
+
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
6413
|
+
const modulus2 = j.modulus;
|
|
6414
|
+
if (modulus1.length !== modulus2.length) {
|
|
6415
|
+
return false;
|
|
6416
|
+
}
|
|
6417
|
+
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
6418
|
+
}
|
|
6419
|
+
function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
6420
|
+
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
6421
|
+
const encryptedBuffer = publicEncrypt_long(initialBuffer, certificate, blockSize);
|
|
6422
|
+
const decryptedBuffer = privateDecrypt_long(encryptedBuffer, privateKey, blockSize);
|
|
6423
|
+
const finalString = decryptedBuffer.toString("utf-8");
|
|
6424
|
+
return initialBuffer.toString("utf-8") === finalString;
|
|
6425
|
+
}
|
|
6426
|
+
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
6427
|
+
const e = explorePrivateKey(privateKey);
|
|
6428
|
+
const blockSize = e.modulus.length;
|
|
6429
|
+
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
6430
|
+
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
6431
|
+
}
|
|
6432
|
+
|
|
6356
6433
|
// source/index_web.ts
|
|
6357
6434
|
var asn1 = { readDirectoryName, readTag, readStruct, readAlgorithmIdentifier, readSignatureValueBin };
|
|
6358
6435
|
|
|
@@ -6394,6 +6471,23 @@ export {
|
|
|
6394
6471
|
verifyCertificateChain,
|
|
6395
6472
|
isCrlIssuedByCertificate,
|
|
6396
6473
|
verifyCrlIssuedByCertificate,
|
|
6474
|
+
exploreAsn1,
|
|
6475
|
+
coerceCertificate,
|
|
6476
|
+
exploreCertificateInfo,
|
|
6477
|
+
readCertificationRequestInfo,
|
|
6478
|
+
exploreCertificateSigningRequest,
|
|
6479
|
+
explorePrivateKey,
|
|
6480
|
+
identifyDERContent,
|
|
6481
|
+
Subject,
|
|
6482
|
+
generateKeyPair,
|
|
6483
|
+
generatePrivateKey,
|
|
6484
|
+
privateKeyToPEM,
|
|
6485
|
+
derToPrivateKey,
|
|
6486
|
+
pemToPrivateKey,
|
|
6487
|
+
coercePEMorDerToPrivateKey,
|
|
6488
|
+
_coercePrivateKey,
|
|
6489
|
+
createCertificateSigningRequest,
|
|
6490
|
+
createSelfSignedCertificate,
|
|
6397
6491
|
rsaLengthPrivateKey,
|
|
6398
6492
|
toPem2,
|
|
6399
6493
|
coercePrivateKeyPem,
|
|
@@ -6401,8 +6495,6 @@ export {
|
|
|
6401
6495
|
coerceRsaPublicKeyPem,
|
|
6402
6496
|
rsaLengthPublicKey,
|
|
6403
6497
|
rsaLengthRsaPublicKey,
|
|
6404
|
-
coerceCertificate,
|
|
6405
|
-
exploreCertificateInfo,
|
|
6406
6498
|
makePseudoRandomBuffer,
|
|
6407
6499
|
computeDerivedKeys,
|
|
6408
6500
|
reduceLength,
|
|
@@ -6413,24 +6505,10 @@ export {
|
|
|
6413
6505
|
decryptBufferWithDerivedKeys,
|
|
6414
6506
|
makeMessageChunkSignatureWithDerivedKeys,
|
|
6415
6507
|
verifyChunkSignatureWithDerivedKeys,
|
|
6416
|
-
exploreAsn1,
|
|
6417
|
-
readCertificationRequestInfo,
|
|
6418
|
-
exploreCertificateSigningRequest,
|
|
6419
|
-
explorePrivateKey,
|
|
6420
6508
|
makePrivateKeyFromPem,
|
|
6421
6509
|
makePrivateKeyThumbPrint,
|
|
6422
6510
|
publicKeyAndPrivateKeyMatches,
|
|
6423
6511
|
certificateMatchesPrivateKey,
|
|
6424
|
-
Subject,
|
|
6425
|
-
generateKeyPair,
|
|
6426
|
-
generatePrivateKey,
|
|
6427
|
-
privateKeyToPEM,
|
|
6428
|
-
derToPrivateKey,
|
|
6429
|
-
pemToPrivateKey,
|
|
6430
|
-
coercePEMorDerToPrivateKey,
|
|
6431
|
-
_coercePrivateKey,
|
|
6432
|
-
createCertificateSigningRequest,
|
|
6433
|
-
createSelfSignedCertificate,
|
|
6434
6512
|
asn1
|
|
6435
6513
|
};
|
|
6436
6514
|
/*! Bundled license information:
|
|
@@ -6501,4 +6579,4 @@ asn1js/build/index.es.js:
|
|
|
6501
6579
|
*
|
|
6502
6580
|
*)
|
|
6503
6581
|
*/
|
|
6504
|
-
//# sourceMappingURL=chunk-
|
|
6582
|
+
//# sourceMappingURL=chunk-KCVNMSLI.js.map
|