From 63284386ebd6069ddb3653d0cd76a13e248b40ca Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 4 Jul 2018 00:28:00 -0600 Subject: [PATCH] update compat to allow testing dns --- node.js | 6 +++++- package.json | 2 +- tests/compat.js | 21 +++++++++++++++++---- tests/promise.js | 4 ++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/node.js b/node.js index 6017f17..ddb2866 100644 --- a/node.js +++ b/node.js @@ -416,13 +416,17 @@ ACME._postChallenge = function (me, options, identifier, ch) { if (1 === options.setChallenge.length) { options.setChallenge(auth).then(testChallenge).then(resolve, reject); } else if (2 === options.setChallenge.length) { - options.setChallenge(auth, function(err) { + var challengeCb = function (err) { if(err) { reject(err); } else { testChallenge().then(resolve, reject); } + }; + Object.keys(auth).forEach(function (key) { + challengeCb[key] = auth[key]; }); + options.setChallenge(auth, challengeCb); } else { options.setChallenge(identifier.value, ch.token, keyAuthorization, function(err) { if(err) { diff --git a/package.json b/package.json index 92b5d93..452c256 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "acme-v2", - "version": "1.1.0", + "version": "1.1.1", "description": "Free SSL. A framework for building Let's Encrypt v2 clients, and other ACME v2 (draft 11) clients. Successor to le-acme-core.js", "homepage": "https://git.coolaj86.com/coolaj86/acme-v2.js", "main": "node.js", diff --git a/tests/compat.js b/tests/compat.js index d0a66b1..b48cfef 100644 --- a/tests/compat.js +++ b/tests/compat.js @@ -12,10 +12,23 @@ module.exports.run = function (directoryUrl, RSA, web, chType, email, accountKey agree(null, tosUrl); } , setChallenge: function (hostname, token, val, cb) { - var pathname = hostname + acme2.acmeChallengePrefix + token; - console.log("Put the string '" + val + "' into a file at '" + pathname + "'"); - console.log("echo '" + val + "' > '" + pathname + "'"); - console.log("\nThen hit the 'any' key to continue..."); + var pathname; + + if ('http-01' === cb.type) { + pathname = hostname + acme2.acmeChallengePrefix + token; + console.log("Put the string '" + val /*keyAuthorization*/ + "' into a file at '" + pathname + "'"); + console.log("echo '" + val /*keyAuthorization*/ + "' > '" + pathname + "'"); + console.log("\nThen hit the 'any' key to continue..."); + } else if ('dns-01' === cb.type) { + // forwards-backwards compat + pathname = acme2.challengePrefixes['dns-01'] + "." + hostname.replace(/^\*\./, ''); + console.log("Put the string '" + cb.dnsAuthorization + "' into the TXT record '" + pathname + "'"); + console.log("dig TXT " + pathname + " '" + cb.dnsAuthorization + "'"); + console.log("\nThen hit the 'any' key to continue..."); + } else { + cb(new Error("[acme-v2] unrecognized challenge type")); + return; + } function onAny() { console.log("'any' key was hit"); diff --git a/tests/promise.js b/tests/promise.js index ee2a028..7c1c17f 100644 --- a/tests/promise.js +++ b/tests/promise.js @@ -35,9 +35,9 @@ module.exports.run = function run(directoryUrl, RSA, web, chType, email, account console.log("Put the string '" + opts.keyAuthorization + "' into a file at '" + pathname + "'"); console.log("echo '" + opts.keyAuthorization + "' > '" + pathname + "'"); } else if ('dns-01' === opts.type) { - pathname = acme2.challengePrefixes['dns-01'] + "." + opts.hostname.replace(/^\*\./, '');; + pathname = acme2.challengePrefixes['dns-01'] + "." + opts.hostname.replace(/^\*\./, ''); console.log("Put the string '" + opts.dnsAuthorization + "' into the TXT record '" + pathname + "'"); - console.log("ddig TXT " + pathname + " '" + opts.dnsAuthorization + "'"); + console.log("dig TXT " + pathname + " '" + opts.dnsAuthorization + "'"); } else { reject(new Error("[acme-v2] unrecognized challenge type")); return;