Documentation
¶
Overview ¶
Package relay is how a phone reaches conch web without Tailscale: both connect out to a relay, which pairs a phone's WebSocket with one the gateway opens for it and copies messages between the two. What it copies is a Noise session the phone and the gateway made with a key the relay never sees (the gateway's, carried in the pairing QR code), so it forwards screens and keystrokes it cannot read and could not forge.
That holds for the bytes it copies, not for the page: the relay also serves the phone's app, the code that makes the session and keeps the device's token, so whoever runs a relay could serve an app that reads everything. The relay is to be trusted as the laptop is — one of your own — and the docs say so rather than leave the Noise session to imply otherwise.
A relay knows rooms, not people. A room's id is a hash of a secret only its gateway holds, so a phone — which knows the id — can ask for the gateway but cannot stand in for it. Nothing is stored: a relay that restarts loses its connections and the gateways make them again.
Index ¶
- Constants
- Variables
- func EncodeKey(b []byte) string
- func Fingerprint(pub []byte) string
- func HTTPURL(relay string) (string, error)
- func KeyFromPrivate(private string) (noise.DHKey, error)
- func NewKey() (noise.DHKey, error)
- func NewSecret() (string, error)
- func RoomID(secret string) string
- func Through(r *http.Request) bool
- func Words() []string
- type Frame
- type Hello
- type Link
- type Open
- type Server
- type Session
- func (s *Session) Close()
- func (s *Session) Do(ctx context.Context, method, path string, h map[string]string, body string) (Frame, error)
- func (s *Session) Done() <-chan struct{}
- func (s *Session) Err() error
- func (s *Session) Socket(ctx context.Context, path string, h map[string]string) (*Socket, error)
- type Socket
- type Status
Constants ¶
const ( GatewayPath = "/relay/gateway" AcceptPath = "/relay/accept" PhonePath = "/relay/phone" HealthPath = "/relay/health" // SecretHeader carries a gateway's room secret. A header, not the // query, so it is in no access log along the way. SecretHeader = "X-Conch-Relay-Secret" )
The relay's addresses. A gateway holds GatewayPath open and opens AcceptPath once for each phone; a phone opens PhonePath.
const ( CodeNoGateway = 4404 // the room's gateway is not connected CodeBusy = 4429 // the room has as many phones as it takes CodeReplaced = 4409 // a newer connection from the same gateway took over CodeTimeout = 4408 // the gateway didn't take the phone in time // Conch Cloud's relay adds two (PROTOCOL §3.3); conch's own never // sends them. CodeBadTicket = 4401 // no ticket, or one used, expired or for another room CodeRevoked = 4403 // the device holding the socket was revoked )
Close codes a phone is told, so it can say which part is missing rather than spin: the relay answered, but the gateway isn't there.
const ( Prologue = "conch-relay-v1" // TunnelHost is the address the gateway's handler sees the tunnel's // calls at, and their Origin: its own, so its same-origin checks hold. TunnelHost = "conch-relay" )
Protocol is the Noise protocol, and Prologue binds a session to conch's use of it: a handshake made for something else does not complete here.
const HandshakeVersion = 1
HandshakeVersion is the tunnel's version. A phone app speaking another is told so rather than half understood.
const TicketHeader = "X-Conch-Relay-Ticket"
TicketHeader carries a ticket to a relay that admits a room's clients only with one (Conch Cloud's, PROTOCOL §3.2): single use, short-lived, handed out by the control plane. A relay of conch's own ignores it.
Variables ¶
var ( ErrTicketRefused = errors.New("the relay refused the ticket") ErrRevoked = errors.New("this device was signed out of the account") )
ErrTicketRefused and ErrRevoked are a cloud relay closing a client's socket: its ticket was not good (used, expired, another room's), or the device it was given to has been signed out.
var ErrNoGateway = errors.New("the computer isn't connected to the relay")
ErrNoGateway is the relay saying the computer isn't connected to it.
var Suite = noise.NewCipherSuite(noise.DH25519, noise.CipherAESGCM, noise.HashSHA256)
Suite is Noise_NK_25519_AESGCM_SHA256: every part of it is in a browser's WebCrypto.
Functions ¶
func Fingerprint ¶
Fingerprint is a key as four words, for a person to compare on the phone and on the computer: the same words, the same key.
func KeyFromPrivate ¶
KeyFromPrivate is a static key from its private half, as kept.
func RoomID ¶
RoomID is the room a secret opens: public, since a phone has to name it, and useless without the secret for anything but asking for the gateway.
Types ¶
type Frame ¶
type Frame struct {
T string `json:"t"`
ID int64 `json:"id"`
M string `json:"m,omitempty"`
P string `json:"p,omitempty"`
H map[string]string `json:"h,omitempty"`
B string `json:"b,omitempty"`
S int `json:"s,omitempty"`
D string `json:"d,omitempty"`
C int `json:"c,omitempty"`
R string `json:"r,omitempty"`
}
Frame is one message of the tunnel.
type Hello ¶
Hello is each side's handshake payload: the version, and on the gateway's side how its direction is compressed.
type Link ¶
type Link struct {
Relay string // wss://relay.example.com
Secret string
Key noise.DHKey
Handler http.Handler
Logf func(format string, args ...any)
// OnStatus, when set, is told every change of Status.
OnStatus func(Status)
// contains filtered or unexported fields
}
Link is a gateway's connection to a relay: it keeps its room open and serves every phone that arrives with Handler — the gateway's own.
type Open ¶
Open is what the relay tells a gateway: when a phone arrives, open AcceptPath with this id to take it. Ready comes first, once the room is the gateway's: until then a phone asking for it would be told nobody is there, so the gateway counts itself connected only from Ready.
type Server ¶
type Server struct {
UI http.Handler
Logf func(format string, args ...any)
// contains filtered or unexported fields
}
Server is a relay. UI, when set, is served for everything that isn't the relay's own — the phone's app, so a phone can open the relay's address and pair.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a phone's end of the tunnel, in Go: what the phone's app does in tunnel.mjs. conch uses it to check a relay works end to end, and the tests to drive a gateway through one.
func Dial ¶
Dial opens a session with the gateway in room, whose key is gwPub (from the pairing link): the relay first, then the handshake through it.
func DialTicket ¶
DialTicket is Dial with a ticket for the relay, when it has one.
func (*Session) Do ¶
func (s *Session) Do(ctx context.Context, method, path string, h map[string]string, body string) (Frame, error)
Do makes one call on the gateway and waits for its answer.
func (*Session) Done ¶
func (s *Session) Done() <-chan struct{}
Done is closed when the session ends.
type Socket ¶
type Socket struct {
// contains filtered or unexported fields
}
Socket is a WebSocket on the gateway, carried by the session.