|
|
@ -1,82 +1,85 @@ |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
/* global Promise */ |
|
|
|
|
|
|
|
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); |
|
|
|
agreeToTerms: function (tosUrl) { |
|
|
|
return Promise.resolve(tosUrl); |
|
|
|
} |
|
|
|
, setChallenge: function (opts) { |
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
var pathname; |
|
|
|
|
|
|
|
console.log(""); |
|
|
|
console.log('identifier:'); |
|
|
|
console.log(opts.identifier); |
|
|
|
console.log('hostname:'); |
|
|
|
console.log(opts.hostname); |
|
|
|
console.log('type:'); |
|
|
|
console.log(opts.type); |
|
|
|
console.log('token:'); |
|
|
|
console.log(opts.token); |
|
|
|
console.log('thumbprint:'); |
|
|
|
console.log(opts.thumbprint); |
|
|
|
console.log('keyAuthorization:'); |
|
|
|
console.log(opts.keyAuthorization); |
|
|
|
console.log('dnsAuthorization:'); |
|
|
|
console.log(opts.dnsAuthorization); |
|
|
|
console.log(""); |
|
|
|
console.log(""); |
|
|
|
console.log('identifier:'); |
|
|
|
console.log(opts.identifier); |
|
|
|
console.log('hostname:'); |
|
|
|
console.log(opts.hostname); |
|
|
|
console.log('type:'); |
|
|
|
console.log(opts.type); |
|
|
|
console.log('token:'); |
|
|
|
console.log(opts.token); |
|
|
|
console.log('thumbprint:'); |
|
|
|
console.log(opts.thumbprint); |
|
|
|
console.log('keyAuthorization:'); |
|
|
|
console.log(opts.keyAuthorization); |
|
|
|
console.log('dnsAuthorization:'); |
|
|
|
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.replace(/^\*\./, '');; |
|
|
|
console.log("Put the string '" + opts.dnsAuthorization + "' into the TXT record '" + pathname + "'"); |
|
|
|
console.log("ddig TXT " + pathname + " '" + opts.dnsAuthorization + "'"); |
|
|
|
} else { |
|
|
|
reject(new Error("[acme-v2] unrecognized challenge type")); |
|
|
|
return; |
|
|
|
} |
|
|
|
console.log("\nThen hit the 'any' key to continue..."); |
|
|
|
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
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); |
|
|
|
|
|
|
|
resolve(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
process.stdin.setRawMode(true); |
|
|
|
process.stdin.resume(); |
|
|
|
process.stdin.on('data', onAny); |
|
|
|
}); |
|
|
|
} |
|
|
|
, removeChallenge: function (opts) { |
|
|
|
// hostname, key
|
|
|
|
console.log('[DEBUG] remove challenge', opts.hostname, opts.keyAuthorization); |
|
|
|
console.log("Remove the file '" + opts.hostname + "/" + opts.token + "'"); |
|
|
|
|
|
|
|
console.log('[acme-v2] remove challenge', opts.hostname, opts.keyAuthorization); |
|
|
|
return new Promise(function (resolve) { |
|
|
|
// hostname, key
|
|
|
|
setTimeout(resolve, 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); |
|
|
|
}); |
|
|
|
}); |
|
|
|