159 lines
5.2 KiB
Markdown
159 lines
5.2 KiB
Markdown
# Zero-touch Auto-Enrollment
|
|
|
|
The old one-time token flow is replaced by a per-device, idempotent
|
|
auto-enrollment flow.
|
|
|
|
## Flow
|
|
|
|
```text
|
|
BAĞLAN
|
|
-> AmneziaWG missing? install MSI silently (app runs elevated)
|
|
-> config missing? POST /api/v1/auto-enroll
|
|
-> save %LOCALAPPDATA%\LD-FDPI\ld-fdpi.conf
|
|
-> install/start AmneziaWGTunnel$ld-fdpi
|
|
-> enable WFP kill-switch
|
|
-> wait up to 10 s for tunnel egress
|
|
-> on failure: delete config, re-enroll, retry once
|
|
```
|
|
|
|
## Identity
|
|
|
|
- Windows `HKLM\SOFTWARE\Microsoft\Cryptography\MachineGuid`
|
|
- SHA-256(`ld-fdpi-hwid-v1` + lowercased MachineGuid) = 64-char hex `device_id`
|
|
- X25519 key pair remains local; private key sealed with DPAPI
|
|
- `device_id` is stable across app reinstall and `%LOCALAPPDATA%` deletion
|
|
|
|
## API
|
|
|
|
`POST https://ttmadethat.shop/api/v1/auto-enroll`
|
|
|
|
Headers:
|
|
|
|
```text
|
|
Content-Type: application/json
|
|
X-App-Secret: <embedded shared secret>
|
|
```
|
|
|
|
Body:
|
|
|
|
```json
|
|
{"public_key":"...","device_id":"<64 hex>","client_version":"1.5.10"}
|
|
```
|
|
|
|
Behavior:
|
|
|
|
- New device -> next free `10.8.1.x/32`, new PSK, peer added.
|
|
- Existing device + same public key -> same IP/PSK, peer re-applied.
|
|
- Existing device + new public key -> old peer removed, same IP reused.
|
|
- Public key already bound to another device -> `409`.
|
|
- IP pool exhausted -> `503`.
|
|
- Per-IP rate limit: **5 requests / minute**.
|
|
- `X-App-Secret` wrong/missing -> `401`.
|
|
|
|
## Server deployment
|
|
|
|
`/opt/ld-fdpi-enroll/.env`:
|
|
|
|
```text
|
|
LD_FDPI_APP_SECRET=<same value embedded in client>
|
|
```
|
|
|
|
The FastAPI site proxies `/api/v1/auto-enroll` to `172.17.0.1:9471` and forwards
|
|
`X-App-Secret`, `X-Real-IP` (Cloudflare client IP). Backup:
|
|
`/opt/tylorindar-safelink/backups/main.py.bak-auto-enroll`.
|
|
|
|
## Watchdog
|
|
|
|
After a successful connect, a watchdog checks the tunnel every 3 seconds. It
|
|
does **not** use the local `latest handshake` age: WireGuard only rekeys about
|
|
every 2 minutes, and deleting the server peer does not immediately reset the
|
|
client's displayed handshake time.
|
|
|
|
Checks:
|
|
|
|
1. If the AWG service stopped unexpectedly, recovery starts immediately.
|
|
2. Otherwise a DNS query to `1.1.1.1:53` goes through the tunnel. WFP blocks
|
|
port 53 on the physical interface and permits only the tunnel LUID, so a
|
|
direct WAN response cannot mask a dead peer.
|
|
3. Three consecutive failed checks (~9 s) trigger WFP teardown, service
|
|
stop/delete, config removal, auto-enroll, service reinstall, and WFP re-arm.
|
|
4. Recovery is attempted at most 3 times; after that the watchdog stops and
|
|
reports an error instead of looping forever.
|
|
|
|
If WFP teardown fails, recovery aborts instead of attempting an HTTPS request
|
|
through the catch-all block.
|
|
|
|
## MSI installation
|
|
|
|
The bundled MSI is copied out of `Program Files` to a plain
|
|
`%WINDIR%\Temp\ld-amneziawg.msi` path before `msiexec` runs. This avoids
|
|
extended `\\?\` paths and Program Files/MSI open failures (`1619`). The MSI log
|
|
is written to `%WINDIR%\Temp\ld-awg-msi.log` and its tail is included in the
|
|
error if installation fails.
|
|
|
|
## Sandbox acceptance result
|
|
|
|
Windows Sandbox (`--auto-connect-vpn`) passed:
|
|
|
|
- WebView2 + app install
|
|
- Silent AmneziaWG MSI install via temp copy
|
|
- Automatic enrollment (new `10.8.1.x/32`)
|
|
- Service start + handshake
|
|
- Tunnel ping (8.8.8.8 through VPN, ~55 ms)
|
|
- Server peer deletion -> peer re-added, `latest handshake` refreshed in <40 s
|
|
|
|
Not tested: forced WFP-teardown failure and reboot persistence.
|
|
|
|
## Headless acceptance flag
|
|
|
|
`ld-fdpi.exe --auto-connect-vpn` starts the normal zero-touch pipeline without
|
|
UI interaction and writes:
|
|
|
|
```text
|
|
%LOCALAPPDATA%\LD-FDPI\auto-connect-result.txt
|
|
```
|
|
|
|
This exists for Windows Sandbox/CI acceptance testing.
|
|
|
|
## Key rotation / stale peer blocks
|
|
|
|
When a device re-enrolls with a new public key, the old peer is removed from
|
|
the running AWG interface **and** its `[Peer]` block is removed from
|
|
`awg0.conf`. Otherwise a container restart could revive the old key on the same
|
|
`10.8.1.x/32`, causing endpoint flapping.
|
|
|
|
## WFP / retry ordering
|
|
|
|
The kill-switch blocks physical egress. Re-enrolling while it is still active
|
|
would make the HTTPS request to `ttmadethat.shop` fail, so the retry path is:
|
|
|
|
```text
|
|
handshake fail
|
|
-> disable_killswitch() with 3 attempts
|
|
-> if teardown fails: ABORT, keep the tunnel/service state, report error
|
|
-> stop service
|
|
-> delete config
|
|
-> auto-enroll over normal physical HTTPS
|
|
-> reinstall/start service
|
|
```
|
|
|
|
The API IP is not permanently whitelisted in WFP; that would punch a hole in the
|
|
kill-switch. The teardown result is checked instead.
|
|
|
|
## Security warning
|
|
|
|
`APP_SECRET` is embedded in the installer and is extractable. This is **not**
|
|
real authentication; it only stops random scanners. Anyone who extracts it can
|
|
enroll devices until the shared secret is rotated and a new client is shipped.
|
|
|
|
The IP rate limit also means shared NAT (school/office) can hit 5/minute.
|
|
Token enrollment remains available as a legacy endpoint but is no longer used
|
|
by the UI.
|
|
|
|
## Known limitation
|
|
|
|
`MachineGuid` is per Windows installation, not per Windows user. Two Windows
|
|
users on the same PC share `device_id`; the last enrollment wins. Disk-cloned
|
|
Windows images without Sysprep can also share it. If that becomes common, add
|
|
the SMBIOS UUID/baseboard serial to the hash; the current audience is fine with
|
|
MachineGuid alone.
|