UNPKG

782 BJavaScriptView Raw
1/**
2* check if root CA exists and installed
3* will prompt to generate when needed
4*/
5
6const thunkify = require('thunkify');
7const AnyProxy = require('../proxy');
8const logUtil = require('../lib/log');
9
10const certMgr = AnyProxy.utils.certMgr;
11
12function checkRootCAExists() {
13 return certMgr.isRootCAFileExists();
14}
15
16module.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