Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Jun 1, 2024
1 parent 9807e78 commit 88f11a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CreateRootCA, addCertToSystemTrustStoreAndSaveCerts, generateCert } fro
const cli = new CAC('tlsx')

interface Options {
domain: string
output: string
key: string
cert: string
Expand All @@ -25,6 +26,8 @@ cli
.usage('tlsx secure <domain> [options]')
.example('tlsx secure example.com --output /etc/ssl')
.action(async (domain: string, options?: Options) => {
domain = domain ?? options?.domain

log.debug(`Generating a self-signed SSL certificate for domain: ${domain}`)
log.debug('Options:', options)

Expand Down
5 changes: 3 additions & 2 deletions src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,11 @@ export async function addCertToSystemTrustStoreAndSaveCerts(
await runCommand(
`sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ${CAcertPath}`,
)

else if (platform === 'win32')
// Windows
await runCommand(`certutil -f -v -addstore -enterprise Root ${CAcertPath}`)

else if (platform === 'linux')
// Linux (This might vary based on the distro)
// for Ubuntu/Debian based systems
Expand All @@ -322,16 +324,15 @@ export async function addCertToSystemTrustStoreAndSaveCerts(
// reload system trust store
`sudo update-ca-certificates`,
])

else throw new Error(`Unsupported platform: ${platform}`)

return certPath
}

//
export function storeCert(cert: { certificate: string; privateKey: string }, options?: AddCertOptions) {
// Construct the path using os.homedir() and path.join()
const certPath = options?.customCertPath || path.join(os.homedir(), '.stacks', 'ssl', `stacks.localhost.crt`)

const certKeyPath = options?.customCertPath || path.join(os.homedir(), '.stacks', 'ssl', `stacks.localhost.crt.key`)

// Ensure the directory exists before writing the file
Expand Down

0 comments on commit 88f11a7

Please sign in to comment.