diff options
Diffstat (limited to 'src/helpers')
-rw-r--r-- | src/helpers/certs-helpers.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/helpers/certs-helpers.ts b/src/helpers/certs-helpers.ts new file mode 100644 index 000000000..a81e7e365 --- /dev/null +++ b/src/helpers/certs-helpers.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import { readdirSync, readFileSync, ensureDirSync } from 'fs-extra'; | ||
2 | import { join } from 'node:path'; | ||
3 | import { userDataCertsPath } from '../environment-remote'; | ||
4 | |||
5 | export function removeNewLines(string: string) { | ||
6 | return string.replaceAll(/\r?\n|\r/g, ''); | ||
7 | } | ||
8 | |||
9 | export function readCerts() { | ||
10 | const certsFolder = userDataCertsPath(); | ||
11 | |||
12 | ensureDirSync(certsFolder); | ||
13 | |||
14 | const certs: string[] = []; | ||
15 | |||
16 | for (const file of readdirSync(certsFolder)) { | ||
17 | const cert = readFileSync(join(certsFolder, file), { | ||
18 | encoding: 'utf8', | ||
19 | flag: 'r', | ||
20 | }); | ||
21 | certs.push(removeNewLines(cert)); | ||
22 | } | ||
23 | |||
24 | return certs; | ||
25 | } | ||