mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-21 19:04:23 +00:00
34 lines
788 B
JavaScript
34 lines
788 B
JavaScript
/**
|
|
* check if root CA exists and installed
|
|
* will prompt to generate when needed
|
|
*/
|
|
|
|
const thunkify = require('thunkify');
|
|
const AnyProxy = require('../dist/proxy');
|
|
const logUtil = require('../dist/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);
|
|
}
|
|
};
|
|
|