updates
This commit is contained in:
parent
88406b9c0b
commit
1e4affc079
|
@ -1,3 +1,7 @@
|
||||||
|
letsencrypt.work
|
||||||
|
letsencrypt.logs
|
||||||
|
letsencrypt.config
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
|
|
|
@ -1,36 +1,52 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var path = require('path');
|
||||||
var leBinPath = require('homedir')() + '/.local/share/letsencrypt/bin/letsencrypt';
|
var leBinPath = require('homedir')() + '/.local/share/letsencrypt/bin/letsencrypt';
|
||||||
var lep = require('letsencrypt-python').create(leBinPath);
|
var LEP = require('letsencrypt-python');
|
||||||
|
var lep = LEP.create(leBinPath, { debug: true });
|
||||||
var conf = {
|
var conf = {
|
||||||
domains: process.argv[2]
|
domains: process.argv[2]
|
||||||
, email: process.argv[3]
|
, email: process.argv[3]
|
||||||
, agree: process.argv[4]
|
, agree: process.argv[4]
|
||||||
};
|
};
|
||||||
|
var port = 80;
|
||||||
|
var tlsPort = 5001;
|
||||||
|
|
||||||
|
if (!conf.domains || !conf.email || !conf.agree) {
|
||||||
|
console.error("Usage: letsencrypt <domain1,domain2> <email> agree");
|
||||||
|
console.error("Example: letsencrypt example.com,www.example.com user@example.com agree");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// backend-specific defaults
|
// backend-specific defaults
|
||||||
// Note: For legal reasons you should NOT set email or agreeTos as a default
|
// Note: For legal reasons you should NOT set email or agreeTos as a default
|
||||||
var bkDefaults = {
|
var bkDefaults = {
|
||||||
webroot: true
|
webroot: true
|
||||||
, webrootPath: __dirname + '/acme-challenge'
|
, webrootPath: path.join(__dirname, '..', 'tests', 'acme-challenge')
|
||||||
, fullchainTpl: '/live/:hostname/fullchain.pem'
|
, fullchainTpl: '/live/:hostname/fullchain.pem'
|
||||||
, privkeyTpl: '/live/:hostname/fullchain.pem'
|
, privkeyTpl: '/live/:hostname/fullchain.pem'
|
||||||
, configDir: '/etc/letsencrypt'
|
, configDir: path.join(__dirname, '..', 'tests', 'letsencrypt.config')
|
||||||
, logsDir: '/var/log/letsencrypt'
|
, logsDir: path.join(__dirname, '..', 'tests', 'letsencrypt.logs')
|
||||||
, workDir: '/var/lib/letsencrypt'
|
, workDir: path.join(__dirname, '..', 'tests', 'letsencrypt.work')
|
||||||
|
, server: LEP.stagingServer
|
||||||
, text: true
|
, text: true
|
||||||
};
|
};
|
||||||
var le = require('../').create(lep, bkDefaults);
|
var le = require('../').create(lep, bkDefaults, {
|
||||||
|
});
|
||||||
|
|
||||||
var localCerts = require('localhost.daplie.com-certificates');
|
var localCerts = require('localhost.daplie.com-certificates');
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
app.use(le.middleware());
|
app.use('/', function (req, res, next) {
|
||||||
|
console.log('[DEBUG]', req.method, req.protocol, req.hostname, req.url);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
app.use('/', le.middleware());
|
||||||
|
|
||||||
var server = require('http').createServer();
|
var server = require('http').createServer();
|
||||||
server.on('request', app);
|
server.on('request', app);
|
||||||
server.listen(80, function () {
|
server.listen(port, function () {
|
||||||
console.log('Listening http', server.address());
|
console.log('Listening http', server.address());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -40,7 +56,7 @@ var tlsServer = require('https').createServer({
|
||||||
, SNICallback: le.sniCallback
|
, SNICallback: le.sniCallback
|
||||||
});
|
});
|
||||||
tlsServer.on('request', app);
|
tlsServer.on('request', app);
|
||||||
tlsServer.listen(443, function () {
|
tlsServer.listen(tlsPort, function () {
|
||||||
console.log('Listening http', tlsServer.address());
|
console.log('Listening http', tlsServer.address());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
21
index.js
21
index.js
|
@ -1,7 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var PromiseA = require('bluebird');
|
||||||
|
|
||||||
module.exports.create = function (letsencrypt, defaults, options) {
|
module.exports.create = function (letsencrypt, defaults, options) {
|
||||||
var PromiseA = require('bluebird');
|
letsencrypt = PromiseA.promisifyAll(letsencrypt);
|
||||||
var tls = require('tls');
|
var tls = require('tls');
|
||||||
var fs = PromiseA.promisifyAll(require('fs'));
|
var fs = PromiseA.promisifyAll(require('fs'));
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
|
@ -28,18 +30,24 @@ module.exports.create = function (letsencrypt, defaults, options) {
|
||||||
var now;
|
var now;
|
||||||
var le;
|
var le;
|
||||||
|
|
||||||
options.cacheContextsFor = options.cacheContextsFor || (1 * 60 * 60 * 1000);
|
// TODO check certs on initial load
|
||||||
|
// TODO expect that certs expire every 90 days
|
||||||
|
// TODO check certs with setInterval?
|
||||||
|
//options.cacheContextsFor = options.cacheContextsFor || (1 * 60 * 60 * 1000);
|
||||||
|
|
||||||
defaults.webroot = true;
|
defaults.webroot = true;
|
||||||
|
|
||||||
function merge(args) {
|
function merge(args) {
|
||||||
var copy = {};
|
var copy = {};
|
||||||
|
|
||||||
Object.keys(defaults).forEach(function (key) {
|
Object.keys(defaults).forEach(function (key) {
|
||||||
copy[key] = defaults[key];
|
copy[key] = defaults[key];
|
||||||
});
|
});
|
||||||
Object.keys(args).forEach(function (key) {
|
Object.keys(args).forEach(function (key) {
|
||||||
copy[key] = args[key];
|
copy[key] = args[key];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sniCallback(hostname, cb) {
|
function sniCallback(hostname, cb) {
|
||||||
|
@ -65,21 +73,28 @@ module.exports.create = function (letsencrypt, defaults, options) {
|
||||||
|
|
||||||
le = {
|
le = {
|
||||||
validate: function () {
|
validate: function () {
|
||||||
|
// TODO check dns, etc
|
||||||
|
return PromiseA.resolve();
|
||||||
}
|
}
|
||||||
, middleware: function () {
|
, middleware: function () {
|
||||||
|
console.log('[DEBUG] webrootPath', defaults.webrootPath);
|
||||||
var serveStatic = require('serve-static')(defaults.webrootPath);
|
var serveStatic = require('serve-static')(defaults.webrootPath);
|
||||||
var prefix = '/.well-known/acme-challenge/';
|
var prefix = '/.well-known/acme-challenge/';
|
||||||
|
|
||||||
return function (req, res, next) {
|
return function (req, res, next) {
|
||||||
if (0 === req.url.indexOf(prefix)) {
|
if (0 !== req.url.indexOf(prefix)) {
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('[DEBUG] req.url 0', req.url);
|
||||||
var pathname = req.url;
|
var pathname = req.url;
|
||||||
req.url = req.url.substr(prefix.length - 1);
|
req.url = req.url.substr(prefix.length - 1);
|
||||||
|
console.log('[DEBUG] req.url 1', req.url);
|
||||||
serveStatic(req, res, function (err) {
|
serveStatic(req, res, function (err) {
|
||||||
|
console.log('[DEBUG] req.url 2', req.url);
|
||||||
req.url = pathname;
|
req.url = pathname;
|
||||||
|
console.log('[DEBUG] req.url 3', req.url);
|
||||||
next(err);
|
next(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
"localhost.daplie.com-certificates": "^1.1.2"
|
"localhost.daplie.com-certificates": "^1.1.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"letsencrypt-python": "^1.0.3"
|
"bluebird": "^3.0.6",
|
||||||
|
"letsencrypt-python": "^1.0.3",
|
||||||
|
"serve-static": "^1.10.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue