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.
@@ -6,11 +6,11 @@ import {
6
6
  privateKeyToPEM,
7
7
  removeTrailingLF,
8
8
  toPem
9
- } from "./chunk-EURHGMEG.mjs";
9
+ } from "./chunk-ULG5CYBT.mjs";
10
10
 
11
11
  // source_nodejs/generate_private_key_filename.ts
12
+ import { generateKeyPairSync } from "crypto";
12
13
  import fs from "fs";
13
- import jsrsasign from "jsrsasign";
14
14
  async function generatePrivateKeyFile(privateKeyFilename, modulusLength) {
15
15
  const keys = await generateKeyPair(modulusLength);
16
16
  const privateKeyPem = await privateKeyToPEM(keys.privateKey);
@@ -19,11 +19,12 @@ async function generatePrivateKeyFile(privateKeyFilename, modulusLength) {
19
19
  privateKeyPem.privDer = new ArrayBuffer(0);
20
20
  }
21
21
  async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength) {
22
- const kp = jsrsasign.KEYUTIL.generateKeypair("RSA", modulusLength);
23
- const prv = kp.prvKeyObj;
24
- const _pub = kp.pubKeyObj;
25
- const prvpem = jsrsasign.KEYUTIL.getPEM(prv, "PKCS8PRV");
26
- await fs.promises.writeFile(privateKeyFilename, prvpem, "utf-8");
22
+ const { privateKey } = generateKeyPairSync("rsa", {
23
+ modulusLength,
24
+ privateKeyEncoding: { type: "pkcs8", format: "pem" },
25
+ publicKeyEncoding: { type: "spki", format: "pem" }
26
+ });
27
+ await fs.promises.writeFile(privateKeyFilename, privateKey, "utf-8");
27
28
  }
28
29
 
29
30
  // source_nodejs/read.ts
@@ -165,4 +166,4 @@ export {
165
166
  readCertificateRevocationList,
166
167
  readCertificateSigningRequest
167
168
  };
168
- //# sourceMappingURL=chunk-CQ5JIXZF.mjs.map
169
+ //# sourceMappingURL=chunk-UXPULF3W.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../source_nodejs/generate_private_key_filename.ts","../source_nodejs/read.ts","../source_nodejs/read_certificate_revocation_list.ts","../source_nodejs/read_certificate_signing_request.ts"],"sourcesContent":["// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2026 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport { generateKeyPairSync } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport { generateKeyPair, privateKeyToPEM } from \"../source/index.js\";\nexport async function generatePrivateKeyFile(privateKeyFilename: string, modulusLength: 1024 | 2048 | 3072 | 4096) {\n const keys = await generateKeyPair(modulusLength);\n const privateKeyPem = await privateKeyToPEM(keys.privateKey);\n await fs.promises.writeFile(privateKeyFilename, privateKeyPem.privPem, \"utf-8\");\n privateKeyPem.privPem = \"\";\n privateKeyPem.privDer = new ArrayBuffer(0);\n}\n\n/**\n * alternate function to generate PrivateKeyFile, using native\n * node:crypto.\n *\n * This function is slower than generatePrivateKeyFile\n */\nexport async function generatePrivateKeyFileAlternate(privateKeyFilename: string, modulusLength: 2048 | 3072 | 4096) {\n const { privateKey } = generateKeyPairSync(\"rsa\", {\n modulusLength,\n privateKeyEncoding: { type: \"pkcs8\", format: \"pem\" },\n publicKeyEncoding: { type: \"spki\", format: \"pem\" },\n });\n await fs.promises.writeFile(privateKeyFilename, privateKey, \"utf-8\");\n}\n","// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2026 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport assert from \"node:assert\";\nimport { createPrivateKey, createPublicKey } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport sshpk from \"sshpk\";\nimport type {\n Certificate,\n CertificatePEM,\n DER,\n KeyObject,\n PEM,\n PrivateKey,\n PrivateKeyPEM,\n PublicKey,\n PublicKeyPEM,\n} from \"../source/common.js\";\nimport { convertPEMtoDER, identifyPemType, removeTrailingLF, toPem } from \"../source/crypto_utils.js\";\n\nfunction _readPemFile(filename: string): PEM {\n assert(typeof filename === \"string\");\n return removeTrailingLF(fs.readFileSync(filename, \"utf-8\"));\n}\n\nfunction _readPemOrDerFileAsDER(filename: string): DER {\n if (filename.match(/.*\\.der/)) {\n return fs.readFileSync(filename) as Buffer;\n }\n const raw_key: string = _readPemFile(filename);\n return convertPEMtoDER(raw_key);\n}\n\n/**\n * read a DER or PEM certificate from file\n */\nexport function readCertificate(filename: string): Certificate {\n return _readPemOrDerFileAsDER(filename) as Certificate;\n}\n\n/**\n * read a DER or PEM certificate from file\n */\nexport function readPublicKey(filename: string): KeyObject {\n if (filename.match(/.*\\.der/)) {\n const der = fs.readFileSync(filename) as Buffer;\n return createPublicKey(der);\n } else {\n const raw_key: string = _readPemFile(filename);\n return createPublicKey(raw_key);\n }\n}\n\n// console.log(\"createPrivateKey\", (crypto as any).createPrivateKey, process.env.NO_CREATE_PRIVATEKEY);\n\nfunction myCreatePrivateKey(rawKey: string | Buffer): PrivateKey {\n if (!createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) {\n // we are not running nodejs or createPrivateKey is not supported in the environment\n if (Buffer.isBuffer(rawKey)) {\n const pemKey = toPem(rawKey, \"PRIVATE KEY\");\n assert([\"RSA PRIVATE KEY\", \"PRIVATE KEY\"].indexOf(identifyPemType(pemKey) as string) >= 0);\n return { hidden: pemKey };\n }\n return { hidden: ensureTrailingLF(rawKey as string) };\n }\n // see https://askubuntu.com/questions/1409458/openssl-config-cuases-error-in-node-js-crypto-how-should-the-config-be-updated\n const backup = process.env.OPENSSL_CONF;\n process.env.OPENSSL_CONF = \"/dev/null\";\n const retValue = createPrivateKey(rawKey);\n process.env.OPENSSL_CONF = backup;\n return { hidden: retValue };\n}\n\nfunction ensureTrailingLF(str: string): string {\n return str.match(/\\n$/) ? str : `${str}\\n`;\n}\n/**\n * read a DER or PEM certificate from file\n */\nexport function readPrivateKey(filename: string): PrivateKey {\n if (filename.match(/.*\\.der/)) {\n const der: Buffer = fs.readFileSync(filename);\n return myCreatePrivateKey(der);\n } else {\n const raw_key: string = _readPemFile(filename);\n return myCreatePrivateKey(raw_key);\n }\n}\n\nexport function readCertificatePEM(filename: string): CertificatePEM {\n return _readPemFile(filename);\n}\n\nexport function readPublicKeyPEM(filename: string): PublicKeyPEM {\n return _readPemFile(filename);\n}\n/**\n *\n * @deprecated\n */\nexport function readPrivateKeyPEM(filename: string): PrivateKeyPEM {\n return _readPemFile(filename);\n}\n\nlet _g_certificate_store: string = \"\";\n\nexport function setCertificateStore(store: string): string {\n const old_store = _g_certificate_store;\n _g_certificate_store = store;\n return old_store;\n}\nexport function getCertificateStore(): string {\n if (!_g_certificate_store) {\n _g_certificate_store = path.join(__dirname, \"../../certificates/\");\n }\n return _g_certificate_store;\n}\n/**\n *\n * @param filename\n */\nexport function readPrivateRsaKey(filename: string): PrivateKey {\n if (!createPrivateKey) {\n throw new Error(\"createPrivateKey is not supported in this environment\");\n }\n if (filename.substring(0, 1) !== \".\" && !fs.existsSync(filename)) {\n filename = path.join(getCertificateStore(), filename);\n }\n const content = fs.readFileSync(filename, \"utf8\");\n const sshKey = sshpk.parsePrivateKey(content, \"auto\");\n const key = sshKey.toString(\"pkcs1\") as PEM;\n const hidden = createPrivateKey({ format: \"pem\", type: \"pkcs1\", key });\n return { hidden };\n}\n\nexport function readPublicRsaKey(filename: string): PublicKey {\n if (filename.substring(0, 1) !== \".\" && !fs.existsSync(filename)) {\n filename = path.join(getCertificateStore(), filename);\n }\n const content = fs.readFileSync(filename, \"utf-8\");\n const sshKey = sshpk.parseKey(content, \"ssh\");\n const key = sshKey.toString(\"pkcs1\") as PEM;\n return createPublicKey({ format: \"pem\", type: \"pkcs1\", key });\n}\n","// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2026 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport fs from \"node:fs\";\nimport type { CertificateRevocationList } from \"../source/common.js\";\nimport { convertPEMtoDER } from \"../source/crypto_utils.js\";\n\nexport async function readCertificateRevocationList(filename: string): Promise<CertificateRevocationList> {\n const crl = await fs.promises.readFile(filename);\n if (crl[0] === 0x30 && crl[1] === 0x82) {\n // der format\n return crl as CertificateRevocationList;\n }\n const raw_crl = crl.toString();\n return convertPEMtoDER(raw_crl);\n}\n","// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2026 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport fs from \"node:fs\";\nimport type { CertificateRevocationList } from \"../source/common.js\";\nimport { convertPEMtoDER } from \"../source/crypto_utils.js\";\n\nexport type CertificateSigningRequest = Buffer;\n\nexport async function readCertificateSigningRequest(filename: string): Promise<CertificateSigningRequest> {\n const csr = await fs.promises.readFile(filename);\n if (csr[0] === 0x30 && csr[1] === 0x82) {\n // der format\n return csr as CertificateRevocationList;\n }\n const raw_crl = csr.toString();\n return convertPEMtoDER(raw_crl);\n}\n"],"mappings":";;;;;;;;;;;AAuBA,SAAS,2BAA2B;AACpC,OAAO,QAAQ;AAEf,eAAsB,uBAAuB,oBAA4B,eAA0C;AAC/G,QAA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fs","fs","fs"]}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { AttributeTypeAndValue, AuthorityKeyIdentifier, BasicConstraints, CertificateExtension, CertificateInfo, CertificateInternals, CertificateRevocationListInfo, CertificateSerialNumber, CertificateSigningRequestInfo, ComputeDerivedKeysOptions, CreateSelfSignCertificateOptions, DerivedKeys, DirectoryName, ExtensionRequest, Extensions, Name, PaddingAlgorithm, PrivateKeyInternals, PublicKeyLength, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, RevokedCertificate, Subject, SubjectOptions, SubjectPublicKey, SubjectPublicKeyInfo, TBSCertList, TbsCertificate, Validity, VerifyChunkSignatureOptions, VerifyMessageChunkSignatureOptions, Version, X509ExtKeyUsage, X509KeyUsage, _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 } from './source/index_web.mjs';
1
+ export { AttributeTypeAndValue, AuthorityKeyIdentifier, BasicConstraints, CertificateExtension, CertificateInfo, CertificateInternals, CertificateRevocationListInfo, CertificateSerialNumber, CertificateSigningRequestInfo, ComputeDerivedKeysOptions, CreateSelfSignCertificateOptions, DerivedKeys, DirectoryName, ExtensionRequest, Extensions, Name, PaddingAlgorithm, PrivateKeyInternals, PublicKeyLength, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, RevokedCertificate, Subject, SubjectAltName, SubjectOptions, SubjectPublicKey, SubjectPublicKeyInfo, TBSCertList, TbsCertificate, Validity, VerifyChunkSignatureOptions, VerifyMessageChunkSignatureOptions, Version, X509ExtKeyUsage, X509KeyUsage, _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 } from './source/index_web.mjs';
2
2
  export { CertificateSigningRequest, generatePrivateKeyFile, generatePrivateKeyFileAlternate, getCertificateStore, readCertificate, readCertificatePEM, readCertificateRevocationList, readCertificateSigningRequest, readPrivateKey, readPrivateKeyPEM, readPrivateRsaKey, readPublicKey, readPublicKeyPEM, readPublicRsaKey, setCertificateStore } from './source_nodejs/index.mjs';
3
3
  export { C as Certificate, d as CertificatePEM, h as CertificatePurpose, g as CertificateRevocationList, D as DER, K as KeyObject, N as Nonce, b as PEM, P as PrivateKey, e as PrivateKeyPEM, a as PublicKey, f as PublicKeyPEM, S as Signature, c as createPrivateKeyFromNodeJSCrypto, i as isKeyObject } from './common-DxHkx4Pv.mjs';
4
4
  import 'node:crypto';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { AttributeTypeAndValue, AuthorityKeyIdentifier, BasicConstraints, CertificateExtension, CertificateInfo, CertificateInternals, CertificateRevocationListInfo, CertificateSerialNumber, CertificateSigningRequestInfo, ComputeDerivedKeysOptions, CreateSelfSignCertificateOptions, DerivedKeys, DirectoryName, ExtensionRequest, Extensions, Name, PaddingAlgorithm, PrivateKeyInternals, PublicKeyLength, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, RevokedCertificate, Subject, SubjectOptions, SubjectPublicKey, SubjectPublicKeyInfo, TBSCertList, TbsCertificate, Validity, VerifyChunkSignatureOptions, VerifyMessageChunkSignatureOptions, Version, X509ExtKeyUsage, X509KeyUsage, _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 } from './source/index_web.js';
1
+ export { AttributeTypeAndValue, AuthorityKeyIdentifier, BasicConstraints, CertificateExtension, CertificateInfo, CertificateInternals, CertificateRevocationListInfo, CertificateSerialNumber, CertificateSigningRequestInfo, ComputeDerivedKeysOptions, CreateSelfSignCertificateOptions, DerivedKeys, DirectoryName, ExtensionRequest, Extensions, Name, PaddingAlgorithm, PrivateKeyInternals, PublicKeyLength, RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING, RevokedCertificate, Subject, SubjectAltName, SubjectOptions, SubjectPublicKey, SubjectPublicKeyInfo, TBSCertList, TbsCertificate, Validity, VerifyChunkSignatureOptions, VerifyMessageChunkSignatureOptions, Version, X509ExtKeyUsage, X509KeyUsage, _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 } from './source/index_web.js';
2
2
  export { CertificateSigningRequest, generatePrivateKeyFile, generatePrivateKeyFileAlternate, getCertificateStore, readCertificate, readCertificatePEM, readCertificateRevocationList, readCertificateSigningRequest, readPrivateKey, readPrivateKeyPEM, readPrivateRsaKey, readPublicKey, readPublicKeyPEM, readPublicRsaKey, setCertificateStore } from './source_nodejs/index.js';
3
3
  export { C as Certificate, d as CertificatePEM, h as CertificatePurpose, g as CertificateRevocationList, D as DER, K as KeyObject, N as Nonce, b as PEM, P as PrivateKey, e as PrivateKeyPEM, a as PublicKey, f as PublicKeyPEM, S as Signature, c as createPrivateKeyFromNodeJSCrypto, i as isKeyObject } from './common-DxHkx4Pv.js';
4
4
  import 'node:crypto';
package/dist/index.js CHANGED
@@ -69,6 +69,7 @@ __export(index_exports, {
69
69
  getCertificateStore: () => getCertificateStore,
70
70
  hexDump: () => hexDump,
71
71
  identifyPemType: () => identifyPemType,
72
+ isCrlIssuedByCertificate: () => isCrlIssuedByCertificate,
72
73
  isKeyObject: () => isKeyObject,
73
74
  makeMessageChunkSignature: () => makeMessageChunkSignature,
74
75
  makeMessageChunkSignatureWithDerivedKeys: () => makeMessageChunkSignatureWithDerivedKeys,
@@ -115,6 +116,7 @@ __export(index_exports, {
115
116
  verifyCertificateSignature: () => verifyCertificateSignature,
116
117
  verifyChunkSignature: () => verifyChunkSignature,
117
118
  verifyChunkSignatureWithDerivedKeys: () => verifyChunkSignatureWithDerivedKeys,
119
+ verifyCrlIssuedByCertificate: () => verifyCrlIssuedByCertificate,
118
120
  verifyMessageChunkSignature: () => verifyMessageChunkSignature
119
121
  });
120
122
  module.exports = __toCommonJS(index_exports);
@@ -703,7 +705,6 @@ function readTime(buffer, block) {
703
705
  var import_node_assert2 = __toESM(require("assert"));
704
706
  var import_node_constants = __toESM(require("constants"));
705
707
  var import_node_crypto2 = require("crypto");
706
- var import_jsrsasign = __toESM(require("jsrsasign"));
707
708
 
708
709
  // source/buffer_utils.ts
709
710
  var createFastUninitializedBuffer = Buffer.allocUnsafe ? Buffer.allocUnsafe : (size) => {
@@ -893,8 +894,8 @@ function coerceCertificatePem(certificate) {
893
894
  }
894
895
  function extractPublicKeyFromCertificateSync(certificate) {
895
896
  certificate = coerceCertificatePem(certificate);
896
- const key = import_jsrsasign.default.KEYUTIL.getKey(certificate);
897
- const publicKeyAsPem = import_jsrsasign.default.KEYUTIL.getPEM(key);
897
+ const publicKeyObject = (0, import_node_crypto2.createPublicKey)(certificate);
898
+ const publicKeyAsPem = publicKeyObject.export({ format: "pem", type: "spki" }).toString();
898
899
  (0, import_node_assert2.default)(typeof publicKeyAsPem === "string");
899
900
  return publicKeyAsPem;
900
901
  }
@@ -1316,13 +1317,154 @@ function combine_der(certificates) {
1316
1317
  return Buffer.concat(certificates);
1317
1318
  }
1318
1319
 
1320
+ // source/explore_certificate_revocation_list.ts
1321
+ function readNameForCrl(buffer, block) {
1322
+ return readDirectoryName(buffer, block);
1323
+ }
1324
+ function _readTbsCertList(buffer, blockInfo) {
1325
+ const blocks = readStruct(buffer, blockInfo);
1326
+ const hasOptionalVersion = blocks[0].tag === 2 /* INTEGER */;
1327
+ if (hasOptionalVersion) {
1328
+ const _version = readIntegerValue(buffer, blocks[0]);
1329
+ const signature = readAlgorithmIdentifier(buffer, blocks[1]);
1330
+ const issuer = readNameForCrl(buffer, blocks[2]);
1331
+ const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[2])));
1332
+ const thisUpdate = readTime(buffer, blocks[3]);
1333
+ const nextUpdate = readTime(buffer, blocks[4]);
1334
+ const revokedCertificates = [];
1335
+ if (blocks[5] && blocks[5].tag < 128) {
1336
+ const list = readStruct(buffer, blocks[5]);
1337
+ for (const r of list) {
1338
+ const rr = readStruct(buffer, r);
1339
+ const userCertificate = formatBuffer2DigitHexWithColum(readLongIntegerValue(buffer, rr[0]));
1340
+ const revocationDate = readTime(buffer, rr[1]);
1341
+ revokedCertificates.push({
1342
+ revocationDate,
1343
+ userCertificate
1344
+ });
1345
+ }
1346
+ }
1347
+ const _ext0 = findBlockAtIndex(blocks, 0);
1348
+ return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates };
1349
+ } else {
1350
+ const signature = readAlgorithmIdentifier(buffer, blocks[0]);
1351
+ const issuer = readNameForCrl(buffer, blocks[1]);
1352
+ const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[1])));
1353
+ const thisUpdate = readTime(buffer, blocks[2]);
1354
+ const nextUpdate = readTime(buffer, blocks[3]);
1355
+ const revokedCertificates = [];
1356
+ if (blocks[4] && blocks[4].tag < 128) {
1357
+ const list = readStruct(buffer, blocks[4]);
1358
+ for (const r of list) {
1359
+ const rr = readStruct(buffer, r);
1360
+ const userCertificate = formatBuffer2DigitHexWithColum(readLongIntegerValue(buffer, rr[0]));
1361
+ const revocationDate = readTime(buffer, rr[1]);
1362
+ revokedCertificates.push({
1363
+ revocationDate,
1364
+ userCertificate
1365
+ });
1366
+ }
1367
+ }
1368
+ return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates };
1369
+ }
1370
+ }
1371
+ function exploreCertificateRevocationList(crl) {
1372
+ const blockInfo = readTag(crl, 0);
1373
+ const blocks = readStruct(crl, blockInfo);
1374
+ const tbsCertList = _readTbsCertList(crl, blocks[0]);
1375
+ const signatureAlgorithm = readAlgorithmIdentifier(crl, blocks[1]);
1376
+ const signatureValue = readSignatureValueBin(crl, blocks[2]);
1377
+ return { tbsCertList, signatureAlgorithm, signatureValue };
1378
+ }
1379
+
1380
+ // source/verify_certificate_signature.ts
1381
+ var import_node_crypto3 = require("crypto");
1382
+ function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
1383
+ const block_info = readTag(certificateOrCrl, 0);
1384
+ const blocks = readStruct(certificateOrCrl, block_info);
1385
+ const bufferToBeSigned = certificateOrCrl.subarray(block_info.position, blocks[1].position - 2);
1386
+ const signatureAlgorithm = readAlgorithmIdentifier(certificateOrCrl, blocks[1]);
1387
+ const signatureValue = readSignatureValueBin(certificateOrCrl, blocks[2]);
1388
+ const p = split_der(parentCertificate)[0];
1389
+ const certPem = toPem(p, "CERTIFICATE");
1390
+ const verify = (0, import_node_crypto3.createVerify)(signatureAlgorithm.identifier);
1391
+ verify.update(bufferToBeSigned);
1392
+ verify.end();
1393
+ return verify.verify(certPem, signatureValue);
1394
+ }
1395
+ function verifyCertificateSignature(certificate, parentCertificate) {
1396
+ return verifyCertificateOrClrSignature(certificate, parentCertificate);
1397
+ }
1398
+ function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
1399
+ return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
1400
+ }
1401
+ async function verifyCertificateChain(certificateChain) {
1402
+ for (let index = 1; index < certificateChain.length; index++) {
1403
+ const cert = certificateChain[index - 1];
1404
+ const certParent = certificateChain[index];
1405
+ const certParentInfo = exploreCertificate(certParent);
1406
+ const keyUsage = certParentInfo.tbsCertificate.extensions?.keyUsage;
1407
+ if (!keyUsage || !keyUsage.keyCertSign) {
1408
+ return {
1409
+ status: "BadCertificateIssuerUseNotAllowed",
1410
+ reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing"
1411
+ };
1412
+ }
1413
+ const parentSignChild = verifyCertificateSignature(cert, certParent);
1414
+ if (!parentSignChild) {
1415
+ return {
1416
+ status: "BadCertificateInvalid",
1417
+ reason: "One of the certificate in the chain is not signing the previous certificate"
1418
+ };
1419
+ }
1420
+ const certInfo = exploreCertificate(cert);
1421
+ if (!certInfo.tbsCertificate.extensions) {
1422
+ return {
1423
+ status: "BadCertificateInvalid",
1424
+ reason: "Cannot find X409 Extension 3 in certificate"
1425
+ };
1426
+ }
1427
+ if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
1428
+ return {
1429
+ status: "BadCertificateInvalid",
1430
+ reason: "Cannot find X409 Extension 3 in certificate (parent)"
1431
+ };
1432
+ }
1433
+ if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !== certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
1434
+ return {
1435
+ status: "BadCertificateInvalid",
1436
+ reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate"
1437
+ };
1438
+ }
1439
+ }
1440
+ return {
1441
+ status: "Good",
1442
+ reason: `certificate chain is valid(length = ${certificateChain.length})`
1443
+ };
1444
+ }
1445
+
1446
+ // source/crl_utils.ts
1447
+ function isCrlIssuedByCertificate(crl, certificate) {
1448
+ const crlInfo = exploreCertificateRevocationList(crl);
1449
+ const certInfo = exploreCertificate(certificate);
1450
+ return crlInfo.tbsCertList.issuerFingerprint === certInfo.tbsCertificate.subjectFingerPrint;
1451
+ }
1452
+ function verifyCrlIssuedByCertificate(crl, certificate) {
1453
+ if (!isCrlIssuedByCertificate(crl, certificate)) {
1454
+ return false;
1455
+ }
1456
+ return verifyCertificateRevocationListSignature(crl, certificate);
1457
+ }
1458
+
1319
1459
  // source/crypto_utils2.ts
1320
1460
  var import_node_assert5 = __toESM(require("assert"));
1321
- var import_jsrsasign2 = __toESM(require("jsrsasign"));
1461
+ var import_node_crypto4 = require("crypto");
1322
1462
  function rsaLengthPrivateKey(key) {
1323
1463
  const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
1324
- const a = import_jsrsasign2.default.KEYUTIL.getKey(keyPem);
1325
- return a.n.toString(16).length / 2;
1464
+ const keyObject = (0, import_node_crypto4.createPrivateKey)(keyPem);
1465
+ const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
1466
+ (0, import_node_assert5.default)(modulusLength, "Cannot determine modulus length from private key");
1467
+ return modulusLength / 8;
1326
1468
  }
1327
1469
  function toPem2(raw_key, pem) {
1328
1470
  if (raw_key.hidden) {
@@ -1362,19 +1504,23 @@ function coerceRsaPublicKeyPem(publicKey) {
1362
1504
  function rsaLengthPublicKey(key) {
1363
1505
  key = coercePublicKeyPem(key);
1364
1506
  (0, import_node_assert5.default)(typeof key === "string");
1365
- const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
1366
- return a.n.toString(16).length / 2;
1507
+ const keyObject = (0, import_node_crypto4.createPublicKey)(key);
1508
+ const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
1509
+ (0, import_node_assert5.default)(modulusLength, "Cannot determine modulus length from public key");
1510
+ return modulusLength / 8;
1367
1511
  }
1368
1512
  function rsaLengthRsaPublicKey(key) {
1369
1513
  key = coerceRsaPublicKeyPem(key);
1370
1514
  (0, import_node_assert5.default)(typeof key === "string");
1371
- const a = import_jsrsasign2.default.KEYUTIL.getKey(key);
1372
- return a.n.toString(16).length / 2;
1515
+ const keyObject = (0, import_node_crypto4.createPublicKey)(key);
1516
+ const modulusLength = keyObject.asymmetricKeyDetails?.modulusLength;
1517
+ (0, import_node_assert5.default)(modulusLength, "Cannot determine modulus length from public key");
1518
+ return modulusLength / 8;
1373
1519
  }
1374
1520
 
1375
1521
  // source/derived_keys.ts
1376
1522
  var import_node_assert7 = __toESM(require("assert"));
1377
- var import_node_crypto3 = require("crypto");
1523
+ var import_node_crypto5 = require("crypto");
1378
1524
 
1379
1525
  // source/explore_certificate.ts
1380
1526
  var import_node_assert6 = __toESM(require("assert"));
@@ -1403,7 +1549,7 @@ function exploreCertificateInfo(certificate) {
1403
1549
 
1404
1550
  // source/derived_keys.ts
1405
1551
  function HMAC_HASH(sha1or256, secret, message) {
1406
- return (0, import_node_crypto3.createHmac)(sha1or256, secret).update(message).digest();
1552
+ return (0, import_node_crypto5.createHmac)(sha1or256, secret).update(message).digest();
1407
1553
  }
1408
1554
  function plus(buf1, buf2) {
1409
1555
  return Buffer.concat([buf1, buf2]);
@@ -1480,7 +1626,7 @@ function encryptBufferWithDerivedKeys(buffer, derivedKeys) {
1480
1626
  const algorithm = derivedKeys_algorithm(derivedKeys);
1481
1627
  const key = derivedKeys.encryptingKey;
1482
1628
  const initVector = derivedKeys.initializationVector;
1483
- const cipher = (0, import_node_crypto3.createCipheriv)(algorithm, key, initVector);
1629
+ const cipher = (0, import_node_crypto5.createCipheriv)(algorithm, key, initVector);
1484
1630
  cipher.setAutoPadding(false);
1485
1631
  const encrypted_chunks = [];
1486
1632
  encrypted_chunks.push(cipher.update(buffer));
@@ -1491,7 +1637,7 @@ function decryptBufferWithDerivedKeys(buffer, derivedKeys) {
1491
1637
  const algorithm = derivedKeys_algorithm(derivedKeys);
1492
1638
  const key = derivedKeys.encryptingKey;
1493
1639
  const initVector = derivedKeys.initializationVector;
1494
- const cipher = (0, import_node_crypto3.createDecipheriv)(algorithm, key, initVector);
1640
+ const cipher = (0, import_node_crypto5.createDecipheriv)(algorithm, key, initVector);
1495
1641
  cipher.setAutoPadding(false);
1496
1642
  const decrypted_chunks = [];
1497
1643
  decrypted_chunks.push(cipher.update(buffer));
@@ -1503,7 +1649,7 @@ function makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys) {
1503
1649
  (0, import_node_assert7.default)(Buffer.isBuffer(derivedKeys.signingKey));
1504
1650
  (0, import_node_assert7.default)(typeof derivedKeys.sha1or256 === "string");
1505
1651
  (0, import_node_assert7.default)(derivedKeys.sha1or256 === "SHA1" || derivedKeys.sha1or256 === "SHA256");
1506
- const signature = (0, import_node_crypto3.createHmac)(derivedKeys.sha1or256, derivedKeys.signingKey).update(message).digest();
1652
+ const signature = (0, import_node_crypto5.createHmac)(derivedKeys.sha1or256, derivedKeys.signingKey).update(message).digest();
1507
1653
  (0, import_node_assert7.default)(signature.length === derivedKeys.signatureLength);
1508
1654
  return signature;
1509
1655
  }
@@ -1541,66 +1687,6 @@ function exploreAsn1(buffer) {
1541
1687
  dump(0, 0);
1542
1688
  }
1543
1689
 
1544
- // source/explore_certificate_revocation_list.ts
1545
- function readNameForCrl(buffer, block) {
1546
- return readDirectoryName(buffer, block);
1547
- }
1548
- function _readTbsCertList(buffer, blockInfo) {
1549
- const blocks = readStruct(buffer, blockInfo);
1550
- const hasOptionalVersion = blocks[0].tag === 2 /* INTEGER */;
1551
- if (hasOptionalVersion) {
1552
- const _version = readIntegerValue(buffer, blocks[0]);
1553
- const signature = readAlgorithmIdentifier(buffer, blocks[1]);
1554
- const issuer = readNameForCrl(buffer, blocks[2]);
1555
- const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[2])));
1556
- const thisUpdate = readTime(buffer, blocks[3]);
1557
- const nextUpdate = readTime(buffer, blocks[4]);
1558
- const revokedCertificates = [];
1559
- if (blocks[5] && blocks[5].tag < 128) {
1560
- const list = readStruct(buffer, blocks[5]);
1561
- for (const r of list) {
1562
- const rr = readStruct(buffer, r);
1563
- const userCertificate = formatBuffer2DigitHexWithColum(readLongIntegerValue(buffer, rr[0]));
1564
- const revocationDate = readTime(buffer, rr[1]);
1565
- revokedCertificates.push({
1566
- revocationDate,
1567
- userCertificate
1568
- });
1569
- }
1570
- }
1571
- const _ext0 = findBlockAtIndex(blocks, 0);
1572
- return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates };
1573
- } else {
1574
- const signature = readAlgorithmIdentifier(buffer, blocks[0]);
1575
- const issuer = readNameForCrl(buffer, blocks[1]);
1576
- const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(getBlock(buffer, blocks[1])));
1577
- const thisUpdate = readTime(buffer, blocks[2]);
1578
- const nextUpdate = readTime(buffer, blocks[3]);
1579
- const revokedCertificates = [];
1580
- if (blocks[4] && blocks[4].tag < 128) {
1581
- const list = readStruct(buffer, blocks[4]);
1582
- for (const r of list) {
1583
- const rr = readStruct(buffer, r);
1584
- const userCertificate = formatBuffer2DigitHexWithColum(readLongIntegerValue(buffer, rr[0]));
1585
- const revocationDate = readTime(buffer, rr[1]);
1586
- revokedCertificates.push({
1587
- revocationDate,
1588
- userCertificate
1589
- });
1590
- }
1591
- }
1592
- return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates };
1593
- }
1594
- }
1595
- function exploreCertificateRevocationList(crl) {
1596
- const blockInfo = readTag(crl, 0);
1597
- const blocks = readStruct(crl, blockInfo);
1598
- const tbsCertList = _readTbsCertList(crl, blocks[0]);
1599
- const signatureAlgorithm = readAlgorithmIdentifier(crl, blocks[1]);
1600
- const signatureValue = readSignatureValueBin(crl, blocks[2]);
1601
- return { tbsCertList, signatureAlgorithm, signatureValue };
1602
- }
1603
-
1604
1690
  // source/explore_certificate_signing_request.ts
1605
1691
  function _readExtensionRequest(buffer) {
1606
1692
  const block = readTag(buffer, 0);
@@ -1848,74 +1934,8 @@ var Subject = class _Subject {
1848
1934
  }
1849
1935
  };
1850
1936
 
1851
- // source/verify_certificate_signature.ts
1852
- var import_node_crypto4 = require("crypto");
1853
- function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
1854
- const block_info = readTag(certificateOrCrl, 0);
1855
- const blocks = readStruct(certificateOrCrl, block_info);
1856
- const bufferToBeSigned = certificateOrCrl.subarray(block_info.position, blocks[1].position - 2);
1857
- const signatureAlgorithm = readAlgorithmIdentifier(certificateOrCrl, blocks[1]);
1858
- const signatureValue = readSignatureValueBin(certificateOrCrl, blocks[2]);
1859
- const p = split_der(parentCertificate)[0];
1860
- const certPem = toPem(p, "CERTIFICATE");
1861
- const verify = (0, import_node_crypto4.createVerify)(signatureAlgorithm.identifier);
1862
- verify.update(bufferToBeSigned);
1863
- verify.end();
1864
- return verify.verify(certPem, signatureValue);
1865
- }
1866
- function verifyCertificateSignature(certificate, parentCertificate) {
1867
- return verifyCertificateOrClrSignature(certificate, parentCertificate);
1868
- }
1869
- function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
1870
- return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
1871
- }
1872
- async function verifyCertificateChain(certificateChain) {
1873
- for (let index = 1; index < certificateChain.length; index++) {
1874
- const cert = certificateChain[index - 1];
1875
- const certParent = certificateChain[index];
1876
- const certParentInfo = exploreCertificate(certParent);
1877
- const keyUsage = certParentInfo.tbsCertificate.extensions?.keyUsage;
1878
- if (!keyUsage || !keyUsage.keyCertSign) {
1879
- return {
1880
- status: "BadCertificateIssuerUseNotAllowed",
1881
- reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing"
1882
- };
1883
- }
1884
- const parentSignChild = verifyCertificateSignature(cert, certParent);
1885
- if (!parentSignChild) {
1886
- return {
1887
- status: "BadCertificateInvalid",
1888
- reason: "One of the certificate in the chain is not signing the previous certificate"
1889
- };
1890
- }
1891
- const certInfo = exploreCertificate(cert);
1892
- if (!certInfo.tbsCertificate.extensions) {
1893
- return {
1894
- status: "BadCertificateInvalid",
1895
- reason: "Cannot find X409 Extension 3 in certificate"
1896
- };
1897
- }
1898
- if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
1899
- return {
1900
- status: "BadCertificateInvalid",
1901
- reason: "Cannot find X409 Extension 3 in certificate (parent)"
1902
- };
1903
- }
1904
- if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !== certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
1905
- return {
1906
- status: "BadCertificateInvalid",
1907
- reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate"
1908
- };
1909
- }
1910
- }
1911
- return {
1912
- status: "Good",
1913
- reason: `certificate chain is valid(length = ${certificateChain.length})`
1914
- };
1915
- }
1916
-
1917
1937
  // source/x509/_crypto.ts
1918
- var import_node_crypto5 = __toESM(require("crypto"));
1938
+ var import_node_crypto6 = __toESM(require("crypto"));
1919
1939
  var import_webcrypto = require("@peculiar/webcrypto");
1920
1940
  var x509 = __toESM(require("@peculiar/x509"));
1921
1941
  var x5092 = __toESM(require("@peculiar/x509"));
@@ -1923,7 +1943,7 @@ var doDebug3 = false;
1923
1943
  var _crypto;
1924
1944
  var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
1925
1945
  if (typeof window === "undefined") {
1926
- _crypto = import_node_crypto5.default;
1946
+ _crypto = import_node_crypto6.default;
1927
1947
  if (!_crypto?.subtle || ignoreCrypto) {
1928
1948
  _crypto = new import_webcrypto.Crypto();
1929
1949
  doDebug3 && console.warn("using @peculiar/webcrypto");
@@ -1937,7 +1957,7 @@ if (typeof window === "undefined") {
1937
1957
  x509.cryptoProvider.set(crypto);
1938
1958
  }
1939
1959
  function getCrypto() {
1940
- return _crypto || crypto || import_node_crypto5.default;
1960
+ return _crypto || crypto || import_node_crypto6.default;
1941
1961
  }
1942
1962
 
1943
1963
  // source/x509/create_key_pair.ts
@@ -6440,8 +6460,8 @@ async function createSelfSignedCertificate({
6440
6460
  var asn1 = { readDirectoryName, readTag, readStruct, readAlgorithmIdentifier, readSignatureValueBin };
6441
6461
 
6442
6462
  // source_nodejs/generate_private_key_filename.ts
6463
+ var import_node_crypto7 = require("crypto");
6443
6464
  var import_node_fs = __toESM(require("fs"));
6444
- var import_jsrsasign3 = __toESM(require("jsrsasign"));
6445
6465
  async function generatePrivateKeyFile(privateKeyFilename, modulusLength) {
6446
6466
  const keys = await generateKeyPair(modulusLength);
6447
6467
  const privateKeyPem = await privateKeyToPEM(keys.privateKey);
@@ -6450,16 +6470,17 @@ async function generatePrivateKeyFile(privateKeyFilename, modulusLength) {
6450
6470
  privateKeyPem.privDer = new ArrayBuffer(0);
6451
6471
  }
6452
6472
  async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength) {
6453
- const kp = import_jsrsasign3.default.KEYUTIL.generateKeypair("RSA", modulusLength);
6454
- const prv = kp.prvKeyObj;
6455
- const _pub = kp.pubKeyObj;
6456
- const prvpem = import_jsrsasign3.default.KEYUTIL.getPEM(prv, "PKCS8PRV");
6457
- await import_node_fs.default.promises.writeFile(privateKeyFilename, prvpem, "utf-8");
6473
+ const { privateKey } = (0, import_node_crypto7.generateKeyPairSync)("rsa", {
6474
+ modulusLength,
6475
+ privateKeyEncoding: { type: "pkcs8", format: "pem" },
6476
+ publicKeyEncoding: { type: "spki", format: "pem" }
6477
+ });
6478
+ await import_node_fs.default.promises.writeFile(privateKeyFilename, privateKey, "utf-8");
6458
6479
  }
6459
6480
 
6460
6481
  // source_nodejs/read.ts
6461
6482
  var import_node_assert8 = __toESM(require("assert"));
6462
- var import_node_crypto6 = require("crypto");
6483
+ var import_node_crypto8 = require("crypto");
6463
6484
  var import_node_fs2 = __toESM(require("fs"));
6464
6485
  var import_node_path = __toESM(require("path"));
6465
6486
  var import_sshpk = __toESM(require("sshpk"));
@@ -6480,14 +6501,14 @@ function readCertificate(filename) {
6480
6501
  function readPublicKey(filename) {
6481
6502
  if (filename.match(/.*\.der/)) {
6482
6503
  const der = import_node_fs2.default.readFileSync(filename);
6483
- return (0, import_node_crypto6.createPublicKey)(der);
6504
+ return (0, import_node_crypto8.createPublicKey)(der);
6484
6505
  } else {
6485
6506
  const raw_key = _readPemFile(filename);
6486
- return (0, import_node_crypto6.createPublicKey)(raw_key);
6507
+ return (0, import_node_crypto8.createPublicKey)(raw_key);
6487
6508
  }
6488
6509
  }
6489
6510
  function myCreatePrivateKey(rawKey) {
6490
- if (!import_node_crypto6.createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) {
6511
+ if (!import_node_crypto8.createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) {
6491
6512
  if (Buffer.isBuffer(rawKey)) {
6492
6513
  const pemKey = toPem(rawKey, "PRIVATE KEY");
6493
6514
  (0, import_node_assert8.default)(["RSA PRIVATE KEY", "PRIVATE KEY"].indexOf(identifyPemType(pemKey)) >= 0);
@@ -6497,7 +6518,7 @@ function myCreatePrivateKey(rawKey) {
6497
6518
  }
6498
6519
  const backup = process.env.OPENSSL_CONF;
6499
6520
  process.env.OPENSSL_CONF = "/dev/null";
6500
- const retValue = (0, import_node_crypto6.createPrivateKey)(rawKey);
6521
+ const retValue = (0, import_node_crypto8.createPrivateKey)(rawKey);
6501
6522
  process.env.OPENSSL_CONF = backup;
6502
6523
  return { hidden: retValue };
6503
6524
  }
@@ -6536,7 +6557,7 @@ function getCertificateStore() {
6536
6557
  return _g_certificate_store;
6537
6558
  }
6538
6559
  function readPrivateRsaKey(filename) {
6539
- if (!import_node_crypto6.createPrivateKey) {
6560
+ if (!import_node_crypto8.createPrivateKey) {
6540
6561
  throw new Error("createPrivateKey is not supported in this environment");
6541
6562
  }
6542
6563
  if (filename.substring(0, 1) !== "." && !import_node_fs2.default.existsSync(filename)) {
@@ -6545,7 +6566,7 @@ function readPrivateRsaKey(filename) {
6545
6566
  const content = import_node_fs2.default.readFileSync(filename, "utf8");
6546
6567
  const sshKey = import_sshpk.default.parsePrivateKey(content, "auto");
6547
6568
  const key = sshKey.toString("pkcs1");
6548
- const hidden = (0, import_node_crypto6.createPrivateKey)({ format: "pem", type: "pkcs1", key });
6569
+ const hidden = (0, import_node_crypto8.createPrivateKey)({ format: "pem", type: "pkcs1", key });
6549
6570
  return { hidden };
6550
6571
  }
6551
6572
  function readPublicRsaKey(filename) {
@@ -6555,7 +6576,7 @@ function readPublicRsaKey(filename) {
6555
6576
  const content = import_node_fs2.default.readFileSync(filename, "utf-8");
6556
6577
  const sshKey = import_sshpk.default.parseKey(content, "ssh");
6557
6578
  const key = sshKey.toString("pkcs1");
6558
- return (0, import_node_crypto6.createPublicKey)({ format: "pem", type: "pkcs1", key });
6579
+ return (0, import_node_crypto8.createPublicKey)({ format: "pem", type: "pkcs1", key });
6559
6580
  }
6560
6581
 
6561
6582
  // source_nodejs/read_certificate_revocation_list.ts
@@ -6620,6 +6641,7 @@ async function readCertificateSigningRequest(filename) {
6620
6641
  getCertificateStore,
6621
6642
  hexDump,
6622
6643
  identifyPemType,
6644
+ isCrlIssuedByCertificate,
6623
6645
  isKeyObject,
6624
6646
  makeMessageChunkSignature,
6625
6647
  makeMessageChunkSignatureWithDerivedKeys,
@@ -6666,6 +6688,7 @@ async function readCertificateSigningRequest(filename) {
6666
6688
  verifyCertificateSignature,
6667
6689
  verifyChunkSignature,
6668
6690
  verifyChunkSignatureWithDerivedKeys,
6691
+ verifyCrlIssuedByCertificate,
6669
6692
  verifyMessageChunkSignature
6670
6693
  });
6671
6694
  /*! Bundled license information: