Sendspin has two standard ways to establish connections: Server and Client initiated. Server Initiated connections are RECOMMENDED as they provide standardized multi-server behavior.
Servers MUST support both methods described below. Clients MUST use exactly one of the two methods at a time, advertising or discovering accordingly.
Connections to an address advertised via mDNS MUST use plain ws://. Confidentiality and integrity are provided end to end by the Noise layer inside the WebSocket payloads.
Clients announce their presence via mDNS using:
- Service type:
_sendspin._tcp.local. - Port: The port the Sendspin client is listening on (recommended:
8928) - TXT record:
pathkey specifying the WebSocket endpoint, REQUIRED (recommended value:/sendspin) - TXT record:
namekey specifying the friendly name of the client (OPTIONAL)
The server discovers available clients through mDNS and connects to each client via WebSocket using the advertised address and path. The server SHOULD only connect to an advertised address that is not a loopback or unspecified address, and only when the advertised path matches the path-absolute rule of RFC 3986. The server MUST NOT include an Origin header in the upgrade request.
The client MUST reject a WebSocket upgrade request to its Sendspin endpoint that carries an Origin header.
The TXT name SHOULD match the name the client sends in client/hello. It is only a discovery-time hint; if the two differ, the client/hello value is authoritative. The TXT name is plain text.
Clients MUST NOT manually connect to servers while advertising _sendspin._tcp.
A client admits one connection at a time. It MAY admit more, as long as at most one admitted connection has 'playback' in its activities and at most one has 'pairing'. One connection MAY have both.
Clients MUST persistently store the server_id of the server that most recently held an admitted connection while 'playback' was among its activities (the "last-playback server").
When a new server connects, the client lets the handshake complete before applying admission; the new connection is provisional until its first server/activate declares its activities. The client arbitrates that activation and every later one, and MUST NOT arbitrate an activation that is not admissible.
An activation conflicts with another admitted connection when it declares an activity, 'playback' or 'pairing', that the other connection already has in its activities. On a client that admits only one connection at a time, an activation on a provisional connection always conflicts with the admitted connection. A client MAY cap how many connections it admits at once. When a client is at its cap and an activation on a provisional connection conflicts with no admitted connection, it conflicts with each admitted connection with empty activities instead, and the client rejects it if there is none. The client compares the activating connection with each connection it conflicts with, classifying each by the highest-ranked activity in its activities, and the activating connection by those the activation declares, from highest to lowest:
'playback''pairing'
A connection with empty activities ranks lowest. The activating connection wins when it ranks higher or equal, and loses when it ranks lower. Two exceptions:
- A connection with a pairing attempt in progress is not displaced: the activating connection loses against it.
- When both connections have empty
activities, the activating connection wins only if itsserver_idmatches the last-playback server (and the other's does not).
The client applies an activation that conflicts with no connection or wins against every connection it conflicts with, admitting its connection if provisional, and displaces those connections. Otherwise it rejects the activating connection.
A provisional connection that has not sent server/activate within 30 seconds is dropped. Clients MAY cap how many provisional connections they hold at once, rejecting further incoming connections as if they were lower priority.
A displaced connection receives client/goodbye reason 'another_server' (or pair/abort reason concurrent_attempt if it is a pairing handshake). A rejected connection, provisional or admitted, receives client/goodbye reason 'concurrent_attempt' (or pair/abort reason concurrent_attempt if the rejected activation declares 'pairing'). The client then closes the connection.
A server that already holds a connection to a client MUST NOT open another connection to it for pairing. It pairs on the existing connection instead.
If clients prefer to initiate the connection instead of waiting for the server to connect, the server MUST be discoverable via mDNS using:
- Service type:
_sendspin-server._tcp.local. - Port: The port the Sendspin server is listening on (recommended:
8927) - TXT record:
pathkey specifying the WebSocket endpoint, REQUIRED (recommended value:/sendspin) - TXT record:
namekey specifying the friendly name of the server (OPTIONAL)
Clients SHOULD discover the server through mDNS. A client that discovers the server initiates a WebSocket connection using the advertised address and path. The client SHOULD only connect to an advertised address that is not a loopback or unspecified address, and only when the advertised path matches the path-absolute rule of RFC 3986.
The TXT name SHOULD match the name the server sends in server/hello. It is only a discovery-time hint; if the two differ, the server/hello value is authoritative. The TXT name is plain text.
Clients MUST NOT advertise _sendspin._tcp while using client-initiated connections.
Unlike server-initiated connections, servers cannot reclaim clients by reconnecting. How clients handle multiple discovered servers, server selection, and switching is implementation-defined.
Note: After this point, Sendspin works independently of how the connection was established.
All Sendspin connections use end-to-end encryption based on the Noise Protocol Framework.
Sendspin uses the KKpsk2 Noise pattern. Both static keys are pre-known to both parties (the client_id of the client and the server_id of the server are the static public keys), and a Pre-Shared Key is mixed in at the end of the handshake's second message.
The server is the Noise initiator, the client is the Noise responder, regardless of which side initiated the WebSocket connection.
Security properties. Forward secrecy is provided by the ephemeral-key DH in each handshake: compromise of static keys or the PSK does not retroactively decrypt prior sessions' transport traffic (the exception is the first handshake message's payload, recoverable with the client's static key). Replay protection is provided by Noise's per-direction transport counter; a repeated or out-of-order ciphertext fails AEAD decryption and aborts the connection.
A suite specifies the <DH>_<cipher>_<hash> part of the full Noise protocol name. Sendspin defines two:
25519_ChaChaPoly_SHA256- software-friendly suite25519_AESGCM_SHA256- hardware-accelerated suite (AES-NI / ARMv8 Crypto Extensions)
Servers MUST support both suites. Clients MUST support at least one.
The client picks one suite and announces it in client/init; since servers are required to support every suite, no negotiation is needed.
The client_id and server_id fields are the base64url-encoded (no padding) Curve25519 public keys of the client and server respectively, 43 characters each. These keys serve both as routing/persistence identifiers and as the static keys used in the Noise handshake. The private keys MUST be drawn from a CSPRNG per device and MUST NOT be a fixed default shared across devices.
Key rotation. Each side's static keypair is intended to be long-lived; the identifier is the pubkey, so rotating the keypair changes the identity. A server that rotates its static keypair (e.g., reprovisioned hardware, migrated host, lost private key) appears to clients as a different server. Operators who want to preserve identity across server moves must preserve the server's static private key (e.g., as part of the server's backup/restore set).
The PSK is mixed into the handshake state at the end of the second handshake message (the psk2 modifier). The transport-mode keys derived after the handshake therefore include the PSK, but the first handshake message's payload (sent by the server) is encrypted without the PSK mixed in.
To let the client select the right PSK before the PSK must be mixed in, the server includes a psk_id and a psk_category in the first handshake message's payload. The identifier is a 43-character base64url-encoded value (no padding) of a 32-byte SHA-256 output, derived deterministically from the PSK:
psk_id = base64url(SHA-256("sendspin-psk-id-v1" || PSK))
The label is the UTF-8 byte sequence of the literal characters shown (no NUL terminator, no surrounding quotes); || denotes byte concatenation. The same formula applies to all three PSK categories (long-term, pairing, Sentinel); the client stores each of its PSKs tagged with its category. psk_category declares which category the server is using the referenced PSK as - 'lt' (long-term), 'pr' (pairing), or 'sn' (Sentinel) - so a match binds both sides to the same category, which determines how to proceed. The single handshake pattern (KKpsk2) is used in all three cases; only the PSK input differs.
The Sentinel PSK is a published constant used as the PSK input whenever no other PSK applies. It provides no authentication on its own (its value is public); authentication, when needed, is established later during Pairing. The sentinel value is:
Sentinel PSK = SHA-256("sendspin-sentinel-psk-v1")
= 0x1b5e24dbc1aed95fc2a5a338a90c05df44bd10f5ec1f4cd66cbf86272767b9d3
and its psk_id is therefore also a published constant:
Sentinel psk_id = 0x185b15f6d2da4909bd1dc156a4ab206103abef0153bcd52d926170b95cf7ce8a
= base64url "GFsV9tLaSQm9HcFWpKsgYQOr7wFTvNUtkmFwuVz3zoo"
The client decrypts the first handshake message's payload (possible without a PSK, as noted above), compares the included psk_id to the hash of each candidate PSK of the declared psk_category, and selects the one that matches. It then mixes that PSK in to process the second handshake message. If no candidate matches, the client falls back to the Sentinel PSK (see Sentinel Fallback).
Each long-term PSK is persisted in a pairing record alongside the server's server_id. After a psk_id match, the client verifies that the matched PSK's stored server_id equals the one in server/init; mismatch fails the handshake.
A psk_id lookup miss means the server referenced a credential the client cannot use: the client lost its pairing record (e.g., a Factory Reset, eviction, or storage failure), an interrupted pairing finalize left the client without the record the server persisted, or the client holds the referenced PSK under a different category than the declared psk_category. On a lookup miss in the initial handshake the client completes the second handshake message with the Sentinel PSK instead of failing. The fallback applies only there: a miss during a re-handshake, and a failed stored-pubkey post-match check (a misbinding, not a miss), fail the handshake as before.
The server verifies the second handshake message against the PSK its first message referenced. If that fails and the referenced PSK was not the Sentinel, it verifies the same message against the Sentinel PSK before treating the handshake as failed. A second message that validates under the Sentinel is an authenticated credential-mismatch signal: the handshake authenticates the client's static key, so the signal proves its holder could not use the referenced PSK. The signal alone MUST NOT cause either side to remove or replace a record.
The session proceeds as an ordinary unpaired Sentinel-keyed one, except that the server MUST NOT activate roles or declare the 'playback' activity while its pairing record exists - the session carries a pairing exchange or stays idle. The server SHOULD surface the mismatch to its operator and offer re-pairing, which replaces the record and restores normal service.
The prologue mixed into the Noise handshake state on both sides is the concatenation of the exact bytes of client/init followed by the exact bytes of server/init, as transmitted on the wire (the JSON-encoded UTF-8 message body, without the WebSocket framing). This binds the cleartext init exchange to the handshake; tampering causes the handshake to fail.
Both sides MUST hash the raw message bytes exactly as sent and received, not a re-encoding of the parsed message.
A server-side failure decided from the cleartext client/init alone - an unsupported version, an unknown suite, or a message that is not valid JSON of the defined shape - is an init failure: the server MUST send server/error with the matching reason, then close the connection. The message is unauthenticated, so the reason is a hint for logging and operator display.
A client/init that parses as JSON of the message envelope and whose version is an integer other than 1 is unsupported_version regardless of its other payload fields, since a future version may define a different shape. Every other shape failure, including input that is not valid JSON, is malformed; suite is checked after version, then the remaining fields.
Every other handshake-phase failure - a client-side rejection of server/init, a handshake timeout, a malformed inner noise/handshake payload, a psk_id lookup miss without the Sentinel Fallback, Noise AEAD failure, AEAD failure once in transport mode, or a cleartext message received after switching to transport mode - is a silent failure: the detecting side closes the connection without sending any further message.
Implementations SHOULD apply a timeout (e.g., 30 seconds) for each side to receive the next expected message during the prologue and Noise-handshake phases.
The server MAY rerun the Noise handshake in transport mode to swap session keys without closing the WebSocket - typically to promote the session to paired after a successful pairing, to switch from Sentinel to a pairing PSK, or to rotate session keys on long-running connections.
The server initiates, as in the original handshake. The two noise/handshake messages are sent as encrypted binary messages inside the current channel; psk_id and psk_category in noise message 1 select the PSK for the new session. client/init and server/init are not re-sent - client_id, server_id, and suite carry over. The new handshake's prologue is the prior handshake's hash h. Once the new keys are in place, the server MUST send server/activate as its first message under the new keys. Neither server/hello nor client/hello is re-sent. That activation is a subsequent one on the same connection. The activation rules, including those for omitted active_roles, apply under the newly matched PSK.
The server MUST NOT start new application messages after sending Noise message 1, nor the client after receiving it, except for the handshake and server/activate. This restriction ends when the server sends, or the client receives, the new server/activate.
The server MUST tolerate valid old-key application messages received before Noise message 2, since the client may have sent them before receiving message 1. It MAY discard them without processing or responding.
Connection state, such as open streams with their buffered data or the time filter, persists across a re-handshake; only the session keys and what the handshake itself derives change.