From fd04a5070b920c61100dbd06c00761af8830bead Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 20 Oct 2019 03:17:19 -0600 Subject: [PATCH] need to fail when privkey cannot be found --- accounts.js | 7 ------- certificates.js | 7 ++++--- greenlock.js | 18 ++++++++++++------ tests/index.js | 6 ++++-- utils.js | 4 ++-- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/accounts.js b/accounts.js index 71de6f4..2fdfc66 100644 --- a/accounts.js +++ b/accounts.js @@ -7,11 +7,9 @@ var E = require('./errors.js'); var pending = {}; A._getOrCreate = function(greenlock, db, acme, args) { - console.log('[debug] A get or create', args); var email = args.subscriberEmail || greenlock._defaults.subscriberEmail; if (!email) { - console.log('[debug] throw no sub'); throw E.NO_SUBSCRIBER('get account', args.subject); } @@ -21,9 +19,7 @@ A._getOrCreate = function(greenlock, db, acme, args) { throw E.NO_SUBSCRIBER('get account', args.subcriberEmail); }) .then(function() { - console.log('[debug] valid email'); if (pending[email]) { - console.log('[debug] return pending'); return pending[email]; } @@ -37,7 +33,6 @@ A._getOrCreate = function(greenlock, db, acme, args) { return result; }); - console.log('[debug] return new'); return pending[email]; }); }; @@ -52,7 +47,6 @@ A._rawGetOrCreate = function(greenlock, db, acme, args, email) { } return p.then(function(fullAccount) { - console.log('[debug] full account', fullAccount); if (!fullAccount) { return A._newAccount(greenlock, db, acme, args, email, null); } @@ -83,7 +77,6 @@ A._newAccount = function(greenlock, db, acme, args, email, fullAccount) { accountKeypair: keypair, debug: args.debug }; - console.log('[debug] create account', accReg); return acme.accounts.create(accReg).then(function(receipt) { var reg = { keypair: keypair, diff --git a/certificates.js b/certificates.js index 4ecf44a..cbe1d03 100644 --- a/certificates.js +++ b/certificates.js @@ -61,7 +61,7 @@ C._rawGetOrOrder = function( args ).then(function(newPems) { // do not wait on notify - greenlock.notify('cert_issue', { + greenlock._notify('cert_issue', { options: args, subject: args.subject, altnames: args.altnames, @@ -92,7 +92,7 @@ C._rawGetOrOrder = function( args ).then(function(renewedPems) { // do not wait on notify - greenlock.notify('cert_renewal', { + greenlock._notify('cert_renewal', { options: args, subject: args.subject, altnames: args.altnames, @@ -144,7 +144,7 @@ C._rawOrder = function(greenlock, db, acme, challenges, account, email, args) { }) .then(function(csr) { function notify() { - greenlock.notify('challenge_status', { + greenlock._notify('challenge_status', { options: args, subject: args.subject, altnames: args.altnames, @@ -176,6 +176,7 @@ C._rawOrder = function(greenlock, db, acme, challenges, account, email, args) { if (kresult.exists) { return pems; } + query.keypair = serverKeypair; return db.setKeypair(query, serverKeypair).then(function() { return pems; }); diff --git a/greenlock.js b/greenlock.js index 62c7974..6de72c6 100644 --- a/greenlock.js +++ b/greenlock.js @@ -4,6 +4,7 @@ var pkg = require('./package.json'); var ACME = require('@root/acme'); var Greenlock = module.exports; +var homedir = require('os').homedir(); var G = Greenlock; var U = require('./utils.js'); @@ -201,7 +202,6 @@ G.create = function(gconf) { return greenlock.manager.find(args).then(function(sites) { // Note: the manager must guaranteed that these are mutable copies - console.log('[debug] found what?', sites); var renewedOrFailed = []; function next() { @@ -267,7 +267,6 @@ G.create = function(gconf) { greenlock.order = function(args) { return greenlock._acme(args).then(function(acme) { - console.log('[debug] acme meta', acme); var storeConf = args.store || greenlock._defaults.store; return P._load(storeConf.module).then(function(plugin) { var store = Greenlock._normalizeStore( @@ -275,20 +274,19 @@ G.create = function(gconf) { plugin.create(storeConf) ); - console.log('[debug] store', storeConf); return A._getOrCreate( greenlock, store.accounts, acme, args ).then(function(account) { - console.log('[debug] account', account); var challengeConfs = args.challenges || greenlock._defaults.challenges; console.log('[debug] challenge confs', challengeConfs); return Promise.all( Object.keys(challengeConfs).map(function(typ01) { var chConf = challengeConfs[typ01]; + console.log('[debug] module', chConf); return P._load(chConf.module).then(function( plugin ) { @@ -367,7 +365,7 @@ G._defaults = function(opts) { if (!defaults.store) { defaults.store = { module: 'greenlock-store-fs', - basePath: '~/.config/greenlock/' + basePath: homedir + '/.config/greenlock/' }; } P._loadSync(defaults.store.module); @@ -405,6 +403,13 @@ G._defaults = function(opts) { }; } + if (!defaults.renewOffset) { + defaults.renewOffset = '-45d'; + } + if (!defaults.renewStagger) { + defaults.renewStagger = '3d'; + } + if (!defaults.accountKeyType) { defaults.accountKeyType = 'EC-P256'; } @@ -412,8 +417,9 @@ G._defaults = function(opts) { if (defaults.domainKeyType) { console.warn('use serverKeyType instead of domainKeyType'); defaults.serverKeyType = defaults.domainKeyType; + } else { + defaults.serverKeyType = 'RSA-2048'; } - defaults.serverKeyType = 'RSA-2048'; } if (defaults.domainKeypair) { console.warn('use serverKeypair instead of domainKeypair'); diff --git a/tests/index.js b/tests/index.js index 561921d..db6944c 100644 --- a/tests/index.js +++ b/tests/index.js @@ -9,7 +9,7 @@ var subject = process.env.BASE_DOMAIN; var altnames = [subject, '*.' + subject, 'foo.bar.' + subject]; var email = process.env.SUBSCRIBER_EMAIL; var challenge = JSON.parse(process.env.CHALLENGE_OPTIONS); -challenge.module = process.env.CHALLENGE_MODULE; +challenge.module = process.env.CHALLENGE_PLUGIN; var greenlock = Greenlock.create({ agreeTos: true, @@ -33,7 +33,9 @@ greenlock subscriberEmail: email }) .then(function() { - return greenlock.renew(); + return greenlock.renew().then(function (pems) { + console.info(pems); + }); }) .catch(function(e) { console.error('yo', e.code); diff --git a/utils.js b/utils.js index 915cc86..341ce7f 100644 --- a/utils.js +++ b/utils.js @@ -174,8 +174,8 @@ U._importKeypair = function(keypair) { throw new Error('missing private key'); } - return Keypairs.import({ pem: keypair.privateKeyPem }).then(function(pair) { - return U._jwkToSet(pair.private); + return Keypairs.import({ pem: keypair.privateKeyPem }).then(function(priv) { + return U._jwkToSet(priv); }); };