yay for test with callback options working

This commit is contained in:
AJ ONeal 2018-04-05 02:13:20 -06:00
parent fe5a48764b
commit ef0505ed69
4 changed files with 69 additions and 47 deletions

14
node.js
View File

@ -9,6 +9,11 @@
var ACME = module.exports.ACME = {};
ACME.acmeChallengePrefix = '/.well-known/acme-challenge/';
ACME.acmeChallengeDnsPrefix = '_acme-challenge';
ACME.acmeChallengePrefixes = {
'http-01': '/.well-known/acme-challenge/'
, 'dns-01': '_acme-challenge'
};
ACME._getUserAgentString = function (deps) {
var uaDefaults = {
@ -368,6 +373,7 @@ ACME._getCertificate = function (me, options) {
console.log('[acme-v2] certificates.create');
return ACME._getNonce(me).then(function () {
console.log("27 &#&#&#&#&#&#&&##&#&#&#&#&#&#&#&");
var body = {
identifiers: options.domains.map(function (hostname) {
return { type: "dns" , value: hostname };
@ -401,6 +407,11 @@ ACME._getCertificate = function (me, options) {
me._finalize = resp.body.finalize;
//console.log('[DEBUG] finalize:', me._finalize); return;
if (!me._authorizations) {
console.log("&#&#&#&#&#&#&&##&#&#&#&#&#&#&#&");
}
console.log("47 &#&#&#&#&#&#&&##&#&#&#&#&#&#&#&");
//return resp.body;
return Promise.all(me._authorizations.map(function (authUrl, i) {
console.log("Authorizations map #" + i);
@ -425,6 +436,7 @@ ACME._getCertificate = function (me, options) {
return ACME._postChallenge(me, options, results.identifier, challenge);
});
})).then(function () {
console.log("37 &#&#&#&#&#&#&&##&#&#&#&#&#&#&#&");
var validatedDomains = body.identifiers.map(function (ident) {
return ident.value;
});
@ -444,6 +456,8 @@ ACME._getCertificate = function (me, options) {
ACME.create = function create(me) {
if (!me) { me = {}; }
me.acmeChallengePrefix = ACME.acmeChallengePrefix;
me.acmeChallengeDnsPrefix = ACME.acmeChallengeDnsPrefix;
me.acmeChallengePrefixes = ACME.acmeChallengePrefixes;
me.RSA = me.RSA || require('rsa-compat').RSA;
me.request = me.request || require('request');
me.promisify = me.promisify || require('util').promisify;

View File

@ -1,21 +1,17 @@
'use strict';
module.exports.run = function run(web, chType, email) {
module.exports.run = function run(web, chType, email, accountKeypair, domainKeypair) {
var RSA = require('rsa-compat').RSA;
var directoryUrl = 'https://acme-staging-v02.api.letsencrypt.org/directory';
var acme2 = require('./compat').ACME.create({ RSA: RSA });
var acme2 = require('./').ACME.create({ RSA: RSA });
// [ 'test.ppl.family' ] 'coolaj86@gmail.com''http-01'
console.log(web, chType, email);
return;
acme2.init(directoryUrl).then(function (body) {
console.log(body);
return;
acme2.init(directoryUrl).then(function () {
var options = {
agreeToTerms: function (tosUrl, agree) {
agree(null, tosUrl);
}
, setChallenge: function (opts, cb) {
var pathname;
console.log("");
console.log('identifier:');
@ -34,40 +30,50 @@ module.exports.run = function run(web, chType, email) {
console.log(opts.dnsAuthorization);
console.log("");
console.log("Put the string '" + opts.keyAuthorization + "' into a file at '" + opts.hostname + "/" + opts.token + "'");
console.log("\nThen hit the 'any' key to continue (must be specifically the 'any' key)...");
if ('http-01' === opts.type) {
pathname = opts.hostname + acme2.acmeChallengePrefix + "/" + opts.token;
console.log("Put the string '" + opts.keyAuthorization + "' into a file at '" + pathname + "'");
console.log("echo '" + opts.keyAuthorization + "' > '" + pathname + "'");
} else if ('dns-01' === opts.type) {
pathname = acme2.acmeChallengeDnsPrefix + "." + opts.hostname;
console.log("Put the string '" + opts.dnsAuthorization + "' into the TXT record '" + pathname + "'");
console.log("ddig TXT " + pathname + " '" + opts.dnsAuthorization + "'");
} else {
cb(new Error("[acme-v2] unrecognized challenge type"));
return;
}
console.log("\nThen hit the 'any' key to continue...");
function onAny() {
console.log("'any' key was hit");
process.stdin.pause();
process.stdin.removeEventListener('data', onAny);
process.stdin.removeListener('data', onAny);
process.stdin.setRawMode(false);
cb();
}
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', onAny);
}
, removeChallenge: function (opts, cb) {
// hostname, key
console.log('[DEBUG] remove challenge', hostname, key);
console.log('[acme-v2] remove challenge', opts.hostname, opts.keyAuthorization);
setTimeout(cb, 1 * 1000);
}
, challengeType: chType
, email: email
, accountKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/account.privkey.pem') })
, domainKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/privkey.pem') })
, accountKeypair: accountKeypair
, domainKeypair: domainKeypair
, domains: web
};
acme2.registerNewAccount(options).then(function (account) {
console.log('account:');
acme2.accounts.create(options).then(function (account) {
console.log('[acme-v2] 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:');
acme2.certificates.create(options).then(function (fullchainPem) {
console.log('[acme-v2] fullchain.pem:');
console.log(fullchainPem);
});
});

View File

@ -2,22 +2,22 @@
var RSA = require('rsa-compat').RSA;
module.exports.run = function (web, chType, email) {
module.exports.run = function (web, chType, email, accountKeypair, domainKeypair) {
console.log('[DEBUG] run', web, chType, email);
var acme2 = require('./compat.js').ACME.create({ RSA: RSA });
acme2.getAcmeUrls(acme2.stagingServerUrl, function (err, body) {
acme2.getAcmeUrls(acme2.stagingServerUrl, function (err/*, directoryUrls*/) {
if (err) { console.log('err 1'); throw err; }
console.log(body);
var options = {
agreeToTerms: function (tosUrl, agree) {
agree(null, tosUrl);
}
, setChallenge: function (hostname, token, val, cb) {
console.log("Put the string '" + val + "' into a file at '" + hostname + "/" + acme2.acmeChallengePrefix + "/" + token + "'");
console.log("echo '" + val + "' > '" + hostname + "/" + acme2.acmeChallengePrefix + "/" + token + "'");
console.log("\nThen hit the 'any' key to continue (must be specifically the 'any' key)...");
var pathname = hostname + acme2.acmeChallengePrefix + "/" + token;
console.log("Put the string '" + val + "' into a file at '" + pathname + "'");
console.log("echo '" + val + "' > '" + pathname + "'");
console.log("\nThen hit the 'any' key to continue...");
function onAny() {
console.log("'any' key was hit");
@ -37,8 +37,8 @@ module.exports.run = function (web, chType, email) {
}
, challengeType: chType
, email: email
, accountKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/account.privkey.pem') })
, domainKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/privkey.pem') })
, accountKeypair: accountKeypair
, domainKeypair: domainKeypair
, domains: web
};

10
test.js
View File

@ -1,5 +1,6 @@
'use strict';
var RSA = require('rsa-compat').RSA;
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
@ -35,10 +36,11 @@ function getEmail(web, chType) {
if (!email) { email = null; }
rl.close();
console.log("[DEBUG] rl blah blah");
require('./test.compat.js').run(web, chType, email);
//require('./test.cb.js').run(web, chType, email);
//require('./test.promise.js').run(web, chType, email);
var accountKeypair = RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/account.privkey.pem') });
var domainKeypair = RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/privkey.pem') });
//require('./test.compat.js').run(web, chType, email, accountKeypair, domainKeypair);
require('./test.cb.js').run(web, chType, email, accountKeypair, domainKeypair);
//require('./test.promise.js').run(web, chType, email, accountKeypair, domainKeypair);
});
}