@jsenv/https-local 1.1.0 → 2.0.0

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.
package/README.md CHANGED
@@ -67,13 +67,12 @@ node ./install_certificate_authority.mjs
67
67
  import { createServer } from "node:https"
68
68
  import { requestCertificateForLocalhost } from "@jsenv/https-local"
69
69
 
70
- const { serverCertificate, serverCertificatePrivateKey } =
71
- await requestCertificateForLocalhost()
70
+ const { certificate, privateKey } = requestCertificateForLocalhost()
72
71
 
73
72
  const server = createServer(
74
73
  {
75
- cert: serverCertificate,
76
- key: serverCertificatePrivateKey,
74
+ cert: certificate,
75
+ key: privateKey,
77
76
  },
78
77
  (request, response) => {
79
78
  const body = "Hello world"
@@ -361,10 +360,9 @@ _requestCertificateForLocalhost_ function returns a certificate and private key
361
360
  import { createServer } from "node:https"
362
361
  import { requestCertificateForLocalhost } from "@jsenv/https-local"
363
362
 
364
- const { serverCertificate, serverCertificatePrivateKey } =
365
- await requestCertificateForLocalhost({
366
- serverCertificateAltNames: ["localhost", "local.example"],
367
- })
363
+ const { certificate, privateKey } = requestCertificateForLocalhost({
364
+ altNames: ["localhost", "local.example"],
365
+ })
368
366
  ```
369
367
 
370
368
  [installCertificateAuthority](#installCertificateAuthority) must be called before this function.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/https-local",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "A programmatic way to generate locally trusted certificates",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -13,7 +13,8 @@
13
13
  "url": "https://github.com/jsenv/https-local"
14
14
  },
15
15
  "publishConfig": {
16
- "access": "public"
16
+ "access": "public",
17
+ "registry": "https://registry.npmjs.org"
17
18
  },
18
19
  "engines": {
19
20
  "node": ">=16.13.0"
@@ -21,14 +22,13 @@
21
22
  "type": "module",
22
23
  "exports": {
23
24
  ".": {
24
- "import": "./main.js"
25
+ "import": "./src/main.js"
25
26
  },
26
27
  "./*": "./*"
27
28
  },
28
- "main": "./main.js",
29
+ "main": "./src/main.js",
29
30
  "files": [
30
- "/src/",
31
- "/main.js"
31
+ "/src/"
32
32
  ],
33
33
  "scripts": {
34
34
  "eslint": "npx eslint . --ext=.js,.mjs,.cjs",
@@ -48,28 +48,25 @@
48
48
  "playwright-install": "npx playwright install-deps && npx playwright install"
49
49
  },
50
50
  "dependencies": {
51
- "@jsenv/filesystem": "4.0.2",
52
- "@jsenv/log": "1.6.3",
53
- "@jsenv/logger": "4.1.1",
54
- "@jsenv/urls": "1.1.2",
51
+ "@jsenv/filesystem": "4.1.0",
52
+ "@jsenv/log": "2.0.1",
53
+ "@jsenv/urls": "1.2.6",
55
54
  "command-exists": "1.2.9",
56
55
  "node-forge": "1.3.1",
57
56
  "sudo-prompt": "9.2.1",
58
57
  "which": "2.0.2"
59
58
  },
60
59
  "devDependencies": {
61
- "@jsenv/assert": "2.5.4",
62
- "@jsenv/core": "27.0.0-alpha.69",
60
+ "@jsenv/assert": "2.6.0",
61
+ "@jsenv/core": "27.0.0-alpha.92",
63
62
  "@jsenv/eslint-config": "16.0.9",
64
- "@jsenv/eslint-import-resolver": "0.1.11",
63
+ "@jsenv/eslint-import-resolver": "0.3.0",
65
64
  "@jsenv/github-release-package": "1.4.0",
66
- "@jsenv/importmap-eslint-resolver": "5.2.5",
67
- "@jsenv/importmap-node-module": "5.1.3",
68
65
  "@jsenv/package-publish": "1.7.5",
69
- "@jsenv/performance-impact": "2.2.11",
70
- "eslint": "8.17.0",
66
+ "@jsenv/performance-impact": "2.3.0",
67
+ "eslint": "8.18.0",
71
68
  "eslint-plugin-import": "2.26.0",
72
69
  "playwright": "1.22.2",
73
- "prettier": "2.7.0"
70
+ "prettier": "2.7.1"
74
71
  }
75
- }
72
+ }
@@ -1,14 +1,13 @@
1
1
  import { readFile, writeFile, removeEntry } from "@jsenv/filesystem"
2
- import { createLogger, createDetailedMessage } from "@jsenv/logger"
3
- import { UNICODE } from "@jsenv/log"
2
+ import { UNICODE, createLogger, createDetailedMessage } from "@jsenv/log"
4
3
 
4
+ import { forge } from "./internal/forge.js"
5
5
  import { getAuthorityFileInfos } from "./internal/authority_file_infos.js"
6
6
  import { attributeDescriptionFromAttributeArray } from "./internal/certificate_data_converter.js"
7
7
  import {
8
8
  formatTimeDelta,
9
9
  formatDuration,
10
10
  } from "./internal/validity_formatting.js"
11
- import { importNodeForge } from "./internal/forge.js"
12
11
  import { createAuthorityRootCertificate } from "./internal/certificate_generator.js"
13
12
  import { importPlatformMethods } from "./internal/platform.js"
14
13
  import { jsenvParameters } from "./jsenvParameters.js"
@@ -79,7 +78,7 @@ export const installCertificateAuthority = async ({
79
78
  serialNumber: 0,
80
79
  })
81
80
 
82
- const { pki } = await importNodeForge()
81
+ const { pki } = forge
83
82
  const rootCertificate = pemAsFileContent(
84
83
  pki.certificateToPem(rootCertificateForgeObject),
85
84
  )
@@ -173,7 +172,7 @@ export const installCertificateAuthority = async ({
173
172
  const rootCertificate = await readFile(rootCertificateFileInfo.path, {
174
173
  as: "string",
175
174
  })
176
- const { pki } = await importNodeForge()
175
+ const { pki } = forge
177
176
  const rootCertificateForgeObject = pki.certificateFromPem(rootCertificate)
178
177
 
179
178
  logger.info(`Checking certificate validity...`)
@@ -323,7 +322,7 @@ export const uninstallCertificateAuthority = async ({
323
322
  const rootCertificate = await readFile(rootCertificateFileInfo.url, {
324
323
  as: "string",
325
324
  })
326
- const { pki } = await importNodeForge()
325
+ const { pki } = forge
327
326
  const rootCertificateForgeObject = pki.certificateFromPem(rootCertificate)
328
327
  const rootCertificateCommonName = attributeDescriptionFromAttributeArray(
329
328
  rootCertificateForgeObject.subject.attributes,
@@ -1,39 +1,38 @@
1
- import { readFile, writeFile } from "@jsenv/filesystem"
2
- import { createLogger, createDetailedMessage } from "@jsenv/logger"
3
- import { UNICODE } from "@jsenv/log"
1
+ import { readFileSync } from "node:fs"
2
+ import { writeFileSync } from "@jsenv/filesystem"
3
+ import { UNICODE, createLogger, createDetailedMessage } from "@jsenv/log"
4
4
 
5
+ import { forge } from "./internal/forge.js"
5
6
  import {
6
7
  createValidityDurationOfXDays,
7
8
  verifyServerCertificateValidityDuration,
8
9
  } from "./validity_duration.js"
9
10
  import { getAuthorityFileInfos } from "./internal/authority_file_infos.js"
10
- import { importNodeForge } from "./internal/forge.js"
11
11
  import { requestCertificateFromAuthority } from "./internal/certificate_generator.js"
12
12
  import { formatDuration } from "./internal/validity_formatting.js"
13
13
 
14
- export const requestCertificateForLocalhost = async ({
14
+ export const requestCertificateForLocalhost = ({
15
15
  logLevel,
16
16
  logger = createLogger({ logLevel }), // to be able to catch logs during unit tests
17
17
 
18
- serverCertificateAltNames = ["localhost"],
19
- serverCertificateCommonName = "https local server certificate",
20
- serverCertificateValidityDurationInMs = createValidityDurationOfXDays(396),
18
+ altNames = ["localhost"],
19
+ commonName = "https local server certificate",
20
+ validityDurationInMs = createValidityDurationOfXDays(396),
21
21
  } = {}) => {
22
- if (typeof serverCertificateValidityDurationInMs !== "number") {
22
+ if (typeof validityDurationInMs !== "number") {
23
23
  throw new TypeError(
24
- `serverCertificateValidityDurationInMs must be a number but received ${serverCertificateValidityDurationInMs}`,
24
+ `validityDurationInMs must be a number but received ${validityDurationInMs}`,
25
25
  )
26
26
  }
27
- if (serverCertificateValidityDurationInMs < 1) {
27
+ if (validityDurationInMs < 1) {
28
28
  throw new TypeError(
29
- `serverCertificateValidityDurationInMs must be > 0 but received ${serverCertificateValidityDurationInMs}`,
29
+ `validityDurationInMs must be > 0 but received ${validityDurationInMs}`,
30
30
  )
31
31
  }
32
- const validityDurationInfo = verifyServerCertificateValidityDuration(
33
- serverCertificateValidityDurationInMs,
34
- )
32
+ const validityDurationInfo =
33
+ verifyServerCertificateValidityDuration(validityDurationInMs)
35
34
  if (!validityDurationInfo.ok) {
36
- serverCertificateValidityDurationInMs = validityDurationInfo.maxAllowedValue
35
+ validityDurationInMs = validityDurationInfo.maxAllowedValue
37
36
  logger.warn(
38
37
  createDetailedMessage(validityDurationInfo.message, {
39
38
  details: validityDurationInfo.details,
@@ -59,19 +58,16 @@ export const requestCertificateForLocalhost = async ({
59
58
  }
60
59
 
61
60
  logger.debug(`Restoring certificate authority from filesystem...`)
62
- const { pki } = await importNodeForge()
63
- const rootCertificate = await readFile(rootCertificateFileInfo.url, {
64
- as: "string",
65
- })
66
- const rootCertificatePrivateKey = await readFile(
67
- rootCertificatePrivateKeyFileInfo.url,
68
- {
69
- as: "string",
70
- },
61
+ const { pki } = forge
62
+ const rootCertificate = String(
63
+ readFileSync(new URL(rootCertificateFileInfo.url)),
64
+ )
65
+ const rootCertificatePrivateKey = String(
66
+ readFileSync(new URL(rootCertificatePrivateKeyFileInfo.url)),
67
+ )
68
+ const certificateAuthorityData = JSON.parse(
69
+ String(readFileSync(new URL(authorityJsonFileInfo.url))),
71
70
  )
72
- const certificateAuthorityData = await readFile(authorityJsonFileInfo.url, {
73
- as: "json",
74
- })
75
71
  const rootCertificateForgeObject = pki.certificateFromPem(rootCertificate)
76
72
  const rootCertificatePrivateKeyForgeObject = pki.privateKeyFromPem(
77
73
  rootCertificatePrivateKey,
@@ -80,26 +76,26 @@ export const requestCertificateForLocalhost = async ({
80
76
 
81
77
  const serverCertificateSerialNumber =
82
78
  certificateAuthorityData.serialNumber + 1
83
- await writeFile(
79
+ writeFileSync(
84
80
  authorityJsonFileInfo.url,
85
81
  JSON.stringify({ serialNumber: serverCertificateSerialNumber }, null, " "),
86
82
  )
87
83
 
88
- if (!serverCertificateAltNames.includes("localhost")) {
89
- serverCertificateAltNames.push("localhost")
84
+ if (!altNames.includes("localhost")) {
85
+ altNames.push("localhost")
90
86
  }
91
87
 
92
88
  logger.debug(`Generating server certificate...`)
93
89
  const { certificateForgeObject, certificatePrivateKeyForgeObject } =
94
- await requestCertificateFromAuthority({
90
+ requestCertificateFromAuthority({
95
91
  logger,
96
92
  authorityCertificateForgeObject: rootCertificateForgeObject,
97
93
  auhtorityCertificatePrivateKeyForgeObject:
98
94
  rootCertificatePrivateKeyForgeObject,
99
95
  serialNumber: serverCertificateSerialNumber,
100
- altNames: serverCertificateAltNames,
101
- commonName: serverCertificateCommonName,
102
- validityDurationInMs: serverCertificateValidityDurationInMs,
96
+ altNames,
97
+ commonName,
98
+ validityDurationInMs,
103
99
  })
104
100
  const serverCertificate = pki.certificateToPem(certificateForgeObject)
105
101
  const serverCertificatePrivateKey = pki.privateKeyToPem(
@@ -109,13 +105,13 @@ export const requestCertificateForLocalhost = async ({
109
105
  `${
110
106
  UNICODE.OK
111
107
  } server certificate generated, it will be valid for ${formatDuration(
112
- serverCertificateValidityDurationInMs,
108
+ validityDurationInMs,
113
109
  )}`,
114
110
  )
115
111
 
116
112
  return {
117
- serverCertificate,
118
- serverCertificatePrivateKey,
113
+ certificate: serverCertificate,
114
+ privateKey: serverCertificatePrivateKey,
119
115
  rootCertificateFilePath: rootCertificateFileInfo.path,
120
116
  }
121
117
  }
@@ -1,5 +1,4 @@
1
- import { createDetailedMessage, createLogger } from "@jsenv/logger"
2
- import { UNICODE } from "@jsenv/log"
1
+ import { createDetailedMessage, createLogger, UNICODE } from "@jsenv/log"
3
2
 
4
3
  import {
5
4
  HOSTS_FILE_PATH,
@@ -1,7 +1,7 @@
1
1
  // https://github.com/digitalbazaar/forge/blob/master/examples/create-cert.js
2
2
  // https://github.com/digitalbazaar/forge/issues/660#issuecomment-467145103
3
3
 
4
- import { importNodeForge } from "./forge.js"
4
+ import { forge } from "./forge.js"
5
5
  import {
6
6
  attributeArrayFromAttributeDescription,
7
7
  attributeDescriptionFromAttributeArray,
@@ -23,7 +23,6 @@ export const createAuthorityRootCertificate = async ({
23
23
  throw new TypeError(`serial must be a number but received ${serialNumber}`)
24
24
  }
25
25
 
26
- const forge = await importNodeForge()
27
26
  const { pki } = forge
28
27
  const rootCertificateForgeObject = pki.createCertificate()
29
28
  const keyPair = pki.rsa.generateKeyPair(2048) // TODO: use async version https://github.com/digitalbazaar/forge#rsa
@@ -86,7 +85,7 @@ export const createAuthorityRootCertificate = async ({
86
85
  }
87
86
  }
88
87
 
89
- export const requestCertificateFromAuthority = async ({
88
+ export const requestCertificateFromAuthority = ({
90
89
  authorityCertificateForgeObject, // could be intermediate or root certificate authority
91
90
  auhtorityCertificatePrivateKeyForgeObject,
92
91
  serialNumber,
@@ -116,7 +115,6 @@ export const requestCertificateFromAuthority = async ({
116
115
  )
117
116
  }
118
117
 
119
- const forge = await importNodeForge()
120
118
  const { pki } = forge
121
119
  const certificateForgeObject = pki.createCertificate()
122
120
  const keyPair = pki.rsa.generateKeyPair(2048) // TODO: use async version https://github.com/digitalbazaar/forge#rsa
@@ -2,6 +2,4 @@ import { createRequire } from "node:module"
2
2
 
3
3
  const require = createRequire(import.meta.url)
4
4
 
5
- export const importNodeForge = async () => {
6
- return require("node-forge")
7
- }
5
+ export const forge = require("node-forge")
@@ -1,8 +1,9 @@
1
1
  import { existsSync } from "node:fs"
2
2
  import { execSync } from "node:child_process"
3
3
  import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
4
-
5
4
  import { UNICODE } from "@jsenv/log"
5
+
6
+ import { executeTrustQueryOnBrowserNSSDB } from "../nssdb_browser.js"
6
7
  import {
7
8
  nssCommandName,
8
9
  detectIfNSSIsInstalled,
@@ -10,8 +11,6 @@ import {
10
11
  getCertutilBinPath,
11
12
  } from "./nss_linux.js"
12
13
 
13
- import { executeTrustQueryOnBrowserNSSDB } from "../nssdb_browser.js"
14
-
15
14
  export const executeTrustQueryOnChrome = ({
16
15
  logger,
17
16
  certificateCommonName,
@@ -3,6 +3,7 @@ import { execSync } from "node:child_process"
3
3
  import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
4
4
  import { UNICODE } from "@jsenv/log"
5
5
 
6
+ import { executeTrustQueryOnBrowserNSSDB } from "../nssdb_browser.js"
6
7
  import {
7
8
  nssCommandName,
8
9
  detectIfNSSIsInstalled,
@@ -10,8 +11,6 @@ import {
10
11
  getCertutilBinPath,
11
12
  } from "./nss_linux.js"
12
13
 
13
- import { executeTrustQueryOnBrowserNSSDB } from "../nssdb_browser.js"
14
-
15
14
  export const executeTrustQueryOnFirefox = ({
16
15
  logger,
17
16
  certificateCommonName,
@@ -4,16 +4,15 @@
4
4
 
5
5
  import { existsSync } from "node:fs"
6
6
  import { fileURLToPath } from "node:url"
7
- import { createDetailedMessage } from "@jsenv/logger"
8
7
  import { readFile } from "@jsenv/filesystem"
9
- import { UNICODE } from "@jsenv/log"
8
+ import { createDetailedMessage, UNICODE } from "@jsenv/log"
10
9
 
11
- import { exec } from "@jsenv/https-local/src/internal/exec.js"
12
10
  import {
13
11
  VERB_CHECK_TRUST,
14
12
  VERB_ADD_TRUST,
15
13
  VERB_REMOVE_TRUST,
16
14
  } from "../trust_query.js"
15
+ import { exec } from "../exec.js"
17
16
 
18
17
  const REASON_NEW_AND_TRY_TO_TRUST_DISABLED =
19
18
  "certificate is new and tryToTrust is disabled"
@@ -1,7 +1,7 @@
1
1
  import { UNICODE } from "@jsenv/log"
2
2
 
3
- import { memoize } from "@jsenv/https-local/src/internal/memoize.js"
4
- import { exec } from "@jsenv/https-local/src/internal/exec.js"
3
+ import { memoize } from "../memoize.js"
4
+ import { exec } from "../exec.js"
5
5
 
6
6
  export const nssCommandName = "libnss3-tools"
7
7
 
@@ -1,7 +1,7 @@
1
1
  import { existsSync } from "node:fs"
2
2
  import { UNICODE } from "@jsenv/log"
3
3
 
4
- import { memoize } from "@jsenv/https-local/src/internal/memoize.js"
4
+ import { memoize } from "../memoize.js"
5
5
 
6
6
  const REASON_CHROME_NOT_DETECTED = `Chrome not detected`
7
7
 
@@ -1,11 +1,10 @@
1
1
  // https://ss64.com/osx/security.html
2
2
 
3
3
  import { fileURLToPath } from "node:url"
4
- import { createDetailedMessage } from "@jsenv/logger"
4
+ import { createDetailedMessage, UNICODE } from "@jsenv/log"
5
5
 
6
- import { UNICODE } from "@jsenv/log"
7
- import { exec } from "@jsenv/https-local/src/internal/exec.js"
8
- import { searchCertificateInCommandOutput } from "@jsenv/https-local/src/internal/search_certificate_in_command_output.js"
6
+ import { exec } from "../exec.js"
7
+ import { searchCertificateInCommandOutput } from "../search_certificate_in_command_output.js"
9
8
  import {
10
9
  VERB_CHECK_TRUST,
11
10
  VERB_ADD_TRUST,
@@ -2,9 +2,9 @@ import { fileURLToPath } from "node:url"
2
2
  import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
3
3
  import { UNICODE } from "@jsenv/log"
4
4
 
5
- import { memoize } from "@jsenv/https-local/src/internal/memoize.js"
6
- import { exec } from "@jsenv/https-local/src/internal/exec.js"
7
- import { commandExists } from "@jsenv/https-local/src/internal/command.js"
5
+ import { memoize } from "../memoize.js"
6
+ import { exec } from "../exec.js"
7
+ import { commandExists } from "../command.js"
8
8
 
9
9
  export const nssCommandName = "nss"
10
10
 
@@ -5,13 +5,12 @@
5
5
 
6
6
  import { existsSync } from "node:fs"
7
7
  import { fileURLToPath } from "node:url"
8
- import { createDetailedMessage } from "@jsenv/logger"
9
8
  import { urlToFilename } from "@jsenv/urls"
9
+ import { createDetailedMessage, UNICODE } from "@jsenv/log"
10
10
  import { assertAndNormalizeDirectoryUrl, collectFiles } from "@jsenv/filesystem"
11
- import { UNICODE } from "@jsenv/log"
12
11
 
13
- import { exec } from "@jsenv/https-local/src/internal/exec.js"
14
- import { searchCertificateInCommandOutput } from "@jsenv/https-local/src/internal/search_certificate_in_command_output.js"
12
+ import { exec } from "./exec.js"
13
+ import { searchCertificateInCommandOutput } from "./search_certificate_in_command_output.js"
15
14
  import { VERB_CHECK_TRUST, VERB_ADD_TRUST } from "./trust_query.js"
16
15
 
17
16
  export const executeTrustQueryOnBrowserNSSDB = async ({
@@ -2,7 +2,7 @@ import { createRequire } from "node:module"
2
2
  import { existsSync } from "node:fs"
3
3
  import { UNICODE } from "@jsenv/log"
4
4
 
5
- import { memoize } from "@jsenv/https-local/src/internal/memoize.js"
5
+ import { memoize } from "../memoize.js"
6
6
 
7
7
  const require = createRequire(import.meta.url)
8
8
 
@@ -7,7 +7,7 @@ import { createRequire } from "node:module"
7
7
  import { existsSync } from "node:fs"
8
8
  import { UNICODE } from "@jsenv/log"
9
9
 
10
- import { memoize } from "@jsenv/https-local/src/internal/memoize.js"
10
+ import { memoize } from "../memoize.js"
11
11
 
12
12
  const require = createRequire(import.meta.url)
13
13
 
@@ -4,10 +4,9 @@
4
4
  */
5
5
 
6
6
  import { fileURLToPath } from "node:url"
7
- import { createDetailedMessage } from "@jsenv/logger"
8
- import { UNICODE } from "@jsenv/log"
7
+ import { createDetailedMessage, UNICODE } from "@jsenv/log"
9
8
 
10
- import { exec } from "@jsenv/https-local/src/internal/exec.js"
9
+ import { exec } from "../exec.js"
11
10
  import {
12
11
  VERB_CHECK_TRUST,
13
12
  VERB_ADD_TRUST,
@@ -7,13 +7,13 @@
7
7
  export {
8
8
  installCertificateAuthority,
9
9
  uninstallCertificateAuthority,
10
- } from "./src/certificate_authority.js"
10
+ } from "./certificate_authority.js"
11
11
 
12
12
  export {
13
13
  createValidityDurationOfXYears,
14
14
  createValidityDurationOfXDays,
15
- } from "./src/validity_duration.js"
15
+ } from "./validity_duration.js"
16
16
 
17
- export { verifyHostsFile } from "./src/hosts_file_verif.js"
17
+ export { verifyHostsFile } from "./hosts_file_verif.js"
18
18
 
19
- export { requestCertificateForLocalhost } from "./src/certificate_for_localhost.js"
19
+ export { requestCertificateForLocalhost } from "./certificate_for_localhost.js"
@@ -3,7 +3,6 @@ const MILLISECONDS_PER_YEAR = MILLISECONDS_PER_DAY * 365
3
3
 
4
4
  export const verifyRootCertificateValidityDuration = (validityDurationInMs) => {
5
5
  const durationInYears = validityDurationInMs / MILLISECONDS_PER_YEAR
6
-
7
6
  if (durationInYears > 25) {
8
7
  return {
9
8
  ok: false,
@@ -13,26 +12,22 @@ export const verifyRootCertificateValidityDuration = (validityDurationInMs) => {
13
12
  "https://serverfault.com/questions/847190/in-theory-could-a-ca-make-a-certificate-that-is-valid-for-arbitrarily-long",
14
13
  }
15
14
  }
16
-
17
15
  return { ok: true }
18
16
  }
19
17
 
20
18
  export const verifyServerCertificateValidityDuration = (
21
- serverCertificateValidityDurationInMs,
19
+ validityDurationInMs,
22
20
  ) => {
23
- const serverCertificateValidityDurationInDays =
24
- serverCertificateValidityDurationInMs / MILLISECONDS_PER_DAY
25
-
26
- if (serverCertificateValidityDurationInDays > 397) {
21
+ const validityDurationInDays = validityDurationInMs / MILLISECONDS_PER_DAY
22
+ if (validityDurationInDays > 397) {
27
23
  return {
28
24
  ok: false,
29
25
  maxAllowedValue: MILLISECONDS_PER_DAY * 397,
30
- message: `certificate validity duration of ${serverCertificateValidityDurationInMs} days is too much, using the max recommended duration: 397 days`,
26
+ message: `certificate validity duration of ${validityDurationInMs} days is too much, using the max recommended duration: 397 days`,
31
27
  details:
32
28
  "https://www.globalsign.com/en/blog/maximum-ssltls-certificate-validity-now-one-year",
33
29
  }
34
30
  }
35
-
36
31
  return { ok: true }
37
32
  }
38
33