Skip to content

Commit

Permalink
crypto: make OTK count for other user log less noisy
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 14, 2024
1 parent d86913b commit 6f9927c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions crypto/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ type OlmMachine struct {
megolmEncryptLock sync.Mutex
megolmDecryptLock sync.Mutex

otkUploadLock sync.Mutex
lastOTKUpload time.Time
otkUploadLock sync.Mutex
lastOTKUpload time.Time
receivedOTKsForSelf bool

CrossSigningKeys *CrossSigningKeysCache
crossSigningPubkeys *CrossSigningPublicKeysCache
Expand Down Expand Up @@ -258,16 +259,15 @@ func (mach *OlmMachine) otkCountIsForCrossSigningKey(otkCount *mautrix.OTKCount)

func (mach *OlmMachine) HandleOTKCounts(ctx context.Context, otkCount *mautrix.OTKCount) {
if (len(otkCount.UserID) > 0 && otkCount.UserID != mach.Client.UserID) || (len(otkCount.DeviceID) > 0 && otkCount.DeviceID != mach.Client.DeviceID) {
if mach.otkCountIsForCrossSigningKey(otkCount) {
return
if otkCount.UserID != mach.Client.UserID || (!mach.receivedOTKsForSelf && !mach.otkCountIsForCrossSigningKey(otkCount)) {
mach.Log.Warn().
Str("target_user_id", otkCount.UserID.String()).
Str("target_device_id", otkCount.DeviceID.String()).
Msg("Dropping OTK counts targeted to someone else")
}
// TODO This log probably needs to be silence-able if someone wants to use encrypted appservices with multiple e2ee sessions
mach.Log.Warn().
Str("target_user_id", otkCount.UserID.String()).
Str("target_device_id", otkCount.DeviceID.String()).
Msg("Dropping OTK counts targeted to someone else")
return
}
mach.receivedOTKsForSelf = true

minCount := mach.account.Internal.MaxNumberOfOneTimeKeys() / 2
if otkCount.SignedCurve25519 < int(minCount) {
Expand Down

0 comments on commit 6f9927c

Please sign in to comment.