Skip to content

Commit f96689a

Browse files
committed
chore: add Cert interface
1 parent f915923 commit f96689a

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

src/certificate.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,14 @@ export async function generateCert(options?: CertOption): Promise<GenerateCertRe
198198
}
199199
}
200200

201-
export async function addCertToSystemTrustStoreAndSaveCerts(
202-
cert: { certificate: string, privateKey: string },
203-
CAcert: string,
204-
options?: AddCertOption,
205-
): Promise<string> {
201+
interface Cert {
202+
certificate: string
203+
privateKey: string
204+
}
205+
206+
export async function addCertToSystemTrustStoreAndSaveCerts(cert: Cert, caCert: string, options?: AddCertOption): Promise<string> {
206207
const certPath = storeCert(cert, options)
207-
const caCertPath = storeCACert(CAcert, options)
208+
const caCertPath = storeCACert(caCert, options)
208209

209210
const platform = os.platform()
210211
const args = 'TC, C, C'
@@ -241,24 +242,6 @@ export async function addCertToSystemTrustStoreAndSaveCerts(
241242

242243
log.info(`Cert added to ${folder}`)
243244
}
244-
245-
// await runCommands([
246-
// `sudo cp ${certPath} /usr/local/share/ca-certificates/`,
247-
248-
// // add new cert to system trust store
249-
// `certutil -d sql:${os.homedir()}/.pki/nssdb -A -t ${args} -n ${config.commonName} -i ${caCertPath}`,
250-
251-
// // add new cert to system trust store for Brave
252-
// `certutil -d sql:${os.homedir()}/snap/brave/411/.pki/nssdb -A -t ${args} -n ${config.commonName} -i ${caCertPath}`,
253-
254-
// // add new cert to system trust store for Firefox
255-
// `certutil -d sql:${os.homedir()}/snap/firefox/common/.mozilla/firefox/3l148raz.default -A -t ${args} -n ${config.commonName} -i ${caCertPath}`,
256-
257-
// // reload system trust store
258-
// `sudo update-ca-certificates`,
259-
// ]).catch((err) => {
260-
// throw new Error(err)
261-
// })
262245
}
263246
else {
264247
throw new Error(`Unsupported platform: ${platform}`)
@@ -267,7 +250,7 @@ export async function addCertToSystemTrustStoreAndSaveCerts(
267250
return certPath
268251
}
269252

270-
export function storeCert(cert: { certificate: string, privateKey: string }, options?: AddCertOption): string {
253+
export function storeCert(cert: Cert, options?: AddCertOption): string {
271254
// Construct the path using os.homedir() and path.join()
272255
const certPath = options?.customCertPath || config.certPath
273256
const certKeyPath = options?.customCertPath || config.keyPath
@@ -295,7 +278,7 @@ export function storeCert(cert: { certificate: string, privateKey: string }, opt
295278
* @param options - The options for storing the CA Certificate
296279
* @returns The path to the CA Certificate
297280
*/
298-
export function storeCACert(CAcert: string, options?: AddCertOption): string {
281+
export function storeCACert(caCert: string, options?: AddCertOption): string {
299282
// Construct the path using os.homedir() and path.join()
300283
const caCertPath = options?.customCertPath || config.caCertPath
301284

@@ -304,7 +287,7 @@ export function storeCACert(CAcert: string, options?: AddCertOption): string {
304287
if (!fs.existsSync(caCertDir))
305288
fs.mkdirSync(caCertDir, { recursive: true })
306289

307-
fs.writeFileSync(caCertPath, CAcert)
290+
fs.writeFileSync(caCertPath, caCert)
308291

309292
return caCertPath
310293
}

0 commit comments

Comments
 (0)