From c44935e7df14e286fd38778a7046a5a288509dbf Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 15 Dec 2015 13:11:19 +0000 Subject: [PATCH] more working --- backends/ursa.js | 20 ++++++++++++++++---- lib/crypto-utils-ursa.js | 6 +++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/backends/ursa.js b/backends/ursa.js index e4ef705..2798dbd 100644 --- a/backends/ursa.js +++ b/backends/ursa.js @@ -22,14 +22,26 @@ function getAcmeUrls(args) { return requestAsync({ url: args.server - }).then(function (data) { + }).then(function (resp) { + var data = resp.body; + + if ('string' === typeof data) { + try { + data = JSON.parse(data); + } catch(e) { + return PromiseA.reject(e); + } + } + 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); } ipc.acmeUrlsUpdatedAt = Date.now(); @@ -56,7 +68,7 @@ function createAccount(args, handlers) { return lef.registerNewAccountAsync({ email: args.email - , newReg: args.server + , newReg: args._acmeUrls.newReg , debug: args.debug || handlers.debug , agreeToTerms: function (tosUrl, agree) { // args.email = email; // already there @@ -173,7 +185,7 @@ module.exports.create = function (defaults, handlers) { args.renewalDir = args.renewalDir || path.join(configDir, 'renewal', args.domains[0] + '.conf'); args.accountsDir = args.accountsDir || path.join(configDir, 'accounts', acmeHostname, 'directory'); - pyconf.readFileAsync(args.renewalDir).then(function (renewal) { + return pyconf.readFileAsync(args.renewalDir).then(function (renewal) { return renewal.account; }, function (err) { if ("EENOENT" === err.code) { @@ -189,7 +201,7 @@ module.exports.create = function (defaults, handlers) { if (accountId) { return getAccount(accountId, args, handlers); } else { - return createAccount(args); + return createAccount(args, handlers); } }); }).then(function (account) { diff --git a/lib/crypto-utils-ursa.js b/lib/crypto-utils-ursa.js index c5ed3e2..f9e9de6 100644 --- a/lib/crypto-utils-ursa.js +++ b/lib/crypto-utils-ursa.js @@ -27,8 +27,8 @@ function toAcmePrivateKey(privkeyPem) { function generateRsaKeypair(bitlen, exp, cb) { var keypair = ursa.generatePrivateKey(bitlen /*|| 2048*/, exp /*65537*/); var pems = { - publicKeyPem: keypair.toPublicPem() // ascii PEM: ----BEGIN... - , privateKeyPem: keypair.toPrivatePem() // ascii PEM: ----BEGIN... + publicKeyPem: keypair.toPublicPem().toString('ascii') // ascii PEM: ----BEGIN... + , privateKeyPem: keypair.toPrivatePem().toString('ascii') // ascii PEM: ----BEGIN... }; // I would have chosen sha1 or sha2... but whatever @@ -67,7 +67,7 @@ function parseAccountPrivateKey(pkj, cb) { cb(null, { privateKeyPem: priv.toPrivatePem.toString('ascii') - , publicKeyPem: priv.toPrivatePem.toString('ascii') + , publicKeyPem: priv.toPublicPem.toString('ascii') }); }