diff --git a/crates/matrix-sdk/src/encryption/recovery/mod.rs b/crates/matrix-sdk/src/encryption/recovery/mod.rs index 768e4c3f8..1adfe3f20 100644 --- a/crates/matrix-sdk/src/encryption/recovery/mod.rs +++ b/crates/matrix-sdk/src/encryption/recovery/mod.rs @@ -399,24 +399,27 @@ impl Recovery { Ok(devices.devices().count() == 1) } + /// Did we correctly set up cross-signing and backups? async fn all_known_secrets_available(&self) -> Result { + // Cross-signing state is fine if we have all the private cross-signing keys, as + // indicated in the status. let cross_signing_complete = self .client .encryption() .cross_signing_status() .await - .map(|status| status.is_complete()) - .unwrap_or_default(); + .map(|status| status.is_complete()); + if !cross_signing_complete.unwrap_or_default() { + return Ok(false); + } // The backup state is fine if we have backups enabled locally, or if backups // have been marked as disabled. - let backup_state_ok = if self.client.encryption().backups().are_enabled().await { - true + if self.client.encryption().backups().are_enabled().await { + Ok(true) } else { - self.are_backups_marked_as_disabled().await? - }; - - Ok(cross_signing_complete && backup_state_ok) + self.are_backups_marked_as_disabled().await + } } async fn should_auto_enable_backups(&self) -> Result { @@ -448,6 +451,8 @@ impl Recovery { Ok(()) } + /// Run a network request to figure whether backups have been disabled at + /// the account level. async fn are_backups_marked_as_disabled(&self) -> Result { Ok(self .client diff --git a/crates/matrix-sdk/tests/integration/encryption/recovery.rs b/crates/matrix-sdk/tests/integration/encryption/recovery.rs index f08db1093..e54ade6ba 100644 --- a/crates/matrix-sdk/tests/integration/encryption/recovery.rs +++ b/crates/matrix-sdk/tests/integration/encryption/recovery.rs @@ -176,19 +176,6 @@ async fn recovery_status_secret_storage_set_up() { mock_secret_store_with_backup_key(user_id, KEY_ID, &server).await; - Mock::given(method("GET")) - .and(path(format!( - "_matrix/client/r0/user/{user_id}/account_data/m.org.matrix.custom.backup_disabled" - ))) - .and(header("authorization", "Bearer 1234")) - .respond_with(ResponseTemplate::new(404).set_body_json(json!({ - "errcode": "M_NOT_FOUND", - "error": "Account data not found" - }))) - .expect(1..) - .mount(&server) - .await; - client.restore_session(session).await.unwrap(); client.encryption().wait_for_e2ee_initialization_tasks().await; @@ -724,19 +711,6 @@ async fn recover_and_reset() { mock_secret_store_with_backup_key(user_id, KEY_ID, &server).await; - Mock::given(method("GET")) - .and(path(format!( - "_matrix/client/r0/user/{user_id}/account_data/m.org.matrix.custom.backup_disabled" - ))) - .and(header("authorization", "Bearer 1234")) - .respond_with(ResponseTemplate::new(404).set_body_json(json!({ - "errcode": "M_NOT_FOUND", - "error": "Account data not found" - }))) - .expect(1..) - .mount(&server) - .await; - Mock::given(method("GET")) .and(path("_matrix/client/r0/room_keys/version")) .and(header("authorization", "Bearer 1234"))