Skip to content

Commit

Permalink
Drop OTK counts intended for other devices
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 24, 2021
1 parent be2dee6 commit 02f00b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions crypto/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ func (mach *OlmMachine) HandleDeviceLists(dl *mautrix.DeviceLists, since string)
}

func (mach *OlmMachine) HandleOTKCounts(otkCount *mautrix.OTKCount) {
if (len(otkCount.UserID) > 0 && otkCount.UserID != mach.Client.UserID) || (len(otkCount.DeviceID) > 0 && otkCount.DeviceID != mach.Client.DeviceID) {
// TODO This log probably needs to be silence-able if someone wants to use encrypted appservices with multiple e2ee sessions
mach.Log.Debug("Dropping OTK counts targeted to %s/%s (not us)", otkCount.UserID, otkCount.DeviceID)
return
}

minCount := mach.account.Internal.MaxNumberOfOneTimeKeys() / 2
if otkCount.SignedCurve25519 < int(minCount) {
mach.Log.Debug("Sync response said we have %d signed curve25519 keys left, sharing new ones...", otkCount.SignedCurve25519)
Expand Down
3 changes: 2 additions & 1 deletion responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ type OTKCount struct {
SignedCurve25519 int `json:"signed_curve25519"`

// For appservice OTK counts only: the user ID in question
UserID id.UserID `json:"-"`
UserID id.UserID `json:"-"`
DeviceID id.DeviceID `json:"-"`
}

type SyncLeftRoom struct {
Expand Down

0 comments on commit 02f00b9

Please sign in to comment.