mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +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
@@ -7,8 +7,8 @@ const { generateRootCA, loadRootCA, generateLeafCert } = require("./rootCA");
|
||||
* Generate Root CA certificate (one-time setup)
|
||||
* This replaces the old static wildcard cert approach
|
||||
*/
|
||||
async function generateCert() {
|
||||
return await generateRootCA();
|
||||
function generateCert() {
|
||||
return generateRootCA();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ function isCertExpired(certPath) {
|
||||
* Generate Root CA certificate (only once, auto-regenerate if expired)
|
||||
* This Root CA will sign all dynamic leaf certificates
|
||||
*/
|
||||
async function generateRootCA() {
|
||||
function generateRootCA() {
|
||||
const exists = fs.existsSync(ROOT_CA_KEY_PATH) && fs.existsSync(ROOT_CA_CERT_PATH);
|
||||
if (exists && !isCertExpired(ROOT_CA_CERT_PATH)) {
|
||||
console.log("✅ Root CA already exists");
|
||||
|
||||
+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