Skip to content

Commit

Permalink
chore: load config to cert from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
mohameedsherif committed Aug 1, 2024
1 parent aa84f9a commit 98b5e33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ cli
.usage('tlsx secure <domain> [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,
Expand Down
13 changes: 8 additions & 5 deletions src/keys.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -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() {
Expand All @@ -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,
},
]

Expand Down Expand Up @@ -149,9 +151,10 @@ export async function generateCert(options?: GenerateCertOptions) {
shortName: 'L',
value: DEFAULT_L,
},

{
shortName: 'CN',
value: options.hostCertCN,
value: config?.ssl?.organizationName,
},
]

Expand Down

0 comments on commit 98b5e33

Please sign in to comment.