Documentation
¶
Overview ¶
Package auth is the daemon's device registry: it gates every WebSocket connection on a bearer a device obtained by pairing. Bearers are high-entropy random tokens, shown to a device once and stored only as a hash — a leaked devices.json cannot be replayed. Pairing the FIRST device uses a one-time bootstrap code (see otp.go). This is a process-wide security boundary, so it lives in its own package, not folded into serve.
Index ¶
- Variables
- type Class
- type Device
- type PendingJoin
- type PushTarget
- type Store
- func (s *Store) Bootstrap(ttl time.Duration) string
- func (s *Store) ConfirmJoin(joinID, code string) (string, error)
- func (s *Store) Join(name, platform string) string
- func (s *Store) Lookup(bearer string) (Device, bool)
- func (s *Store) Mint(name string, class Class) (string, error)
- func (s *Store) Pair(code, name, platform string) (string, error)
- func (s *Store) PendingJoins() []PendingJoin
- func (s *Store) PushTargets() []PushTarget
- func (s *Store) RegisterPush(bearer, token, platform string) error
- func (s *Store) UpdateLastUsed(bearer string)
Constants ¶
This section is empty.
Variables ¶
var ErrPairing = errors.New("auth: invalid or expired pairing code")
ErrPairing is returned by Pair when the bootstrap code is wrong, expired, or already spent.
Functions ¶
This section is empty.
Types ¶
type Class ¶
type Class string
Class is what a device IS. It is a fact about the device, not a permission: this package stores it and never interprets it, so what a class may DO is decided in one place by whoever assembles connections (see internal/serve). Storing the category rather than the permissions is deliberate — permissions written into devices.json would freeze today's rules into every record, and widening them later would need another migration of the kind stampClasses already had to do once.
It is a separate axis from Platform: that one selects the push provider, and a browser and a speaker in the hallway could both be "web". There is deliberately no ordering — a class is a category, not a level.
The name avoids Kind and Role, both of which already mean something else here: Kind is the gate's permission dimension (and, separately, which chat store a command addresses, and which sort of notification fired), and agentkit.Role is a message author.
const ( // ClassUnknown is the zero value, and carries the least authority. A record that failed to say // what it is must never be assumed trustworthy — the same reasoning as gate.RecallNever and // agent.Strict. ClassUnknown Class = "" // ClassApp is a paired companion app: a screen, a lock, and a person holding it. Someone at it // is identified, so what it reports can be taken as that person's answer. ClassApp Class = "app" // ClassAppliance is a device with NO authenticated input path — a speaker in a hallway, a // doorbell, a car. Whoever is present can operate it, and none of them identified themselves, so // nothing it reports is anybody's consent. // // Named for that property rather than for a product: a voice satellite is one of these, but so // is anything else whose input nobody signed. ClassAppliance Class = "appliance" // ClassTool is a local operator tool — the `nocturn` command talking to its own daemon. It is // not a device anyone carries and nobody is identified at it, so it consents to nothing; what it // may do it may do because whoever runs it already holds the workspace on disk. ClassTool Class = "tool" )
type Device ¶
type Device struct {
ID string `json:"id"`
Name string `json:"name"`
Class Class `json:"class,omitempty"` // what it is; decides whether it may approve
Platform string `json:"platform,omitempty"` // ios|android|web, selects the push provider
BearerHash string `json:"bearerHash"` // hex sha256 of the bearer
PushToken string `json:"pushToken,omitempty"` // APNs/FCM token, for out-of-band wake
Added time.Time `json:"added"`
LastUsed time.Time `json:"lastUsed,omitzero"`
}
Device is one paired device. The bearer itself is never stored — only its hash.
type PendingJoin ¶
type PendingJoin struct {
JoinID string `json:"joinId"`
Name string `json:"name"`
Platform string `json:"platform,omitempty"`
Code string `json:"code"`
}
PendingJoin is a second device's request awaiting confirmation, shown to an ALREADY-PAIRED device so a human can relay the code. The code is never returned to the joining device.
type PushTarget ¶
PushTarget is a device reachable out of band: its push token and platform.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store verifies bearers and pairs new devices, persisting device records (hashes only, 0600).
func New ¶
New opens (or creates) a device store at path.
The directory is created here rather than left to the first write: the first write is the one that enrols a device, and a failure there leaves the daemon running with a registry it cannot persist — the least useful moment to discover a missing folder.
func (*Store) Bootstrap ¶
Bootstrap arms a fresh pairing code IF nothing in the registry can bring a phone in by itself, valid for ttl, and returns it to show the operator. It returns "" once such a device exists.
The test is on ClassApp, not on the registry being empty, and the difference is the whole flow: the daemon enrols its own command line (ClassTool) at startup, and an appliance may be enrolled on someone's behalf. Neither can relay a join code — see serve.capabilitiesOf, where a class becomes abilities — so counting them as "a device is paired" retires the bootstrap code while nothing is left that could pair the first phone, and the household can never be entered at all.
func (*Store) ConfirmJoin ¶
ConfirmJoin redeems a joinId and its relayed code for a new device's bearer. A wrong code is counted; past joinMaxTries the join is dropped so the 6-digit code cannot be brute-forced. An unknown, expired, or exhausted join fails with ErrPairing.
func (*Store) Join ¶
Join records a second device's request and returns its joinId — never the code. The code is minted server-side and revealed only to an already-paired device via PendingJoins; a human relays it.
func (*Store) Lookup ¶
Lookup returns the device owning bearer, comparing hashes in constant time.
It replaces a plain yes/no check because the answer alone is no longer enough: what a connection is allowed to do depends on the device's Class, and a caller that has to ask a second question would have to search again.
func (*Store) Mint ¶
Mint enrols a device of the given class outright, without a code exchange, and returns its bearer (shown once, never stored).
It exists for devices that cannot take part in one. A satellite has no screen to show a code and no keyboard to enter one, so the join flow — where a device asks and an already-paired device confirms — has nothing to work with. Enrolling itself is not the alternative: a device that can do that is the hole. Instead an already-authenticated caller asks for this on its behalf, so the human authorises on something that can authorise, and the satellite only ever receives.
The CALLER is responsible for being trusted. This function checks nothing.
func (*Store) Pair ¶
Pair redeems the bootstrap code, registering a device named name (on platform, optional) and returning its bearer (shown once, never stored). The code is single-use.
func (*Store) PendingJoins ¶
func (s *Store) PendingJoins() []PendingJoin
PendingJoins lists the open join requests with their codes, for an already-paired device to relay to a human. Expired entries are pruned in passing.
func (*Store) PushTargets ¶
func (s *Store) PushTargets() []PushTarget
PushTargets returns every device reachable out of band (has a push token).
func (*Store) RegisterPush ¶
RegisterPush records (or, with an empty token, clears) the push token of the device owning bearer, so it can be woken out of band. A no-op if the bearer is unknown.
func (*Store) UpdateLastUsed ¶
UpdateLastUsed sets a device's LastUsed to now on connect. A no-op if the bearer is unknown (already rejected by Verify).