# Build spec — School WiFi Tunnel

**Published:** `installers/vless-setup.pkg` (25,772,033 bytes, sha256 `1217964f…`) — no subscription inside
**Private:** `vless-setup.pkg` (25,772,087 bytes, sha256 `ceb94d812b55b245…`) — same build with a link baked in
**Analysis:** `demos/school-wifi-tunnel-analysis.html`
**Mirror:** `demos/school-wifi-tunnel-mirror/` (`index.html` + `manifest.json` + `payload/`)
**Source:** `/tmp/vlesspkg/` (staging: `root/`, `scripts/postinstall`, `Distribution.xml`, `resources/`)

## What it is

A tunnel that survives a school network which blocks VPNs by protocol fingerprint, packaged as a
one-double-click macOS installer for someone else's laptop. **VLESS over WebSocket and TLS on port
443**, to a Cloudflare-hosted domain, so the connection looks like ordinary HTTPS. 388 lines of bash
plus xray 26.11.9 as a universal binary. No Python, because a fresh Mac has no `python3`.

## Hard requirements (do not regress these)

1. **The proxy is set last.** Traffic must prove itself through the tunnel before a single system
   setting changes. If no node answers, nothing is touched. The failure mode is "sites stop loading",
   never "no internet at all" — this came directly from the user's warning.
2. **A watcher clears the proxy when the tunnel dies.** A detached process holds the PID; the proxy
   comes off the moment the tunnel exits. A dead tunnel with the proxy still set blackholes everything,
   which is exactly what happened once already.
3. **Check the port before testing.** If something else already listens on 1080, the test measures
   that other program and reports a false success. This was caught in testing: the first run looked
   perfect because a tunnel from earlier in the day still held the port.
4. **All network services, not just Wi-Fi.** The helper loops every service so Ethernet and personal
   hotspot orders cannot be blackholed.
5. **Passwordless sudo limited to one path.** `%admin ALL=(root) NOPASSWD: /usr/local/libexec/proxy-toggle`
   — validated with `visudo -cf` and removed if rejected. `vless uninstall` deliberately still prompts.
6. **Bash and perl only.** `perl` ships with macOS and does the URL decoding; nothing else is assumed.
7. **Universal binary.** `lipo -create` of the amd64 and arm64 builds, so the friend's chip cannot be
   the wrong one.

## Layout

```
/usr/local/libexec/vless/vless            212 lines  on / off / status / uninstall / supervise
/usr/local/libexec/vless/vless-autostart   75 lines  per-network decision, lock, log
/usr/local/libexec/vless/xray              67.7 MB   v26.11.9, x86_64 + arm64
/usr/local/libexec/vless/subscription      1 URL     embedded so the friend needs zero config
/usr/local/libexec/vless/README.html                 plain-English usage page
/usr/local/libexec/vless/uninstall         28 lines  removes everything
/usr/local/libexec/proxy-toggle            37 lines  root helper, all services
/Library/LaunchAgents/com.vless.autostart.plist  WatchPaths + login + every 300 s
/etc/sudoers.d/vless-proxy                 1 rule, mode 440
/usr/local/bin/vless -> ../libexec/vless/vless
```

## Autostart logic

Join a filtered network → the LaunchAgent fires on `WatchPaths=/Library/Preferences/SystemConfiguration`.
The script probes three sites with `curl --noproxy '*'`. If they fail, and the resolver's search domain
looks like a filtered network, it runs `vless on`. If they succeed, it runs `vless off`. A 300-second
timer covers captive portals, and a lockfile stops two runs colliding.

## Build

```
pkgbuild --root root --scripts scripts --identifier com.isaac.vless --version 1.0 \
         --install-location / --ownership recommended build/vless-component.pkg
productbuild --distribution Distribution.xml --resources resources \
             --package-path build ~/Desktop/vless-setup.pkg
```

## Verification (what was actually run)

| Check | Result |
|---|---|
| `bash -n` on all five scripts | pass |
| `plutil -lint` on the plist | pass |
| `visudo -cf` on the rule | pass |
| Payload re-extracted from the finished `.pkg` (`pkgutil --expand-full`) | 12 entries, symlink intact |
| `lipo -info` on the engine inside the pkg | `x86_64 arm64` |
| Runner executed from inside the extracted pkg, spare port | node 1 up, YouTube **200 in 0.43 s**, Discord **200** |
| Direct vs tunnel egress on the same Wi-Fi | `118.143.86.157` → `107.148.118.151` |
| `vless off`, then `pgrep` + `lsof` | no process left, port free |

## Deliberate non-goals

- **Not a VPN.** SOCKS proxy only; apps that ignore the system proxy stay on the blocked route.
- **Not anonymous.** The exit sees the site names.
- **Two builds, one code line.** The published package has no subscription inside: first run is
  `vless setup <link>`, which writes `~/.vless/subscription` at mode 600. The private build is the same
  tree with that file baked in. Both are rebuilt from the same source so they cannot drift.
