matrix-org / matrix-rust-sdk

Matrix Client-Server SDK for Rust
Apache License 2.0
1.26k stars 252 forks source link

Disabling and recreating key backup on Web leaves the SDK (EX) in a weird state. #4190

Open pixlwave opened 2 weeks ago

pixlwave commented 2 weeks ago

The SDK detects when the backup is disabled, when re-enabling it, it believes it is enabled until you try to send a message (or maybe receive one that needs to open the key backup?) at which point it believes the backup is disabled again. Choosing to enable the backup fails with

2024-10-30T12:38:16.481302Z ERROR elementx: Failed enabling secure backup with error: BackupExistsOnServer | SecureBackupController.swift:91 | spans: root
2024-10-30T12:38:16.482975Z ERROR elementx: Failed enabling key backup with error: failedEnablingBackup | SecureBackupScreenViewModel.swift:77 | spans: root⁦

Recording of 2 webs + an EX showing this and how it is handled differently.

https://github.com/user-attachments/assets/c5d2906e-b1e2-4f3f-bc8c-573f1b3ad15a

poljar commented 1 day ago

I think that at least one of the weird behavior here is caused by the fact that the backup key is never removed from the store:

https://github.com/matrix-org/matrix-rust-sdk/blob/232391c6b262f759f7422764dc2fc58f2d345094/crates/matrix-sdk/src/encryption/backups/mod.rs#L140

That's why the SDK things the backup is active again after the restart.

I reproduced this and it can happen if there are multiple backups alive on the server as well. The SDK deletes the currently active one, the one the SDK uses itself, but after that one got deleted another one has become active.