diff --git a/AGENTS.md b/AGENTS.md index 505903d..4aeeff3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -71,6 +71,29 @@ If a required command fails or emits a warning from project code, fix it in the ## Lessons +- Hiddify can rename Linux release assets and wrap its Windows portable files + in an outer directory. Verify the publisher's asset names and SHA-256 values, + assert the real ZIP layout in the installer fixture, and publish the complete + directory only after locating the executable. Stage explicit files after + frontend verification because TypeScript rewrites its tracked build cache. + Join filesystem path components separately in fixtures as well as native + installer code so the path source contract passes on every host. +- Keep Hiddify executable inspection in the environment apps collector. Inline + diagnostics for the misplaced ZIP push the shared environment collector over + Clippy's line limit. Bind the path from `TempDir::keep` when retaining a + failed rollback's backup. +- A spawned browser opener is not a successful handoff. Check the launcher exit + status and pass Windows URLs as data to the system association resolver. + Linux `xdg-open` can stay attached to the browser, so leave a still-running + process alive after the handoff wait (ADR 0075). + +- Parallel PRs can reserve the same ADR number and version. Keep both ADRs, + renumber the incoming one, and sync the next version from the root + `version` file after retaining the current main lockfile. +- A pinned fallback does not pin an installer that tries `releases/latest` + first. Hiddify's automatic installer and manual fallback guide must use the + same tested release on Linux and Windows (ADR 0139). + - The advisory database can make an unchanged lockfile fail the gate. Update vulnerable transitive crates through Cargo and replace unmaintained direct dependencies. The `chrono` migration must preserve RFC 3339 strings in diff --git a/Cargo.lock b/Cargo.lock index e557e79..02f8caf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2044,7 +2044,7 @@ dependencies = [ [[package]] name = "iran-split-cli" -version = "6.2.94" +version = "6.2.96" dependencies = [ "async-trait", "clap", @@ -2062,7 +2062,7 @@ dependencies = [ [[package]] name = "iran-split-clients" -version = "6.2.94" +version = "6.2.96" dependencies = [ "async-trait", "ipnet", @@ -2078,7 +2078,7 @@ dependencies = [ [[package]] name = "iran-split-config" -version = "6.2.94" +version = "6.2.96" dependencies = [ "hex", "rand 0.9.5", @@ -2091,7 +2091,7 @@ dependencies = [ [[package]] name = "iran-split-core" -version = "6.2.94" +version = "6.2.96" dependencies = [ "async-trait", "iran-split-config", @@ -2108,7 +2108,7 @@ dependencies = [ [[package]] name = "iran-split-desktop" -version = "6.2.94" +version = "6.2.96" dependencies = [ "dirs 6.0.0", "flate2", @@ -2150,7 +2150,7 @@ dependencies = [ [[package]] name = "iran-split-helper" -version = "6.2.94" +version = "6.2.96" dependencies = [ "clap", "hex", @@ -2175,7 +2175,7 @@ dependencies = [ [[package]] name = "iran-split-helper-winacl" -version = "6.2.94" +version = "6.2.96" dependencies = [ "tokio", "windows", @@ -2183,7 +2183,7 @@ dependencies = [ [[package]] name = "iran-split-ipc" -version = "6.2.94" +version = "6.2.96" dependencies = [ "bytes", "serde", @@ -2195,7 +2195,7 @@ dependencies = [ [[package]] name = "iran-split-mihomo" -version = "6.2.94" +version = "6.2.96" dependencies = [ "futures-util", "hex", @@ -2218,7 +2218,7 @@ dependencies = [ [[package]] name = "iran-split-netstats" -version = "6.2.94" +version = "6.2.96" dependencies = [ "libc", "tempfile", @@ -2227,7 +2227,7 @@ dependencies = [ [[package]] name = "iran-split-platform-linux" -version = "6.2.94" +version = "6.2.96" dependencies = [ "async-trait", "hex", @@ -2251,7 +2251,7 @@ dependencies = [ [[package]] name = "iran-split-platform-macos" -version = "6.2.94" +version = "6.2.96" dependencies = [ "async-trait", "hex", @@ -2275,7 +2275,7 @@ dependencies = [ [[package]] name = "iran-split-platform-win" -version = "6.2.94" +version = "6.2.96" dependencies = [ "async-trait", "iran-split-clients", @@ -2298,7 +2298,7 @@ dependencies = [ [[package]] name = "iran-split-rules" -version = "6.2.94" +version = "6.2.96" dependencies = [ "async-trait", "hex", @@ -2320,7 +2320,7 @@ dependencies = [ [[package]] name = "iran-split-taskbar" -version = "6.2.94" +version = "6.2.96" dependencies = [ "iran-split-config", "objc2", diff --git a/Cargo.toml b/Cargo.toml index 05f995e..4fcaad1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ members = [ ] [workspace.package] -version = "6.2.94" +version = "6.2.96" edition = "2021" license = "MIT OR Apache-2.0" rust-version = "1.88" diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 294a39a..4fc7155 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -1,6 +1,6 @@ { "name": "@iran-split/desktop", - "version": "6.2.94", + "version": "6.2.96", "private": true, "type": "module", "scripts": { diff --git a/apps/desktop/src/api/mock.ts b/apps/desktop/src/api/mock.ts index e26b709..5b0102c 100644 --- a/apps/desktop/src/api/mock.ts +++ b/apps/desktop/src/api/mock.ts @@ -563,11 +563,11 @@ function guideFor(id: string): InstallGuide { return { id, title: linux ? "Install Hiddify on Linux" : "Install Hiddify on Windows", - download_url: "https://github.com/hiddify/hiddify-app/releases/latest", + download_url: `https://github.com/hiddify/hiddify-app/releases/download/v5.9.15/${linux ? "Hiddify-Linux-x64.AppImage" : "Hiddify-Windows-Setup-x64.exe"}`, steps: linux ? [ - "Download Hiddify-Linux-x64-AppImage.AppImage from the official GitHub release.", - "chmod +x Hiddify-Linux-x64-AppImage.AppImage", + "Download Hiddify-Linux-x64.AppImage from the official GitHub release.", + "chmod +x Hiddify-Linux-x64.AppImage", "Move it to ~/.local/share/biflow/apps/Hiddify.AppImage", "Restart BiFlow and press Connect.", ] diff --git a/apps/desktop/src/components/ClientRegistry.test.tsx b/apps/desktop/src/components/ClientRegistry.test.tsx index 0d85e28..bbf3bb6 100644 --- a/apps/desktop/src/components/ClientRegistry.test.tsx +++ b/apps/desktop/src/components/ClientRegistry.test.tsx @@ -332,6 +332,7 @@ describe("ClientRegistry profile picker", () => { }); it("offers OpenVPN download on the Windscribe catalog and missing-binary banner", async () => { + useAppStore.setState({ boot: { platform: "linux" } as BootstrapResult }); vi.mocked(desktop.clientBinaryInstalled).mockResolvedValue(false); render(); @@ -347,7 +348,7 @@ describe("ClientRegistry profile picker", () => { within(row).getByRole("button", { name: "Download OpenVPN" }), ); expect(desktop.openUrl).toHaveBeenCalledWith( - "https://openvpn.net/community-downloads/", + "https://openvpn.net/community-docs/installing-openvpn/", ); const card = screen.getByTestId("client-card-windscribe"); @@ -362,29 +363,36 @@ describe("ClientRegistry profile picker", () => { within(missingBanner).getByRole("button", { name: "Download OpenVPN" }), ); expect(desktop.openUrl).toHaveBeenLastCalledWith( - "https://openvpn.net/community-downloads/", + "https://openvpn.net/community-docs/installing-openvpn/", ); }); - it("reports a failed macOS OpenVPN download page handoff", async () => { - useAppStore.setState({ boot: { platform: "macos" } as BootstrapResult }); - vi.mocked(desktop.openUrl).mockRejectedValueOnce("browser handoff failed"); - render(); + it.each([ + ["macos", "https://formulae.brew.sh/formula/openvpn"], + ["linux", "https://openvpn.net/community-docs/installing-openvpn/"], + ["windows", "https://openvpn.net/community/"], + ] as const)( + "reports a failed %s OpenVPN download page handoff", + async (platform, url) => { + useAppStore.setState({ boot: { platform } as BootstrapResult }); + vi.mocked(desktop.openUrl).mockRejectedValueOnce( + "browser handoff failed", + ); + render(); - await userEvent.click(screen.getByRole("button", { name: "Add client" })); - const row = screen.getByTestId("client-catalog-openvpn"); - await userEvent.click( - within(row).getByRole("button", { name: "Download OpenVPN" }), - ); + await userEvent.click(screen.getByRole("button", { name: "Add client" })); + const row = screen.getByTestId("client-catalog-openvpn"); + await userEvent.click( + within(row).getByRole("button", { name: "Download OpenVPN" }), + ); - expect(desktop.openUrl).toHaveBeenCalledWith( - "https://formulae.brew.sh/formula/openvpn", - ); - expect(useAppStore.getState().toast).toMatchObject({ - text: "Could not open the download page.", - tone: "danger", - }); - }); + expect(desktop.openUrl).toHaveBeenCalledWith(url); + expect(useAppStore.getState().toast).toMatchObject({ + text: "Could not open the download page.", + tone: "danger", + }); + }, + ); it("leaves the path unchanged when the picker is cancelled", async () => { const updateClient = vi.fn(); diff --git a/apps/desktop/src/lib/presets.test.ts b/apps/desktop/src/lib/presets.test.ts index 7e803e8..f0fa409 100644 --- a/apps/desktop/src/lib/presets.test.ts +++ b/apps/desktop/src/lib/presets.test.ts @@ -14,7 +14,7 @@ describe("preset downloads", () => { "downloadWindscribeConfig", ]); expect(downloadUrlFor(links[0]!.spec, "linux")).toBe( - "https://openvpn.net/community-downloads/", + "https://openvpn.net/community-docs/installing-openvpn/", ); expect(downloadUrlFor(links[1]!.spec, "linux")).toBe( "https://windscribe.com/getconfig/openvpn", diff --git a/apps/desktop/src/lib/presets.ts b/apps/desktop/src/lib/presets.ts index 805b364..f80f00b 100644 --- a/apps/desktop/src/lib/presets.ts +++ b/apps/desktop/src/lib/presets.ts @@ -50,8 +50,8 @@ export const PRESETS: PresetSpec[] = [ installHint: "Install OpenVPN and choose a .ovpn profile. BiFlow never lets it take the default route.", downloads: { - linux: "https://openvpn.net/community-downloads/", - windows: "https://openvpn.net/community-downloads/", + linux: "https://openvpn.net/community-docs/installing-openvpn/", + windows: "https://openvpn.net/community/", macos: "https://formulae.brew.sh/formula/openvpn", }, }, @@ -64,8 +64,10 @@ export const PRESETS: PresetSpec[] = [ installHint: "Run Happ and expose a local SOCKS or mixed port (default 10808).", downloads: { - linux: "https://www.happ.su/main/download", - windows: "https://www.happ.su/main/download", + linux: + "https://github.com/Happ-proxy/happ-desktop/releases/latest/download/Happ.linux.x64.deb", + windows: + "https://github.com/Happ-proxy/happ-desktop/releases/latest/download/setup-Happ.x64.exe", macos: "https://github.com/Happ-proxy/happ-desktop/releases/latest/download/Happ.macOS.universal.dmg", }, diff --git a/crates/iran-split-config/src/clients.rs b/crates/iran-split-config/src/clients.rs index c83f7db..e48a757 100644 --- a/crates/iran-split-config/src/clients.rs +++ b/crates/iran-split-config/src/clients.rs @@ -214,8 +214,8 @@ const OPENVPN_SPEC: PresetSpec = PresetSpec { install_hint: "Install OpenVPN and choose a .ovpn profile. BiFlow never lets it take the default route.", downloads: PresetDownloads { - linux: "https://openvpn.net/community-downloads/", - windows: "https://openvpn.net/community-downloads/", + linux: "https://openvpn.net/community-docs/installing-openvpn/", + windows: "https://openvpn.net/community/", macos: "https://formulae.brew.sh/formula/openvpn", }, }; @@ -246,8 +246,8 @@ const HAPP_SPEC: PresetSpec = PresetSpec { macos_bypass: &["Happ", "*Happ*", "sing-box", "xray", "v2ray"], install_hint: "Run Happ and expose a local SOCKS or mixed port (default 10808).", downloads: PresetDownloads { - linux: "https://www.happ.su/main/download", - windows: "https://www.happ.su/main/download", + linux: "https://github.com/Happ-proxy/happ-desktop/releases/latest/download/Happ.linux.x64.deb", + windows: "https://github.com/Happ-proxy/happ-desktop/releases/latest/download/setup-Happ.x64.exe", macos: "https://github.com/Happ-proxy/happ-desktop/releases/latest/download/Happ.macOS.universal.dmg", }, }; diff --git a/docs/adr/0074-happ-discovery-and-hidden-google.md b/docs/adr/0074-happ-discovery-and-hidden-google.md index c45e5b9..b52fa95 100644 --- a/docs/adr/0074-happ-discovery-and-hidden-google.md +++ b/docs/adr/0074-happ-discovery-and-hidden-google.md @@ -4,6 +4,10 @@ Accepted +The Clients catalog opens Happ's official x64 Debian package on Linux and +its x64 setup executable on Windows. The publisher's macOS DMG is the +corresponding macOS destination. + ## Context Connect logged `happ is not running and its executable was not found` even diff --git a/docs/adr/0075-windscribe-openvpn-download.md b/docs/adr/0075-windscribe-openvpn-download.md index 99532a3..7b0b081 100644 --- a/docs/adr/0075-windscribe-openvpn-download.md +++ b/docs/adr/0075-windscribe-openvpn-download.md @@ -17,15 +17,17 @@ already had a profile still had no in-app path to OpenVPN. - Windscribe catalog and card download rows list **Download OpenVPN** first (the same platform page as the OpenVPN preset), then **Get Windscribe config**. On macOS that link opens the Homebrew formula for the standalone - `openvpn` executable. On Linux and Windows it opens OpenVPN Community. + `openvpn` executable. On Linux it opens OpenVPN's distribution package + instructions. On Windows it opens the official Community installer page. - The amber "OpenVPN is not installed" banner always opens the OpenVPN page, including on a Windscribe card. - The URL allowlist stays derived from the preset table; Windscribe reuses the OpenVPN row so it cannot drift. -- Use `/usr/bin/open` for macOS download links and check its exit status with - a bounded async wait. Client download buttons show a toast if the handoff - fails. Environment snapshots report whether the selected opener exists and - include `external_url_opener_missing` when it does not. +- Use `/usr/bin/open` on macOS, `xdg-open` on Linux, and the Windows shell + association via PowerShell. Pass the Windows URL as process environment data. + Check launcher status asynchronously and show a toast when the handoff + fails. On Linux, a launcher still running after the wait may own the browser + process, so leave it running. Environment snapshots report opener availability. ## Consequences diff --git a/docs/adr/0139-hiddify-5-5-5.md b/docs/adr/0139-hiddify-5-5-5.md new file mode 100644 index 0000000..8ca13c1 --- /dev/null +++ b/docs/adr/0139-hiddify-5-5-5.md @@ -0,0 +1,29 @@ +# ADR 0139: Use Hiddify 5.5.5 for managed installation + +## Status + +Accepted + +ADR 0140 updates the managed download to 5.9.15 and corrects Windows ZIP +installation. + +## Context + +The Windows installer still downloaded Hiddify 4.1.1. Linux tried the mutable +`releases/latest` AppImage before falling back to 4.1.1, so the platforms could +install different versions. + +## Decision + +- Pin managed Hiddify downloads and manual installation guides to the official + [5.5.5 release](https://github.com/hiddify/hiddify-app/releases/tag/v5.5.5). +- Linux downloads its versioned x64 AppImage directly. Windows retains the + versioned x64 portable ZIP followed by the setup executable fallback. +- Preserve discovery of existing installations and their settings. This change + selects the version for new managed installations; it does not replace an + existing external client automatically. + +## Validation + +A cross-platform unit test checks the exact Linux and Windows asset URLs and +that the manual guide uses the same download as automatic installation. diff --git a/docs/adr/0140-hiddify-5-9-15.md b/docs/adr/0140-hiddify-5-9-15.md new file mode 100644 index 0000000..5ba969d --- /dev/null +++ b/docs/adr/0140-hiddify-5-9-15.md @@ -0,0 +1,32 @@ +# ADR 0140: Verify managed Hiddify 5.9.15 packages + +## Status + +Accepted + +## Context + +Hiddify 5.9.15 changed the x64 Linux AppImage name. The Windows portable ZIP +has an outer `Hiddify` directory, which the previous installer extracted inside +another directory of the same name. Discovery then missed the executable. + +## Decision + +- Pin the Linux AppImage, Windows portable ZIP, and Windows setup executable + to the official 5.9.15 release and verify the publisher's SHA-256 for each. + The manual guides link to packages from that release. +- Verify and stage the Windows directory before publishing + `apps/Hiddify/Hiddify.exe` and its runtime files. Validate the archive before + replacing earlier files. Try the separately verified setup executable when + the portable download is unavailable. +- Preserve existing client discovery and settings. The managed package is + downloaded on installation when the dependency is missing. +- Report a previously misplaced Windows portable executable in environment + findings. Record the installer fallback and any staging failures without + logging download URLs or user paths. + +## Validation + +The installer test uses the publisher's archive structure and checks normal +binary discovery, runtime files, and preservation of an installed copy when a +replacement is invalid. The guide test checks the exact versioned asset URLs. diff --git a/docs/adr/README.md b/docs/adr/README.md index 5475557..8786177 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -142,3 +142,5 @@ Keep this index current. Add a new ADR for each non-obvious change, or update th | [0136](./0136-preserve-completed-proxy-handoff.md) | Preserve a completed proxy handoff on repeated Stop and Quit | Accepted | | [0137](./0137-inactive-host-dns-evidence.md) | Record classified host DNS answers while disconnected | Accepted | | [0138](./0138-maintained-timestamps.md) | Use maintained timestamp and URL dependencies | Accepted | +| [0139](./0139-hiddify-5-5-5.md) | Use Hiddify 5.5.5 for managed installation | Accepted | +| [0140](./0140-hiddify-5-9-15.md) | Verify managed Hiddify 5.9.15 packages | Accepted | diff --git a/docs/screenshots/desktop.png b/docs/screenshots/desktop.png index ebd5560..05928f7 100644 Binary files a/docs/screenshots/desktop.png and b/docs/screenshots/desktop.png differ diff --git a/docs/screenshots/diagnostics.png b/docs/screenshots/diagnostics.png index 809d521..fb18cdb 100644 Binary files a/docs/screenshots/diagnostics.png and b/docs/screenshots/diagnostics.png differ diff --git a/docs/screenshots/mobile.png b/docs/screenshots/mobile.png index 456fe4b..d97823b 100644 Binary files a/docs/screenshots/mobile.png and b/docs/screenshots/mobile.png differ diff --git a/docs/screenshots/settings-speed.png b/docs/screenshots/settings-speed.png index 8eacab4..9d28f28 100644 Binary files a/docs/screenshots/settings-speed.png and b/docs/screenshots/settings-speed.png differ diff --git a/e2e/primary-flows.spec.ts b/e2e/primary-flows.spec.ts index 57c8b0c..e64626f 100644 --- a/e2e/primary-flows.spec.ts +++ b/e2e/primary-flows.spec.ts @@ -599,56 +599,77 @@ test.describe("primary BiFlow flows", () => { await expect(config.locator("textarea, input")).toHaveCount(0); }); - test("opens the macOS OpenVPN and Happ downloads from Clients", async ({ - page, - }) => { - await page.addInitScript(() => { - Object.defineProperty(navigator, "platform", { value: "MacIntel" }); - }); - await openFresh(page); - await page.evaluate(async () => { - // Intercept the mock desktop handoff without opening a real browser tab. - const modulePath = "/src/api/desktop.ts"; - const { desktop } = await import(modulePath); - desktop.openUrl = async (url: string) => { - sessionStorage.setItem("client-download-test-url", url); - }; + for (const [platform, navigatorPlatform, url, happAsset] of [ + [ + "macOS", + "MacIntel", + "https://formulae.brew.sh/formula/openvpn", + "Happ.macOS.universal.dmg", + ], + [ + "Linux", + "Linux x86_64", + "https://openvpn.net/community-docs/installing-openvpn/", + "Happ.linux.x64.deb", + ], + [ + "Windows", + "Win32", + "https://openvpn.net/community/", + "setup-Happ.x64.exe", + ], + ] as const) { + test(`opens the ${platform} OpenVPN and Happ downloads from Clients`, async ({ + page, + }) => { + await page.addInitScript((value) => { + Object.defineProperty(navigator, "platform", { value }); + }, navigatorPlatform); + await openFresh(page); + await page.evaluate(async () => { + // Intercept the mock desktop handoff without opening a real browser tab. + const modulePath = "/src/api/desktop.ts"; + const { desktop } = await import(modulePath); + desktop.openUrl = async (url: string) => { + sessionStorage.setItem("client-download-test-url", url); + }; + }); + await goTo(page, "Clients"); + await page.getByRole("button", { name: "Add client" }).click(); + const row = page.getByTestId("client-catalog-openvpn"); + const openedUrl = () => + page.evaluate(() => sessionStorage.getItem("client-download-test-url")); + await row.getByRole("button", { name: "Download OpenVPN" }).click(); + await expect.poll(openedUrl).toBe(url); + + await row.getByRole("button", { name: /^OpenVPN/ }).click(); + const card = page.getByTestId("client-card-openvpn"); + await expect( + card.getByText("OpenVPN is not installed on this system."), + ).toBeVisible(); + await page.evaluate(() => + sessionStorage.removeItem("client-download-test-url"), + ); + await card.getByRole("button", { name: "Download OpenVPN" }).click(); + await expect.poll(openedUrl).toBe(url); + + await page.getByRole("button", { name: "Add client" }).click(); + const happRow = page.getByTestId("client-catalog-happ"); + const happUrl = `https://github.com/Happ-proxy/happ-desktop/releases/latest/download/${happAsset}`; + await happRow.getByRole("button", { name: "Download & install" }).click(); + await expect.poll(openedUrl).toBe(happUrl); + await happRow.getByRole("button", { name: /^Happ/ }).click(); + const happCard = page.getByTestId("client-card-happ"); + await happCard.getByText("Settings & pinned hosts").click(); + await page.evaluate(() => + sessionStorage.removeItem("client-download-test-url"), + ); + await happCard + .getByRole("button", { name: "Download & install" }) + .click(); + await expect.poll(openedUrl).toBe(happUrl); }); - await goTo(page, "Clients"); - await page.getByRole("button", { name: "Add client" }).click(); - const row = page.getByTestId("client-catalog-openvpn"); - const url = "https://formulae.brew.sh/formula/openvpn"; - const openedUrl = () => - page.evaluate(() => sessionStorage.getItem("client-download-test-url")); - await row.getByRole("button", { name: "Download OpenVPN" }).click(); - await expect.poll(openedUrl).toBe(url); - - await row.getByRole("button", { name: /^OpenVPN/ }).click(); - const card = page.getByTestId("client-card-openvpn"); - await expect( - card.getByText("OpenVPN is not installed on this system."), - ).toBeVisible(); - await page.evaluate(() => - sessionStorage.removeItem("client-download-test-url"), - ); - await card.getByRole("button", { name: "Download OpenVPN" }).click(); - await expect.poll(openedUrl).toBe(url); - - await page.getByRole("button", { name: "Add client" }).click(); - const happRow = page.getByTestId("client-catalog-happ"); - const happUrl = - "https://github.com/Happ-proxy/happ-desktop/releases/latest/download/Happ.macOS.universal.dmg"; - await happRow.getByRole("button", { name: "Download & install" }).click(); - await expect.poll(openedUrl).toBe(happUrl); - await happRow.getByRole("button", { name: /^Happ/ }).click(); - const happCard = page.getByTestId("client-card-happ"); - await happCard.getByText("Settings & pinned hosts").click(); - await page.evaluate(() => - sessionStorage.removeItem("client-download-test-url"), - ); - await happCard.getByRole("button", { name: "Download & install" }).click(); - await expect.poll(openedUrl).toBe(happUrl); - }); + } test("picks a config file for OpenVPN and Windscribe", async ({ page }) => { await openFresh(page); diff --git a/package.json b/package.json index 645a495..9dec49a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iran-split-desktop-workspace", - "version": "6.2.94", + "version": "6.2.96", "private": true, "packageManager": "pnpm@9.0.1", "engines": { diff --git a/src-tauri/src/deps.rs b/src-tauri/src/deps.rs index aa572da..ca783f0 100644 --- a/src-tauri/src/deps.rs +++ b/src-tauri/src/deps.rs @@ -4,7 +4,6 @@ use flate2::read::GzDecoder; use serde::Serialize; use sha2::{Digest, Sha256}; use std::{ - error::Error as _, fs, io::{Cursor, Read, Write}, path::{Path, PathBuf}, @@ -15,7 +14,15 @@ use tracing::{info, warn}; const USER_AGENT: &str = concat!("BiFlow/", env!("CARGO_PKG_VERSION")); const MAX_DOWNLOAD_BYTES: usize = 180 * 1024 * 1024; -const HIDDIFY_VERSION: &str = "v4.1.1"; +const HIDDIFY_VERSION: &str = "v5.9.15"; +const HIDDIFY_LINUX_APPIMAGE: &str = "Hiddify-Linux-x64.AppImage"; +const HIDDIFY_LINUX_SHA256: &str = + "07e6565e8479a6789ca6456924a91ce886e7167f83864f0ba20bc328e9b6e4cb"; +const HIDDIFY_WINDOWS_ZIP_SHA256: &str = + "3b1b15ba141dfc6103a6f0b11c11c845bcb3aad6fb0644376433006a31c9bcef"; +const HIDDIFY_WINDOWS_SETUP_SHA256: &str = + "817bf87f2d0c268f4b5c1169784ac19c5acd60d59a006e928a8c44b685997164"; +static HIDDIFY_INSTALL_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(()); const MIHOMO_VERSION: &str = "v1.19.29"; const MIHOMO_LINUX_SHA256: &str = "9c397be7489538628fae781bc005e4c5b8cd7b0961b8bb2ca815c8150f193577"; @@ -273,7 +280,7 @@ pub fn install_guide(id: DependencyId) -> InstallGuide { (DependencyId::Hiddify, "windows") => InstallGuide { id: id.as_str(), title: "Install Hiddify on Windows".into(), - download_url: hiddify_windows_url(), + download_url: hiddify_windows_setup_url(), steps: vec![ "Open the official Hiddify release page and download Hiddify-Windows-Setup-x64.exe.".into(), "Run the installer and accept the Windows permission prompt.".into(), @@ -285,8 +292,8 @@ pub fn install_guide(id: DependencyId) -> InstallGuide { title: "Install Hiddify on Linux".into(), download_url: hiddify_linux_appimage_url(), steps: vec![ - "Download Hiddify-Linux-x64-AppImage.AppImage from the official GitHub release.".into(), - "Make it executable: chmod +x Hiddify-Linux-x64-AppImage.AppImage".into(), + format!("Download {HIDDIFY_LINUX_APPIMAGE} from the official GitHub release."), + format!("Make it executable: chmod +x {HIDDIFY_LINUX_APPIMAGE}"), "Move it to ~/.local/share/biflow/apps/Hiddify.AppImage".into(), "Restart BiFlow and press Connect.".into(), ], @@ -366,6 +373,7 @@ pub async fn install_dependency( } async fn install_hiddify(data: &Path) -> Result { + let _install_guard = HIDDIFY_INSTALL_LOCK.lock().await; if cfg!(target_os = "windows") { install_hiddify_windows(data).await } else { @@ -374,18 +382,17 @@ async fn install_hiddify(data: &Path) -> Result { } async fn install_hiddify_linux(data: &Path) -> Result { - let bytes = download_first(&[ - hiddify_linux_appimage_url(), - hiddify_linux_appimage_pinned_url(), - ]) - .await?; + let bytes = download(&hiddify_linux_appimage_url()).await?; + verify_sha256(&bytes, HIDDIFY_LINUX_SHA256)?; if !is_elf(&bytes) { return Err(DepsError::Integrity( "Hiddify AppImage is not an ELF binary".into(), )); } let appimage = data.join("apps").join("Hiddify.AppImage"); - write_executable(&appimage, &bytes)?; + let staged = tempfile::NamedTempFile::new_in(data.join("apps"))?; + write_executable(staged.path(), &bytes)?; + staged.persist(&appimage).map_err(|error| error.error)?; let link = data.join("bin").join("hiddify"); if let Err(cause) = fs::remove_file(&link) { if cause.kind() != std::io::ErrorKind::NotFound { @@ -404,15 +411,21 @@ async fn install_hiddify_linux(data: &Path) -> Result { } async fn install_hiddify_windows(data: &Path) -> Result { - let bytes = - download_first(&[hiddify_windows_portable_url(), hiddify_windows_setup_url()]).await?; - if is_zip(&bytes) { - let dest = data.join("apps").join("Hiddify"); - extract_zip(&bytes, &dest)?; - return first_existing(&hiddify_candidates(data)).ok_or_else(|| { - DepsError::Install("Hiddify portable archive did not contain Hiddify.exe".into()) - }); + if let Ok(bytes) = download(&hiddify_windows_portable_url()).await { + verify_sha256(&bytes, HIDDIFY_WINDOWS_ZIP_SHA256)?; + return install_hiddify_portable(&bytes, &data.join("apps")); } + warn!( + event = "dependency.portable_download_failed", + section = "dependencies", + initiator = "dependency_installer", + cause = "portable_fetch_failed", + trace_route = "dependency_installer->hiddify_setup_fallback", + dependency_id = "hiddify", + "portable Hiddify download failed; fetching the setup executable" + ); + let bytes = download(&hiddify_windows_setup_url()).await?; + verify_sha256(&bytes, HIDDIFY_WINDOWS_SETUP_SHA256)?; if !is_pe(&bytes) { return Err(DepsError::Integrity( "Hiddify installer is not a Windows executable".into(), @@ -420,9 +433,10 @@ async fn install_hiddify_windows(data: &Path) -> Result { } let installer = data.join("apps").join("Hiddify-Setup.exe"); fs::write(&installer, bytes)?; - let status = std::process::Command::new(&installer) + let status = tokio::process::Command::new(&installer) .args(["/VERYSILENT", "/NORESTART", "/SUPPRESSMSGBOXES"]) .status() + .await .map_err(|error| DepsError::Install(error.to_string()))?; if !status.success() { std::process::Command::new(&installer).spawn().map_err(|cause| { @@ -448,6 +462,54 @@ async fn install_hiddify_windows(data: &Path) -> Result { }) } +fn install_hiddify_portable(bytes: &[u8], apps: &Path) -> Result { + let staging = tempfile::tempdir_in(apps)?; + extract_zip(bytes, staging.path())?; + let incoming = staging.path().join("Hiddify"); + if !incoming.join("Hiddify.exe").is_file() { + return Err(DepsError::Install( + "Hiddify portable archive did not contain Hiddify/Hiddify.exe".into(), + )); + } + + let destination = apps.join("Hiddify"); + let backup = staging.path().join("previous"); + let backed_up = match fs::rename(&destination, &backup) { + Ok(()) => true, + Err(cause) if cause.kind() == std::io::ErrorKind::NotFound => false, + Err(cause) => return Err(cause.into()), + }; + if let Err(cause) = fs::rename(incoming, &destination) { + if backed_up { + if let Err(restore_error) = fs::rename(backup, &destination) { + let _retained_backup_directory = staging.keep(); + warn!( + event = "dependency.portable_restore_failed", + section = "dependencies", + initiator = "dependency_installer", + cause = %restore_error.kind(), + trace_route = "dependency_installer->hiddify_portable->restore_previous", + dependency_id = "hiddify", + "could not restore the previous Hiddify directory; retained the staged backup" + ); + } + } + return Err(cause.into()); + } + if let Err(cause) = staging.close() { + warn!( + event = "dependency.staging_cleanup_failed", + section = "dependencies", + initiator = "dependency_installer", + cause = %cause.kind(), + trace_route = "dependency_installer->hiddify_portable->staging_cleanup", + dependency_id = "hiddify", + "Hiddify was installed but its staging directory could not be removed" + ); + } + Ok(destination.join("Hiddify.exe")) +} + async fn install_mihomo(data: &Path, bundled_dependencies: &Path) -> Result { let dest = mihomo_install_path(data); if cfg!(target_os = "windows") { @@ -577,26 +639,17 @@ fn mihomo_file_name() -> &'static str { } fn hiddify_linux_appimage_url() -> String { - "https://github.com/hiddify/hiddify-app/releases/latest/download/Hiddify-Linux-x64-AppImage.AppImage" - .into() -} - -fn hiddify_linux_appimage_pinned_url() -> String { format!( - "https://github.com/hiddify/hiddify-app/releases/download/{HIDDIFY_VERSION}/Hiddify-Linux-x64-AppImage.AppImage" + "https://github.com/hiddify/hiddify-app/releases/download/{HIDDIFY_VERSION}/{HIDDIFY_LINUX_APPIMAGE}" ) } -fn hiddify_windows_url() -> String { +fn hiddify_windows_setup_url() -> String { format!( "https://github.com/hiddify/hiddify-app/releases/download/{HIDDIFY_VERSION}/Hiddify-Windows-Setup-x64.exe" ) } -fn hiddify_windows_setup_url() -> String { - hiddify_windows_url() -} - fn hiddify_windows_portable_url() -> String { format!( "https://github.com/hiddify/hiddify-app/releases/download/{HIDDIFY_VERSION}/Hiddify-Windows-Portable-x64.zip" @@ -675,38 +728,28 @@ async fn download_with_client(url: &str, direct: bool) -> Result, String if direct { builder = builder.no_proxy(); } - let client = builder.build().map_err(|error| error_chain(&error))?; + let client = builder.build().map_err(download_error)?; let response = client .get(url) .send() .await .and_then(reqwest::Response::error_for_status) - .map_err(|error| error_chain(&error))?; + .map_err(download_error)?; if response .content_length() .is_some_and(|length| length > MAX_DOWNLOAD_BYTES as u64) { return Err("download exceeded the size limit".into()); } - let bytes = response - .bytes() - .await - .map_err(|error| error_chain(&error))?; + let bytes = response.bytes().await.map_err(download_error)?; if bytes.len() > MAX_DOWNLOAD_BYTES { return Err("download exceeded the size limit".into()); } Ok(bytes.to_vec()) } -fn error_chain(error: &reqwest::Error) -> String { - let mut message = error.to_string(); - let mut source = error.source(); - while let Some(cause) = source { - message.push_str(": "); - message.push_str(&cause.to_string()); - source = cause.source(); - } - message +fn download_error(error: reqwest::Error) -> String { + error.without_url().to_string() } fn gunzip(bytes: &[u8]) -> Result, DepsError> { @@ -798,20 +841,25 @@ fn is_macho(bytes: &[u8]) -> bool { bytes.len() >= 4 && bytes[0] == 0xcf && bytes[1] == 0xfa && bytes[2] == 0xed && bytes[3] == 0xfe } -fn is_zip(bytes: &[u8]) -> bool { - bytes.len() >= 4 && bytes[0] == b'P' && bytes[1] == b'K' -} +const WINDOWS_URL_ENV: &str = "BIFLOW_EXTERNAL_URL"; +const WINDOWS_OPEN_URL_SCRIPT: &str = concat!( + "$ErrorActionPreference = 'Stop'; ", + "$start = New-Object System.Diagnostics.ProcessStartInfo; ", + "$start.FileName = $env:BIFLOW_EXTERNAL_URL; ", + "$start.UseShellExecute = $true; ", + "[void][System.Diagnostics.Process]::Start($start)" +); -fn external_url_opener(platform: &str) -> (&'static str, &'static [&'static str]) { +fn external_url_opener(platform: &str) -> &'static str { match platform { - "macos" => ("/usr/bin/open", &[]), - "windows" => ("cmd.exe", &["/C", "start", ""]), - _ => ("xdg-open", &[]), + "macos" => "/usr/bin/open", + "windows" => "powershell.exe", + _ => "xdg-open", } } pub(super) fn external_url_opener_available() -> bool { - let (program, _) = external_url_opener(std::env::consts::OS); + let program = external_url_opener(std::env::consts::OS); if Path::new(program).is_absolute() { Path::new(program).is_file() } else { @@ -823,11 +871,22 @@ fn external_url_command(url: &str, platform: &str) -> Result Result Result<(), DepsError> { - let mut command = external_url_command(url, std::env::consts::OS)?; - if cfg!(target_os = "macos") { - // Launch Services returns once it hands off the URL to the browser. - // Await it for failure feedback without blocking the Tauri thread. - let status = - tokio::time::timeout(Duration::from_secs(5), command.kill_on_drop(true).status()) - .await - .map_err(|_| DepsError::OpenLink("browser handoff timed out".into()))? - .map_err(|error| DepsError::OpenLink(error.kind().to_string()))?; - if !status.success() { - return Err(DepsError::OpenLink(status.to_string())); + let platform = std::env::consts::OS; + let mut command = external_url_command(url, platform)?; + wait_for_browser_handoff(&mut command, platform, Duration::from_secs(5)).await +} + +async fn wait_for_browser_handoff( + command: &mut tokio::process::Command, + platform: &str, + limit: Duration, +) -> Result<(), DepsError> { + // On Linux xdg-open can become the browser process. A successful launch + // may therefore outlive the wait, so leave a running process alone. + let may_outlive_handoff = platform == "linux"; + match tokio::time::timeout(limit, command.kill_on_drop(!may_outlive_handoff).status()).await { + Ok(Ok(status)) if status.success() => Ok(()), + Ok(Ok(status)) => Err(DepsError::OpenLink(status.to_string())), + Ok(Err(error)) => Err(DepsError::OpenLink(error.kind().to_string())), + Err(_) if may_outlive_handoff => { + info!( + event = "dependency.url_opener_still_running", + section = "dependencies", + initiator = "open_external_url", + cause = "linux_opener_outlived_handoff_wait", + trace_route = "open_external_url->xdg_open", + "Linux URL opener is still running after the handoff wait" + ); + Ok(()) } - } else { - command - .spawn() - .map_err(|error| DepsError::OpenLink(error.kind().to_string()))?; + Err(_) => Err(DepsError::OpenLink("browser handoff timed out".into())), } - Ok(()) } fn open_url_allowed(url: &str) -> bool { @@ -906,6 +977,64 @@ mod tests { assert!(!url_allowed("https://example.com/hiddify")); } + #[test] + fn hiddify_downloads_and_manual_guide_use_5_9_15() { + let release = "https://github.com/hiddify/hiddify-app/releases/download/v5.9.15"; + assert_eq!( + hiddify_linux_appimage_url(), + format!("{release}/Hiddify-Linux-x64.AppImage") + ); + assert_eq!( + hiddify_windows_portable_url(), + format!("{release}/Hiddify-Windows-Portable-x64.zip") + ); + assert_eq!( + hiddify_windows_setup_url(), + format!("{release}/Hiddify-Windows-Setup-x64.exe") + ); + let guide = install_guide(DependencyId::Hiddify); + assert_eq!( + guide.download_url, + if cfg!(target_os = "windows") { + hiddify_windows_setup_url() + } else { + hiddify_linux_appimage_url() + } + ); + } + + #[test] + fn hiddify_portable_publishes_official_archive_layout_and_preserves_a_working_install() { + let archive = |entries: &[&str]| { + let mut writer = zip::ZipWriter::new(Cursor::new(Vec::new())); + for entry in entries { + writer + .start_file(*entry, zip::write::SimpleFileOptions::default()) + .unwrap(); + writer.write_all(b"fixture").unwrap(); + } + writer.finish().unwrap().into_inner() + }; + let root = tempfile::tempdir().unwrap(); + let apps = root.path().join("apps"); + let destination = apps.join("Hiddify"); + let misplaced = destination.join("Hiddify").join("Hiddify.exe"); + fs::create_dir_all(misplaced.parent().unwrap()).unwrap(); + fs::write(&misplaced, b"old nested executable").unwrap(); + let bytes = archive(&["Hiddify/Hiddify.exe", "Hiddify/data/icudtl.dat"]); + let installed = install_hiddify_portable(&bytes, &apps).unwrap(); + assert_eq!(installed, destination.join("Hiddify.exe")); + assert_eq!( + first_existing(&hiddify_candidates(root.path())), + Some(installed.clone()) + ); + assert!(destination.join("data").join("icudtl.dat").is_file()); + assert!(!misplaced.exists()); + + assert!(install_hiddify_portable(&archive(&["Hiddify/unrelated.exe"]), &apps).is_err()); + assert_eq!(fs::read(installed).unwrap(), b"fixture"); + } + #[test] fn opens_biflow_repository_links() { assert!(open_url_allowed("https://github.com/devlifeX/BiFlow")); @@ -919,23 +1048,53 @@ mod tests { fn opens_the_platform_openvpn_download_with_the_native_launcher() { let downloads = iran_split_config::PresetId::Openvpn.spec().downloads; assert_eq!(downloads.macos, "https://formulae.brew.sh/formula/openvpn"); - for (platform, program, args) in [ - ("macos", "/usr/bin/open", vec![downloads.macos]), - ("linux", "xdg-open", vec![downloads.linux]), - ( - "windows", - "cmd.exe", - vec!["/C", "start", "", downloads.windows], - ), + assert_eq!( + downloads.linux, + "https://openvpn.net/community-docs/installing-openvpn/" + ); + assert_eq!(downloads.windows, "https://openvpn.net/community/"); + for (platform, program, url) in [ + ("macos", "/usr/bin/open", downloads.macos), + ("linux", "xdg-open", downloads.linux), + ("windows", "powershell.exe", downloads.windows), ] { - let url = args.last().expect("download URL"); let command = external_url_command(url, platform).expect("catalog URL is allowed"); assert_eq!(command.as_std().get_program(), program); - assert!(command.as_std().get_args().eq(args)); + if platform == "windows" { + assert!(command.as_std().get_args().eq([ + "-NoProfile", + "-NonInteractive", + "-Command", + WINDOWS_OPEN_URL_SCRIPT, + ])); + assert!(command.as_std().get_envs().any(|(name, value)| { + name == WINDOWS_URL_ENV && value.is_some_and(|value| value == url) + })); + } else { + assert!(command.as_std().get_args().eq([url])); + } assert!(external_url_command("https://example.com/openvpn", platform).is_err()); } } + #[tokio::test] + async fn browser_handoff_reports_a_nonzero_exit_status() { + let mut command = if cfg!(windows) { + let mut command = tokio::process::Command::new("powershell.exe"); + command.args(["-NoProfile", "-NonInteractive", "-Command", "exit 7"]); + command + } else { + let mut command = tokio::process::Command::new("sh"); + command.args(["-c", "exit 7"]); + command + }; + let failure = + wait_for_browser_handoff(&mut command, std::env::consts::OS, Duration::from_secs(5)) + .await + .unwrap_err(); + assert!(matches!(failure, DepsError::OpenLink(status) if status.contains('7'))); + } + #[test] fn macos_happ_download_opens_the_publishers_universal_dmg() { let url = "https://github.com/Happ-proxy/happ-desktop/releases/latest/download/Happ.macOS.universal.dmg"; diff --git a/src-tauri/src/environment/apps.rs b/src-tauri/src/environment/apps.rs index 726e1e6..9868336 100644 --- a/src-tauri/src/environment/apps.rs +++ b/src-tauri/src/environment/apps.rs @@ -3,7 +3,7 @@ //! the `OpenVPN` binary and `.ovpn` profiles side tunnels ride on, and the //! clock (vmess/reality and `OpenVPN` TLS both fail on a skewed clock). -use super::{classify_host, parse_endpoint, EnvironmentReport}; +use super::{classify_host, parse_endpoint, CollectContext, EnvironmentReport}; use iran_split_config::{AppConfig, ClientConfig, EgressKind}; use iran_split_core::{HelperStatus, StackPhase, StackSnapshot}; use jiff::{ @@ -57,6 +57,7 @@ pub struct BinaryInfo { pub struct HiddifyInfo { pub data_dir_found: bool, pub executable: Option, + pub misplaced_portable_executable: bool, /// `flutter.service-mode`: `proxy`, `system-proxy`, `tun`, ... pub service_mode: Option, pub region: Option, @@ -315,7 +316,23 @@ fn modified(path: &Path) -> Option { } /// Reads only whitelisted keys: never profiles, subscriptions, or outbounds. -pub(super) fn hiddify_info(data_dir: Option<&Path>) -> HiddifyInfo { +pub(super) fn installed_hiddify(context: &CollectContext) -> HiddifyInfo { + let data_dir = context.data_dir.as_deref(); + let mut info = hiddify_info(context.hiddify_data_dir.as_deref()); + // Running the GUI with `--version` opens a window, so report its location. + let executable = context.hiddify_executable.as_deref(); + info.executable = Some(BinaryInfo { + found: executable.is_some(), + location: executable.map_or("missing", |path| path_location(path, data_dir)), + version: None, + }); + info.misplaced_portable_executable = cfg!(windows) + && executable.is_none() + && data_dir.is_some_and(|dir| dir.join("apps/Hiddify/Hiddify/Hiddify.exe").is_file()); + info +} + +fn hiddify_info(data_dir: Option<&Path>) -> HiddifyInfo { let Some(dir) = data_dir else { return HiddifyInfo::default(); }; @@ -746,6 +763,9 @@ fn hiddify_findings( let Some(hiddify) = &report.apps.hiddify else { return; }; + if hiddify.misplaced_portable_executable { + findings.push("hiddify_windows_portable_extracted_one_level_too_deep".into()); + } let configured = config.and_then(|config| { config.enabled_clients().into_iter().find_map(|client| { match (&client.preset, &client.config) { @@ -972,6 +992,26 @@ mod tests { assert!(found.contains(&"hiddify_port_mismatch:biflow=12334:hiddify=2334".to_owned())); } + #[test] + fn environment_reports_the_misplaced_windows_portable_executable() { + let report = EnvironmentReport { + apps: AppsInfo { + hiddify: Some(HiddifyInfo { + misplaced_portable_executable: true, + ..HiddifyInfo::default() + }), + ..AppsInfo::default() + }, + ..EnvironmentReport::default() + }; + let mut findings = Vec::new(); + hiddify_findings(&report, None, &mut findings); + assert_eq!( + findings, + ["hiddify_windows_portable_extracted_one_level_too_deep"] + ); + } + #[test] fn ovpn_summary_classifies_remotes_and_counts_missing_files() { let text = "client\ndev tun\nproto udp\nremote ber-449.example.com 443\nremote 185.1.2.3 1194 tcp\n\ diff --git a/src-tauri/src/environment/mod.rs b/src-tauri/src/environment/mod.rs index 54200c7..7402906 100644 --- a/src-tauri/src/environment/mod.rs +++ b/src-tauri/src/environment/mod.rs @@ -503,31 +503,13 @@ async fn collect(context: CollectContext) -> EnvironmentReport { let openvpn = apps::openvpn_candidates() .into_iter() .find(|path| path.exists()); - let (mihomo, openvpn_binary, hiddify_binary, clock) = tokio::join!( + let (mihomo, openvpn_binary, clock) = tokio::join!( apps::binary_info(context.mihomo_path.as_deref(), "-v", data_dir), apps::binary_info(openvpn.as_deref(), "--version", data_dir), - async { - // Hiddify is a GUI; running it with `--version` would open a - // window, so only its location is reported. - context - .hiddify_executable - .as_deref() - .map(|path| apps::BinaryInfo { - found: true, - location: apps::path_location(path, data_dir), - version: None, - }) - }, apps::clock_info(), ); - let mut hiddify = apps::hiddify_info(context.hiddify_data_dir.as_deref()); - hiddify.executable = Some(hiddify_binary.unwrap_or(apps::BinaryInfo { - found: false, - location: "missing", - version: None, - })); report.apps = AppsInfo { - hiddify: Some(hiddify), + hiddify: Some(apps::installed_hiddify(&context)), mihomo: Some(mihomo), openvpn: Some(openvpn_binary), side_tunnels: apps::side_tunnel_profiles(context.config.as_ref(), data_dir), diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 15ffa24..bba7f69 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "BiFlow", - "version": "6.2.94", + "version": "6.2.96", "identifier": "app.biflow.desktop", "build": { "beforeDevCommand": "pnpm bundle:check && pnpm --dir apps/desktop dev", diff --git a/version b/version index 9c57137..971c4de 100644 --- a/version +++ b/version @@ -1 +1 @@ -6.2.94 +6.2.96