Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mohameedsherif committed May 23, 2024
1 parent c57b8b7 commit 3363f1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 0 additions & 3 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ cli

const certFilePath = options?.output ?? `${os.homedir()}/.stacks/ssl/stacks.localhost.crt`

console.log();

// Check if the certificate is expired or domain already exists

if ((await isCertificateExpired(certFilePath)) || !(await isDomainExists(domain, certFilePath))) {

log.debug(`Start to generate a new certificate for domain: ${domain}`)

console.log('Start to generate a new certificate for domain:', domain)
Expand Down
17 changes: 16 additions & 1 deletion src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ const getCANotAfter = (notBefore: any) => {
// Function to check if a certificate file has expired
export const isCertificateExpired = async (certFilePath: string): Promise<boolean> => {
return new Promise((resolve, reject) => {

try {
// Check if the file exists
if (!fs.existsSync(certFilePath)) {
reject('Certificate not found')
}

// Read the certificate file
const certData = fs.readFileSync(certFilePath, 'utf8')



// check if cert exists
if (!certData) {
reject('Certificate not found')
Expand All @@ -69,10 +77,11 @@ export const isCertificateExpired = async (certFilePath: string): Promise<boolea
const isExpired = expiryDate < new Date()

resolve(isExpired)

} catch (error) {
// Handle errors
console.error(`Error checking certificate expiry: ${error}`)
reject(error) // Reject the promise with the error
// reject(error) // Reject the promise with the error
}
})
}
Expand All @@ -82,6 +91,12 @@ export const isDomainExists = async (domainToCheck: string, certificatePath: str
// Read the certificate file
const certificateContents = fs.readFileSync(certificatePath, 'utf8')


if(!certificateContents) {

throw new Error('Certificate not found')
}

// Parse the certificate data
const certificate = forge.pki.certificateFromPem(certificateContents)

Expand Down

0 comments on commit 3363f1d

Please sign in to comment.