mirror of
				https://github.com/therootcompany/greenlock.js.git
				synced 2024-11-16 17:29:00 +00:00 
			
		
		
		
	register multiple challenges
This commit is contained in:
		
							parent
							
								
									bb211e8f42
								
							
						
					
					
						commit
						9517980889
					
				| @ -122,7 +122,8 @@ function leAgree(opts, agreeCb) { | |||||||
| le = LE.create({ | le = LE.create({ | ||||||
|   server: LE.stagingServerUrl                             // or LE.productionServerUrl |   server: LE.stagingServerUrl                             // or LE.productionServerUrl | ||||||
| , store: leStore                                          // handles saving of config, accounts, and certificates | , store: leStore                                          // handles saving of config, accounts, and certificates | ||||||
| , challenge: leChallenge                                  // handles /.well-known/acme-challege keys and tokens | , challenges: { 'http-01': leChallenge }                  // handles /.well-known/acme-challege keys and tokens | ||||||
|  | , challengeType: 'http-01'                                // default to this challenge type | ||||||
| , agreeToTerms: leAgree                                   // hook to allow user to view and accept LE TOS | , agreeToTerms: leAgree                                   // hook to allow user to view and accept LE TOS | ||||||
| , debug: false | , debug: false | ||||||
| }); | }); | ||||||
| @ -132,7 +133,7 @@ le = LE.create({ | |||||||
| // app.use('/', le.middleware()); | // app.use('/', le.middleware()); | ||||||
| // | // | ||||||
| // Otherwise you should see the test file for usage of this: | // Otherwise you should see the test file for usage of this: | ||||||
| // le.challenge.get(opts.domain, key, val, done) | // le.challenges['http-01'].get(opts.domain, key, val, done) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -160,7 +161,7 @@ le.check({ domains: [ 'example.com' ] }).then(function (results) { | |||||||
|   }, function (err) { |   }, function (err) { | ||||||
| 
 | 
 | ||||||
|     // Note: you must either use le.middleware() with express, |     // Note: you must either use le.middleware() with express, | ||||||
|     // manually use le.challenge.get(opts, domain, key, val, done) |     // manually use le.challenges['http-01'].get(opts, domain, key, val, done) | ||||||
|     // or have a webserver running and responding |     // or have a webserver running and responding | ||||||
|     // to /.well-known/acme-challenge at `webrootPath` |     // to /.well-known/acme-challenge at `webrootPath` | ||||||
|     console.error('[Error]: node-letsencrypt/examples/standalone'); |     console.error('[Error]: node-letsencrypt/examples/standalone'); | ||||||
|  | |||||||
							
								
								
									
										51
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								index.js
									
									
									
									
									
								
							| @ -13,6 +13,7 @@ LE.defaults = { | |||||||
| 
 | 
 | ||||||
| , rsaKeySize: ACME.rsaKeySize || 2048 | , rsaKeySize: ACME.rsaKeySize || 2048 | ||||||
| , challengeType: ACME.challengeType || 'http-01' | , challengeType: ACME.challengeType || 'http-01' | ||||||
|  | , challengeTypes: ACME.challengeTypes || [ 'http-01', 'tls-sni-01', 'dns-01' ] | ||||||
| 
 | 
 | ||||||
| , acmeChallengePrefix: ACME.acmeChallengePrefix | , acmeChallengePrefix: ACME.acmeChallengePrefix | ||||||
| }; | }; | ||||||
| @ -28,6 +29,9 @@ LE._undefined = { | |||||||
|   acme: u |   acme: u | ||||||
| , store: u | , store: u | ||||||
| , challenge: u | , challenge: u | ||||||
|  | , challenges: u | ||||||
|  | , sni: u | ||||||
|  | , httpsOptions: u | ||||||
| 
 | 
 | ||||||
| , register: u | , register: u | ||||||
| , check: u | , check: u | ||||||
| @ -57,9 +61,29 @@ LE.create = function (le) { | |||||||
| 
 | 
 | ||||||
|   le.acme = le.acme || ACME.create({ debug: le.debug }); |   le.acme = le.acme || ACME.create({ debug: le.debug }); | ||||||
|   le.store = le.store || require('le-store-certbot').create({ debug: le.debug }); |   le.store = le.store || require('le-store-certbot').create({ debug: le.debug }); | ||||||
|   le.challenge = le.challenge || require('le-challenge-fs').create({ debug: le.debug }); |  | ||||||
|   le.core = require('./lib/core'); |   le.core = require('./lib/core'); | ||||||
| 
 | 
 | ||||||
|  |   if (!le.challenges) { | ||||||
|  |     le.challenges = {}; | ||||||
|  |   } | ||||||
|  |   if (!le.challenges['http-01']) { | ||||||
|  |     le.challenges['http-01'] = require('le-challenge-fs').create({ debug: le.debug }); | ||||||
|  |   } | ||||||
|  |   if (!le.challenges['tls-sni-01']) { | ||||||
|  |     le.challenges['tls-sni-01'] = le.challenges['http-01']; | ||||||
|  |   } | ||||||
|  |   if (!le.challenges['dns-01']) { | ||||||
|  |     try { | ||||||
|  |       le.challenges['dns-01'] = require('le-challenge-ddns').create({ debug: le.debug }); | ||||||
|  |     } catch(e) { | ||||||
|  |       try { | ||||||
|  |         le.challenges['dns-01'] = require('le-challenge-dns').create({ debug: le.debug }); | ||||||
|  |       } catch(e) { | ||||||
|  |         // not yet implemented
 | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   le = LE._undefine(le); |   le = LE._undefine(le); | ||||||
|   le.acmeChallengePrefix = LE.acmeChallengePrefix; |   le.acmeChallengePrefix = LE.acmeChallengePrefix; | ||||||
|   le.rsaKeySize = le.rsaKeySize || LE.rsaKeySize; |   le.rsaKeySize = le.rsaKeySize || LE.rsaKeySize; | ||||||
| @ -106,16 +130,33 @@ LE.create = function (le) { | |||||||
|     } |     } | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   if (le.challenge.create) { |   LE.challengeTypes.forEach(function (challengeType) { | ||||||
|     le.challenge = le.challenge.create(le); |     if (le.challenges[challengeType].create) { | ||||||
|  |       le.challenges[challengeType] = le.challenges[challengeType].create(le); | ||||||
|     } |     } | ||||||
|   le.challenge = PromiseA.promisifyAll(le.challenge); |     le.challenges[challengeType] = PromiseA.promisifyAll(le.challenges[challengeType]); | ||||||
|   le._challengeOpts = le.challenge.getOptions(); |     le['_challengeOpts_' + challengeType] = le.challenges[challengeType].getOptions(); | ||||||
|     Object.keys(le._challengeOpts).forEach(function (key) { |     Object.keys(le._challengeOpts).forEach(function (key) { | ||||||
|       if (!(key in le)) { |       if (!(key in le)) { | ||||||
|         le[key] = le._challengeOpts[key]; |         le[key] = le._challengeOpts[key]; | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Backwards compat until we fix le.challenges to be per-request
 | ||||||
|  |   //
 | ||||||
|  |   if (le.challenge) { | ||||||
|  |     console.warn("Deprecated use of le.challenge. Use le.challenges['" + LE.challengeType + "'] instead."); | ||||||
|  |     // TODO le.challenges[le.challengeType] = le.challenge
 | ||||||
|  |     if (le.challenge.create) { | ||||||
|  |       le.challenge = le.challenge.create(le); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   else { | ||||||
|  |     le.challenge = le.challenge[le.challengeType]; | ||||||
|  |   } | ||||||
|  |   le._challengeOpts = le.challenge.getOptions(); | ||||||
| 
 | 
 | ||||||
|   le.sni = le.sni || null; |   le.sni = le.sni || null; | ||||||
|   if (!le.httpsOptions) { |   if (!le.httpsOptions) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user