Skip to main content

Module pairing

Module pairing 

Source
Expand description

Pairing a device with a portable identity: the link a device shows as a QR code, and the frames the identity’s phone and the device then exchange over a direct Iroh connection on PAIR_ALPN. No Spoolframe server takes part.

A TV has no camera, so the QR code goes one way, device to phone:

spoolframe://pair?e=<endpoint id>&c=<code>&n=<name>&a=<ip:port>&r=<relay url>

  • e, the device’s EndpointId as 64 hex digits, and c, the one-time PairingCode as 43 base64url characters (no padding), are required. The phone dials e and nothing else, and Iroh’s TLS proves the key, so the phone pairs with the device that showed the code or with nothing.
  • n is the device’s name, for “Pairing with …” while the phone dials; cut to MAX_NAME characters.
  • a (repeated, at most MAX_ADDRS) and r (repeated, at most MAX_RELAYS) are where the device may be reached. Hints: the key is still proved whatever path is taken.

Values are percent-encoded as in an invite link (crate::invite). A parameter this build does not know is ignored; a second e or c is not (the link is refused), nor is one that cannot be read.

Then, on one bidirectional stream, each frame a crate::codec frame (big-endian u32 length, CBOR) of at most MAX_FRAME bytes:

  1. phone → device: PhoneFrame::Hello, the code and the identity the phone wants this device to act as;
  2. device → phone: DeviceFrame::Key, the device’s key for that identity and its name, or DeviceFrame::Refused;
  3. phone → device: PhoneFrame::Credential, the root’s credential for that key, the identity’s newest state and the servers it signs in to, or PhoneFrame::Declined;
  4. device → phone: DeviceFrame::Done, or DeviceFrame::Refused.

Structs§

PairedServer
A server the paired identity signs in to, as the phone has it saved: enough for the device to pin and reach it. The phone vouches for it as the invite that brought it there did; the device dials the key and nothing else, and Iroh proves it.
PairingAnswer
The root terminal’s answer to a PairingOffer: what PhoneFrame::Credential carries on a direct pairing. The server only carries it: the device checks the credential names its own key and shows whose identity it is before it keeps it.
PairingCode
A one-time pairing code: 32 random bytes the device made, shown only in its QR code. Compared in constant time; fmt::Debug does not show it.
PairingLink
What a pairing link holds.
PairingOffer
A device’s pairing request, held on a server under a RelayCode for a root terminal to fetch: the key the root is to vouch for and the device’s name. Public data: whoever has the code may read it.
RelayCode
The short code a device shows beside its QR code, for a root terminal with no camera to pair it through a server both reach: 10 characters of Crockford’s base32, written in two groups of five.

Enums§

DeviceFrame
What the device sends.
LinkError
Why a text is not a pairing link.
PhoneFrame
What the phone sends.
Refusal
Why a device refused a pairing. The device’s pairing ends with each of them: it shows a new code to try again.

Constants§

CODE_LEN
Bytes in a PairingCode: 256 bits, out of reach of guessing within its five minutes whatever the rate.
CODE_TTL_SECS
How long a code is good for, from when the device shows it.
MAX_ADDRS
The most a hints a link is written or read with.
MAX_FRAME
The largest pairing frame either side reads: room for an identity state at its limit of revoked keys, 1024 of about 90 bytes each.
MAX_LINK
The longest link read, in bytes. A link this build writes fits with every hint at its limit, the name in characters of three bytes each; a usual one (a LAN address or two, a short name) is under 250, a QR code of version 10 or so.
MAX_NAME
The most characters of the device’s name a link carries.
MAX_PAIRED_SERVERS
The most servers a PhoneFrame::Credential carries; a device reads no more.
MAX_RELAYS
The most r hints a link is written or read with.
PAIR_ALPN
The ALPN of pairing, version 1. A device accepts it only while it shows a pairing code; at any other time a connection on it fails its handshake.
RELAY_CODE_LEN
Characters in a RelayCode: 10 of Crockford’s base32, 50 bits. Typed by a person, so short; guessed only at the rate the server lets a stranger try, against a code that lives RELAY_TTL_SECS.
RELAY_TTL_SECS
How long a server holds a relayed pairing, from its offer.

Functions§

parse_link
The pairing link text holds.