UNPKG

2.96 kBMarkdownView Raw
1# devcert - Development SSL made easy
2
3So, running a local HTTPS server usually sucks. There's a range of approaches,
4each with their own tradeoff. The common one, using self-signed certificates,
5means having to ignore scary browser warnings for each project.
6
7devcert makes the process easy. Want a private key and certificate file to use
8with your server? Just ask:
9
10```js
11import { createServer } from 'https';
12import * as express from 'express';
13import getDevelopmentCertificate from 'devcert';
14
15async function buildMyApp() {
16 let app = express();
17
18 app.get('/', function (req, res) {
19 res.send('Hello Secure World!');
20 });
21
22 let ssl;
23 if (process.env.NODE_ENV === 'development') {
24 ssl = await getDevelopmentCertificate('my-app', { installCertutil: true });
25 } else {
26 ssl = // load production ssl ...
27 }
28
29 return createServer(ssl, app).listen(3000);
30}
31```
32
33Now open https://localhost:3000 and voila - your page loads with no scary
34warnings or hoops to jump through.
35
36> Certificates are cached by name, so two calls for
37`getDevelopmentCertificate('foo')` will return the same key and certificate.
38
39### installCertutil option
40
41devcert currently takes a single option: `installCertutil`. If true, devcert
42will attempt to install some software necessary to tell Firefox (and Chrome on
43Linux) to trust your development certificates. This is not required, but without
44it, you'll need to tell Firefox to trust these certificates manually:
45
46Firefox provides a point-and-click wizard for importing and trusting a
47certificate, so if you don't provide `installCertutil: true` to devcert, we'll
48instead open Firefox and kick off this wizard for you. Simply follow the prompts
49to trust the certificate. **Reminder: you'll only need to do this once per
50machine**
51
52**Note:** Chrome on Linux **requires** `installCertutil: true`, or else you'll
53face the scary browser warnings every time. Unfortunately, there's no way to
54tell Chrome on Linux to trust a certificate without install certutil.
55
56The software installed varies by OS:
57
58* Mac: `brew install nss`
59* Linux: `apt install libnss3-tools`
60* Windows: N/A
61
62## How it works
63
64When you ask for a development certificate, devcert will first check to see if
65it has run on this machine before. If not, it will create a root certificate
66authority and add it to your OS and various browser trust stores. You'll likely
67see password prompts from your OS at this point to authorize the new root CA.
68This is the only time you'll see these prompts.
69
70This root certificate authority allows devcert to create a new SSL certificate
71whenever you want without needing to ask for elevated permissions again. It also
72ensures that browsers won't show scary warnings about untrusted certificates,
73since your OS and browsers will now trust devcert's certificates. The root CA
74certificate is unique to your machine only, and is generated on-the-fly when it
75is installed.
76
77## License
78
79MIT © [Dave Wasmer](http://davewasmer.com)