From 4ee2f815359b519219b71055272c7512fb1d35f8 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 7 Apr 2019 17:31:03 -0600 Subject: [PATCH] v3.0.1: ACME http-01 challenge reference implementation for Greenlock v2.7+ (and v3) --- README.md | 16 ++++++++-------- index.js | 12 ++++++++---- package-lock.json | 4 ++-- package.json | 10 +++++----- test.js | 33 ++++++++------------------------- 5 files changed, 31 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 89711a8..3955161 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# [le-challenge-http](https://git.coolaj86.com/coolaj86/le-challenge-http.js) +# [greenlock-challenge-http](https://git.coolaj86.com/coolaj86/greenlock-challenge-http.js) | A [Root](https://rootprojects.org) Project | @@ -17,15 +17,15 @@ GET http://example.com/.well-known/acme-challenge/xxxxxxxxxxxxxxxx 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) +* [greenlock-challenge-manual](https://git.coolaj86.com/coolaj86/greenlock-challenge-manual.js.git) +* [**greenlock-challenge-http**](https://git.coolaj86.com/coolaj86/greenlock-challenge-http.js.git) +* [greenlock-challenge-dns](https://git.coolaj86.com/coolaj86/greenlock-challenge-dns.js.git) Install ------- ```bash -npm install --save le-challenge-http@3.x +npm install --save greenlock-challenge-http@3.x ``` Usage @@ -36,9 +36,9 @@ var Greenlock = require('greenlock'); Greenlock.create({ ... -, challenges: { 'http-01': require('le-challenge-http').create({ debug: true }) - , 'dns-01': require('le-challenge-dns') - , 'tls-alpn-01': require('le-challenge-manual') +, challenges: { 'http-01': require('greenlock-challenge-http').create({ debug: true }) + , 'dns-01': require('greenlock-challenge-dns') + , 'tls-alpn-01': require('greenlock-challenge-manual') } ... }); diff --git a/index.js b/index.js index 451beea..5454444 100644 --- a/index.js +++ b/index.js @@ -92,11 +92,15 @@ Challenge._removeHttp = function (args) { Challenge._getHttp = function (args) { var ch = args.challenge; + var altname = ch.altname || ch.identifier.value; + var hostname = ch.hostname || ch.identifier.value; - if (!Challenge._getCache[ch.altname + ':' + ch.token]) { - Challenge._getCache[ch.altname + ':' + ch.token] = true; + console.log(args); + if (ch._test || !Challenge._getCache[ch.token]) { + Challenge._getCache[ch.token] = true; console.info(""); - console.info('GET http://' + ch.altname + '/.well-known/acme-challenge/' + ch.token); + console.info("[ACME " + ch.type + " '" + altname + "' REQUEST]: " + ch.status); + console.info('GET http://' + hostname + '/.well-known/acme-challenge/' + ch.token); console.info("(paste in the \"Key Authorization\" you received a moment ago to respond)"); process.stdout.write("> "); } @@ -109,7 +113,7 @@ Challenge._getHttp = function (args) { process.stdin.once('data', function (chunk) { process.stdin.pause(); - var result = chunk.toString('utf8'); + var result = chunk.toString('utf8').trim(); try { result = JSON.parse(result); } catch(e) { diff --git a/package-lock.json b/package-lock.json index 93bb092..136a8f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "le-challenge-manual", - "version": "2.1.1", + "name": "greenlock-challenge-http", + "version": "3.0.0", "lockfileVersion": 1 } diff --git a/package.json b/package.json index 9e810e3..6ed4915 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { - "name": "le-challenge-http", - "version": "3.0.0", + "name": "greenlock-challenge-http", + "version": "3.0.1", "description": "A very simple reference implementation of an ACME http-01 challenge for Greenlock v2.7+ (and v3)", "main": "index.js", - "homepage": "https://git.coolaj86.com/coolaj86/le-challenge-http.js", + "homepage": "https://git.coolaj86.com/coolaj86/greenlock-challenge-http.js", "scripts": { "test": "node test.js" }, "repository": { "type": "git", - "url": "https://git.coolaj86.com/coolaj86/le-challenge-http.js.git" + "url": "https://git.coolaj86.com/coolaj86/greenlock-challenge-http.js.git" }, "keywords": [ "Let's Encrypt", @@ -23,6 +23,6 @@ "author": "AJ ONeal (https://coolaj86.com/)", "license": "MPL-2.0", "bugs": { - "url": "https://git.coolaj86.com/coolaj86/le-challenge-http.js/issues" + "url": "https://git.coolaj86.com/coolaj86/greenlock-challenge-http.js/issues" } } diff --git a/test.js b/test.js index 26e666b..4a21357 100644 --- a/test.js +++ b/test.js @@ -1,33 +1,16 @@ 'use strict'; -/*global Promise*/ -var challenge = require('./').create({}); +var tester = require('greenlock-challenge-test'); -var opts = challenge.getOptions && challenge.getOptions() || challenge.options; +var type = 'http-01'; +//var challenger = require('greenlock-challenge-http').create({}); +var challenger = require('./').create({}); -function run() { - // this will cause the prompt to appear - return new Promise(function (resolve, reject) { - challenge.set(opts, function () { - // this will cause the final completion message to appear - return Promise.resolve(challenge.remove(opts)).then(resolve).catch(reject); - }); - }); -} +// The dry-run tests can pass on, literally, 'example.com' +// but the integration tests require that you have control over the domain +var domain = 'example.com'; -opts.challenge = { - type: 'dns-01' -, identifier: { type: 'dns', value: 'example.com' } -, wildcard: true -, expires: '2012-01-01T12:00:00.000Z' -, token: 'abc123' -, thumbprint: '<>' -, keyAuthorization: 'abc123.xxxx' -, dnsHost: '_acme-challenge.example.com' -, dnsAuthorization: 'yyyy' -, altname: '*.example.com' -}; -run(opts).then(function () { +tester.test(type, domain, challenger).then(function () { console.info("PASS"); }).catch(function (err) { console.error("FAIL");