Certificate registration completes successfully! :-)

This commit is contained in:
AJ ONeal 2015-12-15 15:40:44 +00:00
parent 3e6fecf008
commit c48de554c2
3 changed files with 35 additions and 5 deletions

View File

@ -184,6 +184,11 @@ function getCertificateAsync(account, args, defaults, handlers) {
domains: args.domains domains: args.domains
, accountPrivateKeyPem: account.privateKeyPem , accountPrivateKeyPem: account.privateKeyPem
, domainPrivateKeyPem: domain.privateKeyPem , domainPrivateKeyPem: domain.privateKeyPem
, getChallenge: function (domain, key, done) {
args.domains = [domain];
args.webrootPath = args.webrootPath || defaults.webrootPath;
handlers.getChallenge(args, key, done);
}
, setChallenge: function (domain, key, value, done) { , setChallenge: function (domain, key, value, done) {
args.domains = [domain]; args.domains = [domain];
args.webrootPath = args.webrootPath || defaults.webrootPath; args.webrootPath = args.webrootPath || defaults.webrootPath;

View File

@ -39,6 +39,22 @@ LE.create = function (backend, defaults, handlers) {
cb(null, null); cb(null, null);
}; };
} }
if (!handlers.getChallenge) {
if (!defaults.webrootPath) {
// GET /.well-known/acme-challenge/{{challengeKey}} should return {{tokenValue}}
throw new Error("handlers.getChallenge or defaults.webrootPath must be set");
}
handlers.getChallenge = function (hostname, key, done) {
// TODO associate by hostname?
// hmm... I don't think there's a direct way to associate this with
// the request it came from... it's kinda stateless in that way
// but realistically there only needs to be one handler and one
// "directory" for this. It's not that big of a deal.
var defaultos = LE.merge(defaults, {});
defaultos.domains = [hostname];
require('./lib/default-handlers').getChallenge(defaultos, key, done);
};
}
if (!handlers.setChallenge) { if (!handlers.setChallenge) {
if (!defaults.webrootPath) { if (!defaults.webrootPath) {
// GET /.well-known/acme-challenge/{{challengeKey}} should return {{tokenValue}} // GET /.well-known/acme-challenge/{{challengeKey}} should return {{tokenValue}}
@ -49,7 +65,7 @@ LE.create = function (backend, defaults, handlers) {
if (!handlers.removeChallenge) { if (!handlers.removeChallenge) {
if (!defaults.webrootPath) { if (!defaults.webrootPath) {
// GET /.well-known/acme-challenge/{{challengeKey}} should return {{tokenValue}} // GET /.well-known/acme-challenge/{{challengeKey}} should return {{tokenValue}}
throw new Error("handlers.setChallenge or defaults.webrootPath must be set"); throw new Error("handlers.removeChallenge or defaults.webrootPath must be set");
} }
handlers.removeChallenge = require('./lib/default-handlers').removeChallenge; handlers.removeChallenge = require('./lib/default-handlers').removeChallenge;
} }
@ -143,17 +159,25 @@ LE.create = function (backend, defaults, handlers) {
cb(null, true); cb(null, true);
} }
, middleware: function () { , middleware: function () {
//console.log('[DEBUG] webrootPath', defaults.webrootPath);
var serveStatic = require('serve-static')(defaults.webrootPath, { dotfiles: 'allow' });
var prefix = '/.well-known/acme-challenge/'; var prefix = '/.well-known/acme-challenge/';
return function (req, res, next) { return function (req, res, next) {
if (0 !== req.url.indexOf(prefix)) { if (0 !== req.url.indexOf(prefix)) {
console.log('[LE middleware]: pass');
next(); next();
return; return;
} }
serveStatic(req, res, next); //args.domains = [req.hostname];
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.");
return;
}
res.send(token);
});
}; };
} }
, SNICallback: sniCallback , SNICallback: sniCallback

View File

@ -29,7 +29,8 @@ module.exports.setChallenge = function (args, challengePath, keyAuthorization, d
module.exports.getChallenge = function (args, key, done) { module.exports.getChallenge = function (args, key, done) {
//var hostname = args.domains[0]; //var hostname = args.domains[0];
fs.readFile(path.join(args.webroot, key), 'utf8', done); console.log("getting the challenge", args, key);
fs.readFile(path.join(args.webrootPath, key), 'utf8', done);
}; };
module.exports.removeChallenge = function (args, key, done) { module.exports.removeChallenge = function (args, key, done) {