@jsenv/https-local 3.5.0 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -358
- package/package.json +4 -4
- package/src/certificate_request.js +1 -1
- package/src/https_local_cli.mjs +21 -11
package/README.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
# HTTPS Local [](https://www.npmjs.com/package/@jsenv/https-local)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generate locally trusted HTTPS certificates for local development.
|
|
4
4
|
|
|
5
|
-
🔒
|
|
5
|
+
🔒 Certificates trusted by your operating system and browsers
|
|
6
6
|
🌐 Perfect for local HTTPS development
|
|
7
7
|
🖥️ Works on macOS, Linux, and Windows
|
|
8
|
-
⚡ Simple
|
|
8
|
+
⚡ Simple CLI and JavaScript API
|
|
9
9
|
|
|
10
10
|
## Table of Contents
|
|
11
11
|
|
|
12
12
|
- [HTTPS Local ](#https-local-)
|
|
13
13
|
- [Table of Contents](#table-of-contents)
|
|
14
14
|
- [Quick Start](#quick-start)
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
15
|
+
- [CLI](#cli)
|
|
16
|
+
- [init](#init)
|
|
17
|
+
- [generate](#generate)
|
|
18
|
+
- [cleanup](#cleanup)
|
|
19
19
|
- [Certificate Expiration](#certificate-expiration)
|
|
20
20
|
- [JavaScript API](#javascript-api)
|
|
21
21
|
- [requestCertificate](#requestcertificate)
|
|
@@ -27,23 +27,20 @@ A programmatic way to generate locally trusted certificates for HTTPS developmen
|
|
|
27
27
|
## Quick Start
|
|
28
28
|
|
|
29
29
|
```console
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
# Install and trust the root certificate
|
|
34
|
-
npx @jsenv/https-local install --trust
|
|
30
|
+
npx @jsenv/https-local init
|
|
31
|
+
npx @jsenv/https-local generate
|
|
35
32
|
```
|
|
36
33
|
|
|
34
|
+
Then start your server reading the generated certificate files:
|
|
35
|
+
|
|
37
36
|
```js
|
|
38
|
-
// In your server file
|
|
39
37
|
import { createServer } from "node:https";
|
|
40
|
-
import {
|
|
38
|
+
import { readFileSync } from "node:fs";
|
|
41
39
|
|
|
42
|
-
const { certificate, privateKey } = requestCertificate();
|
|
43
40
|
const server = createServer(
|
|
44
41
|
{
|
|
45
|
-
cert: certificate,
|
|
46
|
-
key:
|
|
42
|
+
cert: readFileSync("certificate.pem"),
|
|
43
|
+
key: readFileSync("private_key.pem"),
|
|
47
44
|
},
|
|
48
45
|
(request, response) => {
|
|
49
46
|
response.end("Hello HTTPS world!");
|
|
@@ -53,75 +50,112 @@ const server = createServer(
|
|
|
53
50
|
});
|
|
54
51
|
```
|
|
55
52
|
|
|
56
|
-
##
|
|
53
|
+
## CLI
|
|
54
|
+
|
|
55
|
+
### init
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
```console
|
|
58
|
+
npx @jsenv/https-local init
|
|
59
|
+
```
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
Installs a root certificate authority, trusts it in your OS and browsers, and ensures `localhost` is mapped to `127.0.0.1` in your hosts file. Safe to re-run — subsequent runs report the current status.
|
|
62
|
+
|
|
63
|
+
<details>
|
|
64
|
+
<summary>First execution (macOS)</summary>
|
|
61
65
|
|
|
62
66
|
```console
|
|
63
|
-
npx @jsenv/https-local
|
|
67
|
+
> npx @jsenv/https-local init
|
|
68
|
+
|
|
69
|
+
ℹ authority root certificate not found in filesystem
|
|
70
|
+
Generating authority root certificate with a validity of 20 years...
|
|
71
|
+
✔ authority root certificate written at /Users/you/https_local/https_local_root_certificate.crt
|
|
72
|
+
Adding certificate to mac keychain...
|
|
73
|
+
❯ sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "/Users/you/https_local/https_local_root_certificate.crt"
|
|
74
|
+
Password:
|
|
75
|
+
✔ certificate added to mac keychain
|
|
76
|
+
Adding certificate to firefox...
|
|
77
|
+
✔ certificate added to Firefox
|
|
78
|
+
Check hosts file content...
|
|
79
|
+
✔ all ip mappings found in hosts file
|
|
64
80
|
```
|
|
65
81
|
|
|
66
|
-
|
|
82
|
+
</details>
|
|
67
83
|
|
|
68
|
-
|
|
69
|
-
|
|
84
|
+
<details>
|
|
85
|
+
<summary>Second execution (macOS)</summary>
|
|
70
86
|
|
|
71
|
-
|
|
87
|
+
```console
|
|
88
|
+
> npx @jsenv/https-local init
|
|
72
89
|
|
|
73
|
-
|
|
90
|
+
✔ authority root certificate found in filesystem
|
|
91
|
+
Checking certificate validity...
|
|
92
|
+
✔ certificate still valid for 19 years
|
|
93
|
+
Detect if certificate attributes have changed...
|
|
94
|
+
✔ certificate attributes are the same
|
|
95
|
+
Check if certificate is in mac keychain...
|
|
96
|
+
✔ certificate found in mac keychain
|
|
97
|
+
Check if certificate is in Firefox...
|
|
98
|
+
✔ certificate found in Firefox
|
|
99
|
+
Check hosts file content...
|
|
100
|
+
✔ all ip mappings found in hosts file
|
|
101
|
+
```
|
|
74
102
|
|
|
75
|
-
|
|
76
|
-
import { createServer } from "node:https";
|
|
77
|
-
import { requestCertificate } from "@jsenv/https-local";
|
|
103
|
+
</details>
|
|
78
104
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
key: privateKey,
|
|
84
|
-
},
|
|
85
|
-
(request, response) => {
|
|
86
|
-
const body = "Hello world";
|
|
87
|
-
response.writeHead(200, {
|
|
88
|
-
"content-type": "text/plain",
|
|
89
|
-
"content-length": Buffer.byteLength(body),
|
|
90
|
-
});
|
|
91
|
-
response.write(body);
|
|
92
|
-
response.end();
|
|
93
|
-
},
|
|
94
|
-
);
|
|
95
|
-
server.listen(8080);
|
|
96
|
-
console.log(`Server listening at https://local.example:8080`);
|
|
105
|
+
### generate
|
|
106
|
+
|
|
107
|
+
```console
|
|
108
|
+
npx @jsenv/https-local generate
|
|
97
109
|
```
|
|
98
110
|
|
|
99
|
-
|
|
111
|
+
Generates a server certificate signed by the local certificate authority and writes it to files. Requires `init` to have been run first.
|
|
112
|
+
|
|
113
|
+
> **Note:** Certificate files are static — they are not renewed automatically. Re-run `generate` after one year to replace expired files.
|
|
114
|
+
|
|
115
|
+
Options:
|
|
116
|
+
|
|
117
|
+
| Option | Description | Default |
|
|
118
|
+
| --------------- | --------------------------------- | ----------------- |
|
|
119
|
+
| `--certificate` | Path for the certificate file | `certificate.pem` |
|
|
120
|
+
| `--private-key` | Path for the private key file | `private_key.pem` |
|
|
121
|
+
| `--hostnames` | Comma-separated list of hostnames | `localhost` |
|
|
122
|
+
|
|
123
|
+
Example:
|
|
100
124
|
|
|
101
125
|
```console
|
|
102
|
-
|
|
126
|
+
npx @jsenv/https-local generate --certificate server.pem --private-key server.key --hostnames localhost,myapp.local
|
|
103
127
|
```
|
|
104
128
|
|
|
105
|
-
|
|
129
|
+
### cleanup
|
|
130
|
+
|
|
131
|
+
```console
|
|
132
|
+
npx @jsenv/https-local cleanup
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Uninstalls the root certificate and removes its trust from your OS and browsers.
|
|
106
136
|
|
|
107
137
|
## Certificate Expiration
|
|
108
138
|
|
|
109
|
-
| Certificate | Expires after | How to renew?
|
|
110
|
-
| ----------- | ------------- |
|
|
111
|
-
| server | 1 year | Re-run
|
|
112
|
-
| authority | 20 years | Re-run
|
|
139
|
+
| Certificate | Expires after | How to renew? |
|
|
140
|
+
| ----------- | ------------- | ----------------- |
|
|
141
|
+
| server | 1 year | Re-run `generate` |
|
|
142
|
+
| authority | 20 years | Re-run `init` |
|
|
113
143
|
|
|
114
144
|
The **server certificate** expires after one year, which is the maximum duration allowed by web browsers.
|
|
115
|
-
In the unlikely scenario where a local server is running for more than a year without interruption, restart it to re-run requestCertificate.
|
|
116
145
|
|
|
117
|
-
The **authority root certificate** expires after 20 years
|
|
118
|
-
In the very unlikely scenario where you are using the same machine for more than 20 years, re-execute [installCertificateAuthority](#installcertificateauthority) to update certificate authority then restart your server.
|
|
146
|
+
The **authority root certificate** expires after 20 years. Re-running `init` after expiry will reinstall and re-trust a new one.
|
|
119
147
|
|
|
120
148
|
## JavaScript API
|
|
121
149
|
|
|
150
|
+
To use the JavaScript API, add the package to your dev dependencies:
|
|
151
|
+
|
|
152
|
+
```console
|
|
153
|
+
npm install --save-dev @jsenv/https-local
|
|
154
|
+
```
|
|
155
|
+
|
|
122
156
|
### requestCertificate
|
|
123
157
|
|
|
124
|
-
The `requestCertificate` function
|
|
158
|
+
The `requestCertificate` function generates a fresh certificate each time it is called and returns it in memory. Because the certificate is generated on every server startup, it is always valid — as long as your server is restarted at least once a year.
|
|
125
159
|
|
|
126
160
|
```js
|
|
127
161
|
import { createServer } from "node:https";
|
|
@@ -130,13 +164,21 @@ import { requestCertificate } from "@jsenv/https-local";
|
|
|
130
164
|
const { certificate, privateKey } = requestCertificate({
|
|
131
165
|
altNames: ["localhost", "local.example"],
|
|
132
166
|
});
|
|
167
|
+
const server = createServer(
|
|
168
|
+
{ cert: certificate, key: privateKey },
|
|
169
|
+
(request, response) => {
|
|
170
|
+
response.end("Hello HTTPS world!");
|
|
171
|
+
},
|
|
172
|
+
).listen(8443, () => {
|
|
173
|
+
console.log("HTTPS server running at https://localhost:8443");
|
|
174
|
+
});
|
|
133
175
|
```
|
|
134
176
|
|
|
135
|
-
[
|
|
177
|
+
[`init`](#init) (or `installCertificateAuthority`) must be called once before using this function.
|
|
136
178
|
|
|
137
179
|
### verifyHostsFile
|
|
138
180
|
|
|
139
|
-
|
|
181
|
+
Verifies that IP mappings important for your local server are present in the hosts file.
|
|
140
182
|
|
|
141
183
|
```js
|
|
142
184
|
import { verifyHostsFile } from "@jsenv/https-local";
|
|
@@ -148,40 +190,6 @@ await verifyHostsFile({
|
|
|
148
190
|
});
|
|
149
191
|
```
|
|
150
192
|
|
|
151
|
-
Find below logs written in terminal when this function is executed:
|
|
152
|
-
|
|
153
|
-
<details>
|
|
154
|
-
<summary>Mac and Linux output</summary>
|
|
155
|
-
|
|
156
|
-
```console
|
|
157
|
-
> node ./verify_hosts.mjs
|
|
158
|
-
|
|
159
|
-
Check hosts file content...
|
|
160
|
-
⚠ 1 mapping is missing in hosts file
|
|
161
|
-
--- hosts file path ---
|
|
162
|
-
/etc/hosts
|
|
163
|
-
--- line(s) to add ---
|
|
164
|
-
127.0.0.1 localhost local.example
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
</details>
|
|
168
|
-
|
|
169
|
-
<details>
|
|
170
|
-
<summary>Windows output</summary>
|
|
171
|
-
|
|
172
|
-
```console
|
|
173
|
-
> node ./verify_hosts.mjs
|
|
174
|
-
|
|
175
|
-
Check hosts file content...
|
|
176
|
-
⚠ 1 mapping is missing in hosts file
|
|
177
|
-
--- hosts file path ---
|
|
178
|
-
C:\\Windows\\System32\\Drivers\\etc\\hosts
|
|
179
|
-
--- line(s) to add ---
|
|
180
|
-
127.0.0.1 localhost local.example
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
</details>
|
|
184
|
-
|
|
185
193
|
#### Auto Update Hosts
|
|
186
194
|
|
|
187
195
|
It's possible to update hosts file programmatically using `tryToUpdateHostsFile`:
|
|
@@ -197,52 +205,6 @@ await verifyHostsFile({
|
|
|
197
205
|
});
|
|
198
206
|
```
|
|
199
207
|
|
|
200
|
-
<details>
|
|
201
|
-
<summary>Mac and Linux output</summary>
|
|
202
|
-
|
|
203
|
-
```console
|
|
204
|
-
Check hosts file content...
|
|
205
|
-
ℹ 1 mapping is missing in hosts file
|
|
206
|
-
Adding 1 mapping(s) in hosts file...
|
|
207
|
-
❯ echo "127.0.0.1 local.example" | sudo tee -a /etc/hosts
|
|
208
|
-
Password:
|
|
209
|
-
✔ mappings added to hosts file
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
_Second execution logs_
|
|
213
|
-
|
|
214
|
-
```console
|
|
215
|
-
> node ./verify_hosts.mjs
|
|
216
|
-
|
|
217
|
-
Check hosts file content...
|
|
218
|
-
✔ all ip mappings found in hosts file
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
</details>
|
|
222
|
-
|
|
223
|
-
<details>
|
|
224
|
-
<summary>Windows output</summary>
|
|
225
|
-
|
|
226
|
-
```console
|
|
227
|
-
Check hosts file content...
|
|
228
|
-
ℹ 1 mapping is missing in hosts file
|
|
229
|
-
Adding 1 mapping(s) in hosts file...
|
|
230
|
-
❯ (echo 127.0.0.1 local.example) >> C:\\Windows\\System32\\Drivers\\etc\\hosts
|
|
231
|
-
Password:
|
|
232
|
-
✔ mappings added to hosts file
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
_Second execution logs_
|
|
236
|
-
|
|
237
|
-
```console
|
|
238
|
-
> node ./verify_hosts.mjs
|
|
239
|
-
|
|
240
|
-
Check hosts file content...
|
|
241
|
-
✔ all ip mappings found in hosts file
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
</details>
|
|
245
|
-
|
|
246
208
|
### installCertificateAuthority
|
|
247
209
|
|
|
248
210
|
The `installCertificateAuthority` function generates a certificate authority valid for 20 years.
|
|
@@ -254,103 +216,7 @@ import { installCertificateAuthority } from "@jsenv/https-local";
|
|
|
254
216
|
await installCertificateAuthority();
|
|
255
217
|
```
|
|
256
218
|
|
|
257
|
-
By default, trusting
|
|
258
|
-
|
|
259
|
-
<details>
|
|
260
|
-
<summary>macOS output</summary>
|
|
261
|
-
|
|
262
|
-
```console
|
|
263
|
-
> node ./install_certificate_authority.mjs
|
|
264
|
-
|
|
265
|
-
ℹ authority root certificate not found in filesystem
|
|
266
|
-
Generating authority root certificate with a validity of 20 years...
|
|
267
|
-
✔ authority root certificate written at /Users/dmail/https_local/http_local_root_certificate.crt
|
|
268
|
-
ℹ You should add root certificate to mac keychain
|
|
269
|
-
ℹ You should add root certificate to firefox
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
_Second execution logs_
|
|
273
|
-
|
|
274
|
-
```console
|
|
275
|
-
> node ./install_certificate_authority.mjs
|
|
276
|
-
|
|
277
|
-
✔ authority root certificate found in filesystem
|
|
278
|
-
Checking certificate validity...
|
|
279
|
-
✔ certificate still valid for 19 years
|
|
280
|
-
Detect if certificate attributes have changed...
|
|
281
|
-
✔ certificate attributes are the same
|
|
282
|
-
Check if certificate is in mac keychain...
|
|
283
|
-
ℹ certificate not found in mac keychain
|
|
284
|
-
Check if certificate is in firefox...
|
|
285
|
-
ℹ certificate not found in firefox
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
</details>
|
|
289
|
-
|
|
290
|
-
<details>
|
|
291
|
-
<summary>Linux output</summary>
|
|
292
|
-
|
|
293
|
-
```console
|
|
294
|
-
> node ./install_certificate_authority.mjs
|
|
295
|
-
|
|
296
|
-
ℹ authority root certificate not found in filesystem
|
|
297
|
-
Generating authority root certificate with a validity of 20 years...
|
|
298
|
-
✔ authority root certificate written at /home/dmail/.config/https_local/https_local_root_certificate.crt
|
|
299
|
-
ℹ You should add certificate to linux
|
|
300
|
-
ℹ You should add certificate to chrome
|
|
301
|
-
ℹ You should add certificate to firefox
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
_Second execution logs_
|
|
305
|
-
|
|
306
|
-
```console
|
|
307
|
-
> node ./install_certificate_authority.mjs
|
|
308
|
-
|
|
309
|
-
✔ authority root certificate found in filesystem
|
|
310
|
-
Checking certificate validity...
|
|
311
|
-
✔ certificate still valid for 19 years
|
|
312
|
-
Detect if certificate attributes have changed...
|
|
313
|
-
✔ certificate attributes are the same
|
|
314
|
-
Check if certificate is in linux...
|
|
315
|
-
ℹ certificate in linux is outdated
|
|
316
|
-
Check if certificate is in chrome...
|
|
317
|
-
ℹ certificate not found in chrome
|
|
318
|
-
Check if certificate is in firefox...
|
|
319
|
-
ℹ certificate not found in firefox
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
</details>
|
|
323
|
-
|
|
324
|
-
<details>
|
|
325
|
-
<summary>Windows output</summary>
|
|
326
|
-
|
|
327
|
-
```console
|
|
328
|
-
> node ./install_certificate_authority.mjs
|
|
329
|
-
|
|
330
|
-
ℹ authority root certificate not found in filesystem
|
|
331
|
-
Generating authority root certificate with a validity of 20 years...
|
|
332
|
-
✔ authority root certificate written at C:\Users\Dmail\AppData\Local\https_local\https_local_root_certificate.crt
|
|
333
|
-
ℹ You should add certificate to windows
|
|
334
|
-
ℹ You should add certificate to firefox
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
_Second execution logs_
|
|
338
|
-
|
|
339
|
-
```console
|
|
340
|
-
> node ./install_certificate_authority.mjs
|
|
341
|
-
|
|
342
|
-
✔ authority root certificate found in filesystem
|
|
343
|
-
Checking certificate validity...
|
|
344
|
-
✔ certificate still valid for 19 years
|
|
345
|
-
Detect if certificate attributes have changed...
|
|
346
|
-
✔ certificate attributes are the same
|
|
347
|
-
Check if certificate is trusted by windows...
|
|
348
|
-
ℹ certificate is not trusted by windows
|
|
349
|
-
Check if certificate is trusted by firefox...
|
|
350
|
-
ℹ unable to detect if certificate is trusted by firefox (not implemented on windows)
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
</details>
|
|
219
|
+
By default, trusting the root certificate is a manual process. See [BenMorel/dev-certificates](https://github.com/BenMorel/dev-certificates/tree/c10cd68945da772f31815b7a36721ddf848ff3a3#import-the-ca-in-your-browser) for instructions. This can also be done programmatically as shown in [Auto Trust](#auto-trust).
|
|
354
220
|
|
|
355
221
|
#### Auto Trust
|
|
356
222
|
|
|
@@ -363,124 +229,3 @@ await installCertificateAuthority({
|
|
|
363
229
|
tryToTrust: true,
|
|
364
230
|
});
|
|
365
231
|
```
|
|
366
|
-
|
|
367
|
-
<details>
|
|
368
|
-
<summary>macOS output</summary>
|
|
369
|
-
|
|
370
|
-
```console
|
|
371
|
-
> node ./install_certificate_authority.mjs
|
|
372
|
-
|
|
373
|
-
ℹ authority root certificate not found in filesystem
|
|
374
|
-
Generating authority root certificate with a validity of 20 years...
|
|
375
|
-
✔ authority root certificate written at /Users/dmail/https_local/https_local_root_certificate.crt
|
|
376
|
-
Adding certificate to mac keychain...
|
|
377
|
-
❯ sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "/Users/dmail/https_local/https_local_root_certificate.crt"
|
|
378
|
-
Password:
|
|
379
|
-
✔ certificate added to mac keychain
|
|
380
|
-
Adding certificate to firefox...
|
|
381
|
-
✔ certificate added to Firefox
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
_Second execution logs_
|
|
385
|
-
|
|
386
|
-
```console
|
|
387
|
-
> node ./install_certificate_authority.mjs
|
|
388
|
-
|
|
389
|
-
✔ authority root certificate found in filesystem
|
|
390
|
-
Checking certificate validity...
|
|
391
|
-
✔ certificate still valid for 19 years
|
|
392
|
-
Detect if certificate attributes have changed...
|
|
393
|
-
✔ certificate attributes are the same
|
|
394
|
-
Check if certificate is in mac keychain...
|
|
395
|
-
✔ certificate found in mac keychain
|
|
396
|
-
Check if certificate is in Firefox...
|
|
397
|
-
✔ certificate found in Firefox
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
</details>
|
|
401
|
-
|
|
402
|
-
<details>
|
|
403
|
-
<summary>Linux output</summary>
|
|
404
|
-
|
|
405
|
-
```console
|
|
406
|
-
> node ./install_certificate_authority.mjs
|
|
407
|
-
|
|
408
|
-
✔ authority root certificate found in filesystem
|
|
409
|
-
Checking certificate validity...
|
|
410
|
-
✔ certificate still valid for 19 years
|
|
411
|
-
Detect if certificate attributes have changed...
|
|
412
|
-
✔ certificate attributes are the same
|
|
413
|
-
Check if certificate is in linux...
|
|
414
|
-
ℹ certificate not in linux
|
|
415
|
-
Adding certificate to linux...
|
|
416
|
-
❯ sudo /bin/cp -f "/home/dmail/.config/https_local/https_local_root_certificate.crt" /usr/local/share/ca-certificates/https_local_root_certificate.crt
|
|
417
|
-
[sudo] Password for dmail :
|
|
418
|
-
❯ sudo update-ca-certificates
|
|
419
|
-
✔ certificate added to linux
|
|
420
|
-
Check if certificate is in chrome...
|
|
421
|
-
ℹ certificate not found in chrome
|
|
422
|
-
Adding certificate to chrome...
|
|
423
|
-
✔ certificate added to chrome
|
|
424
|
-
Check if certificate is in firefox...
|
|
425
|
-
ℹ certificate not found in firefox
|
|
426
|
-
Adding certificate to firefox...
|
|
427
|
-
✔ certificate added to firefox
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
_Second execution logs_
|
|
431
|
-
|
|
432
|
-
```console
|
|
433
|
-
> node ./install_certificate_authority.mjs
|
|
434
|
-
|
|
435
|
-
✔ authority root certificate found in filesystem
|
|
436
|
-
Checking certificate validity...
|
|
437
|
-
✔ certificate still valid for 19 years
|
|
438
|
-
Detect if certificate attributes have changed...
|
|
439
|
-
✔ certificate attributes are the same
|
|
440
|
-
Check if certificate is in linux...
|
|
441
|
-
✔ certificate found in linux
|
|
442
|
-
Check if certificate is in chrome...
|
|
443
|
-
✔ certificate found in chrome
|
|
444
|
-
Check if certificate is in firefox...
|
|
445
|
-
✔ certificate found in firefox
|
|
446
|
-
```
|
|
447
|
-
|
|
448
|
-
</details>
|
|
449
|
-
|
|
450
|
-
<details>
|
|
451
|
-
<summary>Windows output</summary>
|
|
452
|
-
|
|
453
|
-
```console
|
|
454
|
-
> node ./install_certificate_authority.mjs
|
|
455
|
-
|
|
456
|
-
✔ authority root certificate found in filesystem
|
|
457
|
-
Checking certificate validity...
|
|
458
|
-
✔ certificate still valid for 19 years
|
|
459
|
-
Detect if certificate attributes have changed...
|
|
460
|
-
✔ certificate attributes are the same
|
|
461
|
-
Check if certificate is trusted by windows...
|
|
462
|
-
ℹ certificate not trusted by windows
|
|
463
|
-
Adding certificate to windows...
|
|
464
|
-
❯ certutil -addstore -user root C:\Users\Dmail\AppData\Local\https_local\https_local_root_certificate.crt
|
|
465
|
-
✔ certificate added to windows
|
|
466
|
-
Check if certificate is trusted by firefox...
|
|
467
|
-
ℹ unable to detect if certificate is trusted by firefox (not implemented on windows)
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
_Second execution logs_
|
|
471
|
-
|
|
472
|
-
```console
|
|
473
|
-
> node ./install_certificate_authority.mjs
|
|
474
|
-
|
|
475
|
-
✔ authority root certificate found in filesystem
|
|
476
|
-
Checking certificate validity...
|
|
477
|
-
✔ certificate still valid for 19 years
|
|
478
|
-
Detect if certificate attributes have changed...
|
|
479
|
-
✔ certificate attributes are the same
|
|
480
|
-
Check if certificate is trusted by windows...
|
|
481
|
-
✔ certificate trusted by windows
|
|
482
|
-
Check if certificate is trusted by firefox...
|
|
483
|
-
ℹ unable to detect if certificate is trusted by firefox (not implemented on windows)
|
|
484
|
-
```
|
|
485
|
-
|
|
486
|
-
</details>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/https-local",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A programmatic way to generate locally trusted certificates",
|
|
6
6
|
"repository": {
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"test:start-node-server": "node ./scripts/certificate/start_node_server.mjs"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@jsenv/filesystem": "4.15.
|
|
41
|
-
"@jsenv/humanize": "1.7.
|
|
42
|
-
"@jsenv/urls": "2.9.
|
|
40
|
+
"@jsenv/filesystem": "4.15.16",
|
|
41
|
+
"@jsenv/humanize": "1.7.7",
|
|
42
|
+
"@jsenv/urls": "2.9.9",
|
|
43
43
|
"command-exists": "1.2.9",
|
|
44
44
|
"node-forge": "1.4.0",
|
|
45
45
|
"sudo-prompt": "9.2.1",
|
|
@@ -48,7 +48,7 @@ export const requestCertificate = ({
|
|
|
48
48
|
throw new Error(
|
|
49
49
|
`Certificate authority not found, "installCertificateAuthority" must be called before "requestServerCertificate".
|
|
50
50
|
--- Suggested command to run ---
|
|
51
|
-
npx @jsenv/https-local
|
|
51
|
+
npx @jsenv/https-local init`,
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
if (!rootCertificatePrivateKeyFileInfo.exists) {
|
package/src/https_local_cli.mjs
CHANGED
|
@@ -34,14 +34,25 @@ const { values, positionals } = parseArgs({
|
|
|
34
34
|
if (values.help || positionals.length === 0) {
|
|
35
35
|
console.log(`https-local: Generate https certificates to use on your machine.
|
|
36
36
|
|
|
37
|
-
Usage:
|
|
37
|
+
Usage:
|
|
38
38
|
|
|
39
|
-
npx @jsenv/https-local
|
|
40
|
-
Install root certificate,
|
|
39
|
+
npx @jsenv/https-local init
|
|
40
|
+
Install root certificate, trust it and ensure localhost is mapped to 127.0.0.1
|
|
41
|
+
|
|
42
|
+
npx @jsenv/https-local cleanup
|
|
43
|
+
Uninstall root certificate and remove its trust from os and browsers
|
|
44
|
+
|
|
45
|
+
npx @jsenv/https-local generate
|
|
46
|
+
Generate a server certificate and write it to files
|
|
47
|
+
- certificate: Path where to write the certificate file (default: certificate.pem)
|
|
48
|
+
- private-key: Path where to write the private key file (default: private_key.pem)
|
|
49
|
+
- hostnames: Comma-separated list of hostnames (default: localhost)
|
|
50
|
+
|
|
51
|
+
Advanced commands:
|
|
41
52
|
|
|
42
53
|
npx @jsenv/https-local install --trust
|
|
43
54
|
Install root certificate on the filesystem
|
|
44
|
-
- trust: Try to add root certificate to os and browser trusted stores
|
|
55
|
+
- trust: Try to add root certificate to os and browser trusted stores
|
|
45
56
|
|
|
46
57
|
npx @jsenv/https-local uninstall
|
|
47
58
|
Uninstall root certificate from the filesystem
|
|
@@ -49,12 +60,6 @@ npx @jsenv/https-local uninstall
|
|
|
49
60
|
npx @jsenv/https-local localhost-mapping
|
|
50
61
|
Ensure localhost mapping to 127.0.0.1 is set on the filesystem
|
|
51
62
|
|
|
52
|
-
npx @jsenv/https-local generate
|
|
53
|
-
Generate a server certificate and write it to files
|
|
54
|
-
- certificate: Path where to write the certificate file (default: certificate.pem)
|
|
55
|
-
- private-key: Path where to write the private key file (default: private_key.pem)
|
|
56
|
-
- hostnames: Comma-separated list of hostnames (default: localhost)
|
|
57
|
-
|
|
58
63
|
https://github.com/jsenv/core/tree/main/packages/tooling/https-local
|
|
59
64
|
|
|
60
65
|
`);
|
|
@@ -63,7 +68,7 @@ https://github.com/jsenv/core/tree/main/packages/tooling/https-local
|
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
const commandHandlers = {
|
|
66
|
-
|
|
71
|
+
init: async () => {
|
|
67
72
|
await installCertificateAuthority({
|
|
68
73
|
tryToTrust: true,
|
|
69
74
|
NSSDynamicInstall: true,
|
|
@@ -75,6 +80,11 @@ const commandHandlers = {
|
|
|
75
80
|
tryToUpdateHostsFile: true,
|
|
76
81
|
});
|
|
77
82
|
},
|
|
83
|
+
cleanup: async () => {
|
|
84
|
+
await uninstallCertificateAuthority({
|
|
85
|
+
tryToUntrust: true,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
78
88
|
install: async ({ trust }) => {
|
|
79
89
|
await installCertificateAuthority({
|
|
80
90
|
tryToTrust: trust,
|