mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Log olm session descriptions
This commit is contained in:
parent
e7b839dbb3
commit
6f77a6785b
4 changed files with 24 additions and 1 deletions
|
|
@ -132,7 +132,7 @@ func (mach *OlmMachine) tryDecryptOlmCiphertext(sender id.UserID, senderKey id.S
|
|||
go mach.unwedgeDevice(sender, senderKey)
|
||||
return nil, fmt.Errorf("failed to create new session from prekey message: %w", err)
|
||||
}
|
||||
mach.Log.Debug("Created inbound olm session %s for %s/%s", session.ID(), sender, senderKey)
|
||||
mach.Log.Debug("Created inbound olm session %s for %s/%s: %s", session.ID(), sender, senderKey, session.Describe())
|
||||
|
||||
plaintext, err = session.Decrypt(ciphertext, olmType)
|
||||
if err != nil {
|
||||
|
|
@ -151,6 +151,7 @@ func (mach *OlmMachine) tryDecryptOlmCiphertextWithExistingSession(senderKey id.
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get session for %s: %w", senderKey, err)
|
||||
}
|
||||
|
||||
for _, session := range sessions {
|
||||
if olmType == id.OlmMsgTypePreKey {
|
||||
matches, err := session.Internal.MatchesInboundSession(ciphertext)
|
||||
|
|
@ -160,6 +161,7 @@ func (mach *OlmMachine) tryDecryptOlmCiphertextWithExistingSession(senderKey id.
|
|||
continue
|
||||
}
|
||||
}
|
||||
mach.Log.Trace("Trying to decrypt olm message from %s with session %s: %s", senderKey, session.ID(), session.Describe())
|
||||
plaintext, err := session.Decrypt(ciphertext, olmType)
|
||||
if err != nil {
|
||||
if olmType == id.OlmMsgTypePreKey {
|
||||
|
|
@ -170,6 +172,7 @@ func (mach *OlmMachine) tryDecryptOlmCiphertextWithExistingSession(senderKey id.
|
|||
if err != nil {
|
||||
mach.Log.Warn("Failed to update olm session in crypto store after decrypting: %v", err)
|
||||
}
|
||||
mach.Log.Trace("Decrypted olm message from %s with session %s", senderKey, session.ID())
|
||||
return plaintext, nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ func (mach *OlmMachine) encryptOlmEvent(session *OlmSession, recipient *DeviceId
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
mach.Log.Trace("Encrypting olm message for %s with session %s: %s", recipient.IdentityKey, session.ID(), session.Describe())
|
||||
msgType, ciphertext := session.Encrypt(plaintext)
|
||||
err = mach.CryptoStore.UpdateSession(recipient.IdentityKey, session)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package olm
|
|||
|
||||
// #cgo LDFLAGS: -lolm -lstdc++
|
||||
// #include <olm/olm.h>
|
||||
// #include <stdlib.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
|
|
@ -328,3 +329,17 @@ func (s *Session) Decrypt(message string, msgType id.OlmMsgType) ([]byte, error)
|
|||
}
|
||||
return plaintext[:r], nil
|
||||
}
|
||||
|
||||
// https://gitlab.matrix.org/matrix-org/olm/-/blob/3.2.8/include/olm/olm.h#L392-393
|
||||
const maxDescribeSize = 600
|
||||
|
||||
// Describe generates a string describing the internal state of an olm session for debugging and logging purposes.
|
||||
func (s *Session) Describe() string {
|
||||
desc := (*C.char)(C.malloc(C.size_t(maxDescribeSize)))
|
||||
defer C.free(unsafe.Pointer(desc))
|
||||
C.olm_session_describe(
|
||||
(*C.OlmSession)(s.int),
|
||||
desc,
|
||||
C.size_t(maxDescribeSize))
|
||||
return C.GoString(desc)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,10 @@ func (session *OlmSession) ID() id.SessionID {
|
|||
return session.id
|
||||
}
|
||||
|
||||
func (session *OlmSession) Describe() string {
|
||||
return session.Internal.Describe()
|
||||
}
|
||||
|
||||
func wrapSession(session *olm.Session) *OlmSession {
|
||||
return &OlmSession{
|
||||
Internal: *session,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue