2018-06-30 18:01:53 +08:00
|
|
|
/**
|
|
|
|
* check if root CA exists and installed
|
|
|
|
* will prompt to generate when needed
|
|
|
|
*/
|
|
|
|
|
|
|
|
const thunkify = require('thunkify');
|
2018-07-29 22:34:55 +08:00
|
|
|
const AnyProxy = require('../dist/proxy');
|
2018-07-11 16:00:47 +08:00
|
|
|
const logUtil = require('../dist/log');
|
2018-06-30 18:01:53 +08:00
|
|
|
|
|
|
|
const certMgr = AnyProxy.utils.certMgr;
|
|
|
|
|
|
|
|
function checkRootCAExists() {
|
|
|
|
return certMgr.isRootCAFileExists();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function *() {
|
|
|
|
try {
|
|
|
|
if (!checkRootCAExists()) {
|
|
|
|
logUtil.warn('Missing root CA, generating now');
|
|
|
|
yield thunkify(certMgr.generateRootCA)();
|
|
|
|
yield certMgr.trustRootCA();
|
|
|
|
} else {
|
|
|
|
const isCATrusted = yield thunkify(certMgr.ifRootCATrusted)();
|
|
|
|
if (!isCATrusted) {
|
|
|
|
logUtil.warn('ROOT CA NOT INSTALLED YET');
|
|
|
|
yield certMgr.trustRootCA();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|