This commit is contained in:
AJ ONeal 2015-12-16 02:51:38 +00:00
parent 9f5b52a7be
commit 4767d14517
3 changed files with 60 additions and 1 deletions

View File

@ -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

56
lib/get-acme-urls.js Normal file
View File

@ -0,0 +1,56 @@
/*!
* letiny-core
* Copyright(c) 2015 AJ ONeal <aj@daplie.com> 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;
};

View File

@ -1,5 +1,5 @@
/*!
* letsencrypt-core
* letiny-core
* Copyright(c) 2015 AJ ONeal <aj@daplie.com> 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;
}