Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow IP address as domains #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
21 changes: 12 additions & 9 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(`IP.${dnsEntries.length + 1} = ${domain}`)
: dnsEntries.concat([
`DNS.${dnsEntries.length + 1} = ${domain}`,
`DNS.${dnsEntries.length + 2} = *.${domain}`,
]), [] as string[])
.join("\r\n");
}

Expand Down
25 changes: 10 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -69,8 +64,8 @@ type IReturnData<O extends Options = {}> = (IDomainData) & (IReturnCa<O>) & (IRe
export async function certificateFor<O extends Options>(requestedDomains: string | string[], options: O = {} as O): Promise<IReturnData<O>> {
const domains = Array.isArray(requestedDomains) ? requestedDomains : [requestedDomains];
domains.forEach((domain) => {
if (domain !== "localhost" && !isValidDomain(domain, { subdomain: true, wildcard: false, allowUnicode: true, topLevel: false })) {
throw new Error(`"${domain}" is not a valid domain name.`);
if (domain !== "localhost" && !isValidDomain(domain, { subdomain: true, wildcard: false, allowUnicode: true, topLevel: false }) && isIP(domain) === 0) {
throw new Error(`"${domain}" is not a domain name or IP address.`);
}
});

Expand Down