From 4767d14517f1231e2d7e85dbec60fa0d2b876a11 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 16 Dec 2015 02:51:38 +0000 Subject: [PATCH] updates --- README.md | 1 + lib/get-acme-urls.js | 56 ++++++++++++++++++++++++++++++++++++++++++++ node.js | 4 +++- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 lib/get-acme-urls.js diff --git a/README.md b/README.md index 83ba1ae..e464755 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,7 @@ LeCore.acmeChallengePrefix // /.well-known/acme-challenge/ LeCore.configDir // /etc/letsencrypt/ LeCore.logsDir // /var/log/letsencrypt/ LeCore.workDir // /var/lib/letsencrypt/ +LeCore.knownEndpoints // new-authz, new-cert, new-reg, revoke-cert // HTTP Client Helpers diff --git a/lib/get-acme-urls.js b/lib/get-acme-urls.js new file mode 100644 index 0000000..87d14c5 --- /dev/null +++ b/lib/get-acme-urls.js @@ -0,0 +1,56 @@ +/*! + * letiny-core + * Copyright(c) 2015 AJ ONeal https://daplie.com + * Apache-2.0 OR MIT (and hence also MPL 2.0) +*/ +'use strict'; + +module.exports.create = function (deps) { + var request = deps.request; + var knownUrls = deps.LeCore.knownEndpoints; + + function getAcmeUrls(acmeDiscoveryUrl, cb) { + + // TODO check response header on request for cache time + return request({ + url: acmeDiscoveryUrl + }, function (err, resp) { + if (err) { + cb(err); + return; + } + + var data = resp.body; + + if ('string' === typeof data) { + try { + data = JSON.parse(data); + } catch(e) { + cb(e); + return; + } + } + + if (4 !== Object.keys(data).length) { + console.warn("This Let's Encrypt / ACME server has been updated with urls that this client doesn't understand"); + console.warn(data); + } + + if (!knownUrls.every(function (url) { + return data[url]; + })) { + console.warn("This Let's Encrypt / ACME server is missing urls that this client may need."); + console.warn(data); + } + + return { + newAuthz: data['new-authz'] + , newCert: data['new-cert'] + , newReg: data['new-reg'] + , revokeCert: data['revoke-cert'] + }; + }); + } + + return getAcmeUrls; +}; diff --git a/node.js b/node.js index fb81c94..69d3b8b 100644 --- a/node.js +++ b/node.js @@ -1,5 +1,5 @@ /*! - * letsencrypt-core + * letiny-core * Copyright(c) 2015 AJ ONeal https://daplie.com * Apache-2.0 OR MIT (and hence also MPL 2.0) */ @@ -9,6 +9,7 @@ function create(deps) { var LeCore = {}; LeCore.leCrypto = deps.leCrypto; + LeCore.getAcmeUrls = require('./lib/get-acme-urls').create(deps); deps.Acme = LeCore.Acme = require('./lib/acme-client').create(deps); LeCore.registerNewAccount = require('./lib/register-new-account').create(deps); LeCore.getCertificate = require('./lib/get-certificate').create(deps); @@ -22,6 +23,7 @@ function create(deps) { LeCore.configDir = "/etc/letsencrypt/"; LeCore.logsDir = "/var/log/letsencrypt/"; LeCore.workDir = "/var/lib/letsencrypt/"; + LeCore.knownEndpoints = ['new-authz', 'new-cert', 'new-reg', 'revoke-cert']; return LeCore; }