Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix(mitm): add Linux cert install and skip sudo password when root

Muhammad Tamir1064b85a7d52
diff --git a/src/app/api/settings/mitm/route.ts b/src/app/api/settings/mitm/route.ts
index 247742ff69..dd56242e5b 100644
--- a/src/app/api/settings/mitm/route.ts
+++ b/src/app/api/settings/mitm/route.ts
@@ -205,12 +205,14 @@ export async function PUT(request: Request) {
if (typeof parsed.data.enabled === "boolean") {
const { getCachedPassword, setCachedPassword, startMitm, stopMitm } =
await import("@/mitm/manager");
+ const { isRoot } = await import("@/mitm/systemCommands");
const isWin = process.platform === "win32";
+ const isRootUser = !isWin && isRoot();
const sudoPassword = parsed.data.sudoPassword || getCachedPassword() || "";
if (parsed.data.enabled) {
const apiKey = await resolveApiKey(parsed.data.keyId || null, parsed.data.apiKey || null);
- if (!apiKey || (!isWin && !sudoPassword)) {
+ if (!apiKey || (!isWin && !isRootUser && !sudoPassword)) {
return NextResponse.json(
{ error: isWin ? "Missing apiKey" : "Missing apiKey or sudoPassword" },
{ status: 400 }
@@ -219,7 +221,7 @@ export async function PUT(request: Request) {
await startMitm(apiKey, sudoPassword, { port: config.port });
if (!isWin) setCachedPassword(sudoPassword);
} else {
- if (!isWin && !sudoPassword) {
+ if (!isWin && !isRootUser && !sudoPassword) {
return NextResponse.json({ error: "Missing sudoPassword" }, { status: 400 });
}
await stopMitm(sudoPassword);
diff --git a/src/mitm/cert/install.ts b/src/mitm/cert/install.ts
index 1b876eca02..4f6a100aa1 100644
--- a/src/mitm/cert/install.ts
+++ b/src/mitm/cert/install.ts
@@ -9,6 +9,11 @@ import {
} from "../systemCommands.ts";
const IS_WIN = process.platform === "win32";
+const IS_MAC = process.platform === "darwin";
+
+const LINUX_CERT_NAME = "omniroute-mitm.crt";
+const LINUX_CA_DIR = "/usr/local/share/ca-certificates";
+const LINUX_CERT_DEST = `${LINUX_CA_DIR}/${LINUX_CERT_NAME}`;
// Get SHA1 fingerprint from cert file using Node.js crypto
function getCertFingerprint(certPath: string): string {
@@ -25,10 +30,9 @@ function getCertFingerprint(certPath: string): string {
* Check if certificate is already installed in system store
*/
export async function checkCertInstalled(certPath: string): Promise<boolean> {
- if (IS_WIN) {
- return checkCertInstalledWindows(certPath);
- }
- return checkCertInstalledMac(certPath);
+ if (IS_WIN) return checkCertInstalledWindows(certPath);
+ if (IS_MAC) return checkCertInstalledMac(certPath);
+ return checkCertInstalledLinux(certPath);
}
async function checkCertInstalledMac(certPath: string): Promise<boolean> {
@@ -46,6 +50,15 @@ async function checkCertInstalledMac(certPath: string): Promise<boolean> {
}
}
+async function checkCertInstalledLinux(certPath: string): Promise<boolean> {
+ try {
+ if (!fs.existsSync(LINUX_CERT_DEST)) return false;
+ return getCertFingerprint(certPath) === getCertFingerprint(LINUX_CERT_DEST);
+ } catch {
+ return false;
+ }
+}
+
async function checkCertInstalledWindows(_certPath: string): Promise<boolean> {
try {
await execFileText("certutil", ["-store", "Root", "daily-cloudcode-pa.googleapis.com"]);
@@ -71,8 +84,10 @@ export async function installCert(sudoPassword: string, certPath: string): Promi
if (IS_WIN) {
await installCertWindows(certPath);
- } else {
+ } else if (IS_MAC) {
await installCertMac(sudoPassword, certPath);
+ } else {
+ await installCertLinux(sudoPassword, certPath);
}
}
@@ -103,6 +118,20 @@ async function installCertMac(sudoPassword: string, certPath: string): Promise<v
}
}
+async function installCertLinux(sudoPassword: string, certPath: string): Promise<void> {
+ try {
+ await execFileWithPassword("sudo", ["-S", "mkdir", "-p", LINUX_CA_DIR], sudoPassword);
+ await execFileWithPassword("sudo", ["-S", "cp", certPath, LINUX_CERT_DEST], sudoPassword);
+ await execFileWithPassword("sudo", ["-S", "update-ca-certificates"], sudoPassword);
+ } catch (error) {
+ const message = getErrorMessage(error);
+ const msg = message.includes("canceled")
+ ? "User canceled authorization"
+ : "Certificate install failed";
+ throw new Error(msg);
+ }
+}
+
async function installCertWindows(certPath: string): Promise<void> {
await runElevatedPowerShell(`
$certPath = ${quotePowerShell(certPath)};
@@ -124,8 +153,10 @@ export async function uninstallCert(sudoPassword: string, certPath: string): Pro
if (IS_WIN) {
await uninstallCertWindows();
- } else {
+ } else if (IS_MAC) {
await uninstallCertMac(sudoPassword, certPath);
+ } else {
+ await uninstallCertLinux(sudoPassword, certPath);
}
}
@@ -150,6 +181,17 @@ async function uninstallCertMac(sudoPassword: string, certPath: string): Promise
}
}
+async function uninstallCertLinux(sudoPassword: string, certPath: string): Promise<void> {
+ try {
+ if (fs.existsSync(LINUX_CERT_DEST)) {
+ await execFileWithPassword("sudo", ["-S", "rm", "-f", LINUX_CERT_DEST], sudoPassword);
+ }
+ await execFileWithPassword("sudo", ["-S", "update-ca-certificates", "--fresh"], sudoPassword);
+ } catch (err) {
+ throw new Error("Failed to uninstall certificate");
+ }
+}
+
async function uninstallCertWindows(): Promise<void> {
await runElevatedPowerShell(`
$proc = Start-Process certutil -ArgumentList @('-delstore','Root','daily-cloudcode-pa.googleapis.com') -Verb RunAs -Wait -PassThru;