Security & Zero Trust
Operating a remote-control interface for an AI development environment demands enterprise-grade security. Antimatter connects your mobile device to your local machine without opening any firewall ports or exposing your local IP address, using multiple overlapping layers of protection.
Defense-in-Depth Architecture
Section titled βDefense-in-Depth ArchitectureβCompromising any single layer is not sufficient to gain access to your agent or machine.
LAYER 1 ββ Cloudflare Tunnel (TLS + origin validation)LAYER 2 ββ 256-bit Bearer Token (timing-safe comparison)LAYER 3 ββ Ed25519 Cryptographic Handshake (MITM prevention)LAYER 4 ββ End-to-End Encryption (zero-knowledge routing)LAYER 5 ββ Biometric Authentication Gate (device owner verification)LAYER 6 ββ Gateway/Adapter Sandboxing (execution isolation)LAYER 7 ββ Payload Size Limits (DoS mitigation)Layer 1: Cloudflare Tunnel
Section titled βLayer 1: Cloudflare TunnelβThe Gateway uses cloudflared to expose the WebSocket server through a Cloudflare tunnel. This means:
- No open firewall ports β your machineβs local WebSocket server is never directly reachable from the internet.
- No static IP required β the tunnel URL changes with every restart (unless using a persistent Zero Trust domain).
- TLS termination at Cloudflare β all traffic between mobile and Cloudflare edge is TLS-encrypted.
Origin Header Validation (CSWSH Protection)
Section titled βOrigin Header Validation (CSWSH Protection)βTo prevent Cross-Site WebSocket Hijacking, the Gateway enforces strict Origin header validation on every WebSocket upgrade request. Only these origins are accepted:
vscode-webview://β¦(Antigravity IDE webview)https://<team>.cloudflareaccess.com(Cloudflare Access)- Mobile app origins
Anything else β HTTP 403 Forbidden. This prevents malicious websites in your browser from silently connecting to the local server.
Layer 2: 256-bit Bearer & IPC Tokens
Section titled βLayer 2: 256-bit Bearer & IPC TokensβOn first run, the Gateway generates two 256-bit (32-byte) cryptographic tokens using OS-level entropy:
- Pairing Token (Mobile β Gateway):
- Stored permanently in the OS keychain (macOS Keychain, Windows Credential Manager, Linux
libsecret). - If the keychain is unavailable, it falls back to a headless AES-GCM vault secured by a key derived via 600,000 PBKDF2 iterations.
- Stored permanently in the OS keychain (macOS Keychain, Windows Credential Manager, Linux
- IPC Token (Adapter β Gateway):
- Stored in
~/.antimatter_daemon/.ipc_token(mode0600). - Ensures local adapters are authenticated before establishing an IPC bridge.
- Stored in
Both tokens are verified using crypto.timingSafeEqual (or its Python equivalent hmac.compare_digest) β immune to timing side-channel attacks. Invalid token β close code 4001 Unauthorized.
Layer 3: Ed25519 Cryptographic Handshake
Section titled βLayer 3: Ed25519 Cryptographic HandshakeβAfter token verification, the Ed25519 handshake proves the Gatewayβs identity:
Client Gateway β β β AUTH_CHALLENGE { nonce } β β βββββββββββββββββββββββββββββββββΊβ β β sign(nonce) with Ed25519 private key β AUTH_RESPONSE { signature } β β ββββββββββββββββββββββββββββββββββ β β β verify(signature, public_key) β β β proven genuine Gateway βThe Ed25519 private key is stored in the OS keychain. The public key is transferred to the mobile client only during QR pairing. After pairing, the client uses the stored public key to verify every future connection β making Man-in-the-Middle attacks impossible even if the Cloudflare tunnel is compromised.
Layer 4: End-to-End Encryption (E2EE)
Section titled βLayer 4: End-to-End Encryption (E2EE)βBeyond TLS (handled by Cloudflare) and token auth, Antimatter implements true E2EE using a Diffie-Hellman key exchange:
Pairing time: Phone generates ephemeral DH keypair β shares public key via QR Gateway generates ephemeral DH keypair β shares public key in response Both sides derive identical 256-bit shared secret (ECDH) *(This guarantees **Forward Secrecy** β because keys are ephemeral per-session, a compromised key today cannot decrypt past traffic.)*
Runtime: Sender: AES-GCM encrypt(payload, sharedSecret, randomNonce) Transport: only ciphertext traverses Cloudflare Receiver: AES-GCM decrypt(ciphertext, sharedSecret, nonce)Zero-knowledge routing: Cloudflare, proxies, and any other intermediary can only see encrypted bytes. Only the device and Gateway can decrypt.
Platform Implementations
Section titled βPlatform Implementationsβ| Platform | Crypto Library |
|---|---|
| Android | javax.crypto.Cipher (AES/GCM/NoPadding) + JCA Ed25519 |
| iOS | CryptoKit β AES.GCM.seal/open + Curve25519.Signing |
| Gateway | Node.js crypto β createCipheriv / verify |
Layer 5: Biometric Authentication
Section titled βLayer 5: Biometric AuthenticationβBefore the mobile app establishes any WebSocket connection, it requires the device ownerβs biometric verification:
- Android:
BiometricPromptβ Fingerprint, Face Unlock, or PIN fallback. - iOS:
LocalAuthenticationβ Face ID, Touch ID, or passcode fallback.
This ensures that even if someone physically picks up your phone, they cannot issue commands to your agent without authenticating as you.
Layer 6: Gateway/Adapter Sandboxing
Section titled βLayer 6: Gateway/Adapter SandboxingβThe system creates a strict security airgap between network ingress and local execution:
| Layer | Internet Access | Local Execution | Holds Secrets |
|---|---|---|---|
| Gateway | β (via Cloudflare) | β | β (keys, tokens) |
| Adapters | β | β | β |
If an attacker breaches the Cloudflare tunnel, they still need to defeat the 256-bit token + Ed25519 handshake.
If they defeat the handshake, the Gateway only forwards structured JSON payloads to adapters via 127.0.0.1:8765. Adapters have zero internet exposure.
If they compromise an adapter, they can only send structured IPC messages β not execute arbitrary code on the Gateway.
Layer 7: Payload Size Limits
Section titled βLayer 7: Payload Size LimitsβTo mitigate memory exhaustion (DoS) attacks:
- Maximum WebSocket payload size: 10 MiB
- Oversized frames β immediate connection close
- Per-IP connection limits enforced at the Gateway level
Optional: Cloudflare Zero Trust (Enterprise)
Section titled βOptional: Cloudflare Zero Trust (Enterprise)βFor the strongest security posture, configure a persistent Cloudflare Zero Trust tunnel with an Application Policy:
- Create a Cloudflare Zero Trust account.
- Create a Tunnel and point it to
localhost:8765. - Add an Application Policy that requires your email/SSO to access the tunnel URL.
- Update your
antimatter-gatewayconfig with theCLOUDFLARE_TUNNEL_TOKEN.
This adds a secondary authentication layer before any WebSocket connection is even attempted β your mobile must be logged in to Cloudflare Access first.
Threat Model Summary
Section titled βThreat Model Summaryβ| Threat | Mitigation |
|---|---|
| Network MITM (Cloudflare compromised) | E2EE + Ed25519 handshake |
| Stolen QR code / pairing token | Ed25519 identity proof on every connection |
| CSWSH (malicious website) | Origin header validation β 403 |
| Brute force token | Timing-safe comparison + rate limiting |
| Physical phone theft | Biometric auth gate before any connection |
| Adapter RCE escalation | Gateway/adapter sandboxing + payload size limits |
| DoS via large payloads | 10 MiB payload cap |
