Documentation ¶
Overview ¶
Package session implements the functionality necessary to establish encrypted peer and group sessions.
Index ¶
- Constants
- type GroupRecord
- func (g *GroupRecord) AddState(state *GroupState) error
- func (g *GroupRecord) RemoveState(chainID uint32, signatureKey curve.PublicKey) (*GroupState, bool)
- func (g *GroupRecord) RemoveStates(chainID uint32) int
- func (g *GroupRecord) State() (*GroupState, error)
- func (g *GroupRecord) StateForChainID(chainID uint32) *GroupState
- type GroupSession
- func (g *GroupSession) DecryptMessage(ctx context.Context, ciphertext *message.SenderKey) ([]byte, error)
- func (g *GroupSession) EncryptMessage(ctx context.Context, random io.Reader, plaintext []byte) (*message.SenderKey, error)
- func (g *GroupSession) NewSenderKeyDistribution(ctx context.Context, random io.Reader) (*message.SenderKeyDistribution, error)
- func (g *GroupSession) ProcessSenderKeyDistribution(ctx context.Context, message *message.SenderKeyDistribution) error
- type GroupState
- func (s *GroupState) AddMessageKey(key senderkey.MessageKey)
- func (s *GroupState) ChainID() uint32
- func (s *GroupState) PrivateSigningKey() (curve.PrivateKey, error)
- func (s *GroupState) PublicSigningKey() (curve.PublicKey, error)
- func (s *GroupState) RemoveMessageKeys(iteration uint32) (senderkey.MessageKey, bool, error)
- func (s *GroupState) SenderChainKey() senderkey.ChainKey
- func (s *GroupState) SetSenderChainKey(chainKey senderkey.ChainKey)
- func (s *GroupState) Version() uint32
- type GroupStateConfig
- type GroupStore
- type Record
- func (r *Record) ArchiveCurrentState()
- func (r *Record) HasSessionState(version uint32, aliceBaseKey []byte) (bool, error)
- func (r *Record) LocalIdentityKey() (identity.Key, error)
- func (r *Record) PreviousStates() ([]*State, error)
- func (r *Record) PromoteOldState(idx int, state *State)
- func (r *Record) PromoteState(state *State)
- func (r *Record) ReceiverChainKey(sender curve.PublicKey) (ratchet.ChainKey, bool, error)
- func (r *Record) RemoteIdentityKey() (identity.Key, bool, error)
- func (r *Record) SenderChainKey() (ratchet.ChainKey, error)
- func (r *Record) SetSessionState(session *State)
- func (r *Record) State() *State
- func (r *Record) Version() (uint32, error)
- type Session
- func (s *Session) DecryptMessage(ctx context.Context, random io.Reader, ciphertext message.Ciphertext) ([]byte, error)
- func (s *Session) EncryptMessage(ctx context.Context, plaintext []byte) (message.Ciphertext, error)
- func (s *Session) ProcessPreKey(ctx context.Context, record *Record, message *message.PreKey) (*prekey.ID, error)
- func (s *Session) ProcessPreKeyBundle(ctx context.Context, random io.Reader, bundle *prekey.Bundle) error
- type State
- func (s *State) AddReceiverChain(sender curve.PublicKey, chainKey ratchet.ChainKey)
- func (s *State) AliceBaseKey() []byte
- func (s *State) Bytes() []byte
- func (s *State) ClearUnacknowledgedPreKeyMessage()
- func (s *State) Clone() *State
- func (s *State) LocalIdentityKey() (identity.Key, error)
- func (s *State) LocalRegistrationID() uint32
- func (s *State) MessageKeys(sender curve.PublicKey, counter uint32) (ratchet.MessageKeys, bool, error)
- func (s *State) PreviousCounter() uint32
- func (s *State) ReceiverChain(sender curve.PublicKey) (int, *v1.SessionStructure_Chain)
- func (s *State) ReceiverChainKey(sender curve.PublicKey) (ratchet.ChainKey, bool, error)
- func (s *State) RemoteIdentityKey() (identity.Key, bool, error)
- func (s *State) RootKey() (ratchet.RootKey, error)
- func (s *State) SenderChainKey() (ratchet.ChainKey, error)
- func (s *State) SenderRatchetKey() (curve.PublicKey, error)
- func (s *State) SenderRatchetPrivateKey() (curve.PrivateKey, error)
- func (s *State) SessionWithSelf() (bool, error)
- func (s *State) SetAliceBaseKey(key []byte)
- func (s *State) SetLocalRegistrationID(id uint32)
- func (s *State) SetMessageKeys(sender curve.PublicKey, messageKeys ratchet.MessageKeys) error
- func (s *State) SetPreviousCounter(counter uint32)
- func (s *State) SetReceiverChainKey(sender curve.PublicKey, chainKey ratchet.ChainKey) error
- func (s *State) SetRemoteRegistrationID(id uint32)
- func (s *State) SetRootKey(key ratchet.RootKey)
- func (s *State) SetSenderChain(sender *curve.KeyPair, nextChainKey ratchet.ChainKey)
- func (s *State) SetSenderChainKey(nextChainKey ratchet.ChainKey)
- func (s *State) SetUnacknowledgedPreKeyMessage(preKeyID *prekey.ID, signedPreKeyID prekey.ID, baseKey curve.PublicKey)
- func (s *State) UnacknowledgedPreKeyMessages() (*UnacknowledgedPreKeyMessageItems, error)
- func (s *State) Version() uint32
- type Store
- type UnacknowledgedPreKeyMessageItems
Constants ¶
const MaxJumps = 25_000
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GroupRecord ¶
type GroupRecord struct {
// contains filtered or unexported fields
}
GroupRecord holds a record of a group session's current and past states.
func NewGroupRecord ¶
func NewGroupRecord() *GroupRecord
func (*GroupRecord) AddState ¶
func (g *GroupRecord) AddState(state *GroupState) error
func (*GroupRecord) RemoveState ¶
func (g *GroupRecord) RemoveState(chainID uint32, signatureKey curve.PublicKey) (*GroupState, bool)
func (*GroupRecord) RemoveStates ¶
func (g *GroupRecord) RemoveStates(chainID uint32) int
func (*GroupRecord) State ¶
func (g *GroupRecord) State() (*GroupState, error)
func (*GroupRecord) StateForChainID ¶
func (g *GroupRecord) StateForChainID(chainID uint32) *GroupState
type GroupSession ¶
type GroupSession struct { // SenderAddress is the address of the user sending the message. // // It is meant to be populated by both a sender and a receiver. SenderAddress address.Address // DistID is the distribution ID of the group. // // It is meant to be populated by a sender, only. DistID distribution.ID SenderKeyStore GroupStore }
GroupSession represents a unidirectional group sender-key encrypted session. It may only be used for sending or for receiving, but not both.
func (*GroupSession) DecryptMessage ¶
func (g *GroupSession) DecryptMessage(ctx context.Context, ciphertext *message.SenderKey) ([]byte, error)
DecryptMessage decrypts the ciphertext message.
func (*GroupSession) EncryptMessage ¶
func (g *GroupSession) EncryptMessage(ctx context.Context, random io.Reader, plaintext []byte) (*message.SenderKey, error)
EncryptMessage encrypts the plaintext message.
func (*GroupSession) NewSenderKeyDistribution ¶
func (g *GroupSession) NewSenderKeyDistribution(ctx context.Context, random io.Reader) (*message.SenderKeyDistribution, error)
NewSenderKeyDistribution constructs a sender-key distribution message for establishing a group session.
func (*GroupSession) ProcessSenderKeyDistribution ¶
func (g *GroupSession) ProcessSenderKeyDistribution(ctx context.Context, message *message.SenderKeyDistribution) error
ProcessSenderKeyDistribution processes a group sender-key distribution message to establish a group session to receive messages from the sender.
type GroupState ¶
type GroupState struct {
// contains filtered or unexported fields
}
GroupState represents a group session's state.
func NewGroupState ¶
func NewGroupState(cfg GroupStateConfig) *GroupState
func (*GroupState) AddMessageKey ¶
func (s *GroupState) AddMessageKey(key senderkey.MessageKey)
func (*GroupState) ChainID ¶
func (s *GroupState) ChainID() uint32
func (*GroupState) PrivateSigningKey ¶
func (s *GroupState) PrivateSigningKey() (curve.PrivateKey, error)
func (*GroupState) PublicSigningKey ¶
func (s *GroupState) PublicSigningKey() (curve.PublicKey, error)
func (*GroupState) RemoveMessageKeys ¶
func (s *GroupState) RemoveMessageKeys(iteration uint32) (senderkey.MessageKey, bool, error)
func (*GroupState) SenderChainKey ¶
func (s *GroupState) SenderChainKey() senderkey.ChainKey
func (*GroupState) SetSenderChainKey ¶
func (s *GroupState) SetSenderChainKey(chainKey senderkey.ChainKey)
func (*GroupState) Version ¶
func (s *GroupState) Version() uint32
type GroupStateConfig ¶
type GroupStore ¶
type GroupStore interface { Load(ctx context.Context, sender address.Address, distributionID distribution.ID) (*GroupRecord, bool, error) Store(ctx context.Context, sender address.Address, distributionID distribution.ID, record *GroupRecord) error }
func NewInMemGroupStore ¶
func NewInMemGroupStore() GroupStore
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record holds a record of a session's current and past states.
func InitializeBobSessionRecord ¶
func InitializeBobSessionRecord(params *ratchet.BobParameters) (*Record, error)
func NewRecord ¶
NewRecord creates a new Record with current session set to the given state. Set state to `nil` for a "fresh" record.
func NewRecordBytes ¶
func (*Record) ArchiveCurrentState ¶
func (r *Record) ArchiveCurrentState()
func (*Record) HasSessionState ¶
func (*Record) PreviousStates ¶
func (*Record) PromoteOldState ¶
func (*Record) PromoteState ¶
func (*Record) ReceiverChainKey ¶
func (*Record) SetSessionState ¶
type Session ¶
type Session struct { RemoteAddress address.Address SessionStore Store PreKeyStore prekey.Store SignedPreKeyStore prekey.SignedStore IdentityKeyStore identity.Store }
Session represents a protocol session with another user.
func (*Session) DecryptMessage ¶
func (s *Session) DecryptMessage(ctx context.Context, random io.Reader, ciphertext message.Ciphertext) ([]byte, error)
DecryptMessage decrypts the ciphertext message.
func (*Session) EncryptMessage ¶
EncryptMessage encrypts the plaintext message.
func (*Session) ProcessPreKey ¶
func (s *Session) ProcessPreKey(ctx context.Context, record *Record, message *message.PreKey) (*prekey.ID, error)
ProcessPreKey processes a pre-key message to initialize a "Bob" session after receiving a message from "Alice".
This method returns the one-time pre-key used by "Alice" when sending the initial message, if one was used.
func (*Session) ProcessPreKeyBundle ¶
func (s *Session) ProcessPreKeyBundle(ctx context.Context, random io.Reader, bundle *prekey.Bundle) error
ProcessPreKeyBundle processes a pre-key bundle to initialize an "Alice" session to send encrypted messages to some "Bob" user identified by the pre-key bundle.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State represents a session's state.
func NewState ¶
func NewState(session *v1.SessionStructure) *State
func (*State) AddReceiverChain ¶
func (*State) AliceBaseKey ¶
func (*State) ClearUnacknowledgedPreKeyMessage ¶
func (s *State) ClearUnacknowledgedPreKeyMessage()
func (*State) LocalRegistrationID ¶
func (*State) MessageKeys ¶
func (*State) PreviousCounter ¶
func (*State) ReceiverChain ¶
func (*State) ReceiverChainKey ¶
func (*State) SenderRatchetPrivateKey ¶
func (s *State) SenderRatchetPrivateKey() (curve.PrivateKey, error)
func (*State) SessionWithSelf ¶
func (*State) SetAliceBaseKey ¶
func (*State) SetLocalRegistrationID ¶
func (*State) SetMessageKeys ¶
func (*State) SetPreviousCounter ¶
func (*State) SetReceiverChainKey ¶
func (*State) SetRemoteRegistrationID ¶
func (*State) SetRootKey ¶
func (*State) SetSenderChain ¶
func (*State) SetSenderChainKey ¶
func (*State) SetUnacknowledgedPreKeyMessage ¶
func (*State) UnacknowledgedPreKeyMessages ¶
func (s *State) UnacknowledgedPreKeyMessages() (*UnacknowledgedPreKeyMessageItems, error)
type Store ¶
type Store interface { Load(ctx context.Context, address address.Address) (*Record, bool, error) Store(ctx context.Context, address address.Address, record *Record) error }
Store defines a session store.
func NewInMemStore ¶
func NewInMemStore() Store
NewInMemStore creates a new in-memory session store.
type UnacknowledgedPreKeyMessageItems ¶
type UnacknowledgedPreKeyMessageItems struct {
// contains filtered or unexported fields
}
func (UnacknowledgedPreKeyMessageItems) BaseKey ¶
func (u UnacknowledgedPreKeyMessageItems) BaseKey() curve.PublicKey
func (UnacknowledgedPreKeyMessageItems) PreKeyID ¶
func (u UnacknowledgedPreKeyMessageItems) PreKeyID() *prekey.ID
func (UnacknowledgedPreKeyMessageItems) SignedPreKeyID ¶
func (u UnacknowledgedPreKeyMessageItems) SignedPreKeyID() prekey.ID