| 
									
										
										
										
											2018-12-16 21:19:20 -07: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-04-05 01:31:57 -06:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2018-07-04 00:10:43 -06:00
										 |  |  | /* global Promise */ | 
					
						
							| 
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | var ACME2 = require('./').ACME; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function resolveFn(cb) { | 
					
						
							|  |  |  |   return function (val) { | 
					
						
							|  |  |  |     // nextTick to get out of Promise chain
 | 
					
						
							|  |  |  |     process.nextTick(function () { cb(null, val); }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function rejectFn(cb) { | 
					
						
							|  |  |  |   return function (err) { | 
					
						
							| 
									
										
										
										
											2018-04-11 18:03:40 +00:00
										 |  |  |     console.error('[acme-v2] handled(?) rejection as errback:'); | 
					
						
							|  |  |  |     console.error(err.stack); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 |  |  |     // nextTick to get out of Promise chain
 | 
					
						
							|  |  |  |     process.nextTick(function () { cb(err); }); | 
					
						
							| 
									
										
										
										
											2018-04-11 18:03:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // do not resolve promise further
 | 
					
						
							|  |  |  |     return new Promise(function () {}); | 
					
						
							| 
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function create(deps) { | 
					
						
							|  |  |  |   deps.LeCore = {}; | 
					
						
							|  |  |  |   var acme2 = ACME2.create(deps); | 
					
						
							|  |  |  |   acme2.registerNewAccount = function (options, cb) { | 
					
						
							|  |  |  |     acme2.accounts.create(options).then(resolveFn(cb), rejectFn(cb)); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   acme2.getCertificate = function (options, cb) { | 
					
						
							| 
									
										
										
										
											2018-04-11 07:22:42 +00:00
										 |  |  |     options.agreeToTerms = options.agreeToTerms || function (tos) { | 
					
						
							|  |  |  |       return Promise.resolve(tos); | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2018-07-04 00:10:43 -06:00
										 |  |  |     acme2.certificates.create(options).then(function (certs) { | 
					
						
							| 
									
										
										
										
											2018-04-11 07:22:42 +00:00
										 |  |  |       var privkeyPem = acme2.RSA.exportPrivatePem(options.domainKeypair); | 
					
						
							| 
									
										
										
										
											2018-07-04 00:10:43 -06:00
										 |  |  |       certs.privkey = privkeyPem; | 
					
						
							|  |  |  |       resolveFn(cb)(certs); | 
					
						
							| 
									
										
										
										
											2018-04-11 07:22:42 +00:00
										 |  |  |     }, rejectFn(cb)); | 
					
						
							| 
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 |  |  |   }; | 
					
						
							|  |  |  |   acme2.getAcmeUrls = function (options, cb) { | 
					
						
							|  |  |  |     acme2.init(options).then(resolveFn(cb), rejectFn(cb)); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-04-11 07:22:42 +00:00
										 |  |  |   acme2.getOptions = function () { | 
					
						
							|  |  |  |     var defs = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Object.keys(module.exports.defaults).forEach(function (key) { | 
					
						
							|  |  |  |       defs[key] = defs[deps] || module.exports.defaults[key]; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return defs; | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 |  |  |   acme2.stagingServerUrl = module.exports.defaults.stagingServerUrl; | 
					
						
							|  |  |  |   acme2.productionServerUrl = module.exports.defaults.productionServerUrl; | 
					
						
							| 
									
										
										
										
											2018-04-11 17:34:18 +00:00
										 |  |  |   acme2.acmeChallengePrefix = module.exports.defaults.acmeChallengePrefix; | 
					
						
							| 
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 |  |  |   return acme2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports.ACME = { }; | 
					
						
							|  |  |  | module.exports.defaults = { | 
					
						
							|  |  |  |   productionServerUrl:    'https://acme-v02.api.letsencrypt.org/directory' | 
					
						
							|  |  |  | , stagingServerUrl:       'https://acme-staging-v02.api.letsencrypt.org/directory' | 
					
						
							|  |  |  | , knownEndpoints:         [ 'keyChange', 'meta', 'newAccount', 'newNonce', 'newOrder', 'revokeCert' ] | 
					
						
							|  |  |  | , challengeTypes:         [ 'http-01', 'dns-01' ] | 
					
						
							|  |  |  | , challengeType:          'http-01' | 
					
						
							| 
									
										
										
										
											2018-04-11 07:22:42 +00:00
										 |  |  | //, keyType:                'rsa' // ecdsa
 | 
					
						
							|  |  |  | //, keySize:                2048 // 256
 | 
					
						
							|  |  |  | , rsaKeySize:             2048 // 256
 | 
					
						
							| 
									
										
										
										
											2018-04-13 23:23:08 +00:00
										 |  |  | , acmeChallengePrefix:    '/.well-known/acme-challenge/' | 
					
						
							| 
									
										
										
										
											2018-04-05 01:31:57 -06:00
										 |  |  | }; | 
					
						
							|  |  |  | Object.keys(module.exports.defaults).forEach(function (key) { | 
					
						
							|  |  |  |   module.exports.ACME[key] = module.exports.defaults[key]; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | Object.keys(ACME2).forEach(function (key) { | 
					
						
							|  |  |  |   module.exports.ACME[key] = ACME2[key]; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2018-04-11 17:34:18 +00:00
										 |  |  | module.exports.ACME.create = create; |