From 2bc14032001c1e92ec89f6b45370993b9a0af35c Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 16 Dec 2015 12:57:53 +0000 Subject: [PATCH] pure node :-) --- index.js | 14 +++++++++----- lib/common.js | 8 ++++++-- lib/default-handlers.js | 6 +++--- lib/letiny-core.js | 26 +++++++++++++++----------- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 3d23ae8..3ad21e8 100644 --- a/index.js +++ b/index.js @@ -86,7 +86,7 @@ LE.create = function (defaults, handlers, backend) { }; } if (!handlers.getChallenge) { - if (!defaults.webrootPath) { + if (!defaults.manual && !defaults.webrootPath) { // GET /.well-known/acme-challenge/{{challengeKey}} should return {{tokenValue}} throw new Error("handlers.getChallenge or defaults.webrootPath must be set"); } @@ -209,13 +209,13 @@ LE.create = function (defaults, handlers, backend) { return function (req, res, next) { if (0 !== req.url.indexOf(prefix)) { - console.log('[LE middleware]: pass'); + //console.log('[LE middleware]: pass'); next(); return; } //args.domains = [req.hostname]; - console.log('[LE middleware]:', req.hostname, req.url, req.url.slice(prefix.length)); + //console.log('[LE middleware]:', req.hostname, req.url, req.url.slice(prefix.length)); handlers.getChallenge(req.hostname, req.url.slice(prefix.length), function (err, token) { if (err) { res.send("Error: These aren't the tokens you're looking for. Move along."); @@ -245,9 +245,9 @@ LE.create = function (defaults, handlers, backend) { return; } - console.log("[NLE]: begin registration"); + //console.log("[NLE]: begin registration"); return backend.registerAsync(copy).then(function () { - console.log("[NLE]: end registration"); + //console.log("[NLE]: end registration"); // calls fetch because fetch calls cacheCertInfo return le.fetch(args, cb); }, cb); @@ -317,6 +317,10 @@ LE.create = function (defaults, handlers, backend) { le._fetchHelper(args, cb); } , register: function (args, cb) { + if (!Array.isArray(args.domains)) { + cb(new Error('args.domains should be an array of domains')); + return; + } // this may be run in a cluster environment // in that case it should NOT check the cache // but ensure that it has the most fresh copy diff --git a/lib/common.js b/lib/common.js index 7be610b..f8ccde6 100644 --- a/lib/common.js +++ b/lib/common.js @@ -5,8 +5,12 @@ var PromiseA = require('bluebird'); module.exports.fetchFromDisk = function (args, defaults) { var hostname = args.domains[0]; - var crtpath = defaults.configDir + defaults.fullchainTpl.replace(/:hostname/, hostname); - var privpath = defaults.configDir + defaults.privkeyTpl.replace(/:hostname/, hostname); + var crtpath = (args.fullchainPath || defaults.fullchainPath) + || (defaults.configDir + + (args.fullchainTpl || defaults.fullchainTpl || ':hostname/fullchain.pem').replace(/:hostname/, hostname)); + var privpath = (args.privkeyPath || defaults.privkeyPath) + || (defaults.configDir + + (args.privkeyTpl || defaults.privkeyTpl || ':hostname/privkey.pem').replace(/:hostname/, hostname)); return PromiseA.all([ fs.readFileAsync(privpath, 'ascii') diff --git a/lib/default-handlers.js b/lib/default-handlers.js index dfcd225..17852a2 100644 --- a/lib/default-handlers.js +++ b/lib/default-handlers.js @@ -12,8 +12,8 @@ module.exports.setChallenge = function (args, challengePath, keyAuthorization, d var mkdirp = require('mkdirp'); // TODO should be args.webrootPath - console.log('args.webrootPath, challengePath'); - console.log(args.webrootPath, challengePath); + //console.log('args.webrootPath, challengePath'); + //console.log(args.webrootPath, challengePath); mkdirp(args.webrootPath, function (err) { if (err) { done(err); @@ -29,7 +29,7 @@ module.exports.setChallenge = function (args, challengePath, keyAuthorization, d module.exports.getChallenge = function (args, key, done) { //var hostname = args.domains[0]; - console.log("getting the challenge", args, key); + //console.log("getting the challenge", args, key); fs.readFile(path.join(args.webrootPath, key), 'utf8', done); }; diff --git a/lib/letiny-core.js b/lib/letiny-core.js index bc1b790..6be57e0 100644 --- a/lib/letiny-core.js +++ b/lib/letiny-core.js @@ -176,12 +176,18 @@ function getCertificateAsync(account, args, defaults, handlers) { , sfs.writeFileAsync(chainPath, result.chain, 'ascii') , sfs.writeFileAsync(fullchainPath, result.fullchain, 'ascii') , sfs.writeFileAsync(privkeyPath, result.key, 'ascii') - ]); + ]).then(function () { + // TODO format result licesy + //console.log(liveDir); + //console.log(result); + return { + certPath: certPath + , chainPath: chainPath + , fullchainPath: fullchainPath + , privkeyPath: privkeyPath + }; + }); }); - - console.log(liveDir); - console.log(result); - throw new Error("IMPLEMENTATION NOT COMPLETE"); }); }); } @@ -193,8 +199,6 @@ function registerWithAcme(args, defaults, handlers) { var configDir = args.configDir || defaults.configDir || LE.configDir; args.server = server; - console.log('args.server'); - console.log(server); args.renewalDir = args.renewalDir || path.join(configDir, 'renewal', args.domains[0] + '.conf'); args.accountsDir = args.accountsDir || path.join(configDir, 'accounts', acmeHostname, 'directory'); @@ -228,14 +232,14 @@ function registerWithAcme(args, defaults, handlers) { } */ - console.log(account); + //console.log(account); return fetchFromConfigLiveDir(args, defaults).then(function (certs) { // if nothing, register and save // if something, check date (don't register unless 30+ days) // if good, don't bother registering // (but if we get to the point that we're actually calling // this function, that shouldn't be the case, right?) - console.log(certs); + //console.log(certs); if (!certs) { // no certs, seems like a good time to get some return getCertificateAsync(account, args, defaults, handlers); @@ -244,12 +248,12 @@ function registerWithAcme(args, defaults, handlers) { // cert is at least 27 days old we can renew that return getCertificateAsync(account, args, defaults, handlers); } - else if (args.force) { + else if (args.duplicate) { // YOLO! I be gettin' fresh certs 'erday! Yo! return getCertificateAsync(account, args, defaults, handlers); } else { - console.warn('[WARN] Ignoring renewal attempt for certificate less than 27 days old. Use args.force to force.'); + console.warn('[WARN] Ignoring renewal attempt for certificate less than 27 days old. Use args.duplicate to force.'); // We're happy with what we have return certs; }