2018-12-17 04:19:20 +00:00
|
|
|
// 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';
|
|
|
|
|
2018-04-05 08:13:20 +00:00
|
|
|
var RSA = require('rsa-compat').RSA;
|
2018-04-05 07:31:57 +00:00
|
|
|
var readline = require('readline');
|
|
|
|
var rl = readline.createInterface({
|
2019-06-13 07:55:25 +00:00
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout
|
2018-04-05 07:31:57 +00:00
|
|
|
});
|
2018-03-21 07:33:54 +00:00
|
|
|
|
2018-04-16 01:04:06 +00:00
|
|
|
require('./genkeypair.js');
|
|
|
|
|
2018-04-05 07:31:57 +00:00
|
|
|
function getWeb() {
|
2019-06-13 07:55:25 +00:00
|
|
|
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);
|
|
|
|
if (!web[0]) {
|
|
|
|
getWeb();
|
|
|
|
return;
|
|
|
|
}
|
2018-03-21 07:33:54 +00:00
|
|
|
|
2019-06-13 07:55:25 +00:00
|
|
|
if (
|
|
|
|
web.some(function(w) {
|
|
|
|
return '*' === w[0];
|
|
|
|
})
|
|
|
|
) {
|
|
|
|
console.log('Wildcard domains must use dns-01');
|
|
|
|
getEmail(web, 'dns-01');
|
|
|
|
} else {
|
|
|
|
getChallengeType(web);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2018-04-05 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getChallengeType(web) {
|
2019-06-13 07:55:25 +00:00
|
|
|
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-04-05 07:31:57 +00:00
|
|
|
|
2019-06-13 07:55:25 +00:00
|
|
|
getEmail(web, chType);
|
|
|
|
}
|
|
|
|
);
|
2018-04-05 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getEmail(web, chType) {
|
2019-06-13 07:55:25 +00:00
|
|
|
rl.question('What email should we use? (optional) ', function(email) {
|
|
|
|
email = (email || '').trim();
|
|
|
|
if (!email) {
|
|
|
|
email = null;
|
|
|
|
}
|
2018-04-05 07:31:57 +00:00
|
|
|
|
2019-06-13 07:55:25 +00:00
|
|
|
getApiStyle(web, chType, email);
|
|
|
|
});
|
2018-04-16 01:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getApiStyle(web, chType, email) {
|
2019-06-13 07:55:25 +00:00
|
|
|
var defaultStyle = 'compat';
|
|
|
|
rl.question(
|
|
|
|
'What API style would you like to test? v1-compat or promise? [v1-compat] ',
|
|
|
|
function(apiStyle) {
|
|
|
|
apiStyle = (apiStyle || '').trim();
|
|
|
|
if (!apiStyle) {
|
|
|
|
apiStyle = 'v1-compat';
|
|
|
|
}
|
2018-04-16 01:04:06 +00:00
|
|
|
|
2019-06-13 07:55:25 +00:00
|
|
|
rl.close();
|
2018-04-16 01:04:06 +00:00
|
|
|
|
2019-06-13 07:55:25 +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'
|
|
|
|
)
|
|
|
|
});
|
|
|
|
var directoryUrl =
|
|
|
|
'https://acme-staging-v02.api.letsencrypt.org/directory';
|
2018-04-16 01:04:06 +00:00
|
|
|
|
2019-06-13 07:55:25 +00:00
|
|
|
if ('promise' === apiStyle) {
|
|
|
|
require('../tests/promise.js').run(
|
|
|
|
directoryUrl,
|
|
|
|
RSA,
|
|
|
|
web,
|
|
|
|
chType,
|
|
|
|
email,
|
|
|
|
accountKeypair,
|
|
|
|
domainKeypair
|
|
|
|
);
|
|
|
|
} else if ('cb' === apiStyle) {
|
|
|
|
require('../tests/cb.js').run(
|
|
|
|
directoryUrl,
|
|
|
|
RSA,
|
|
|
|
web,
|
|
|
|
chType,
|
|
|
|
email,
|
|
|
|
accountKeypair,
|
|
|
|
domainKeypair
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
if ('v1-compat' !== apiStyle) {
|
|
|
|
console.warn(
|
|
|
|
"Didn't understand '" + apiStyle + "', using 'v1-compat' instead..."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
require('../tests/compat.js').run(
|
|
|
|
directoryUrl,
|
|
|
|
RSA,
|
|
|
|
web,
|
|
|
|
chType,
|
|
|
|
email,
|
|
|
|
accountKeypair,
|
|
|
|
domainKeypair
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2018-04-05 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getWeb();
|