crypto

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: MPL-2.0 Imports: 12 Imported by: 26

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	IncorrectEncryptedContentType = errors.New("event content is not instance of *event.EncryptedEventContent")
	NoSessionFound                = errors.New("failed to decrypt megolm event: no session with given ID found")
	DuplicateMessageIndex         = errors.New("duplicate message index")
	WrongRoom                     = errors.New("encrypted megolm event is not intended for this room")
	DeviceKeyMismatch             = errors.New("device keys in event and verified device info do not match")
)
View Source
var (
	UnsupportedAlgorithm                = errors.New("unsupported event encryption algorithm")
	NotEncryptedForMe                   = errors.New("olm event doesn't contain ciphertext for this device")
	UnsupportedOlmMessageType           = errors.New("unsupported olm message type")
	DecryptionFailedWithMatchingSession = errors.New("decryption failed with matching session")
	DecryptionFailedForNormalMessage    = errors.New("decryption failed for normal message")
	SenderMismatch                      = errors.New("mismatched sender in olm payload")
	RecipientMismatch                   = errors.New("mismatched recipient in olm payload")
	RecipientKeyMismatch                = errors.New("mismatched recipient key in olm payload")
)
View Source
var (
	MismatchingDeviceID   = errors.New("mismatching device ID in parameter and keys object")
	MismatchingUserID     = errors.New("mismatching user ID in parameter and keys object")
	MismatchingSigningKey = errors.New("received update for device with different signing key")
	NoSigningKeyFound     = errors.New("didn't find ed25519 signing key")
	NoIdentityKeyFound    = errors.New("didn't find curve25519 identity key")
	InvalidKeySignature   = errors.New("invalid signature on device keys")
)
View Source
var (
	AlreadyShared  = errors.New("group session already shared")
	NoGroupSession = errors.New("no group session created")
)
View Source
var (
	SessionNotShared = errors.New("session has not been shared")
	SessionExpired   = errors.New("session has expired")
)

Functions

This section is empty.

Types

type DeviceIdentity

type DeviceIdentity struct {
	UserID      id.UserID
	DeviceID    id.DeviceID
	IdentityKey id.Curve25519
	SigningKey  id.Ed25519

	Trust   TrustState
	Deleted bool
	Name    string
}

type ExpirationMixin

type ExpirationMixin struct {
	TimeMixin
	MaxAge time.Duration
}

func (*ExpirationMixin) Expired

func (exp *ExpirationMixin) Expired() bool

type GobStore

type GobStore struct {
	Account          *OlmAccount
	Sessions         map[id.SenderKey]OlmSessionList
	GroupSessions    map[id.RoomID]map[id.SenderKey]map[id.SessionID]*InboundGroupSession
	OutGroupSessions map[id.RoomID]*OutboundGroupSession
	MessageIndices   map[messageIndexKey]messageIndexValue
	Devices          map[id.UserID]map[id.DeviceID]*DeviceIdentity
	// contains filtered or unexported fields
}

func NewGobStore

func NewGobStore(path string) (*GobStore, error)

func (*GobStore) AddOutboundGroupSession added in v0.4.4

func (gs *GobStore) AddOutboundGroupSession(session *OutboundGroupSession) error

func (*GobStore) AddSession

func (gs *GobStore) AddSession(senderKey id.SenderKey, session *OlmSession) error

func (*GobStore) FilterTrackedUsers added in v0.3.1

func (gs *GobStore) FilterTrackedUsers(users []id.UserID) []id.UserID

func (*GobStore) Flush

func (gs *GobStore) Flush() error

func (*GobStore) GetAccount

func (gs *GobStore) GetAccount() (*OlmAccount, error)

func (*GobStore) GetDevice added in v0.4.7

func (gs *GobStore) GetDevice(userID id.UserID, deviceID id.DeviceID) (*DeviceIdentity, error)

func (*GobStore) GetDevices

func (gs *GobStore) GetDevices(userID id.UserID) (map[id.DeviceID]*DeviceIdentity, error)

func (*GobStore) GetGroupSession

func (gs *GobStore) GetGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (*InboundGroupSession, error)

func (*GobStore) GetLatestSession

func (gs *GobStore) GetLatestSession(senderKey id.SenderKey) (*OlmSession, error)

func (*GobStore) GetOutboundGroupSession

func (gs *GobStore) GetOutboundGroupSession(roomID id.RoomID) (*OutboundGroupSession, error)

func (*GobStore) GetSessions

func (gs *GobStore) GetSessions(senderKey id.SenderKey) (OlmSessionList, error)

func (*GobStore) HasSession

func (gs *GobStore) HasSession(senderKey id.SenderKey) bool

func (*GobStore) PutAccount

func (gs *GobStore) PutAccount(account *OlmAccount) error

func (*GobStore) PutDevices

func (gs *GobStore) PutDevices(userID id.UserID, devices map[id.DeviceID]*DeviceIdentity) error

func (*GobStore) PutGroupSession

func (gs *GobStore) PutGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, igs *InboundGroupSession) error

func (*GobStore) RemoveOutboundGroupSession added in v0.4.4

func (gs *GobStore) RemoveOutboundGroupSession(roomID id.RoomID) error

func (*GobStore) UpdateOutboundGroupSession added in v0.4.4

func (gs *GobStore) UpdateOutboundGroupSession(session *OutboundGroupSession) error

func (*GobStore) UpdateSession added in v0.4.3

func (gs *GobStore) UpdateSession(key id.SenderKey, session *OlmSession) error

func (*GobStore) ValidateMessageIndex

func (gs *GobStore) ValidateMessageIndex(senderKey id.SenderKey, sessionID id.SessionID, eventID id.EventID, index uint, timestamp int64) bool

type InboundGroupSession

type InboundGroupSession struct {
	Internal olm.InboundGroupSession

	SigningKey id.Ed25519
	SenderKey  id.Curve25519
	RoomID     id.RoomID

	ForwardingChains []string
	// contains filtered or unexported fields
}

func NewInboundGroupSession

func NewInboundGroupSession(senderKey id.SenderKey, signingKey id.Ed25519, roomID id.RoomID, sessionKey string) (*InboundGroupSession, error)

func (*InboundGroupSession) ID

func (igs *InboundGroupSession) ID() id.SessionID

type Logger

type Logger interface {
	Error(message string, args ...interface{})
	Warn(message string, args ...interface{})
	Debug(message string, args ...interface{})
	Trace(message string, args ...interface{})
}

type MegolmEvent

type MegolmEvent struct {
	RoomID  id.RoomID     `json:"room_id"`
	Type    event.Type    `json:"type"`
	Content event.Content `json:"content"`
}

type OGSState

type OGSState int
const (
	OGSNotShared OGSState = iota
	OGSAlreadyShared
	OGSIgnored
)

type OlmAccount

type OlmAccount struct {
	Internal olm.Account
	Shared   bool
}

func NewOlmAccount added in v0.4.1

func NewOlmAccount() *OlmAccount

func (*OlmAccount) NewInboundSessionFrom

func (account *OlmAccount) NewInboundSessionFrom(senderKey id.Curve25519, ciphertext string) (*OlmSession, error)

type OlmEvent

type OlmEvent struct {
	Source *event.Event `json:"-"`

	SenderKey id.SenderKey `json:"-"`

	Sender        id.UserID    `json:"sender"`
	SenderDevice  id.DeviceID  `json:"sender_device"`
	Keys          OlmEventKeys `json:"keys"`
	Recipient     id.UserID    `json:"recipient"`
	RecipientKeys OlmEventKeys `json:"recipient_keys"`

	Type    event.Type    `json:"type"`
	Content event.Content `json:"content"`
}

type OlmEventKeys

type OlmEventKeys struct {
	Ed25519 id.Ed25519 `json:"ed25519"`
}

type OlmMachine

type OlmMachine struct {
	Client *mautrix.Client
	Log    Logger

	CryptoStore Store
	StateStore  StateStore
	// contains filtered or unexported fields
}

func NewOlmMachine

func NewOlmMachine(client *mautrix.Client, log Logger, cryptoStore Store, stateStore StateStore) *OlmMachine

func (*OlmMachine) DecryptMegolmEvent

func (mach *OlmMachine) DecryptMegolmEvent(evt *event.Event) (*event.Event, error)

func (*OlmMachine) EncryptMegolmEvent

func (mach *OlmMachine) EncryptMegolmEvent(roomID id.RoomID, evtType event.Type, content event.Content) (*event.EncryptedEventContent, error)

func (*OlmMachine) Fingerprint added in v0.3.3

func (mach *OlmMachine) Fingerprint() string

func (*OlmMachine) FlushStore

func (mach *OlmMachine) FlushStore() error

func (*OlmMachine) HandleMemberEvent

func (mach *OlmMachine) HandleMemberEvent(evt *event.Event)

func (*OlmMachine) HandleToDeviceEvent

func (mach *OlmMachine) HandleToDeviceEvent(evt *event.Event)

func (*OlmMachine) Load

func (mach *OlmMachine) Load() (err error)

func (*OlmMachine) OnDevicesChanged

func (mach *OlmMachine) OnDevicesChanged(userID id.UserID)

func (*OlmMachine) ProcessSyncResponse

func (mach *OlmMachine) ProcessSyncResponse(resp *mautrix.RespSync, since string)

func (*OlmMachine) SaveAccount

func (mach *OlmMachine) SaveAccount()

func (*OlmMachine) ShareGroupSession

func (mach *OlmMachine) ShareGroupSession(roomID id.RoomID, users []id.UserID) error

func (*OlmMachine) ShareKeys

func (mach *OlmMachine) ShareKeys(currentOTKCount int) error

ShareKeys returns a key upload request.

type OlmSession

type OlmSession struct {
	Internal olm.Session
	ExpirationMixin
	// contains filtered or unexported fields
}

func (*OlmSession) Decrypt

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

func (*OlmSession) Encrypt

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

func (*OlmSession) ID

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

type OlmSessionList

type OlmSessionList []*OlmSession

OlmSessionList is a list of OlmSessions. It implements sort.Interface in a way that sorts items in reverse alphabetic order, which means the newest session is first.

func (OlmSessionList) Len

func (o OlmSessionList) Len() int

func (OlmSessionList) Less

func (o OlmSessionList) Less(i, j int) bool

func (OlmSessionList) Swap

func (o OlmSessionList) Swap(i, j int)

type OutboundGroupSession

type OutboundGroupSession struct {
	Internal olm.OutboundGroupSession

	ExpirationMixin
	MaxMessages  int
	MessageCount int

	Users  map[UserDevice]OGSState
	RoomID id.RoomID
	Shared bool
	// contains filtered or unexported fields
}

func NewOutboundGroupSession

func NewOutboundGroupSession(roomID id.RoomID) *OutboundGroupSession

func (*OutboundGroupSession) Encrypt

func (ogs *OutboundGroupSession) Encrypt(plaintext []byte) ([]byte, error)

func (*OutboundGroupSession) Expired

func (ogs *OutboundGroupSession) Expired() bool

func (*OutboundGroupSession) ID

func (ogs *OutboundGroupSession) ID() id.SessionID

func (*OutboundGroupSession) ShareContent

func (ogs *OutboundGroupSession) ShareContent() event.Content

type StateStore

type StateStore interface {
	IsEncrypted(id.RoomID) bool
	FindSharedRooms(id.UserID) []id.RoomID
}

type Store

type Store interface {
	Flush() error

	PutAccount(*OlmAccount) error
	GetAccount() (*OlmAccount, error)

	HasSession(id.SenderKey) bool
	GetSessions(id.SenderKey) (OlmSessionList, error)
	GetLatestSession(id.SenderKey) (*OlmSession, error)
	AddSession(id.SenderKey, *OlmSession) error
	UpdateSession(id.SenderKey, *OlmSession) error

	PutGroupSession(id.RoomID, id.SenderKey, id.SessionID, *InboundGroupSession) error
	GetGroupSession(id.RoomID, id.SenderKey, id.SessionID) (*InboundGroupSession, error)

	AddOutboundGroupSession(*OutboundGroupSession) error
	UpdateOutboundGroupSession(*OutboundGroupSession) error
	GetOutboundGroupSession(id.RoomID) (*OutboundGroupSession, error)
	RemoveOutboundGroupSession(id.RoomID) error

	ValidateMessageIndex(senderKey id.SenderKey, sessionID id.SessionID, eventID id.EventID, index uint, timestamp int64) bool

	GetDevices(id.UserID) (map[id.DeviceID]*DeviceIdentity, error)
	GetDevice(id.UserID, id.DeviceID) (*DeviceIdentity, error)
	PutDevices(id.UserID, map[id.DeviceID]*DeviceIdentity) error
	FilterTrackedUsers([]id.UserID) []id.UserID
}

type TimeMixin

type TimeMixin struct {
	CreationTime time.Time
	UseTime      time.Time
}

type TrustState

type TrustState int
const (
	TrustStateUnset TrustState = iota
	TrustStateVerified
	TrustStateBlacklisted
	TrustStateIgnored
)

type UserDevice

type UserDevice struct {
	UserID   id.UserID
	DeviceID id.DeviceID
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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