// ============================================================================ // File: verify_workspace.js // ============================================================================ const fs = require('fs'); const path = require('path'); console.log("\x1b[36m%s\x1b[0m", "=========================================================================="); console.log("\x1b[36m%s\x1b[0m", " [Fritree Audit Guard] Running Strategic Workspace Audit (SHA-256)... "); console.log("\x1b[36m%s\x1b[0m", "=========================================================================="); // List of mandatory core and module files required for proper extension operation const REQUIRED_FILES = [ { name: "manifest.json", path: "manifest.json" }, { name: "rules.json", path: "rules.json" }, { name: "index.html", path: "index.html" }, { name: "style.css", path: "style.css" }, { name: "index.js", path: "index.js" }, { name: "rules.js", path: "rules.js" }, { name: "content_fb.js", path: "content_fb.js" }, { name: "content_wa.js", path: "content_wa.js" }, { name: "package.json", path: "package.json" }, { name: "build.js", path: "build.js" }, { name: "modules/crypto.js", path: "modules/crypto.js" }, { name: "modules/storage.js", path: "modules/storage.js" }, { name: "modules/dashboard.js", path: "modules/dashboard.js" }, { name: "modules/facebook.js", path: "modules/facebook.js" }, { name: "modules/whatsapp.js", path: "modules/whatsapp.js" }, { name: "modules/rotation.js", path: "modules/rotation.js" }, { name: "modules/history.js", path: "modules/history.js" }, { name: "modules/account.js", path: "modules/account.js" }, { name: "modules/wallet.js", path: "modules/wallet.js" }, { name: "modules/migration.js", path: "modules/migration.js" }, { name: "README.md", path: "README.md" } ]; let globalScanPassed = true; /** * 1. Verify existence of certified files */ console.log("\n\x1b[33m%s\x1b[0m", "[1/6] Auditing existence and structure of certified workspace files..."); REQUIRED_FILES.forEach(file => { const fullPath = path.join(__dirname, file.path); if (fs.existsSync(fullPath)) { const stats = fs.statSync(fullPath); console.log(` \x1b[32m✔\x1b[0m Verified: File [${file.name}] is available (size: ${(stats.size / 1024).toFixed(2)} KB)`); } else { console.log(` \x1b[31m✘\x1b[0m Critical Error: File [${file.name}] not found at path: "${file.path}"!`); globalScanPassed = false; } }); /** * 2. Audit structural integrity of JSON configuration files */ console.log("\n\x1b[33m%s\x1b[0m", "[2/6] Auditing integrity of structural configuration files (JSON Validation)..."); const jsonFilesToValidate = ["manifest.json", "rules.json", "package.json"]; jsonFilesToValidate.forEach(fileName => { const fullPath = path.join(__dirname, fileName); if (fs.existsSync(fullPath)) { try { const rawContent = fs.readFileSync(fullPath, 'utf8'); JSON.parse(rawContent); console.log(` \x1b[32m✔\x1b[0m JSON syntax verified successfully: [${fileName}]`); } catch (e) { console.log(` \x1b[31m✘\x1b[0m Syntax error in file [${fileName}]: ${e.message}`); globalScanPassed = false; } } }); /** * 3. Proactively audit scripts for raw unencrypted localStorage/chromeStorage writes */ console.log("\n\x1b[33m%s\x1b[0m", "[3/6] Auditing raw local storage writes and unencrypted session caching..."); const fbContentScriptPath = path.join(__dirname, "content_fb.js"); const waContentScriptPath = path.join(__dirname, "content_wa.js"); const waBackgroundPath = path.join(__dirname, "background.js"); const scanTargetForRawStorageSet = (filePath, fileName) => { if (fs.existsSync(filePath)) { const fileContent = fs.readFileSync(filePath, 'utf8'); // Inspect if raw storage APIs are called bypass-passing the unified FritreeStorage encryption layers const rawLocalStoragePattern = /localStorage\.setItem\s*\(\s*['"`](wa_connected|local_shield_config_matrix)['"`]/g; const chromeStorageRawPattern = /chrome\.storage\.local\.set\s*\(\s*\{\s*(wa_connected|local_shield_config_matrix)/g; const hasRawLocalSet = rawLocalStoragePattern.test(fileContent); const hasRawChromeSet = chromeStorageRawPattern.test(fileContent); if (hasRawLocalSet || hasRawChromeSet) { console.log(` \x1b[31m⚠\x1b[0m Potential security vulnerability in [${fileName}]: Raw/unencrypted session data write detected!`); globalScanPassed = false; } else { console.log(` \x1b[32m✔\x1b[0m Successfully verified [${fileName}]: All storage keys pass through encrypted FritreeStorage.`); } } }; scanTargetForRawStorageSet(fbContentScriptPath, "content_fb.js"); scanTargetForRawStorageSet(waContentScriptPath, "content_wa.js"); scanTargetForRawStorageSet(waBackgroundPath, "background.js"); /** * 4. Verify cryptographic modules are correctly bound to SHA-256 standards */ console.log("\n\x1b[33m%s\x1b[0m", "[4/6] Tracing SHA-256 hash algorithm deployment and legacy signatures..."); const cryptoFilePath = path.join(__dirname, "modules/crypto.js"); const storageFilePath = path.join(__dirname, "modules/storage.js"); if (fs.existsSync(cryptoFilePath) && fs.existsSync(storageFilePath)) { const cryptoContent = fs.readFileSync(cryptoFilePath, 'utf8'); const storageContent = fs.readFileSync(storageFilePath, 'utf8'); const hasSHA256_InCrypto = cryptoContent.includes("SHA-256") || cryptoContent.includes("sha256"); const hasSHA256_InStorage = storageContent.includes("SHA-256") || storageContent.includes("sha256"); const hasObsoleteSHA512_InCrypto = cryptoContent.includes("SHA-512") && !cryptoContent.includes("AES-256-GCM-SHA256"); if (hasSHA256_InCrypto && hasSHA256_InStorage && !hasObsoleteSHA512_InCrypto) { console.log(" \x1b[32m✔\x1b[0m Verified: Cryptography and storage modules utilize SHA-256 for signatures and verification."); } else { console.log(" \x1b[31m✘\x1b[0m Security Error: Signature standards have not been fully upgraded to SHA-256 within core security assets!"); globalScanPassed = false; } } /** * 5. Perform loop audit to detect infinite loops freezing client browser threads */ console.log("\n\x1b[33m%s\x1b[0m", "[5/6] Performing proactive loop audit to prevent browser thread freeze..."); if (fs.existsSync(fbContentScriptPath)) { const fbContent = fs.readFileSync(fbContentScriptPath, 'utf8'); const badLoopPattern = /for\s*\(\s*let\s+c\s*=\s*0\s*;\s*i\s*<\s*cycles\s*;\s*c\s*\+\+\s*\)/g; const hasBadLoop = badLoopPattern.test(fbContent); if (hasBadLoop) { console.log(" \x1b[31m✘\x1b[0m Software Defect Detected: Infinite loop pattern found in content_fb.js!"); globalScanPassed = false; } else { console.log(" \x1b[32m✔\x1b[0m Verified: Execution loops are stable and free of thread-freezing conditions."); } } /** * 6. Audit English LTR configurations on main application markup */ console.log("\n\x1b[33m%s\x1b[0m", "[6/6] Auditing LTR alignment and English language configurations..."); const indexHtmlPath = path.join(__dirname, "index.html"); if (fs.existsSync(indexHtmlPath)) { const htmlContent = fs.readFileSync(indexHtmlPath, 'utf8'); const hasLtrDir = htmlContent.includes('dir="ltr"'); const hasEnglishLang = htmlContent.includes('lang="en"'); if (hasLtrDir && hasEnglishLang) { console.log(" \x1b[32m✔\x1b[0m Layout dir='ltr' and English language code successfully activated in [index.html]."); } else { console.log(" \x1b[31m⚠\x1b[0m Technical Alert: Please ensure dir='ltr' and lang='en' are declared to prevent UI misalignments."); globalScanPassed = false; } } // System scan results report summary console.log("\n\x1b[36m%s\x1b[0m", "=========================================================================="); if (globalScanPassed) { console.log("\x1b[32m%s\x1b[0m", " 🎉 [Audit Guard] SUCCESS: Workspace environment is intact and complies with SHA-256 security standards! "); console.log("\x1b[32m%s\x1b[0m", " The extension is fully optimized and ready to dispatch secured campaigns on your browser."); } else { console.log("\x1b[31m%s\x1b[0m", " ❌ [Audit Guard] WARNING: System anomalies or vulnerabilities detected. Please resolve according to audit output. "); } console.log("\x1b[36m%s\x1b[0m", "==========================================================================");