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

export function removeNewLines(string: string) {
  return string.replaceAll(/\r?\n|\r/g, '');
}

export function readCerts() {
  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;
}