From 1e4affc0793f64b6c36523f19af1d40314052308 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 12 Dec 2015 15:05:45 +0000 Subject: [PATCH] updates --- .gitignore | 4 ++++ bin/standalone.js | 34 +++++++++++++++++++++++++--------- index.js | 21 ++++++++++++++++++--- package.json | 4 +++- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 123ae94..bf23d29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +letsencrypt.work +letsencrypt.logs +letsencrypt.config + # Logs logs *.log diff --git a/bin/standalone.js b/bin/standalone.js index af6c094..434cb61 100644 --- a/bin/standalone.js +++ b/bin/standalone.js @@ -1,36 +1,52 @@ 'use strict'; +var path = require('path'); 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 = { domains: process.argv[2] , email: process.argv[3] , agree: process.argv[4] }; +var port = 80; +var tlsPort = 5001; + +if (!conf.domains || !conf.email || !conf.agree) { + console.error("Usage: letsencrypt agree"); + console.error("Example: letsencrypt example.com,www.example.com user@example.com agree"); + return; +} // backend-specific defaults // Note: For legal reasons you should NOT set email or agreeTos as a default var bkDefaults = { webroot: true -, webrootPath: __dirname + '/acme-challenge' +, webrootPath: path.join(__dirname, '..', 'tests', 'acme-challenge') , fullchainTpl: '/live/:hostname/fullchain.pem' , privkeyTpl: '/live/:hostname/fullchain.pem' -, configDir: '/etc/letsencrypt' -, logsDir: '/var/log/letsencrypt' -, workDir: '/var/lib/letsencrypt' +, configDir: path.join(__dirname, '..', 'tests', 'letsencrypt.config') +, logsDir: path.join(__dirname, '..', 'tests', 'letsencrypt.logs') +, workDir: path.join(__dirname, '..', 'tests', 'letsencrypt.work') +, server: LEP.stagingServer , text: true }; -var le = require('../').create(lep, bkDefaults); +var le = require('../').create(lep, bkDefaults, { +}); var localCerts = require('localhost.daplie.com-certificates'); var express = require('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(); server.on('request', app); -server.listen(80, function () { +server.listen(port, function () { console.log('Listening http', server.address()); }); @@ -40,7 +56,7 @@ var tlsServer = require('https').createServer({ , SNICallback: le.sniCallback }); tlsServer.on('request', app); -tlsServer.listen(443, function () { +tlsServer.listen(tlsPort, function () { console.log('Listening http', tlsServer.address()); }); diff --git a/index.js b/index.js index 4787645..df2e372 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,9 @@ 'use strict'; +var PromiseA = require('bluebird'); + module.exports.create = function (letsencrypt, defaults, options) { - var PromiseA = require('bluebird'); + letsencrypt = PromiseA.promisifyAll(letsencrypt); var tls = require('tls'); var fs = PromiseA.promisifyAll(require('fs')); var utils = require('./utils'); @@ -28,18 +30,24 @@ module.exports.create = function (letsencrypt, defaults, options) { var now; 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; function merge(args) { var copy = {}; + Object.keys(defaults).forEach(function (key) { copy[key] = defaults[key]; }); Object.keys(args).forEach(function (key) { copy[key] = args[key]; }); + + return copy; } function sniCallback(hostname, cb) { @@ -65,21 +73,28 @@ module.exports.create = function (letsencrypt, defaults, options) { le = { validate: function () { + // TODO check dns, etc + return PromiseA.resolve(); } , middleware: function () { + console.log('[DEBUG] webrootPath', defaults.webrootPath); var serveStatic = require('serve-static')(defaults.webrootPath); var prefix = '/.well-known/acme-challenge/'; return function (req, res, next) { - if (0 === req.url.indexOf(prefix)) { + if (0 !== req.url.indexOf(prefix)) { next(); return; } + console.log('[DEBUG] req.url 0', req.url); var pathname = req.url; req.url = req.url.substr(prefix.length - 1); + console.log('[DEBUG] req.url 1', req.url); serveStatic(req, res, function (err) { + console.log('[DEBUG] req.url 2', req.url); req.url = pathname; + console.log('[DEBUG] req.url 3', req.url); next(err); }); }; diff --git a/package.json b/package.json index 592dca3..bd2bd2a 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,8 @@ "localhost.daplie.com-certificates": "^1.1.2" }, "dependencies": { - "letsencrypt-python": "^1.0.3" + "bluebird": "^3.0.6", + "letsencrypt-python": "^1.0.3", + "serve-static": "^1.10.0" } }