Fix : MITM

This commit is contained in:
decolua
2026-03-14 23:59:22 +07:00
parent f264bb9a23
commit 1dd5d60724
10 changed files with 151 additions and 65 deletions
+9 -8
View File
@@ -2,6 +2,7 @@ const fs = require("fs");
const crypto = require("crypto");
const { exec } = require("child_process");
const { execWithPassword } = require("../dns/dnsConfig.js");
const { log, err } = require("../logger");
const IS_WIN = process.platform === "win32";
const IS_MAC = process.platform === "darwin";
@@ -60,7 +61,7 @@ async function installCert(sudoPassword, certPath) {
const isInstalled = await checkCertInstalled(certPath);
if (isInstalled) {
console.log(" Certificate already installed");
log("🔐 Cert: already trusted ✅");
return;
}
@@ -79,7 +80,7 @@ async function installCertMac(sudoPassword, certPath) {
const install = `security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "${certPath}"`;
try {
await execWithPassword(`${deleteOld} && ${install}`, sudoPassword);
console.log(`Installed certificate to system keychain: ${certPath}`);
log("🔐 Cert: installed to system keychain");
} catch (error) {
const msg = error.message?.includes("canceled") ? "User canceled authorization" : "Certificate install failed";
throw new Error(msg);
@@ -95,7 +96,7 @@ async function installCertWindows(certPath) {
{ windowsHide: true },
(error) => {
if (error) reject(new Error(`Failed to install certificate: ${error.message}`));
else { console.log("✅ Installed certificate to Windows Root store"); resolve(); }
else { log("🔐 Cert: installed to Windows Root store"); resolve(); }
}
);
});
@@ -107,7 +108,7 @@ async function installCertWindows(certPath) {
async function uninstallCert(sudoPassword, certPath) {
const isInstalled = await checkCertInstalled(certPath);
if (!isInstalled) {
console.log("Certificate not found in system store");
log("🔐 Cert: not found in system store");
return;
}
@@ -125,7 +126,7 @@ async function uninstallCertMac(sudoPassword, certPath) {
const command = `security delete-certificate -Z "${fingerprint}" /Library/Keychains/System.keychain`;
try {
await execWithPassword(command, sudoPassword);
console.log("✅ Uninstalled certificate from system keychain");
log("🔐 Cert: uninstalled from system keychain");
} catch (err) {
throw new Error("Failed to uninstall certificate");
}
@@ -139,7 +140,7 @@ async function uninstallCertWindows() {
{ windowsHide: true },
(error) => {
if (error) reject(new Error(`Failed to uninstall certificate: ${error.message}`));
else { console.log("✅ Uninstalled certificate from Windows Root store"); resolve(); }
else { log("🔐 Cert: uninstalled from Windows Root store"); resolve(); }
}
);
});
@@ -156,7 +157,7 @@ async function installCertLinux(sudoPassword, certPath) {
const cmd = `cp "${certPath}" "${destFile}" && (update-ca-certificates 2>/dev/null || update-ca-trust 2>/dev/null || true)`;
try {
await execWithPassword(cmd, sudoPassword);
console.log("✅ Installed certificate to Linux trust store");
log("🔐 Cert: installed to Linux trust store");
} catch (error) {
throw new Error("Certificate install failed");
}
@@ -167,7 +168,7 @@ async function uninstallCertLinux(sudoPassword) {
const cmd = `rm -f "${destFile}" && (update-ca-certificates 2>/dev/null || update-ca-trust 2>/dev/null || true)`;
try {
await execWithPassword(cmd, sudoPassword);
console.log("✅ Uninstalled certificate from Linux trust store");
log("🔐 Cert: uninstalled from Linux trust store");
} catch (error) {
throw new Error("Failed to uninstall certificate");
}