update version detection

This commit is contained in:
AJ ONeal 2018-05-15 15:42:04 -06:00
parent 75ed99904c
commit 4c6cdfde0a
4 changed files with 127 additions and 54 deletions

View File

@ -3,7 +3,7 @@ STOP
**These aren't the droids you're looking for.** **These aren't the droids you're looking for.**
You probably don't want to use `node-letsencrypt` directly. You probably don't want to use `greenlock` directly.
Instead, look here: Instead, look here:
@ -12,21 +12,21 @@ Webservers
For any type of webserver (express, hapi, koa, connect, https, spdy, etc), For any type of webserver (express, hapi, koa, connect, https, spdy, etc),
you're going to want to take a look at you're going to want to take a look at
[letsencrypt-express](https://github.com/Daplie/letsencrypt-express). [greenlock-express](https://git.coolaj86.com/coolaj86/greenlock-express.js).
<https://github.com/Daplie/letsencrypt-express> <https://git.coolaj86.com/coolaj86/greenlock-express.js>
CLIs CLIs
---- ----
For any type of CLI (like what you want to use with bash, fish, zsh, cmd.exe, PowerShell, etc), For any type of CLI (like what you want to use with bash, fish, zsh, cmd.exe, PowerShell, etc),
you're going to want to take a look at you're going to want to take a look at
[letsencrypt-cli](https://github.com/Daplie/letsencrypt-cli). [greenlock-cli](https://git.coolaj86.com/coolaj86/greenlock-cli.js).
<https://github.com/Daplie/letsencrypt-cli> <https://git.coolaj86.com/coolaj86/greenlock-cli.js>
No, I wanted node-letsencrypt No, I wanted greenlock
============================= ======================
Well, take a look at the API in the main README Well, take a look at the API in the main README
and you can also check out the code in the repos above. and you can also check out the code in the repos above.

View File

@ -5,9 +5,10 @@ var LE = require('../');
var db = {}; var db = {};
var config = { var config = {
server: LE.stagingServerUrl // or LE.productionServerUrl server: 'https://acme-staging-v02.api.letsencrypt.org/directory'
, version: 'v02'
, configDir: require('homedir')() + '/letsencrypt/etc' // or /etc/letsencrypt or wherever , configDir: require('os').homedir() + '/acme/etc' // or /etc/acme or wherever
, privkeyPath: ':config/live/:hostname/privkey.pem' // , privkeyPath: ':config/live/:hostname/privkey.pem' //
, fullchainPath: ':config/live/:hostname/fullchain.pem' // Note: both that :config and :hostname , fullchainPath: ':config/live/:hostname/fullchain.pem' // Note: both that :config and :hostname
@ -34,7 +35,7 @@ var handlers = {
cb(null); cb(null);
} }
, getChallenge: function (opts, hostname, key, cb) { // this is special because it is called by the webserver , getChallenge: function (opts, hostname, key, cb) { // this is special because it is called by the webserver
cb(null, db[key].val); // (see letsencrypt-cli/bin & letsencrypt-express/standalone), cb(null, db[key].val); // (see greenlock-cli/bin & greenlock-express/standalone),
// not by the library itself // not by the library itself
} }
, agreeToTerms: function (tosUrl, cb) { // gives you an async way to expose the legal agreement , agreeToTerms: function (tosUrl, cb) { // gives you an async way to expose the legal agreement
@ -43,6 +44,8 @@ var handlers = {
}; };
var le = LE.create(config, handlers); var le = LE.create(config, handlers);
console.error("CHANGE THE EMAIL, DOMAINS, AND AGREE TOS IN THE EXAMPLE BEFORE RUNNING IT");
process.exit(1);
// checks :conf/renewal/:hostname.conf // checks :conf/renewal/:hostname.conf
le.register({ // and either renews or registers le.register({ // and either renews or registers
domains: ['example.com'] // CHANGE TO YOUR DOMAIN domains: ['example.com'] // CHANGE TO YOUR DOMAIN
@ -55,8 +58,8 @@ le.register({ // and either renews
// Note: you must have a webserver running // Note: you must have a webserver running
// and expose handlers.getChallenge to it // and expose handlers.getChallenge to it
// in order to pass validation // in order to pass validation
// See letsencrypt-cli and or letsencrypt-express // See greenlock-cli and or greenlock-express
console.error('[Error]: node-letsencrypt/examples/standalone'); console.error('[Error]: greenlock/examples/standalone');
console.error(err.stack); console.error(err.stack);
} else { } else {
console.log('success'); console.log('success');

117
index.js
View File

@ -19,8 +19,8 @@ function _log(debug) {
} }
LE.defaults = { LE.defaults = {
productionServerUrl: 'https://acme-v02.api.letsencrypt.org/directory' productionServerUrl: 'https://acme-v01.api.letsencrypt.org/directory'
, stagingServerUrl: 'https://acme-staging-v02.api.letsencrypt.org/directory' , stagingServerUrl: 'https://acme-staging.api.letsencrypt.org/directory'
, rsaKeySize: ACME.rsaKeySize || 2048 , rsaKeySize: ACME.rsaKeySize || 2048
, challengeType: ACME.challengeType || 'http-01' , challengeType: ACME.challengeType || 'http-01'
@ -111,26 +111,13 @@ LE.create = function (le) {
if (!le.renewWithin) { le.renewWithin = 14 * DAY; } if (!le.renewWithin) { le.renewWithin = 14 * DAY; }
// renewBy has a default in le-sni-auto // renewBy has a default in le-sni-auto
if (!le.server) {
throw new Error("opts.server must be set to 'staging' or a production url, such as LE.productionServerUrl'");
}
if ('staging' === le.server) {
le.server = LE.stagingServerUrl;
}
else if ('production' === le.server) {
le.server = LE.productionServerUrl;
}
if (-1 !== [ 'https://acme-v01.api.letsencrypt.org/directory'
, 'https://acme-staging.api.letsencrypt.org/directory' ].indexOf(le.server)) { ///////////////////////////
ACME = require('le-acme-core').ACME; // BEGIN VERSION MADNESS //
console.warn("Let's Encrypt v1 is deprecated. Please update to Let's Encrypt v2 (ACME draft 11)"); ///////////////////////////
}
else if (-1 !== [ 'https://acme-v02.api.letsencrypt.org/directory' if (!le.version) {
, 'https://acme-staging-v02.api.letsencrypt.org/directory' ].indexOf(le.server)) {
if ('v02' !== le.version && 'draft-11' !== le.version) {
ACME = require('le-acme-core').ACME;
if ('v01' !== le.version) {
//console.warn("Please specify version: 'v01' (Let's Encrypt v1) or 'draft-11' (Let's Encrypt v2 / ACME draft 11)"); //console.warn("Please specify version: 'v01' (Let's Encrypt v1) or 'draft-11' (Let's Encrypt v2 / ACME draft 11)");
console.warn(""); console.warn("");
console.warn(""); console.warn("");
@ -141,20 +128,104 @@ LE.create = function (le) {
console.warn(""); console.warn("");
console.warn("Please specify 'version' option:"); console.warn("Please specify 'version' option:");
console.warn(""); console.warn("");
console.warn(" 'v01' for Let's Encrypt v1");
console.warn(" or");
console.warn(" 'draft-11' for Let's Encrypt v2 and ACME draft 11"); console.warn(" 'draft-11' for Let's Encrypt v2 and ACME draft 11");
console.warn(" ('v02' is an alias of 'draft-11'"); console.warn(" ('v02' is an alias of 'draft-11'");
console.warn(""); console.warn("");
console.warn("or");
console.warn("");
console.warn(" 'v01' for Let's Encrypt v1 (deprecated)");
console.warn("");
console.warn("===================================================================="); console.warn("====================================================================");
console.warn("== this will be required from version v2.3 forward =="); console.warn("== this will be required from version v2.3 forward ==");
console.warn("===================================================================="); console.warn("====================================================================");
console.warn(""); console.warn("");
console.warn(""); console.warn("");
console.warn(""); console.warn("");
} else if ('v02' === le.version) {
le.version = 'draft-11';
} else if ('v01' !== le.version && 'draft-11' !== le.version) {
throw new Error("Unrecognized version '" + le.version + "'");
}
if (!le.server) {
throw new Error("opts.server must specify an ACME directory URL, such as 'https://acme-staging-v02.api.letsencrypt.org/directory'");
}
if ('staging' === le.server) {
le.server = 'https://acme-staging.api.letsencrypt.org/directory';
le.version = 'v01';
console.warn("");
console.warn("");
console.warn("=== WARNING ===");
console.warn("");
console.warn("Due to versioning issues the 'staging' option is deprecated. Please specify the full url and version.");
console.warn("");
console.warn("\t--acme-url '" + le.server + "' \\");
console.warn("\t--acme-version '" + le.version + "' \\");
console.warn("");
console.warn("");
}
else if ('production' === le.server) {
le.server = 'https://acme-v01.api.letsencrypt.org/directory';
le.version = 'v01';
console.warn("");
console.warn("");
console.warn("=== WARNING ===");
console.warn("");
console.warn("Due to versioning issues the 'production' option is deprecated. Please specify the full url and version.");
console.warn("");
console.warn("\t--acme-url '" + le.server + "' \\");
console.warn("\t--acme-version '" + le.version + "' \\");
console.warn("");
console.warn("");
}
function loadLeV01() {
console.warn("");
console.warn("=== WARNING ===");
console.warn("");
console.warn("Let's Encrypt v1 is deprecated. Please update to Let's Encrypt v2 (ACME draft 11)");
console.warn("");
try {
return require('le-acme-core').ACME;
} catch(e) {
console.error(e);
console.info("");
console.info("");
console.info("If you require v01 API support (which is deprecated), you must install it:");
console.info("");
console.info("\tnpm install le-acme-core");
console.info("");
console.info("");
process.exit(e.code || 13);
} }
} }
if (-1 !== [
'https://acme-v02.api.letsencrypt.org/directory'
, 'https://acme-staging-v02.api.letsencrypt.org/directory' ].indexOf(le.server)
) {
if ('draft-11' !== le.version) {
console.warn("Detected Let's Encrypt v02 URL. Changing version to draft-11.");
le.version = 'draft-11';
} }
} else if (-1 !== [
'https://acme-v01.api.letsencrypt.org/directory'
, 'https://acme-staging.api.letsencrypt.org/directory' ].indexOf(le.server)
|| 'v01' === le.version
) {
if ('v01' !== le.version) {
console.warn("Detected Let's Encrypt v01 URL (deprecated). Changing version to v01.");
le.version = 'v01';
}
}
if ('v01' === le.version) {
ACME = loadLeV01();
}
/////////////////////////
// END VERSION MADNESS //
/////////////////////////
le.acme = le.acme || ACME.create({ debug: le.debug }); le.acme = le.acme || ACME.create({ debug: le.debug });
if (le.acme.create) { if (le.acme.create) {

View File

@ -65,7 +65,6 @@
"asn1js": "^1.2.12", "asn1js": "^1.2.12",
"certpem": "^1.0.0", "certpem": "^1.0.0",
"homedir": "^0.6.0", "homedir": "^0.6.0",
"le-acme-core": "^2.1.2",
"le-challenge-fs": "^2.0.2", "le-challenge-fs": "^2.0.2",
"le-challenge-sni": "^2.0.0", "le-challenge-sni": "^2.0.0",
"le-sni-auto": "^2.1.3", "le-sni-auto": "^2.1.3",