From 7db66d710ba861bd587ad6365a778870e526d4f1 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 11 Apr 2018 07:22:42 +0000 Subject: [PATCH] working even better --- README.md | 3 ++- compat.js | 26 +++++++++++++++++++++++--- node.js | 20 +++++++++++++++++++- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 16b63df..01539b3 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,12 @@ In progress * Apr 5, 2018 - test subdomains and its wildcard * Apr 5, 2018 - test http and dns challenges (success and failure) * Apr 5, 2018 - export http and dns challenge tests +* Apr 10, 2018 - tested backwards-compatibility using greenlock.js Todo -* Apr 5, 2018 - appears that sometimes 'pending' status cannot be progressed to 'processing' nor 'deactivated' * support ECDSA keys +* Apr 5, 2018 - appears that sometimes 'pending' status cannot be progressed to 'processing' nor 'deactivated' ## Let's Encrypt Directory URLs diff --git a/compat.js b/compat.js index b9f6b62..8b35579 100644 --- a/compat.js +++ b/compat.js @@ -24,11 +24,30 @@ function create(deps) { acme2.accounts.create(options).then(resolveFn(cb), rejectFn(cb)); }; acme2.getCertificate = function (options, cb) { - acme2.certificates.create(options).then(resolveFn(cb), rejectFn(cb)); + options.agreeToTerms = options.agreeToTerms || function (tos) { + return Promise.resolve(tos); + }; + acme2.certificates.create(options).then(function (chainPem) { + var privkeyPem = acme2.RSA.exportPrivatePem(options.domainKeypair); + resolveFn(cb)({ + cert: chainPem.split(/[\r\n]{2,}/g)[0] + '\r\n' + , privkey: privkeyPem + , chain: chainPem.split(/[\r\n]{2,}/g)[1] + '\r\n' + }); + }, rejectFn(cb)); }; acme2.getAcmeUrls = function (options, cb) { acme2.init(options).then(resolveFn(cb), rejectFn(cb)); }; + acme2.getOptions = function () { + var defs = {}; + + Object.keys(module.exports.defaults).forEach(function (key) { + defs[key] = defs[deps] || module.exports.defaults[key]; + }); + + return defs; + }; acme2.stagingServerUrl = module.exports.defaults.stagingServerUrl; acme2.productionServerUrl = module.exports.defaults.productionServerUrl; return acme2; @@ -41,8 +60,9 @@ module.exports.defaults = { , knownEndpoints: [ 'keyChange', 'meta', 'newAccount', 'newNonce', 'newOrder', 'revokeCert' ] , challengeTypes: [ 'http-01', 'dns-01' ] , challengeType: 'http-01' -, keyType: 'rsa' // ecdsa -, keySize: 2048 // 256 +//, keyType: 'rsa' // ecdsa +//, keySize: 2048 // 256 +, rsaKeySize: 2048 // 256 }; Object.keys(module.exports.defaults).forEach(function (key) { module.exports.ACME[key] = module.exports.defaults[key]; diff --git a/node.js b/node.js index 7a6bca8..5964c44 100644 --- a/node.js +++ b/node.js @@ -452,6 +452,17 @@ ACME._getCertificate = function (me, options) { options.challengeTypes = [ options.challengeType ]; } + if (!me._kid) { + if (options.accountKid) { + me._kid = options.accountKid; + } else { + //return Promise.reject(new Error("must include KeyID")); + return ACME._registerAccount(me, options).then(function () { + return ACME._getCertificate(me, options); + }); + } + } + if (me.debug) { console.log('[acme-v2] certificates.create'); } return ACME._getNonce(me).then(function () { var body = { @@ -491,7 +502,9 @@ ACME._getCertificate = function (me, options) { //console.log('[DEBUG] finalize:', me._finalize); return; if (!me._authorizations) { - console.error("[acme-v2.js] authorizations were not fetched"); + console.error("[acme-v2.js] authorizations were not fetched:"); + console.error(resp.body); + return Promise.reject(new Error("authorizations were not fetched")); } if (me.debug) { console.log("47 &#&#&#&#&#&#&&##&#&#&#&#&#&#&#&"); } @@ -534,7 +547,10 @@ ACME._getCertificate = function (me, options) { return ACME._finalizeOrder(me, options, validatedDomains); }).then(function () { + console.log('acme-v2: order was finalized'); return me._request({ method: 'GET', url: me._certificate, json: true }).then(function (resp) { + console.log('acme-v2: csr submitted and cert received:'); + console.log(resp.body); return resp.body; }); }); @@ -544,6 +560,8 @@ ACME._getCertificate = function (me, options) { ACME.create = function create(me) { if (!me) { me = {}; } + // + me.debug = true; me.acmeChallengePrefix = ACME.acmeChallengePrefix; me.acmeChallengeDnsPrefix = ACME.acmeChallengeDnsPrefix; me.acmeChallengePrefixes = ACME.acmeChallengePrefixes;