2015-12-16 02:51:38 +00:00
|
|
|
/*!
|
|
|
|
* letiny-core
|
2018-11-20 21:39:54 +00:00
|
|
|
* Copyright(c) 2015 AJ ONeal <coolaj86@gmail.com> https://coolaj86.com
|
2015-12-16 02:51:38 +00:00
|
|
|
* Apache-2.0 OR MIT (and hence also MPL 2.0)
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
module.exports.create = function (deps) {
|
2017-03-11 21:46:33 +00:00
|
|
|
var acmeRequest = deps.acmeRequest;
|
2015-12-16 02:51:38 +00:00
|
|
|
var knownUrls = deps.LeCore.knownEndpoints;
|
|
|
|
|
|
|
|
function getAcmeUrls(acmeDiscoveryUrl, cb) {
|
2015-12-16 09:48:34 +00:00
|
|
|
if ('string' !== typeof acmeDiscoveryUrl) {
|
|
|
|
cb(new Error("getAcmeUrls: acmeDiscoveryUrl must be a string"));
|
|
|
|
}
|
2015-12-16 02:51:38 +00:00
|
|
|
|
|
|
|
// TODO check response header on request for cache time
|
2017-03-11 21:46:33 +00:00
|
|
|
return acmeRequest.create()({
|
2015-12-16 02:51:38 +00:00
|
|
|
url: acmeDiscoveryUrl
|
2015-12-16 12:57:26 +00:00
|
|
|
, encoding: 'utf8'
|
2015-12-16 02:51:38 +00:00
|
|
|
}, function (err, resp) {
|
|
|
|
if (err) {
|
|
|
|
cb(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = resp.body;
|
|
|
|
|
|
|
|
if ('string' === typeof data) {
|
|
|
|
try {
|
|
|
|
data = JSON.parse(data);
|
|
|
|
} catch(e) {
|
2016-08-11 14:41:30 +00:00
|
|
|
e.raw = data;
|
|
|
|
e.url = acmeDiscoveryUrl;
|
|
|
|
e.stack += '\n\nresponse data:\n'
|
|
|
|
+ data + '\n\nacmeDiscoveryUrl:' + acmeDiscoveryUrl;
|
2015-12-16 02:51:38 +00:00
|
|
|
cb(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-12-16 02:57:17 +00:00
|
|
|
cb(null, {
|
2015-12-16 02:51:38 +00:00
|
|
|
newAuthz: data['new-authz']
|
|
|
|
, newCert: data['new-cert']
|
|
|
|
, newReg: data['new-reg']
|
|
|
|
, revokeCert: data['revoke-cert']
|
2017-01-12 22:37:34 +00:00
|
|
|
, keyChange: data['key-change']
|
2015-12-16 02:57:17 +00:00
|
|
|
});
|
2015-12-16 02:51:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return getAcmeUrls;
|
|
|
|
};
|