Overview
The Mullvad VPN daemon communicates withapi.mullvad.net for account management, relay list updates, version checks, and other operations. To ensure API reachability even in censored networks, the client supports multiple access methods including direct connections, Shadowsocks bridges, and custom proxies.
Reference: mullvad-daemon/src/api.rs, docs/architecture.md:48-62
API Endpoints
The daemon interacts with Mullvad’s REST API for:- Account operations: Create account, login, check expiry, submit vouchers
- Device management: Register devices, rotate WireGuard keys, list/remove devices
- Relay list updates: Download current relay and bridge server lists
- Version checks: Check for app updates and security advisories
- GeoIP lookups: Determine current location and verify tunnel connectivity
- Problem reports: Submit diagnostic logs (with user consent)
Access Methods
The client supports multiple methods to reach the API, automatically selected based on availability and user configuration.1. Direct TLS Connection
Default method: Standard HTTPS connection toapi.mullvad.net.
- Fastest and most reliable when available
- Uses standard TLS 1.3
- No additional overhead
- May be blocked in censored networks
mullvad-daemon/src/api.rs:54
2. Mullvad Bridges (Shadowsocks)
Censorship-resistant: Routes API traffic through Shadowsocks proxies hosted on Mullvad bridge servers.- Client requests bridge server from relay selector
- Relay selector chooses Shadowsocks-enabled bridge
- All API traffic proxied through bridge
- Bridge forwards to actual API endpoint
mullvad-daemon/src/api.rs:55-63, management_interface.proto:478-488
Shadowsocks details:
- Cipher: Encryption algorithm (e.g.,
chacha20-ietf-poly1305) - Password: Shared secret for authentication
- Protocol: TCP or UDP transport
management_interface.proto:766-771
3. Encrypted DNS Proxy
Domain fronting: Uses encrypted DNS protocols to obfuscate API connections.- Client fetches encrypted DNS proxy configs from
frakta.eu - Connects using DNS-over-HTTPS (DoH) or DNS-over-TLS (DoT)
- DNS proxy forwards requests to actual API
- Appears as DNS traffic to network observers
mullvad-daemon/src/api.rs:64-78
4. Custom Proxies
Users can configure custom SOCKS5 or Shadowsocks proxies. SOCKS5 (Local):management_interface.proto:448-453
SOCKS5 (Remote):
management_interface.proto:454-462
Shadowsocks (Custom):
management_interface.proto:463-468
Access Method Selection
The daemon uses anAccessMethodResolver to dynamically select the appropriate access method.
Resolution Process
mullvad-daemon/src/api.rs:26-96
Access Method Priority
The client maintains a list of access methods with priorities:management_interface.proto:503-508, 490-495
Automatic Failover
When an API request fails:- Current access method is marked as potentially unavailable
- Next enabled access method is tried
- Process repeats until success or all methods exhausted
- Failed requests can trigger access method testing
Testing Access Methods
Users can test access methods before using them:- Proxy connectivity
- API reachability through proxy
- Authentication success
management_interface.proto:93-94
API Availability Monitoring
The daemon continuously monitors API availability:- Periodic connectivity checks
- Request success/failure tracking
- Automatic access method switching
- Exponential backoff on repeated failures
mullvad-daemon/src/lib.rs:46
Firewall Integration
API traffic must be allowed even when the tunnel is not connected.Allowed Endpoints
The firewall receives a list of allowed endpoints for API communication:mullvad-daemon/src/api.rs:98-100
Tunnel State Coordination
The API runtime coordinates with the tunnel state machine:- In secured states (Connecting, Connected, Error), only API traffic allowed outside tunnel
- In disconnected state, broader internet access may be permitted (depending on lockdown mode)
- API endpoint changes communicated to firewall in real-time
docs/architecture.md:55-58
Request Management
Asynchronous Operations
All API requests are asynchronous:Request Cancellation
API requests can be dropped in flight:- When tunnel connects, API connection resets
- Allows switching between access methods
- Ensures API uses current endpoint configuration
docs/architecture.md:59-61
Offline State Handling
When the device is offline:- API requests are blocked/queued
- Prevents wasted connection attempts
- Resumes when connectivity restored
docs/architecture.md:61-62
Address Caching
The API client caches the resolved IP address ofapi.mullvad.net:
- Reduces DNS lookup failures
- Enables API access when DNS is blocked/unreliable
- Periodically refreshed when DNS is available
mullvad-daemon/src/api.rs:9,29,36
Connection Modes
Direct Mode
Proxied Mode
mullvad-api/src/proxy.rs
API Client Implementation
The API client is implemented in themullvad-api crate:
Request Flow
- Daemon initiates request:
api_handle.get_relay_list().await - Access method resolution: Select appropriate access method
- Endpoint resolution: Determine IP address and port
- Firewall configuration: Ensure endpoint is allowed
- HTTP request: Execute via direct or proxied connection
- Response processing: Parse and return data
- Error handling: Retry or failover on errors
Censorship Resistance Strategies
Traffic Obfuscation
Different access methods provide varying levels of obfuscation:- Direct: Standard TLS - easily identifiable
- Shadowsocks: Encrypted proxy protocol - hard to detect
- Encrypted DNS Proxy: Masquerades as DNS traffic - very hard to block without breaking DNS
- Custom SOCKS5: Depends on proxy configuration
Domain Fronting
Encrypted DNS Proxy uses domain fronting:- TLS SNI shows innocent domain (
frakta.eu) - Actual API requests hidden in encrypted payload
- Difficult to block without blocking entire domain
Port Variability
Multiple ports supported for each method:- Shadowsocks: Range of ports from relay list
- UDP2TCP: Ports 80, 443, 5001
- QUIC: Port 443
- Harder to block all ports without false positives
Security Considerations
TLS Certificate Validation
All API connections validate TLS certificates:- Pinned certificate or standard CA validation
- Prevents man-in-the-middle attacks
- Even when using proxies, end-to-end TLS maintained
Proxy Trust Model
Mullvad bridges:- Operated by Mullvad
- Same trust as Mullvad relays
- API requests encrypted end-to-end
- User-provided
- TLS still protects API requests
- Proxy sees encrypted traffic only
Authentication
API requests authenticated via:- Account tokens (for account operations)
- Device tokens (for device-specific operations)
- OAuth tokens (for web authentication)
Management Interface Integration
Configuration
Access methods managed via gRPC:management_interface.proto:86-92
Events
Access method changes broadcast to frontends:management_interface.proto:729-740
Bridge Server List
Separate from relay list, bridge servers are dedicated to API access:management_interface.proto:748-761
Bridge Endpoint Data
management_interface.proto:764
Debugging and Testing
Access Method Testing
Test individual access methods before relying on them:- Proxy connectivity
- API reachability
- Authentication
Current Access Method
Check which method is currently active:Forced Access Method
Override automatic selection:Error Recovery
Request Retry Logic
Failed API requests trigger:- Immediate retry with same access method
- Switch to next access method on repeated failure
- Exponential backoff between attempts
- Circuit breaker after extended failures
Access Method Rotation
Periodic rotation ensures:- Dead access methods are discovered
- New methods are tested
- Best-performing method is used
Performance Optimization
Connection Reuse
HTTP connections are reused when possible:- Connection pooling for repeated requests
- Reduced TLS handshake overhead
- Lower latency for consecutive requests
Caching
- Relay lists cached locally (refreshed periodically)
- Account data cached (refreshed on access)
- Address cache reduces DNS lookups
Parallel Requests
Multiple independent API requests can run concurrently:- Relay list updates don’t block account checks
- Version checks run in background
- No artificial serialization
Related Documentation
- Management Interface
- Relay Selector
- Mullvad vs Talpid Layers
- Offline Detection
- Architecture Overview (source repository)