2018-04-05 07:31:57 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-04-16 01:04:06 +00:00
|
|
|
module.exports.run = function (directoryUrl, RSA, web, chType, email, accountKeypair, domainKeypair) {
|
2018-04-05 07:31:57 +00:00
|
|
|
console.log('[DEBUG] run', web, chType, email);
|
|
|
|
|
2018-04-16 01:04:06 +00:00
|
|
|
var acme2 = require('../compat.js').ACME.create({ RSA: RSA });
|
2018-04-05 08:13:20 +00:00
|
|
|
acme2.getAcmeUrls(acme2.stagingServerUrl, function (err/*, directoryUrls*/) {
|
2018-04-05 07:31:57 +00:00
|
|
|
if (err) { console.log('err 1'); throw err; }
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
agreeToTerms: function (tosUrl, agree) {
|
|
|
|
agree(null, tosUrl);
|
|
|
|
}
|
|
|
|
, setChallenge: function (hostname, token, val, cb) {
|
2018-04-05 11:44:02 +00:00
|
|
|
var pathname = hostname + acme2.acmeChallengePrefix + token;
|
2018-04-05 08:13:20 +00:00
|
|
|
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...");
|
2018-04-05 07:31:57 +00:00
|
|
|
|
|
|
|
function onAny() {
|
|
|
|
console.log("'any' key was hit");
|
|
|
|
process.stdin.pause();
|
|
|
|
process.stdin.removeListener('data', onAny);
|
|
|
|
process.stdin.setRawMode(false);
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
process.stdin.setRawMode(true);
|
|
|
|
process.stdin.resume();
|
|
|
|
process.stdin.on('data', onAny);
|
|
|
|
}
|
|
|
|
, removeChallenge: function (hostname, key, cb) {
|
|
|
|
console.log('[DEBUG] remove challenge', hostname, key);
|
|
|
|
setTimeout(cb, 1 * 1000);
|
|
|
|
}
|
|
|
|
, challengeType: chType
|
|
|
|
, email: email
|
2018-04-05 08:13:20 +00:00
|
|
|
, accountKeypair: accountKeypair
|
|
|
|
, domainKeypair: domainKeypair
|
2018-04-05 07:31:57 +00:00
|
|
|
, domains: web
|
|
|
|
};
|
|
|
|
|
|
|
|
acme2.registerNewAccount(options, function (err, account) {
|
|
|
|
if (err) { console.log('err 2'); throw err; }
|
2018-04-16 01:04:06 +00:00
|
|
|
if (options.debug) console.debug('account:');
|
|
|
|
if (options.debug) console.log(account);
|
2018-04-05 07:31:57 +00:00
|
|
|
|
|
|
|
acme2.getCertificate(options, function (err, fullchainPem) {
|
|
|
|
if (err) { console.log('err 3'); throw err; }
|
|
|
|
console.log('[acme-v2] A fullchain.pem:');
|
|
|
|
console.log(fullchainPem);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|