| 
									
										
										
										
											2016-09-07 14:58:25 -06:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var Challenge = module.exports; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:08:21 -06:00
										 |  |  | Challenge.create = function (defaults) { | 
					
						
							| 
									
										
										
										
											2017-04-19 16:51:48 -05:00
										 |  |  |   return { | 
					
						
							| 
									
										
										
										
											2016-10-14 20:08:21 -06:00
										 |  |  |     getOptions: function () { | 
					
						
							|  |  |  |       return defaults || {}; | 
					
						
							| 
									
										
										
										
											2016-09-07 14:58:25 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:08:21 -06:00
										 |  |  |   , set: Challenge.set | 
					
						
							|  |  |  |   , get: Challenge.get | 
					
						
							|  |  |  |   , remove: Challenge.remove | 
					
						
							|  |  |  |   , loopback: Challenge.loopback | 
					
						
							|  |  |  |   , test: Challenge.test | 
					
						
							| 
									
										
										
										
											2016-09-07 14:58:25 -06:00
										 |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:08:21 -06:00
										 |  |  | // Show the user the token and key and wait for them to be ready to continue
 | 
					
						
							|  |  |  | Challenge.set = function (args, domain, challenge, keyAuthorization, cb) { | 
					
						
							| 
									
										
										
										
											2016-09-15 00:51:29 -06:00
										 |  |  |   var keyAuthDigest = require('crypto').createHash('sha256').update(keyAuthorization||'').digest('base64') | 
					
						
							|  |  |  |     .replace(/\+/g, '-') | 
					
						
							|  |  |  |     .replace(/\//g, '_') | 
					
						
							|  |  |  |     .replace(/=+$/g, '') | 
					
						
							|  |  |  |     ; | 
					
						
							| 
									
										
										
										
											2017-06-19 15:44:55 -07:00
										 |  |  |   var challengeDomain = domain; | 
					
						
							| 
									
										
										
										
											2016-10-14 20:08:21 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 15:44:55 -07:00
										 |  |  |   if (this.leDnsResponse) { | 
					
						
							|  |  |  |       this.leDnsResponse(challenge, keyAuthorization, keyAuthDigest, challengeDomain, domain) | 
					
						
							| 
									
										
										
										
											2018-05-12 19:17:26 -06:00
										 |  |  |       .then(function (/*successMessage*/) { | 
					
						
							| 
									
										
										
										
											2017-06-19 15:44:55 -07:00
										 |  |  |           cb(null); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     console.info(""); | 
					
						
							|  |  |  |     console.info("Challenge for '" + domain + "'"); | 
					
						
							|  |  |  |     console.info(""); | 
					
						
							|  |  |  |     console.info("We now present (for you copy-and-paste pleasure) your ACME Challenge"); | 
					
						
							|  |  |  |     console.info("public Challenge and secret KeyAuthorization and Digest, in that order, respectively:"); | 
					
						
							|  |  |  |     console.info(challenge); | 
					
						
							|  |  |  |     console.info(keyAuthorization); | 
					
						
							|  |  |  |     console.info(keyAuthDigest); | 
					
						
							|  |  |  |     console.info(""); | 
					
						
							|  |  |  |     console.info(challengeDomain + "\tTXT " + keyAuthDigest + "\tTTL 60"); | 
					
						
							|  |  |  |     console.info(""); | 
					
						
							|  |  |  |     console.info(JSON.stringify({ | 
					
						
							|  |  |  |       domain: domain | 
					
						
							|  |  |  |     , challenge: challenge | 
					
						
							|  |  |  |     , keyAuthorization: keyAuthorization | 
					
						
							|  |  |  |     , keyAuthDigest: keyAuthDigest | 
					
						
							|  |  |  |     }, null, '  ').replace(/^/gm, '\t')); | 
					
						
							|  |  |  |     console.info(""); | 
					
						
							|  |  |  |     console.info("hit enter to continue..."); | 
					
						
							|  |  |  |     process.stdin.resume(); | 
					
						
							|  |  |  |     process.stdin.on('data', function () { | 
					
						
							|  |  |  |       process.stdin.pause(); | 
					
						
							|  |  |  |       cb(null); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-09-07 14:58:25 -06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:08:21 -06:00
										 |  |  | // nothing to do here, that's why it's manual
 | 
					
						
							|  |  |  | Challenge.get = function (defaults, domain, challenge, cb) { | 
					
						
							|  |  |  |   cb(null); | 
					
						
							| 
									
										
										
										
											2016-09-07 14:58:25 -06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:08:21 -06:00
										 |  |  | // might as well tell the user that whatever they were setting up has been checked
 | 
					
						
							|  |  |  | Challenge.remove = function (args, domain, challenge, cb) { | 
					
						
							| 
									
										
										
										
											2017-06-21 14:55:19 -07:00
										 |  |  |     console.info("Challenge for '" + domain + "' complete. You may remove it."); | 
					
						
							| 
									
										
										
										
											2016-10-14 20:08:21 -06:00
										 |  |  |     cb(null); | 
					
						
							|  |  |  |   //});
 | 
					
						
							| 
									
										
										
										
											2016-09-07 14:58:25 -06:00
										 |  |  | }; |