Documentation ¶
Index ¶
- Constants
- Variables
- func ExportKeys(passphrase string, sessions []*InboundGroupSession) ([]byte, error)
- func Fingerprint(key id.SigningKey) stringdeprecated
- func IsShareError(err error) bool
- type CrossSigningKeysCache
- type CrossSigningPublicKeysCache
- type CrossSigningSeeds
- type DecimalSASData
- type DecryptedOlmEvent
- type EmojiSASData
- type ExpirationMixin
- type ExportedSession
- type InboundGroupSession
- type KeyShareRejection
- type MemoryStore
- func (gs *MemoryStore) AddOutboundGroupSession(session *OutboundGroupSession) error
- func (gs *MemoryStore) AddSession(senderKey id.SenderKey, session *OlmSession) error
- func (gs *MemoryStore) DropSignaturesByKey(userID id.UserID, key id.Ed25519) (int64, error)
- func (gs *MemoryStore) FilterTrackedUsers(users []id.UserID) ([]id.UserID, error)
- func (gs *MemoryStore) FindDeviceByKey(userID id.UserID, identityKey id.IdentityKey) (*id.Device, error)
- func (gs *MemoryStore) Flush() error
- func (gs *MemoryStore) GetAccount() (*OlmAccount, error)
- func (gs *MemoryStore) GetAllGroupSessions() ([]*InboundGroupSession, error)
- func (gs *MemoryStore) GetCrossSigningKeys(userID id.UserID) (map[id.CrossSigningUsage]id.CrossSigningKey, error)
- func (gs *MemoryStore) GetDevice(userID id.UserID, deviceID id.DeviceID) (*id.Device, error)
- func (gs *MemoryStore) GetDevices(userID id.UserID) (map[id.DeviceID]*id.Device, error)
- func (gs *MemoryStore) GetGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (*InboundGroupSession, error)
- func (gs *MemoryStore) GetGroupSessionsForRoom(roomID id.RoomID) ([]*InboundGroupSession, error)
- func (gs *MemoryStore) GetLatestSession(senderKey id.SenderKey) (*OlmSession, error)
- func (gs *MemoryStore) GetOutboundGroupSession(roomID id.RoomID) (*OutboundGroupSession, error)
- func (gs *MemoryStore) GetSessions(senderKey id.SenderKey) (OlmSessionList, error)
- func (gs *MemoryStore) GetSignaturesForKeyBy(userID id.UserID, key id.Ed25519, signerID id.UserID) (map[id.Ed25519]string, error)
- func (gs *MemoryStore) GetWithheldGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (*event.RoomKeyWithheldEventContent, error)
- func (gs *MemoryStore) HasSession(senderKey id.SenderKey) bool
- func (gs *MemoryStore) IsKeySignedBy(userID id.UserID, key id.Ed25519, signerID id.UserID, signerKey id.Ed25519) (bool, error)
- func (gs *MemoryStore) PutAccount(account *OlmAccount) error
- func (gs *MemoryStore) PutCrossSigningKey(userID id.UserID, usage id.CrossSigningUsage, key id.Ed25519) error
- func (gs *MemoryStore) PutDevice(userID id.UserID, device *id.Device) error
- func (gs *MemoryStore) PutDevices(userID id.UserID, devices map[id.DeviceID]*id.Device) error
- func (gs *MemoryStore) PutGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, ...) error
- func (gs *MemoryStore) PutSignature(signedUserID id.UserID, signedKey id.Ed25519, signerUserID id.UserID, ...) error
- func (gs *MemoryStore) PutWithheldGroupSession(content event.RoomKeyWithheldEventContent) error
- func (gs *MemoryStore) RedactExpiredGroupSessions() ([]id.SessionID, error)
- func (gs *MemoryStore) RedactGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, ...) error
- func (gs *MemoryStore) RedactGroupSessions(roomID id.RoomID, senderKey id.SenderKey, reason string) ([]id.SessionID, error)
- func (gs *MemoryStore) RedactOutdatedGroupSessions() ([]id.SessionID, error)
- func (gs *MemoryStore) RemoveOutboundGroupSession(roomID id.RoomID) error
- func (gs *MemoryStore) UpdateOutboundGroupSession(_ *OutboundGroupSession) error
- func (gs *MemoryStore) UpdateSession(_ id.SenderKey, _ *OlmSession) error
- func (gs *MemoryStore) ValidateMessageIndex(_ context.Context, senderKey id.SenderKey, sessionID id.SessionID, ...) (bool, error)
- type OGSState
- type OlmAccount
- type OlmEventKeys
- type OlmMachine
- func (mach *OlmMachine) AddAppserviceListener(ep asEventProcessor)
- func (mach *OlmMachine) CancelSASVerification(userID id.UserID, transactionID, reason string) error
- func (mach *OlmMachine) DecryptMegolmEvent(ctx context.Context, evt *event.Event) (*event.Event, error)
- func (mach *OlmMachine) EncryptMegolmEvent(ctx context.Context, roomID id.RoomID, evtType event.Type, content interface{}) (*event.EncryptedEventContent, error)
- func (mach *OlmMachine) ExpiredKeyDeleteLoop(ctx context.Context)
- func (mach *OlmMachine) ExportCrossSigningKeys() CrossSigningSeeds
- func (mach *OlmMachine) FetchCrossSigningKeysFromSSSS(key *ssss.Key) error
- func (mach *OlmMachine) Fingerprint() string
- func (mach *OlmMachine) FlushStore() error
- func (mach *OlmMachine) GenerateAndUploadCrossSigningKeys(userPassword, passphrase string) (string, error)
- func (mach *OlmMachine) GenerateCrossSigningKeys() (*CrossSigningKeysCache, error)
- func (mach *OlmMachine) GetAccount() *OlmAccount
- func (mach *OlmMachine) GetCrossSigningPublicKeys(userID id.UserID) (*CrossSigningPublicKeysCache, error)
- func (mach *OlmMachine) GetOrFetchDevice(ctx context.Context, userID id.UserID, deviceID id.DeviceID) (*id.Device, error)
- func (mach *OlmMachine) GetOrFetchDeviceByKey(ctx context.Context, userID id.UserID, identityKey id.IdentityKey) (*id.Device, error)
- func (mach *OlmMachine) GetOwnCrossSigningPublicKeys() *CrossSigningPublicKeysCache
- func (mach *OlmMachine) HandleDeviceLists(dl *mautrix.DeviceLists, since string)
- func (mach *OlmMachine) HandleMemberEvent(_ mautrix.EventSource, evt *event.Event)
- func (mach *OlmMachine) HandleOTKCounts(otkCount *mautrix.OTKCount)
- func (mach *OlmMachine) HandleToDeviceEvent(evt *event.Event)
- func (mach *OlmMachine) ImportCrossSigningKeys(keys CrossSigningSeeds) (err error)
- func (mach *OlmMachine) ImportKeys(passphrase string, data []byte) (int, int, error)
- func (mach *OlmMachine) IsDeviceTrusted(device *id.Device) bool
- func (mach *OlmMachine) IsUserTrusted(ctx context.Context, userID id.UserID) (bool, error)
- func (mach *OlmMachine) Load() (err error)
- func (mach *OlmMachine) LoadDevices(user id.UserID) map[id.DeviceID]*id.Device
- func (mach *OlmMachine) NewInRoomSASVerificationWith(inRoomID id.RoomID, userID id.UserID, hooks VerificationHooks, ...) (string, error)
- func (mach *OlmMachine) NewSASVerificationWith(device *id.Device, hooks VerificationHooks, transactionID string, ...) (string, error)
- func (mach *OlmMachine) NewSimpleSASVerificationWith(device *id.Device, hooks VerificationHooks) (string, error)
- func (mach *OlmMachine) OnDevicesChanged(userID id.UserID)
- func (mach *OlmMachine) OwnIdentity() *id.Device
- func (mach *OlmMachine) ProcessInRoomVerification(evt *event.Event) error
- func (mach *OlmMachine) ProcessSyncResponse(resp *mautrix.RespSync, since string) bool
- func (mach *OlmMachine) PublishCrossSigningKeys(keys *CrossSigningKeysCache, uiaCallback mautrix.UIACallback) error
- func (mach *OlmMachine) RequestRoomKey(ctx context.Context, toUser id.UserID, toDevice id.DeviceID, roomID id.RoomID, ...) (chan bool, error)deprecated
- func (mach *OlmMachine) ResolveTrust(device *id.Device) id.TrustState
- func (mach *OlmMachine) ResolveTrustContext(ctx context.Context, device *id.Device) (id.TrustState, error)
- func (mach *OlmMachine) SendEncryptedToDevice(ctx context.Context, device *id.Device, evtType event.Type, ...) error
- func (mach *OlmMachine) SendInRoomSASVerificationAccept(roomID id.RoomID, fromUser id.UserID, ...) error
- func (mach *OlmMachine) SendInRoomSASVerificationCancel(roomID id.RoomID, userID id.UserID, transactionID string, reason string, ...) error
- func (mach *OlmMachine) SendInRoomSASVerificationKey(roomID id.RoomID, userID id.UserID, transactionID string, key string) error
- func (mach *OlmMachine) SendInRoomSASVerificationMAC(roomID id.RoomID, userID id.UserID, deviceID id.DeviceID, transactionID string, ...) error
- func (mach *OlmMachine) SendInRoomSASVerificationReady(roomID id.RoomID, transactionID string) error
- func (mach *OlmMachine) SendInRoomSASVerificationRequest(roomID id.RoomID, toUserID id.UserID, methods []VerificationMethod) (string, error)
- func (mach *OlmMachine) SendInRoomSASVerificationStart(roomID id.RoomID, toUserID id.UserID, transactionID string, ...) (*event.VerificationStartEventContent, error)
- func (mach *OlmMachine) SendRoomKeyRequest(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, ...) error
- func (mach *OlmMachine) SendSASVerificationAccept(fromUser id.UserID, startEvent *event.VerificationStartEventContent, ...) error
- func (mach *OlmMachine) SendSASVerificationCancel(userID id.UserID, deviceID id.DeviceID, transactionID string, reason string, ...) error
- func (mach *OlmMachine) SendSASVerificationKey(userID id.UserID, deviceID id.DeviceID, transactionID string, key string) error
- func (mach *OlmMachine) SendSASVerificationMAC(userID id.UserID, deviceID id.DeviceID, transactionID string, sas *olm.SAS) error
- func (mach *OlmMachine) SendSASVerificationStart(toUserID id.UserID, toDeviceID id.DeviceID, transactionID string, ...) (*event.VerificationStartEventContent, error)
- func (mach *OlmMachine) ShareGroupSession(ctx context.Context, roomID id.RoomID, users []id.UserID) error
- func (mach *OlmMachine) ShareKeys(ctx context.Context, currentOTKCount int) error
- func (mach *OlmMachine) SignOwnDevice(device *id.Device) error
- func (mach *OlmMachine) SignOwnMasterKey() error
- func (mach *OlmMachine) SignUser(userID id.UserID, masterKey id.Ed25519) error
- func (mach *OlmMachine) UploadCrossSigningKeysToSSSS(key *ssss.Key, keys *CrossSigningKeysCache) error
- func (mach *OlmMachine) WaitForSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, ...) bool
- type OlmSession
- type OlmSessionList
- type OutboundGroupSession
- type RatchetSafety
- type SASData
- type SQLCryptoStore
- func (store *SQLCryptoStore) AddOutboundGroupSession(session *OutboundGroupSession) error
- func (store *SQLCryptoStore) AddSession(key id.SenderKey, session *OlmSession) error
- func (store *SQLCryptoStore) DropSignaturesByKey(userID id.UserID, key id.Ed25519) (int64, error)
- func (store *SQLCryptoStore) FilterTrackedUsers(users []id.UserID) ([]id.UserID, error)
- func (store *SQLCryptoStore) FindDeviceByKey(userID id.UserID, identityKey id.IdentityKey) (*id.Device, error)
- func (store *SQLCryptoStore) FindDeviceID() (deviceID id.DeviceID)
- func (store *SQLCryptoStore) Flush() error
- func (store *SQLCryptoStore) GetAccount() (*OlmAccount, error)
- func (store *SQLCryptoStore) GetAllGroupSessions() ([]*InboundGroupSession, error)
- func (store *SQLCryptoStore) GetCrossSigningKeys(userID id.UserID) (map[id.CrossSigningUsage]id.CrossSigningKey, error)
- func (store *SQLCryptoStore) GetDevice(userID id.UserID, deviceID id.DeviceID) (*id.Device, error)
- func (store *SQLCryptoStore) GetDevices(userID id.UserID) (map[id.DeviceID]*id.Device, error)
- func (store *SQLCryptoStore) GetGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (*InboundGroupSession, error)
- func (store *SQLCryptoStore) GetGroupSessionsForRoom(roomID id.RoomID) ([]*InboundGroupSession, error)
- func (store *SQLCryptoStore) GetLatestSession(key id.SenderKey) (*OlmSession, error)
- func (store *SQLCryptoStore) GetNextBatch() (string, error)
- func (store *SQLCryptoStore) GetOutboundGroupSession(roomID id.RoomID) (*OutboundGroupSession, error)
- func (store *SQLCryptoStore) GetSessions(key id.SenderKey) (OlmSessionList, error)
- func (store *SQLCryptoStore) GetSignaturesForKeyBy(userID id.UserID, key id.Ed25519, signerID id.UserID) (map[id.Ed25519]string, error)
- func (store *SQLCryptoStore) GetWithheldGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (*event.RoomKeyWithheldEventContent, error)
- func (store *SQLCryptoStore) HasSession(key id.SenderKey) bool
- func (store *SQLCryptoStore) IsKeySignedBy(signedUserID id.UserID, signedKey id.Ed25519, signerUserID id.UserID, ...) (isSigned bool, err error)
- func (store *SQLCryptoStore) LoadFilterID(_ id.UserID) string
- func (store *SQLCryptoStore) LoadNextBatch(_ id.UserID) string
- func (store *SQLCryptoStore) PutAccount(account *OlmAccount) error
- func (store *SQLCryptoStore) PutCrossSigningKey(userID id.UserID, usage id.CrossSigningUsage, key id.Ed25519) error
- func (store *SQLCryptoStore) PutDevice(userID id.UserID, device *id.Device) error
- func (store *SQLCryptoStore) PutDevices(userID id.UserID, devices map[id.DeviceID]*id.Device) error
- func (store *SQLCryptoStore) PutGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, ...) error
- func (store *SQLCryptoStore) PutNextBatch(nextBatch string) error
- func (store *SQLCryptoStore) PutSignature(signedUserID id.UserID, signedKey id.Ed25519, signerUserID id.UserID, ...) error
- func (store *SQLCryptoStore) PutWithheldGroupSession(content event.RoomKeyWithheldEventContent) error
- func (store *SQLCryptoStore) RedactExpiredGroupSessions() ([]id.SessionID, error)
- func (store *SQLCryptoStore) RedactGroupSession(_ id.RoomID, _ id.SenderKey, sessionID id.SessionID, reason string) error
- func (store *SQLCryptoStore) RedactGroupSessions(roomID id.RoomID, senderKey id.SenderKey, reason string) ([]id.SessionID, error)
- func (store *SQLCryptoStore) RedactOutdatedGroupSessions() ([]id.SessionID, error)
- func (store *SQLCryptoStore) RemoveOutboundGroupSession(roomID id.RoomID) error
- func (store *SQLCryptoStore) SaveFilterID(_ id.UserID, _ string)
- func (store *SQLCryptoStore) SaveNextBatch(_ id.UserID, nextBatchToken string)
- func (store *SQLCryptoStore) UpdateOutboundGroupSession(session *OutboundGroupSession) error
- func (store *SQLCryptoStore) UpdateSession(_ id.SenderKey, session *OlmSession) error
- func (store *SQLCryptoStore) ValidateMessageIndex(ctx context.Context, senderKey id.SenderKey, sessionID id.SessionID, ...) (bool, error)
- type SenderClaimedKeys
- type StateStore
- type Store
- type TimeMixin
- type UserDevice
- type VerificationEmoji
- type VerificationHooks
- type VerificationMethod
- type VerificationMethodDecimal
- type VerificationMethodEmoji
- type VerificationRequestResponse
Constants ¶
const MinUnwedgeInterval = 1 * time.Hour
Variables ¶
var ( ErrCrossSigningKeysNotCached = errors.New("cross-signing private keys not in cache") ErrUserSigningKeyNotCached = errors.New("user-signing private key not in cache") ErrSelfSigningKeyNotCached = errors.New("self-signing private key not in cache") ErrSignatureUploadFail = errors.New("server-side failure uploading signatures") ErrCantSignOwnMasterKey = errors.New("signing your own master key is not allowed") ErrCantSignOtherDevice = errors.New("signing other users' devices is not allowed") ErrUserNotInQueryResponse = errors.New("could not find user in query keys response") ErrDeviceNotInQueryResponse = errors.New("could not find device in query keys response") ErrOlmAccountNotLoaded = errors.New("olm account has not been loaded") ErrCrossSigningMasterKeyNotFound = errors.New("cross-signing master key not found") ErrMasterKeyMACNotFound = errors.New("found cross-signing master key, but didn't find corresponding MAC in verification request") ErrMismatchingMasterKeyMAC = errors.New("mismatching cross-signing master key MAC") )
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 megolm 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") SenderKeyMismatch = errors.New("sender keys in content and megolm session do not match") RatchetError = errors.New("failed to ratchet session after use") )
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") )
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") )
var ( NoGroupSession = errors.New("no group session created") )
var ( ErrMissingExportPrefix = errors.New("invalid Matrix key export: missing prefix") ErrMissingExportSuffix = errors.New("invalid Matrix key export: missing suffix") ErrUnsupportedExportVersion = errors.New("unsupported Matrix key export format version") ErrMismatchingExportHash = errors.New("mismatching hash; incorrect passphrase?") ErrInvalidExportedAlgorithm = errors.New("session has unknown algorithm") ErrMismatchingExportedSessionID = errors.New("imported session has different ID than expected") )
var ( KeyShareRejection{} )KeyShareRejectNoResponse =
var ( SessionExpired = errors.New("session has expired") )
var ( ErrUnknownUserForTransaction = errors.New("unknown user for transaction") ErrTransactionAlreadyExists = errors.New("transaction already exists") // ErrUnknownTransaction is returned when a key verification message is received with an unknown transaction ID. ErrUnknownTransaction = errors.New("unknown transaction") // ErrUnknownVerificationMethod is returned when the verification method in a received m.key.verification.start is unknown. ErrUnknownVerificationMethod = errors.New("unknown verification method") )
var ( ErrNoVerificationFromDevice = errors.New("from_device field is empty") ErrNoVerificationMethods = errors.New("verification method list is empty") ErrNoRelatesTo = errors.New("missing m.relates_to info") )
var ErrGroupSessionWithheld error = &event.RoomKeyWithheldEventContent{}
var PostgresArrayWrapper func(interface{}) interface { driver.Valuer sql.Scanner }
Functions ¶
func ExportKeys ¶
func ExportKeys(passphrase string, sessions []*InboundGroupSession) ([]byte, error)
ExportKeys exports the given Megolm sessions with the format specified in the Matrix spec. See https://spec.matrix.org/v1.2/client-server-api/#key-exports
func Fingerprint
deprecated
func Fingerprint(key id.SigningKey) string
Deprecated: moved to SigningKey.Fingerprint
func IsShareError ¶
IsShareError returns true if the error is caused by the lack of an outgoing megolm session and can be solved with OlmMachine.ShareGroupSession
Types ¶
type CrossSigningKeysCache ¶
type CrossSigningKeysCache struct { MasterKey *olm.PkSigning SelfSigningKey *olm.PkSigning UserSigningKey *olm.PkSigning }
CrossSigningKeysCache holds the three cross-signing keys for the current user.
func (*CrossSigningKeysCache) PublicKeys ¶
func (cskc *CrossSigningKeysCache) PublicKeys() *CrossSigningPublicKeysCache
type CrossSigningSeeds ¶
type DecimalSASData ¶
type DecimalSASData [3]uint
DecimalSASData contains the verification numbers for the decimal SAS method.
func (DecimalSASData) Type ¶
func (DecimalSASData) Type() event.SASMethod
Type returns the decimal SAS method type.
type DecryptedOlmEvent ¶
type DecryptedOlmEvent 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"` }
DecryptedOlmEvent represents an event that was decrypted from an event encrypted with the m.olm.v1.curve25519-aes-sha2 algorithm.
type EmojiSASData ¶
type EmojiSASData [7]VerificationEmoji
EmojiSASData contains the verification emojis for the emoji SAS method.
func (EmojiSASData) Type ¶
func (EmojiSASData) Type() event.SASMethod
Type returns the emoji SAS method type.
type ExpirationMixin ¶
func (*ExpirationMixin) Expired ¶
func (exp *ExpirationMixin) Expired() bool
type ExportedSession ¶
type ExportedSession struct { Algorithm id.Algorithm `json:"algorithm"` ForwardingChains []string `json:"forwarding_curve25519_key_chain"` RoomID id.RoomID `json:"room_id"` SenderKey id.SenderKey `json:"sender_key"` SenderClaimedKeys SenderClaimedKeys `json:"sender_claimed_keys"` SessionID id.SessionID `json:"session_id"` SessionKey string `json:"session_key"` }
type InboundGroupSession ¶
type InboundGroupSession struct { Internal olm.InboundGroupSession SigningKey id.Ed25519 SenderKey id.Curve25519 RoomID id.RoomID ForwardingChains []string RatchetSafety RatchetSafety ReceivedAt time.Time MaxAge int64 MaxMessages int IsScheduled bool // contains filtered or unexported fields }
func NewInboundGroupSession ¶
func (*InboundGroupSession) ID ¶
func (igs *InboundGroupSession) ID() id.SessionID
func (*InboundGroupSession) RatchetTo ¶
func (igs *InboundGroupSession) RatchetTo(index uint32) error
type KeyShareRejection ¶
type KeyShareRejection struct {}
type MemoryStore ¶
type MemoryStore struct { Account *OlmAccount Sessions map[id.SenderKey]OlmSessionList GroupSessions map[id.RoomID]map[id.SenderKey]map[id.SessionID]*InboundGroupSession WithheldGroupSessions map[id.RoomID]map[id.SenderKey]map[id.SessionID]*event.RoomKeyWithheldEventContent OutGroupSessions map[id.RoomID]*OutboundGroupSession MessageIndices map[messageIndexKey]messageIndexValue Devices map[id.UserID]map[id.DeviceID]*id.Device CrossSigningKeys map[id.UserID]map[id.CrossSigningUsage]id.CrossSigningKey KeySignatures map[id.UserID]map[id.Ed25519]map[id.UserID]map[id.Ed25519]string // contains filtered or unexported fields }
MemoryStore is a simple in-memory Store implementation. It can optionally have a callback function for saving data, but the actual storage must be implemented manually.
func NewMemoryStore ¶
func NewMemoryStore(saveCallback func() error) *MemoryStore
func (*MemoryStore) AddOutboundGroupSession ¶
func (gs *MemoryStore) AddOutboundGroupSession(session *OutboundGroupSession) error
func (*MemoryStore) AddSession ¶
func (gs *MemoryStore) AddSession(senderKey id.SenderKey, session *OlmSession) error
func (*MemoryStore) DropSignaturesByKey ¶
func (*MemoryStore) FilterTrackedUsers ¶
func (*MemoryStore) FindDeviceByKey ¶
func (gs *MemoryStore) FindDeviceByKey(userID id.UserID, identityKey id.IdentityKey) (*id.Device, error)
func (*MemoryStore) Flush ¶
func (gs *MemoryStore) Flush() error
func (*MemoryStore) GetAccount ¶
func (gs *MemoryStore) GetAccount() (*OlmAccount, error)
func (*MemoryStore) GetAllGroupSessions ¶
func (gs *MemoryStore) GetAllGroupSessions() ([]*InboundGroupSession, error)
func (*MemoryStore) GetCrossSigningKeys ¶
func (gs *MemoryStore) GetCrossSigningKeys(userID id.UserID) (map[id.CrossSigningUsage]id.CrossSigningKey, error)
func (*MemoryStore) GetDevices ¶
func (*MemoryStore) GetGroupSession ¶
func (gs *MemoryStore) GetGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (*InboundGroupSession, error)
func (*MemoryStore) GetGroupSessionsForRoom ¶
func (gs *MemoryStore) GetGroupSessionsForRoom(roomID id.RoomID) ([]*InboundGroupSession, error)
func (*MemoryStore) GetLatestSession ¶
func (gs *MemoryStore) GetLatestSession(senderKey id.SenderKey) (*OlmSession, error)
func (*MemoryStore) GetOutboundGroupSession ¶
func (gs *MemoryStore) GetOutboundGroupSession(roomID id.RoomID) (*OutboundGroupSession, error)
func (*MemoryStore) GetSessions ¶
func (gs *MemoryStore) GetSessions(senderKey id.SenderKey) (OlmSessionList, error)
func (*MemoryStore) GetSignaturesForKeyBy ¶
func (*MemoryStore) GetWithheldGroupSession ¶
func (gs *MemoryStore) GetWithheldGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (*event.RoomKeyWithheldEventContent, error)
func (*MemoryStore) HasSession ¶
func (gs *MemoryStore) HasSession(senderKey id.SenderKey) bool
func (*MemoryStore) IsKeySignedBy ¶
func (*MemoryStore) PutAccount ¶
func (gs *MemoryStore) PutAccount(account *OlmAccount) error
func (*MemoryStore) PutCrossSigningKey ¶
func (gs *MemoryStore) PutCrossSigningKey(userID id.UserID, usage id.CrossSigningUsage, key id.Ed25519) error
func (*MemoryStore) PutDevices ¶
func (*MemoryStore) PutGroupSession ¶
func (gs *MemoryStore) PutGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, igs *InboundGroupSession) error
func (*MemoryStore) PutSignature ¶
func (*MemoryStore) PutWithheldGroupSession ¶
func (gs *MemoryStore) PutWithheldGroupSession(content event.RoomKeyWithheldEventContent) error
func (*MemoryStore) RedactExpiredGroupSessions ¶
func (gs *MemoryStore) RedactExpiredGroupSessions() ([]id.SessionID, error)
func (*MemoryStore) RedactGroupSession ¶
func (*MemoryStore) RedactGroupSessions ¶
func (*MemoryStore) RedactOutdatedGroupSessions ¶
func (gs *MemoryStore) RedactOutdatedGroupSessions() ([]id.SessionID, error)
func (*MemoryStore) RemoveOutboundGroupSession ¶
func (gs *MemoryStore) RemoveOutboundGroupSession(roomID id.RoomID) error
func (*MemoryStore) UpdateOutboundGroupSession ¶
func (gs *MemoryStore) UpdateOutboundGroupSession(_ *OutboundGroupSession) error
func (*MemoryStore) UpdateSession ¶
func (gs *MemoryStore) UpdateSession(_ id.SenderKey, _ *OlmSession) error
type OlmAccount ¶
func NewOlmAccount ¶
func NewOlmAccount() *OlmAccount
func (*OlmAccount) IdentityKey ¶
func (account *OlmAccount) IdentityKey() id.IdentityKey
func (*OlmAccount) Keys ¶
func (account *OlmAccount) Keys() (id.SigningKey, id.IdentityKey)
func (*OlmAccount) NewInboundSessionFrom ¶
func (account *OlmAccount) NewInboundSessionFrom(senderKey id.Curve25519, ciphertext string) (*OlmSession, error)
func (*OlmAccount) SigningKey ¶
func (account *OlmAccount) SigningKey() id.SigningKey
type OlmEventKeys ¶
type OlmMachine ¶
type OlmMachine struct { Client *mautrix.Client SSSS *ssss.Machine Log *zerolog.Logger CryptoStore Store StateStore StateStore PlaintextMentions bool SendKeysMinTrust id.TrustState DefaultSASTimeout time.Duration // AcceptVerificationFrom determines whether the machine will accept verification requests from this device. AcceptVerificationFrom func(string, *id.Device, id.RoomID) (VerificationRequestResponse, VerificationHooks) CrossSigningKeys *CrossSigningKeysCache DeleteOutboundKeysOnAck bool DontStoreOutboundKeys bool DeletePreviousKeysOnReceive bool RatchetKeysOnDecrypt bool DeleteFullyUsedKeysOnDecrypt bool DeleteKeysOnDeviceDelete bool DisableDeviceChangeKeyRotation bool // contains filtered or unexported fields }
OlmMachine is the main struct for handling Matrix end-to-end encryption.
func NewOlmMachine ¶
func NewOlmMachine(client *mautrix.Client, log *zerolog.Logger, cryptoStore Store, stateStore StateStore) *OlmMachine
NewOlmMachine creates an OlmMachine with the given client, logger and stores.
func (*OlmMachine) AddAppserviceListener ¶
func (mach *OlmMachine) AddAppserviceListener(ep asEventProcessor)
func (*OlmMachine) CancelSASVerification ¶
func (mach *OlmMachine) CancelSASVerification(userID id.UserID, transactionID, reason string) error
CancelSASVerification is used by the user to cancel a SAS verification process with the given reason.
func (*OlmMachine) DecryptMegolmEvent ¶
func (mach *OlmMachine) DecryptMegolmEvent(ctx context.Context, evt *event.Event) (*event.Event, error)
DecryptMegolmEvent decrypts an m.room.encrypted event where the algorithm is m.megolm.v1.aes-sha2
func (*OlmMachine) EncryptMegolmEvent ¶
func (mach *OlmMachine) EncryptMegolmEvent(ctx context.Context, roomID id.RoomID, evtType event.Type, content interface{}) (*event.EncryptedEventContent, error)
EncryptMegolmEvent encrypts data with the m.megolm.v1.aes-sha2 algorithm.
If you use the event.Content struct, make sure you pass a pointer to the struct, as JSON serialization will not work correctly otherwise.
func (*OlmMachine) ExpiredKeyDeleteLoop ¶
func (mach *OlmMachine) ExpiredKeyDeleteLoop(ctx context.Context)
func (*OlmMachine) ExportCrossSigningKeys ¶
func (mach *OlmMachine) ExportCrossSigningKeys() CrossSigningSeeds
func (*OlmMachine) FetchCrossSigningKeysFromSSSS ¶
func (mach *OlmMachine) FetchCrossSigningKeysFromSSSS(key *ssss.Key) error
FetchCrossSigningKeysFromSSSS fetches all the cross-signing keys from SSSS, decrypts them using the given key and stores them in the olm machine.
func (*OlmMachine) Fingerprint ¶
func (mach *OlmMachine) Fingerprint() string
Fingerprint returns the fingerprint of the Olm account that can be used for non-interactive verification.
func (*OlmMachine) FlushStore ¶
func (mach *OlmMachine) FlushStore() error
FlushStore calls the Flush method of the CryptoStore.
func (*OlmMachine) GenerateAndUploadCrossSigningKeys ¶
func (mach *OlmMachine) GenerateAndUploadCrossSigningKeys(userPassword, passphrase string) (string, error)
GenerateAndUploadCrossSigningKeys generates a new key with all corresponding cross-signing keys.
A passphrase can be provided to generate the SSSS key. If the passphrase is empty, a random key is used. The base58-formatted recovery key is the first return parameter.
The account password of the user is required for uploading keys to the server.
func (*OlmMachine) GenerateCrossSigningKeys ¶
func (mach *OlmMachine) GenerateCrossSigningKeys() (*CrossSigningKeysCache, error)
GenerateCrossSigningKeys generates new cross-signing keys.
func (*OlmMachine) GetAccount ¶
func (mach *OlmMachine) GetAccount() *OlmAccount
func (*OlmMachine) GetCrossSigningPublicKeys ¶
func (mach *OlmMachine) GetCrossSigningPublicKeys(userID id.UserID) (*CrossSigningPublicKeysCache, error)
func (*OlmMachine) GetOrFetchDevice ¶
func (mach *OlmMachine) GetOrFetchDevice(ctx context.Context, userID id.UserID, deviceID id.DeviceID) (*id.Device, error)
GetOrFetchDevice attempts to retrieve the device identity for the given device from the store and if it's not found it asks the server for it.
func (*OlmMachine) GetOrFetchDeviceByKey ¶
func (mach *OlmMachine) GetOrFetchDeviceByKey(ctx context.Context, userID id.UserID, identityKey id.IdentityKey) (*id.Device, error)
GetOrFetchDeviceByKey attempts to retrieve the device identity for the device with the given identity key from the store and if it's not found it asks the server for it. This returns nil if the server doesn't return a device with the given identity key.
func (*OlmMachine) GetOwnCrossSigningPublicKeys ¶
func (mach *OlmMachine) GetOwnCrossSigningPublicKeys() *CrossSigningPublicKeysCache
func (*OlmMachine) HandleDeviceLists ¶
func (mach *OlmMachine) HandleDeviceLists(dl *mautrix.DeviceLists, since string)
func (*OlmMachine) HandleMemberEvent ¶
func (mach *OlmMachine) HandleMemberEvent(_ mautrix.EventSource, evt *event.Event)
HandleMemberEvent handles a single membership event.
Currently this is not automatically called, so you must add a listener yourself:
client.Syncer.(mautrix.ExtensibleSyncer).OnEventType(event.StateMember, c.crypto.HandleMemberEvent)
func (*OlmMachine) HandleOTKCounts ¶
func (mach *OlmMachine) HandleOTKCounts(otkCount *mautrix.OTKCount)
func (*OlmMachine) HandleToDeviceEvent ¶
func (mach *OlmMachine) HandleToDeviceEvent(evt *event.Event)
HandleToDeviceEvent handles a single to-device event. This is automatically called by ProcessSyncResponse, so you don't need to add any custom handlers if you use that method.
func (*OlmMachine) ImportCrossSigningKeys ¶
func (mach *OlmMachine) ImportCrossSigningKeys(keys CrossSigningSeeds) (err error)
func (*OlmMachine) ImportKeys ¶
ImportKeys imports data that was exported with the format specified in the Matrix spec. See https://spec.matrix.org/v1.2/client-server-api/#key-exports
func (*OlmMachine) IsDeviceTrusted ¶
func (mach *OlmMachine) IsDeviceTrusted(device *id.Device) bool
IsDeviceTrusted returns whether a device has been determined to be trusted either through verification or cross-signing.
func (*OlmMachine) IsUserTrusted ¶
IsUserTrusted returns whether a user has been determined to be trusted by our user-signing key having signed their master key. In the case the user ID is our own and we have successfully retrieved our cross-signing keys, we trust our own user.
func (*OlmMachine) Load ¶
func (mach *OlmMachine) Load() (err error)
Load loads the Olm account information from the crypto store. If there's no olm account, a new one is created. This must be called before using the machine.
func (*OlmMachine) LoadDevices ¶
func (*OlmMachine) NewInRoomSASVerificationWith ¶
func (mach *OlmMachine) NewInRoomSASVerificationWith(inRoomID id.RoomID, userID id.UserID, hooks VerificationHooks, timeout time.Duration) (string, error)
NewInRoomSASVerificationWith starts the in-room SAS verification process with another user in the given room. It returns the generated transaction ID.
func (*OlmMachine) NewSASVerificationWith ¶
func (mach *OlmMachine) NewSASVerificationWith(device *id.Device, hooks VerificationHooks, transactionID string, timeout time.Duration) (string, error)
NewSASVerificationWith starts the SAS verification process with another device. If the other device accepts the verification transaction, the methods in `hooks` will be used to verify the SAS match and to complete the transaction.. If the transaction ID is empty, a new one is generated.
func (*OlmMachine) NewSimpleSASVerificationWith ¶
func (mach *OlmMachine) NewSimpleSASVerificationWith(device *id.Device, hooks VerificationHooks) (string, error)
NewSimpleSASVerificationWith starts the SAS verification process with another device with a default timeout, a generated transaction ID and support for both emoji and decimal SAS methods.
func (*OlmMachine) OnDevicesChanged ¶
func (mach *OlmMachine) OnDevicesChanged(userID id.UserID)
OnDevicesChanged finds all shared rooms with the given user and invalidates outbound sessions in those rooms.
This is called automatically whenever a device list change is noticed in ProcessSyncResponse and usually does not need to be called manually.
func (*OlmMachine) OwnIdentity ¶
func (mach *OlmMachine) OwnIdentity() *id.Device
OwnIdentity returns this device's id.Device struct
func (*OlmMachine) ProcessInRoomVerification ¶
func (mach *OlmMachine) ProcessInRoomVerification(evt *event.Event) error
ProcessInRoomVerification is a callback that is to be called when a client receives a message related to in-room verification.
Currently this is not automatically called, so you must add the listener yourself. Note that in-room verification events are wrapped in m.room.encrypted, but this expects the decrypted events.
func (*OlmMachine) ProcessSyncResponse ¶
func (mach *OlmMachine) ProcessSyncResponse(resp *mautrix.RespSync, since string) bool
ProcessSyncResponse processes a single /sync response.
This can be easily registered into a mautrix client using .OnSync():
client.Syncer.(mautrix.ExtensibleSyncer).OnSync(c.crypto.ProcessSyncResponse)
func (*OlmMachine) PublishCrossSigningKeys ¶
func (mach *OlmMachine) PublishCrossSigningKeys(keys *CrossSigningKeysCache, uiaCallback mautrix.UIACallback) error
PublishCrossSigningKeys signs and uploads the public keys of the given cross-signing keys to the server.
func (*OlmMachine) RequestRoomKey
deprecated
func (mach *OlmMachine) RequestRoomKey(ctx context.Context, toUser id.UserID, toDevice id.DeviceID, roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (chan bool, error)
RequestRoomKey sends a key request for a room to the current user's devices. If the context is cancelled, then so is the key request. Returns a bool channel that will get notified either when the key is received or the request is cancelled.
Deprecated: this only supports a single key request target, so the whole automatic cancelling feature isn't very useful.
func (*OlmMachine) ResolveTrust ¶
func (mach *OlmMachine) ResolveTrust(device *id.Device) id.TrustState
func (*OlmMachine) ResolveTrustContext ¶
func (mach *OlmMachine) ResolveTrustContext(ctx context.Context, device *id.Device) (id.TrustState, error)
ResolveTrustContext resolves the trust state of the device from cross-signing.
func (*OlmMachine) SendEncryptedToDevice ¶
func (mach *OlmMachine) SendEncryptedToDevice(ctx context.Context, device *id.Device, evtType event.Type, content event.Content) error
SendEncryptedToDevice sends an Olm-encrypted event to the given user device.
func (*OlmMachine) SendInRoomSASVerificationAccept ¶
func (mach *OlmMachine) SendInRoomSASVerificationAccept(roomID id.RoomID, fromUser id.UserID, startEvent *event.VerificationStartEventContent, transactionID string, publicKey []byte, methods []VerificationMethod) error
SendInRoomSASVerificationAccept is used to manually send an accept for an in-room SAS verification process from a received m.key.verification.start event.
func (*OlmMachine) SendInRoomSASVerificationCancel ¶
func (mach *OlmMachine) SendInRoomSASVerificationCancel(roomID id.RoomID, userID id.UserID, transactionID string, reason string, code event.VerificationCancelCode) error
SendInRoomSASVerificationCancel is used to manually send an in-room SAS cancel message process with the given reason and cancellation code.
func (*OlmMachine) SendInRoomSASVerificationKey ¶
func (mach *OlmMachine) SendInRoomSASVerificationKey(roomID id.RoomID, userID id.UserID, transactionID string, key string) error
SendInRoomSASVerificationKey sends the ephemeral public key for a device to the partner device for an in-room verification.
func (*OlmMachine) SendInRoomSASVerificationMAC ¶
func (mach *OlmMachine) SendInRoomSASVerificationMAC(roomID id.RoomID, userID id.UserID, deviceID id.DeviceID, transactionID string, sas *olm.SAS) error
SendInRoomSASVerificationMAC sends the MAC of a device's key to the partner device for an in-room verification.
func (*OlmMachine) SendInRoomSASVerificationReady ¶
func (mach *OlmMachine) SendInRoomSASVerificationReady(roomID id.RoomID, transactionID string) error
SendInRoomSASVerificationReady is used to manually send an in-room SAS verification ready message to another user.
func (*OlmMachine) SendInRoomSASVerificationRequest ¶
func (mach *OlmMachine) SendInRoomSASVerificationRequest(roomID id.RoomID, toUserID id.UserID, methods []VerificationMethod) (string, error)
SendInRoomSASVerificationRequest is used to manually send an in-room SAS verification request message to another user.
func (*OlmMachine) SendInRoomSASVerificationStart ¶
func (mach *OlmMachine) SendInRoomSASVerificationStart(roomID id.RoomID, toUserID id.UserID, transactionID string, methods []VerificationMethod) (*event.VerificationStartEventContent, error)
SendInRoomSASVerificationStart is used to manually send the in-room SAS verification start message to another user.
func (*OlmMachine) SendRoomKeyRequest ¶
func (mach *OlmMachine) SendRoomKeyRequest(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, requestID string, users map[id.UserID][]id.DeviceID) error
SendRoomKeyRequest sends a key request for the given key (identified by the room ID, sender key and session ID) to the given users.
The request ID parameter is optional. If it's empty, a random ID will be generated.
This function does not wait for the keys to arrive. You can use WaitForSession to wait for the session to arrive (in any way, not just as a reply to this request). There's also RequestRoomKey which waits for a response to the specific key request, but currently it only supports a single target device and is therefore deprecated. A future function may properly support multiple targets and automatically canceling the other requests when receiving the first response.
func (*OlmMachine) SendSASVerificationAccept ¶
func (mach *OlmMachine) SendSASVerificationAccept(fromUser id.UserID, startEvent *event.VerificationStartEventContent, publicKey []byte, methods []VerificationMethod) error
SendSASVerificationAccept is used to manually send an accept for a SAS verification process from a received m.key.verification.start event.
func (*OlmMachine) SendSASVerificationCancel ¶
func (mach *OlmMachine) SendSASVerificationCancel(userID id.UserID, deviceID id.DeviceID, transactionID string, reason string, code event.VerificationCancelCode) error
SendSASVerificationCancel is used to manually send a SAS cancel message process with the given reason and cancellation code.
func (*OlmMachine) SendSASVerificationKey ¶
func (mach *OlmMachine) SendSASVerificationKey(userID id.UserID, deviceID id.DeviceID, transactionID string, key string) error
SendSASVerificationKey sends the ephemeral public key for a device to the partner device.
func (*OlmMachine) SendSASVerificationMAC ¶
func (mach *OlmMachine) SendSASVerificationMAC(userID id.UserID, deviceID id.DeviceID, transactionID string, sas *olm.SAS) error
SendSASVerificationMAC is use the MAC of a device's key to the partner device.
func (*OlmMachine) SendSASVerificationStart ¶
func (mach *OlmMachine) SendSASVerificationStart(toUserID id.UserID, toDeviceID id.DeviceID, transactionID string, methods []VerificationMethod) (*event.VerificationStartEventContent, error)
SendSASVerificationStart is used to manually send the SAS verification start message to another device.
func (*OlmMachine) ShareGroupSession ¶
func (mach *OlmMachine) ShareGroupSession(ctx context.Context, roomID id.RoomID, users []id.UserID) error
ShareGroupSession shares a group session for a specific room with all the devices of the given user list.
For devices with TrustStateBlacklisted, a m.room_key.withheld event with code=m.blacklisted is sent. If AllowUnverifiedDevices is false, a similar event with code=m.unverified is sent to devices with TrustStateUnset
func (*OlmMachine) ShareKeys ¶
func (mach *OlmMachine) ShareKeys(ctx context.Context, currentOTKCount int) error
ShareKeys uploads necessary keys to the server.
If the Olm account hasn't been shared, the account keys will be uploaded. If currentOTKCount is less than half of the limit (100 / 2 = 50), enough one-time keys will be uploaded so exactly half of the limit is filled.
func (*OlmMachine) SignOwnDevice ¶
func (mach *OlmMachine) SignOwnDevice(device *id.Device) error
SignOwnDevice creates a cross-signing signature for a device belonging to the current user and uploads it to the server.
func (*OlmMachine) SignOwnMasterKey ¶
func (mach *OlmMachine) SignOwnMasterKey() error
SignOwnMasterKey uses the current account for signing the current user's master key and uploads the signature.
func (*OlmMachine) SignUser ¶
SignUser creates a cross-signing signature for a user, stores it and uploads it to the server.
func (*OlmMachine) UploadCrossSigningKeysToSSSS ¶
func (mach *OlmMachine) UploadCrossSigningKeysToSSSS(key *ssss.Key, keys *CrossSigningKeysCache) error
UploadCrossSigningKeysToSSSS stores the given cross-signing keys on the server encrypted with the given key.
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) Describe ¶
func (session *OlmSession) Describe() string
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 so that the session with recent successful decryptions comes 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 // contains filtered or unexported fields }
func NewOutboundGroupSession ¶
func NewOutboundGroupSession(roomID id.RoomID, encryptionContent *event.EncryptionEventContent) *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 RatchetSafety ¶
type SQLCryptoStore ¶
type SQLCryptoStore struct { DB *dbutil.Database AccountID string DeviceID id.DeviceID SyncToken string PickleKey []byte Account *OlmAccount // contains filtered or unexported fields }
SQLCryptoStore is an implementation of a crypto Store for a database backend.
func NewSQLCryptoStore ¶
func NewSQLCryptoStore(db *dbutil.Database, log dbutil.DatabaseLogger, accountID string, deviceID id.DeviceID, pickleKey []byte) *SQLCryptoStore
NewSQLCryptoStore initializes a new crypto Store using the given database, for a device's crypto material. The stored material will be encrypted with the given key.
func (*SQLCryptoStore) AddOutboundGroupSession ¶
func (store *SQLCryptoStore) AddOutboundGroupSession(session *OutboundGroupSession) error
AddOutboundGroupSession stores an outbound Megolm session, along with the information about the room and involved devices.
func (*SQLCryptoStore) AddSession ¶
func (store *SQLCryptoStore) AddSession(key id.SenderKey, session *OlmSession) error
AddSession persists an Olm session for a sender in the database.
func (*SQLCryptoStore) DropSignaturesByKey ¶
DropSignaturesByKey deletes the signatures made by the given user and key from the store. It returns the number of signatures deleted.
func (*SQLCryptoStore) FilterTrackedUsers ¶
FilterTrackedUsers finds all the user IDs out of the given ones for which the database contains identity information.
func (*SQLCryptoStore) FindDeviceByKey ¶
func (store *SQLCryptoStore) FindDeviceByKey(userID id.UserID, identityKey id.IdentityKey) (*id.Device, error)
FindDeviceByKey finds a specific device by its sender key.
func (*SQLCryptoStore) FindDeviceID ¶
func (store *SQLCryptoStore) FindDeviceID() (deviceID id.DeviceID)
func (*SQLCryptoStore) Flush ¶
func (store *SQLCryptoStore) Flush() error
Flush does nothing for this implementation as data is already persisted in the database.
func (*SQLCryptoStore) GetAccount ¶
func (store *SQLCryptoStore) GetAccount() (*OlmAccount, error)
GetAccount retrieves an OlmAccount from the database.
func (*SQLCryptoStore) GetAllGroupSessions ¶
func (store *SQLCryptoStore) GetAllGroupSessions() ([]*InboundGroupSession, error)
func (*SQLCryptoStore) GetCrossSigningKeys ¶
func (store *SQLCryptoStore) GetCrossSigningKeys(userID id.UserID) (map[id.CrossSigningUsage]id.CrossSigningKey, error)
GetCrossSigningKeys retrieves a user's stored cross-signing keys.
func (*SQLCryptoStore) GetDevice ¶
GetDevice returns the device dentity for a given user and device ID.
func (*SQLCryptoStore) GetDevices ¶
GetDevices returns a map of device IDs to device identities, including the identity and signing keys, for a given user ID.
func (*SQLCryptoStore) GetGroupSession ¶
func (store *SQLCryptoStore) GetGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (*InboundGroupSession, error)
GetGroupSession retrieves an inbound Megolm group session for a room, sender and session.
func (*SQLCryptoStore) GetGroupSessionsForRoom ¶
func (store *SQLCryptoStore) GetGroupSessionsForRoom(roomID id.RoomID) ([]*InboundGroupSession, error)
func (*SQLCryptoStore) GetLatestSession ¶
func (store *SQLCryptoStore) GetLatestSession(key id.SenderKey) (*OlmSession, error)
GetLatestSession retrieves the Olm session for a given sender key from the database that has the largest ID.
func (*SQLCryptoStore) GetNextBatch ¶
func (store *SQLCryptoStore) GetNextBatch() (string, error)
GetNextBatch retrieves the next sync batch token for the current account.
func (*SQLCryptoStore) GetOutboundGroupSession ¶
func (store *SQLCryptoStore) GetOutboundGroupSession(roomID id.RoomID) (*OutboundGroupSession, error)
GetOutboundGroupSession retrieves the outbound Megolm session for the given room ID.
func (*SQLCryptoStore) GetSessions ¶
func (store *SQLCryptoStore) GetSessions(key id.SenderKey) (OlmSessionList, error)
GetSessions returns all the known Olm sessions for a sender key.
func (*SQLCryptoStore) GetSignaturesForKeyBy ¶
func (store *SQLCryptoStore) GetSignaturesForKeyBy(userID id.UserID, key id.Ed25519, signerID id.UserID) (map[id.Ed25519]string, error)
GetSignaturesForKeyBy retrieves the stored signatures for a given cross-signing or device key, by the given signer.
func (*SQLCryptoStore) GetWithheldGroupSession ¶
func (store *SQLCryptoStore) GetWithheldGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (*event.RoomKeyWithheldEventContent, error)
func (*SQLCryptoStore) HasSession ¶
func (store *SQLCryptoStore) HasSession(key id.SenderKey) bool
HasSession returns whether there is an Olm session for the given sender key.
func (*SQLCryptoStore) IsKeySignedBy ¶
func (store *SQLCryptoStore) IsKeySignedBy(signedUserID id.UserID, signedKey id.Ed25519, signerUserID id.UserID, signerKey id.Ed25519) (isSigned bool, err error)
IsKeySignedBy returns whether a cross-signing or device key is signed by the given signer.
func (*SQLCryptoStore) LoadFilterID ¶
func (store *SQLCryptoStore) LoadFilterID(_ id.UserID) string
func (*SQLCryptoStore) LoadNextBatch ¶
func (store *SQLCryptoStore) LoadNextBatch(_ id.UserID) string
func (*SQLCryptoStore) PutAccount ¶
func (store *SQLCryptoStore) PutAccount(account *OlmAccount) error
PutAccount stores an OlmAccount in the database.
func (*SQLCryptoStore) PutCrossSigningKey ¶
func (store *SQLCryptoStore) PutCrossSigningKey(userID id.UserID, usage id.CrossSigningUsage, key id.Ed25519) error
PutCrossSigningKey stores a cross-signing key of some user along with its usage.
func (*SQLCryptoStore) PutDevice ¶
PutDevice stores a single device for a user, replacing it if it exists already.
func (*SQLCryptoStore) PutDevices ¶
PutDevices stores the device identity information for the given user ID.
func (*SQLCryptoStore) PutGroupSession ¶
func (store *SQLCryptoStore) PutGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, session *InboundGroupSession) error
PutGroupSession stores an inbound Megolm group session for a room, sender and session.
func (*SQLCryptoStore) PutNextBatch ¶
func (store *SQLCryptoStore) PutNextBatch(nextBatch string) error
PutNextBatch stores the next sync batch token for the current account.
func (*SQLCryptoStore) PutSignature ¶
func (store *SQLCryptoStore) PutSignature(signedUserID id.UserID, signedKey id.Ed25519, signerUserID id.UserID, signerKey id.Ed25519, signature string) error
PutSignature stores a signature of a cross-signing or device key along with the signer's user ID and key.
func (*SQLCryptoStore) PutWithheldGroupSession ¶
func (store *SQLCryptoStore) PutWithheldGroupSession(content event.RoomKeyWithheldEventContent) error
func (*SQLCryptoStore) RedactExpiredGroupSessions ¶
func (store *SQLCryptoStore) RedactExpiredGroupSessions() ([]id.SessionID, error)
func (*SQLCryptoStore) RedactGroupSession ¶
func (*SQLCryptoStore) RedactGroupSessions ¶
func (*SQLCryptoStore) RedactOutdatedGroupSessions ¶
func (store *SQLCryptoStore) RedactOutdatedGroupSessions() ([]id.SessionID, error)
func (*SQLCryptoStore) RemoveOutboundGroupSession ¶
func (store *SQLCryptoStore) RemoveOutboundGroupSession(roomID id.RoomID) error
RemoveOutboundGroupSession removes the outbound Megolm session for the given room ID.
func (*SQLCryptoStore) SaveFilterID ¶
func (store *SQLCryptoStore) SaveFilterID(_ id.UserID, _ string)
func (*SQLCryptoStore) SaveNextBatch ¶
func (store *SQLCryptoStore) SaveNextBatch(_ id.UserID, nextBatchToken string)
func (*SQLCryptoStore) UpdateOutboundGroupSession ¶
func (store *SQLCryptoStore) UpdateOutboundGroupSession(session *OutboundGroupSession) error
UpdateOutboundGroupSession replaces an outbound Megolm session with for same room and session ID.
func (*SQLCryptoStore) UpdateSession ¶
func (store *SQLCryptoStore) UpdateSession(_ id.SenderKey, session *OlmSession) error
UpdateSession replaces the Olm session for a sender in the database.
func (*SQLCryptoStore) ValidateMessageIndex ¶
func (store *SQLCryptoStore) ValidateMessageIndex(ctx context.Context, senderKey id.SenderKey, sessionID id.SessionID, eventID id.EventID, index uint, timestamp int64) (bool, error)
ValidateMessageIndex returns whether the given event information match the ones stored in the database for the given sender key, session ID and index. If the index hasn't been stored, this will store it.
type SenderClaimedKeys ¶
type StateStore ¶
type StateStore interface { // IsEncrypted returns whether a room is encrypted. IsEncrypted(id.RoomID) bool // GetEncryptionEvent returns the encryption event's content for an encrypted room. GetEncryptionEvent(id.RoomID) *event.EncryptionEventContent FindSharedRooms(id.UserID) []id.RoomID }
StateStore is used by OlmMachine to get room state information that's needed for encryption.
type Store ¶
type Store interface { // Flush ensures that everything in the store is persisted to disk. // This doesn't have to do anything, e.g. for database-backed implementations that persist everything immediately. Flush() error // PutAccount updates the OlmAccount in the store. PutAccount(*OlmAccount) error // GetAccount returns the OlmAccount in the store that was previously inserted with PutAccount. GetAccount() (*OlmAccount, error) // AddSession inserts an Olm session into the store. AddSession(id.SenderKey, *OlmSession) error // HasSession returns whether or not the store has an Olm session with the given sender key. HasSession(id.SenderKey) bool // GetSessions returns all Olm sessions in the store with the given sender key. GetSessions(id.SenderKey) (OlmSessionList, error) // GetLatestSession returns the session with the highest session ID (lexiographically sorting). // It's usually safe to return the most recently added session if sorting by session ID is too difficult. GetLatestSession(id.SenderKey) (*OlmSession, error) // UpdateSession updates a session that has previously been inserted with AddSession. UpdateSession(id.SenderKey, *OlmSession) error // PutGroupSession inserts an inbound Megolm session into the store. If an earlier withhold event has been inserted // with PutWithheldGroupSession, this call should replace that. However, PutWithheldGroupSession must not replace // sessions inserted with this call. PutGroupSession(id.RoomID, id.SenderKey, id.SessionID, *InboundGroupSession) error // GetGroupSession gets an inbound Megolm session from the store. If the group session has been withheld // (i.e. a room key withheld event has been saved with PutWithheldGroupSession), this should return the // ErrGroupSessionWithheld error. The caller may use GetWithheldGroupSession to find more details. GetGroupSession(id.RoomID, id.SenderKey, id.SessionID) (*InboundGroupSession, error) // RedactGroupSession removes the session data for the given inbound Megolm session from the store. RedactGroupSession(id.RoomID, id.SenderKey, id.SessionID, string) error // RedactGroupSessions removes the session data for all inbound Megolm sessions from a specific device and/or in a specific room. RedactGroupSessions(id.RoomID, id.SenderKey, string) ([]id.SessionID, error) // RedactExpiredGroupSessions removes the session data for all inbound Megolm sessions that have expired. RedactExpiredGroupSessions() ([]id.SessionID, error) // RedactOutdatedGroupSessions removes the session data for all inbound Megolm sessions that are lacking the expiration metadata. RedactOutdatedGroupSessions() ([]id.SessionID, error) // PutWithheldGroupSession tells the store that a specific Megolm session was withheld. PutWithheldGroupSession(event.RoomKeyWithheldEventContent) error // GetWithheldGroupSession gets the event content that was previously inserted with PutWithheldGroupSession. GetWithheldGroupSession(id.RoomID, id.SenderKey, id.SessionID) (*event.RoomKeyWithheldEventContent, error) // GetGroupSessionsForRoom gets all the inbound Megolm sessions for a specific room. This is used for creating key // export files. Unlike GetGroupSession, this should not return any errors about withheld keys. GetGroupSessionsForRoom(id.RoomID) ([]*InboundGroupSession, error) // GetAllGroupSessions gets all the inbound Megolm sessions in the store. This is used for creating key export // files. Unlike GetGroupSession, this should not return any errors about withheld keys. GetAllGroupSessions() ([]*InboundGroupSession, error) // AddOutboundGroupSession inserts the given outbound Megolm session into the store. // // The store should index inserted sessions by the RoomID field to support getting and removing sessions. // There will only be one outbound session per room ID at a time. AddOutboundGroupSession(*OutboundGroupSession) error // UpdateOutboundGroupSession updates the given outbound Megolm session in the store. UpdateOutboundGroupSession(*OutboundGroupSession) error // GetOutboundGroupSession gets the stored outbound Megolm session for the given room ID from the store. GetOutboundGroupSession(id.RoomID) (*OutboundGroupSession, error) // RemoveOutboundGroupSession removes the stored outbound Megolm session for the given room ID. RemoveOutboundGroupSession(id.RoomID) error // ValidateMessageIndex validates that the given message details aren't from a replay attack. // // Implementations should store a map from (senderKey, sessionID, index) to (eventID, timestamp), then use that map // to check whether or not the message index is valid: // // * If the map key doesn't exist, the given values should be stored and this should return true. // * If the map key exists and the stored values match the given values, this should return true. // * If the map key exists, but the stored values do not match the given values, this should return false. ValidateMessageIndex(ctx context.Context, senderKey id.SenderKey, sessionID id.SessionID, eventID id.EventID, index uint, timestamp int64) (bool, error) // GetDevices returns a map from device ID to id.Device struct containing all devices of a given user. GetDevices(id.UserID) (map[id.DeviceID]*id.Device, error) // GetDevice returns a specific device of a given user. GetDevice(id.UserID, id.DeviceID) (*id.Device, error) // PutDevice stores a single device for a user, replacing it if it exists already. PutDevice(id.UserID, *id.Device) error // PutDevices overrides the stored device list for the given user with the given list. PutDevices(id.UserID, map[id.DeviceID]*id.Device) error // FindDeviceByKey finds a specific device by its identity key. FindDeviceByKey(id.UserID, id.IdentityKey) (*id.Device, error) // FilterTrackedUsers returns a filtered version of the given list that only includes user IDs whose device lists // have been stored with PutDevices. A user is considered tracked even if the PutDevices list was empty. FilterTrackedUsers([]id.UserID) ([]id.UserID, error) // PutCrossSigningKey stores a cross-signing key of some user along with its usage. PutCrossSigningKey(id.UserID, id.CrossSigningUsage, id.Ed25519) error // GetCrossSigningKeys retrieves a user's stored cross-signing keys. GetCrossSigningKeys(id.UserID) (map[id.CrossSigningUsage]id.CrossSigningKey, error) // PutSignature stores a signature of a cross-signing or device key along with the signer's user ID and key. PutSignature(signedUser id.UserID, signedKey id.Ed25519, signerUser id.UserID, signerKey id.Ed25519, signature string) error // IsKeySignedBy returns whether a cross-signing or device key is signed by the given signer. IsKeySignedBy(userID id.UserID, key id.Ed25519, signedByUser id.UserID, signedByKey id.Ed25519) (bool, error) // DropSignaturesByKey deletes the signatures made by the given user and key from the store. It returns the number of signatures deleted. DropSignaturesByKey(id.UserID, id.Ed25519) (int64, error) }
Store is used by OlmMachine to store Olm and Megolm sessions, user device lists and message indices.
General implementation details: * Get methods should not return errors if the requested data does not exist in the store, they should simply return nil. * Update methods may assume that the pointer is the same as what has earlier been added to or fetched from the store.
type VerificationEmoji ¶
VerificationEmoji describes an emoji that might be sent for verifying devices.
func (VerificationEmoji) GetDescription ¶
func (vm VerificationEmoji) GetDescription() string
func (VerificationEmoji) GetEmoji ¶
func (vm VerificationEmoji) GetEmoji() rune
type VerificationHooks ¶
type VerificationHooks interface { // VerifySASMatch receives the generated SAS and its method, as well as the device that is being verified. // It returns whether the given SAS match with the SAS displayed on other device. VerifySASMatch(otherDevice *id.Device, sas SASData) bool // VerificationMethods returns the list of supported verification methods in order of preference. // It must contain at least the decimal method. VerificationMethods() []VerificationMethod OnCancel(cancelledByUs bool, reason string, reasonCode event.VerificationCancelCode) OnSuccess() }
type VerificationMethod ¶
type VerificationMethod interface { // GetVerificationSAS uses the user, device ID and key of the user who initiated the verification transaction, // the user, device ID and key of the user who accepted, the transaction ID and the SAS object to generate a SAS. // The SAS can be any type, such as an array of numbers or emojis. GetVerificationSAS(initUserID id.UserID, initDeviceID id.DeviceID, initKey string, acceptUserID id.UserID, acceptDeviceID id.DeviceID, acceptKey string, transactionID string, sas *olm.SAS) (SASData, error) // Type returns the type of this SAS method Type() event.SASMethod }
VerificationMethod describes a method for generating a SAS.
type VerificationMethodDecimal ¶
type VerificationMethodDecimal struct{}
VerificationMethodDecimal describes the decimal SAS method.
func (VerificationMethodDecimal) GetVerificationSAS ¶
func (VerificationMethodDecimal) GetVerificationSAS(initUserID id.UserID, initDeviceID id.DeviceID, initKey string, acceptUserID id.UserID, acceptDeviceID id.DeviceID, acceptKey string, transactionID string, sas *olm.SAS) (SASData, error)
GetVerificationSAS generates the three numbers that need to match with the other device for a verification to be valid.
func (VerificationMethodDecimal) Type ¶
func (VerificationMethodDecimal) Type() event.SASMethod
Type returns the decimal SAS method type.
type VerificationMethodEmoji ¶
type VerificationMethodEmoji struct{}
VerificationMethodEmoji describes the emoji SAS method.
func (VerificationMethodEmoji) GetVerificationSAS ¶
func (VerificationMethodEmoji) GetVerificationSAS(initUserID id.UserID, initDeviceID id.DeviceID, initKey string, acceptUserID id.UserID, acceptDeviceID id.DeviceID, acceptKey string, transactionID string, sas *olm.SAS) (SASData, error)
GetVerificationSAS generates the three numbers that need to match with the other device for a verification to be valid.
func (VerificationMethodEmoji) Type ¶
func (VerificationMethodEmoji) Type() event.SASMethod
Type returns the emoji SAS method type.
type VerificationRequestResponse ¶
type VerificationRequestResponse int
const ( AcceptRequest VerificationRequestResponse = iota RejectRequest IgnoreRequest )
Source Files ¶
- account.go
- cross_sign_key.go
- cross_sign_pubkey.go
- cross_sign_signing.go
- cross_sign_ssss.go
- cross_sign_store.go
- cross_sign_validation.go
- decryptmegolm.go
- decryptolm.go
- devicelist.go
- encryptmegolm.go
- encryptolm.go
- keyexport.go
- keyimport.go
- keysharing.go
- machine.go
- sessions.go
- sql_store.go
- store.go
- verification.go
- verification_in_room.go
- verification_sas_methods.go