fix: resolve MITM not working when connecting Antigravity (#1399)
This commit is contained in:
@@ -82,10 +82,13 @@ async function installCertMac(sudoPassword, certPath) {
|
||||
}
|
||||
|
||||
async function installCertWindows(certPath) {
|
||||
// Use PowerShell elevated to add cert to Root store
|
||||
const psCommand = `Start-Process certutil -ArgumentList '-addstore','Root','${certPath.replace(/'/g, "''")}' -Verb RunAs -Wait`;
|
||||
// Use PowerShell elevated to add cert to Root store and capture exit code
|
||||
const psScript = `
|
||||
$proc = Start-Process certutil -ArgumentList '-addstore','Root','${certPath.replace(/'/g, "''")}' -Verb RunAs -Wait -PassThru;
|
||||
if ($proc.ExitCode -ne 0) { throw "certutil exited with code $($proc.ExitCode)" }
|
||||
`;
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`powershell -Command "${psCommand}"`, (error) => {
|
||||
exec(`powershell -Command "${psScript.replace(/\n/g, " ")}"`, (error) => {
|
||||
if (error) {
|
||||
reject(new Error(`Failed to install certificate: ${error.message}`));
|
||||
} else {
|
||||
|
||||
@@ -30,8 +30,11 @@ export function execWithPassword(command, password) {
|
||||
*/
|
||||
function execElevatedWindows(command) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const psCommand = `Start-Process cmd -ArgumentList '/c','${command.replace(/'/g, "''")}' -Verb RunAs -Wait`;
|
||||
exec(`powershell -Command "${psCommand}"`, (error, stdout, stderr) => {
|
||||
const psScript = `
|
||||
$proc = Start-Process cmd -ArgumentList '/c','${command.replace(/'/g, "''")}' -Verb RunAs -Wait -PassThru;
|
||||
if ($proc.ExitCode -ne 0) { throw "Elevated command exited with code $($proc.ExitCode)" }
|
||||
`;
|
||||
exec(`powershell -Command "${psScript.replace(/\n/g, " ")}"`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(new Error(`Elevated command failed: ${error.message}\n${stderr}`));
|
||||
} else {
|
||||
@@ -50,7 +53,7 @@ export function checkDNSEntry() {
|
||||
const lines = hostsContent.split(/\r?\n/);
|
||||
return lines.some((line) => {
|
||||
const parts = line.trim().split(/\s+/);
|
||||
return parts.length >= 2 && parts[0] === "127.0.0.1" && parts.some(p => p === TARGET_HOST);
|
||||
return parts.length >= 2 && parts[0] === "127.0.0.1" && parts.some((p) => p === TARGET_HOST);
|
||||
});
|
||||
} catch {
|
||||
return false;
|
||||
|
||||
+4
-1
@@ -25,11 +25,14 @@ export function clearCachedPassword() {
|
||||
|
||||
const PID_FILE = path.join(resolveDataDir(), "mitm", ".mitm.pid");
|
||||
const MITM_SERVER_URL = new URL("./server.cjs", import.meta.url);
|
||||
const MITM_SERVER_PATH =
|
||||
const urlPath =
|
||||
process.platform === "win32" && MITM_SERVER_URL.pathname.startsWith("/")
|
||||
? decodeURIComponent(MITM_SERVER_URL.pathname.slice(1))
|
||||
: decodeURIComponent(MITM_SERVER_URL.pathname);
|
||||
|
||||
const cwdPath = path.join(process.cwd(), "src", "mitm", "server.cjs");
|
||||
const MITM_SERVER_PATH = fs.existsSync(cwdPath) ? cwdPath : urlPath;
|
||||
|
||||
// Check if a PID is alive
|
||||
function isProcessAlive(pid) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user