Daniel Bae
Menu

Concept art from Arcane

Before a Latch machine answers anything, it asks Tailscale one question: is the caller signed in as the same account?

Latch streams a desktop, full screen, between your own machines. Mac, Windows, Linux and a VPS container run the same app, written in Rust with egui and wgpu, and each machine lists the others and can share its own desktop. The picture comes from Sunshine, the streaming engine Latch installs and configures, and the Moonlight protocol library, moonlight-common-c, is compiled into the viewer. On a Mac the frames are decoded by VideoToolbox. On Windows and Linux the viewer decodes H.264 in software with OpenH264, which the repository calls a development path. Latch is GPL-3.0-or-later. The source is on GitHub and there is a product page.

One question, put to Tailscale

Every machine runs a small control service on a fixed TCP port. Other machines use it to read status, enter a pairing PIN, sleep the machine, read its clipboard and push it a new version of the app. There are no Latch accounts and no passwords. A comment at the top of crates/core/src/tailscale.rs says what stands in for them: the tailnet is “Latch’s network and its list of trusted machines”. Latch reads Tailscale through its command line, tailscale status --json for the machine list and tailscale whois to learn who owns an address.

The rule is in Service::authorized. Loopback is the host’s own window and always passes. An address outside Tailscale’s range is refused. Everything else goes to whois.

Rust
fn authorized(&self, ip: IpAddr) -> bool {
    if ip.is_loopback() {
        return true;
    }
    if !is_tailnet_ip(ip) {
        return false;
    }

The comparison is Owner::admits. For an ordinary machine, the caller has to be the same Tailscale user.

Rust
fn admits(&self, peer: &tailscale::WhoIs) -> bool {
    let user = peer.user_profile.id;
    if user == 0 {
        return false;
    }
    if !self.tagged {
        return user == self.user;
    }

Anyone else gets a 403. A whois answer is remembered for a minute, refusals included; a failed lookup is not remembered, and counts as a no. A server with an ACL tag, such as a relay VPS, belongs to no account, so the code falls back to the members of its own tailnet, matched by login. Every tagged machine shows up as the same “tagged-devices” user, and the source notes that a matching ID proves nothing across tailnets.

Two more checks sit around it. Before it, a request with an Origin or Sec-Fetch-Site header, or a Host that is not one of the service’s own addresses, gets a 403, so a web page cannot drive the service even through DNS rebinding. After it, a POST has to carry JSON or the executable itself, which a page cannot send cross-origin without a preflight that nothing answers. On Windows, setup also adds a firewall rule that admits the port only from Tailscale’s address range.

None of this held in every release. The 4.1.0 changelog says that since 4.0.0 the service had answered any machine Tailscale could name, so a machine shared in from someone else’s tailnet could pair with the PC, sleep or restart it, read and write its clipboard, and push it a new latch-host.exe. The loosening had a reason, given in its commit message: a tagged node’s own user is “tagged-devices”, so a strict comparison made a relay VPS refuse the Mac that wanted to open its desktop. The fix keeps the account comparison and gives tagged nodes the tailnet rule, and its test covers three shapes: the owner’s Mac, a tagged relay and a friend’s shared-in machine.

Pairing without a PIN to type

Sunshine pairs clients with the Moonlight handshake, which needs a four-digit PIN entered on the host. Latch does both ends. On first connection the viewer picks a random PIN and starts the handshake, and the engine holds its first reply until a PIN arrives. Meanwhile the viewer posts the PIN to the host’s control service. That route sits behind the check above, so only a machine on the account can have a PIN entered. Latch on the host passes it to Sunshine’s own API using a login Latch generated for the engine, which stays on that machine.

When the handshake finishes, the viewer pins the host’s certificate and accepts only that one from then on. If the engine is reinstalled and the certificate changes, the viewer notices the mismatch, forgets the old certificate and pairs again.

The clipboard

The streaming protocol carries keys and pictures, not clipboards, so the control service has a /v1/clipboard route. While a stream runs the viewer polls it about every second and a half and puts new host text on its own clipboard. When you paste in the stream, the viewer first sends its own text to the host and then sends the paste shortcut.

It is text only, cut at 32 KB so that it fits a 64 KiB request body once escaped, and line endings are converted for Windows. Being an ordinary route, it falls under the same rule: only the account’s own machines can read or write a clipboard. The 4.1.0 changelog records a bug here. Text copied on a Mac or Linux machine never reached the viewer, because only Windows reported a clipboard sequence number; elsewhere it was always 0, and the viewer took every copy for one it had already seen.

A relay of your own

Tailscale tries a direct path first, then a peer relay, then its shared DERP relays, and Latch needs no code for that order. It does show which path a stream is on: “Direct”, “Via your relay” or “Relayed via” and a city. The deploy/relay/ directory is a Docker kit that turns a machine with a public address into a peer relay, which is a node tagged tag:relay plus a policy grant. A peer relay serves only its own tailnet, the kit’s notes point out, so there is no shared Latch relay and there cannot be one.

Tests and releases

CI runs on GitHub Actions for Windows, macOS and Linux: clippy with warnings denied and cargo test --workspace. The UI tests build the window headlessly from fixture data and check that every state fits the smallest and the largest window with no control overlapping another. A separate test, ignored by default, renders the same states to PNG for review. The figure is one of those renders, so its machines and addresses are fixtures.

Latch’s Machines tab: this Mac, a Windows PC reached through a relay, a sleeping PC and a Linux machine.
The Machines tab as the snapshot test renders it. The second row is on a relayed path.

A release is a tag.

YAML
on:
  workflow_dispatch:
  push:
    tags: ["v*"]

The workflow runs the tests before building the macOS tarball and the Windows zip, checks that the pinned Sunshine archive matches the pin in setup.rs, and publishes through gh release create with that version’s section of CHANGELOG.md as the notes. The Mac app is signed ad hoc rather than with a Developer ID, which is why the install command clears the quarantine flag.

After that the app updates itself. The Mac asks GitHub for the latest release every few hours, checks the digest and its own code signature, and swaps itself in once no stream is running. It also sends the new host executable to each Windows PC over /v1/update. The PC verifies the SHA-256, replaces its executable and restarts, and since 4.1.0 it puts the old one back if the new one has exited within two seconds.

Share

TopicsRustTailscale

Written by Daniel Bae

Computer science student at UCLA. I build desktop, web and command-line software in Rust, Go and Python, and write here about how it is made. About this site