session

package
v0.0.0-...-7cf77d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2024 License: AGPL-3.0 Imports: 24 Imported by: 1

Documentation

Overview

Package session implements the functionality necessary to establish encrypted peer and group sessions.

Index

Constants

View Source
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 GroupStateConfig struct {
	MessageVersion      uint8
	ChainID             uint32
	Iteration           uint32
	ChainKey            []byte
	SignatureKey        curve.PublicKey
	SignaturePrivateKey curve.PrivateKey
}

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 InitializeAliceSessionRecord

func InitializeAliceSessionRecord(random io.Reader, params *ratchet.AliceParameters) (*Record, error)

func InitializeBobSessionRecord

func InitializeBobSessionRecord(params *ratchet.BobParameters) (*Record, error)

func NewRecord

func NewRecord(state *State) *Record

NewRecord creates a new Record with current session set to the given state. Set state to `nil` for a "fresh" record.

func NewRecordBytes

func NewRecordBytes(bytes []byte) (*Record, error)

func (*Record) ArchiveCurrentState

func (r *Record) ArchiveCurrentState()

func (*Record) HasSessionState

func (r *Record) HasSessionState(version uint32, aliceBaseKey []byte) (bool, error)

func (*Record) LocalIdentityKey

func (r *Record) LocalIdentityKey() (identity.Key, error)

func (*Record) PreviousStates

func (r *Record) PreviousStates() ([]*State, error)

func (*Record) PromoteOldState

func (r *Record) PromoteOldState(idx int, state *State)

func (*Record) PromoteState

func (r *Record) PromoteState(state *State)

func (*Record) ReceiverChainKey

func (r *Record) ReceiverChainKey(sender curve.PublicKey) (ratchet.ChainKey, bool, error)

func (*Record) RemoteIdentityKey

func (r *Record) RemoteIdentityKey() (identity.Key, bool, error)

func (*Record) SenderChainKey

func (r *Record) SenderChainKey() (ratchet.ChainKey, error)

func (*Record) SetSessionState

func (r *Record) SetSessionState(session *State)

func (*Record) State

func (r *Record) State() *State

func (*Record) Version

func (r *Record) Version() (uint32, error)

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

func (s *Session) EncryptMessage(ctx context.Context, plaintext []byte) (message.Ciphertext, error)

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 (s *State) AddReceiverChain(sender curve.PublicKey, chainKey ratchet.ChainKey)

func (*State) AliceBaseKey

func (s *State) AliceBaseKey() []byte

func (*State) Bytes

func (s *State) Bytes() []byte

func (*State) ClearUnacknowledgedPreKeyMessage

func (s *State) ClearUnacknowledgedPreKeyMessage()

func (*State) Clone

func (s *State) Clone() *State

func (*State) LocalIdentityKey

func (s *State) LocalIdentityKey() (identity.Key, error)

func (*State) LocalRegistrationID

func (s *State) LocalRegistrationID() uint32

func (*State) MessageKeys

func (s *State) MessageKeys(sender curve.PublicKey, counter uint32) (ratchet.MessageKeys, bool, error)

func (*State) PreviousCounter

func (s *State) PreviousCounter() uint32

func (*State) ReceiverChain

func (s *State) ReceiverChain(sender curve.PublicKey) (int, *v1.SessionStructure_Chain)

func (*State) ReceiverChainKey

func (s *State) ReceiverChainKey(sender curve.PublicKey) (ratchet.ChainKey, bool, error)

func (*State) RemoteIdentityKey

func (s *State) RemoteIdentityKey() (identity.Key, bool, error)

func (*State) RootKey

func (s *State) RootKey() (ratchet.RootKey, error)

func (*State) SenderChainKey

func (s *State) SenderChainKey() (ratchet.ChainKey, error)

func (*State) SenderRatchetKey

func (s *State) SenderRatchetKey() (curve.PublicKey, error)

func (*State) SenderRatchetPrivateKey

func (s *State) SenderRatchetPrivateKey() (curve.PrivateKey, error)

func (*State) SessionWithSelf

func (s *State) SessionWithSelf() (bool, error)

func (*State) SetAliceBaseKey

func (s *State) SetAliceBaseKey(key []byte)

func (*State) SetLocalRegistrationID

func (s *State) SetLocalRegistrationID(id uint32)

func (*State) SetMessageKeys

func (s *State) SetMessageKeys(sender curve.PublicKey, messageKeys ratchet.MessageKeys) error

func (*State) SetPreviousCounter

func (s *State) SetPreviousCounter(counter uint32)

func (*State) SetReceiverChainKey

func (s *State) SetReceiverChainKey(sender curve.PublicKey, chainKey ratchet.ChainKey) error

func (*State) SetRemoteRegistrationID

func (s *State) SetRemoteRegistrationID(id uint32)

func (*State) SetRootKey

func (s *State) SetRootKey(key ratchet.RootKey)

func (*State) SetSenderChain

func (s *State) SetSenderChain(sender *curve.KeyPair, nextChainKey ratchet.ChainKey)

func (*State) SetSenderChainKey

func (s *State) SetSenderChainKey(nextChainKey ratchet.ChainKey)

func (*State) SetUnacknowledgedPreKeyMessage

func (s *State) SetUnacknowledgedPreKeyMessage(preKeyID *prekey.ID, signedPreKeyID prekey.ID, baseKey curve.PublicKey)

func (*State) UnacknowledgedPreKeyMessages

func (s *State) UnacknowledgedPreKeyMessages() (*UnacknowledgedPreKeyMessageItems, error)

func (*State) Version

func (s *State) Version() uint32

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 (UnacknowledgedPreKeyMessageItems) PreKeyID

func (UnacknowledgedPreKeyMessageItems) SignedPreKeyID

func (u UnacknowledgedPreKeyMessageItems) SignedPreKeyID() prekey.ID

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL