aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/certs-helpers.ts
blob: fdbc495bc7deb4b66da01c5f0bee73a062d0b33e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { join } from 'node:path';
import { ensureDirSync, readFileSync, readdirSync } from 'fs-extra';
import { userDataCertsPath } from '../environment-remote';
import { removeNewLines } from '../jsUtils';

export function checkIfCertIsPresent(certData: string): boolean {
  const certsFolder = userDataCertsPath();

  ensureDirSync(certsFolder);

  const certs: string[] = [];

  for (const file of readdirSync(certsFolder)) {
    const cert = readFileSync(join(certsFolder, file), {
      encoding: 'utf8',
      flag: 'r',
    });
    certs.push(removeNewLines(cert));
  }

  return certs.length > 0 && certs.includes(removeNewLines(certData));
}