Skip to content

Commit 6965222

Browse files
committed
Merge branch 'esm'
2 parents 831dd8f + 9b17d1f commit 6965222

24 files changed

+4453
-2174
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
22
.nyc_output
3+
coverage
4+
mkcert-bin

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [7.0.0] - 2021-03-06
9+
10+
This version is optimised for use on development machines via npm install. It carries out the mkcert binary installation in a postinstall script. In version 6.x and earlier, all binaries for all platforms were bundled as the library also supported use from a binary install (see [Site.js](https://sitejs.org)). The 6.x branch will still be updated with new mkcert versions but the 7.x and later versions will be used in [Place](https://github.com/small-tech/place).
11+
12+
### Changed
13+
14+
- Uses ECMAScript Modules (ESM; es6 modules)
15+
- __Breaking change:__ mkcert binary is now downloaded during installation and the root certificate authority and TLS certificates are created at this time also.
16+
- __Breaking change:__ The settings path is no longer configurable and is shared by all installations of this package. This means whenever you install this package, it will update to the latest version of mkcert and recreate the root certificate authorities and local certificates and these will be used by all instances of Auto Encrypt Localhost on your dev machine (and this is most likely the behaviour you want).
17+
- __Breaking change:__ Removed command-line interface as it is no longer nececessary. Your local certificate authority and TLS certificates are ready to be used once your npm install is complete.
18+
819
## [6.1.0] - 2020-11-04
920

1021
### Changed

README.md

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,24 @@ Automatically provisions and installs locally-trusted TLS certificates for Node.
44

55
## How it works
66

7-
Before creating your HTTPS server, uses mkcert to create a local certificate authority, adds it to the various trust stores, and uses it to create locally-trusted TLS certificates that are installed in your server.
7+
At installation time, Auto Encrypt Localhost uses mkcert to create a local certificate authority, adds it to the various trust stores, and uses it to create locally-trusted TLS certificates that are installed in your server.
88

9-
You can reach your server via the local loopback addresses (localhost, 127.0.0.1) on the device itself and also from other devices on the local area network by using your device’s external IPv4 address.
9+
At runtime, you can reach your server via the local loopback addresses (localhost, 127.0.0.1) on the device itself and also from other devices on the local area network by using your device’s external IPv4 address(es).
1010

1111
## Installation
1212

1313
```sh
1414
npm i @small-tech/auto-encrypt-localhost
1515
```
1616

17-
### On Linux
18-
19-
Make sure you disable privileged ports:
20-
21-
```
22-
sudo sysctl -w net.ipv4.ip_unprivileged_port_start=0
23-
```
24-
25-
(On Linux, ports 80 and 443 require special privileges. Please see [A note on Linux and the security farce that is “privileged ports”](#a-note-on-linux-and-the-security-farce-that-is-priviliged-ports). If you just need a Node web server that handles all that and more for you – or to see how to implement privilege escalation seamlessly in your own servers – see [Site.js](https://sitejs.org)).
26-
2717
## Usage
2818

2919
### Instructions
3020

3121
1. Import the module:
3222

3323
```js
34-
const AutoEncryptLocalhost = require('@small-tech/auto-encrypt-localhost')
24+
import AutoEncryptLocalhost from '@small-tech/auto-encrypt-localhost'
3525
```
3626

3727
2. Prefix your server creation code with a reference to the Auto Encrypt Localhost class:
@@ -48,18 +38,18 @@ sudo sysctl -w net.ipv4.ip_unprivileged_port_start=0
4838
```js
4939
// Create an https server using locally-trusted certificates.
5040
51-
const AutoEncryptLocalhost = require('@small-tech/auto-encrypt-localhost')
41+
import AutoEncryptLocalhost from '@small-tech/auto-encrypt-localhost'
5242
5343
const server = AutoEncryptLocalhost.https.createServer((request, response) => {
5444
response.end('Hello, world!')
5545
})
5646
57-
server.listen(() => {
47+
server.listen(443, () => {
5848
console.log('Web server is running at https://localhost')
5949
})
6050
```
6151

62-
You can now reach your server via https://localhost, https://127.0.0.1, and via its external IPv4 address on your local area network. To find out what that is, you can run the following in the Node interpreter:
52+
You can now reach your server via https://localhost, https://127.0.0.1, and via its external IPv4 address(es) on your local area network. To find the list of IP addresses that your local server is reachable from, you can run the following code in the Node interpreter:
6353

6454
```js
6555
Object.entries(os.networkInterfaces())
@@ -69,6 +59,48 @@ Object.entries(os.networkInterfaces())
6959
.map(addresses => addresses.address)).flat()
7060
```
7161

62+
### Plain Node.js example
63+
64+
If you just want to use the TLS certificates generated at installation time without using the Auto Encrypt Localhost library itself at runtime, you should install Auto Encrypt Localhost into your `dev-dependencies`. Post install, you can find your certificates in the _~/.small-tech.org/auto-encrypt-localhost_ folder.
65+
66+
Here’s a somewhat equivalent example to the one above but using Node’s regular `https` module instead of Auto Encrypt Localhost at runtime:
67+
68+
```js
69+
import os from 'os'
70+
import fs from 'fs'
71+
import path from 'path'
72+
import https from 'https'
73+
74+
const certificatesPath = path.join(os.homedir(), '.small-tech.org', 'auto-encrypt-localhost')
75+
const keyFilePath = path.join(certificatesPath, 'localhost-key.pem')
76+
const certFilePath = path.join(certificatesPath, 'localhost.pem')
77+
78+
const options = {
79+
key: fs.readFileSync(keyFilePath, 'utf-8'),
80+
cert: fs.readFileSync(certFilePath, 'utf-8')
81+
}
82+
83+
const server = https.createServer(options, (request, response) => {
84+
response.end('Hello, world!')
85+
})
86+
87+
server.listen(443, () => {
88+
console.log('Web server is running at https://localhost')
89+
})
90+
```
91+
92+
_Note that if you don’t use Auto Encrypt Localhost at runtime, you won’t get some of the benefits that it provides, like automatically adding the certificate authority to Node’s trust store (for hitting your server using Node.js without certificate errors, the `/.ca` convenience route, and HTTP to HTTPS forwarding, etc.)_
93+
94+
### On Linux
95+
96+
To access your server on port 443, make sure you’ve disabled privileged ports:
97+
98+
```
99+
sudo sysctl -w net.ipv4.ip_unprivileged_port_start=0
100+
```
101+
102+
(On Linux, ports 80 and 443 require special privileges. Please see [A note on Linux and the security farce that is “privileged ports”](#a-note-on-linux-and-the-security-farce-that-is-priviliged-ports). If you just need a Node web server that handles all that and more for you – or to see how to implement privilege escalation seamlessly in your own servers – see [Site.js](https://sitejs.org)).
103+
72104
### Multiple servers
73105
74106
You are not limited to running your server on port 443. You can listen on any port you like and you can have multiple servers with the following caveat: the HTTP server that redirects HTTP calls to HTTPS and serves your local root certificate authority public key (see below) will only be created for the first server and then only if port 80 is free.
@@ -91,29 +123,6 @@ The browser will download the local root certificate authority’s public key an
91123
92124
You can also transfer your key manually. You can find the key at `~/.small-tech/auto-encrypt-localhost/rootCA.pem` after you’ve created at least one server. For more details on transferring your key to other devices, please refer to [the relevant section in the mkcert documentation](https://github.com/FiloSottile/mkcert#mobile-devices).
93125
94-
95-
## Configuration
96-
97-
You can specify a custom settings path for your local certificate authority and certificate data to be stored in by adding the Auto Encrypt Localhost-specific `settingsPath` option to the options object you pass to the Node `https` server. If not specified, the default settings path (_~/.small-tech.org/auto-encrypt-localhost/_) is used.
98-
99-
### Example
100-
101-
```js
102-
const AutoEncrypt = require('@small-tech/auto-encrypt-localhost')
103-
104-
const options = {
105-
// Regular HTTPS server and TLS server options, if any, go here.
106-
107-
// Optional Auto Encrypt options:
108-
settingsPath: '/custom/settings/path'
109-
}
110-
111-
// Pass the options object to https.createServer()
112-
const server = AutoEncryptLocalhost.https.createServer(options, listener)
113-
114-
// …
115-
```
116-
117126
## Developer documentation
118127
119128
If you want to help improve Auto Encrypt Localhost or better understand how it is structured and operates, please see the [developer documentation](developer-documentation.md).
@@ -130,51 +139,44 @@ This is [small technology](https://small-tech.org/about/#small-technology).
130139
131140
If you’re evaluating this for a “startup” or an enterprise, let us save you some time: this is not the right tool for you. This tool is for individual developers to build personal web sites and apps for themselves and for others in a non-colonial manner that respects the human rights of the people who use them.
132141
133-
## Command-line interface
134-
135-
### Install
136-
137-
```sh
138-
npm i -g @small-tech/auto-encrypt-localhost
139-
```
140-
141-
### Use
142-
143-
```sh
144-
auto-encrypt-localhost
145-
```
146-
Your certificates will be created in the _~/.small-tech.org/auto-encrypt-localhost_ directory.
147-
148142
## Caveats
149143
150144
### Windows
151145
152146
Locally-trusted certificates do not work under Firefox. Please use Edge or Chrome on this platform. This is [a mkcert limitation](https://github.com/FiloSottile/mkcert#supported-root-stores).
153147
148+
__Version 7.x is currently not tested under Windows.__ It may not be able to set the executable bit on the binary download if that’s necessary. __This notice will be removed once it’s been tested and confirmed to be working.__
149+
154150
## Related projects
155151
156152
From lower-level to higher-level:
157153
158154
### Auto Encrypt
159155
160-
- Source: https://source.small-tech.org/site.js/lib/auto-encrypt
156+
- Source: https://github.com/small-tech/auto-encrypt
161157
- Package: [@small-tech/auto-encrypt](https://www.npmjs.com/package/@small-tech/auto-encrypt)
162158
163159
Adds automatic provisioning and renewal of [Let’s Encrypt](https://letsencrypt.org) TLS certificates with [OCSP Stapling](https://letsencrypt.org/docs/integration-guide/#implement-ocsp-stapling) to [Node.js](https://nodejs.org) [https](https://nodejs.org/dist/latest-v12.x/docs/api/https.html) servers (including [Express.js](https://expressjs.com/), etc.)
164160
165161
### HTTPS
166162
167-
- Source: https://source.small-tech.org/site.js/lib/https
163+
- Source: https://github.com/small-tech/https
168164
- Package: [@small-tech/https](https://www.npmjs.com/package/@small-tech/https)
169165
170166
A drop-in replacement for the [standard Node.js HTTPS module](https://nodejs.org/dist/latest-v12.x/docs/api/https.html) with automatic development-time (localhost) certificates via Auto Encrypt Localhost and automatic production certificates via Auto Encrypt.
171167
172168
### Site.js
173169
174170
- Web site: https://sitejs.org
175-
- Source: https://source.small-tech.org/site.js/app
171+
- Source: https://github.com/small-tech/site.js
172+
173+
A tool for developing, testing, and deploying a secure static or dynamic personal web site or app with zero configuration.
174+
175+
### Place (work-in-progress)
176+
177+
Small Web Protocol Reference Server.
176178
177-
A complete [small technology](https://small-tech.org/about/#small-technology) tool for developing, testing, and deploying a secure static or dynamic personal web site or app with zero configuration.
179+
- Source: https://github.com/small-tech/place
178180
179181
## A note on Linux and the security farce that is “privileged ports”
180182
@@ -207,7 +209,7 @@ We exist in part thanks to patronage by people like you. If you share [our visio
207209

208210
## Copyright
209211

210-
Copyright © [Aral Balkan](https://ar.al), [Small Technology Foundation](https://small-tech.org).
212+
Copyright © 2019-2021 [Aral Balkan](https://ar.al), [Small Technology Foundation](https://small-tech.org).
211213

212214
## License
213215

0 commit comments

Comments
 (0)