mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
crypto: log destination map when sharing megolm sessions
Some checks failed
Some checks failed
This commit is contained in:
parent
98c830181b
commit
dd51c562ab
3 changed files with 18 additions and 16 deletions
|
|
@ -134,6 +134,9 @@ func (mach *OlmMachine) decryptAndParseOlmCiphertext(ctx context.Context, evt *e
|
|||
}
|
||||
|
||||
func olmMessageHash(ciphertext string) ([32]byte, error) {
|
||||
if ciphertext == "" {
|
||||
return [32]byte{}, fmt.Errorf("empty ciphertext")
|
||||
}
|
||||
ciphertextBytes, err := base64.RawStdEncoding.DecodeString(ciphertext)
|
||||
return sha256.Sum256(ciphertextBytes), err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -370,26 +370,19 @@ func (mach *OlmMachine) encryptAndSendGroupSession(ctx context.Context, session
|
|||
log.Trace().Msg("Encrypting group session for all found devices")
|
||||
deviceCount := 0
|
||||
toDevice := &mautrix.ReqSendToDevice{Messages: make(map[id.UserID]map[id.DeviceID]*event.Content)}
|
||||
logUsers := zerolog.Dict()
|
||||
for userID, sessions := range olmSessions {
|
||||
if len(sessions) == 0 {
|
||||
continue
|
||||
}
|
||||
logDevices := zerolog.Dict()
|
||||
output := make(map[id.DeviceID]*event.Content)
|
||||
toDevice.Messages[userID] = output
|
||||
for deviceID, device := range sessions {
|
||||
log.Trace().
|
||||
Stringer("target_user_id", userID).
|
||||
Stringer("target_device_id", deviceID).
|
||||
Stringer("target_identity_key", device.identity.IdentityKey).
|
||||
Msg("Encrypting group session for device")
|
||||
content := mach.encryptOlmEvent(ctx, device.session, device.identity, event.ToDeviceRoomKey, session.ShareContent())
|
||||
output[deviceID] = &event.Content{Parsed: content}
|
||||
logDevices.Str(string(deviceID), string(device.identity.IdentityKey))
|
||||
deviceCount++
|
||||
log.Debug().
|
||||
Stringer("target_user_id", userID).
|
||||
Stringer("target_device_id", deviceID).
|
||||
Stringer("target_identity_key", device.identity.IdentityKey).
|
||||
Msg("Encrypted group session for device")
|
||||
if !mach.DisableSharedGroupSessionTracking {
|
||||
err := mach.CryptoStore.MarkOutboundGroupSessionShared(ctx, userID, device.identity.IdentityKey, session.id)
|
||||
if err != nil {
|
||||
|
|
@ -403,11 +396,13 @@ func (mach *OlmMachine) encryptAndSendGroupSession(ctx context.Context, session
|
|||
}
|
||||
}
|
||||
}
|
||||
logUsers.Dict(string(userID), logDevices)
|
||||
}
|
||||
|
||||
log.Debug().
|
||||
Int("device_count", deviceCount).
|
||||
Int("user_count", len(toDevice.Messages)).
|
||||
Dict("destination_map", logUsers).
|
||||
Msg("Sending to-device messages to share group session")
|
||||
_, err := mach.Client.SendToDevice(ctx, event.ToDeviceEncrypted, toDevice)
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -96,15 +96,19 @@ func (mach *OlmMachine) encryptOlmEvent(ctx context.Context, session *OlmSession
|
|||
panic(err)
|
||||
}
|
||||
log := mach.machOrContextLog(ctx)
|
||||
log.Debug().
|
||||
Str("recipient_identity_key", recipient.IdentityKey.String()).
|
||||
Str("olm_session_id", session.ID().String()).
|
||||
Str("olm_session_description", session.Describe()).
|
||||
Msg("Encrypting olm message")
|
||||
msgType, ciphertext, err := session.Encrypt(plaintext)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ciphertextStr := string(ciphertext)
|
||||
ciphertextHash, _ := olmMessageHash(ciphertextStr)
|
||||
log.Debug().
|
||||
Stringer("event_type", evtType).
|
||||
Str("recipient_identity_key", recipient.IdentityKey.String()).
|
||||
Str("olm_session_id", session.ID().String()).
|
||||
Str("olm_session_description", session.Describe()).
|
||||
Hex("ciphertext_hash", ciphertextHash[:]).
|
||||
Msg("Encrypted olm message")
|
||||
err = mach.CryptoStore.UpdateSession(ctx, recipient.IdentityKey, session)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to update olm session in crypto store after encrypting")
|
||||
|
|
@ -115,7 +119,7 @@ func (mach *OlmMachine) encryptOlmEvent(ctx context.Context, session *OlmSession
|
|||
OlmCiphertext: event.OlmCiphertexts{
|
||||
recipient.IdentityKey: {
|
||||
Type: msgType,
|
||||
Body: string(ciphertext),
|
||||
Body: ciphertextStr,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue