2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								'use strict';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-16 01:04:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								module.exports.run = function run(directoryUrl, RSA, web, chType, email, accountKeypair, domainKeypair) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  // [ 'test.ppl.family' ] 'coolaj86@gmail.com''http-01'
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-16 01:04:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  var acme2 = require('../').ACME.create({ RSA: RSA });
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  acme2.init(directoryUrl).then(function () {
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    var options = {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      agreeToTerms: function (tosUrl, agree) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        agree(null, tosUrl);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , setChallenge: function (opts, cb) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        var pathname;
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        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("");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if ('http-01' === opts.type) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-11 17:34:18 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          pathname = opts.hostname + acme2.challengePrefixes['http-01'] + "/" + opts.token;
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          console.log("Put the string '" + opts.keyAuthorization + "' into a file at '" + pathname + "'");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          console.log("echo '" + opts.keyAuthorization + "' > '" + pathname + "'");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else if ('dns-01' === opts.type) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-11 17:34:18 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          pathname = acme2.challengePrefixes['dns-01'] + "." + opts.hostname.replace(/^\*\./, '');
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          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...");
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        function onAny() {
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          console.log("'any' key was hit");
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          process.stdin.pause();
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          process.stdin.removeListener('data', onAny);
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          process.stdin.setRawMode(false);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          cb();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        process.stdin.setRawMode(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        process.stdin.resume();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        process.stdin.on('data', onAny);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , removeChallenge: function (opts, cb) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // hostname, key
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        console.log('[acme-v2] remove challenge', opts.hostname, opts.keyAuthorization);
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setTimeout(cb, 1 * 1000);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , challengeType: chType
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , email: email
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    , accountKeypair: accountKeypair
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , domainKeypair: domainKeypair
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , domains: web
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    acme2.accounts.create(options).then(function (account) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      console.log('[acme-v2] account:');
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      console.log(account);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 02:13:20 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      acme2.certificates.create(options).then(function (fullchainPem) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        console.log('[acme-v2] fullchain.pem:');
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        console.log(fullchainPem);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 |