use node:tls library for ca certs (#5552)

This commit is contained in:
lohit
2025-09-12 20:29:28 +05:30
committed by lohit-bruno
parent b02639d30a
commit 66bcbf00ea
4 changed files with 6 additions and 80 deletions

View File

@@ -27,7 +27,6 @@
"axios": "^1.9.0",
"grpc-reflection-js": "^0.3.0",
"is-ip": "^5.0.1",
"system-ca": "^2.0.1",
"tough-cookie": "^6.0.0"
},
"devDependencies": {

View File

@@ -39,6 +39,6 @@ module.exports = [
typescript({ tsconfig: './tsconfig.json' }),
terser(),
],
external: ['axios', 'qs', 'system-ca']
external: ['axios', 'qs']
}
];

View File

@@ -1,5 +1,4 @@
import { systemCertsAsync, Options as SystemCAOptions } from 'system-ca';
import { rootCertificates } from 'node:tls';
import * as tls from 'node:tls';
import * as fs from 'node:fs';
type T_CACertificatesOptions = {
@@ -19,11 +18,11 @@ type T_CACertificatesResult = {
let systemCertsCache: string[] | undefined;
async function getSystemCerts(systemCAOpts: SystemCAOptions = {}): Promise<string[]> {
async function getSystemCerts(): Promise<string[]> {
if (systemCertsCache) return systemCertsCache;
try {
systemCertsCache = await systemCertsAsync(systemCAOpts);
systemCertsCache = tls.getCACertificates('system');
return systemCertsCache;
} catch (error) {
@@ -131,7 +130,7 @@ const getCACertificates = async ({ caCertFilePath, shouldKeepDefaultCerts = true
caCertificatesCount.system = systemCerts.length;
// get root certs
rootCerts = [...rootCertificates];
rootCerts = [...tls.rootCertificates];
caCertificatesCount.root = rootCerts.length;
}
} else {
@@ -140,7 +139,7 @@ const getCACertificates = async ({ caCertFilePath, shouldKeepDefaultCerts = true
caCertificatesCount.system = systemCerts.length;
// get root certs
rootCerts = [...rootCertificates];
rootCerts = [...tls.rootCertificates];
caCertificatesCount.root = rootCerts.length;
}