1
0
Derivar 0

pure node :-)

Este cometimento está contido em:
AJ ONeal 2015-12-16 12:57:53 +00:00
ascendente b965141dd2
cometimento 2bc1403200
4 ficheiros modificados com 33 adições e 21 eliminações

Ver ficheiro

@ -86,7 +86,7 @@ LE.create = function (defaults, handlers, backend) {
}; };
} }
if (!handlers.getChallenge) { if (!handlers.getChallenge) {
if (!defaults.webrootPath) { if (!defaults.manual && !defaults.webrootPath) {
// GET /.well-known/acme-challenge/{{challengeKey}} should return {{tokenValue}} // GET /.well-known/acme-challenge/{{challengeKey}} should return {{tokenValue}}
throw new Error("handlers.getChallenge or defaults.webrootPath must be set"); throw new Error("handlers.getChallenge or defaults.webrootPath must be set");
} }
@ -209,13 +209,13 @@ LE.create = function (defaults, handlers, backend) {
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'); //console.log('[LE middleware]: pass');
next(); next();
return; return;
} }
//args.domains = [req.hostname]; //args.domains = [req.hostname];
console.log('[LE middleware]:', req.hostname, req.url, req.url.slice(prefix.length)); //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) { handlers.getChallenge(req.hostname, req.url.slice(prefix.length), function (err, token) {
if (err) { if (err) {
res.send("Error: These aren't the tokens you're looking for. Move along."); res.send("Error: These aren't the tokens you're looking for. Move along.");
@ -245,9 +245,9 @@ LE.create = function (defaults, handlers, backend) {
return; return;
} }
console.log("[NLE]: begin registration"); //console.log("[NLE]: begin registration");
return backend.registerAsync(copy).then(function () { return backend.registerAsync(copy).then(function () {
console.log("[NLE]: end registration"); //console.log("[NLE]: end registration");
// calls fetch because fetch calls cacheCertInfo // calls fetch because fetch calls cacheCertInfo
return le.fetch(args, cb); return le.fetch(args, cb);
}, cb); }, cb);
@ -317,6 +317,10 @@ LE.create = function (defaults, handlers, backend) {
le._fetchHelper(args, cb); le._fetchHelper(args, cb);
} }
, register: function (args, cb) { , register: function (args, cb) {
if (!Array.isArray(args.domains)) {
cb(new Error('args.domains should be an array of domains'));
return;
}
// this may be run in a cluster environment // this may be run in a cluster environment
// in that case it should NOT check the cache // in that case it should NOT check the cache
// but ensure that it has the most fresh copy // but ensure that it has the most fresh copy

Ver ficheiro

@ -5,8 +5,12 @@ var PromiseA = require('bluebird');
module.exports.fetchFromDisk = function (args, defaults) { module.exports.fetchFromDisk = function (args, defaults) {
var hostname = args.domains[0]; var hostname = args.domains[0];
var crtpath = defaults.configDir + defaults.fullchainTpl.replace(/:hostname/, hostname); var crtpath = (args.fullchainPath || defaults.fullchainPath)
var privpath = defaults.configDir + defaults.privkeyTpl.replace(/:hostname/, hostname); || (defaults.configDir
+ (args.fullchainTpl || defaults.fullchainTpl || ':hostname/fullchain.pem').replace(/:hostname/, hostname));
var privpath = (args.privkeyPath || defaults.privkeyPath)
|| (defaults.configDir
+ (args.privkeyTpl || defaults.privkeyTpl || ':hostname/privkey.pem').replace(/:hostname/, hostname));
return PromiseA.all([ return PromiseA.all([
fs.readFileAsync(privpath, 'ascii') fs.readFileAsync(privpath, 'ascii')

Ver ficheiro

@ -12,8 +12,8 @@ module.exports.setChallenge = function (args, challengePath, keyAuthorization, d
var mkdirp = require('mkdirp'); var mkdirp = require('mkdirp');
// TODO should be args.webrootPath // TODO should be args.webrootPath
console.log('args.webrootPath, challengePath'); //console.log('args.webrootPath, challengePath');
console.log(args.webrootPath, challengePath); //console.log(args.webrootPath, challengePath);
mkdirp(args.webrootPath, function (err) { mkdirp(args.webrootPath, function (err) {
if (err) { if (err) {
done(err); done(err);
@ -29,7 +29,7 @@ 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];
console.log("getting the challenge", args, key); //console.log("getting the challenge", args, key);
fs.readFile(path.join(args.webrootPath, key), 'utf8', done); fs.readFile(path.join(args.webrootPath, key), 'utf8', done);
}; };

Ver ficheiro

@ -176,12 +176,18 @@ function getCertificateAsync(account, args, defaults, handlers) {
, sfs.writeFileAsync(chainPath, result.chain, 'ascii') , sfs.writeFileAsync(chainPath, result.chain, 'ascii')
, sfs.writeFileAsync(fullchainPath, result.fullchain, 'ascii') , sfs.writeFileAsync(fullchainPath, result.fullchain, 'ascii')
, sfs.writeFileAsync(privkeyPath, result.key, 'ascii') , sfs.writeFileAsync(privkeyPath, result.key, 'ascii')
]); ]).then(function () {
// TODO format result licesy
//console.log(liveDir);
//console.log(result);
return {
certPath: certPath
, chainPath: chainPath
, fullchainPath: fullchainPath
, privkeyPath: privkeyPath
};
});
}); });
console.log(liveDir);
console.log(result);
throw new Error("IMPLEMENTATION NOT COMPLETE");
}); });
}); });
} }
@ -193,8 +199,6 @@ function registerWithAcme(args, defaults, handlers) {
var configDir = args.configDir || defaults.configDir || LE.configDir; var configDir = args.configDir || defaults.configDir || LE.configDir;
args.server = server; args.server = server;
console.log('args.server');
console.log(server);
args.renewalDir = args.renewalDir || path.join(configDir, 'renewal', args.domains[0] + '.conf'); args.renewalDir = args.renewalDir || path.join(configDir, 'renewal', args.domains[0] + '.conf');
args.accountsDir = args.accountsDir || path.join(configDir, 'accounts', acmeHostname, 'directory'); args.accountsDir = args.accountsDir || path.join(configDir, 'accounts', acmeHostname, 'directory');
@ -228,14 +232,14 @@ function registerWithAcme(args, defaults, handlers) {
} }
*/ */
console.log(account); //console.log(account);
return fetchFromConfigLiveDir(args, defaults).then(function (certs) { return fetchFromConfigLiveDir(args, defaults).then(function (certs) {
// if nothing, register and save // if nothing, register and save
// if something, check date (don't register unless 30+ days) // if something, check date (don't register unless 30+ days)
// if good, don't bother registering // if good, don't bother registering
// (but if we get to the point that we're actually calling // (but if we get to the point that we're actually calling
// this function, that shouldn't be the case, right?) // this function, that shouldn't be the case, right?)
console.log(certs); //console.log(certs);
if (!certs) { if (!certs) {
// no certs, seems like a good time to get some // no certs, seems like a good time to get some
return getCertificateAsync(account, args, defaults, handlers); return getCertificateAsync(account, args, defaults, handlers);
@ -244,12 +248,12 @@ function registerWithAcme(args, defaults, handlers) {
// cert is at least 27 days old we can renew that // cert is at least 27 days old we can renew that
return getCertificateAsync(account, args, defaults, handlers); return getCertificateAsync(account, args, defaults, handlers);
} }
else if (args.force) { else if (args.duplicate) {
// YOLO! I be gettin' fresh certs 'erday! Yo! // YOLO! I be gettin' fresh certs 'erday! Yo!
return getCertificateAsync(account, args, defaults, handlers); return getCertificateAsync(account, args, defaults, handlers);
} }
else { else {
console.warn('[WARN] Ignoring renewal attempt for certificate less than 27 days old. Use args.force to force.'); console.warn('[WARN] Ignoring renewal attempt for certificate less than 27 days old. Use args.duplicate to force.');
// We're happy with what we have // We're happy with what we have
return certs; return certs;
} }