1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const thunkify = require('thunkify');
|
7 | const AnyProxy = require('../proxy');
|
8 | const logUtil = require('../lib/log');
|
9 |
|
10 | const certMgr = AnyProxy.utils.certMgr;
|
11 |
|
12 | function checkRootCAExists() {
|
13 | return certMgr.isRootCAFileExists();
|
14 | }
|
15 |
|
16 | module.exports = function *() {
|
17 | try {
|
18 | if (!checkRootCAExists()) {
|
19 | logUtil.warn('Missing root CA, generating now');
|
20 | yield thunkify(certMgr.generateRootCA)();
|
21 | yield certMgr.trustRootCA();
|
22 | } else {
|
23 | const isCATrusted = yield thunkify(certMgr.ifRootCATrusted)();
|
24 | if (!isCATrusted) {
|
25 | logUtil.warn('ROOT CA NOT INSTALLED YET');
|
26 | yield certMgr.trustRootCA();
|
27 | }
|
28 | }
|
29 | } catch (e) {
|
30 | console.error(e);
|
31 | }
|
32 | };
|
33 |
|