Documentation
¶
Overview ¶
Package store is the party's session-state store: the records every fleet host shares, loaded as a snapshot at version v, mutated in memory through the libsignal store interfaces, and written back by Commit under compare-and-swap. A Commit that finds another host's version refuses with ErrConflict and changes nothing; the caller reloads and redoes its work (plan decision 5).
Two record kinds: `keys`, the party keys record (package keys), and one `ss.<channel>` per channel — the Signal session, the remote identity, the seen message ids, the pull cursor and the pinned peer. A Backend holds them: file (JSON + flock) for one machine, pages (a ccc-pages /d/ data record) for a fleet, wrapped in Sealed so the page holds ciphertext only.
The orders decision 5 fixes: serve = decrypt → spool → Commit → inbox birth from the spool; send = encrypt → outbox → Commit → put → clear. The Journal is the spool and the outbox; ReplaySpool and ReplayOutbox run every serve round and finish what a crash or a failed step interrupted.
Index ¶
- Constants
- Variables
- func ChannelKey(channel string) string
- func ReplayOutbox(j *Journal, put func(*Entry) error) error
- func SealKey(id *keys.Identity) [32]byte
- func ValidKey(key string) bool
- type Backend
- type Channel
- func (c *Channel) AdmitAnyIdentity()
- func (c *Channel) Announced() uint32
- func (c *Channel) Card() *card.Signed
- func (c *Channel) ClearHeld()
- func (c *Channel) Commit(ctx context.Context) error
- func (c *Channel) ContainsSession(ctx context.Context, addr *protocol.SignalAddress) (bool, error)
- func (c *Channel) Cursor() int64
- func (c *Channel) DeleteAllSessions(ctx context.Context) error
- func (c *Channel) DeleteSession(ctx context.Context, addr *protocol.SignalAddress) error
- func (c *Channel) Deposited() int
- func (c *Channel) Drop(ctx context.Context) error
- func (c *Channel) GetIdentityKeyPair() *identity.KeyPair
- func (c *Channel) GetLocalRegistrationID() uint32
- func (c *Channel) GetSubDeviceSessions(ctx context.Context, name string) ([]uint32, error)
- func (c *Channel) Gone() bool
- func (c *Channel) Held() (*card.Signed, int64)
- func (c *Channel) Hold(s *card.Signed, seq int64)
- func (c *Channel) IsTrustedIdentity(ctx context.Context, addr *protocol.SignalAddress, key *identity.Key) (bool, error)
- func (c *Channel) LoadSession(ctx context.Context, addr *protocol.SignalAddress) (*record.Session, error)
- func (c *Channel) MarkSeen(id string, seq int64)
- func (c *Channel) Name() string
- func (c *Channel) PinCard(s *card.Signed)
- func (c *Channel) PinRoot(root ed25519.PublicKey)
- func (c *Channel) Received() bool
- func (c *Channel) RemoteIdentity(addr *protocol.SignalAddress) ([32]byte, bool)
- func (c *Channel) Root() ed25519.PublicKey
- func (c *Channel) SaveIdentity(ctx context.Context, addr *protocol.SignalAddress, key *identity.Key) error
- func (c *Channel) Secret() []byte
- func (c *Channel) Seen(id string) bool
- func (c *Channel) SetAnnounced(id uint32)
- func (c *Channel) SetCursor(seq int64)
- func (c *Channel) SetDeposited(n int)
- func (c *Channel) SetSecret(secret []byte)
- func (c *Channel) SpendDeposit()
- func (c *Channel) StoreSession(ctx context.Context, addr *protocol.SignalAddress, r *record.Session) error
- func (c *Channel) Version() int64
- type ConflictError
- type Entry
- type Feed
- type FeedReader
- type Journal
- type Keys
- func (k *Keys) Commit(ctx context.Context) error
- func (k *Keys) ContainsPreKey(ctx context.Context, id uint32) (bool, error)
- func (k *Keys) ContainsSignedPreKey(ctx context.Context, id uint32) (bool, error)
- func (k *Keys) LoadPreKey(ctx context.Context, id uint32) (*record.PreKey, error)
- func (k *Keys) LoadSignedPreKey(ctx context.Context, id uint32) (*record.SignedPreKey, error)
- func (k *Keys) LoadSignedPreKeys(ctx context.Context) ([]*record.SignedPreKey, error)
- func (k *Keys) RemovePreKey(ctx context.Context, id uint32) error
- func (k *Keys) RemoveSignedPreKey(ctx context.Context, id uint32) error
- func (k *Keys) StorePreKey(ctx context.Context, id uint32, p *record.PreKey) error
- func (k *Keys) StoreSignedPreKey(ctx context.Context, id uint32, r *record.SignedPreKey) error
- func (k *Keys) Version() int64
- type OwnCard
- type Store
- func (s *Store) Channel(ctx context.Context, name string) (*Channel, error)
- func (s *Store) Feed(ctx context.Context) (*Feed, error)
- func (s *Store) Keys(ctx context.Context) (*Keys, error)
- func (s *Store) OwnCard(ctx context.Context) (*OwnCard, error)
- func (s *Store) ReplaySpool(ctx context.Context, j *Journal, deliver func(*Entry) error) error
- type Watcher
Constants ¶
const FeedKey = "feed"
FeedKey is the record key of the party's feed record.
const KeysKey = "keys"
KeysKey is the party keys record's key.
const MaxSeen = 1000
MaxSeen is how many message ids a channel record remembers; the oldest go first. The ratchet rejects a replayed ciphertext on its own; the seen set is the fleet's second check, by message id, and bounded so the record stays well under the backend's cap.
const OwnCardKey = "card"
OwnCardKey is the record key of the party's own card.
Variables ¶
var ( ErrConflict = errors.New("store: version conflict") ErrTooLarge = errors.New("store: record too large") ErrCorrupt = errors.New("store: record does not open") ErrNoKeys = errors.New("store: party keys record absent") )
Errors a caller can match with errors.Is.
var ErrBusy = errors.New("store: another process holds the journal's lock")
ErrBusy is a lock another process on this machine holds.
var ErrPermanent = errors.New("store: entry cannot be put")
ErrPermanent is a put no retry can land: the channel is gone, the token is refused, the entry's own bytes are wrong. ReplayOutbox drops such an entry.
var ErrProbe = errors.New("store: a snapshot that admits any identity is not committed")
ErrProbe is a Commit of a snapshot that admits any identity.
Functions ¶
func ReplayOutbox ¶
ReplayOutbox puts the outbox entries whose Commit landed and drops the uncommitted ones — a ciphertext whose session state was never committed must not reach the relay, since the next send reuses its counter. A put the relay already holds is refused by the receiver's ratchet as a replay; a committed entry never put leaves a counter gap the receiver's skipped-key store absorbs.
One entry never blocks the others: a put that returns ErrPermanent drops its entry, any other failure leaves it for the next replay, and either way the entries behind it — other channels, other relays — are tried. Every failure comes back joined, for the caller to report.
Types ¶
type Backend ¶
type Backend interface {
// Load returns a record's bytes and version; an absent key is nil, 0, nil.
Load(ctx context.Context, key string) ([]byte, int64, error)
// Store writes data as version expect+1 when the stored version is expect
// (0 for an absent key); another version refuses with a *ConflictError.
Store(ctx context.Context, key string, data []byte, expect int64) (int64, error)
}
Backend holds versioned records by key.
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel is one channel's record, loaded at a version: the libsignal session store and identity store for the channel, the seen ids, the pull cursor and the pinned peer. Mutations stay in memory until Commit.
func (*Channel) AdmitAnyIdentity ¶
func (c *Channel) AdmitAnyIdentity()
AdmitAnyIdentity makes this snapshot admit every identity key, to read the record a key change arrives in (design §3.2) without applying anything: the snapshot refuses to commit from here on.
func (*Channel) Announced ¶
Announced is the signed prekey id the card last sent on this channel carried, 0 when unknown.
func (*Channel) Commit ¶
Commit writes the record as version Version()+1. Another host's commit in between refuses with ErrConflict and changes nothing here: reload the channel and redo the work on it.
func (*Channel) ContainsSession ¶
ContainsSession reports whether addr has a session record.
func (*Channel) DeleteAllSessions ¶
DeleteAllSessions drops every session record of the channel.
func (*Channel) DeleteSession ¶
DeleteSession drops addr's session record.
func (*Channel) Deposited ¶
Deposited is how many one-time prekeys the relay is believed to hold for this party's side of the channel.
func (*Channel) Drop ¶ added in v0.3.0
Drop replaces the record with a tombstone at the next version: the party forgot the peer (peer forget), so the sessions, the pinned root and card, the invite secret and the seen ids go. Channel ids are never reused, so nothing loads the tombstone again. Another host's version refuses with ErrConflict.
func (*Channel) GetIdentityKeyPair ¶
GetIdentityKeyPair serves the party's identity key pair.
func (*Channel) GetLocalRegistrationID ¶
GetLocalRegistrationID serves the party's registrationId.
func (*Channel) GetSubDeviceSessions ¶
GetSubDeviceSessions lists the device ids other than keys.DeviceID that name has sessions for.
func (*Channel) Held ¶
Held is the peer's root-signed card naming a new identity key that waits for the human, with the relay seq it came in under; nil, 0 when none.
func (*Channel) Hold ¶
Hold keeps s, verified by the caller against the pinned root, for the human's yes; seq is the relay seq it came in under.
func (*Channel) IsTrustedIdentity ¶
func (c *Channel) IsTrustedIdentity(ctx context.Context, addr *protocol.SignalAddress, key *identity.Key) (bool, error)
IsTrustedIdentity accepts any identity key until a card is pinned, and after that only the identity keys the pinned card lists and has not retired: a rotated card makes the old session's next Encrypt or Decrypt fail with signalerror.ErrUntrustedIdentity, the teardown design §3.2 wants, and whoever holds the voided key is refused with it. Before the pin the host checks the first contact itself, after decrypting the peer's card (§3.4: session identity == card keys[].identity).
func (*Channel) LoadSession ¶
func (c *Channel) LoadSession(ctx context.Context, addr *protocol.SignalAddress) (*record.Session, error)
LoadSession is the libsignal session store: a fresh record for an address without one, never nil.
func (*Channel) PinCard ¶
PinCard records s as the peer's newest root-signed card. The caller has verified it (card.Verify); from here on IsTrustedIdentity accepts only the identity keys it lists.
func (*Channel) Received ¶
Received reports whether a message from the peer has opened on this channel: the seen set holds an id. The set drops its oldest ids past MaxSeen and is never emptied.
func (*Channel) RemoteIdentity ¶
func (c *Channel) RemoteIdentity(addr *protocol.SignalAddress) ([32]byte, bool)
RemoteIdentity is the identity key SaveIdentity recorded for addr — the key the session was built with — for the host's check against the pinned card's keys[].identity (design §3.4).
func (*Channel) SaveIdentity ¶
func (c *Channel) SaveIdentity(ctx context.Context, addr *protocol.SignalAddress, key *identity.Key) error
SaveIdentity records the remote identity key the library saw for addr.
func (*Channel) SetAnnounced ¶
SetAnnounced records the signed prekey id the card being sent carries.
func (*Channel) SetDeposited ¶
SetDeposited records the relay's count after a deposit.
func (*Channel) SpendDeposit ¶
func (c *Channel) SpendDeposit()
SpendDeposit records that a PreKey message spent one deposited key.
func (*Channel) StoreSession ¶
func (c *Channel) StoreSession(ctx context.Context, addr *protocol.SignalAddress, r *record.Session) error
StoreSession keeps the session record's bytes for addr.
type ConflictError ¶
ConflictError is a Store that found another version than expected.
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
func (*ConflictError) Is ¶
func (e *ConflictError) Is(target error) bool
Is makes errors.Is(err, ErrConflict) true.
type Entry ¶
type Entry struct {
// ID is the message id; Channel the channel it belongs to.
ID string `json:"id"`
Channel string `json:"channel"`
// Seq is the relay seq the envelope arrived under (spool); 0 in the outbox.
Seq int64 `json:"seq"`
// Type is the envelope type; Body the plaintext (spool) or ciphertext (outbox).
Type string `json:"type"`
Body []byte `json:"body"`
// Committed is set by MarkCommitted once the Commit this entry waited on landed.
Committed bool `json:"committed"`
// Bump is a room outbox entry whose put bumps the membership version: a
// removal record, which bumps however often it is retried.
Bump bool `json:"bump,omitempty"`
// contains filtered or unexported fields
}
Entry is one journaled message.
type Feed ¶ added in v0.5.0
type Feed struct {
// Source is the source secret, in clear.
Source string
// Readers is every link minted and not revoked, in minting order.
Readers []FeedReader
// contains filtered or unexported fields
}
Feed is the party's feed record: the source secret its hosts say hello to the reader feed with, and every reader link minted, by the hash of its token. It is the one home of both — every machine of the party reads it, nothing is provisioned by hand, and no machine needs root.json to set the feed up or mint a link (plan-delivery decision 33). The worker holds the hashes alone. Source is "" and Readers nil while the record is absent.
func (*Feed) Commit ¶ added in v0.5.0
Commit writes the record as version Version()+1; ErrConflict as Channel.Commit.
func (*Feed) Hashes ¶ added in v0.5.0
Hashes is the readers' token hashes, in record order; never nil.
type FeedReader ¶ added in v0.5.0
type FeedReader struct {
Hash string `json:"hash"`
Label string `json:"label"`
At string `json:"at"`
}
FeedReader is one minted link: the hash of its token as the worker names it, the label the person gave it, and when it was minted.
type Journal ¶
type Journal struct {
// contains filtered or unexported fields
}
Journal is a crash-safe local list of entries that wait on a Commit, in a directory outside the tree: the serve spool (a decrypted message awaiting its inbox birth) and the send outbox (a ciphertext awaiting its relay put). The sequence is Add → Commit → MarkCommitted → deliver or put → Remove; a CAS loser Removes its entry; ReplaySpool and ReplayOutbox finish what a crash or a failed step cut, every serve round.
func OpenJournal ¶
OpenJournal opens (creating) the journal directory.
func (*Journal) Lock ¶ added in v0.2.0
Lock takes the machine's exclusive lock on key's entries — a flock on a sibling key.lock file, so two processes on one host (peer send and peer serve) never put one entry twice — and returns its release. wait blocks until the holder releases; without it a held lock is ErrBusy. A process that dies drops its lock. The lock is per open file, so a nested Lock of the same key from one process waits on itself.
func (*Journal) MarkCommitted ¶
MarkCommitted records that e's Commit landed.
type Keys ¶
type Keys struct {
// PartyKeys is the record's content.
PartyKeys *keys.PartyKeys
// contains filtered or unexported fields
}
Keys is the party keys record, loaded at a version: the libsignal prekey and signed-prekey stores. PartyKeys is nil while the record is absent — the host seeds it from the party keys file peer init wrote and commits. The record keeps raw 32-byte keys (package keys), never libsignal's record bytes, whose reload corrupts the public key.
func (*Keys) Commit ¶
Commit writes the record as version Version()+1; ErrConflict as Channel.Commit.
func (*Keys) ContainsPreKey ¶
ContainsPreKey reports whether the one-time prekey id is held.
func (*Keys) ContainsSignedPreKey ¶
ContainsSignedPreKey reports whether id is a signed prekey held.
func (*Keys) LoadPreKey ¶
LoadPreKey is the libsignal prekey store: nil, nil for an unknown id.
func (*Keys) LoadSignedPreKey ¶
LoadSignedPreKey is the libsignal signed-prekey store: the current signed prekey or the one the last rotation replaced, nil, nil for any other id.
func (*Keys) LoadSignedPreKeys ¶
LoadSignedPreKeys lists the current signed prekey and the previous one.
func (*Keys) RemovePreKey ¶
RemovePreKey drops the one-time prekey id; the library calls it after a PreKey message used it.
func (*Keys) RemoveSignedPreKey ¶
RemoveSignedPreKey drops the signed prekey id, current or previous; a record without a current one cannot be committed.
func (*Keys) StorePreKey ¶
StorePreKey adds or replaces the one-time prekey id.
func (*Keys) StoreSignedPreKey ¶
StoreSignedPreKey makes r the current signed prekey; the one it replaces becomes the previous.
type OwnCard ¶
type OwnCard struct {
// Issued is when the card was signed; Identity the identity key its
// current key names, in text form; SignedPrekey the signed prekey id it
// carries — what a reader compares against its own to see the card is stale.
Issued time.Time
Identity string
SignedPrekey uint32
// Public is the card without details, Details the one with them.
Public, Details *card.Signed
// contains filtered or unexported fields
}
OwnCard is the party's own root-signed card on the store, in both forms it travels: without details (envelope #0, in clear on the relay) and with details (in-session). The root key signs it where the root lives — peer init, peer card publish, peer identity rotate — and every host reads it from here, so no fleet host needs root.json to open a channel, answer a card or announce a rotation. The fields are nil while the record is absent.
func (*OwnCard) Commit ¶
Commit writes the record as version Version()+1; ErrConflict as Channel.Commit.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a party's state store: a backend plus the identity the libsignal identity store serves.
func (*Store) ReplaySpool ¶
ReplaySpool runs on serve's start and before every round's pulls: it delivers the spool entries whose Commit landed — marked committed, or whose id the channel record has seen — and drops the rest, whose message the cursor will pull again. A delivered entry is removed, so a replay delivers each message once; an entry another host also committed may be delivered twice — a duplicate at most, never a loss (decision 5).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package file is the store backend for one machine: one JSON file per record under a directory, `{"version": n, "data": …}`, written under an exclusive flock on a sibling lock file so two processes on the machine compare-and-swap correctly.
|
Package file is the store backend for one machine: one JSON file per record under a directory, `{"version": n, "data": …}`, written under an exclusive flock on a sibling lock file so two processes on the machine compare-and-swap correctly. |
|
Package pages is the fleet's store backend: each record is one ccc-pages /d/ data record on the party's private state page (UCC design v2 § 5 commitment 5) — `GET /d/<slug>/<key>` and `PUT /d/<slug>/<key>?v=<n>` with the owner Bearer, the bytes base64 once in the envelope's data string under Schema, the 256 KiB cap on the envelope.
|
Package pages is the fleet's store backend: each record is one ccc-pages /d/ data record on the party's private state page (UCC design v2 § 5 commitment 5) — `GET /d/<slug>/<key>` and `PUT /d/<slug>/<key>?v=<n>` with the owner Bearer, the bytes base64 once in the envelope's data string under Schema, the 256 KiB cap on the envelope. |
|
pagestest
Package pagestest serves a fake ccc-pages /d/ store for tests: the owner Bearer, CAS by ?v=, the envelope cap, and the status codes and bodies the real one answers (plan-research-ccc-pages § 5).
|
Package pagestest serves a fake ccc-pages /d/ store for tests: the owner Bearer, CAS by ?v=, the envelope cap, and the status codes and bodies the real one answers (plan-research-ccc-pages § 5). |