From 6764ed368406784c9d4de10471893caea637a7b9 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 11 Aug 2016 03:07:20 -0400 Subject: [PATCH] very very very nearly complete --- lib/master.js | 25 +++++++++++++++++++++---- lib/worker.js | 18 +++++++++++++++++- serve.js | 1 + 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/master.js b/lib/master.js index 08c6dcd..16b2cd0 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.daplie.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 81ce14d..8d4d993 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,