From e4beb3f04ed3a2493efedc060502ee64b598c78f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 21 Mar 2018 01:33:54 -0600 Subject: [PATCH] use supplied directoryUrl --- node.js | 15 +++------------ test.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 test.js diff --git a/node.js b/node.js index 2069281..f1c01e4 100644 --- a/node.js +++ b/node.js @@ -61,10 +61,10 @@ function create(deps) { var request = deps.promisify(getRequest({})); var acme2 = { - getAcmeUrls: function () { + getAcmeUrls: function (_directoryUrl) { var me = this; - return request({ url: directoryUrl }).then(function (resp) { - me._directoryUrls = JSON.parse(resp.body); + return request({ url: _directoryUrl || directoryUrl, json: true }).then(function (resp) { + me._directoryUrls = resp.body; me._tos = me._directoryUrls.meta.termsOfService; return me._directoryUrls; }); @@ -206,14 +206,6 @@ function create(deps) { var keyAuthorization = ch.token + '.' + thumbprint; // keyAuthorization = token || '.' || base64url(JWK_Thumbprint(accountKey)) // /.well-known/acme-challenge/:token - console.log('type:'); - console.log(ch.type); - console.log('ch.token:'); - console.log(ch.token); - console.log('thumbprint:'); - console.log(thumbprint); - console.log('keyAuthorization:'); - console.log(keyAuthorization); return new Promise(function (resolve, reject) { if (options.setupChallenge) { @@ -426,7 +418,6 @@ function create(deps) { var location = resp.toJSON().headers.location; console.log(location); // the account id url console.log(resp.toJSON()); - //var body = JSON.parse(resp.body); me._authorizations = resp.body.authorizations; me._order = location; me._finalize = resp.body.finalize; diff --git a/test.js b/test.js new file mode 100644 index 0000000..7c1f373 --- /dev/null +++ b/test.js @@ -0,0 +1,56 @@ +'use strict'; + +var RSA = require('rsa-compat').RSA; +var acme2 = require('./').ACME.create({ RSA: RSA }); + +acme2.getAcmeUrls(acme2.stagingServerUrl).then(function (body) { + console.log(body); + + var options = { + agreeToTerms: function (tosUrl, agree) { + agree(null, tosUrl); + } + /* + , setupChallenge: function (opts) { + console.log('type:'); + console.log(ch.type); + console.log('ch.token:'); + console.log(ch.token); + console.log('thumbprint:'); + console.log(thumbprint); + console.log('keyAuthorization:'); + console.log(keyAuthorization); + console.log('dnsAuthorization:'); + console.log(dnsAuthorization); + } + */ + // teardownChallenge + , setChallenge: function (hostname, key, val, cb) { + console.log('[DEBUG] set challenge', hostname, key, val); + console.log("You have 20 seconds to put the string '" + val + "' into a file at '" + hostname + "/" + key + "'"); + setTimeout(cb, 20 * 1000); + } + , removeChallenge: function (hostname, key, cb) { + console.log('[DEBUG] remove challenge', hostname, key); + setTimeout(cb, 1 * 1000); + } + , challengeType: 'http-01' + , email: 'coolaj86@gmail.com' + , accountKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/account.privkey.pem') }) + , domainKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/privkey.pem') }) + , domains: [ 'test.ppl.family' ] + }; + + acme2.registerNewAccount(options).then(function (account) { + console.log('account:'); + console.log(account); + + acme2.getCertificate(options, function (fullchainPem) { + console.log('[acme-v2] A fullchain.pem:'); + console.log(fullchainPem); + }).then(function (fullchainPem) { + console.log('[acme-v2] B fullchain.pem:'); + console.log(fullchainPem); + }); + }); +});