minor bugix, whitespace, formatting
This commit is contained in:
		
							parent
							
								
									c15f16cfe4
								
							
						
					
					
						commit
						bd30378d57
					
				| @ -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; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user