open-transfer

Nearby-device protocol (v1)

How Open Transfer apps find each other, pair, and send files directly to the devices a person picks. Anything that speaks this protocol can join a network of Open Transfer devices — the desktop apps, the Android app and the CLI all run the same Python implementation (discovery.py, mesh.py, mesh_api.py).

Roles

Term Meaning
app A device running Open Transfer. Has a stable id (d- + 24 hex), an HTTP server, and announces itself.
owner The person using an app on that device — requests from 127.0.0.1. Accepts or declines incoming files.
visitor A browser on a device without the app (opened an app’s link / QR code). Gets an id w-… in a signed session cookie. The app it opened sends and receives on its behalf.
flowchart LR
  subgraph Wi-Fi
    A[Mac app] <-- HTTP --> B[Windows app]
    A <-- HTTP --> C[Android app]
    B <-- HTTP --> C
    P((Phone browser)) -- opens link of --> C
  end

Apps talk to each other directly. A visitor’s files travel visitor → its app → receiver (one hop through the app it is connected to).

1. Discovery (UDP multicast)

{"app": "open-transfer", "v": 1, "type": "announce",
 "id": "d-3f…", "name": "Sonu’s MacBook", "form": "computer", "platform": "macos",
 "port": 5000, "rev": 7, "ver": "3.0.0"}

type is announce | reply | find | bye. The peer’s address is the datagram’s source IP, never a field in the packet. A bye counts at once only from the address we hold for that device; from any other address we say hello to the device there first, and it’s gone only if it doesn’t answer. rev changes when the app’s visitors or name change, prompting others to fetch its info.

find — “whoever has Add device open, answer”: {"type": "find", "id": "d-…"}. Nothing about the code is sent. An app whose Add device screen is open answers with a reply, and its announcements and /info carry "pairing": true while it stays open.

Multicast is often blocked (guest Wi-Fi, some routers, Docker). So apps also:

An app’s addresses are those of its interfaces too, not just the route out: on a device that is the hotspot, the hotspot address is often on neither. Mobile-data, VPN and container interfaces are left out.

An app is nearby while it was heard from in the last 15 s; unpaired apps are forgotten after 2 minutes, paired ones stay listed as “Not nearby”.

2. App ↔ app HTTP API

All under /api/p2p/v1, JSON unless noted. No PIN is needed (the PIN guards the web UI); every transfer still needs the receiver’s consent. Requests between paired apps carry a signature (§4).

Request Purpose
GET /info {id, name, form, platform, port, version, accepts, visitors: [{id, name, form, platform}]} (visitors hidden when a PIN is set and the caller isn’t paired)
POST /hello body = caller’s info Registers the caller (address = TCP peer address); returns /info plus you: {reachable} once it has tried to reach the caller — how a PC learns that others can’t connect to it (usually its firewall)
POST /offers Offer files (below) → 201 {id, secret, state, reason} (reason says why, when it is declined straight away)
GET /offers/<id> + X-OT-Secret {state, reason, files: [{state, received}]}
PUT /offers/<id>/files/<n> + X-OT-Secret, Content-Length Raw file bytes → 201 {file} (small files)
PUT /offers/<id>/files/<n> + X-OT-Secret, Content-Range One 2 MiB piece of a big file → 308 {received, ranges} until complete, then 201. Pieces may arrive in any order; the receiver stages them sparsely and publishes atomically
GET /offers/<id>/files/<n>/status + X-OT-Secret Staged bytes/ranges for one incoming file (sender resumes the missing pieces)
DELETE /offers/<id> + X-OT-Secret Sender cancels
POST /pair/begin, POST /pair/prove Pairing (§3)
POST /unpaired (signed) {id} The sender unpaired this device: it forgets the sender too (here only, not its sync network) and the owner’s page says “X unpaired this device. Pair again…”. An unsigned or forged one is 403. A signed offer from an app this one no longer trusts gets 403 peer_unpaired (“Pair again to send to it”), never a plain or unverified fallback
POST /clip (signed) A clipboard item shared by hand (both sides must allow each other)
POST /sync (signed) {env} A sync/1 envelope: clip, introduction, revocation or join, sealed for this device
POST /sync/forward (signed) {to, env} Pass a sealed clip on to to (one hop) when the sender can’t reach it

Offer

POST /api/p2p/v1/offers
{"from":   {"id": "d-sender…", "name": "Gaming PC", "form": "computer", "platform": "windows", "port": 5000},
 "origin": {"id": "w-visitor…", "name": "Pixel 8", "form": "phone", "platform": "android"},
 "to":     "d-receiver…",
 "files":  [{"name": "IMG_0001.jpg", "size": 2481331, "mime": "image/jpeg"}]}

States: pending → accepted → receiving → done, or declined, expired (no answer in 120 s), canceled, failed. Offers to an owner from a paired app (and with --auto-accept) start as accepted. With --paired-only, offers from unpaired apps are refused (403). With “Encrypted transfers only” (--encrypted-only or the owner’s switch), an offer without a usable enc block is refused (403 encrypted_only, with what to do), and the sender doesn’t offer to an app it can’t encrypt to.

The sender polls GET /offers/<id> until it leaves pending, then uploads each file with PUT. The receiver streams it to a .part file and publishes it atomically; the byte count must equal the offered size. If the receiver cancels, further reads fail and the upload gets 410.

One-to-many

The sender’s own browser uploads each file once to its app (PUT /api/send/<job>/files/<n>). The app streams the bytes to every accepting receiver at the same time — each receiver has its own thread and a bounded queue; a receiver that takes no data for 60 s is dropped without stalling the others. Nothing is staged on the sender’s disk.

Browser to browser (WebRTC)

When the receiver is a browser (a visitor) and the sender is a page too (any visitor, or an app’s own window), the file goes straight between the two browsers over a WebRTC data channel; the apps only carry the two connection messages:

sender page → its app        POST /api/signal {job, target, kind: "offer", sdp}
  its app → receiver's app   POST /api/p2p/v1/signal {dir: "to_receiver", session, secret, kind, sdp, n, mac}
receiver page ← its app      GET  /api/signals            (announced by "signals": n in /api/state)
receiver page → its app      POST /api/signal {session, kind: "answer", sdp}
  … → sender's app           POST /api/p2p/v1/signal {dir: "to_sender", job, target, secret, kind, sdp, n, mac}

3. Pairing

Pairing runs SRP-6a (RFC 5054: 2048-bit group, SHA-256) over the short-lived 6-digit code, and leaves both apps with a shared 32-byte key. A is the app showing the code, B the one entering it; the SRP identity is "<idA>|<idB>".

B → A  POST /pair/begin  {device: B-info}
A → B                     {salt, b: B (hex), device: A-info}
B → A  POST /pair/prove  {id: B, a: A (hex), m1: M1}
A → B                     {m2: M2}
key = HMAC-SHA256(K, "open-transfer-pair-key/2|<idA>|<idB>")

K is SRP’s session key; M1 and M2 prove each side has it. Someone who sees every message can’t test a guess offline (not even the right code), and someone pretending to be A or B gets one guess per attempt.

A accepts the code only while its Add device screen is open: the page renews a 30-second window while it shows, and opening it shows a fresh code. A rate-limits proofs (5 per minute per address) and shows a new code after 10 wrong guesses, after every successful pairing, and every 10 minutes. Keys are stored in <state>/trusted.json, sealed with a vault key from the OS keystore (encryption.md). An app from before SRP answers /pair/begin with 404, and B says to update it.

Entering a code without an address: B sends a multicast find and asks every device it knows for /info, then runs SRP with those showing "pairing": true (devices it isn’t paired with first).

The QR code in “Add a device” is http://<ip>:<port>/?pair=<code> (+ &join=<token> with a PIN set: 10 minutes, never the PIN). Every app’s Scan its QR code (under Add device → Enter a code) reads it with the device’s camera and pairs as above: the Android app with its own scanner, the desktop windows and browsers with any camera they have (built-in or USB, switchable), decoding with BarcodeDetector or, where there’s none, jsQR. The camera is asked for only when a scan starts and let go when it ends (found, Cancel, the sheet closed, the page hidden); entering the code is always there. A phone camera simply opens it, which signs that browser in as a trusted visitor (its sends to the owner are accepted automatically).

4. Signed requests

Requests from a paired app carry:

X-OT-From: d-sender…
X-OT-Auth: <unix time>:<hex HMAC-SHA256(key, "open-transfer/1\n<time>\n<METHOD>\n<path>\n<sender>\n<sha256(body)>")>

Receivers accept signatures within ±120 s and refuse a signature they have already seen. A valid signature makes an offer from that app’s owner auto-accepted; anything else is treated as a stranger (asked first).

A paired app’s new address

Anyone on the Wi-Fi can send an announcement carrying a paired app’s id, so for a paired app the address (and anything else the packet says) changes only on proof:

Apps that aren’t paired move as before (there’s no key to prove anything with). Older apps don’t answer challenges; their own signed hellos still move them.

Security notes and limits