Compare commits
	
		
			8 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 58887c8086 | |||
| 
						 | 
					50ca48230d | ||
| 
						 | 
					85d9547b4d | ||
| b65fd583d8 | |||
| 
						 | 
					6487df49f9 | ||
| 
						 | 
					bd4f99d34a | ||
| 
						 | 
					c30847e388 | ||
| 
						 | 
					177c27ea43 | 
							
								
								
									
										5
									
								
								.github/ISSUE_TEMPLATE.md
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								.github/ISSUE_TEMPLATE.md
									
									
									
									
										vendored
									
									
								
							@ -2,10 +2,11 @@
 | 
			
		||||
ATTENTION!
 | 
			
		||||
==========
 | 
			
		||||
 | 
			
		||||
Please report issues at https://github.com/Daplie/letsencrypt-express
 | 
			
		||||
Please report issues at https://git.coolaj86.com/coolaj86/greenlock-express.js
 | 
			
		||||
 | 
			
		||||
========
 | 
			
		||||
ACHTUNG!
 | 
			
		||||
========
 | 
			
		||||
 | 
			
		||||
Bitte melden Sie Probleme bei https://github.com/Daplie/letsencrypt-express
 | 
			
		||||
Bitte melden Sie Probleme bei
 | 
			
		||||
https://git.coolaj86.com/coolaj86/greenlock-express.js
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										31
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								LICENSE
									
									
									
									
									
								
							@ -1,3 +1,32 @@
 | 
			
		||||
At your option you may choose either of the following licenses:
 | 
			
		||||
 | 
			
		||||
  * The MIT License (MIT)
 | 
			
		||||
  * The Apache License 2.0 (Apache-2.0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
The MIT License (MIT)
 | 
			
		||||
 | 
			
		||||
Copyright (c) 2016-2018 AJ ONeal
 | 
			
		||||
 | 
			
		||||
Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
in the Software without restriction, including without limitation the rights
 | 
			
		||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
furnished to do so, subject to the following conditions:
 | 
			
		||||
 | 
			
		||||
The above copyright notice and this permission notice shall be included in all
 | 
			
		||||
copies or substantial portions of the Software.
 | 
			
		||||
 | 
			
		||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 | 
			
		||||
SOFTWARE.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                                 Apache License
 | 
			
		||||
                           Version 2.0, January 2004
 | 
			
		||||
                        http://www.apache.org/licenses/
 | 
			
		||||
@ -186,7 +215,7 @@
 | 
			
		||||
      same "printed page" as the copyright notice for easier
 | 
			
		||||
      identification within third-party archives.
 | 
			
		||||
 | 
			
		||||
   Copyright {yyyy} {name of copyright owner}
 | 
			
		||||
   Copyright 2015 AJ ONeal
 | 
			
		||||
 | 
			
		||||
   Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
   you may not use this file except in compliance with the License.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										157
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										157
									
								
								README.md
									
									
									
									
									
								
							@ -1,94 +1,76 @@
 | 
			
		||||
<!-- BANNER_TPL_BEGIN -->
 | 
			
		||||
# Greenlock™ for hapi
 | 
			
		||||
 | 
			
		||||
About Daplie: We're taking back the Internet!
 | 
			
		||||
--------------
 | 
			
		||||
An Automated HTTPS ACME client (Let's Encrypt v2) for hapi
 | 
			
		||||
 | 
			
		||||
Down with Google, Apple, and Facebook!
 | 
			
		||||
| Sponsered by [ppl](https://ppl.family)
 | 
			
		||||
| Greenlock™ is for
 | 
			
		||||
[Browsers](https://git.coolaj86.com/coolaj86/greenlock.html),
 | 
			
		||||
[Node.js](https://git.coolaj86.com/coolaj86/greenlock.js),
 | 
			
		||||
[Commandline](https://git.coolaj86.com/coolaj86/greenlock-cli.js),
 | 
			
		||||
[Express.js](https://git.coolaj86.com/coolaj86/greenlock-express.js),
 | 
			
		||||
[Node.js Cluster](https://git.coolaj86.com/coolaj86/greenlock-cluster.js),
 | 
			
		||||
**hapi**,
 | 
			
		||||
[Koa](https://git.coolaj86.com/coolaj86/greenlock-koa.js),
 | 
			
		||||
and [rill](https://git.coolaj86.com/coolaj86/greenlock-rill.js) |
 | 
			
		||||
 | 
			
		||||
We're re-decentralizing the web and making it read-write again - one home cloud system at a time.
 | 
			
		||||
Features
 | 
			
		||||
========
 | 
			
		||||
 | 
			
		||||
Tired of serving the Empire? Come join the Rebel Alliance:
 | 
			
		||||
  * [x] Automatic Registration via SNI (`httpsOptions.SNICallback`)
 | 
			
		||||
  * [x] Secure domain approval callback
 | 
			
		||||
  * [x] Automatic renewal between 10 and 14 days before expiration
 | 
			
		||||
  * [x] Virtual Hosting (vhost) with Multiple Domains & SAN
 | 
			
		||||
  * [x] plugins for AWS, redis, etc
 | 
			
		||||
  * [x] and [more](https://git.coolaj86.com/coolaj86/greenlock-express.js)
 | 
			
		||||
 | 
			
		||||
<a href="mailto:jobs@daplie.com">jobs@daplie.com</a> | [Invest in Daplie on Wefunder](https://daplie.com/invest/) | [Pre-order Cloud](https://daplie.com/preorder/), The World's First Home Server for Everyone
 | 
			
		||||
This module is just an alias for greenlock-express.js,
 | 
			
		||||
which works with any middleware system.
 | 
			
		||||
 | 
			
		||||
<!-- BANNER_TPL_END -->
 | 
			
		||||
 | 
			
		||||
# greenlock-hapi (letsencrypt-hapi)
 | 
			
		||||
 | 
			
		||||
[](https://gitter.im/Daplie/letsencrypt-express?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
 | 
			
		||||
 | 
			
		||||
| [greenlock (lib)](https://git.daplie.com/Daplie/node-greenlock)
 | 
			
		||||
| [greenlock-cli](https://git.daplie.com/Daplie/greenlock-cli) 
 | 
			
		||||
| [greenlock-express](https://git.daplie.com/Daplie/greenlock-express)
 | 
			
		||||
| [greenlock-cluster](https://git.daplie.com/Daplie/greenlock-cluster)
 | 
			
		||||
| [greenlock-koa](https://git.daplie.com/Daplie/greenlock-koa)
 | 
			
		||||
| **greenlock-hapi**
 | 
			
		||||
|
 | 
			
		||||
 | 
			
		||||
Free SSL and Automatic HTTPS for node.js with hapi.js and other middleware systems via Let's Encrypt
 | 
			
		||||
 | 
			
		||||
* Automatic Registration via SNI (`httpsOptions.SNICallback`)
 | 
			
		||||
  * **registrations** require an **approval callback** in *production*
 | 
			
		||||
* Automatic Renewal (around 80 days)
 | 
			
		||||
  * **renewals** are *fully automatic* and happen in the *background*, with **no downtime**
 | 
			
		||||
* Automatic vhost / virtual hosting
 | 
			
		||||
 | 
			
		||||
All you have to do is start the webserver and then visit it at it's domain name.
 | 
			
		||||
 | 
			
		||||
## Install
 | 
			
		||||
Install
 | 
			
		||||
=======
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
npm install --save greenlock-express@2.x
 | 
			
		||||
npm install --save greenlock-hapi@2.x
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
*Pay no attention to the man behind the curtain.* (just ignore that the name of the module is greenlock-express)
 | 
			
		||||
 | 
			
		||||
### Part 1: Configure Greenlock
 | 
			
		||||
QuickStart
 | 
			
		||||
==========
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
'use strict';
 | 
			
		||||
 | 
			
		||||
var le = require('greenlock-express').create({
 | 
			
		||||
  server: 'staging' // in production use https://acme-v01.api.letsencrypt.org/directory
 | 
			
		||||
  
 | 
			
		||||
, configDir: require('os').homedir() + '/letsencrypt/etc'
 | 
			
		||||
  
 | 
			
		||||
, approveDomains: function (opts, certs, cb) {
 | 
			
		||||
    opts.domains = certs && certs.altnames || opts.domains;
 | 
			
		||||
    opts.email = 'john.doe@example.com' // CHANGE ME
 | 
			
		||||
    opts.agreeTos = true;
 | 
			
		||||
    
 | 
			
		||||
    cb(null, { options: opts, certs: certs });
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
 , debug: true
 | 
			
		||||
//////////////////////
 | 
			
		||||
// Greenlock Setup  //
 | 
			
		||||
//////////////////////
 | 
			
		||||
 | 
			
		||||
var greenlock = require('greenlock-hapi').create({
 | 
			
		||||
  version: 'draft-11' // Let's Encrypt v2
 | 
			
		||||
  // You MUST change this to 'https://acme-v02.api.letsencrypt.org/directory' in production
 | 
			
		||||
, server: 'https://acme-staging-v02.api.letsencrypt.org/directory'
 | 
			
		||||
 | 
			
		||||
, email: 'jon@example.com'
 | 
			
		||||
, agreeTos: true
 | 
			
		||||
, approveDomains: [ 'example.com' ]
 | 
			
		||||
 | 
			
		||||
  // Join the community to get notified of important updates
 | 
			
		||||
  // and help make greenlock better
 | 
			
		||||
, communityMember: true
 | 
			
		||||
 | 
			
		||||
, configDir: require('os').homedir() + '/acme/etc'
 | 
			
		||||
 | 
			
		||||
//, debug: true
 | 
			
		||||
});
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
WARNING: If you don't do any checks and simply complete `approveDomains` callback,
 | 
			
		||||
an attacker will spoof SNI packets with bad hostnames and that will cause you to be rate-limited
 | 
			
		||||
and/or blocked from the ACME server.
 | 
			
		||||
Alternatively, You can run registration *manually*:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
npm install -g greenlock-cli
 | 
			
		||||
///////////////////
 | 
			
		||||
// Just add hapi //
 | 
			
		||||
///////////////////
 | 
			
		||||
 | 
			
		||||
greenlock certonly --standalone \
 | 
			
		||||
  --server 'https://acme-v01.api.letsencrypt.org/directory' \
 | 
			
		||||
  --config-dir ~/letsencrypt/etc \
 | 
			
		||||
  --agree-tos --domains example.com --email user@example.com
 | 
			
		||||
 | 
			
		||||
# Note: the '--webrootPath' option is also available if you don't want to shut down your webserver to get the cert.
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Part 2: Just add Hapi
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
var hapi = require('hapi');
 | 
			
		||||
var https = require('spdy');
 | 
			
		||||
var https = require('https');
 | 
			
		||||
var server = new hapi.Server();
 | 
			
		||||
var acmeResponder = le.middleware();
 | 
			
		||||
var httpsServer = https.createServer(le.httpsOptions).listen(443);
 | 
			
		||||
var acmeResponder = greenlock.middleware();
 | 
			
		||||
var httpsServer = https.createServer(greenlock.httpsOptions).listen(443);
 | 
			
		||||
 | 
			
		||||
server.connection({ listener: httpsServer, autoListen: false, tls: true });
 | 
			
		||||
 | 
			
		||||
@ -111,15 +93,38 @@ server.route({
 | 
			
		||||
    reply("Hello, I'm so Hapi!");
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Part 3: Redirect http to https
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
//
 | 
			
		||||
// http redirect to https
 | 
			
		||||
//
 | 
			
		||||
var http = require('http');
 | 
			
		||||
var redirectHttps = require('redirect-https')();
 | 
			
		||||
 | 
			
		||||
http.createServer(le.middleware(redirectHttps)).listen(80, function () {
 | 
			
		||||
  console.log('handle ACME http-01 challenge and redirect to https');
 | 
			
		||||
http.createServer(greenlock.middleware(redirectHttps)).listen(80, function () {
 | 
			
		||||
  console.log('Listening on port 80 to handle ACME http-01 challenge and redirect to https');
 | 
			
		||||
});
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Usage & Troubleshooting
 | 
			
		||||
============================
 | 
			
		||||
 | 
			
		||||
See <https://git.coolaj86.com/coolaj86/greenlock-express.js>
 | 
			
		||||
 | 
			
		||||
Handling a dynamic list of domains
 | 
			
		||||
========================
 | 
			
		||||
 | 
			
		||||
In the oversimplified exapmple above we handle a static list of domains.
 | 
			
		||||
If you add domains programmatically you'll want to use the `approveDomains`
 | 
			
		||||
callback.
 | 
			
		||||
 | 
			
		||||
**SECURITY**: Be careful with this.
 | 
			
		||||
If you don't check that the domains being requested are the domains you
 | 
			
		||||
allow an attacker can make you hit your rate limit for failed verification
 | 
			
		||||
attempts.
 | 
			
		||||
 | 
			
		||||
We have a
 | 
			
		||||
[vhost example](https://git.coolaj86.com/coolaj86/greenlock-express.js/src/branch/master/examples/vhost.js)
 | 
			
		||||
that allows any domain for which there is a folder on the filesystem in a specific location.
 | 
			
		||||
 | 
			
		||||
See that example for an idea of how this is done.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										7
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								index.js
									
									
									
									
									
								
							@ -1,3 +1,8 @@
 | 
			
		||||
'use strict';
 | 
			
		||||
 | 
			
		||||
module.exports = require('greenlock-express');
 | 
			
		||||
module.exports = require('greenlock-express');
 | 
			
		||||
module.exports._greenlockExpressCreate = module.exports.create;
 | 
			
		||||
module.create = function (opts) {
 | 
			
		||||
  opts._communityPackage = opts._communityPackage || 'greenlock-hapi';
 | 
			
		||||
  return module.exports._greenlockExpressCreate(opts);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								package.json
									
									
									
									
									
								
							@ -1,32 +1,33 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "greenlock-hapi",
 | 
			
		||||
  "version": "2.0.2",
 | 
			
		||||
  "description": "Free SSL and Automatic HTTPS for node.js with hapi and other middleware systems via ACME (Let's Encrypt)",
 | 
			
		||||
  "homepage": "https://git.coolaj86.com/coolaj86/greenlock-hapi.js",
 | 
			
		||||
  "version": "2.1.3",
 | 
			
		||||
  "description": "An Automated HTTPS ACME client (Let's Encrypt v2) for hapi",
 | 
			
		||||
  "main": "index.js",
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "test": "echo \"Error: no test specified\" && exit 1"
 | 
			
		||||
  },
 | 
			
		||||
  "repository": {
 | 
			
		||||
    "type": "git",
 | 
			
		||||
    "url": "git@git.daplie.com:Daplie/greenlock-hapi.git"
 | 
			
		||||
    "url": "git+https://git.coolaj86.com/coolaj86/greenlock-hapi.js.git"
 | 
			
		||||
  },
 | 
			
		||||
  "keywords": [
 | 
			
		||||
    "hapi",
 | 
			
		||||
    "acme",
 | 
			
		||||
    "cloud",
 | 
			
		||||
    "cluster",
 | 
			
		||||
    "free",
 | 
			
		||||
    "greenlock",
 | 
			
		||||
    "freessl",
 | 
			
		||||
    "free ssl",
 | 
			
		||||
    "https",
 | 
			
		||||
    "hapi",
 | 
			
		||||
    "le",
 | 
			
		||||
    "letsencrypt",
 | 
			
		||||
    "multi-core",
 | 
			
		||||
    "node",
 | 
			
		||||
    "node.js",
 | 
			
		||||
    "scale",
 | 
			
		||||
    "ssl",
 | 
			
		||||
    "tls"
 | 
			
		||||
  ],
 | 
			
		||||
  "author": "AJ ONeal <aj@daplie.com> (https://daplie.com/)",
 | 
			
		||||
  "author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)",
 | 
			
		||||
  "license": "(MIT OR Apache-2.0)"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user