minor bugix, whitespace, formatting
This commit is contained in:
parent
6b2321093e
commit
c746008f0b
|
@ -1,13 +1,27 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// renewWithin, renew, register, httpsOptions
|
// opts = { renewWithin, renew, register, httpsOptions }
|
||||||
module.exports.create = function (opts) {
|
module.exports.create = function (opts) {
|
||||||
var tls = require('tls');
|
var tls = require('tls');
|
||||||
// just to account for clock skew
|
|
||||||
var fiveMin = 5 * 60 * 1000;
|
|
||||||
var snicb = {
|
var snicb = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// in-process cache
|
// in-process cache
|
||||||
_ipc: {}
|
_ipc: {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// just to account for clock skew
|
||||||
|
, _fiveMin: 5 * 60 * 1000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// cache and format incoming certs
|
||||||
, cacheCerts: function (certs) {
|
, cacheCerts: function (certs) {
|
||||||
certs.altnames.forEach(function (domain) {
|
certs.altnames.forEach(function (domain) {
|
||||||
snicb._ipc[domain] = { subject: certs.subject };
|
snicb._ipc[domain] = { subject: certs.subject };
|
||||||
|
@ -26,6 +40,11 @@ module.exports.create = function (opts) {
|
||||||
|
|
||||||
return certs;
|
return certs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// automate certificate registration on request
|
||||||
, sniCallback: function (domain, cb) {
|
, sniCallback: function (domain, cb) {
|
||||||
var certs = snicb._ipc[domain];
|
var certs = snicb._ipc[domain];
|
||||||
var promise;
|
var promise;
|
||||||
|
@ -39,13 +58,13 @@ module.exports.create = function (opts) {
|
||||||
if (!certs) {
|
if (!certs) {
|
||||||
promise = opts.register(domain);
|
promise = opts.register(domain);
|
||||||
}
|
}
|
||||||
else if (now >= (certs.expiresAt - fiveMin)) {
|
else if (now >= (certs.expiresAt - snicb._fiveMin)) {
|
||||||
promise = opts.renew(domain, certs);
|
promise = opts.renew(domain, certs);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (now >= (certs.expiresAt - opts.renewWithin)) {
|
if (now >= (certs.expiresAt - opts.renewWithin)) {
|
||||||
// in background
|
// in background
|
||||||
opts.renew(domain, certs);
|
opts.renew(domain, certs).then(snicb.cacheCerts);
|
||||||
}
|
}
|
||||||
cb(null, certs);
|
cb(null, certs);
|
||||||
return;
|
return;
|
||||||
|
@ -55,6 +74,10 @@ module.exports.create = function (opts) {
|
||||||
cb(null, certs.tlsContext);
|
cb(null, certs.tlsContext);
|
||||||
}, cb);
|
}, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return snicb;
|
return snicb;
|
||||||
|
|
Loading…
Reference in New Issue