@comate/zulu 0.8.0 → 0.8.2
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/comate-engine/node_modules/@comate/plugin-engine/dist/index.js +8 -8
- package/comate-engine/node_modules/@comate/plugin-host/dist/index-DRjiQy-z.js +1 -0
- package/comate-engine/node_modules/@comate/plugin-host/dist/index.js +1 -1
- package/comate-engine/node_modules/@comate/plugin-host/dist/main.js +1 -1
- package/comate-engine/node_modules/@comate/plugin-host/dist/user-NJTZ_OFu.js +44 -0
- package/comate-engine/node_modules/@comate/plugin-shared-internals/dist/index.d.ts +406 -15
- package/comate-engine/node_modules/@comate/plugin-shared-internals/dist/index.js +8 -8
- package/comate-engine/node_modules/@comate/plugin-shared-internals/package.json +4 -1
- package/comate-engine/node_modules/win-ca/LICENSE +21 -0
- package/comate-engine/node_modules/win-ca/README.md +648 -0
- package/comate-engine/node_modules/win-ca/lib/crypt32-ia32.node +0 -0
- package/comate-engine/node_modules/win-ca/lib/crypt32-x64.node +0 -0
- package/comate-engine/node_modules/win-ca/lib/der2.js +78 -0
- package/comate-engine/node_modules/win-ca/lib/fallback.js +110 -0
- package/comate-engine/node_modules/win-ca/lib/forge.js +16 -0
- package/comate-engine/node_modules/win-ca/lib/hash.js +52 -0
- package/comate-engine/node_modules/win-ca/lib/index.js +162 -0
- package/comate-engine/node_modules/win-ca/lib/inject.js +65 -0
- package/comate-engine/node_modules/win-ca/lib/n-api.js +62 -0
- package/comate-engine/node_modules/win-ca/lib/none.js +13 -0
- package/comate-engine/node_modules/win-ca/lib/oids.js +4 -0
- package/comate-engine/node_modules/win-ca/lib/roots.exe +0 -0
- package/comate-engine/node_modules/win-ca/lib/save.js +112 -0
- package/comate-engine/node_modules/win-ca/lib/unique.js +17 -0
- package/comate-engine/node_modules/win-ca/package.json +66 -0
- package/comate-engine/package.json +9 -2
- package/comate-engine/plugins/demo-feature/dist/index.js +72178 -7934
- package/comate-engine/server.js +173 -106
- package/dist/bundle/index.js +12 -8
- package/package.json +1 -1
- package/comate-engine/node_modules/@comate/plugin-host/dist/user-CoKKEQY1.js +0 -44
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"@types/fs-extra": "^11.0.4",
|
|
54
54
|
"@types/lodash": "^4.14.202",
|
|
55
55
|
"@types/ospath": "^1.2.3",
|
|
56
|
+
"@types/win-ca": "^3.5.4",
|
|
56
57
|
"anymatch": "^3.1.3",
|
|
57
58
|
"axios": "^1.9.0",
|
|
58
59
|
"compare-versions": "^6.1.1",
|
|
@@ -67,11 +68,13 @@
|
|
|
67
68
|
"lodash": "^4.17.21",
|
|
68
69
|
"marked": "^11.2.0",
|
|
69
70
|
"ospath": "^1.2.2",
|
|
71
|
+
"proxy-agent": "^6.5.0",
|
|
70
72
|
"shell-quote": "^1.8.2",
|
|
71
73
|
"string-similarity-js": "^2.1.4",
|
|
72
74
|
"vite": "^5.1.6",
|
|
73
75
|
"vitest": "^1.2.2",
|
|
74
76
|
"vscode-languageserver": "8.0.2",
|
|
75
|
-
"vscode-uri": "^3.0.8"
|
|
77
|
+
"vscode-uri": "^3.0.8",
|
|
78
|
+
"win-ca": "3.5.1"
|
|
76
79
|
}
|
|
77
80
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Stas Ukolov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
# win-ca
|
|
2
|
+
|
|
3
|
+
[](https://ci.appveyor.com/project/ukoloff/win-ca)
|
|
4
|
+
[](http://badge.fury.io/js/win-ca)
|
|
5
|
+
[](https://github.com/ukoloff/win-ca/actions)
|
|
6
|
+
|
|
7
|
+
Get Windows System Root certificates for [Node.js].
|
|
8
|
+
|
|
9
|
+
## Rationale
|
|
10
|
+
|
|
11
|
+
Unlike [Ruby][], [Node.js][] on Windows **allows**
|
|
12
|
+
HTTPS requests out-of-box.
|
|
13
|
+
But it is implemented in a rather bizarre way:
|
|
14
|
+
|
|
15
|
+
> Node uses a
|
|
16
|
+
> [statically compiled, manually updated, hardcoded list][node.pem]
|
|
17
|
+
> of certificate authorities,
|
|
18
|
+
> rather than relying on the system's trust store...
|
|
19
|
+
> [Read more][node/4175]
|
|
20
|
+
|
|
21
|
+
It's somewhat non-intuitive under any OS,
|
|
22
|
+
but Windows differs from most of them
|
|
23
|
+
by having its own trust store,
|
|
24
|
+
fully incompatible with [OpenSSL].
|
|
25
|
+
|
|
26
|
+
This package is intended to
|
|
27
|
+
fetch Root CAs from Windows' store
|
|
28
|
+
(*Trusted Root Certification Authorities*)
|
|
29
|
+
and make them available to
|
|
30
|
+
[Node.js] application with minimal efforts.
|
|
31
|
+
|
|
32
|
+
### Advantages
|
|
33
|
+
|
|
34
|
+
- No internet access is required at all
|
|
35
|
+
- Windows store is updated automatically (in most modern environments)
|
|
36
|
+
- Manually installed Root certificates are used
|
|
37
|
+
- Enterprise trusted certificates (GPO etc.) are made available too
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
For 95% of users:
|
|
42
|
+
|
|
43
|
+
1. Just say `npm install --save win-ca`
|
|
44
|
+
2. Then call `require('win-ca')`.
|
|
45
|
+
3. That's it!
|
|
46
|
+
|
|
47
|
+
If you need more -
|
|
48
|
+
proceed to [API](#api)
|
|
49
|
+
section below.
|
|
50
|
+
|
|
51
|
+
By the way,
|
|
52
|
+
`win-ca` is safe to be used
|
|
53
|
+
under other OSes (not M$ Windows).
|
|
54
|
+
It does nothing there.
|
|
55
|
+
|
|
56
|
+
### Electron
|
|
57
|
+
`win-ca` was adapted to run inside Electron applications
|
|
58
|
+
with no additional configuration
|
|
59
|
+
([asar] supported).
|
|
60
|
+
|
|
61
|
+
See
|
|
62
|
+
[Minimal Electron application using win-ca][electron-win-ca]
|
|
63
|
+
for usage example.
|
|
64
|
+
|
|
65
|
+
### VS Code extension
|
|
66
|
+
|
|
67
|
+
Special [extension](vscode) for [VS Code]
|
|
68
|
+
was created to import `win-ca`
|
|
69
|
+
in context of VS Code's Extension Host.
|
|
70
|
+
|
|
71
|
+
Since all VS Code extensions share the same process,
|
|
72
|
+
root certificates imported by one of them
|
|
73
|
+
are immediately available to others.
|
|
74
|
+
This can allow VS Code extensions to connect to
|
|
75
|
+
(properly configured)
|
|
76
|
+
intranet sites from Windows machines.
|
|
77
|
+
|
|
78
|
+
## API
|
|
79
|
+
<details>
|
|
80
|
+
<summary>
|
|
81
|
+
Click to view...
|
|
82
|
+
</summary>
|
|
83
|
+
|
|
84
|
+
First versions of `win-ca`
|
|
85
|
+
opened Windows' *Trusted Root Certificate Store*,
|
|
86
|
+
fetched certificates,
|
|
87
|
+
deduplicated them and installed to
|
|
88
|
+
`https.globalAgent.options.ca`,
|
|
89
|
+
so they are automatically used for all
|
|
90
|
+
requests with Node.js' `https` module.
|
|
91
|
+
|
|
92
|
+
But sometimes one needs to
|
|
93
|
+
get these certificates to
|
|
94
|
+
do something else.
|
|
95
|
+
For that case,
|
|
96
|
+
full featured API was devised.
|
|
97
|
+
It is the only function
|
|
98
|
+
with numerous parameters
|
|
99
|
+
and operation modes, eg:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
const ca = require('win-ca')
|
|
103
|
+
|
|
104
|
+
rootCAs = []
|
|
105
|
+
// Fetch all certificates in PEM format
|
|
106
|
+
ca({
|
|
107
|
+
format: ca.der2.pem,
|
|
108
|
+
ondata: crt => rootCAs.push(crt)
|
|
109
|
+
})
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Entry points
|
|
113
|
+
|
|
114
|
+
`win-ca` offers three ways of importing:
|
|
115
|
+
|
|
116
|
+
1. Regular `require('win-ca')`
|
|
117
|
+
2. Fallback `require('win-ca/fallback')`
|
|
118
|
+
3. Pure API `require('win-ca/api')`
|
|
119
|
+
|
|
120
|
+
They all export the same API,
|
|
121
|
+
but differ in initialization:
|
|
122
|
+
|
|
123
|
+
1. `win-ca` *does* fetch certificates from
|
|
124
|
+
`Root` store,
|
|
125
|
+
saves them to disk
|
|
126
|
+
and makes them available to
|
|
127
|
+
`https` module with no effort.
|
|
128
|
+
|
|
129
|
+
2. `win-ca/fallback` does the same,
|
|
130
|
+
but it never uses [N-API](#n-api)
|
|
131
|
+
for fetching certificates,
|
|
132
|
+
so it should work
|
|
133
|
+
in all versions of Node.js
|
|
134
|
+
as well as inside Electron application.
|
|
135
|
+
|
|
136
|
+
3. `win-ca/api` does *nothing*,
|
|
137
|
+
just exports API,
|
|
138
|
+
so you decide yourself
|
|
139
|
+
what to do.
|
|
140
|
+
|
|
141
|
+
## API Parameters
|
|
142
|
+
|
|
143
|
+
API function may be called with no parameters,
|
|
144
|
+
but that makes little sense.
|
|
145
|
+
One should pass it object with some fields, ie:
|
|
146
|
+
|
|
147
|
+
- `format`
|
|
148
|
+
defines representation of certificates to fetch.
|
|
149
|
+
Available values are:
|
|
150
|
+
|
|
151
|
+
| Constant | Value | Meaning
|
|
152
|
+
|---|---:|---
|
|
153
|
+
|der2.der | 0 | DER-format (binary, Node's [Buffer][])
|
|
154
|
+
|der2.pem | 1 | PEM-format (text, Base64-encoded)
|
|
155
|
+
|der2.txt | 2 | PEM-format plus some <abbr title="This is SPARTA!!!">laconic</abbr> header
|
|
156
|
+
|der2.asn1| 3 | ASN.1-parsed certificate
|
|
157
|
+
|der2.x509| 4 | Certificate in `node-forge` format (RSA only!)
|
|
158
|
+
|
|
159
|
+
Default value is `der`.
|
|
160
|
+
|
|
161
|
+
See also [der2](#der2) function below.
|
|
162
|
+
|
|
163
|
+
- `store` -
|
|
164
|
+
which Windows' store to use.
|
|
165
|
+
Default is `Root`
|
|
166
|
+
(ie *Trusted Root Certification Authorities*).
|
|
167
|
+
|
|
168
|
+
Windows has a whole lot of Certificate
|
|
169
|
+
stores (eg `Root`, `CA`, `My`, `TrustedPublisher` etc.)
|
|
170
|
+
One can list certificates from
|
|
171
|
+
any of them
|
|
172
|
+
(knowing its name)
|
|
173
|
+
or several stores at once
|
|
174
|
+
(using array for `store` parameter).
|
|
175
|
+
|
|
176
|
+
```js
|
|
177
|
+
var list = []
|
|
178
|
+
require('win-ca/api')({store: ['root', 'ca'], ondata: list})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- `unique`
|
|
182
|
+
whether certificates list
|
|
183
|
+
should be deduplicated.
|
|
184
|
+
Default is `true`
|
|
185
|
+
(no duplicates returned).
|
|
186
|
+
|
|
187
|
+
Use `{unique: false}`
|
|
188
|
+
to see all certificates
|
|
189
|
+
in store.
|
|
190
|
+
|
|
191
|
+
- `ondata` - callback fired for each certificate found.
|
|
192
|
+
|
|
193
|
+
Every certificate will be converted to `format`
|
|
194
|
+
and passed as the first (the only) parameter.
|
|
195
|
+
|
|
196
|
+
As a syntactic sugar,
|
|
197
|
+
array can be passed instead of function,
|
|
198
|
+
it will be populated with certificates.
|
|
199
|
+
|
|
200
|
+
- `onend` - callback fired (with no parameters) at the end of retrieval
|
|
201
|
+
|
|
202
|
+
Useful for asynchronous invocations,
|
|
203
|
+
but works in any case.
|
|
204
|
+
|
|
205
|
+
- `fallback` - boolean flag,
|
|
206
|
+
indicating [N-API](#n-api)
|
|
207
|
+
shouldn't be used
|
|
208
|
+
even if it is available.
|
|
209
|
+
|
|
210
|
+
Default value depends on Node.js version
|
|
211
|
+
(4, 5 and 7 `{fallback: true}`;
|
|
212
|
+
modern versions `{fallback: false}`).
|
|
213
|
+
It is also `true` if Electron is detected.
|
|
214
|
+
|
|
215
|
+
Finally, if `win-ca` has been required as
|
|
216
|
+
`win-ca/fallback`,
|
|
217
|
+
default value for this flag is also
|
|
218
|
+
set to `true`.
|
|
219
|
+
|
|
220
|
+
Note, that one can force [N-API](#n-api) by setting
|
|
221
|
+
`{fallback: false}`,
|
|
222
|
+
but if Node.js cannot proceed,
|
|
223
|
+
exception will be thrown.
|
|
224
|
+
It can be catched,
|
|
225
|
+
but Node.js will nevertheless remain in unstable state,
|
|
226
|
+
so beware.
|
|
227
|
+
|
|
228
|
+
- `async` - boolean flag to make retrieval process asynchronous
|
|
229
|
+
(`false` by default)
|
|
230
|
+
|
|
231
|
+
If `true`, API call returns immediately,
|
|
232
|
+
certificates will be
|
|
233
|
+
fetched later and feed to `ondata` callback.
|
|
234
|
+
Finally `onend` callback will be called.
|
|
235
|
+
|
|
236
|
+
- `generator` - boolean flag to emulate ES6 generator
|
|
237
|
+
(default: `false`)
|
|
238
|
+
|
|
239
|
+
If called with this flag,
|
|
240
|
+
ES6 iterator object is immediately
|
|
241
|
+
returned
|
|
242
|
+
(regular or asynchronous -
|
|
243
|
+
according to `async` flag).
|
|
244
|
+
|
|
245
|
+
```js
|
|
246
|
+
const ca = require('win-ca/api')
|
|
247
|
+
|
|
248
|
+
// Iterate
|
|
249
|
+
for (let der of ca({generator: true})) {
|
|
250
|
+
// Process(der)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Or thus (Node.js v>=6)
|
|
254
|
+
let list = [...ca({generator: true})]
|
|
255
|
+
|
|
256
|
+
// Or even (Node.js v>=10)
|
|
257
|
+
for await(let der of ca({generator: true, async: true})) {
|
|
258
|
+
// await Process(der)
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Note, that if callbacks are set along
|
|
263
|
+
with `generator` flag,
|
|
264
|
+
they will be *also* fired.
|
|
265
|
+
|
|
266
|
+
- `inject` - how to install certificates
|
|
267
|
+
(default: `false`, ie just fetch from store, do not install)
|
|
268
|
+
|
|
269
|
+
If set to `true`,
|
|
270
|
+
certificated fetched
|
|
271
|
+
will be also added to
|
|
272
|
+
`https.globalAgent.options.ca`
|
|
273
|
+
(in PEM format, regardless of `format` parameter),
|
|
274
|
+
so all subsequent calls
|
|
275
|
+
to `https` client methods
|
|
276
|
+
(https.request, https.get etc.)
|
|
277
|
+
will silently use them
|
|
278
|
+
*instead* of built-in ones.
|
|
279
|
+
|
|
280
|
+
If set to `'+'`,
|
|
281
|
+
new *experimental*
|
|
282
|
+
method is used instead:
|
|
283
|
+
`tls.createSecureContext()`
|
|
284
|
+
is patched and
|
|
285
|
+
fetched certificates
|
|
286
|
+
are used *in addition* to
|
|
287
|
+
built-in ones
|
|
288
|
+
(and not only for `https`,
|
|
289
|
+
but for all secure connections).
|
|
290
|
+
|
|
291
|
+
Injection mode can be later
|
|
292
|
+
changed (or disabled)
|
|
293
|
+
with [.inject()](#inject)
|
|
294
|
+
helper function.
|
|
295
|
+
|
|
296
|
+
- `save` - how to save certificates to disk
|
|
297
|
+
(default: `false`, ie use *no* I/O at all)
|
|
298
|
+
|
|
299
|
+
If set to string, or array of strings,
|
|
300
|
+
they will be treated as
|
|
301
|
+
list of candidate folders to save certificates to.
|
|
302
|
+
First one that exists or can be
|
|
303
|
+
(recursively) created will be used.
|
|
304
|
+
|
|
305
|
+
If no valid folder path found,
|
|
306
|
+
saving will be silently discarded.
|
|
307
|
+
|
|
308
|
+
If `{save: true}` used,
|
|
309
|
+
predefined list of folders will be tried:
|
|
310
|
+
+ `pem` folder inside `win-ca` module itself
|
|
311
|
+
+ `.local/win-ca/pem` folder inside user's profile
|
|
312
|
+
|
|
313
|
+
Certificates will be stored into the folder in two formats:
|
|
314
|
+
+ Each certificate as separate text file with special file name
|
|
315
|
+
(mimics behavour of [OpenSSL]'s `c_rehash` utility) -
|
|
316
|
+
suitable for `SSL_CERT_DIR`
|
|
317
|
+
+ All certificates in single `roots.pem` file -
|
|
318
|
+
suitable for `SSL_CERT_FILE`
|
|
319
|
+
|
|
320
|
+
If `win-ca` is required not via `win-ca/api`,
|
|
321
|
+
it calls itself with `{inject: true, save: true}`
|
|
322
|
+
and additionaly sets `ca.path` field
|
|
323
|
+
and `SSL_CERT_DIR` environment variable
|
|
324
|
+
to the folder with certificates saved.
|
|
325
|
+
|
|
326
|
+
- `onsave` - callback called at the end of saving
|
|
327
|
+
(if `save` is truthy).
|
|
328
|
+
|
|
329
|
+
Path to a folder is passed to callback,
|
|
330
|
+
or no parameters (`undefined`)
|
|
331
|
+
if it has been impossible to save certificates to disk.
|
|
332
|
+
|
|
333
|
+
## Helper functions
|
|
334
|
+
|
|
335
|
+
Some internal functions are exposed:
|
|
336
|
+
|
|
337
|
+
### der2
|
|
338
|
+
|
|
339
|
+
```js
|
|
340
|
+
var certificate = ca.der2(format, certificate_in_der_format)
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
Converts certificate from DER
|
|
344
|
+
to
|
|
345
|
+
[format](#api-parameters)
|
|
346
|
+
specified in first parameter.
|
|
347
|
+
|
|
348
|
+
Function `.der2()` is curried:
|
|
349
|
+
|
|
350
|
+
```js
|
|
351
|
+
var toPEM = ca.der2(ca.der2.pem)
|
|
352
|
+
|
|
353
|
+
var pem = toPEM(der)
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### hash
|
|
357
|
+
```js
|
|
358
|
+
var hash = ca.hash(version, certificate_in_der_format)
|
|
359
|
+
```
|
|
360
|
+
Gives certificate hash
|
|
361
|
+
(aka X509_NAME_hash),
|
|
362
|
+
ie 8-character hexadecimal string,
|
|
363
|
+
derived from certificate subject.
|
|
364
|
+
|
|
365
|
+
If version (first parameter) is 0,
|
|
366
|
+
an old algorithm is used
|
|
367
|
+
(aka X509_NAME_hash_old, used in OpenSSL v0.\*),
|
|
368
|
+
else - the new one
|
|
369
|
+
(X509_NAME_hash of OpenSSL v1.\*).
|
|
370
|
+
|
|
371
|
+
Function `.hash()` is also curried:
|
|
372
|
+
|
|
373
|
+
```js
|
|
374
|
+
var hasher = ca.hash()
|
|
375
|
+
console.log(hasher(der))
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### inject
|
|
379
|
+
```js
|
|
380
|
+
ca.inject(mode)
|
|
381
|
+
// or:
|
|
382
|
+
ca.inject(mode, array_of_certificates)
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
Manages the way
|
|
386
|
+
certificates are
|
|
387
|
+
passed to other modules.
|
|
388
|
+
|
|
389
|
+
This function is internally called by API
|
|
390
|
+
when `{inject:}` parameter used.
|
|
391
|
+
|
|
392
|
+
First argument (`mode`) is injection mode:
|
|
393
|
+
|
|
394
|
+
- `false`: no injection, built-in certificates are used
|
|
395
|
+
|
|
396
|
+
- `true`: put certificates to `https.globalAgent.options.ca`
|
|
397
|
+
and use them *instead* of built-in ones for `https` module
|
|
398
|
+
|
|
399
|
+
- `'+'`: new *experimental* mode:
|
|
400
|
+
`tls.createSecureContext()` is patched
|
|
401
|
+
and certificates are used
|
|
402
|
+
*along with* built-in ones.
|
|
403
|
+
This mode should affect all secure connections,
|
|
404
|
+
not just `https` module.
|
|
405
|
+
|
|
406
|
+
Second parameter (`array_of_certificates`)
|
|
407
|
+
is list of certificates to inject.
|
|
408
|
+
If it is omitted,
|
|
409
|
+
previous list is used
|
|
410
|
+
(only inject mode is changed).
|
|
411
|
+
|
|
412
|
+
For example,
|
|
413
|
+
simplest way to test new
|
|
414
|
+
injection mode is:
|
|
415
|
+
```js
|
|
416
|
+
const ca = require('win-ca') // Fetch certificates and start injecting (old way)
|
|
417
|
+
|
|
418
|
+
ca.inject('+') // Switch to new injection mode
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
Note,
|
|
422
|
+
that this function should be called
|
|
423
|
+
before first secure connection is established,
|
|
424
|
+
since every secure connection populates
|
|
425
|
+
different caches,
|
|
426
|
+
that are extremely hard to invalidate.
|
|
427
|
+
Changing injection mode in the
|
|
428
|
+
middle of secure communication
|
|
429
|
+
can lead to unpredictable results.
|
|
430
|
+
|
|
431
|
+
### exe
|
|
432
|
+
|
|
433
|
+
Applications that use `win-ca`
|
|
434
|
+
are sometimes packed / bundled.
|
|
435
|
+
In this case one should find appropriate
|
|
436
|
+
place for binary utility `roots.exe`
|
|
437
|
+
(used in fallback mode,
|
|
438
|
+
which is always the case with Electron apps)
|
|
439
|
+
and then make `win-ca` to find the binary.
|
|
440
|
+
|
|
441
|
+
Function `.exe()` is intended to provide this
|
|
442
|
+
functionality.
|
|
443
|
+
You must call it **before** first invocation of library itself,
|
|
444
|
+
eg:
|
|
445
|
+
```js
|
|
446
|
+
var ca = require('win-ca/api')
|
|
447
|
+
|
|
448
|
+
ca.exe('/full/path/to/roots.exe')
|
|
449
|
+
ca({fallback: true, inject: true})
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
`.exe()` with no parameters switches to
|
|
453
|
+
default location
|
|
454
|
+
(inside `lib` folder).
|
|
455
|
+
In any case it returns previous
|
|
456
|
+
path to `roots.exe`:
|
|
457
|
+
```
|
|
458
|
+
console.log(require('win-ca').exe()) // Where is my root.exe?
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
## Legacy API
|
|
462
|
+
<details>
|
|
463
|
+
<summary>
|
|
464
|
+
Click to view...
|
|
465
|
+
</summary>
|
|
466
|
+
|
|
467
|
+
`win-ca` v2 had another API,
|
|
468
|
+
which is preserved for compatibility,
|
|
469
|
+
but discouraged to use.
|
|
470
|
+
It consists of three functions:
|
|
471
|
+
|
|
472
|
+
* Synchronous:
|
|
473
|
+
+ `.all()`
|
|
474
|
+
+ `.each()`
|
|
475
|
+
* Asynchronous:
|
|
476
|
+
+ `.each.async()`
|
|
477
|
+
|
|
478
|
+
```
|
|
479
|
+
var ca = require('win-ca')
|
|
480
|
+
|
|
481
|
+
do.something.with(ca.all(ca.der2.pem))
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
Note:
|
|
485
|
+
1. All three yield
|
|
486
|
+
certificates
|
|
487
|
+
in [node-forge][]'s format
|
|
488
|
+
by default
|
|
489
|
+
(unlike [modern API](#api),
|
|
490
|
+
that returns DER
|
|
491
|
+
if unspecified by user).
|
|
492
|
+
|
|
493
|
+
Unfortunately, `node-forge` at the time of writing is unable to
|
|
494
|
+
parse non-RSA certificates
|
|
495
|
+
(namely, ECC certificates becoming more popular).
|
|
496
|
+
If your *Trusted Root Certification Authorities* store
|
|
497
|
+
contains modern certificates,
|
|
498
|
+
legacy API calls
|
|
499
|
+
will throw exception.
|
|
500
|
+
To tackle the problem -
|
|
501
|
+
pass them [format](#api-parameters)
|
|
502
|
+
as the first parameter.
|
|
503
|
+
|
|
504
|
+
2. `.all()` deduplicates
|
|
505
|
+
certificates (like [regular API](#api)),
|
|
506
|
+
while both `.each` calls
|
|
507
|
+
may return duplicates
|
|
508
|
+
(`{unique: false}` applied)
|
|
509
|
+
|
|
510
|
+
3. `Root` store always used
|
|
511
|
+
(no way for `store:` option)
|
|
512
|
+
|
|
513
|
+
4. Both `.each` calls require callback
|
|
514
|
+
(with optional `format`)
|
|
515
|
+
|
|
516
|
+
Synchronous `.each()` callback gets single
|
|
517
|
+
argument - certificate
|
|
518
|
+
(in specified format)
|
|
519
|
+
|
|
520
|
+
```js
|
|
521
|
+
var ca = require('win-ca')
|
|
522
|
+
ca.each(ca.der2.x509, crt=>
|
|
523
|
+
console.log(crt.serialNumber)
|
|
524
|
+
)
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
Asynchronous `.each.async()` callback
|
|
528
|
+
gets two parameters:
|
|
529
|
+
+ `error` (which is always `undefined` in this version)
|
|
530
|
+
+ `result` - certificate in requested `format`
|
|
531
|
+
or `undefined` to signal end of retrieval
|
|
532
|
+
|
|
533
|
+
```js
|
|
534
|
+
let ca = require('win-ca')
|
|
535
|
+
|
|
536
|
+
ca.each.async((error, crt)=> {
|
|
537
|
+
if (error) throw error;
|
|
538
|
+
if(crt)
|
|
539
|
+
console.log(forge.pki.certificateToPem(crt))
|
|
540
|
+
else
|
|
541
|
+
console.log("That's all folks!")
|
|
542
|
+
})
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
</details>
|
|
546
|
+
|
|
547
|
+
## N-API
|
|
548
|
+
|
|
549
|
+
Current version uses [N-API],
|
|
550
|
+
so it can be used in [Node.js versions with N-API support][N-API-support],
|
|
551
|
+
i.e. v6 and all versions starting from v8.
|
|
552
|
+
|
|
553
|
+
Thanks to N-API, it is possible to precompile
|
|
554
|
+
[Windows DLL](n-api/crypt32.cpp) and save it to package,
|
|
555
|
+
so no compilation is needed at installation time.
|
|
556
|
+
|
|
557
|
+
For other Node.js versions
|
|
558
|
+
(v4, 5 or 7)
|
|
559
|
+
special [fallback utility](n-api/roots.c) is called
|
|
560
|
+
in the background to fetch the list anyway.
|
|
561
|
+
|
|
562
|
+
If you wish to use this fallback engine
|
|
563
|
+
(even for modern Node.js),
|
|
564
|
+
you can
|
|
565
|
+
```js
|
|
566
|
+
require('win-ca/fallback')
|
|
567
|
+
```
|
|
568
|
+
</details>
|
|
569
|
+
|
|
570
|
+
## Caveats
|
|
571
|
+
|
|
572
|
+
Windows 10 tends to
|
|
573
|
+
have only a few certificates in
|
|
574
|
+
its *Trusted Root Certification Authorities* store
|
|
575
|
+
and [lazily add them to it on first use][win.lazy].
|
|
576
|
+
|
|
577
|
+
If your OS does so,
|
|
578
|
+
`win-ca` will still help to
|
|
579
|
+
connect to your own sites
|
|
580
|
+
(protected by self-signed certificates,
|
|
581
|
+
or by the ones, distributed with GPO),
|
|
582
|
+
but will make connection to
|
|
583
|
+
well-known sites
|
|
584
|
+
(like Google or Twitter) impossible!
|
|
585
|
+
|
|
586
|
+
The simplest remedy is to
|
|
587
|
+
*once* open desired site in
|
|
588
|
+
Internet Explorer / Google Chrome
|
|
589
|
+
(certificate will be *silently* added
|
|
590
|
+
to Root store).
|
|
591
|
+
|
|
592
|
+
Another option is to switch to new
|
|
593
|
+
*experimental* [injection](#inject) method:
|
|
594
|
+
```js
|
|
595
|
+
require('win-ca').inject('+')
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
### Clear `pem` folder on publish
|
|
599
|
+
|
|
600
|
+
If you use `win-ca` in some Electron app or VS Code extension,
|
|
601
|
+
be warned that
|
|
602
|
+
`node_modules/win-ca/pem` folder
|
|
603
|
+
is *highly likely* to be packed into your bundle
|
|
604
|
+
with all root certificates on development machine.
|
|
605
|
+
|
|
606
|
+
You had better remove said folder
|
|
607
|
+
before publishing
|
|
608
|
+
(eg. in `prepack` npm script if it applies).
|
|
609
|
+
|
|
610
|
+
## Building
|
|
611
|
+
|
|
612
|
+
- npm install
|
|
613
|
+
- npm run pretest
|
|
614
|
+
- npm run [nvm$]
|
|
615
|
+
- npm publish
|
|
616
|
+
|
|
617
|
+
This builds both `x86` and `x64` versions with [N-API](#n-api) support.
|
|
618
|
+
For older Node.js versions standalone binary utility is built.
|
|
619
|
+
|
|
620
|
+
## See also
|
|
621
|
+
|
|
622
|
+
- [OpenSSL::Win::Root][] for Ruby version
|
|
623
|
+
- [mac-ca][] for Mac OS version
|
|
624
|
+
|
|
625
|
+
## Credits
|
|
626
|
+
|
|
627
|
+
Uses [node-forge][]
|
|
628
|
+
and used to use [node-ffi-napi][] (ancestor of [node-ffi][]).
|
|
629
|
+
|
|
630
|
+
[node-ffi]: https://github.com/node-ffi/node-ffi
|
|
631
|
+
[node-ffi-napi]: https://github.com/node-ffi-napi/node-ffi-napi
|
|
632
|
+
[node-forge]: https://github.com/digitalbazaar/forge
|
|
633
|
+
[OpenSSL::Win::Root]: https://github.com/ukoloff/openssl-win-root
|
|
634
|
+
[Node.js]: http://nodejs.org/
|
|
635
|
+
[Buffer]: https://nodejs.org/api/buffer.html
|
|
636
|
+
[Ruby]: https://www.ruby-lang.org/
|
|
637
|
+
[node.pem]: https://github.com/nodejs/node/blob/master/src/node_root_certs.h
|
|
638
|
+
[node/4175]: https://github.com/nodejs/node/issues/4175
|
|
639
|
+
[OpenSSL]: https://www.openssl.org/
|
|
640
|
+
[nvm$]: https://github.com/ukoloff/nvms
|
|
641
|
+
[N-API]: https://nodejs.org/api/n-api.html
|
|
642
|
+
[N-API-support]: https://github.com/nodejs/node-addon-api/blob/master/index.js#L17
|
|
643
|
+
[VS Code]: https://code.visualstudio.com/
|
|
644
|
+
[mac-ca]: https://github.com/jfromaniello/mac-ca
|
|
645
|
+
[Electron]: https://electronjs.org/
|
|
646
|
+
[electron-win-ca]: https://github.com/ukoloff/electron-win-ca
|
|
647
|
+
[win.lazy]: https://social.technet.microsoft.com/wiki/contents/articles/3147.pki-certificate-chaining-engine-cce.aspx
|
|
648
|
+
[asar]: https://github.com/electron/asar
|
|
Binary file
|
|
Binary file
|