session

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MPL-2.0 Imports: 17 Imported by: 1

Documentation

Overview

Package session provides the different types of sessions for en/decrypting of messages

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MegolmInboundSession

type MegolmInboundSession struct {
	Ratchet            megolm.Ratchet          `json:"ratchet"`
	SigningKey         crypto.Ed25519PublicKey `json:"signing_key"`
	InitialRatchet     megolm.Ratchet          `json:"initial_ratchet"`
	SigningKeyVerified bool                    `json:"signing_key_verified"` //not used for now
}

MegolmInboundSession stores information about the sessions of receive.

func MegolmInboundSessionFromPickled

func MegolmInboundSessionFromPickled(pickled, key []byte) (*MegolmInboundSession, error)

MegolmInboundSessionFromPickled loads the MegolmInboundSession details from a pickled base64 string. The input is decrypted with the supplied key.

func NewMegolmInboundSession

func NewMegolmInboundSession(input []byte) (*MegolmInboundSession, error)

NewMegolmInboundSession creates a new MegolmInboundSession from a base64 encoded session sharing message.

func NewMegolmInboundSessionFromExport

func NewMegolmInboundSessionFromExport(input []byte) (*MegolmInboundSession, error)

NewMegolmInboundSessionFromExport creates a new MegolmInboundSession from a base64 encoded session export message.

func (*MegolmInboundSession) Decrypt

func (o *MegolmInboundSession) Decrypt(ciphertext []byte) ([]byte, uint, error)

Decrypt decrypts a base64 encoded group message.

func (*MegolmInboundSession) Export added in v0.21.0

func (o *MegolmInboundSession) Export(messageIndex uint32) ([]byte, error)

Export returns the base64-encoded ratchet key for this session, at the given index, in a format which can be used by InboundGroupSession.InboundGroupSessionImport(). Encrypts the InboundGroupSession using the supplied key. Returns error on failure. if we do not have a session key corresponding to the given index (ie, it was sent before the session key was shared with us) the error will be returned.

func (*MegolmInboundSession) FirstKnownIndex added in v0.21.0

func (s *MegolmInboundSession) FirstKnownIndex() uint32

FirstKnownIndex returns the first message index we know how to decrypt.

func (*MegolmInboundSession) ID added in v0.21.0

ID returns the base64 endoded signing key

func (*MegolmInboundSession) IsVerified added in v0.21.0

func (s *MegolmInboundSession) IsVerified() bool

IsVerified check if the session has been verified as a valid session. (A session is verified either because the original session share was signed, or because we have subsequently successfully decrypted a message.)

func (*MegolmInboundSession) Pickle

func (o *MegolmInboundSession) Pickle(key []byte) ([]byte, error)

Pickle returns a base64 encoded and with key encrypted pickled MegolmInboundSession using PickleLibOlm().

func (*MegolmInboundSession) PickleAsJSON

func (o *MegolmInboundSession) PickleAsJSON(key []byte) ([]byte, error)

PickleAsJSON returns an MegolmInboundSession as a base64 string encrypted using the supplied key. The unencrypted representation of the Account is in JSON format.

func (*MegolmInboundSession) PickleLen

func (o *MegolmInboundSession) PickleLen() int

PickleLen returns the number of bytes the pickled session will have.

func (*MegolmInboundSession) PickleLibOlm

func (o *MegolmInboundSession) PickleLibOlm(target []byte) (int, error)

PickleLibOlm encodes the session into target. target has to have a size of at least PickleLen() and is written to from index 0. It returns the number of bytes written.

func (*MegolmInboundSession) Unpickle

func (o *MegolmInboundSession) Unpickle(pickled, key []byte) error

Unpickle decodes the base64 encoded string and decrypts the result with the key. The decrypted value is then passed to UnpickleLibOlm.

func (*MegolmInboundSession) UnpickleAsJSON

func (o *MegolmInboundSession) UnpickleAsJSON(pickled, key []byte) error

UnpickleAsJSON updates an MegolmInboundSession by a base64 encrypted string using the supplied key. The unencrypted representation has to be in JSON format.

func (*MegolmInboundSession) UnpickleLibOlm

func (o *MegolmInboundSession) UnpickleLibOlm(value []byte) (int, error)

UnpickleLibOlm decodes the unencryted value and populates the Session accordingly. It returns the number of bytes read.

type MegolmOutboundSession

type MegolmOutboundSession struct {
	Ratchet    megolm.Ratchet        `json:"ratchet"`
	SigningKey crypto.Ed25519KeyPair `json:"signing_key"`
}

MegolmOutboundSession stores information about the sessions to send.

func MegolmOutboundSessionFromPickled

func MegolmOutboundSessionFromPickled(pickled, key []byte) (*MegolmOutboundSession, error)

MegolmOutboundSessionFromPickled loads the MegolmOutboundSession details from a pickled base64 string. The input is decrypted with the supplied key.

func NewMegolmOutboundSession

func NewMegolmOutboundSession() (*MegolmOutboundSession, error)

NewMegolmOutboundSession creates a new MegolmOutboundSession.

func (*MegolmOutboundSession) Encrypt

func (o *MegolmOutboundSession) Encrypt(plaintext []byte) ([]byte, error)

Encrypt encrypts the plaintext as a base64 encoded group message.

func (*MegolmOutboundSession) ID added in v0.21.0

SessionID returns the base64 endoded public signing key

func (*MegolmOutboundSession) Key added in v0.21.0

func (s *MegolmOutboundSession) Key() string

Key returns the base64-encoded current ratchet key for this session.

func (*MegolmOutboundSession) MessageIndex added in v0.21.0

func (s *MegolmOutboundSession) MessageIndex() uint

MessageIndex returns the message index for this session. Each message is sent with an increasing index; this returns the index for the next message.

func (*MegolmOutboundSession) Pickle

func (o *MegolmOutboundSession) Pickle(key []byte) ([]byte, error)

Pickle returns a base64 encoded and with key encrypted pickled MegolmOutboundSession using PickleLibOlm().

func (*MegolmOutboundSession) PickleAsJSON

func (o *MegolmOutboundSession) PickleAsJSON(key []byte) ([]byte, error)

PickleAsJSON returns an Session as a base64 string encrypted using the supplied key. The unencrypted representation of the Account is in JSON format.

func (*MegolmOutboundSession) PickleLen

func (o *MegolmOutboundSession) PickleLen() int

PickleLen returns the number of bytes the pickled session will have.

func (*MegolmOutboundSession) PickleLibOlm

func (o *MegolmOutboundSession) PickleLibOlm(target []byte) (int, error)

PickleLibOlm encodes the session into target. target has to have a size of at least PickleLen() and is written to from index 0. It returns the number of bytes written.

func (*MegolmOutboundSession) SessionSharingMessage

func (o *MegolmOutboundSession) SessionSharingMessage() ([]byte, error)

func (*MegolmOutboundSession) Unpickle

func (o *MegolmOutboundSession) Unpickle(pickled, key []byte) error

Unpickle decodes the base64 encoded string and decrypts the result with the key. The decrypted value is then passed to UnpickleLibOlm.

func (*MegolmOutboundSession) UnpickleAsJSON

func (o *MegolmOutboundSession) UnpickleAsJSON(pickled, key []byte) error

UnpickleAsJSON updates an Session by a base64 encrypted string with the key. The unencrypted representation has to be in JSON format.

func (*MegolmOutboundSession) UnpickleLibOlm

func (o *MegolmOutboundSession) UnpickleLibOlm(value []byte) (int, error)

UnpickleLibOlm decodes the unencryted value and populates the Session accordingly. It returns the number of bytes read.

type OlmSession

type OlmSession struct {
	ReceivedMessage  bool                       `json:"received_message"`
	AliceIdentityKey crypto.Curve25519PublicKey `json:"alice_id_key"`
	AliceBaseKey     crypto.Curve25519PublicKey `json:"alice_base_key"`
	BobOneTimeKey    crypto.Curve25519PublicKey `json:"bob_one_time_key"`
	Ratchet          ratchet.Ratchet            `json:"ratchet"`
}

OlmSession stores all information for an olm session

func NewInboundOlmSession

func NewInboundOlmSession(identityKeyAlice *crypto.Curve25519PublicKey, receivedOTKMsg []byte, searchBobOTK SearchOTKFunc, identityKeyBob crypto.Curve25519KeyPair) (*OlmSession, error)

NewInboundOlmSession creates a new inbound session from receiving the first message.

func NewOlmSession

func NewOlmSession() *OlmSession

NewOlmSession creates a new Session.

func NewOutboundOlmSession

func NewOutboundOlmSession(identityKeyAlice crypto.Curve25519KeyPair, identityKeyBob crypto.Curve25519PublicKey, oneTimeKeyBob crypto.Curve25519PublicKey) (*OlmSession, error)

NewOutboundOlmSession creates a new outbound session for sending the first message to a given curve25519 identityKey and oneTimeKey.

func OlmSessionFromJSONPickled

func OlmSessionFromJSONPickled(pickled, key []byte) (*OlmSession, error)

OlmSessionFromJSONPickled loads an OlmSession from a pickled base64 string. Decrypts the Session using the supplied key.

func OlmSessionFromPickled

func OlmSessionFromPickled(pickled, key []byte) (*OlmSession, error)

OlmSessionFromPickled loads the OlmSession details from a pickled base64 string. The input is decrypted with the supplied key.

func (*OlmSession) Decrypt

func (s *OlmSession) Decrypt(crypttext string, msgType id.OlmMsgType) ([]byte, error)

Decrypt decrypts a base64 encoded message using the Session.

func (*OlmSession) Describe

func (o *OlmSession) Describe() string

Describe returns a string describing the current state of the session for debugging.

func (*OlmSession) Encrypt

func (s *OlmSession) Encrypt(plaintext []byte) (id.OlmMsgType, []byte, error)

Encrypt encrypts a message using the Session. Returns the encrypted message base64 encoded.

func (*OlmSession) EncryptMsgType

func (s *OlmSession) EncryptMsgType() id.OlmMsgType

EncryptMsgType returns the type of the next message that Encrypt will return. Returns MsgTypePreKey if the message will be a oneTimeKeyMsg. Returns MsgTypeMsg if the message will be a normal message.

func (*OlmSession) HasReceivedMessage

func (s *OlmSession) HasReceivedMessage() bool

HasReceivedMessage returns true if this session has received any message.

func (*OlmSession) ID

func (s *OlmSession) ID() id.SessionID

ID returns an identifier for this Session. Will be the same for both ends of the conversation. Generated by hashing the public keys used to create the session.

func (*OlmSession) MatchesInboundSession added in v0.21.0

func (s *OlmSession) MatchesInboundSession(oneTimeKeyMsg string) (bool, error)

MatchesInboundSession checks if the PRE_KEY message is for this in-bound Session. This can happen if multiple messages are sent to this Account before this Account sends a message in reply. Returns true if the session matches. Returns false if the session does not match. Returns error on failure.

func (*OlmSession) MatchesInboundSessionFrom

func (s *OlmSession) MatchesInboundSessionFrom(theirIdentityKey, oneTimeKeyMsg string) (bool, error)

MatchesInboundSessionFrom checks if the PRE_KEY message is for this in-bound Session. This can happen if multiple messages are sent to this Account before this Account sends a message in reply. Returns true if the session matches. Returns false if the session does not match. Returns error on failure.

func (*OlmSession) Pickle

func (s *OlmSession) Pickle(key []byte) ([]byte, error)

Pickle returns a base64 encoded and with key encrypted pickled olmSession using PickleLibOlm().

func (OlmSession) PickleAsJSON

func (a OlmSession) PickleAsJSON(key []byte) ([]byte, error)

PickleAsJSON returns an Session as a base64 string encrypted using the supplied key. The unencrypted representation of the Account is in JSON format.

func (*OlmSession) PickleLen

func (o *OlmSession) PickleLen() int

PickleLen returns the actual number of bytes the pickled session will have.

func (*OlmSession) PickleLenMin

func (o *OlmSession) PickleLenMin() int

PickleLenMin returns the minimum number of bytes the pickled session must have.

func (*OlmSession) PickleLibOlm

func (o *OlmSession) PickleLibOlm(target []byte) (int, error)

PickleLibOlm encodes the session into target. target has to have a size of at least PickleLen() and is written to from index 0. It returns the number of bytes written.

func (*OlmSession) Unpickle

func (o *OlmSession) Unpickle(pickled, key []byte) error

Unpickle decodes the base64 encoded string and decrypts the result with the key. The decrypted value is then passed to UnpickleLibOlm.

func (*OlmSession) UnpickleAsJSON

func (a *OlmSession) UnpickleAsJSON(pickled, key []byte) error

UnpickleAsJSON updates an Session by a base64 encrypted string with the key. The unencrypted representation has to be in JSON format.

func (*OlmSession) UnpickleLibOlm

func (o *OlmSession) UnpickleLibOlm(value []byte) (int, error)

UnpickleLibOlm decodes the unencryted value and populates the Session accordingly. It returns the number of bytes read.

type SearchOTKFunc

type SearchOTKFunc = func(crypto.Curve25519PublicKey) *crypto.OneTimeKey

SearchOTKFunc is used to retrieve a crypto.OneTimeKey from a public key.

Jump to

Keyboard shortcuts

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