Skip to content

Security: sqlpxc/airhand

Security

docs/security.md

Security

← Back to README · 简体中文

Relay server and control codes

  • TLS 1.3 throughout (QUIC); the client verifies the server by certificate fingerprint pinning. Without a configured fingerprint the server's certificate is remembered on the first connection (trust on first use: [server_trust] in config.toml, Settings on Android, server-trust.txt for the web console), and a different certificate is refused afterwards
  • Brute-force protection: at most 20 failed attempts per IP (IPv6 grouped by /64) per 10 minutes, and each failure adds a 400 ms delay
  • When a code exists but its host isn't ready (still registering, or disconnecting), the answer is exactly the same as for a code that doesn't exist (counted as a failure, delayed the same way), so response timing doesn't reveal whether a code exists
  • Requests with the right code are rate limited too. Every request takes one of the host's session slots and an end-to-end handshake, so one IP (IPv6 grouped by /64) can start at most 6 connections per minute to the same host (AIRHAND_CONNECTS_PER_MINUTE; requests with a resume token count as well). If someone who knows the code keeps pestering a host, change its control code
  • Registering can't be used to probe codes: getting a code back requires a secret the server issued for that code (signed with the server's own key, which is kept in airhand.db, so it still works after a restart). Without one the host gets a fresh code whether or not the code it asked for is in use. Fresh codes are limited per network (30 per 10 minutes per IPv4 address / IPv6 /48, AIRHAND_NEW_CODES_PER_IP), so codes can't be hoarded
  • Resume tokens: when a controller connects, the server gives it a token, and the controller presents it when reconnecting. The first half of the token is the server's signature (with its own key) over the control code, proving the holder connected to that code before; the second half is derived from the host's code and secret (it can't be computed or reversed without the secret). Requests with a token don't count as failures and aren't subject to the guessing limit, so however long a host stays offline, neither automatic reconnects nor opening an offline device from My devices use up the guessing allowance of the IP (or of a web console sharing one IP). A token that wasn't issued by the server for that code always gets the same answer, whether or not the code exists or is in use, so tokens can't be used to guess codes. A token stops working when the host changes its code, and when the user at the host disconnects all controllers (the server then gives the host a new secret, so a disconnected controller can't come straight back with its token; it would need the control code again). If the host gets disconnected while changing its secret and never receives the new one, it asks the server to change it when it registers next time (by then the server may have restarted and remember nothing), so the old secret can't become valid again and bring the old tokens back
  • Getting a control code back after a reconnect requires a random secret, so nobody else can claim it
  • Server resources: at most 128 simultaneous connections per IP (IPv6 /64, AIRHAND_MAX_CONNS_PER_IP), and the relay's QUIC flow-control windows are sized for forwarding (4 MiB per stream, 16 MiB per connection), so a peer that stops reading can only make the server buffer a few MiB for it. Clipboard files through the relay are limited per paste (AIRHAND_MAX_FILE_SIZE, 50 MiB by default); the server only sees ciphertext and enforces this per stream. It's a resource limit, not a security boundary: two cooperating clients can split one paste into many streams
  • Fixed control codes: the server only stores a hash of the host's secret (in airhand.db), so the database can't be used to claim codes. On Windows the host's secret is encrypted with DPAPI for the SYSTEM account (for that user when installed just for the current user), so a copied config.toml doesn't carry the code to another computer; on macOS / Linux config.toml is readable by your account only. Change control code retires the old code on the server: nobody can claim it back (not even with the old secret), and it isn't handed out to anyone else for 7 days
  • My devices holds other computers' control codes: on Windows they're encrypted with your account (DPAPI), on macOS / Linux protected by the file permissions (600). Don't share config.toml
  • Installed for all users, the Windows host runs as SYSTEM so that it can operate UAC prompts and the sign-in screen: whoever can connect to it (knows the control code, and has paired or knows the pairing code) controls the computer with administrator rights. Give the codes only to people you trust; whoever sits at the computer sees who is connected and can disconnect them, change the control code / pairing code or quit Airhand. The program the service runs can only be installed inside Program Files (the installer checks), so ordinary users can't replace it. Installed just for the current user, the host runs as that user, and whoever connects only gets that user's rights
  • The host's tray always shows who is controlling the computer; disconnect them or change the code with one click
  • Files on the clipboard (see How it works → Files on the clipboard): the other side can only fetch what this computer's clipboard offered (the two latest copies). Every path segment is checked, .. can't climb out, links inside folders aren't followed, and there's no general-purpose file reading interface. The Windows host runs as SYSTEM, so files copied locally are read by the tray as the signed-in user and a controller can't borrow SYSTEM's rights; without a tray nothing is offered. Whatever you copy is given: copy a folder and the other side can fetch everything in it. Like copied text, there's no switch for this on the host (the controller can operate the computer anyway); a controller with clipboard sync off neither takes nor gives files

End-to-end encryption

TLS to the relay ends at the relay, so sessions get a second, end-to-end layer (protocol in crates/airhand-proto/src/handshake.rs):

  • Can't read, can't tamper: at the start of every session the controller and the host run a Noise handshake on the control lane (X25519, ChaCha20-Poly1305, BLAKE2s). After that the picture, sound, keyboard and mouse input and the clipboard are encrypted end to end (AES-256-GCM), with one key per lane and direction, and every frame carries a counter (on the control and bulk lanes they must follow one another). The relay can't read them, and frames it changes, drops, replays or injects fail to decrypt, which ends the session. The session version is checked for an exact match inside the authenticated handshake; there is no downgrade or unencrypted fallback.
  • Knowing who's on the other end: every device has a long-term key pair. The first time a controller connects to a computer it remembers that computer's public key (host_key in My devices, like SSH's known_hosts) and only accepts that key afterwards. If it differs, the controller says "the remote computer's identity changed", doesn't reconnect automatically, and can't simply be told to trust the new identity: that error arrives in the clear before the handshake completes, so the relay could forge it, and trusting a new identity without verification would let the relay get itself remembered as that computer. Once you've confirmed the computer really was reinstalled (it may also be someone impersonating it), enter its current pairing code (from its tray, or a phone's Share screen tab) to pair again: the pairing code authenticates the device, and only a successful pairing records the new identity. On the first connection both sides show the same 6-digit safety code (console: hover the control code in the toolbar; Android controller: the session menu; computer host: after the device in the tray's list of controllers; phone host: in the list of who's watching and in the notification when it connects), so you can check that nobody is in between
  • Pairing code: the relay assigns the control codes and uses them to find hosts, so the relay knows every control code; letting anyone in on the control code alone would mean trusting the relay (it could connect by itself), so no host ever does that. Every host, computer or phone, asks for a pairing code: a controller that hasn't paired yet has to enter the 6-digit pairing code shown on the host (a computer's tray menu, a phone's Share screen tab) on its first connection. The rules are the same code on both (airhand_link::host::pairing). The pairing code never goes through the server; both sides turn it into a key with SPAKE2 (it's only a few digits: used directly as a key, a man in the middle could brute-force it offline from one recorded handshake; with SPAKE2 each attempt allows one guess). After 5 unsuccessful attempts (wrong codes, interrupted handshakes or timeouts), pairing is paused until the local user picks a new code. Each handshake reserves a local slot before starting: failures plus outstanding attempts cannot exceed 5. Changing the code or forgetting paired controllers prevents old handshakes from committing authorization. Once paired, the host remembers the controller ([[paired]] in config.toml; pairing.json in a phone's private files), and the code isn't needed again
  • Replays: a reconnect to a computer the controller already knows takes a single round trip (Noise IK), and the first message of that kind of handshake has no freshness: the relay could send a recorded one again. The host answers it and starts capturing (without waiting for the confirmation, saving a round trip), but only shows the controller in the tray / the phone's list (and notifies the person holding the phone) after it decrypts the controller's first encrypted frame (the confirmation), and ends the session if that doesn't arrive within 10 s. Only the real controller can produce that frame, and only it can derive the keys the video is encrypted with. So a replay can't make the host show a paired controller that isn't there and reveals nothing; at most the host encodes for a few seconds for nobody
  • The tray menu (a phone: the Share screen tab, and Settings for forgetting) can change the pairing code and forget paired controllers; Change control code does both. "Disconnect all controllers" only disconnects them: paired controllers can come back with the control code
  • A paired controller connects to a phone without anyone at the phone confirming, so the phone notifies whoever holds it every time a device connects (who, from which IP, the safety code, with "Disconnect all"). The phone only accepts connections while it's sharing, which the person at it starts and the system confirms each time
  • Where the keys live: the host's identity and pairing code in [host] in config.toml (encrypted with DPAPI for the SYSTEM account on Windows); the console's identity in [controller] (one per account on Windows, encrypted with that account's DPAPI); on Android in the app's private storage; for the web console in controller-key.txt (AIRHAND_WEB_IDENTITY)
  • What the relay still knows: who connected to whom and when (control codes, IPs, the names and systems both sides report), and the size and timing of the traffic (typing rhythm may show in the timing). With one stream per video frame (frame streams) it also sees how large each frame is and when one is abandoned (roughly visible from the timing anyway).
  • Direct path (see How it works): the direct path carries the same end-to-end ciphertext, so it is exactly as secure as going through the relay. Who is on the other end is settled by mutual TLS: each end has a throwaway certificate whose fingerprint is exchanged over the encrypted, authenticated control lane, and TLS only accepts those two fingerprints, so a man in the middle can't impersonate either side. The control lane always has a complete copy on the relay, where the counters must still follow one another; frames dropped or delayed on the direct path change nothing. A direct path needs each end to know the other's IP address: the server only tells each end its own public address, and the candidates (including LAN addresses) are exchanged over the encrypted control lane, the host sending its own only after the session has started (after it let this controller in). So someone who only knows the control code and hasn't been let in can't learn the host's address, and the relay never sees LAN addresses. The host only accepts direct handshakes while one of its sessions is offering candidates
  • Desktop console: the console window reaches the controller service inside the app over a WebSocket that only listens on 127.0.0.1. The URL carries a random token that only the console page gets (from a Tauri command), and only the console page's Origin is accepted, so neither other local programs nor web pages in a browser can connect. What travels on it is already decrypted, and never leaves this computer
  • Web console: end-to-end encryption ends at the web console service (it is the controller); the browser talks to it over HTTPS / WSS. So the machine running the web console can see the picture; if it's the same machine as the relay, web console users effectively have no end-to-end encryption

Privacy mode

  • A controller that can connect can already operate this computer (with administrator (SYSTEM) rights on Windows, with the logged-in user's rights on a Mac); privacy mode lets it do so without the people at the computer seeing it: all local monitors go blank and the local keyboard and mouse stop working. To keep others from doing that on a computer, add privacy_mode = false to its config.toml
  • It's only turned on after the controller confirms the handshake, so a replayed handshake message can't blank the screen. When the remote control ends (the controller disconnects; one that dropped gets 30 seconds to reconnect) the host locks the screen first and then turns privacy mode off, so the local monitors come back showing the lock screen; a key press or click at the computer after the controller dropped (or shortly before) stops waiting for it to reconnect, still locking first, so people there only get the lock screen; people at the computer can end it by disconnecting it from the network or restarting it (after a restart a Windows host first restores the monitors)
  • The screen is locked by default when the remote control ends (not only in privacy mode): when the controller leaves, the desktop isn't left open in front of whoever is at the computer. To turn this off, uncheck "Lock screen when remote control ends" in the tray menu (lock_on_end in config.toml)
  • On Windows, display changes are never saved to Windows' display database, and they're undone after a crash or a power cut too, so the computer won't come up with a black screen later (see How it works). On a Mac no display settings are changed: the gamma tables that blank the displays, the black windows and the event tap that blocks the keyboard and mouse all belong to Airhand's process, and macOS removes them when it quits (or crashes)
  • On a Mac, blocking the keyboard and mouse keeps the people at the computer from interfering; it isn't a security boundary: keyboard and mouse events synthesized by other programs on the Mac aren't blocked, nor is the local keyboard while a password field has focus (see Known limitations)

Pausing AirDrop during remote control (macOS)

  • The helper installed when you turn this option on (/Library/PrivilegedHelperTools/app.airhand.awdl) runs as root; launchd only starts it when a connection comes in, and it exits after a while with nobody using it. It does one thing: while a connection "holds" it, it keeps awdl0 down, and when all connections are gone it puts it back the way it was. The interface name is fixed, it takes no arguments, reads and writes no files, and its protocol has a single command (see client/src-tauri/src/awdl/helper.c)
  • It accepts connections on /var/run/app.airhand.awdl.sock, which programs of any local user can reach: the most they can do is keep this Mac's AirDrop, Sidecar and the like unavailable while they stay connected (it takes at most 16 connections at a time)
  • When installing, the helper itself (base64) and the launchd configuration travel inside the arguments of the administrator script, never through a temporary file an ordinary user could write, so no other program gets a chance to swap it before root copies it; the installed files belong to root and ordinary users can't change them
  • To get rid of it: turn the option off in the menu (the helper stays but doesn't run), turn app.airhand.awdl off under System Settings → General → Login Items & Extensions → Allow in the Background, or uninstall Airhand (which removes it, see Uninstalling)

Web console

  • The WebSocket only accepts pages from the same site (so other websites can't connect through your browser); an access password can be set (HTTP Basic login, then an HttpOnly, SameSite=Strict cookie; wrong passwords are answered with a delay); use HTTPS from other computers. The web console sees the picture too, so run it on a machine you trust. Everyone using it reaches the relay from that machine's IP, so they share the brute-force allowance

There aren't any published security advisories