diff --git a/lib/master.js b/lib/master.js index 08c6dcd..4b5142c 100644 --- a/lib/master.js +++ b/lib/master.js @@ -25,20 +25,37 @@ module.exports.create = function (opts) { }); worker.on('message', function (msg) { - log(opts.debug, 'Message from worker ' + worker.pid, msg, msg && msg.type); + log(opts.debug, 'Message from worker ' + worker.id); if ('LE_REQUEST' !== (msg && msg.type)) { + log(opts.debug, 'Ignoring irrelevant message'); + log(opts.debug, msg); return; } + log(opts.debug, 'about to approveDomains'); opts.approveDomains(msg.domain, msg.certs, function (err, results) { if (err) { log(opts.debug, 'Approval got ERROR', err.stack || err); - worker.send({ type: 'LE_RESPONSE', error: err }); + worker.send({ type: 'LE_RESPONSE', domain: msg.domain, error: err }); return; } var promise; + // /* + var certs = require('localhost.coolaj86.com-certificates').merge({ + subject: msg.domain + , altnames: [ msg.domain ] + , issuedAt: Date.now() + , expiresAt: Date.now() + (90 * 24 * 60 * 60 * 1000) + }); + certs.privkey = certs.key.toString('ascii'); + certs.cert = certs.cert.toString('ascii'); + certs.chain = ''; + worker.send({ type: 'LE_RESPONSE', domain: msg.domain, certs: certs }); + return; + // */ + if (results.certs) { promise = opts._le.renew(results.options, results.certs); } @@ -49,10 +66,10 @@ 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', certs: certs }); + worker.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', error: err }); + worker.send({ type: 'LE_RESPONSE', domain: msg.domain, error: err }); }); }); }); diff --git a/lib/worker.js b/lib/worker.js index caec885..c397207 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -1,5 +1,18 @@ 'use strict'; +function log(debug) { + if (!debug) { + return; + } + + var args = Array.prototype.slice.call(arguments); + args.shift(); + args.unshift("[le/lib/core.js]"); + console.log.apply(console, args); +} + + + module.exports.create = function (opts) { @@ -12,8 +25,11 @@ module.exports.create = function (opts) { process.send({ type: 'LE_REQUEST', domain: domain, options: { domains: [domain] }, certs: certs }); process.on('message', function (msg) { + log(opts.debug, 'Message from master'); + log(opts.debug, msg); + if (msg.domain === domain) { - cb(msg.certs); + cb(null, msg.certs); } }); }); diff --git a/serve.js b/serve.js index 411df1a..1bb964c 100644 --- a/serve.js +++ b/serve.js @@ -43,6 +43,7 @@ function runWorker() { , notBefore: 15 * 24 * 60 * 60 * 1000 , notAfter: 10 * 24 * 60 * 60 * 1000 // optional + , webrootPath: require('os').tmpdir() + require('path').sep + 'acme-challenge' /* , getChallenge: function (domain, token, cb) { // the default behavior is to pass a message to master,