use supplied directoryUrl

This commit is contained in:
AJ ONeal 2018-03-21 01:33:54 -06:00
parent 92b494f535
commit e4beb3f04e
2 changed files with 59 additions and 12 deletions

15
node.js
View File

@ -61,10 +61,10 @@ function create(deps) {
var request = deps.promisify(getRequest({})); var request = deps.promisify(getRequest({}));
var acme2 = { var acme2 = {
getAcmeUrls: function () { getAcmeUrls: function (_directoryUrl) {
var me = this; var me = this;
return request({ url: directoryUrl }).then(function (resp) { return request({ url: _directoryUrl || directoryUrl, json: true }).then(function (resp) {
me._directoryUrls = JSON.parse(resp.body); me._directoryUrls = resp.body;
me._tos = me._directoryUrls.meta.termsOfService; me._tos = me._directoryUrls.meta.termsOfService;
return me._directoryUrls; return me._directoryUrls;
}); });
@ -206,14 +206,6 @@ function create(deps) {
var keyAuthorization = ch.token + '.' + thumbprint; var keyAuthorization = ch.token + '.' + thumbprint;
// keyAuthorization = token || '.' || base64url(JWK_Thumbprint(accountKey)) // keyAuthorization = token || '.' || base64url(JWK_Thumbprint(accountKey))
// /.well-known/acme-challenge/:token // /.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) { return new Promise(function (resolve, reject) {
if (options.setupChallenge) { if (options.setupChallenge) {
@ -426,7 +418,6 @@ function create(deps) {
var location = resp.toJSON().headers.location; var location = resp.toJSON().headers.location;
console.log(location); // the account id url console.log(location); // the account id url
console.log(resp.toJSON()); console.log(resp.toJSON());
//var body = JSON.parse(resp.body);
me._authorizations = resp.body.authorizations; me._authorizations = resp.body.authorizations;
me._order = location; me._order = location;
me._finalize = resp.body.finalize; me._finalize = resp.body.finalize;

56
test.js Normal file
View File

@ -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);
});
});
});