2015-12-11 14:22:46 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-12-17 04:59:47 +00:00
|
|
|
var leCore = require('letiny-core');
|
2015-12-12 15:05:45 +00:00
|
|
|
|
2015-12-13 01:04:12 +00:00
|
|
|
var LE = module.exports;
|
2016-08-05 22:50:42 +00:00
|
|
|
// in-process cache, shared between all instances
|
|
|
|
var ipc = {};
|
2016-08-04 22:49:35 +00:00
|
|
|
|
2016-02-13 02:33:50 +00:00
|
|
|
LE.defaults = {
|
2016-08-05 22:21:10 +00:00
|
|
|
productionServerUrl: leCore.productionServerUrl
|
2016-08-04 22:49:35 +00:00
|
|
|
, stagingServerUrl: leCore.stagingServerUrl
|
|
|
|
|
2016-08-05 22:21:10 +00:00
|
|
|
, rsaKeySize: leCore.rsaKeySize || 2048
|
|
|
|
, challengeType: leCore.challengeType || 'http-01'
|
|
|
|
|
2016-08-04 22:49:35 +00:00
|
|
|
, acmeChallengePrefix: leCore.acmeChallengePrefix
|
2016-02-13 02:33:50 +00:00
|
|
|
};
|
2015-12-20 10:41:17 +00:00
|
|
|
|
2015-12-16 09:11:31 +00:00
|
|
|
// backwards compat
|
2016-08-04 22:49:35 +00:00
|
|
|
Object.keys(LE.defaults).forEach(function (key) {
|
|
|
|
LE[key] = LE.defaults[key];
|
|
|
|
});
|
2015-12-13 01:04:12 +00:00
|
|
|
|
2016-08-05 22:21:10 +00:00
|
|
|
// show all possible options
|
2016-08-05 22:16:29 +00:00
|
|
|
var u; // undefined
|
|
|
|
LE._undefined = {
|
|
|
|
store: u
|
|
|
|
, challenger: u
|
|
|
|
, register: u
|
|
|
|
, check: u
|
|
|
|
, renewWithin: u
|
|
|
|
, memorizeFor: u
|
|
|
|
, acmeChallengePrefix: u
|
2016-08-05 22:21:10 +00:00
|
|
|
, rsaKeySize: u
|
|
|
|
, challengeType: u
|
|
|
|
, server: u
|
2016-08-06 05:33:19 +00:00
|
|
|
, agreeToTerms: u
|
2016-08-05 22:50:42 +00:00
|
|
|
, _ipc: u
|
2016-08-05 22:16:29 +00:00
|
|
|
};
|
|
|
|
LE._undefine = function (le) {
|
|
|
|
Object.keys(LE._undefined).forEach(function (key) {
|
|
|
|
if (!(key in le)) {
|
|
|
|
le[key] = u;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return le;
|
|
|
|
};
|
|
|
|
LE.create = function (le) {
|
2016-08-05 22:50:42 +00:00
|
|
|
var PromiseA = require('bluebird');
|
|
|
|
|
|
|
|
le.store = le.store || require('le-store-certbot').create({ debug: le.debug });
|
|
|
|
le.challenger = le.challenger || require('le-store-certbot').create({ debug: le.debug });
|
|
|
|
le.core = require('./lib/core');
|
2016-08-05 22:16:29 +00:00
|
|
|
|
2016-08-05 22:50:42 +00:00
|
|
|
le = LE._undefine(le);
|
2016-08-05 22:16:29 +00:00
|
|
|
le.acmeChallengePrefix = LE.acmeChallengePrefix;
|
2016-08-05 22:21:10 +00:00
|
|
|
le.rsaKeySize = le.rsaKeySize || LE.rsaKeySize;
|
|
|
|
le.challengeType = le.challengeType || LE.challengeType;
|
2016-08-05 22:50:42 +00:00
|
|
|
le._ipc = ipc;
|
2016-08-05 22:16:29 +00:00
|
|
|
|
|
|
|
if (!le.renewWithin) { le.renewWithin = 3 * 24 * 60 * 60 * 1000; }
|
|
|
|
if (!le.memorizeFor) { le.memorizeFor = 1 * 24 * 60 * 60 * 1000; }
|
|
|
|
|
|
|
|
if (!le.server) {
|
|
|
|
throw new Error("opts.server must be set to 'staging' or a production url, such as LE.productionServerUrl'");
|
|
|
|
}
|
|
|
|
if ('staging' === le.server) {
|
|
|
|
le.server = LE.stagingServerUrl;
|
|
|
|
}
|
|
|
|
else if ('production' === le.server) {
|
|
|
|
le.server = LE.productionServerUrl;
|
2015-12-13 05:03:48 +00:00
|
|
|
}
|
2015-12-17 08:46:40 +00:00
|
|
|
|
2016-08-05 22:50:42 +00:00
|
|
|
if (le.store.create) {
|
|
|
|
le.store = le.store.create(le);
|
2015-12-15 15:40:44 +00:00
|
|
|
}
|
2016-08-05 22:50:42 +00:00
|
|
|
le.store = PromiseA.promisifyAll(le.store);
|
|
|
|
le._storeOpts = le.store.getOptions();
|
2016-08-05 22:16:29 +00:00
|
|
|
Object.keys(le._storeOpts).forEach(function (key) {
|
|
|
|
if (!(key in le._storeOpts)) {
|
|
|
|
le[key] = le._storeOpts[key];
|
2015-12-12 14:20:12 +00:00
|
|
|
}
|
2016-08-05 22:16:29 +00:00
|
|
|
});
|
|
|
|
|
2016-08-05 22:50:42 +00:00
|
|
|
if (le.challenger.create) {
|
|
|
|
le.challenger = le.challenger.create(le);
|
2016-08-05 22:16:29 +00:00
|
|
|
}
|
2016-08-05 22:50:42 +00:00
|
|
|
le.challenger = PromiseA.promisifyAll(le.challenger);
|
|
|
|
le._challengerOpts = le.challenger.getOptions();
|
2016-08-05 22:16:29 +00:00
|
|
|
Object.keys(le._storeOpts).forEach(function (key) {
|
|
|
|
if (!(key in le._challengerOpts)) {
|
|
|
|
le[key] = le._challengerOpts[key];
|
2015-12-20 10:41:17 +00:00
|
|
|
}
|
2016-08-05 22:16:29 +00:00
|
|
|
});
|
|
|
|
|
2016-08-05 22:50:42 +00:00
|
|
|
if (le.core.create) {
|
|
|
|
le.core = le.core.create(le);
|
|
|
|
}
|
2016-08-05 22:16:29 +00:00
|
|
|
|
|
|
|
le.register = function (args) {
|
2016-08-07 06:02:02 +00:00
|
|
|
return le.core.certificates.getAsync(args);
|
2015-12-12 14:20:12 +00:00
|
|
|
};
|
2015-12-11 14:22:46 +00:00
|
|
|
|
2016-08-05 22:16:29 +00:00
|
|
|
le.check = function (args) {
|
|
|
|
// TODO must return email, domains, tos, pems
|
2016-08-07 06:02:02 +00:00
|
|
|
return le.core.certificates.checkAsync(args);
|
2016-08-05 22:16:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
le.middleware = function () {
|
|
|
|
return require('./lib/middleware')(le);
|
|
|
|
};
|
2016-08-05 08:14:40 +00:00
|
|
|
|
2015-12-12 14:20:12 +00:00
|
|
|
return le;
|
2015-12-11 14:22:46 +00:00
|
|
|
};
|