Add command to reset the megolm session in a room
This commit is contained in:
parent
f21f57f09f
commit
0f17863708
3 changed files with 21 additions and 0 deletions
13
commands.go
13
commands.go
|
@ -123,6 +123,8 @@ func (handler *CommandHandler) CommandMux(ce *CommandEvent) {
|
|||
handler.CommandDeletePortal(ce)
|
||||
case "delete-all-portals":
|
||||
handler.CommandDeleteAllPortals(ce)
|
||||
case "discard-megolm-session", "discard-session":
|
||||
handler.CommandDiscardMegolmSession(ce)
|
||||
case "dev-test":
|
||||
handler.CommandDevTest(ce)
|
||||
case "set-pl":
|
||||
|
@ -163,6 +165,17 @@ func (handler *CommandHandler) CommandMux(ce *CommandEvent) {
|
|||
}
|
||||
}
|
||||
|
||||
func (handler *CommandHandler) CommandDiscardMegolmSession(ce *CommandEvent) {
|
||||
if handler.bridge.Crypto == nil {
|
||||
ce.Reply("This bridge instance doesn't have end-to-bridge encryption enabled")
|
||||
} else if !ce.User.Admin {
|
||||
ce.Reply("Only the bridge admin can reset Megolm sessions")
|
||||
} else {
|
||||
handler.bridge.Crypto.ResetSession(ce.RoomID)
|
||||
ce.Reply("Successfully reset Megolm session in this room. New decryption keys will be shared the next time a message is sent from WhatsApp.")
|
||||
}
|
||||
}
|
||||
|
||||
func (handler *CommandHandler) CommandRelaybot(ce *CommandEvent) {
|
||||
if handler.bridge.Relaybot == nil {
|
||||
ce.Reply("The relaybot is disabled")
|
||||
|
|
|
@ -189,6 +189,13 @@ func (helper *CryptoHelper) WaitForSession(roomID id.RoomID, senderKey id.Sender
|
|||
return helper.mach.WaitForSession(roomID, senderKey, sessionID, timeout)
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) ResetSession(roomID id.RoomID) {
|
||||
err := helper.mach.CryptoStore.RemoveOutboundGroupSession(roomID)
|
||||
if err != nil {
|
||||
helper.log.Debugfln("Error manually removing outbound group session in %s: %v", roomID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (helper *CryptoHelper) HandleMemberEvent(evt *event.Event) {
|
||||
helper.mach.HandleMemberEvent(evt)
|
||||
}
|
||||
|
|
1
main.go
1
main.go
|
@ -154,6 +154,7 @@ type Crypto interface {
|
|||
Decrypt(*event.Event) (*event.Event, error)
|
||||
Encrypt(id.RoomID, event.Type, event.Content) (*event.EncryptedEventContent, error)
|
||||
WaitForSession(id.RoomID, id.SenderKey, id.SessionID, time.Duration) bool
|
||||
ResetSession(id.RoomID)
|
||||
Init() error
|
||||
Start()
|
||||
Stop()
|
||||
|
|
Loading…
Reference in a new issue