From 967a5fadbf8e82a5156ce6e2341a9a6c2a5e59a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evandro=20Ara=C3=BAjo?= Date: Thu, 26 Jan 2023 16:43:07 -0300 Subject: [PATCH 1/3] allow IP addresses as domains --- package-lock.json | 12 ++++++------ package.json | 2 +- src/constants.ts | 21 ++++++++++++--------- src/index.ts | 23 +++++++++-------------- 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index a743d6d..d84e9d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1475,9 +1475,9 @@ } }, "node_modules/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dependencies": { "brace-expansion": "^1.1.7" }, @@ -3571,9 +3571,9 @@ "dev": true }, "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "requires": { "brace-expansion": "^1.1.7" } diff --git a/package.json b/package.json index 841d3d8..901c1a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "devcert", - "version": "1.2.2", + "version": "1.2.3", "description": "Generate trusted local SSL/TLS certificates for local SSL development", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/constants.ts b/src/constants.ts index acac07a..900cc69 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,10 +1,11 @@ -import path from 'path'; -import { unlinkSync as rm, writeFileSync as writeFile, readFileSync as readFile } from 'fs'; -import { sync as mkdirp } from 'mkdirp'; +import eol from 'eol'; +import { readFileSync as readFile, unlinkSync as rm, writeFileSync as writeFile } from 'fs'; import { template as makeTemplate } from 'lodash'; +import { sync as mkdirp } from 'mkdirp'; +import { isIP } from 'net'; +import path from 'path'; +import { mktmp, numericHash } from './utils'; import applicationConfigPath = require('application-config-path'); -import eol from 'eol'; -import {mktmp, numericHash} from './utils'; // Platform shortcuts export const isMac = process.platform === 'darwin'; @@ -52,10 +53,12 @@ export const caSelfSignConfig = path.join(__dirname, '../openssl-configurations/ function generateSubjectAltNames(domains: string[]): string { return domains .reduce((dnsEntries, domain) => - dnsEntries.concat([ - `DNS.${dnsEntries.length + 1} = ${domain}`, - `DNS.${dnsEntries.length + 2} = *.${domain}`, - ]), [] as string[]) + isIP(domain) > 0 + ? dnsEntries.concat(`DNS.${dnsEntries.length + 1} = ${domain}`) + : dnsEntries.concat([ + `DNS.${dnsEntries.length + 1} = ${domain}`, + `DNS.${dnsEntries.length + 2} = *.${domain}`, + ]), [] as string[]) .join("\r\n"); } diff --git a/src/index.ts b/src/index.ts index bee0b4c..fc53097 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,22 +1,17 @@ -import { readFileSync as readFile, readdirSync as readdir, existsSync as exists } from 'fs'; -import createDebug from 'debug'; import { sync as commandExists } from 'command-exists'; +import createDebug from 'debug'; +import { existsSync as exists, readdirSync as readdir, readFileSync as readFile } from 'fs'; +import isValidDomain from 'is-valid-domain'; +import { isIP } from 'net'; import rimraf from 'rimraf'; +import installCertificateAuthority, { ensureCACertReadable, uninstall } from './certificate-authority'; +import generateDomainCertificate from './certificates'; import { - isMac, - isLinux, - isWindows, - pathForDomain, - getStableDomainPath, - domainsDir, - rootCAKeyPath, - rootCACertPath, + domainsDir, getStableDomainPath, isLinux, isMac, isWindows, + pathForDomain, rootCACertPath, rootCAKeyPath } from './constants'; import currentPlatform from './platforms'; -import installCertificateAuthority, { ensureCACertReadable, uninstall } from './certificate-authority'; -import generateDomainCertificate from './certificates'; import UI, { UserInterface } from './user-interface'; -import isValidDomain from 'is-valid-domain'; export { uninstall }; const debug = createDebug('devcert'); @@ -69,7 +64,7 @@ type IReturnData = (IDomainData) & (IReturnCa) & (IRe export async function certificateFor(requestedDomains: string | string[], options: O = {} as O): Promise> { const domains = Array.isArray(requestedDomains) ? requestedDomains : [requestedDomains]; domains.forEach((domain) => { - if (domain !== "localhost" && !isValidDomain(domain, { subdomain: true, wildcard: false, allowUnicode: true, topLevel: false })) { + if (domain !== "localhost" && !isValidDomain(domain, { subdomain: true, wildcard: false, allowUnicode: true, topLevel: false }) && isIP(domain) === 0) { throw new Error(`"${domain}" is not a valid domain name.`); } }); From 960946222ee033284cc90f0503934c80e6cf4937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evandro=20Ara=C3=BAjo?= Date: Thu, 26 Jan 2023 17:08:45 -0300 Subject: [PATCH 2/3] fix ip prefix for SAN --- src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index 900cc69..0f9d3fe 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -54,7 +54,7 @@ function generateSubjectAltNames(domains: string[]): string { return domains .reduce((dnsEntries, domain) => isIP(domain) > 0 - ? dnsEntries.concat(`DNS.${dnsEntries.length + 1} = ${domain}`) + ? dnsEntries.concat(`IP.${dnsEntries.length + 1} = ${domain}`) : dnsEntries.concat([ `DNS.${dnsEntries.length + 1} = ${domain}`, `DNS.${dnsEntries.length + 2} = *.${domain}`, From 939631f69db80fdf174955cf789b52e6ca054d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evandro=20Ara=C3=BAjo?= Date: Thu, 26 Jan 2023 17:09:49 -0300 Subject: [PATCH 3/3] refactoring invalid domain error message --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index fc53097..831b364 100644 --- a/src/index.ts +++ b/src/index.ts @@ -65,7 +65,7 @@ export async function certificateFor(requestedDomains: string const domains = Array.isArray(requestedDomains) ? requestedDomains : [requestedDomains]; domains.forEach((domain) => { if (domain !== "localhost" && !isValidDomain(domain, { subdomain: true, wildcard: false, allowUnicode: true, topLevel: false }) && isIP(domain) === 0) { - throw new Error(`"${domain}" is not a valid domain name.`); + throw new Error(`"${domain}" is not a domain name or IP address.`); } });