@jsenv/https-local 3.0.7 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +160 -192
  2. package/package.json +10 -30
  3. package/src/certificate_authority.js +111 -110
  4. package/src/certificate_request.js +37 -36
  5. package/src/hosts_file_verif.js +34 -35
  6. package/src/https_local_cli.mjs +74 -0
  7. package/src/internal/authority_file_infos.js +12 -13
  8. package/src/internal/browser_detection.js +4 -4
  9. package/src/internal/certificate_authority_file_urls.js +23 -23
  10. package/src/internal/certificate_data_converter.js +39 -39
  11. package/src/internal/certificate_generator.js +39 -39
  12. package/src/internal/command.js +6 -6
  13. package/src/internal/exec.js +10 -10
  14. package/src/internal/forge.js +3 -3
  15. package/src/internal/hosts/hosts_utils.js +2 -2
  16. package/src/internal/hosts/parse_hosts.js +67 -66
  17. package/src/internal/hosts/read_hosts.js +5 -6
  18. package/src/internal/hosts/write_hosts.js +29 -31
  19. package/src/internal/hosts/write_line_hosts.js +30 -32
  20. package/src/internal/hosts.js +5 -5
  21. package/src/internal/linux/chrome_linux.js +19 -20
  22. package/src/internal/linux/firefox_linux.js +19 -20
  23. package/src/internal/linux/linux.js +8 -8
  24. package/src/internal/linux/linux_trust_store.js +58 -59
  25. package/src/internal/linux/nss_linux.js +20 -21
  26. package/src/internal/mac/chrome_mac.js +15 -16
  27. package/src/internal/mac/firefox_mac.js +20 -21
  28. package/src/internal/mac/mac.js +10 -10
  29. package/src/internal/mac/mac_keychain.js +46 -47
  30. package/src/internal/mac/nss_mac.js +29 -30
  31. package/src/internal/mac/safari.js +2 -2
  32. package/src/internal/memoize.js +14 -14
  33. package/src/internal/nssdb_browser.js +150 -145
  34. package/src/internal/platform.js +6 -6
  35. package/src/internal/search_certificate_in_command_output.js +4 -4
  36. package/src/internal/trust_query.js +4 -4
  37. package/src/internal/unsupported_platform/unsupported_platform.js +5 -5
  38. package/src/internal/validity_formatting.js +32 -32
  39. package/src/internal/windows/chrome_windows.js +26 -27
  40. package/src/internal/windows/edge.js +2 -2
  41. package/src/internal/windows/firefox_windows.js +31 -32
  42. package/src/internal/windows/windows.js +10 -10
  43. package/src/internal/windows/windows_certutil.js +41 -42
  44. package/src/jsenvParameters.js +2 -2
  45. package/src/main.js +5 -8
  46. package/src/validity_duration.js +12 -12
@@ -1,37 +1,36 @@
1
- import { fileURLToPath } from "node:url"
2
- import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
3
- import { UNICODE } from "@jsenv/log"
1
+ import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem";
2
+ import { UNICODE } from "@jsenv/humanize";
3
+ import { fileURLToPath } from "node:url";
4
+ import { commandExists } from "../command.js";
5
+ import { exec } from "../exec.js";
6
+ import { memoize } from "../memoize.js";
4
7
 
5
- import { memoize } from "../memoize.js"
6
- import { exec } from "../exec.js"
7
- import { commandExists } from "../command.js"
8
-
9
- export const nssCommandName = "nss"
8
+ export const nssCommandName = "nss";
10
9
 
11
10
  export const detectIfNSSIsInstalled = async ({ logger }) => {
12
- logger.debug(`Detecting if nss is installed....`)
13
- const brewListCommand = `brew list --versions nss`
11
+ logger.debug(`Detecting if nss is installed....`);
12
+ const brewListCommand = `brew list --versions nss`;
14
13
 
15
14
  try {
16
- await exec(brewListCommand)
17
- logger.debug(`${UNICODE.OK} nss is installed`)
18
- return true
19
- } catch (e) {
20
- logger.debug(`${UNICODE.INFO} nss not installed`)
21
- return false
15
+ await exec(brewListCommand);
16
+ logger.debug(`${UNICODE.OK} nss is installed`);
17
+ return true;
18
+ } catch {
19
+ logger.debug(`${UNICODE.INFO} nss not installed`);
20
+ return false;
22
21
  }
23
- }
22
+ };
24
23
 
25
24
  export const getCertutilBinPath = memoize(async () => {
26
- const brewCommand = `brew --prefix nss`
27
- const brewCommandOutput = await exec(brewCommand)
25
+ const brewCommand = `brew --prefix nss`;
26
+ const brewCommandOutput = await exec(brewCommand);
28
27
  const nssCommandDirectoryUrl = assertAndNormalizeDirectoryUrl(
29
28
  brewCommandOutput.trim(),
30
- )
31
- const certutilBinUrl = new URL(`./bin/certutil`, nssCommandDirectoryUrl).href
32
- const certutilBinPath = fileURLToPath(certutilBinUrl)
33
- return certutilBinPath
34
- })
29
+ );
30
+ const certutilBinUrl = new URL(`./bin/certutil`, nssCommandDirectoryUrl).href;
31
+ const certutilBinPath = fileURLToPath(certutilBinUrl);
32
+ return certutilBinPath;
33
+ });
35
34
 
36
35
  export const getNSSDynamicInstallInfo = () => {
37
36
  return {
@@ -39,12 +38,12 @@ export const getNSSDynamicInstallInfo = () => {
39
38
  notInstallableReason: `"brew" is not available`,
40
39
  suggestion: `install "brew" on this mac`,
41
40
  install: async ({ logger }) => {
42
- const brewInstallCommand = `brew install nss`
41
+ const brewInstallCommand = `brew install nss`;
43
42
  logger.info(
44
43
  `"nss" is not installed, trying to install "nss" via Homebrew`,
45
- )
46
- logger.info(`${UNICODE.COMMAND} ${brewInstallCommand}`)
47
- await exec(brewInstallCommand)
44
+ );
45
+ logger.info(`${UNICODE.COMMAND} ${brewInstallCommand}`);
46
+ await exec(brewInstallCommand);
48
47
  },
49
- }
50
- }
48
+ };
49
+ };
@@ -2,5 +2,5 @@ export const executeTrustQueryOnSafari = ({ macTrustInfo }) => {
2
2
  return {
3
3
  status: macTrustInfo.status,
4
4
  reason: macTrustInfo.reason,
5
- }
6
- }
5
+ };
6
+ };
@@ -1,24 +1,24 @@
1
1
  export const memoize = (compute) => {
2
- let memoized = false
3
- let memoizedValue
2
+ let memoized = false;
3
+ let memoizedValue;
4
4
 
5
5
  const fnWithMemoization = (...args) => {
6
6
  if (memoized) {
7
- return memoizedValue
7
+ return memoizedValue;
8
8
  }
9
9
  // if compute is recursive wait for it to be fully done before storing the lockValue
10
10
  // so set locked later
11
- memoizedValue = compute(...args)
12
- memoized = true
13
- return memoizedValue
14
- }
11
+ memoizedValue = compute(...args);
12
+ memoized = true;
13
+ return memoizedValue;
14
+ };
15
15
 
16
16
  fnWithMemoization.forget = () => {
17
- const value = memoizedValue
18
- memoized = false
19
- memoizedValue = undefined
20
- return value
21
- }
17
+ const value = memoizedValue;
18
+ memoized = false;
19
+ memoizedValue = undefined;
20
+ return value;
21
+ };
22
22
 
23
- return fnWithMemoization
24
- }
23
+ return fnWithMemoization;
24
+ };
@@ -3,20 +3,22 @@
3
3
  * Certutil command documentation: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/tools/NSS_Tools_certutil
4
4
  */
5
5
 
6
- import { existsSync } from "node:fs"
7
- import { fileURLToPath } from "node:url"
8
- import { urlToFilename } from "@jsenv/urls"
9
- import { createDetailedMessage, UNICODE } from "@jsenv/log"
10
- import { assertAndNormalizeDirectoryUrl, collectFiles } from "@jsenv/filesystem"
11
-
12
- import { detectBrowser } from "./browser_detection.js"
13
- import { exec } from "./exec.js"
14
- import { searchCertificateInCommandOutput } from "./search_certificate_in_command_output.js"
15
6
  import {
16
- VERB_CHECK_TRUST,
7
+ assertAndNormalizeDirectoryUrl,
8
+ collectFiles,
9
+ } from "@jsenv/filesystem";
10
+ import { createDetailedMessage, UNICODE } from "@jsenv/humanize";
11
+ import { urlToFilename } from "@jsenv/urls";
12
+ import { existsSync } from "node:fs";
13
+ import { fileURLToPath } from "node:url";
14
+ import { detectBrowser } from "./browser_detection.js";
15
+ import { exec } from "./exec.js";
16
+ import { searchCertificateInCommandOutput } from "./search_certificate_in_command_output.js";
17
+ import {
17
18
  VERB_ADD_TRUST,
19
+ VERB_CHECK_TRUST,
18
20
  VERB_ENSURE_TRUST,
19
- } from "./trust_query.js"
21
+ } from "./trust_query.js";
20
22
 
21
23
  export const executeTrustQueryOnBrowserNSSDB = async ({
22
24
  logger,
@@ -37,34 +39,34 @@ export const executeTrustQueryOnBrowserNSSDB = async ({
37
39
  browserNSSDBDirectoryUrls,
38
40
  getBrowserClosedPromise,
39
41
  }) => {
40
- logger.debug(`Detecting ${browserName}...`)
42
+ logger.debug(`Detecting ${browserName}...`);
41
43
 
42
- const browserDetected = detectBrowser(browserPaths)
44
+ const browserDetected = detectBrowser(browserPaths);
43
45
  if (!browserDetected) {
44
- logger.debug(`${UNICODE.INFO} ${browserName} not detected`)
46
+ logger.debug(`${UNICODE.INFO} ${browserName} not detected`);
45
47
  return {
46
48
  status: "other",
47
49
  reason: `${browserName} not detected`,
48
- }
50
+ };
49
51
  }
50
- logger.debug(`${UNICODE.OK} ${browserName} detected`)
52
+ logger.debug(`${UNICODE.OK} ${browserName} detected`);
51
53
 
52
54
  if (verb === VERB_CHECK_TRUST && certificateIsNew) {
53
- logger.info(`${UNICODE.INFO} You should add certificate to ${browserName}`)
55
+ logger.info(`${UNICODE.INFO} You should add certificate to ${browserName}`);
54
56
  return {
55
57
  status: "not_trusted",
56
58
  reason: "certificate is new and tryToTrust is disabled",
57
- }
59
+ };
58
60
  }
59
61
 
60
- logger.info(`Check if certificate is in ${browserName}...`)
61
- const nssIsInstalled = await detectIfNSSIsInstalled({ logger })
62
- const cannotCheckMessage = `${UNICODE.FAILURE} cannot check if certificate is in ${browserName}`
62
+ logger.info(`Check if certificate is in ${browserName}...`);
63
+ const nssIsInstalled = await detectIfNSSIsInstalled({ logger });
64
+ const cannotCheckMessage = `${UNICODE.FAILURE} cannot check if certificate is in ${browserName}`;
63
65
  if (!nssIsInstalled) {
64
66
  if (verb === VERB_ADD_TRUST || verb === VERB_ENSURE_TRUST) {
65
- const nssDynamicInstallInfo = await getNSSDynamicInstallInfo({ logger })
67
+ const nssDynamicInstallInfo = await getNSSDynamicInstallInfo({ logger });
66
68
  if (!nssDynamicInstallInfo.isInstallable) {
67
- const reason = `"${nssCommandName}" is not installed and not cannot be installed`
69
+ const reason = `"${nssCommandName}" is not installed and not cannot be installed`;
68
70
  logger.warn(
69
71
  createDetailedMessage(cannotCheckMessage, {
70
72
  reason,
@@ -72,244 +74,247 @@ export const executeTrustQueryOnBrowserNSSDB = async ({
72
74
  nssDynamicInstallInfo.notInstallableReason,
73
75
  "suggested solution": nssDynamicInstallInfo.suggestion,
74
76
  }),
75
- )
77
+ );
76
78
  return {
77
79
  status: "unknown",
78
80
  reason,
79
- }
81
+ };
80
82
  }
81
83
 
82
84
  if (!NSSDynamicInstall) {
83
- const reason = `"${nssCommandName}" is not installed and NSSDynamicInstall is false`
85
+ const reason = `"${nssCommandName}" is not installed and NSSDynamicInstall is false`;
84
86
  logger.warn(
85
87
  createDetailedMessage(cannotCheckMessage, {
86
88
  reason,
87
89
  "suggested solution": `Allow "${nssCommandName}" dynamic install with NSSDynamicInstall: true`,
88
90
  }),
89
- )
91
+ );
90
92
  return {
91
93
  status: "unknown",
92
94
  reason,
93
- }
95
+ };
94
96
  }
95
97
 
96
98
  try {
97
- await nssDynamicInstallInfo.install({ logger })
99
+ await nssDynamicInstallInfo.install({ logger });
98
100
  } catch (e) {
99
101
  logger.error(
100
102
  createDetailedMessage(cannotCheckMessage, {
101
103
  "reason": `error while trying to install "${nssCommandName}"`,
102
104
  "error stack": e.stack,
103
105
  }),
104
- )
106
+ );
105
107
  return {
106
108
  status: "unknown",
107
109
  reason: `"${nssCommandName}" installation failed`,
108
- }
110
+ };
109
111
  }
110
112
  } else {
111
- const reason = `"${nssCommandName}" is not installed`
113
+ const reason = `"${nssCommandName}" is not installed`;
112
114
  logger.info(
113
115
  createDetailedMessage(cannotCheckMessage, {
114
116
  reason,
115
117
  }),
116
- )
118
+ );
117
119
  return {
118
120
  status: "unknown",
119
121
  reason,
120
- }
122
+ };
121
123
  }
122
124
  }
123
125
 
124
- let NSSDBFiles
126
+ let NSSDBFiles;
125
127
  for (const browserNSSDBDirectoryUrl of browserNSSDBDirectoryUrls) {
126
128
  NSSDBFiles = await findNSSDBFiles({
127
129
  logger,
128
130
  NSSDBDirectoryUrl: browserNSSDBDirectoryUrl,
129
- })
131
+ });
130
132
  if (NSSDBFiles.length > 0) {
131
- break
133
+ break;
132
134
  }
133
135
  }
134
136
 
135
- const fileCount = NSSDBFiles.length
137
+ const fileCount = NSSDBFiles.length;
136
138
  if (fileCount === 0) {
137
- const reason = `could not find nss database file`
138
- logger.warn(createDetailedMessage(cannotCheckMessage), { reason })
139
+ const reason = `could not find nss database file`;
140
+ logger.warn(createDetailedMessage(cannotCheckMessage), { reason });
139
141
  return {
140
142
  status: "unknown",
141
143
  reason,
142
- }
144
+ };
143
145
  }
144
146
 
145
- const certificateFilePath = fileURLToPath(certificateFileUrl)
146
- const certutilBinPath = await getCertutilBinPath()
147
+ const certificateFilePath = fileURLToPath(certificateFileUrl);
148
+ const certutilBinPath = await getCertutilBinPath();
147
149
 
148
150
  const checkNSSDB = async ({ NSSDBFileUrl }) => {
149
- const directoryArg = getDirectoryArgFromNSSDBFileUrl(NSSDBFileUrl)
150
- const certutilListCommand = `${certutilBinPath} -L -a -d ${directoryArg} -n "${certificateCommonName}"`
151
- logger.debug(`Checking if certificate is in nss database...`)
152
- logger.debug(`${UNICODE.COMMAND} ${certutilListCommand}`)
151
+ const directoryArg = getDirectoryArgFromNSSDBFileUrl(NSSDBFileUrl);
152
+ const certutilListCommand = `${certutilBinPath} -L -a -d ${directoryArg} -n "${certificateCommonName}"`;
153
+ logger.debug(`Checking if certificate is in nss database...`);
154
+ logger.debug(`${UNICODE.COMMAND} ${certutilListCommand}`);
153
155
  try {
154
- const output = await execCertutilCommmand(certutilListCommand)
155
- const isInDatabase = searchCertificateInCommandOutput(output, certificate)
156
+ const output = await execCertutilCommmand(certutilListCommand);
157
+ const isInDatabase = searchCertificateInCommandOutput(
158
+ output,
159
+ certificate,
160
+ );
156
161
  if (isInDatabase) {
157
- return "found"
162
+ return "found";
158
163
  }
159
- return "outdated"
164
+ return "outdated";
160
165
  } catch (e) {
161
166
  if (isCertificateNotFoundError(e)) {
162
- return "missing"
167
+ return "missing";
163
168
  }
164
- throw e
169
+ throw e;
165
170
  }
166
- }
171
+ };
167
172
 
168
173
  const addToNSSDB = async ({ NSSDBFileUrl }) => {
169
- const directoryArg = getDirectoryArgFromNSSDBFileUrl(NSSDBFileUrl)
170
- const certutilAddCommand = `${certutilBinPath} -A -d ${directoryArg} -t C,, -i "${certificateFilePath}" -n "${certificateCommonName}"`
171
- logger.debug(`Adding certificate to nss database...`)
172
- logger.debug(`${UNICODE.COMMAND} ${certutilAddCommand}`)
173
- await execCertutilCommmand(certutilAddCommand)
174
- logger.debug(`${UNICODE.OK} certificate added to nss database`)
175
- }
174
+ const directoryArg = getDirectoryArgFromNSSDBFileUrl(NSSDBFileUrl);
175
+ const certutilAddCommand = `${certutilBinPath} -A -d ${directoryArg} -t C,, -i "${certificateFilePath}" -n "${certificateCommonName}"`;
176
+ logger.debug(`Adding certificate to nss database...`);
177
+ logger.debug(`${UNICODE.COMMAND} ${certutilAddCommand}`);
178
+ await execCertutilCommmand(certutilAddCommand);
179
+ logger.debug(`${UNICODE.OK} certificate added to nss database`);
180
+ };
176
181
 
177
182
  const removeFromNSSDB = async ({ NSSDBFileUrl }) => {
178
- const directoryArg = getDirectoryArgFromNSSDBFileUrl(NSSDBFileUrl)
179
- const certutilRemoveCommand = `${certutilBinPath} -D -d ${directoryArg} -t C,, -i "${certificateFilePath}" -n "${certificateCommonName}"`
180
- logger.debug(`Removing certificate from nss database...`)
181
- logger.debug(`${UNICODE.COMMAND} ${certutilRemoveCommand}`)
182
- await execCertutilCommmand(certutilRemoveCommand)
183
- logger.debug(`${UNICODE.OK} certificate removed from nss database`)
184
- }
183
+ const directoryArg = getDirectoryArgFromNSSDBFileUrl(NSSDBFileUrl);
184
+ const certutilRemoveCommand = `${certutilBinPath} -D -d ${directoryArg} -t C,, -i "${certificateFilePath}" -n "${certificateCommonName}"`;
185
+ logger.debug(`Removing certificate from nss database...`);
186
+ logger.debug(`${UNICODE.COMMAND} ${certutilRemoveCommand}`);
187
+ await execCertutilCommmand(certutilRemoveCommand);
188
+ logger.debug(`${UNICODE.OK} certificate removed from nss database`);
189
+ };
185
190
 
186
- const missings = []
187
- const outdateds = []
188
- const founds = []
191
+ const missings = [];
192
+ const outdateds = [];
193
+ const founds = [];
189
194
  await Promise.all(
190
195
  NSSDBFiles.map(async (NSSDBFileUrl) => {
191
- const certificateStatus = await checkNSSDB({ NSSDBFileUrl })
196
+ const certificateStatus = await checkNSSDB({ NSSDBFileUrl });
192
197
 
193
198
  if (certificateStatus === "missing") {
194
- logger.debug(`${UNICODE.INFO} certificate not found in nss database`)
195
- missings.push(NSSDBFileUrl)
196
- return
199
+ logger.debug(`${UNICODE.INFO} certificate not found in nss database`);
200
+ missings.push(NSSDBFileUrl);
201
+ return;
197
202
  }
198
203
 
199
204
  if (certificateStatus === "outdated") {
200
- outdateds.push(NSSDBFileUrl)
201
- return
205
+ outdateds.push(NSSDBFileUrl);
206
+ return;
202
207
  }
203
208
 
204
- logger.debug(`${UNICODE.OK} certificate found in nss database`)
205
- founds.push(NSSDBFileUrl)
209
+ logger.debug(`${UNICODE.OK} certificate found in nss database`);
210
+ founds.push(NSSDBFileUrl);
206
211
  }),
207
- )
212
+ );
208
213
 
209
- const missingCount = missings.length
210
- const outdatedCount = outdateds.length
211
- const foundCount = founds.length
214
+ const missingCount = missings.length;
215
+ const outdatedCount = outdateds.length;
216
+ const foundCount = founds.length;
212
217
 
213
218
  if (verb === VERB_CHECK_TRUST) {
214
219
  if (missingCount > 0 || outdatedCount > 0) {
215
- logger.info(`${UNICODE.INFO} certificate not found in ${browserName}`)
220
+ logger.info(`${UNICODE.INFO} certificate not found in ${browserName}`);
216
221
  return {
217
222
  status: "not_trusted",
218
223
  reason: `missing or outdated in ${browserName} nss database file`,
219
- }
224
+ };
220
225
  }
221
- logger.info(`${UNICODE.OK} certificate found in ${browserName}`)
226
+ logger.info(`${UNICODE.OK} certificate found in ${browserName}`);
222
227
  return {
223
228
  status: "trusted",
224
229
  reason: `found in ${browserName} nss database file`,
225
- }
230
+ };
226
231
  }
227
232
 
228
233
  if (verb === VERB_ADD_TRUST || verb === VERB_ENSURE_TRUST) {
229
234
  if (missingCount === 0 && outdatedCount === 0) {
230
- logger.info(`${UNICODE.OK} certificate found in ${browserName}`)
235
+ logger.info(`${UNICODE.OK} certificate found in ${browserName}`);
231
236
  return {
232
237
  status: "trusted",
233
238
  reason: `found in all ${browserName} nss database file`,
234
- }
239
+ };
235
240
  }
236
- logger.info(`${UNICODE.INFO} certificate not found in ${browserName}`)
237
- logger.info(`Adding certificate to ${browserName}...`)
238
- await getBrowserClosedPromise()
241
+ logger.info(`${UNICODE.INFO} certificate not found in ${browserName}`);
242
+ logger.info(`Adding certificate to ${browserName}...`);
243
+ await getBrowserClosedPromise();
239
244
  await Promise.all(
240
245
  missings.map(async (missing) => {
241
- await addToNSSDB({ NSSDBFileUrl: missing })
246
+ await addToNSSDB({ NSSDBFileUrl: missing });
242
247
  }),
243
- )
248
+ );
244
249
  await Promise.all(
245
250
  outdateds.map(async (outdated) => {
246
- await removeFromNSSDB({ NSSDBFileUrl: outdated })
247
- await addToNSSDB({ NSSDBFileUrl: outdated })
251
+ await removeFromNSSDB({ NSSDBFileUrl: outdated });
252
+ await addToNSSDB({ NSSDBFileUrl: outdated });
248
253
  }),
249
- )
250
- logger.info(`${UNICODE.OK} certificate added to ${browserName}`)
254
+ );
255
+ logger.info(`${UNICODE.OK} certificate added to ${browserName}`);
251
256
  return {
252
257
  status: "trusted",
253
258
  reason: `added to ${browserName} nss database file`,
254
- }
259
+ };
255
260
  }
256
261
 
257
262
  if (outdatedCount === 0 && foundCount === 0) {
258
- logger.info(`${UNICODE.INFO} certificate not found in ${browserName}`)
263
+ logger.info(`${UNICODE.INFO} certificate not found in ${browserName}`);
259
264
  return {
260
265
  status: "not_trusted",
261
266
  reason: `not found in ${browserName} nss database file`,
262
- }
267
+ };
263
268
  }
264
- logger.info(`${UNICODE.INFO} found certificate in ${browserName}`)
265
- logger.info(`Removing certificate from ${browserName}...`)
266
- await getBrowserClosedPromise()
269
+ logger.info(`${UNICODE.INFO} found certificate in ${browserName}`);
270
+ logger.info(`Removing certificate from ${browserName}...`);
271
+ await getBrowserClosedPromise();
267
272
  await Promise.all(
268
273
  outdateds.map(async (outdated) => {
269
- await removeFromNSSDB({ NSSDBFileUrl: outdated })
274
+ await removeFromNSSDB({ NSSDBFileUrl: outdated });
270
275
  }),
271
- )
276
+ );
272
277
  await Promise.all(
273
278
  founds.map(async (found) => {
274
- await removeFromNSSDB({ NSSDBFileUrl: found })
279
+ await removeFromNSSDB({ NSSDBFileUrl: found });
275
280
  }),
276
- )
277
- logger.info(`${UNICODE.OK} certificate removed from ${browserName}`)
281
+ );
282
+ logger.info(`${UNICODE.OK} certificate removed from ${browserName}`);
278
283
  return {
279
284
  status: "not_trusted",
280
285
  reason: `removed from ${browserName} nss database file`,
281
- }
282
- }
286
+ };
287
+ };
283
288
 
284
289
  const isCertificateNotFoundError = (error) => {
285
290
  if (error.message.includes("could not find certificate named")) {
286
- return true
291
+ return true;
287
292
  }
288
293
  if (error.message.includes("PR_FILE_NOT_FOUND_ERROR")) {
289
- return true
294
+ return true;
290
295
  }
291
- return false
292
- }
296
+ return false;
297
+ };
293
298
 
294
- const NSSDirectoryCache = {}
299
+ const NSSDirectoryCache = {};
295
300
  const findNSSDBFiles = async ({ logger, NSSDBDirectoryUrl }) => {
296
- NSSDBDirectoryUrl = String(NSSDBDirectoryUrl)
297
- const resultFromCache = NSSDirectoryCache[NSSDBDirectoryUrl]
301
+ NSSDBDirectoryUrl = String(NSSDBDirectoryUrl);
302
+ const resultFromCache = NSSDirectoryCache[NSSDBDirectoryUrl];
298
303
  if (resultFromCache) {
299
- return resultFromCache
304
+ return resultFromCache;
300
305
  }
301
306
 
302
- logger.debug(`Searching nss database files in directory...`)
303
- const NSSDBDirectoryPath = fileURLToPath(NSSDBDirectoryUrl)
304
- const NSSDBDirectoryExists = existsSync(NSSDBDirectoryPath)
307
+ logger.debug(`Searching nss database files in directory...`);
308
+ const NSSDBDirectoryPath = fileURLToPath(NSSDBDirectoryUrl);
309
+ const NSSDBDirectoryExists = existsSync(NSSDBDirectoryPath);
305
310
  if (!NSSDBDirectoryExists) {
306
311
  logger.info(
307
312
  `${UNICODE.INFO} nss database directory not found on filesystem at ${NSSDBDirectoryPath}`,
308
- )
309
- NSSDirectoryCache[NSSDBDirectoryUrl] = []
310
- return []
313
+ );
314
+ NSSDirectoryCache[NSSDBDirectoryUrl] = [];
315
+ return [];
311
316
  }
312
- NSSDBDirectoryUrl = assertAndNormalizeDirectoryUrl(NSSDBDirectoryUrl)
317
+ NSSDBDirectoryUrl = assertAndNormalizeDirectoryUrl(NSSDBDirectoryUrl);
313
318
  const NSSDBFiles = await collectFiles({
314
319
  directoryUrl: NSSDBDirectoryUrl,
315
320
  associations: {
@@ -318,36 +323,36 @@ const findNSSDBFiles = async ({ logger, NSSDBDirectoryUrl }) => {
318
323
  },
319
324
  predicate: ({ isLegacyNSSDB, isModernNSSDB }) =>
320
325
  isLegacyNSSDB || isModernNSSDB,
321
- })
322
- const fileCount = NSSDBFiles.length
326
+ });
327
+ const fileCount = NSSDBFiles.length;
323
328
  if (fileCount === 0) {
324
329
  logger.warn(
325
330
  `${UNICODE.WARNING} could not find nss database file in ${NSSDBDirectoryUrl}`,
326
- )
327
- NSSDirectoryCache[NSSDBDirectoryUrl] = []
328
- return []
331
+ );
332
+ NSSDirectoryCache[NSSDBDirectoryUrl] = [];
333
+ return [];
329
334
  }
330
335
 
331
336
  logger.debug(
332
337
  `${UNICODE.OK} found ${fileCount} nss database file in ${NSSDBDirectoryUrl}`,
333
- )
338
+ );
334
339
  const files = NSSDBFiles.map((file) => {
335
- return new URL(file.relativeUrl, NSSDBDirectoryUrl).href
336
- })
337
- NSSDirectoryCache[NSSDBDirectoryUrl] = files
338
- return files
339
- }
340
+ return new URL(file.relativeUrl, NSSDBDirectoryUrl).href;
341
+ });
342
+ NSSDirectoryCache[NSSDBDirectoryUrl] = files;
343
+ return files;
344
+ };
340
345
 
341
346
  const getDirectoryArgFromNSSDBFileUrl = (NSSDBFileUrl) => {
342
- const nssDBFilename = urlToFilename(NSSDBFileUrl)
343
- const nssDBDirectoryUrl = new URL("./", NSSDBFileUrl).href
344
- const nssDBDirectoryPath = fileURLToPath(nssDBDirectoryUrl)
347
+ const nssDBFilename = urlToFilename(NSSDBFileUrl);
348
+ const nssDBDirectoryUrl = new URL("./", NSSDBFileUrl).href;
349
+ const nssDBDirectoryPath = fileURLToPath(nssDBDirectoryUrl);
345
350
  return nssDBFilename === "cert8.db"
346
351
  ? `"${nssDBDirectoryPath}"`
347
- : `sql:"${nssDBDirectoryPath}"`
348
- }
352
+ : `sql:"${nssDBDirectoryPath}"`;
353
+ };
349
354
 
350
355
  const execCertutilCommmand = async (command) => {
351
- const output = await exec(command)
352
- return output
353
- }
356
+ const output = await exec(command);
357
+ return output;
358
+ };
@@ -1,13 +1,13 @@
1
1
  export const importPlatformMethods = async () => {
2
- const { platform } = process
2
+ const { platform } = process;
3
3
  if (platform === "darwin") {
4
- return await import("./mac/mac.js")
4
+ return await import("./mac/mac.js");
5
5
  }
6
6
  if (platform === "linux") {
7
- return await import("./linux/linux.js")
7
+ return await import("./linux/linux.js");
8
8
  }
9
9
  if (platform === "win32") {
10
- return await import("./windows/windows.js")
10
+ return await import("./windows/windows.js");
11
11
  }
12
- return await import("./unsupported_platform/unsupported_platform.js")
13
- }
12
+ return await import("./unsupported_platform/unsupported_platform.js");
13
+ };
@@ -2,7 +2,7 @@ export const searchCertificateInCommandOutput = (
2
2
  commandOutput,
3
3
  certificateAsPEM,
4
4
  ) => {
5
- commandOutput = commandOutput.replace(/\r\n/g, "\n").trim()
6
- certificateAsPEM = certificateAsPEM.replace(/\r\n/g, "\n").trim()
7
- return commandOutput.includes(certificateAsPEM)
8
- }
5
+ commandOutput = commandOutput.replace(/\r\n/g, "\n").trim();
6
+ certificateAsPEM = certificateAsPEM.replace(/\r\n/g, "\n").trim();
7
+ return commandOutput.includes(certificateAsPEM);
8
+ };
@@ -1,4 +1,4 @@
1
- export const VERB_CHECK_TRUST = "CHECK_TRUST"
2
- export const VERB_ADD_TRUST = "ADD_TRUST"
3
- export const VERB_ENSURE_TRUST = "ENSURE_TRUST"
4
- export const VERB_REMOVE_TRUST = "REMOVE_TRUST"
1
+ export const VERB_CHECK_TRUST = "CHECK_TRUST";
2
+ export const VERB_ADD_TRUST = "ADD_TRUST";
3
+ export const VERB_ENSURE_TRUST = "ENSURE_TRUST";
4
+ export const VERB_REMOVE_TRUST = "REMOVE_TRUST";