node-opcua-crypto 4.17.0 → 5.1.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.
@@ -36,6 +36,7 @@ import {
36
36
  generatePrivateKey,
37
37
  hexDump,
38
38
  identifyPemType,
39
+ isCrlIssuedByCertificate,
39
40
  isKeyObject,
40
41
  makeMessageChunkSignature,
41
42
  makeMessageChunkSignatureWithDerivedKeys,
@@ -71,8 +72,9 @@ import {
71
72
  verifyCertificateSignature,
72
73
  verifyChunkSignature,
73
74
  verifyChunkSignatureWithDerivedKeys,
75
+ verifyCrlIssuedByCertificate,
74
76
  verifyMessageChunkSignature
75
- } from "../chunk-EURHGMEG.mjs";
77
+ } from "../chunk-ULG5CYBT.mjs";
76
78
  export {
77
79
  CertificatePurpose,
78
80
  PaddingAlgorithm,
@@ -110,6 +112,7 @@ export {
110
112
  generatePrivateKey,
111
113
  hexDump,
112
114
  identifyPemType,
115
+ isCrlIssuedByCertificate,
113
116
  isKeyObject,
114
117
  makeMessageChunkSignature,
115
118
  makeMessageChunkSignatureWithDerivedKeys,
@@ -145,6 +148,7 @@ export {
145
148
  verifyCertificateSignature,
146
149
  verifyChunkSignature,
147
150
  verifyChunkSignatureWithDerivedKeys,
151
+ verifyCrlIssuedByCertificate,
148
152
  verifyMessageChunkSignature
149
153
  };
150
154
  //# sourceMappingURL=index.mjs.map
@@ -1,8 +1,36 @@
1
- import { C as Certificate, d as CertificatePEM, b as PEM, D as DER, P as PrivateKey, f as PublicKeyPEM, S as Signature, K as KeyObject, e as PrivateKeyPEM, a as PublicKey, N as Nonce, g as CertificateRevocationList, h as CertificatePurpose } from '../common-DxHkx4Pv.mjs';
1
+ import { g as CertificateRevocationList, C as Certificate, d as CertificatePEM, b as PEM, D as DER, P as PrivateKey, f as PublicKeyPEM, S as Signature, K as KeyObject, e as PrivateKeyPEM, a as PublicKey, N as Nonce, h as CertificatePurpose } from '../common-DxHkx4Pv.mjs';
2
2
  export { c as createPrivateKeyFromNodeJSCrypto, i as isKeyObject } from '../common-DxHkx4Pv.mjs';
3
3
  import { KeyLike } from 'node:crypto';
4
4
  import * as x509 from '@peculiar/x509';
5
5
 
6
+ /**
7
+ * Determine if a Certificate Revocation List (CRL) was issued by
8
+ * the given certificate, by comparing the CRL's issuer name
9
+ * fingerprint with the certificate's subject name fingerprint.
10
+ *
11
+ * This is a lightweight check (no cryptographic signature
12
+ * verification). Use {@link verifyCrlIssuedByCertificate} for
13
+ * full verification.
14
+ *
15
+ * @param crl - the CRL to check (DER-encoded)
16
+ * @param certificate - the candidate issuer certificate (DER-encoded)
17
+ * @returns `true` if the CRL's issuer fingerprint matches the
18
+ * certificate's subject fingerprint
19
+ */
20
+ declare function isCrlIssuedByCertificate(crl: CertificateRevocationList, certificate: Certificate): boolean;
21
+ /**
22
+ * Verify that a Certificate Revocation List (CRL) was issued by
23
+ * the given certificate. This performs both a fingerprint match
24
+ * **and** a cryptographic signature verification.
25
+ *
26
+ * @param crl - the CRL to verify (DER-encoded)
27
+ * @param certificate - the candidate issuer certificate (DER-encoded)
28
+ * @returns `true` if the CRL's issuer matches the certificate
29
+ * **and** the CRL's signature is valid against the
30
+ * certificate's public key
31
+ */
32
+ declare function verifyCrlIssuedByCertificate(crl: CertificateRevocationList, certificate: Certificate): boolean;
33
+
6
34
  interface DirectoryName {
7
35
  stateOrProvinceName?: string;
8
36
  localityName?: string;
@@ -245,7 +273,7 @@ declare function extractPublicKeyFromCertificate(certificate: CertificatePEM | C
245
273
 
246
274
  /***
247
275
  * @method rsaLengthPrivateKey
248
- * A very expensive way to determine the rsa key length ( i.e 2048bits or 1024bits)
276
+ * A method to determine the rsa key length ( i.e 2048bits or 1024bits)
249
277
  * @param key a PEM public key or a PEM rsa private key
250
278
  * @return the key length in bytes.
251
279
  */
@@ -366,10 +394,16 @@ interface CertificateRevocationListInfo {
366
394
  declare function readNameForCrl(buffer: Buffer, block: BlockInfo): DirectoryName;
367
395
  declare function exploreCertificateRevocationList(crl: CertificateRevocationList): CertificateRevocationListInfo;
368
396
 
397
+ interface SubjectAltName {
398
+ uniformResourceIdentifier: string[];
399
+ dNSName: string[];
400
+ iPAddress: string[];
401
+ [key: string]: unknown;
402
+ }
369
403
  interface ExtensionRequest {
370
404
  basicConstraints: BasicConstraints;
371
405
  keyUsage: X509KeyUsage;
372
- subjectAltName: string;
406
+ subjectAltName: SubjectAltName;
373
407
  }
374
408
  interface CertificateSigningRequestInfo {
375
409
  extensionRequest: ExtensionRequest;
@@ -515,4 +549,4 @@ declare const asn1: {
515
549
  readSignatureValueBin: typeof readSignatureValueBin;
516
550
  };
517
551
 
518
- export { type AttributeTypeAndValue, type AuthorityKeyIdentifier, type BasicConstraints, Certificate, type CertificateExtension, type CertificateInfo, type CertificateInternals, CertificatePEM, CertificatePurpose, CertificateRevocationList, type CertificateRevocationListInfo, type CertificateSerialNumber, type CertificateSigningRequestInfo, type ComputeDerivedKeysOptions, type CreateSelfSignCertificateOptions, DER, type DerivedKeys, type DirectoryName, type ExtensionRequest, type Extensions, KeyObject, type Name, Nonce, PEM, PaddingAlgorithm, PrivateKey, type PrivateKeyInternals, PrivateKeyPEM, PublicKey, type PublicKeyLength, PublicKeyPEM, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, type RevokedCertificate, Signature, Subject, type SubjectOptions, type SubjectPublicKey, type SubjectPublicKeyInfo, type TBSCertList, type TbsCertificate, type Validity, type VerifyChunkSignatureOptions, type VerifyMessageChunkSignatureOptions, type Version, type X509ExtKeyUsage, type X509KeyUsage, type _VerifyStatus, _coercePrivateKey, asn1, certificateMatchesPrivateKey, coerceCertificate, coerceCertificatePem, coercePEMorDerToPrivateKey, coercePrivateKeyPem, coercePublicKeyPem, coerceRsaPublicKeyPem, combine_der, computeDerivedKeys, computePaddingFooter, convertPEMtoDER, createCertificateSigningRequest, createSelfSignedCertificate, decryptBufferWithDerivedKeys, derToPrivateKey, encryptBufferWithDerivedKeys, exploreAsn1, exploreCertificate, exploreCertificateInfo, exploreCertificateRevocationList, exploreCertificateSigningRequest, explorePrivateKey, extractPublicKeyFromCertificate, extractPublicKeyFromCertificateSync, generateKeyPair, generatePrivateKey, hexDump, identifyPemType, makeMessageChunkSignature, makeMessageChunkSignatureWithDerivedKeys, makePrivateKeyFromPem, makePrivateKeyThumbPrint, makePseudoRandomBuffer, makeSHA1Thumbprint, pemToPrivateKey, privateDecrypt, privateDecrypt_long, privateDecrypt_native, privateKeyToPEM, publicEncrypt, publicEncrypt_long, publicEncrypt_native, publicKeyAndPrivateKeyMatches, readCertificationRequestInfo, readExtension, readNameForCrl, readTbsCertificate, reduceLength, removePadding, removeTrailingLF, rsaLengthPrivateKey, rsaLengthPublicKey, rsaLengthRsaPublicKey, split_der, toPem, toPem2, verifyCertificateChain, verifyCertificateOrClrSignature, verifyCertificateRevocationListSignature, verifyCertificateSignature, verifyChunkSignature, verifyChunkSignatureWithDerivedKeys, verifyMessageChunkSignature };
552
+ export { type AttributeTypeAndValue, type AuthorityKeyIdentifier, type BasicConstraints, Certificate, type CertificateExtension, type CertificateInfo, type CertificateInternals, CertificatePEM, CertificatePurpose, CertificateRevocationList, type CertificateRevocationListInfo, type CertificateSerialNumber, type CertificateSigningRequestInfo, type ComputeDerivedKeysOptions, type CreateSelfSignCertificateOptions, DER, type DerivedKeys, type DirectoryName, type ExtensionRequest, type Extensions, KeyObject, type Name, Nonce, PEM, PaddingAlgorithm, PrivateKey, type PrivateKeyInternals, PrivateKeyPEM, PublicKey, type PublicKeyLength, PublicKeyPEM, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, type RevokedCertificate, Signature, Subject, type SubjectAltName, type SubjectOptions, type SubjectPublicKey, type SubjectPublicKeyInfo, type TBSCertList, type TbsCertificate, type Validity, type VerifyChunkSignatureOptions, type VerifyMessageChunkSignatureOptions, type Version, type X509ExtKeyUsage, type X509KeyUsage, type _VerifyStatus, _coercePrivateKey, asn1, certificateMatchesPrivateKey, coerceCertificate, coerceCertificatePem, coercePEMorDerToPrivateKey, coercePrivateKeyPem, coercePublicKeyPem, coerceRsaPublicKeyPem, combine_der, computeDerivedKeys, computePaddingFooter, convertPEMtoDER, createCertificateSigningRequest, createSelfSignedCertificate, decryptBufferWithDerivedKeys, derToPrivateKey, encryptBufferWithDerivedKeys, exploreAsn1, exploreCertificate, exploreCertificateInfo, exploreCertificateRevocationList, exploreCertificateSigningRequest, explorePrivateKey, extractPublicKeyFromCertificate, extractPublicKeyFromCertificateSync, generateKeyPair, generatePrivateKey, hexDump, identifyPemType, isCrlIssuedByCertificate, makeMessageChunkSignature, makeMessageChunkSignatureWithDerivedKeys, makePrivateKeyFromPem, makePrivateKeyThumbPrint, makePseudoRandomBuffer, makeSHA1Thumbprint, pemToPrivateKey, privateDecrypt, privateDecrypt_long, privateDecrypt_native, privateKeyToPEM, publicEncrypt, publicEncrypt_long, publicEncrypt_native, publicKeyAndPrivateKeyMatches, readCertificationRequestInfo, readExtension, readNameForCrl, readTbsCertificate, reduceLength, removePadding, removeTrailingLF, rsaLengthPrivateKey, rsaLengthPublicKey, rsaLengthRsaPublicKey, split_der, toPem, toPem2, verifyCertificateChain, verifyCertificateOrClrSignature, verifyCertificateRevocationListSignature, verifyCertificateSignature, verifyChunkSignature, verifyChunkSignatureWithDerivedKeys, verifyCrlIssuedByCertificate, verifyMessageChunkSignature };
@@ -1,8 +1,36 @@
1
- import { C as Certificate, d as CertificatePEM, b as PEM, D as DER, P as PrivateKey, f as PublicKeyPEM, S as Signature, K as KeyObject, e as PrivateKeyPEM, a as PublicKey, N as Nonce, g as CertificateRevocationList, h as CertificatePurpose } from '../common-DxHkx4Pv.js';
1
+ import { g as CertificateRevocationList, C as Certificate, d as CertificatePEM, b as PEM, D as DER, P as PrivateKey, f as PublicKeyPEM, S as Signature, K as KeyObject, e as PrivateKeyPEM, a as PublicKey, N as Nonce, h as CertificatePurpose } from '../common-DxHkx4Pv.js';
2
2
  export { c as createPrivateKeyFromNodeJSCrypto, i as isKeyObject } from '../common-DxHkx4Pv.js';
3
3
  import { KeyLike } from 'node:crypto';
4
4
  import * as x509 from '@peculiar/x509';
5
5
 
6
+ /**
7
+ * Determine if a Certificate Revocation List (CRL) was issued by
8
+ * the given certificate, by comparing the CRL's issuer name
9
+ * fingerprint with the certificate's subject name fingerprint.
10
+ *
11
+ * This is a lightweight check (no cryptographic signature
12
+ * verification). Use {@link verifyCrlIssuedByCertificate} for
13
+ * full verification.
14
+ *
15
+ * @param crl - the CRL to check (DER-encoded)
16
+ * @param certificate - the candidate issuer certificate (DER-encoded)
17
+ * @returns `true` if the CRL's issuer fingerprint matches the
18
+ * certificate's subject fingerprint
19
+ */
20
+ declare function isCrlIssuedByCertificate(crl: CertificateRevocationList, certificate: Certificate): boolean;
21
+ /**
22
+ * Verify that a Certificate Revocation List (CRL) was issued by
23
+ * the given certificate. This performs both a fingerprint match
24
+ * **and** a cryptographic signature verification.
25
+ *
26
+ * @param crl - the CRL to verify (DER-encoded)
27
+ * @param certificate - the candidate issuer certificate (DER-encoded)
28
+ * @returns `true` if the CRL's issuer matches the certificate
29
+ * **and** the CRL's signature is valid against the
30
+ * certificate's public key
31
+ */
32
+ declare function verifyCrlIssuedByCertificate(crl: CertificateRevocationList, certificate: Certificate): boolean;
33
+
6
34
  interface DirectoryName {
7
35
  stateOrProvinceName?: string;
8
36
  localityName?: string;
@@ -245,7 +273,7 @@ declare function extractPublicKeyFromCertificate(certificate: CertificatePEM | C
245
273
 
246
274
  /***
247
275
  * @method rsaLengthPrivateKey
248
- * A very expensive way to determine the rsa key length ( i.e 2048bits or 1024bits)
276
+ * A method to determine the rsa key length ( i.e 2048bits or 1024bits)
249
277
  * @param key a PEM public key or a PEM rsa private key
250
278
  * @return the key length in bytes.
251
279
  */
@@ -366,10 +394,16 @@ interface CertificateRevocationListInfo {
366
394
  declare function readNameForCrl(buffer: Buffer, block: BlockInfo): DirectoryName;
367
395
  declare function exploreCertificateRevocationList(crl: CertificateRevocationList): CertificateRevocationListInfo;
368
396
 
397
+ interface SubjectAltName {
398
+ uniformResourceIdentifier: string[];
399
+ dNSName: string[];
400
+ iPAddress: string[];
401
+ [key: string]: unknown;
402
+ }
369
403
  interface ExtensionRequest {
370
404
  basicConstraints: BasicConstraints;
371
405
  keyUsage: X509KeyUsage;
372
- subjectAltName: string;
406
+ subjectAltName: SubjectAltName;
373
407
  }
374
408
  interface CertificateSigningRequestInfo {
375
409
  extensionRequest: ExtensionRequest;
@@ -515,4 +549,4 @@ declare const asn1: {
515
549
  readSignatureValueBin: typeof readSignatureValueBin;
516
550
  };
517
551
 
518
- export { type AttributeTypeAndValue, type AuthorityKeyIdentifier, type BasicConstraints, Certificate, type CertificateExtension, type CertificateInfo, type CertificateInternals, CertificatePEM, CertificatePurpose, CertificateRevocationList, type CertificateRevocationListInfo, type CertificateSerialNumber, type CertificateSigningRequestInfo, type ComputeDerivedKeysOptions, type CreateSelfSignCertificateOptions, DER, type DerivedKeys, type DirectoryName, type ExtensionRequest, type Extensions, KeyObject, type Name, Nonce, PEM, PaddingAlgorithm, PrivateKey, type PrivateKeyInternals, PrivateKeyPEM, PublicKey, type PublicKeyLength, PublicKeyPEM, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, type RevokedCertificate, Signature, Subject, type SubjectOptions, type SubjectPublicKey, type SubjectPublicKeyInfo, type TBSCertList, type TbsCertificate, type Validity, type VerifyChunkSignatureOptions, type VerifyMessageChunkSignatureOptions, type Version, type X509ExtKeyUsage, type X509KeyUsage, type _VerifyStatus, _coercePrivateKey, asn1, certificateMatchesPrivateKey, coerceCertificate, coerceCertificatePem, coercePEMorDerToPrivateKey, coercePrivateKeyPem, coercePublicKeyPem, coerceRsaPublicKeyPem, combine_der, computeDerivedKeys, computePaddingFooter, convertPEMtoDER, createCertificateSigningRequest, createSelfSignedCertificate, decryptBufferWithDerivedKeys, derToPrivateKey, encryptBufferWithDerivedKeys, exploreAsn1, exploreCertificate, exploreCertificateInfo, exploreCertificateRevocationList, exploreCertificateSigningRequest, explorePrivateKey, extractPublicKeyFromCertificate, extractPublicKeyFromCertificateSync, generateKeyPair, generatePrivateKey, hexDump, identifyPemType, makeMessageChunkSignature, makeMessageChunkSignatureWithDerivedKeys, makePrivateKeyFromPem, makePrivateKeyThumbPrint, makePseudoRandomBuffer, makeSHA1Thumbprint, pemToPrivateKey, privateDecrypt, privateDecrypt_long, privateDecrypt_native, privateKeyToPEM, publicEncrypt, publicEncrypt_long, publicEncrypt_native, publicKeyAndPrivateKeyMatches, readCertificationRequestInfo, readExtension, readNameForCrl, readTbsCertificate, reduceLength, removePadding, removeTrailingLF, rsaLengthPrivateKey, rsaLengthPublicKey, rsaLengthRsaPublicKey, split_der, toPem, toPem2, verifyCertificateChain, verifyCertificateOrClrSignature, verifyCertificateRevocationListSignature, verifyCertificateSignature, verifyChunkSignature, verifyChunkSignatureWithDerivedKeys, verifyMessageChunkSignature };
552
+ export { type AttributeTypeAndValue, type AuthorityKeyIdentifier, type BasicConstraints, Certificate, type CertificateExtension, type CertificateInfo, type CertificateInternals, CertificatePEM, CertificatePurpose, CertificateRevocationList, type CertificateRevocationListInfo, type CertificateSerialNumber, type CertificateSigningRequestInfo, type ComputeDerivedKeysOptions, type CreateSelfSignCertificateOptions, DER, type DerivedKeys, type DirectoryName, type ExtensionRequest, type Extensions, KeyObject, type Name, Nonce, PEM, PaddingAlgorithm, PrivateKey, type PrivateKeyInternals, PrivateKeyPEM, PublicKey, type PublicKeyLength, PublicKeyPEM, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, type RevokedCertificate, Signature, Subject, type SubjectAltName, type SubjectOptions, type SubjectPublicKey, type SubjectPublicKeyInfo, type TBSCertList, type TbsCertificate, type Validity, type VerifyChunkSignatureOptions, type VerifyMessageChunkSignatureOptions, type Version, type X509ExtKeyUsage, type X509KeyUsage, type _VerifyStatus, _coercePrivateKey, asn1, certificateMatchesPrivateKey, coerceCertificate, coerceCertificatePem, coercePEMorDerToPrivateKey, coercePrivateKeyPem, coercePublicKeyPem, coerceRsaPublicKeyPem, combine_der, computeDerivedKeys, computePaddingFooter, convertPEMtoDER, createCertificateSigningRequest, createSelfSignedCertificate, decryptBufferWithDerivedKeys, derToPrivateKey, encryptBufferWithDerivedKeys, exploreAsn1, exploreCertificate, exploreCertificateInfo, exploreCertificateRevocationList, exploreCertificateSigningRequest, explorePrivateKey, extractPublicKeyFromCertificate, extractPublicKeyFromCertificateSync, generateKeyPair, generatePrivateKey, hexDump, identifyPemType, isCrlIssuedByCertificate, makeMessageChunkSignature, makeMessageChunkSignatureWithDerivedKeys, makePrivateKeyFromPem, makePrivateKeyThumbPrint, makePseudoRandomBuffer, makeSHA1Thumbprint, pemToPrivateKey, privateDecrypt, privateDecrypt_long, privateDecrypt_native, privateKeyToPEM, publicEncrypt, publicEncrypt_long, publicEncrypt_native, publicKeyAndPrivateKeyMatches, readCertificationRequestInfo, readExtension, readNameForCrl, readTbsCertificate, reduceLength, removePadding, removeTrailingLF, rsaLengthPrivateKey, rsaLengthPublicKey, rsaLengthRsaPublicKey, split_der, toPem, toPem2, verifyCertificateChain, verifyCertificateOrClrSignature, verifyCertificateRevocationListSignature, verifyCertificateSignature, verifyChunkSignature, verifyChunkSignatureWithDerivedKeys, verifyCrlIssuedByCertificate, verifyMessageChunkSignature };
@@ -66,6 +66,7 @@ __export(index_web_exports, {
66
66
  generatePrivateKey: () => generatePrivateKey,
67
67
  hexDump: () => hexDump,
68
68
  identifyPemType: () => identifyPemType,
69
+ isCrlIssuedByCertificate: () => isCrlIssuedByCertificate,
69
70
  isKeyObject: () => isKeyObject,
70
71
  makeMessageChunkSignature: () => makeMessageChunkSignature,
71
72
  makeMessageChunkSignatureWithDerivedKeys: () => makeMessageChunkSignatureWithDerivedKeys,
@@ -101,6 +102,7 @@ __export(index_web_exports, {
101
102
  verifyCertificateSignature: () => verifyCertificateSignature,
102
103
  verifyChunkSignature: () => verifyChunkSignature,
103
104
  verifyChunkSignatureWithDerivedKeys: () => verifyChunkSignatureWithDerivedKeys,
105
+ verifyCrlIssuedByCertificate: () => verifyCrlIssuedByCertificate,
104
106
  verifyMessageChunkSignature: () => verifyMessageChunkSignature
105
107
  });
106
108
  module.exports = __toCommonJS(index_web_exports);
@@ -689,7 +691,6 @@ function readTime(buffer, block) {
689
691
  var import_node_assert2 = __toESM(require("assert"));
690
692
  var import_node_constants = __toESM(require("constants"));
691
693
  var import_node_crypto2 = require("crypto");
692
- var import_jsrsasign = __toESM(require("jsrsasign"));
693
694
 
694
695
  // source/buffer_utils.ts
695
696
  var createFastUninitializedBuffer = Buffer.allocUnsafe ? Buffer.allocUnsafe : (size) => {
@@ -879,8 +880,8 @@ function coerceCertificatePem(certificate) {
879
880
  }
880
881
  function extractPublicKeyFromCertificateSync(certificate) {
881
882
  certificate = coerceCertificatePem(certificate);
882
- const key = import_jsrsasign.default.KEYUTIL.getKey(certificate);
883
- const publicKeyAsPem = import_jsrsasign.default.KEYUTIL.getPEM(key);
883
+ const publicKeyObject = (0, import_node_crypto2.createPublicKey)(certificate);
884
+ const publicKeyAsPem = publicKeyObject.export({ format: "pem", type: "spki" }).toString();
884
885
  (0, import_node_assert2.default)(typeof publicKeyAsPem === "string");
885
886
  return publicKeyAsPem;
886
887
  }
@@ -1302,13 +1303,154 @@ function combine_der(certificates) {
1302
1303
  return Buffer.concat(certificates);
1303
1304
  }
1304
1305
 
1306
+ // source/explore_certificate_revocation_list.ts
1307
+ function readNameForCrl(buffer, block) {
1308
+ return readDirectoryName(buffer, block);
1309
+ }
1310
+ function _readTbsCertList(buffer, blockInfo) {
1311
+ const blocks = readStruct(buffer, blockInfo);
1312
+ const hasOptionalVersion = blocks[0].tag === 2 /* INTEGER */;
1313
+ if (hasOptionalVersion) {
1314
+ const _version = readIntegerValue(buffer, blocks[0]);
1315
+ const signature = readAlgorithmIdentifier(buffer, blocks[1]);
1316
+ const issuer = readNameForCrl(buffer, blocks[2]);
1317
+ const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[2])));
1318
+ const thisUpdate = readTime(buffer, blocks[3]);
1319
+ const nextUpdate = readTime(buffer, blocks[4]);
1320
+ const revokedCertificates = [];
1321
+ if (blocks[5] && blocks[5].tag < 128) {
1322
+ const list = readStruct(buffer, blocks[5]);
1323
+ for (const r of list) {
1324
+ const rr = readStruct(buffer, r);
1325
+ const userCertificate = formatBuffer2DigitHexWithColum(readLongIntegerValue(buffer, rr[0]));
1326
+ const revocationDate = readTime(buffer, rr[1]);
1327
+ revokedCertificates.push({
1328
+ revocationDate,
1329
+ userCertificate
1330
+ });
1331
+ }
1332
+ }
1333
+ const _ext0 = findBlockAtIndex(blocks, 0);
1334
+ return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates };
1335
+ } else {
1336
+ const signature = readAlgorithmIdentifier(buffer, blocks[0]);
1337
+ const issuer = readNameForCrl(buffer, blocks[1]);
1338
+ const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[1])));
1339
+ const thisUpdate = readTime(buffer, blocks[2]);
1340
+ const nextUpdate = readTime(buffer, blocks[3]);
1341
+ const revokedCertificates = [];
1342
+ if (blocks[4] && blocks[4].tag < 128) {
1343
+ const list = readStruct(buffer, blocks[4]);
1344
+ for (const r of list) {
1345
+ const rr = readStruct(buffer, r);
1346
+ const userCertificate = formatBuffer2DigitHexWithColum(readLongIntegerValue(buffer, rr[0]));
1347
+ const revocationDate = readTime(buffer, rr[1]);
1348
+ revokedCertificates.push({
1349
+ revocationDate,
1350
+ userCertificate
1351
+ });
1352
+ }
1353
+ }
1354
+ return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates };
1355
+ }
1356
+ }
1357
+ function exploreCertificateRevocationList(crl) {
1358
+ const blockInfo = readTag(crl, 0);
1359
+ const blocks = readStruct(crl, blockInfo);
1360
+ const tbsCertList = _readTbsCertList(crl, blocks[0]);
1361
+ const signatureAlgorithm = readAlgorithmIdentifier(crl, blocks[1]);
1362
+ const signatureValue = readSignatureValueBin(crl, blocks[2]);
1363
+ return { tbsCertList, signatureAlgorithm, signatureValue };
1364
+ }
1365
+
1366
+ // source/verify_certificate_signature.ts
1367
+ var import_node_crypto3 = require("crypto");
1368
+ function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
1369
+ const block_info = readTag(certificateOrCrl, 0);
1370
+ const blocks = readStruct(certificateOrCrl, block_info);
1371
+ const bufferToBeSigned = certificateOrCrl.subarray(block_info.position, blocks[1].position - 2);
1372
+ const signatureAlgorithm = readAlgorithmIdentifier(certificateOrCrl, blocks[1]);
1373
+ const signatureValue = readSignatureValueBin(certificateOrCrl, blocks[2]);
1374
+ const p = split_der(parentCertificate)[0];
1375
+ const certPem = toPem(p, "CERTIFICATE");
1376
+ const verify = (0, import_node_crypto3.createVerify)(signatureAlgorithm.identifier);
1377
+ verify.update(bufferToBeSigned);
1378
+ verify.end();
1379
+ return verify.verify(certPem, signatureValue);
1380
+ }
1381
+ function verifyCertificateSignature(certificate, parentCertificate) {
1382
+ return verifyCertificateOrClrSignature(certificate, parentCertificate);
1383
+ }
1384
+ function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
1385
+ return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
1386
+ }
1387
+ async function verifyCertificateChain(certificateChain) {
1388
+ for (let index = 1; index < certificateChain.length; index++) {
1389
+ const cert = certificateChain[index - 1];
1390
+ const certParent = certificateChain[index];
1391
+ const certParentInfo = exploreCertificate(certParent);
1392
+ const keyUsage = certParentInfo.tbsCertificate.extensions?.keyUsage;
1393
+ if (!keyUsage || !keyUsage.keyCertSign) {
1394
+ return {
1395
+ status: "BadCertificateIssuerUseNotAllowed",
1396
+ reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing"
1397
+ };
1398
+ }
1399
+ const parentSignChild = verifyCertificateSignature(cert, certParent);
1400
+ if (!parentSignChild) {
1401
+ return {
1402
+ status: "BadCertificateInvalid",
1403
+ reason: "One of the certificate in the chain is not signing the previous certificate"
1404
+ };
1405
+ }
1406
+ const certInfo = exploreCertificate(cert);
1407
+ if (!certInfo.tbsCertificate.extensions) {
1408
+ return {
1409
+ status: "BadCertificateInvalid",
1410
+ reason: "Cannot find X409 Extension 3 in certificate"
1411
+ };
1412
+ }
1413
+ if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
1414
+ return {
1415
+ status: "BadCertificateInvalid",
1416
+ reason: "Cannot find X409 Extension 3 in certificate (parent)"
1417
+ };
1418
+ }
1419
+ if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !== certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
1420
+ return {
1421
+ status: "BadCertificateInvalid",
1422
+ reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate"
1423
+ };
1424
+ }
1425
+ }
1426
+ return {
1427
+ status: "Good",
1428
+ reason: `certificate chain is valid(length = ${certificateChain.length})`
1429
+ };
1430
+ }
1431
+
1432
+ // source/crl_utils.ts
1433
+ function isCrlIssuedByCertificate(crl, certificate) {
1434
+ const crlInfo = exploreCertificateRevocationList(crl);
1435
+ const certInfo = exploreCertificate(certificate);
1436
+ return crlInfo.tbsCertList.issuerFingerprint === certInfo.tbsCertificate.subjectFingerPrint;
1437
+ }
1438
+ function verifyCrlIssuedByCertificate(crl, certificate) {
1439
+ if (!isCrlIssuedByCertificate(crl, certificate)) {
1440
+ return false;
1441
+ }
1442
+ return verifyCertificateRevocationListSignature(crl, certificate);
1443
+ }
1444
+
1305
1445
  // source/crypto_utils2.ts
1306
1446
  var import_node_assert5 = __toESM(require("assert"));
1307
- var import_jsrsasign2 = __toESM(require("jsrsasign"));
1447
+ var import_node_crypto4 = require("crypto");
1308
1448
  function rsaLengthPrivateKey(key) {
1309
1449
  const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
1310
- const a = import_jsrsasign2.default.KEYUTIL.getKey(keyPem);
1311
- return a.n.toString(16).length / 2;
1450
+ const keyObject = (0, import_node_crypto4.createPrivateKey)(keyPem);
1451
+ const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
1452
+ (0, import_node_assert5.default)(modulusLength, "Cannot determine modulus length from private key");
1453
+ return modulusLength / 8;
1312
1454
  }
1313
1455
  function toPem2(raw_key, pem) {
1314
1456
  if (raw_key.hidden) {
@@ -1348,19 +1490,23 @@ function coerceRsaPublicKeyPem(publicKey) {
1348
1490
  function rsaLengthPublicKey(key) {
1349
1491
  key = coercePublicKeyPem(key);
1350
1492
  (0, import_node_assert5.default)(typeof key === "string");
1351
- const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
1352
- return a.n.toString(16).length / 2;
1493
+ const keyObject = (0, import_node_crypto4.createPublicKey)(key);
1494
+ const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
1495
+ (0, import_node_assert5.default)(modulusLength, "Cannot determine modulus length from public key");
1496
+ return modulusLength / 8;
1353
1497
  }
1354
1498
  function rsaLengthRsaPublicKey(key) {
1355
1499
  key = coerceRsaPublicKeyPem(key);
1356
1500
  (0, import_node_assert5.default)(typeof key === "string");
1357
- const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
1358
- return a.n.toString(16).length / 2;
1501
+ const keyObject = (0, import_node_crypto4.createPublicKey)(key);
1502
+ const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
1503
+ (0, import_node_assert5.default)(modulusLength, "Cannot determine modulus length from public key");
1504
+ return modulusLength / 8;
1359
1505
  }
1360
1506
 
1361
1507
  // source/derived_keys.ts
1362
1508
  var import_node_assert7 = __toESM(require("assert"));
1363
- var import_node_crypto3 = require("crypto");
1509
+ var import_node_crypto5 = require("crypto");
1364
1510
 
1365
1511
  // source/explore_certificate.ts
1366
1512
  var import_node_assert6 = __toESM(require("assert"));
@@ -1389,7 +1535,7 @@ function exploreCertificateInfo(certificate) {
1389
1535
 
1390
1536
  // source/derived_keys.ts
1391
1537
  function HMAC_HASH(sha1or256, secret, message) {
1392
- return (0, import_node_crypto3.createHmac)(sha1or256, secret).update(message).digest();
1538
+ return (0, import_node_crypto5.createHmac)(sha1or256, secret).update(message).digest();
1393
1539
  }
1394
1540
  function plus(buf1, buf2) {
1395
1541
  return Buffer.concat([buf1, buf2]);
@@ -1466,7 +1612,7 @@ function encryptBufferWithDerivedKeys(buffer, derivedKeys) {
1466
1612
  const algorithm = derivedKeys_algorithm(derivedKeys);
1467
1613
  const key = derivedKeys.encryptingKey;
1468
1614
  const initVector = derivedKeys.initializationVector;
1469
- const cipher = (0, import_node_crypto3.createCipheriv)(algorithm, key, initVector);
1615
+ const cipher = (0, import_node_crypto5.createCipheriv)(algorithm, key, initVector);
1470
1616
  cipher.setAutoPadding(false);
1471
1617
  const encrypted_chunks = [];
1472
1618
  encrypted_chunks.push(cipher.update(buffer));
@@ -1477,7 +1623,7 @@ function decryptBufferWithDerivedKeys(buffer, derivedKeys) {
1477
1623
  const algorithm = derivedKeys_algorithm(derivedKeys);
1478
1624
  const key = derivedKeys.encryptingKey;
1479
1625
  const initVector = derivedKeys.initializationVector;
1480
- const cipher = (0, import_node_crypto3.createDecipheriv)(algorithm, key, initVector);
1626
+ const cipher = (0, import_node_crypto5.createDecipheriv)(algorithm, key, initVector);
1481
1627
  cipher.setAutoPadding(false);
1482
1628
  const decrypted_chunks = [];
1483
1629
  decrypted_chunks.push(cipher.update(buffer));
@@ -1489,7 +1635,7 @@ function makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys) {
1489
1635
  (0, import_node_assert7.default)(Buffer.isBuffer(derivedKeys.signingKey));
1490
1636
  (0, import_node_assert7.default)(typeof derivedKeys.sha1or256 === "string");
1491
1637
  (0, import_node_assert7.default)(derivedKeys.sha1or256 === "SHA1" || derivedKeys.sha1or256 === "SHA256");
1492
- const signature = (0, import_node_crypto3.createHmac)(derivedKeys.sha1or256, derivedKeys.signingKey).update(message).digest();
1638
+ const signature = (0, import_node_crypto5.createHmac)(derivedKeys.sha1or256, derivedKeys.signingKey).update(message).digest();
1493
1639
  (0, import_node_assert7.default)(signature.length === derivedKeys.signatureLength);
1494
1640
  return signature;
1495
1641
  }
@@ -1527,66 +1673,6 @@ function exploreAsn1(buffer) {
1527
1673
  dump(0, 0);
1528
1674
  }
1529
1675
 
1530
- // source/explore_certificate_revocation_list.ts
1531
- function readNameForCrl(buffer, block) {
1532
- return readDirectoryName(buffer, block);
1533
- }
1534
- function _readTbsCertList(buffer, blockInfo) {
1535
- const blocks = readStruct(buffer, blockInfo);
1536
- const hasOptionalVersion = blocks[0].tag === 2 /* INTEGER */;
1537
- if (hasOptionalVersion) {
1538
- const _version = readIntegerValue(buffer, blocks[0]);
1539
- const signature = readAlgorithmIdentifier(buffer, blocks[1]);
1540
- const issuer = readNameForCrl(buffer, blocks[2]);
1541
- const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[2])));
1542
- const thisUpdate = readTime(buffer, blocks[3]);
1543
- const nextUpdate = readTime(buffer, blocks[4]);
1544
- const revokedCertificates = [];
1545
- if (blocks[5] && blocks[5].tag < 128) {
1546
- const list = readStruct(buffer, blocks[5]);
1547
- for (const r of list) {
1548
- const rr = readStruct(buffer, r);
1549
- const userCertificate = formatBuffer2DigitHexWithColum(readLongIntegerValue(buffer, rr[0]));
1550
- const revocationDate = readTime(buffer, rr[1]);
1551
- revokedCertificates.push({
1552
- revocationDate,
1553
- userCertificate
1554
- });
1555
- }
1556
- }
1557
- const _ext0 = findBlockAtIndex(blocks, 0);
1558
- return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates };
1559
- } else {
1560
- const signature = readAlgorithmIdentifier(buffer, blocks[0]);
1561
- const issuer = readNameForCrl(buffer, blocks[1]);
1562
- const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[1])));
1563
- const thisUpdate = readTime(buffer, blocks[2]);
1564
- const nextUpdate = readTime(buffer, blocks[3]);
1565
- const revokedCertificates = [];
1566
- if (blocks[4] && blocks[4].tag < 128) {
1567
- const list = readStruct(buffer, blocks[4]);
1568
- for (const r of list) {
1569
- const rr = readStruct(buffer, r);
1570
- const userCertificate = formatBuffer2DigitHexWithColum(readLongIntegerValue(buffer, rr[0]));
1571
- const revocationDate = readTime(buffer, rr[1]);
1572
- revokedCertificates.push({
1573
- revocationDate,
1574
- userCertificate
1575
- });
1576
- }
1577
- }
1578
- return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates };
1579
- }
1580
- }
1581
- function exploreCertificateRevocationList(crl) {
1582
- const blockInfo = readTag(crl, 0);
1583
- const blocks = readStruct(crl, blockInfo);
1584
- const tbsCertList = _readTbsCertList(crl, blocks[0]);
1585
- const signatureAlgorithm = readAlgorithmIdentifier(crl, blocks[1]);
1586
- const signatureValue = readSignatureValueBin(crl, blocks[2]);
1587
- return { tbsCertList, signatureAlgorithm, signatureValue };
1588
- }
1589
-
1590
1676
  // source/explore_certificate_signing_request.ts
1591
1677
  function _readExtensionRequest(buffer) {
1592
1678
  const block = readTag(buffer, 0);
@@ -1834,74 +1920,8 @@ var Subject = class _Subject {
1834
1920
  }
1835
1921
  };
1836
1922
 
1837
- // source/verify_certificate_signature.ts
1838
- var import_node_crypto4 = require("crypto");
1839
- function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
1840
- const block_info = readTag(certificateOrCrl, 0);
1841
- const blocks = readStruct(certificateOrCrl, block_info);
1842
- const bufferToBeSigned = certificateOrCrl.subarray(block_info.position, blocks[1].position - 2);
1843
- const signatureAlgorithm = readAlgorithmIdentifier(certificateOrCrl, blocks[1]);
1844
- const signatureValue = readSignatureValueBin(certificateOrCrl, blocks[2]);
1845
- const p = split_der(parentCertificate)[0];
1846
- const certPem = toPem(p, "CERTIFICATE");
1847
- const verify = (0, import_node_crypto4.createVerify)(signatureAlgorithm.identifier);
1848
- verify.update(bufferToBeSigned);
1849
- verify.end();
1850
- return verify.verify(certPem, signatureValue);
1851
- }
1852
- function verifyCertificateSignature(certificate, parentCertificate) {
1853
- return verifyCertificateOrClrSignature(certificate, parentCertificate);
1854
- }
1855
- function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
1856
- return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
1857
- }
1858
- async function verifyCertificateChain(certificateChain) {
1859
- for (let index = 1; index < certificateChain.length; index++) {
1860
- const cert = certificateChain[index - 1];
1861
- const certParent = certificateChain[index];
1862
- const certParentInfo = exploreCertificate(certParent);
1863
- const keyUsage = certParentInfo.tbsCertificate.extensions?.keyUsage;
1864
- if (!keyUsage || !keyUsage.keyCertSign) {
1865
- return {
1866
- status: "BadCertificateIssuerUseNotAllowed",
1867
- reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing"
1868
- };
1869
- }
1870
- const parentSignChild = verifyCertificateSignature(cert, certParent);
1871
- if (!parentSignChild) {
1872
- return {
1873
- status: "BadCertificateInvalid",
1874
- reason: "One of the certificate in the chain is not signing the previous certificate"
1875
- };
1876
- }
1877
- const certInfo = exploreCertificate(cert);
1878
- if (!certInfo.tbsCertificate.extensions) {
1879
- return {
1880
- status: "BadCertificateInvalid",
1881
- reason: "Cannot find X409 Extension 3 in certificate"
1882
- };
1883
- }
1884
- if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
1885
- return {
1886
- status: "BadCertificateInvalid",
1887
- reason: "Cannot find X409 Extension 3 in certificate (parent)"
1888
- };
1889
- }
1890
- if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !== certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
1891
- return {
1892
- status: "BadCertificateInvalid",
1893
- reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate"
1894
- };
1895
- }
1896
- }
1897
- return {
1898
- status: "Good",
1899
- reason: `certificate chain is valid(length = ${certificateChain.length})`
1900
- };
1901
- }
1902
-
1903
1923
  // source/x509/_crypto.ts
1904
- var import_node_crypto5 = __toESM(require("crypto"));
1924
+ var import_node_crypto6 = __toESM(require("crypto"));
1905
1925
  var import_webcrypto = require("@peculiar/webcrypto");
1906
1926
  var x509 = __toESM(require("@peculiar/x509"));
1907
1927
  var x5092 = __toESM(require("@peculiar/x509"));
@@ -1909,7 +1929,7 @@ var doDebug3 = false;
1909
1929
  var _crypto;
1910
1930
  var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
1911
1931
  if (typeof window === "undefined") {
1912
- _crypto = import_node_crypto5.default;
1932
+ _crypto = import_node_crypto6.default;
1913
1933
  if (!_crypto?.subtle || ignoreCrypto) {
1914
1934
  _crypto = new import_webcrypto.Crypto();
1915
1935
  doDebug3 && console.warn("using @peculiar/webcrypto");
@@ -1923,7 +1943,7 @@ if (typeof window === "undefined") {
1923
1943
  x509.cryptoProvider.set(crypto);
1924
1944
  }
1925
1945
  function getCrypto() {
1926
- return _crypto || crypto || import_node_crypto5.default;
1946
+ return _crypto || crypto || import_node_crypto6.default;
1927
1947
  }
1928
1948
 
1929
1949
  // source/x509/create_key_pair.ts
@@ -6462,6 +6482,7 @@ var asn1 = { readDirectoryName, readTag, readStruct, readAlgorithmIdentifier, re
6462
6482
  generatePrivateKey,
6463
6483
  hexDump,
6464
6484
  identifyPemType,
6485
+ isCrlIssuedByCertificate,
6465
6486
  isKeyObject,
6466
6487
  makeMessageChunkSignature,
6467
6488
  makeMessageChunkSignatureWithDerivedKeys,
@@ -6497,6 +6518,7 @@ var asn1 = { readDirectoryName, readTag, readStruct, readAlgorithmIdentifier, re
6497
6518
  verifyCertificateSignature,
6498
6519
  verifyChunkSignature,
6499
6520
  verifyChunkSignatureWithDerivedKeys,
6521
+ verifyCrlIssuedByCertificate,
6500
6522
  verifyMessageChunkSignature
6501
6523
  });
6502
6524
  /*! Bundled license information: