Verified Commit 9a1f8eda authored by Sebastiaan Deckers's avatar Sebastiaan Deckers 馃悜

fix: clean up acme files and force new generation

parent 49c6e992
......@@ -2,9 +2,10 @@ const shellEscape = require('shell-escape')
const { exec } = require('child-process-promise')
const { s3cmd } = require('./s3cmd')
const { join } = require('path')
const { copyFile, unlink } = require('fs')
const { copyFile } = require('fs')
const { promisify } = require('util')
const ms = require('ms')
const rimraf = require('rimraf')
async function issueCertificate (fastify, domain) {
const { configuration, mongo: { db }, pubnub } = fastify
......@@ -31,23 +32,25 @@ async function issueCertificate (fastify, domain) {
}
}
const directory = join(configuration.acme.home, `${domain}_ecc`)
try {
await exec(shellEscape([
configuration.acme.acmesh,
'--issue',
'--force',
'--keylength', 'ec-256',
'--webroot', configuration.acme.webroot,
'--home', configuration.acme.home,
...domains.reduce((args, name) => [...args, '--domain', name], [])
]), { capture: ['stdout', 'stderr'] })
} catch (error) {
await promisify(rimraf)(directory)
if (!error.stderr.includes('Domain key exists')) {
throw error
}
}
const directory = join(configuration.acme.home, `${domain}_ecc`)
await Promise.all([
promisify(copyFile)(
join(directory, `${domain}.key`),
......@@ -67,10 +70,7 @@ async function issueCertificate (fastify, domain) {
`s3://${configuration.s3.bucket}/sites/${domain}/crypto/`
)
await Promise.all([
promisify(unlink)(join(directory, 'key.pem')),
promisify(unlink)(join(directory, 'cert.pem'))
])
await promisify(rimraf)(directory)
await db.collection('certificates').updateOne(
{ domain },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment