tsbridge #
Go module bound to Kotlin with gomobile. Serves a webapp directory over
HTTP (the repo's webapp/ by default) and reverse-proxies WebSocket
upgrades to the configured Intiface Central WebSocket server.
The webapp is not embedded here: the handler serves whatever directory
it is given (-webapp for the desktop runner; the Android app unpacks the
webapp bundled in its APK assets, or a folder the user picked from phone
storage), so the running webapp can be swapped without touching tsbridge.
Android interface workaround (tailscale#17311) #
On Android, tsnet.(*Server).Start fails with netlinkrib: permission denied: Go's net.Interfaces() opens netlink route sockets, which Android
SELinux denies to apps (issue open as of 2026-10,
https://github.com/tailscale/tailscale/issues/17311).
The workaround (ifgetaddrs_android.go) implements
netmon.InterfaceGetter over libc getifaddrs(3) — permitted on Android,
the same path java.net.NetworkInterface uses — and registers it via the
public netmon.RegisterInterfaceGetter in init(). No forked tailscale, no
custom toolchain, no JNI. Build-tagged android && cgo; other platforms use
the default enumeration (ifgetaddrs_other.go).
Reference implementation mirrored: https://github.com/GlassOnTin/Haven/blob/main/rclone-android/go/tsbridge/tsbridge.go
Android constraints handled here #
- Android has no
/tmpand noTMPDIR:StartsetsTMPDIRto the caller-provided cache dir before tsnet starts. os.UserConfigDir()errors on Android: tsnet'sDiris always set explicitly to the caller-provided state dir (context.getFilesDir()on the Kotlin side).- gomobile binds only simple types: the exported surface is
Start/Stop/Status/ServePlain/SetCORSwith strings/ints/bools; state is a package-level singleton andStatus()returns JSON. - The server serves on :443 (userspace netstack needs no privileges) and
additionally serves the same handler over plain HTTP on :80, so the
webapp and its WebSocket proxy work at
http://<domain>/too. The webapp picksws:orwss:fromlocation.protocol, so no client-side change is involved. If the:80listener cannot be set up the HTTPS listener keeps serving and the failure is logged in the status ring buffer. /is dual-purpose, mirroring Intiface Central's own server (which accepts WebSocket upgrades on any path, and is dialed without one by clients such as Intiface Central desktop's Repeater mode): WebSocket upgrades on any path are reverse-proxied to Intiface on localhost, plain requests get the static webapp (and/healthz).- CORS is off by default and controlled by
SetCORS(bool)(the Android app's "Allow other web pages" toggle, the desktop runner's-corsflag). When on, the request Origin is reflected on every response — including WebSocket handshakes, which browsers do not preflight — so any web page on any origin may open the proxy. Credentials are never granted,Vary: Originguards caches, and preflight answers carry a deliberately shortAccess-Control-Max-Age(5 minutes) so browsers stop trusting the permissive policy shortly after the user turns it off. - TLS certs are provisioned by our own code (
certs.go), not by tsnet'sListenTLS: on Android upstream stubs the localapi cert endpoint with 404 "disabled on android" (tailscale#18245), which makes ListenTLS unusable there. Instead we run the ACME dns-01 order ourselves with tailscale'stempfork/acmeclient against Let's Encrypt and publish the_acme-challengeTXT via the documentedlocal.Client.SetDNSescape hatch. Certs + the ACME account key are cached under<stateDir>/certs/(persistent → stays under issuance rate limits), and a renewal goroutine re-issues at 2/3 of the cert lifetime. Start's authKey accepts a Tailscale OAuth client secret (tskey-client-...); tsnet'sfeature/oauthkeypackage (imported via thecondregisterside-effect import in tsnet v1.104.1) mints an auth key via the OAuth2 client-credentials flow. That requiresAdvertiseTagsto be non-empty, hence Start'stagsparameter.
Pinned versions #
tailscale.comv1.104.1 (requires Go ≥ 1.27.1; devshell has Go 1.27.2)golang.org/x/mobilev0.0.0-20261011034528-197770444867 (gomobile/gobind installed by the flake shell hook into.tools/bin, and added togo.modas atooldirective as modern gomobile requires)- Vendored webapp dependency:
buttplug@5.0.2dist/web/buttplug.mjs, SHA-256b88615f07a501191e44e083b0cbd47b20d0f979de8b71b8c53be37f8ea67c6d8
Build / test #
go test ./... # handler + WS proxy + healthz unit tests
go vet ./...
gomobile bind -target=android -androidapi 26 -o ../app/libs/tsbridge.aar .