Documentation
¶
Overview ¶
Package sealed is the room record's bytes: one message locked under a fresh key, that key sealed to every recipient, a signed header that commits to the key, and the writer's counter in the header.
The wire form is header ‖ stanzas ‖ body ‖ signature, the first three length-prefixed (uint32 big-endian):
- header: JSON {"v":1,"room":"<32 hex>","idx":k,"ctr":n,"kh":"<base64, 32 bytes>","at":"<RFC 3339 UTC ms>"}
- stanzas: count (uint16) ‖ [idx (uint16) ‖ len (uint16) ‖ enc‖ct]*, in idx order; enc‖ct is HPKE single-shot (DHKEM X25519, HKDF-SHA256, AES-256-GCM) of the 32-byte body key K to the recipient's seal key, info = "peer room seal v1" ‖ room ‖ idx ‖ SHA-256(header)
- body: AES-256-GCM under K, nonce twelve zero bytes, AAD = the header bytes
- signature: Ed25519 over the length-prefixed header ‖ stanzas ‖ body by the writer's room signing key
kh = SHA-256("peer room key commit v1" ‖ K): the signature commits to the body key, so one signed record cannot open to two messages for two members. ctr is the writer's own count of records in the room, +1 each.
A receiver runs Parse, Verify under the roster's signing key for the header's idx, CheckCtr against the writer's last counter, then Open with its own idx and seal keys (the current one first, then each retired one).
Index ¶
Constants ¶
const AtLayout = "2006-01-02T15:04:05.000Z"
AtLayout is the header's at: RFC 3339, UTC, milliseconds.
const MaxRecord = 1 << 20
MaxRecord is the relay's cap on a record's decoded bytes (1 MiB).
const StanzaSize = 32 + 32 + 16
StanzaSize is enc ‖ ct for a 32-byte key under DHKEM(X25519) + AES-256-GCM.
const Version = 1
Version is the header's v.
Variables ¶
var ( ErrMalformed = errors.New("sealed: malformed") ErrTooLarge = errors.New("sealed: record over 1 MiB") ErrSignature = errors.New("sealed: bad signature") ErrUnverified = errors.New("sealed: record not verified") ErrNoStanza = errors.New("sealed: no stanza for this idx") ErrStanza = errors.New("sealed: stanza opens under no key") ErrKeyCommit = errors.New("sealed: key commitment mismatch") ErrBody = errors.New("sealed: body does not open") ErrCtrGap = errors.New("sealed: counter gap") ErrCtrBack = errors.New("sealed: counter step back") )
Functions ¶
func CheckCtr ¶
CheckCtr compares a verified record's ctr with the writer's last one. A gap or a step back is reported for the receiver to log and read on.
Types ¶
type Header ¶
type Header struct {
Room string // 32 lowercase hex
Idx uint16 // the writer's index
Ctr uint64 // the writer's count of records in this room
KH [32]byte
At time.Time
}
Header is the signed header. Seal fills KH; At is written as UTC milliseconds.
type Record ¶
type Record struct {
Header Header
// contains filtered or unexported fields
}
Record is a parsed sealed record.
func Parse ¶
Parse splits and checks a record's framing and header. It verifies nothing: a parsed record is bytes of the right shape.
func (*Record) Open ¶
Open finds idx's stanza, unwraps the body key with each seal key in turn (the current one first, then each retired one), checks it against the header's kh — a mismatch names the writer — and opens the body. It refuses a record Verify has not passed.
func (*Record) Recipients ¶
Recipients lists the stanza indexes in wire order.