From 88c8b812a2b86988c23d4499f9117be11ed4839d Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 11 Aug 2016 00:58:14 -0400 Subject: [PATCH] closer --- lib/worker.js | 27 +++++++++++++++++++++++++-- serve.js | 12 ++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/worker.js b/lib/worker.js index 13cf3be..4a907a0 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -2,10 +2,14 @@ module.exports.create = function (opts) { + + opts.workerSniCallback = require('le-sni-auto').create({ - getCertificates: function (domain, certs, cb) { + notBefore: opts.notBefore || (10 * 24 * 60 * 60 * 1000) + , notAfter: opts.notAfter || (5 * 24 * 60 * 60 * 1000) + , getCertificates: function (domain, certs, cb) { opts.approveDomains(domain, certs, function (err, certs) { - process.send({ type: 'LE_REQUEST', domain: domain, options: { domains: [domain] } certs: certs }); + process.send({ type: 'LE_REQUEST', domain: domain, options: { domains: [domain] }, certs: certs }); process.on('message', function (msg) { if (msg.domain === domain) { @@ -16,5 +20,24 @@ module.exports.create = function (opts) { } }).sniCallback; + + + opts.httpsOptions = require('localhost.daplie.com-certificates').merge({ SNICallback: opts.workerSniCallback }); + + + + opts.challenge = { + get: opts.getChallenge + || (opts.challenge && opts.challenge.get) + || require('le-challenge-fs').create({ webrootPath: opts.webrootPath }).get + }; + + + + // opts.challenge.get, opts.acmeChallengePrefix + opts.middleware = require('letsencrypt/lib/middleware').create(opts); + + + return opts; }; diff --git a/serve.js b/serve.js index 0e2d741..411df1a 100644 --- a/serve.js +++ b/serve.js @@ -21,7 +21,7 @@ function runMaster() { // // Since we implement it in the worker (below) in this example // we'll give it an immediate approval here in the master - var results = { options: { domains: [domain] }, certs: certs }; + var results = { domain: domain, options: { domains: [domain] }, certs: certs }; cb(null, results); } }); @@ -53,7 +53,7 @@ function runWorker() { , approveDomains: function (domain, certs, cb) { // opts = { domains, email, agreeTos, tosUrl } // certs = { subject, altnames, expiresAt, issuedAt } - var results = { options: { domains: [domain] }, certs: certs }; + var results = { domain: domain, options: { domains: [domain] }, certs: certs }; @@ -81,8 +81,12 @@ function runWorker() { res.end("Hello, World!"); } - var plainServer = require('http').createServer(worker.handleAcmeOrRedirectToHttps()); - var server = require('https').createServer(worker.httpsOptions, worker.handleAcmeOrUse(app)); + + // worker.handleAcmeOrRedirectToHttps() + // worker.handleAcmeOrUse(app) + var redirectHttps = require('redirect-https')(); + var plainServer = require('http').createServer(worker.middleware(redirectHttps)); + var server = require('https').createServer(worker.httpsOptions, worker.middleware(app)); plainServer.listen(80); server.listen(443); }