Compare commits

..

No commits in common. "8311d9275c812afa8dfb7ee84ee32ce594d9767c" and "cb5a079ea2a09871174ae1cce6080afbe73327a8" have entirely different histories.

3 changed files with 52 additions and 51 deletions

View File

@ -1,7 +1,11 @@
'use strict'; 'use strict';
var PromiseA = require('bluebird');
var dns = PromiseA.promisifyAll(require('dns'));
var Challenge = module.exports; var Challenge = module.exports;
var leDnsResponse;
Challenge.create = function (defaults) { Challenge.create = function (defaults) {
return { return {
getOptions: function () { getOptions: function () {
@ -26,7 +30,7 @@ Challenge.set = function (args, domain, challenge, keyAuthorization, cb) {
if (this.leDnsResponse) { if (this.leDnsResponse) {
this.leDnsResponse(challenge, keyAuthorization, keyAuthDigest, challengeDomain, domain) this.leDnsResponse(challenge, keyAuthorization, keyAuthDigest, challengeDomain, domain)
.then(function (/*successMessage*/) { .then((successMessage) => {
cb(null); cb(null);
}); });
} else { } else {
@ -68,3 +72,47 @@ Challenge.remove = function (args, domain, challenge, cb) {
cb(null); cb(null);
//}); //});
}; };
Challenge.loopback = function (defaults, domain, challenge, done) {
var challengeDomain = (defaults.test || '') + defaults.acmeChallengeDns + domain;
console.log("dig TXT +noall +answer @8.8.8.8 '" + challengeDomain + "' # " + challenge);
dns.resolveTxtAsync(challengeDomain).then(function (x) { done(null, x); }, done);
};
Challenge.test = function (args, domain, challenge, keyAuthorization, done) {
var me = this;
args.test = args.test || '_test.';
defaults.test = args.test;
me.set(args, domain, challenge, keyAuthorization || challenge, function (err, k) {
if (err) { done(err); return; }
me.loopback(defaults, domain, challenge, function (err, arr) {
if (err) { done(err); return; }
if (!arr.some(function (a) {
return a.some(function (keyAuthDigest) {
return keyAuthDigest === k;
});
})) {
err = new Error("txt record '" + challenge + "' doesn't match '" + k + "'");
}
me.remove(defaults, domain, challenge, function (_err) {
if (_err) { done(_err); return; }
// TODO needs to use native-dns so that specific nameservers can be used
// (otherwise the cache will still have the old answer)
done(err || null);
/*
me.loopback(defaults, domain, challenge, function (err) {
if (err) { done(err); return; }
done();
});
*/
});
});
});
}

View File

@ -1,6 +1,6 @@
{ {
"name": "le-challenge-dns", "name": "le-challenge-dns",
"version": "2.3.0", "version": "2.2.1",
"description": "A manual (interactive CLI) dns-based strategy for node-letsencrypt for setting, retrieving, and clearing ACME DNS-01 challenges issued by the ACME server", "description": "A manual (interactive CLI) dns-based strategy for node-letsencrypt for setting, retrieving, and clearing ACME DNS-01 challenges issued by the ACME server",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

51
test.js
View File

@ -1,58 +1,11 @@
'use strict'; 'use strict';
var PromiseA = require('bluebird'); var leChallengeDns = require('./').create({ });
var resolveTxtAsync = PromiseA.promisify(require('dns').resolveTxt);
var Challenge = require('./');
var leChallengeDns = Challenge.create({ });
var opts = leChallengeDns.getOptions(); var opts = leChallengeDns.getOptions();
var domain = 'test.example.com'; var domain = 'test.daplie.me';
var challenge = 'xxx-acme-challenge-xxx'; var challenge = 'xxx-acme-challenge-xxx';
var keyAuthorization = 'xxx-acme-challenge-xxx.xxx-acme-authorization-xxx'; var keyAuthorization = 'xxx-acme-challenge-xxx.xxx-acme-authorization-xxx';
Challenge.loopback = function (defaults, domain, challenge, done) {
var challengeDomain = (defaults.test || '') + defaults.acmeChallengeDns + domain;
console.log("dig TXT +noall +answer @8.8.8.8 '" + challengeDomain + "' # " + challenge);
resolveTxtAsync(challengeDomain).then(function (x) { done(null, x); }, done);
};
Challenge.test = function (args, domain, challenge, keyAuthorization, done) {
var me = this;
args.test = args.test || '_test.';
//defaults.test = args.test;
me.set(args, domain, challenge, keyAuthorization || challenge, function (err, k) {
if (err) { done(err); return; }
me.loopback(/*defaults*/args, domain, challenge, function (err, arr) {
if (err) { done(err); return; }
if (!arr.some(function (a) {
return a.some(function (keyAuthDigest) {
return keyAuthDigest === k;
});
})) {
err = new Error("txt record '" + challenge + "' doesn't match '" + k + "'");
}
me.remove(/*defaults*/args, domain, challenge, function (_err) {
if (_err) { done(_err); return; }
// TODO needs to use native-dns so that specific nameservers can be used
// (otherwise the cache will still have the old answer)
done(err || null);
/*
me.loopback(defaults, domain, challenge, function (err) {
if (err) { done(err); return; }
done();
});
*/
});
});
});
};
setTimeout(function () { setTimeout(function () {
leChallengeDns.test(opts, domain, challenge, keyAuthorization, function (err) { leChallengeDns.test(opts, domain, challenge, keyAuthorization, function (err) {
// if there's an error, there's a problem // if there's an error, there's a problem