add ca helper when run anyproxy -i

check and help to generate the root CA when run in https interception mode, and install the CA after user's confirmation (Mac only for now)
This commit is contained in:
砚然
2018-06-30 18:01:53 +08:00
parent 71477d5aae
commit 0241b90e4d
7 changed files with 202 additions and 99 deletions

33
bin/rootCACheck.js Normal file
View File

@@ -0,0 +1,33 @@
/**
* check if root CA exists and installed
* will prompt to generate when needed
*/
const thunkify = require('thunkify');
const AnyProxy = require('../proxy');
const logUtil = require('../lib/log');
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);
}
};