From bd30378d574b70d4ea75268635cbb7397a3540e3 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 10 Aug 2016 04:49:57 -0400 Subject: [PATCH] minor bugix, whitespace, formatting --- lib/sni-callback.js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/sni-callback.js b/lib/sni-callback.js index 872340f..c226229 100644 --- a/lib/sni-callback.js +++ b/lib/sni-callback.js @@ -1,13 +1,27 @@ 'use strict'; -// renewWithin, renew, register, httpsOptions +// opts = { renewWithin, renew, register, httpsOptions } module.exports.create = function (opts) { var tls = require('tls'); - // just to account for clock skew - var fiveMin = 5 * 60 * 1000; + var snicb = { + + + + // in-process cache _ipc: {} + + + + + // just to account for clock skew + , _fiveMin: 5 * 60 * 1000 + + + + + // cache and format incoming certs , cacheCerts: function (certs) { certs.altnames.forEach(function (domain) { snicb._ipc[domain] = { subject: certs.subject }; @@ -26,6 +40,11 @@ module.exports.create = function (opts) { return certs; } + + + + + // automate certificate registration on request , sniCallback: function (domain, cb) { var certs = snicb._ipc[domain]; var promise; @@ -39,13 +58,13 @@ module.exports.create = function (opts) { if (!certs) { promise = opts.register(domain); } - else if (now >= (certs.expiresAt - fiveMin)) { + else if (now >= (certs.expiresAt - snicb._fiveMin)) { promise = opts.renew(domain, certs); } else { if (now >= (certs.expiresAt - opts.renewWithin)) { // in background - opts.renew(domain, certs); + opts.renew(domain, certs).then(snicb.cacheCerts); } cb(null, certs); return; @@ -55,6 +74,10 @@ module.exports.create = function (opts) { cb(null, certs.tlsContext); }, cb); } + + + + }; return snicb;