mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-23 04:09:49 +00:00
fix(mitm): generate root ca on server startup (#2228)
Direct MITM server startup read rootCA.key/.crt immediately and exited when either was missing, bypassing the manager.js CA setup path. - generate Root CA from server.js when key/cert is missing - make generateRootCA()/generateCert() synchronous to avoid a startup race before readFileSync - add unit test covering synchronous Root CA creation Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
decolua
co-authored by
Cursor
parent
0b3c794075
commit
182c849979
+6
-1
@@ -9,7 +9,7 @@ const { execSync } = require("child_process");
|
||||
const { log, err, dumpRequest, createResponseDumper, clearDumpDir } = require("./logger");
|
||||
const { IS_DEV, LSOF_BIN, TARGET_HOSTS, URL_PATTERNS, MODEL_SYNONYMS, MODEL_PATTERNS, MODEL_NO_MAP, getToolForHost } = require("./config");
|
||||
const { DATA_DIR, MITM_DIR } = require("./paths");
|
||||
const { getCertForDomain } = require("./cert/generate");
|
||||
const { generateCert, getCertForDomain } = require("./cert/generate");
|
||||
const { getMitmAlias } = require("./dbReader");
|
||||
const { applyAntigravityIdeVersionOverride } = require("./antigravityIdeVersion");
|
||||
const LOCAL_PORT = 443;
|
||||
@@ -57,6 +57,11 @@ function sniCallback(servername, cb) {
|
||||
|
||||
let sslOptions;
|
||||
try {
|
||||
if (!fs.existsSync(path.join(MITM_DIR, "rootCA.key")) || !fs.existsSync(path.join(MITM_DIR, "rootCA.crt"))) {
|
||||
log("Root CA missing, generating...");
|
||||
generateCert();
|
||||
}
|
||||
|
||||
const rootKey = fs.readFileSync(path.join(MITM_DIR, "rootCA.key"));
|
||||
const rootCert = fs.readFileSync(path.join(MITM_DIR, "rootCA.crt"));
|
||||
rootCAPem = rootCert.toString("utf8");
|
||||
|
||||
Reference in New Issue
Block a user