From 98b5e33868c1cc263529185291bd6d209f760918 Mon Sep 17 00:00:00 2001 From: Shicosoft Date: Thu, 1 Aug 2024 20:10:00 +0300 Subject: [PATCH] chore: load config to cert from config file --- bin/cli.ts | 6 +++--- src/keys.ts | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bin/cli.ts b/bin/cli.ts index 87d2c47..ab47290 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -27,17 +27,17 @@ cli .usage('tlsx secure [options]') .example('tlsx secure example.com --output /etc/ssl') .action(async (domain: string, options?: Options) => { + domain = domain ?? config?.ssl?.altNameURIs[0] + log.info(`Generating a self-signed SSL certificate for: ${domain}`) log.debug('Options:', options) - console.log(domain) - const CAcert = await createRootCA() const HostCert = await generateCert({ - hostCertCN: domain, + hostCertCN: config?.ssl?.commonName ?? domain, domain, rootCAObject: { certificate: CAcert.certificate, diff --git a/src/keys.ts b/src/keys.ts index b7d5c4c..d59445f 100644 --- a/src/keys.ts +++ b/src/keys.ts @@ -1,9 +1,9 @@ import fs from 'node:fs' import os from 'node:os' import path from 'node:path' -import { exec, log, runCommand, runCommands } from '@stacksjs/cli' +import { log, runCommand } from '@stacksjs/cli' import forge, { pki, tls } from 'node-forge' -import { resolveConfig } from './config' +import { config, resolveConfig } from './config' import type { GenerateCertOptions } from './types' const makeNumberPositive = (hexString: string) => { @@ -49,7 +49,7 @@ const getCANotAfter = (notBefore: any) => { const DEFAULT_C = 'US' const DEFAULT_ST = 'California' const DEFAULT_L = 'Melbourne' -const DEFAULT_O = 'Tlsx-Stacks-RootCA' +const DEFAULT_O = config.ssl?.organizationName // Generate a new Root CA Certificate export async function createRootCA() { @@ -66,13 +66,15 @@ export async function createRootCA() { shortName: 'ST', value: DEFAULT_ST, }, + { shortName: 'L', value: DEFAULT_L, }, + { shortName: 'CN', - value: DEFAULT_O, + value: config?.ssl?.organizationName, }, ] @@ -149,9 +151,10 @@ export async function generateCert(options?: GenerateCertOptions) { shortName: 'L', value: DEFAULT_L, }, + { shortName: 'CN', - value: options.hostCertCN, + value: config?.ssl?.organizationName, }, ]