acme.js/examples/cli.js

69 lines
2.4 KiB
JavaScript
Raw Normal View History

// Copyright 2018 AJ ONeal. All rights reserved
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
2018-03-21 07:33:54 +00:00
'use strict';
var readline = require('readline');
2018-05-23 04:53:45 +00:00
var inquisitor = {};
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
2018-03-21 07:33:54 +00:00
2018-04-16 01:04:06 +00:00
require('./genkeypair.js');
2018-05-23 04:53:45 +00:00
inquisitor.getWeb = function getWeb() {
rl.question('What web address(es) would you like to get certificates for? (ex: example.com,*.example.com) ', function (web) {
web = (web||'').trim().split(/,/g);
2018-05-23 04:53:45 +00:00
if (!web[0]) { inquisitor.getWeb(); return; }
2018-03-21 07:33:54 +00:00
if (web.some(function (w) { return '*' === w[0]; })) {
console.log('Wildcard domains must use dns-01');
2018-05-23 04:53:45 +00:00
inquisitor.getEmail(web, 'dns-01');
} else {
2018-05-23 04:53:45 +00:00
inquisitor.getChallengeType(web);
2018-03-21 07:33:54 +00:00
}
});
2018-05-23 04:53:45 +00:00
};
2018-05-23 04:53:45 +00:00
inquisitor.getChallengeType = function getChallengeType(web) {
rl.question('What challenge will you be testing today? http-01 or dns-01? [http-01] ', function (chType) {
chType = (chType||'').trim();
if (!chType) { chType = 'http-01'; }
2018-05-23 04:53:45 +00:00
inquisitor.getEmail(web, chType);
});
2018-05-23 04:53:45 +00:00
};
2018-05-23 04:53:45 +00:00
inquisitor.getEmail = function getEmail(web, chType) {
rl.question('What email should we use? (optional) ', function (email) {
email = (email||'').trim();
if (!email) { email = null; }
2018-05-23 04:53:45 +00:00
inquisitor.getDirectoryUrl(web, chType, email);
2018-04-16 01:04:06 +00:00
});
2018-05-23 04:53:45 +00:00
};
2018-04-16 01:04:06 +00:00
2018-05-23 04:53:45 +00:00
inquisitor.getDirectoryUrl = function getDirectoryUrl(web, chType, email) {
var defaultDirectoryUrl = 'https://acme-staging-v02.api.letsencrypt.org/directory';
rl.question('What directoryUrl should we use? [' + defaultDirectoryUrl + '] ', function (directoryUrl) {
directoryUrl = (directoryUrl||'').trim();
if (!directoryUrl) { directoryUrl = 'https://acme-staging-v02.api.letsencrypt.org/directory'; }
2018-04-16 01:04:06 +00:00
2018-05-23 04:53:45 +00:00
inquisitor.run(directoryUrl, web, chType, email);
});
};
2018-04-16 01:04:06 +00:00
2018-05-23 04:53:45 +00:00
inquisitor.run = function run(directoryUrl, web, chType, email) {
rl.close();
2018-04-16 01:04:06 +00:00
2018-05-23 04:53:45 +00:00
var RSA = require('rsa-compat').RSA;
var accountKeypair = RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/../tests/account.privkey.pem') });
var domainKeypair = RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/../tests/privkey.pem') });
require('../tests/promise.js').run(directoryUrl, RSA, web, chType, email, accountKeypair, domainKeypair);
};
2018-05-23 04:53:45 +00:00
inquisitor.getWeb();