Skip to content

Commit

Permalink
chore: several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mohameedsherif authored and chrisbbreuer committed May 1, 2024
1 parent 6108d5b commit 20c6683
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import os from 'node:os'
import { CAC } from 'cac'
import { log } from '@stacksjs/logging'
import { version } from '../package.json'
import { addCertToSystemTrustStore, generateCert } from '../src'

const cli = new CAC('tlsx')

Expand All @@ -26,6 +27,7 @@ cli
.action(async (domain?: string, options?: Options) => {
log.debug(`Generating a self-signed SSL certificate for domain: ${domain}`)
log.debug('Options:', options)
await addCertToSystemTrustStore((await generateCert()).cert) // TODO: domain
// Generate a keypair and create an X.509v3 certificate for the domain
// await generateAndSaveCertificates()
// await addRootCAToSystemTrust()
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@types/bun": "^1.0.12",
"@types/node-forge": "^1.3.11",
"bun-plugin-dts-auto": "^0.10.0",
"sslx": "^0.0.4",
"vitepress": "^1.1.0"
},
"simple-git-hooks": {
Expand Down
9 changes: 5 additions & 4 deletions src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import crypto from 'node:crypto'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { log, runCommand } from '@stacksjs/cli'
import { log, runCommand, runCommands } from '@stacksjs/cli'
import forge, { pki, tls } from 'node-forge'
import { resolveConfig } from './config'
import type { GenerateCertOptions } from './types'
Expand Down Expand Up @@ -77,13 +77,14 @@ export async function addCertToSystemTrustStore(cert: string, options?: AddCertO
if (platform === 'darwin') // macOS
await runCommand(`sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ${certPath}`)
else if (platform === 'win32') // Windows
await runCommand(`certutil -enterprise -f -v -AddStore "Root" ${certPath}`)

await runCommand(`certutil -f -v -addstore -enterprise Root ${certPath}`)

else if (platform === 'linux') // Linux (This might vary based on the distro)
// for Ubuntu/Debian based systems
await runCommand(`sudo cp ${certPath} /usr/local/share/ca-certificates/ && sudo update-ca-certificates`)
await runCommands([`sudo cp ${certPath} /usr/local/share/ca-certificates/`, `sudo update-ca-certificates`])
else
throw new Error(`Unsupported platform: ${platform}`)

return certPath
}

Expand Down

0 comments on commit 20c6683

Please sign in to comment.