aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/certs-helpers.ts
blob: a6c83f5c41066f62899f3470540fb64fcaf34ba2 (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 { readdirSync, readFileSync, ensureDirSync } from 'fs-extra';
import { join } from 'node:path';
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));
}