Documentation ¶
Overview ¶
Package record provides the state and record of an ongoing double ratchet session.
Index ¶
- type Chain
- func (c *Chain) AddMessageKeys(keys *message.Keys)
- func (c *Chain) ChainKey() *chain.Key
- func (c *Chain) MessageKeys() []*message.Keys
- func (c *Chain) PopFirstMessageKeys() *message.Keys
- func (c *Chain) SenderRatchetKey() *ecc.ECKeyPair
- func (c *Chain) SetChainKey(key *chain.Key)
- func (c *Chain) SetMessageKeys(keys []*message.Keys)
- func (c *Chain) SetSenderRatchetKey(key *ecc.ECKeyPair)
- type ChainStructure
- type PendingKeyExchange
- type PendingKeyExchangeStructure
- type PendingPreKey
- type PendingPreKeyStructure
- type PreKey
- type PreKeySerializer
- type PreKeyStructure
- type ReceiverChainPair
- type Session
- func NewSession(serializer SessionSerializer, stateSerializer StateSerializer) *Session
- func NewSessionFromBytes(serialized []byte, serializer SessionSerializer, ...) (*Session, error)
- func NewSessionFromState(sessionState *State, serializer SessionSerializer) *Session
- func NewSessionFromStructure(structure *SessionStructure, serializer SessionSerializer, ...) (*Session, error)
- func (r *Session) ArchiveCurrentState()
- func (r *Session) HasSessionState(version int, senderBaseKey []byte) bool
- func (r *Session) IsFresh() bool
- func (r *Session) PreviousSessionStates() []*State
- func (r *Session) PromoteState(promotedState *State)
- func (r *Session) Serialize() []byte
- func (r *Session) SessionState() *State
- func (r *Session) SetState(sessionState *State)
- type SessionSerializer
- type SessionStructure
- type SignedPreKey
- func NewSignedPreKey(id uint32, timestamp int64, keyPair *ecc.ECKeyPair, sig [64]byte, ...) *SignedPreKey
- func NewSignedPreKeyFromBytes(serialized []byte, serializer SignedPreKeySerializer) (*SignedPreKey, error)
- func NewSignedPreKeyFromStruct(structure *SignedPreKeyStructure, serializer SignedPreKeySerializer) (*SignedPreKey, error)
- type SignedPreKeySerializer
- type SignedPreKeyStructure
- type State
- func (s *State) AddReceiverChain(senderRatchetKey ecc.ECPublicKeyable, chainKey session.ChainKeyable)
- func (s *State) ClearUnackPreKeyMessage()
- func (s *State) HasMessageKeys(senderEphemeral ecc.ECPublicKeyable, counter uint32) bool
- func (s *State) HasPendingKeyExchange() bool
- func (s *State) HasReceiverChain(senderEphemeral ecc.ECPublicKeyable) bool
- func (s *State) HasSenderChain() bool
- func (s *State) HasUnacknowledgedPreKeyMessage() bool
- func (s *State) LocalIdentityKey() *identity.Key
- func (s *State) LocalRegistrationID() uint32
- func (s *State) PendingKeyExchangeBaseKeyPair() *ecc.ECKeyPair
- func (s *State) PendingKeyExchangeIdentityKeyPair() *identity.KeyPair
- func (s *State) PendingKeyExchangeRatchetKeyPair() *ecc.ECKeyPair
- func (s *State) PendingKeyExchangeSequence() uint32
- func (s *State) PreviousCounter() uint32
- func (s *State) ReceiverChainKey(senderEphemeral ecc.ECPublicKeyable) *chain.Key
- func (s *State) RemoteIdentityKey() *identity.Key
- func (s *State) RemoteRegistrationID() uint32
- func (s *State) RemoveMessageKeys(senderEphemeral ecc.ECPublicKeyable, counter uint32) *message.Keys
- func (s *State) RootKey() session.RootKeyable
- func (s *State) SenderBaseKey() []byte
- func (s *State) SenderChainKey() session.ChainKeyable
- func (s *State) SenderRatchetKey() ecc.ECPublicKeyable
- func (s *State) SenderRatchetKeyPair() *ecc.ECKeyPair
- func (s *State) Serialize() []byte
- func (s *State) SetLocalIdentityKey(identityKey *identity.Key)
- func (s *State) SetLocalRegistrationID(registrationID uint32)
- func (s *State) SetMessageKeys(senderEphemeral ecc.ECPublicKeyable, messageKeys *message.Keys)
- func (s *State) SetPendingKeyExchange(sequence uint32, ourBaseKey, ourRatchetKey *ecc.ECKeyPair, ...)
- func (s *State) SetPreviousCounter(previousCounter uint32)
- func (s *State) SetReceiverChainKey(senderEphemeral ecc.ECPublicKeyable, chainKey session.ChainKeyable)
- func (s *State) SetRemoteIdentityKey(identityKey *identity.Key)
- func (s *State) SetRemoteRegistrationID(registrationID uint32)
- func (s *State) SetRootKey(rootKey session.RootKeyable)
- func (s *State) SetSenderBaseKey(senderBaseKey []byte)
- func (s *State) SetSenderChain(senderRatchetKeyPair *ecc.ECKeyPair, chainKey session.ChainKeyable)
- func (s *State) SetSenderChainKey(nextChainKey session.ChainKeyable)
- func (s *State) SetUnacknowledgedPreKeyMessage(preKeyID *optional.Uint32, signedPreKeyID uint32, baseKey ecc.ECPublicKeyable)
- func (s *State) SetVersion(version int)
- func (s *State) UnackPreKeyMessageItems() (*UnackPreKeyMessageItems, error)
- func (s *State) Version() int
- type StateSerializer
- type StateStructure
- type UnackPreKeyMessageItems
- type UnackPreKeyMessageItemsStructure
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 ¶
AddMessageKeys will append the chain state with the given message keys.
func (*Chain) MessageKeys ¶
MessageKeys will return the message keys associated with the chain state.
func (*Chain) PopFirstMessageKeys ¶
PopFirstMessageKeys will remove the first message key from the chain's list of message keys.
func (*Chain) SenderRatchetKey ¶
SenderRatchetKey returns the sender's EC keypair.
func (*Chain) SetChainKey ¶
SetChainKey will set the chain state's chain key.
func (*Chain) SetMessageKeys ¶
SetMessageKeys will set the chain state with the given message keys.
func (*Chain) SetSenderRatchetKey ¶
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.
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 ¶
PreKeyStructure is a structure for serializing PreKey records.
type ReceiverChainPair ¶
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 ¶
HasSessionState will check this record to see if the sender's base key exists in the current and previous states.
func (*Session) IsFresh ¶
IsFresh is used to determine if this is a brand new session or if a session record has already existed.
func (*Session) PreviousSessionStates ¶
PreviousSessionStates returns a list of all currently maintained "previous" session states.
func (*Session) PromoteState ¶
PromoteState takes the given session state and replaces it with the current state, pushing the previous current state to "previousStates".
func (*Session) Serialize ¶
Serialize will return the session as serialized bytes so it can be persistently stored.
func (*Session) SessionState ¶
SessionState returns the session state object of the current session record.
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) 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 ¶
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 ¶
HasSenderChain will check to see if the session state has a sender chain.
func (*State) HasUnacknowledgedPreKeyMessage ¶
HasUnacknowledgedPreKeyMessage will return true if this session has an unacknowledged pre key message.
func (*State) LocalIdentityKey ¶
LocalIdentityKey returns the session's identity key for the local user.
func (*State) LocalRegistrationID ¶
LocalRegistrationID returns the local user's registration id.
func (*State) PendingKeyExchangeBaseKeyPair ¶
PendingKeyExchangeBaseKeyPair will return the session's pending key exchange base keypair.
func (*State) PendingKeyExchangeIdentityKeyPair ¶
PendingKeyExchangeIdentityKeyPair will return the session's pending key exchange identity keypair.
func (*State) PendingKeyExchangeRatchetKeyPair ¶
PendingKeyExchangeRatchetKeyPair will return the session's pending key exchange ratchet keypair.
func (*State) PendingKeyExchangeSequence ¶
PendingKeyExchangeSequence will return the session's pending key exchange sequence number.
func (*State) PreviousCounter ¶
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 ¶
RemoteIdentityKey returns the identity key of the remote user.
func (*State) RemoteRegistrationID ¶
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 ¶
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 ¶
SenderRatchetKeyPair returns the public/private ratchet key pair of the sender.
func (*State) SetLocalIdentityKey ¶
SetLocalIdentityKey sets the session's identity key for the local user.
func (*State) SetLocalRegistrationID ¶
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 ¶
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 ¶
SetRemoteIdentityKey sets this session's identity key for the remote user.
func (*State) SetRemoteRegistrationID ¶
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 ¶
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 ¶
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.
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 ¶
func (u *UnackPreKeyMessageItems) BaseKey() ecc.ECPublicKeyable
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.