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