From f8fc01c5f02fdbf7fdbbd485661f47e69824c7b6 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 9 Aug 2016 23:32:39 -0400 Subject: [PATCH] v2.0.0 --- README.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-- index.js | 32 +++++++++++++++++++++++++++++ package.json | 29 ++++++++++++++++++++++++++ test.js | 51 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 index.js create mode 100644 package.json create mode 100644 test.js diff --git a/README.md b/README.md index d9a2d68..f3d90c9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,56 @@ -# le-challenge-memory -A memory-based strategy for node-letsencrypt for setting, retrieving, and clearing ACME challenges issued by the ACME server +[![Join the chat at https://gitter.im/Daplie/letsencrypt-express](https://badges.gitter.im/Daplie/letsencrypt-express.svg)](https://gitter.im/Daplie/letsencrypt-express?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +| [letsencrypt](https://github.com/Daplie/node-letsencrypt) (library) +| [letsencrypt-cli](https://github.com/Daplie/letsencrypt-cli) +| [letsencrypt-express](https://github.com/Daplie/letsencrypt-express) +| [letsencrypt-koa](https://github.com/Daplie/letsencrypt-koa) +| [letsencrypt-hapi](https://github.com/Daplie/letsencrypt-hapi) +| + +le-challenge-memory +=================== + +An in-memory strategy for node-letsencrypt for setting, retrieving, +and clearing ACME challenges issued by the ACME server + +* Safe to use on ephemeral services (i.e. AWS) +* DO NOT use with node cluester (i.e. letsencrypt-cluster) + +Install +------- + +```bash +npm install --save le-challenge-standalone@2.x +``` + +Usage +----- + +```bash +var leChallenge = require('le-challenge-standalone').create({ +, debug: false +}); + +var LE = require('letsencrypt'); + +LE.create({ + server: LE.stagingServerUrl +, challenge: leChallenge +}); +``` + +NOTE: If you request a certificate with 6 domains listed, +it will require 6 individual challenges. + +Exposed Methods +--------------- + +For ACME Challenge: + +* `set(opts, domain, key, val, done)` +* `get(defaults, domain, key, done)` +* `remove(defaults, domain, key, done)` + +For node-letsencrypt internals: + +* `getOptions()` returns the user supplied options, if any (no effect) diff --git a/index.js b/index.js new file mode 100644 index 0000000..d74cbd6 --- /dev/null +++ b/index.js @@ -0,0 +1,32 @@ +'use strict'; + +module.exports.create = function (defaults) { + var handlers = { + getOptions: function () { + return defaults; + } + // + // set,get,remove challenges + // + // Note: this is fine for a one-off CLI tool + // but a webserver using node-cluster or multiple + // servers should use a database of some sort + , _challenges: {} + , set: function (args, domain, token, secret, cb) { + handlers._challenges[token] = secret; + cb(null); + } + , get: function (args, domain, token, cb) { + // TODO keep in mind that, generally get args are just args.domains + // and it is disconnected from the flow of setChallenge and removeChallenge + cb(null, handlers._challenges[token]); + } + , remove: function (args, domain, token, cb) { + delete handlers._challenges[token]; + cb(null); + } + + }; + + return handlers; +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..37ae903 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "le-challenge-standalone", + "version": "2.0.0", + "description": "An in-memory strategy for node-letsencrypt for setting, retrieving, and clearing ACME challenges issued by the ACME server.", + "main": "index.js", + "scripts": { + "test": "node test.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Daplie/le-challenge-memory.git" + }, + "keywords": [ + "le-challenge", + "le-challenge-", + "memory", + "in-memory", + "standalone", + "ACME", + "letsencrypt", + "certbot" + ], + "author": "AJ ONeal (https://coolaj86.com/)", + "license": "(MIT OR Apache-2.0)", + "bugs": { + "url": "https://github.com/Daplie/le-challenge-memory/issues" + }, + "homepage": "https://github.com/Daplie/le-challenge-memory#readme" +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..a8111f2 --- /dev/null +++ b/test.js @@ -0,0 +1,51 @@ +'use strict'; + +var challenge = require('./').create({ debug: true, webrootPath: '/tmp/acme-challenge' }); + +var opts = challenge.getOptions(); +var domain = 'example.com'; +var token = 'token-id'; +var key = 'secret-key'; + +challenge.remove(opts, domain, token, function () { + // ignore error, if any + + challenge.set(opts, domain, token, key, function (err) { + // if there's an error, there's a problem + if (err) { + throw err; + } + + // throw new Error("manually check /tmp/acme-challenge"); + + challenge.get(opts, domain, token, function (err, _key) { + // if there's an error, there's a problem + if (err) { + throw err; + } + + // should retrieve the key + if (key !== _key) { + throw new Error("FAIL: could not get key by token"); + } + + challenge.remove(opts, domain, token, function () { + // if there's an error, there's a problem + if (err) { + throw err; + } + + challenge.get(opts, domain, token, function (err, _key) { + // error here is okay + + // should NOT retrieve the key + if (_key) { + throw new Error("FAIL: should not get key"); + } + + console.info('PASS'); + }); + }); + }); + }); +});