diff --git a/master.js b/master.js index d504eed..3200742 100644 --- a/master.js +++ b/master.js @@ -4,6 +4,7 @@ // opts.approveDomains(options, certs, cb) module.exports.create = function (opts) { opts = opts || { }; + opts._workers = []; opts.webrootPath = opts.webrootPath || require('os').tmpdir() + require('path').sep + 'acme-challenge'; if (!opts.letsencrypt) { opts.letsencrypt = require('letsencrypt').create(opts); } if ('function' !== typeof opts.approveDomains) { @@ -23,6 +24,7 @@ module.exports.create = function (opts) { opts._le = opts.letsencrypt; opts.addWorker = function (worker) { + opts._workers.push(worker); worker.on('online', function () { log(opts.debug, 'worker is up'); @@ -75,7 +77,9 @@ module.exports.create = function (opts) { promise.then(function (certs) { log(opts.debug, 'Approval got certs', certs); // certs = { subject, domains, issuedAt, expiresAt, privkey, cert, chain }; - worker.send({ type: 'LE_RESPONSE', domain: msg.domain, certs: certs }); + opts._workers.forEach(function (w) { + w.send({ type: 'LE_RESPONSE', domain: msg.domain, certs: certs }); + }); }, function (err) { log(opts.debug, 'Approval got ERROR', err.stack || err); worker.send({ type: 'LE_RESPONSE', domain: msg.domain, error: err }); diff --git a/worker.js b/worker.js index e5b2e72..e24ee6e 100644 --- a/worker.js +++ b/worker.js @@ -15,7 +15,14 @@ function log(debug) { module.exports.create = function (opts) { - + // if another worker updates the certs, + // receive a copy from master here as well + // and update the sni cache manually + process.on('message', function (msg) { + if ('LE_RESPONSE' === msg.type && msg.certs) { + opts.sni.cacheCerts(msg.certs); + } + }); opts.sni = require('le-sni-auto').create({ notBefore: opts.notBefore || (10 * 24 * 60 * 60 * 1000)