From ef562d2984d048628985cc6359dc566ab2612fe1 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 6 Apr 2019 00:19:12 -0600 Subject: [PATCH] v3.0.1: Doc and code updates --- README.md | 24 ++++++++++---------- index.js | 62 +++++++++++++++++++++++++++++++--------------------- package.json | 2 +- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 2c3e238..d4a3275 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,20 @@ -| [Greenlock](https://git.coolaj86.com/coolaj86/greenlock.js) (library) -| [Greenlock CLI](https://git.coolaj86.com/coolaj86/greenlock-cli.js) -| [greenlock-express](https://git.coolaj86.com/coolaj86/greenlock-express.js) -| [greenlock-koa](https://git.coolaj86.com/coolaj86/greenlock-koa.js) -| [greenlock-hapi](https://git.coolaj86.com/coolaj86/greenlock-hapi.js) -| +# [le-challenge-manual](https://git.coolaj86.com/coolaj86/le-challenge-manual.js.git) -le-challenge-manual -=================== +| A [Root](https://rootprojects.org) Project | -A [Root](https://rootprojects.org) Project +An extremely simple reference implementation +of an ACME (Let's Encrypt) challenge strategy +for [Greenlock](https://git.coolaj86.com/coolaj86/greenlock-express.js) v2.7+ (and v3). -A manual cli-based strategy for [Greenlock](https://git.coolaj86.com/coolaj86/greenlock-express.js) v2.7+ (and v3). +* Prints the ACME challenge details to the terminal (and waits for you to hit enter before continuing) +* Asks you to enter the change response. +* Let's you know it's safeto remove the challenge. -Prints the ACME challenge Token and Key and then waits for you to hit enter before continuing. +Other ACME Challenge Reference Implementations: + +* [le-challenge-manual](https://git.coolaj86.com/coolaj86/le-challenge-manual.js.git) +* [le-challenge-http](https://git.coolaj86.com/coolaj86/le-challenge-http.js.git) +* [le-challenge-dns](https://git.coolaj86.com/coolaj86/le-challenge-dns.js.git) Install ------- diff --git a/index.js b/index.js index ca1a2b1..9fc133c 100644 --- a/index.js +++ b/index.js @@ -49,11 +49,11 @@ Challenge.create = function (config) { challenger.get = function (opts) { var ch = opts.challenge; if ('http-01' === ch.type) { - return Challenge._getHttp(opts); + return Challenge._get(opts); } else if ('dns-01' === ch.type) { - return Challenge._getDns(opts); + return Challenge._get(opts); } else { - return Challenge._getAny(opts); + return Challenge._get(opts); } }; @@ -79,18 +79,19 @@ Challenge._setHttp = function (args, cb) { // TODO let acme-v2 handle generating this url console.info('\tURL: http://' + ch.altname + '/.well-known/acme-challenge/' + ch.token); console.info(""); - console.info("And, if you need additional information for debugging:"); - console.info(""); - console.info(JSON.stringify(httpChallengeToJson(ch), null, 2).replace(/^/gm, '\t')); - console.info(""); + if (args.debug) { + console.info("And, if you need additional information for debugging:"); + console.info(""); + console.info(JSON.stringify(httpChallengeToJson(ch), null, 2).replace(/^/gm, '\t')); + console.info(""); + } console.info("This message won't self-destruct, but you may press hit the any as soon as you're ready to continue..."); - console.info(""); console.info("[Press the ANY key to continue...]"); process.stdin.resume(); process.stdin.once('data', function () { process.stdin.pause(); - cb(null); + cb(null, null); }); }; @@ -104,16 +105,19 @@ Challenge._setDns = function (args, cb) { console.info(""); console.info(ch.dnsHost + "\tTXT\t" + ch.dnsKeyAuthorization + "\tTTL 60"); console.info(""); - console.info("Next, wait, no... there is no next. That's it - but here's some stuff anyway:"); - console.info(""); - console.info(JSON.stringify(dnsChallengeToJson(ch), null, 2).replace(/^/gm, '\t')); - console.info(""); + console.info("Next, wait, no... there is no next."); + if (args.debug) { + console.log("Oh, did you want this?"); + console.info(""); + console.info(JSON.stringify(dnsChallengeToJson(ch), null, 2).replace(/^/gm, '\t')); + console.info(""); + } console.info("[Press the ANY key to continue...]"); process.stdin.resume(); process.stdin.once('data', function () { process.stdin.pause(); - cb(null); + cb(null, null); }); }; @@ -128,9 +132,9 @@ Challenge._setAny = function (args, cb) { console.info("[Press the ANY key to continue...]"); process.stdin.resume(); - process.stdin.on('data', function () { + process.stdin.once('data', function () { process.stdin.pause(); - cb(null); + cb(null, null); }); }; @@ -169,29 +173,37 @@ Challenge._removeAny = function (args) { }; // nothing to do here, that's why it's manual -Challenge._get = function (args, cb) { - console.info(""); - console.info("Woah! Hey, guess what!? That's right you guessed it:"); - console.info("It's time to painstakingly type out the ACME challenge response with your bear hands. Yes. Your bear hands."); - process.stdout.write("> "); +Challenge._get = function (args) { + var ch = args.challenge; + + if (!Challenge._getCache[ch.altname + ':' + ch.token]) { + Challenge._getCache[ch.altname + ':' + ch.token] = true; + console.info(""); + console.info('GET http://' + ch.altname + '/.well-known/acme-challenge/' + ch.token); + console.info("It's time to painstakingly type out the ACME challenge response with your bear hands. Yes. Your bear hands."); + process.stdout.write("> "); + } // Using a promise here just to show that Promises are support // (in fact, they're the default) return new Promise(function (resolve, reject) { process.stdin.resume(); - process.stdin.on('error', reject); - process.stdin.on('data', function (chunk) { + process.stdin.once('error', reject); + process.stdin.once('data', function (chunk) { process.stdin.pause(); var result = chunk.toString(); try { result = JSON.parse(result); } catch(e) { - args.keyAuthorization = result; + args.challenge.keyAuthorization = result; + result = args.challenge; } - cb(null); + resolve(result); }); }); }; +// Because the ACME server will hammer us with requests, and that's confusing during a manual test: +Challenge._getCache = {}; function httpChallengeToJson(ch) { return { diff --git a/package.json b/package.json index ad9db33..cb5f2a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "le-challenge-manual", - "version": "3.0.0", + "version": "3.0.1", "description": "A cli-based strategy for node-letsencrypt. Prints the ACME challenge Token and Key and then waits for you to hit enter before continuing.", "main": "index.js", "homepage": "https://git.coolaj86.com/coolaj86/le-challenge-manual.js",