Compare commits
	
		
			No commits in common. "master" and "v2.1.3" have entirely different histories.
		
	
	
		
	
		
							
								
								
									
										20
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								README.md
									
									
									
									
									
								
							| @ -31,8 +31,8 @@ With node-letsencrypt | |||||||
| 
 | 
 | ||||||
| var leSni = require('le-sni-auto').create({ | var leSni = require('le-sni-auto').create({ | ||||||
| 
 | 
 | ||||||
|   renewWithin: 14 * 24 * 60 * 60 1000     // do not renew more than 14 days before expiration |   renewWithin: 10 * 24 * 60 * 60 1000       // do not renew more than 10 days before expiration | ||||||
| , renewBy: 10 * 24 * 60 * 60 1000         // do not wait more than 10 days before expiration | , renewBy: 5 * 24 * 60 * 60 1000         // do not wait more than 5 days before expiration | ||||||
| 
 | 
 | ||||||
| , tlsOptions: { | , tlsOptions: { | ||||||
|     rejectUnauthorized: true              // These options will be used with tls.createSecureContext() |     rejectUnauthorized: true              // These options will be used with tls.createSecureContext() | ||||||
| @ -78,8 +78,8 @@ Standalone | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| var leSni = require('le-sni-auto').create({ | var leSni = require('le-sni-auto').create({ | ||||||
|   renewWithin: 14 * 24 * 60 * 60 1000       // do not renew prior to 10 days before expiration |   renewWithin: 10 * 24 * 60 * 60 1000       // do not renew prior to 10 days before expiration | ||||||
| , renewBy: 10 * 24 * 60 * 60 1000         // do not wait more than 5 days before expiration | , renewBy: 5 * 24 * 60 * 60 1000         // do not wait more than 5 days before expiration | ||||||
| 
 | 
 | ||||||
|   // key (privkey.pem) and cert (cert.pem + chain.pem) will be provided by letsencrypt |   // key (privkey.pem) and cert (cert.pem + chain.pem) will be provided by letsencrypt | ||||||
| , tlsOptions: { rejectUnauthorized: true, requestCert: false, ca: null, crl: null } | , tlsOptions: { rejectUnauthorized: true, requestCert: false, ca: null, crl: null } | ||||||
| @ -92,9 +92,11 @@ var leSni = require('le-sni-auto').create({ | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| var tlsOptions = { | // some default certificates that work with localhost | ||||||
|  | // (because default certificates are required as a fallback) | ||||||
|  | var tlsOptions = require('localhost.daplie.me-certificates').merge({ | ||||||
|   SNICallback: leSni.sniCallback |   SNICallback: leSni.sniCallback | ||||||
| }; | }); | ||||||
| 
 | 
 | ||||||
| https.createServer(tlsOptions, app); | https.createServer(tlsOptions, app); | ||||||
| ``` | ``` | ||||||
| @ -143,12 +145,12 @@ This gets passed to `https.createServer(tlsOptions, app)` as `tlsOptions.SNICall | |||||||
| 
 | 
 | ||||||
| ```javascript | ```javascript | ||||||
| var leSni = require('le-sni-auto').create({ | var leSni = require('le-sni-auto').create({ | ||||||
|   renewWithin: 14 * 24 * 60 * 60 1000 |   renewWithin: 10 * 24 * 60 * 60 1000 | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| var tlsOptions = { | var tlsOptions = require('localhost.daplie.com-certificates').merge({ | ||||||
|   SNICallback: leSni.sniCallback |   SNICallback: leSni.sniCallback | ||||||
| }; | }); | ||||||
| 
 | 
 | ||||||
| function app(req, res) { | function app(req, res) { | ||||||
|   res.end("Hello, World!"); |   res.end("Hello, World!"); | ||||||
|  | |||||||
							
								
								
									
										24
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								index.js
									
									
									
									
									
								
							| @ -5,27 +5,19 @@ var HOUR = 60 * 60 * 1000; | |||||||
| var MIN = 60 * 1000; | var MIN = 60 * 1000; | ||||||
| var defaults = { | var defaults = { | ||||||
|   // don't renew before the renewWithin period
 |   // don't renew before the renewWithin period
 | ||||||
|   renewWithin: 30 * DAY |   renewWithin: 14 * DAY | ||||||
| , _renewWithinMin: 3 * DAY | , _renewWithinMin: 3 * DAY | ||||||
|   // renew before the renewBy period
 |   // renew before the renewBy period
 | ||||||
| , renewBy: 21 * DAY | , renewBy: 10 * DAY | ||||||
| , _renewByMin: Math.floor(DAY / 2) | , _renewByMin: Math.floor(DAY / 2) | ||||||
|   // just to account for clock skew really
 |   // just to account for clock skew really
 | ||||||
| , _dropDead: 5 * MIN | , _dropDead: 5 * MIN | ||||||
| }; | }; | ||||||
| var promisify = require('util').promisify; |  | ||||||
| if (!promisify) { |  | ||||||
|   try { |  | ||||||
|     promisify = require('bluebird').promisify; |  | ||||||
|   } catch(e) { |  | ||||||
|     console.error("You're running an older version of node that doesn't have 'promisify'. Please run 'npm install bluebird --save'."); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| // autoSni = { renewWithin, renewBy, getCertificates, tlsOptions, _dbg_now }
 | // autoSni = { renewWithin, renewBy, getCertificates, tlsOptions, _dbg_now }
 | ||||||
| module.exports.create = function (autoSni) { | module.exports.create = function (autoSni) { | ||||||
| 
 | 
 | ||||||
|   if (!autoSni.getCertificatesAsync) { autoSni.getCertificatesAsync = promisify(autoSni.getCertificates); } |   if (!autoSni.getCertificatesAsync) { autoSni.getCertificatesAsync = require('bluebird').promisify(autoSni.getCertificates); } | ||||||
|   if (!autoSni.renewWithin) { autoSni.renewWithin = autoSni.notBefore || defaults.renewWithin; } |   if (!autoSni.renewWithin) { autoSni.renewWithin = autoSni.notBefore || defaults.renewWithin; } | ||||||
|   if (autoSni.renewWithin < defaults._renewWithinMin) { |   if (autoSni.renewWithin < defaults._renewWithinMin) { | ||||||
|     throw new Error("options.renewWithin should be at least " + (defaults._renewWithinMin / DAY) + " days"); |     throw new Error("options.renewWithin should be at least " + (defaults._renewWithinMin / DAY) + " days"); | ||||||
| @ -72,8 +64,7 @@ module.exports.create = function (autoSni) { | |||||||
|         certs: certs |         certs: certs | ||||||
|       , tlsContext: 'string' === typeof certs.cert && tls.createSecureContext({ |       , tlsContext: 'string' === typeof certs.cert && tls.createSecureContext({ | ||||||
|           key: certs.privkey |           key: certs.privkey | ||||||
|           // backwards/forwards compat
 |         , cert: certs.cert + certs.chain | ||||||
|         , cert: (certs.cert||'').replace(/[\r\n]+$/, '') + '\r\n' + certs.chain |  | ||||||
|         , rejectUnauthorized: autoSni.tlsOptions.rejectUnauthorized |         , rejectUnauthorized: autoSni.tlsOptions.rejectUnauthorized | ||||||
| 
 | 
 | ||||||
|         , requestCert: autoSni.tlsOptions.requestCert  // request peer verification
 |         , requestCert: autoSni.tlsOptions.requestCert  // request peer verification
 | ||||||
| @ -131,7 +122,7 @@ module.exports.create = function (autoSni) { | |||||||
|       else if (certMeta.then) { |       else if (certMeta.then) { | ||||||
|         //log(autoSni.debug, "PROMISED CERT", domain);
 |         //log(autoSni.debug, "PROMISED CERT", domain);
 | ||||||
|         // we are already getting a cert
 |         // we are already getting a cert
 | ||||||
|         promise = certMeta; |         promise = certMeta | ||||||
|       } |       } | ||||||
|       else if (now >= certMeta.expiresNear) { |       else if (now >= certMeta.expiresNear) { | ||||||
|         //log(autoSni.debug, "EXPIRED CERT");
 |         //log(autoSni.debug, "EXPIRED CERT");
 | ||||||
| @ -146,10 +137,7 @@ module.exports.create = function (autoSni) { | |||||||
|           // give the cert some time (2-5 min) to be validated and replaced before trying again
 |           // give the cert some time (2-5 min) to be validated and replaced before trying again
 | ||||||
|           certMeta.renewAt = (autoSni._dbg_now || Date.now()) + (2 * MIN) + (3 * MIN * Math.random()); |           certMeta.renewAt = (autoSni._dbg_now || Date.now()) + (2 * MIN) + (3 * MIN * Math.random()); | ||||||
|           // let the update happen in the background
 |           // let the update happen in the background
 | ||||||
|           autoSni.getCertificatesAsync(domain, certMeta.certs).then(autoSni.cacheCerts, function (error) { |           autoSni.getCertificatesAsync(domain, certMeta.certs).then(autoSni.cacheCerts); | ||||||
|             // console.error('ERROR in le-sni-auto:');
 |  | ||||||
|             // console.error(err.stack || err);
 |  | ||||||
|           }) |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // return the valid cert right away
 |         // return the valid cert right away
 | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										5
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -1,5 +0,0 @@ | |||||||
| { |  | ||||||
|   "name": "le-sni-auto", |  | ||||||
|   "version": "2.1.9", |  | ||||||
|   "lockfileVersion": 1 |  | ||||||
| } |  | ||||||
| @ -1,11 +1,11 @@ | |||||||
| { | { | ||||||
|   "name": "le-sni-auto", |   "name": "le-sni-auto", | ||||||
|   "version": "2.1.9", |   "version": "2.1.3", | ||||||
|   "description": "An auto-sni strategy for registering and renewing letsencrypt certificates using SNICallback", |   "description": "An auto-sni strategy for registering and renewing letsencrypt certificates using SNICallback", | ||||||
|   "homepage": "https://git.coolaj86.com/coolaj86/le-sni-auto.js", |   "homepage": "https://git.coolaj86.com/coolaj86/le-sni-auto.js", | ||||||
|   "main": "index.js", |   "main": "index.js", | ||||||
|   "trulyOptionalDependencies": { |   "dependencies": { | ||||||
|     "bluebird": "^3.5.1" |     "bluebird": "^3.4.1" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": {}, |   "devDependencies": {}, | ||||||
|   "scripts": { |   "scripts": { | ||||||
| @ -13,7 +13,7 @@ | |||||||
|   }, |   }, | ||||||
|   "repository": { |   "repository": { | ||||||
|     "type": "git", |     "type": "git", | ||||||
|     "url": "https://git.coolaj86.com/coolaj86/le-sni-auto.js.git" |     "url": "git+https://git.coolaj86.com/coolaj86/le-sni-auto.git" | ||||||
|   }, |   }, | ||||||
|   "keywords": [ |   "keywords": [ | ||||||
|     "le-sni", |     "le-sni", | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user