record

package
v0.0.0-...-e34fb4d Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package record provides the state and record of an ongoing double ratchet session.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

Chain is a structure used inside the SessionState that keeps track of an ongoing ratcheting chain for a session.

func NewChain

func NewChain(senderRatchetKeyPair *ecc.ECKeyPair, chainKey *chain.Key,
	messageKeys []*message.Keys) *Chain

NewChain returns a new Chain structure for SessionState.

func NewChainFromStructure

func NewChainFromStructure(structure *ChainStructure) (*Chain, error)

NewChainFromStructure will return a new Chain with the given chain structure.

func (*Chain) AddMessageKeys

func (c *Chain) AddMessageKeys(keys *message.Keys)

AddMessageKeys will append the chain state with the given message keys.

func (*Chain) ChainKey

func (c *Chain) ChainKey() *chain.Key

ChainKey will return the chain key in the chain state.

func (*Chain) MessageKeys

func (c *Chain) MessageKeys() []*message.Keys

MessageKeys will return the message keys associated with the chain state.

func (*Chain) PopFirstMessageKeys

func (c *Chain) PopFirstMessageKeys() *message.Keys

PopFirstMessageKeys will remove the first message key from the chain's list of message keys.

func (*Chain) SenderRatchetKey

func (c *Chain) SenderRatchetKey() *ecc.ECKeyPair

SenderRatchetKey returns the sender's EC keypair.

func (*Chain) SetChainKey

func (c *Chain) SetChainKey(key *chain.Key)

SetChainKey will set the chain state's chain key.

func (*Chain) SetMessageKeys

func (c *Chain) SetMessageKeys(keys []*message.Keys)

SetMessageKeys will set the chain state with the given message keys.

func (*Chain) SetSenderRatchetKey

func (c *Chain) SetSenderRatchetKey(key *ecc.ECKeyPair)

SetSenderRatchetKey will set the chain state with the given EC key pair.

type ChainStructure

type ChainStructure struct {
	SenderRatchetKeyPublic  []byte
	SenderRatchetKeyPrivate []byte
	ChainKey                *chain.KeyStructure
	MessageKeys             []*message.KeysStructure
}

ChainStructure is a serializeable structure for chain states.

type PendingKeyExchange

type PendingKeyExchange struct {
	// contains filtered or unexported fields
}

PendingKeyExchange is a structure for storing a pending key exchange for a session state.

func NewPendingKeyExchange

func NewPendingKeyExchange(sequence uint32, localBaseKeyPair, localRatchetKeyPair *ecc.ECKeyPair,
	localIdentityKeyPair *identity.KeyPair) *PendingKeyExchange

NewPendingKeyExchange will return a new PendingKeyExchange object.

func NewPendingKeyExchangeFromStruct

func NewPendingKeyExchangeFromStruct(structure *PendingKeyExchangeStructure) *PendingKeyExchange

NewPendingKeyExchangeFromStruct will return a PendingKeyExchange object from the given structure. This is used to get a deserialized pending prekey exchange fetched from persistent storage.

type PendingKeyExchangeStructure

type PendingKeyExchangeStructure struct {
	Sequence                uint32
	LocalBaseKeyPublic      []byte
	LocalBaseKeyPrivate     []byte
	LocalRatchetKeyPublic   []byte
	LocalRatchetKeyPrivate  []byte
	LocalIdentityKeyPublic  []byte
	LocalIdentityKeyPrivate []byte
}

PendingKeyExchangeStructure is a serializable structure for pending key exchanges. This structure is used for persistent storage of the key exchange state.

type PendingPreKey

type PendingPreKey struct {
	// contains filtered or unexported fields
}

PendingPreKey is a structure for pending pre keys for a session state.

func NewPendingPreKey

func NewPendingPreKey(preKeyID *optional.Uint32, signedPreKeyID uint32,
	baseKey ecc.ECPublicKeyable) *PendingPreKey

NewPendingPreKey will return a new pending pre key object.

func NewPendingPreKeyFromStruct

func NewPendingPreKeyFromStruct(preKey *PendingPreKeyStructure) (*PendingPreKey, error)

NewPendingPreKeyFromStruct will return a new pending prekey object from the given structure.

type PendingPreKeyStructure

type PendingPreKeyStructure struct {
	PreKeyID       *optional.Uint32
	SignedPreKeyID uint32
	BaseKey        []byte
}

PendingPreKeyStructure is a serializeable structure for pending prekeys.

type PreKey

type PreKey struct {
	// contains filtered or unexported fields
}

PreKey record is a structure for storing pre keys inside a PreKeyStore.

func NewPreKey

func NewPreKey(id uint32, keyPair *ecc.ECKeyPair, serializer PreKeySerializer) *PreKey

NewPreKey record returns a new pre key record that can be stored in a PreKeyStore.

func NewPreKeyFromBytes

func NewPreKeyFromBytes(serialized []byte, serializer PreKeySerializer) (*PreKey, error)

NewPreKeyFromBytes will return a prekey record from the given bytes using the given serializer.

func NewPreKeyFromStruct

func NewPreKeyFromStruct(structure *PreKeyStructure, serializer PreKeySerializer) (*PreKey, error)

NewPreKeyFromStruct returns a PreKey record using the given serializable structure.

func (*PreKey) ID

func (p *PreKey) ID() *optional.Uint32

ID returns the pre key record's id.

func (*PreKey) KeyPair

func (p *PreKey) KeyPair() *ecc.ECKeyPair

KeyPair returns the pre key record's key pair.

func (*PreKey) Serialize

func (p *PreKey) Serialize() []byte

Serialize uses the PreKey serializer to return the PreKey as serialized bytes.

type PreKeySerializer

type PreKeySerializer interface {
	Serialize(preKey *PreKeyStructure) []byte
	Deserialize(serialized []byte) (*PreKeyStructure, error)
}

PreKeySerializer is an interface for serializing and deserializing PreKey objects into bytes. An implementation of this interface should be used to encode/decode the object into JSON, Protobuffers, etc.

type PreKeyStructure

type PreKeyStructure struct {
	ID         uint32
	PublicKey  []byte
	PrivateKey []byte
}

PreKeyStructure is a structure for serializing PreKey records.

type ReceiverChainPair

type ReceiverChainPair struct {
	ReceiverChain *Chain
	Index         int
}

ReceiverChainPair is a structure for a receiver chain key and index number.

func NewReceiverChainPair

func NewReceiverChainPair(receiverChain *Chain, index int) *ReceiverChainPair

NewReceiverChainPair will return a new ReceiverChainPair object.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session encapsulates the state of an ongoing session.

func NewSession

func NewSession(serializer SessionSerializer, stateSerializer StateSerializer) *Session

NewSession creates a new session record and uses the given session and state serializers to convert the object into storeable bytes.

func NewSessionFromBytes

func NewSessionFromBytes(serialized []byte, serializer SessionSerializer, stateSerializer StateSerializer) (*Session, error)

NewSessionFromBytes will return a Signal Session from the given bytes using the given serializer.

func NewSessionFromState

func NewSessionFromState(sessionState *State, serializer SessionSerializer) *Session

NewSessionFromState creates a new session record from the given session state.

func NewSessionFromStructure

func NewSessionFromStructure(structure *SessionStructure, serializer SessionSerializer,
	stateSerializer StateSerializer) (*Session, error)

NewSessionFromStructure will return a new Signal Session from the given session structure and serializer.

func (*Session) ArchiveCurrentState

func (r *Session) ArchiveCurrentState()

ArchiveCurrentState moves the current session state into the list of "previous" session states, and replaces the current session state with a fresh reset instance.

func (*Session) HasSessionState

func (r *Session) HasSessionState(version int, senderBaseKey []byte) bool

HasSessionState will check this record to see if the sender's base key exists in the current and previous states.

func (*Session) IsFresh

func (r *Session) IsFresh() bool

IsFresh is used to determine if this is a brand new session or if a session record has already existed.

func (*Session) PreviousSessionStates

func (r *Session) PreviousSessionStates() []*State

PreviousSessionStates returns a list of all currently maintained "previous" session states.

func (*Session) PromoteState

func (r *Session) PromoteState(promotedState *State)

PromoteState takes the given session state and replaces it with the current state, pushing the previous current state to "previousStates".

func (*Session) Serialize

func (r *Session) Serialize() []byte

Serialize will return the session as serialized bytes so it can be persistently stored.

func (*Session) SessionState

func (r *Session) SessionState() *State

SessionState returns the session state object of the current session record.

func (*Session) SetState

func (r *Session) SetState(sessionState *State)

SetState sets the session record's current state to the given one.

type SessionSerializer

type SessionSerializer interface {
	Serialize(state *SessionStructure) []byte
	Deserialize(serialized []byte) (*SessionStructure, error)
}

SessionSerializer is an interface for serializing and deserializing a Signal Session into bytes. An implementation of this interface should be used to encode/decode the object into JSON, Protobuffers, etc.

type SessionStructure

type SessionStructure struct {
	SessionState   *StateStructure
	PreviousStates []*StateStructure
}

SessionStructure is a public, serializeable structure for Signal Sessions. The states defined in the session are immuteable, as they should not be changed by anyone but the serializer.

type SignedPreKey

type SignedPreKey struct {
	// contains filtered or unexported fields
}

SignedPreKey record is a structure for storing a signed pre key in a SignedPreKey store.

func NewSignedPreKey

func NewSignedPreKey(id uint32, timestamp int64, keyPair *ecc.ECKeyPair,
	sig [64]byte, serializer SignedPreKeySerializer) *SignedPreKey

NewSignedPreKey record creates a new signed pre key record with the given properties.

func NewSignedPreKeyFromBytes

func NewSignedPreKeyFromBytes(serialized []byte, serializer SignedPreKeySerializer) (*SignedPreKey, error)

NewSignedPreKeyFromBytes will return a signed prekey record from the given bytes using the given serializer.

func NewSignedPreKeyFromStruct

func NewSignedPreKeyFromStruct(structure *SignedPreKeyStructure,
	serializer SignedPreKeySerializer) (*SignedPreKey, error)

NewSignedPreKeyFromStruct returns a SignedPreKey record using the given serializable structure.

func (*SignedPreKey) ID

func (s *SignedPreKey) ID() uint32

ID returns the record's id.

func (*SignedPreKey) KeyPair

func (s *SignedPreKey) KeyPair() *ecc.ECKeyPair

KeyPair returns the signed pre key record's key pair.

func (*SignedPreKey) Serialize

func (s *SignedPreKey) Serialize() []byte

Serialize uses the SignedPreKey serializer to return the SignedPreKey as serialized bytes.

func (*SignedPreKey) Signature

func (s *SignedPreKey) Signature() [64]byte

Signature returns the record's signed prekey signature.

func (*SignedPreKey) Timestamp

func (s *SignedPreKey) Timestamp() int64

Timestamp returns the record's timestamp

type SignedPreKeySerializer

type SignedPreKeySerializer interface {
	Serialize(signedPreKey *SignedPreKeyStructure) []byte
	Deserialize(serialized []byte) (*SignedPreKeyStructure, error)
}

SignedPreKeySerializer is an interface for serializing and deserializing SignedPreKey objects into bytes. An implementation of this interface should be used to encode/decode the object into JSON, Protobuffers, etc.

type SignedPreKeyStructure

type SignedPreKeyStructure struct {
	ID         uint32
	PublicKey  []byte
	PrivateKey []byte
	Signature  []byte
	Timestamp  int64
}

SignedPreKeyStructure is a flat structure of a signed pre key, used for serialization and deserialization.

type State

type State struct {
	// contains filtered or unexported fields
}

State is a session state that contains the structure for all sessions. Session states are contained inside session records. The session state is implemented as a struct rather than protobuffers to allow other serialization methods.

func NewState

func NewState(serializer StateSerializer) *State

NewState returns a new session state.

func NewStateFromBytes

func NewStateFromBytes(serialized []byte, serializer StateSerializer) (*State, error)

NewStateFromBytes will return a Signal State from the given bytes using the given serializer.

func NewStateFromStructure

func NewStateFromStructure(structure *StateStructure, serializer StateSerializer) (*State, error)

NewStateFromStructure will return a new session state with the given state structure.

func (*State) AddReceiverChain

func (s *State) AddReceiverChain(senderRatchetKey ecc.ECPublicKeyable, chainKey session.ChainKeyable)

AddReceiverChain will add the given ratchet key and chain key to the session state.

func (*State) ClearUnackPreKeyMessage

func (s *State) ClearUnackPreKeyMessage()

ClearUnackPreKeyMessage will clear the session's pending pre key.

func (*State) HasMessageKeys

func (s *State) HasMessageKeys(senderEphemeral ecc.ECPublicKeyable, counter uint32) bool

HasMessageKeys returns true if we have message keys associated with the given sender key and counter.

func (*State) HasPendingKeyExchange

func (s *State) HasPendingKeyExchange() bool

HasPendingKeyExchange will return true if there is a valid pending key exchange waiting.

func (*State) HasReceiverChain

func (s *State) HasReceiverChain(senderEphemeral ecc.ECPublicKeyable) bool

HasReceiverChain will check to see if the session state has the given ephemeral key.

func (*State) HasSenderChain

func (s *State) HasSenderChain() bool

HasSenderChain will check to see if the session state has a sender chain.

func (*State) HasUnacknowledgedPreKeyMessage

func (s *State) HasUnacknowledgedPreKeyMessage() bool

HasUnacknowledgedPreKeyMessage will return true if this session has an unacknowledged pre key message.

func (*State) LocalIdentityKey

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

LocalIdentityKey returns the session's identity key for the local user.

func (*State) LocalRegistrationID

func (s *State) LocalRegistrationID() uint32

LocalRegistrationID returns the local user's registration id.

func (*State) PendingKeyExchangeBaseKeyPair

func (s *State) PendingKeyExchangeBaseKeyPair() *ecc.ECKeyPair

PendingKeyExchangeBaseKeyPair will return the session's pending key exchange base keypair.

func (*State) PendingKeyExchangeIdentityKeyPair

func (s *State) PendingKeyExchangeIdentityKeyPair() *identity.KeyPair

PendingKeyExchangeIdentityKeyPair will return the session's pending key exchange identity keypair.

func (*State) PendingKeyExchangeRatchetKeyPair

func (s *State) PendingKeyExchangeRatchetKeyPair() *ecc.ECKeyPair

PendingKeyExchangeRatchetKeyPair will return the session's pending key exchange ratchet keypair.

func (*State) PendingKeyExchangeSequence

func (s *State) PendingKeyExchangeSequence() uint32

PendingKeyExchangeSequence will return the session's pending key exchange sequence number.

func (*State) PreviousCounter

func (s *State) PreviousCounter() uint32

PreviousCounter returns the counter of the previous message.

func (*State) ReceiverChainKey

func (s *State) ReceiverChainKey(senderEphemeral ecc.ECPublicKeyable) *chain.Key

ReceiverChainKey will use the given ephemeral key to generate a new chain key.

func (*State) RemoteIdentityKey

func (s *State) RemoteIdentityKey() *identity.Key

RemoteIdentityKey returns the identity key of the remote user.

func (*State) RemoteRegistrationID

func (s *State) RemoteRegistrationID() uint32

RemoteRegistrationID returns the remote user's registration id.

func (*State) RemoveMessageKeys

func (s *State) RemoveMessageKeys(senderEphemeral ecc.ECPublicKeyable, counter uint32) *message.Keys

RemoveMessageKeys removes the message key with the given sender key and counter. It will return the removed message key.

func (*State) RootKey

func (s *State) RootKey() session.RootKeyable

RootKey returns the root key for the session.

func (*State) SenderBaseKey

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

SenderBaseKey returns the sender's base key in bytes.

func (*State) SenderChainKey

func (s *State) SenderChainKey() session.ChainKeyable

SenderChainKey will return the chain key of the session state.

func (*State) SenderRatchetKey

func (s *State) SenderRatchetKey() ecc.ECPublicKeyable

SenderRatchetKey returns the public ratchet key of the sender.

func (*State) SenderRatchetKeyPair

func (s *State) SenderRatchetKeyPair() *ecc.ECKeyPair

SenderRatchetKeyPair returns the public/private ratchet key pair of the sender.

func (*State) Serialize

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

Serialize will return the state as bytes using the given serializer.

func (*State) SetLocalIdentityKey

func (s *State) SetLocalIdentityKey(identityKey *identity.Key)

SetLocalIdentityKey sets the session's identity key for the local user.

func (*State) SetLocalRegistrationID

func (s *State) SetLocalRegistrationID(registrationID uint32)

SetLocalRegistrationID sets the local user's registration id.

func (*State) SetMessageKeys

func (s *State) SetMessageKeys(senderEphemeral ecc.ECPublicKeyable, messageKeys *message.Keys)

SetMessageKeys will update the chain associated with the given sender key with the given message keys.

func (*State) SetPendingKeyExchange

func (s *State) SetPendingKeyExchange(sequence uint32, ourBaseKey, ourRatchetKey *ecc.ECKeyPair,
	ourIdentityKey *identity.KeyPair)

SetPendingKeyExchange will set the session's pending key exchange state to the given sequence and key pairs.

func (*State) SetPreviousCounter

func (s *State) SetPreviousCounter(previousCounter uint32)

SetPreviousCounter sets the counter for the previous message.

func (*State) SetReceiverChainKey

func (s *State) SetReceiverChainKey(senderEphemeral ecc.ECPublicKeyable, chainKey session.ChainKeyable)

SetReceiverChainKey sets the session's receiver chain key with the given chain key associated with the given senderEphemeral key.

func (*State) SetRemoteIdentityKey

func (s *State) SetRemoteIdentityKey(identityKey *identity.Key)

SetRemoteIdentityKey sets this session's identity key for the remote user.

func (*State) SetRemoteRegistrationID

func (s *State) SetRemoteRegistrationID(registrationID uint32)

SetRemoteRegistrationID sets the remote user's registration id.

func (*State) SetRootKey

func (s *State) SetRootKey(rootKey session.RootKeyable)

SetRootKey sets the root key for the session.

func (*State) SetSenderBaseKey

func (s *State) SetSenderBaseKey(senderBaseKey []byte)

SetSenderBaseKey sets the sender's base key with the given bytes.

func (*State) SetSenderChain

func (s *State) SetSenderChain(senderRatchetKeyPair *ecc.ECKeyPair, chainKey session.ChainKeyable)

SetSenderChain will set the given ratchet key pair and chain key for this session state.

func (*State) SetSenderChainKey

func (s *State) SetSenderChainKey(nextChainKey session.ChainKeyable)

SetSenderChainKey will set the chain key in the chain state for this session to the given chain key.

func (*State) SetUnacknowledgedPreKeyMessage

func (s *State) SetUnacknowledgedPreKeyMessage(preKeyID *optional.Uint32, signedPreKeyID uint32, baseKey ecc.ECPublicKeyable)

SetUnacknowledgedPreKeyMessage will return unacknowledged pre key message with the given key ids and base key.

func (*State) SetVersion

func (s *State) SetVersion(version int)

SetVersion sets the session state's version number.

func (*State) UnackPreKeyMessageItems

func (s *State) UnackPreKeyMessageItems() (*UnackPreKeyMessageItems, error)

UnackPreKeyMessageItems will return the session's unacknowledged pre key messages.

func (*State) Version

func (s *State) Version() int

Version returns the session's version.

type StateSerializer

type StateSerializer interface {
	Serialize(state *StateStructure) []byte
	Deserialize(serialized []byte) (*StateStructure, error)
}

StateSerializer is an interface for serializing and deserializing a Signal State into bytes. An implementation of this interface should be used to encode/decode the object into JSON, Protobuffers, etc.

type StateStructure

type StateStructure struct {
	LocalIdentityPublic  []byte
	LocalRegistrationID  uint32
	NeedsRefresh         bool
	PendingKeyExchange   *PendingKeyExchangeStructure
	PendingPreKey        *PendingPreKeyStructure
	PreviousCounter      uint32
	ReceiverChains       []*ChainStructure
	RemoteIdentityPublic []byte
	RemoteRegistrationID uint32
	RootKey              []byte
	SenderBaseKey        []byte
	SenderChain          *ChainStructure
	SessionVersion       int
}

StateStructure is the structure of a session state. Fields are public to be used for serialization and deserialization.

type UnackPreKeyMessageItems

type UnackPreKeyMessageItems struct {
	// contains filtered or unexported fields
}

UnackPreKeyMessageItems is a structure for messages that have not been acknowledged.

func NewUnackPreKeyMessageItems

func NewUnackPreKeyMessageItems(preKeyID *optional.Uint32, signedPreKeyID uint32,
	baseKey ecc.ECPublicKeyable) *UnackPreKeyMessageItems

NewUnackPreKeyMessageItems returns message items that are unacknowledged.

func NewUnackPreKeyMessageItemsFromStruct

func NewUnackPreKeyMessageItemsFromStruct(structure *UnackPreKeyMessageItemsStructure) *UnackPreKeyMessageItems

NewUnackPreKeyMessageItemsFromStruct will return a new unacknowledged prekey message items object from the given structure.

func (*UnackPreKeyMessageItems) BaseKey

BaseKey returns the ECC public key of the unacknowledged message.

func (*UnackPreKeyMessageItems) PreKeyID

func (u *UnackPreKeyMessageItems) PreKeyID() *optional.Uint32

PreKeyID returns the prekey id of the unacknowledged message.

func (*UnackPreKeyMessageItems) SignedPreKeyID

func (u *UnackPreKeyMessageItems) SignedPreKeyID() uint32

SignedPreKeyID returns the signed prekey id of the unacknowledged message.

type UnackPreKeyMessageItemsStructure

type UnackPreKeyMessageItemsStructure struct {
	PreKeyID       *optional.Uint32
	SignedPreKeyID uint32
	BaseKey        []byte
}

UnackPreKeyMessageItemsStructure is a serializable structure for unackowledged prekey message items.

Jump to

Keyboard shortcuts

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