-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ssl): refactor ssl setup to use acme.sh rather than greenlock
no issue - greenlock implicitly requires python, acme.sh is much more widely used
- Loading branch information
Showing
6 changed files
with
43 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
acme.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
'use strict'; | ||
const fs = require('fs-extra'); | ||
const url = require('url'); | ||
const path = require('path'); | ||
const execa = require('execa'); | ||
const download = require('download'); | ||
|
||
const LIVE_URL = 'https://acme-v01.api.letsencrypt.org/directory'; | ||
const STAGING_URL = 'https://acme-staging.api.letsencrypt.org/directory'; | ||
// This is how we will do version control for acme.sh | ||
const ACME_VERSION = '2.7.2'; | ||
|
||
module.exports = function letsencrypt(instance, email, staging) { | ||
let hostname = url.parse(instance.config.get('url')).hostname; | ||
let rootPath = path.resolve(instance.dir, 'system', 'nginx-root'); | ||
let letsencryptFolder = path.join(instance.dir, 'system', 'letsencrypt'); | ||
let sslGenArgs = `certonly --agree-tos --email ${email} --webroot --webroot-path ${rootPath}` + | ||
` --config-dir ${letsencryptFolder} --domains ${hostname} --server ${staging ? STAGING_URL : LIVE_URL}`; | ||
module.exports = function letsencrypt(instance, email, staging, renew) { | ||
let downloadPromise; | ||
let acmePath = path.join(__dirname, 'acme.sh'); | ||
|
||
return execa('greenlock', sslGenArgs.split(' '), { | ||
preferLocal: true, | ||
localDir: __dirname | ||
if (fs.existsSync(acmePath)) { | ||
downloadPromise = Promise.resolve(); | ||
} else { | ||
let acmeUrl = `https://raw.githubusercontent.com/Neilpang/acme.sh/${ACME_VERSION}/acme.sh`; | ||
downloadPromise = download(acmeUrl).then(data => fs.writeFile(acmePath, data, {mode: 0o774})); | ||
} | ||
|
||
return downloadPromise.then(() => { | ||
let hostname = url.parse(instance.config.get('url')).hostname; | ||
let rootPath = path.resolve(instance.dir, 'system', 'nginx-root'); | ||
let letsencryptFolder = path.join(instance.dir, 'system', 'letsencrypt'); | ||
|
||
fs.ensureDirSync(letsencryptFolder); | ||
|
||
let fullchain = path.join(letsencryptFolder, 'fullchain.pem'); | ||
let privkey = path.join(letsencryptFolder, 'privkey.pem'); | ||
|
||
let cmd = `${acmePath} --${renew ? 'renew' : 'issue'} --domain ${hostname} --webroot ${rootPath} ` + | ||
`--accountemail ${email} --key-file ${privkey} --fullchain-file ${fullchain}${staging ? ' --staging' : ''}`; | ||
|
||
return execa.shell(cmd); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.