Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(crypto): Redecrypt non-UTD messages to remove no-longer-relevant warning shields #4644

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/matrix-sdk-ui/src/timeline/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,12 @@ impl RoomDataProvider for TestRoomDataProvider {
let info = RoomInfo::new(*DEFAULT_TEST_ROOM_ID, RoomState::Joined);
SharedObservable::new(info).subscribe()
}

async fn get_encryption_info(
&self,
_session_id: &str,
_sender: &UserId,
) -> Option<matrix_sdk::deserialized_responses::EncryptionInfo> {
None
}
}
20 changes: 18 additions & 2 deletions crates/matrix-sdk-ui/src/timeline/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ use indexmap::IndexMap;
#[cfg(test)]
use matrix_sdk::crypto::{DecryptionSettings, RoomEventDecryptionResult, TrustRequirement};
use matrix_sdk::{
crypto::types::events::CryptoContextInfo, deserialized_responses::TimelineEvent,
event_cache::paginator::PaginableRoom, AsyncTraitDeps, Result, Room, SendOutsideWasm,
crypto::types::events::CryptoContextInfo,
deserialized_responses::{EncryptionInfo, TimelineEvent},
event_cache::paginator::PaginableRoom,
AsyncTraitDeps, Result, Room, SendOutsideWasm,
};
use matrix_sdk_base::{latest_event::LatestEvent, RoomInfo};
use ruma::{
Expand Down Expand Up @@ -121,6 +123,12 @@ pub(super) trait RoomDataProvider:
) -> impl Future<Output = Result<(), super::Error>> + SendOutsideWasm + 'a;

fn room_info(&self) -> Subscriber<RoomInfo>;

fn get_encryption_info(
&self,
session_id: &str,
sender: &UserId,
) -> impl Future<Output = Option<EncryptionInfo>> + SendOutsideWasm;
}

impl RoomDataProvider for Room {
Expand Down Expand Up @@ -273,6 +281,14 @@ impl RoomDataProvider for Room {
fn room_info(&self) -> Subscriber<RoomInfo> {
self.subscribe_info()
}

async fn get_encryption_info(
&self,
session_id: &str,
sender: &UserId,
) -> Option<EncryptionInfo> {
self.get_encryption_info(session_id, sender).await
}
}

// Internal helper to make most of retry_event_decryption independent of a room
Expand Down
24 changes: 22 additions & 2 deletions crates/matrix-sdk/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ use futures_util::{
use http::StatusCode;
#[cfg(all(feature = "e2e-encryption", not(target_arch = "wasm32")))]
pub use identity_status_changes::IdentityStatusChanges;
#[cfg(feature = "e2e-encryption")]
use matrix_sdk_base::crypto::{DecryptionSettings, RoomEventDecryptionResult};
#[cfg(all(feature = "e2e-encryption", not(target_arch = "wasm32")))]
use matrix_sdk_base::crypto::{IdentityStatusChange, RoomIdentityProvider, UserIdentity};
#[cfg(feature = "e2e-encryption")]
use matrix_sdk_base::{
crypto::{DecryptionSettings, RoomEventDecryptionResult},
deserialized_responses::EncryptionInfo,
};
use matrix_sdk_base::{
deserialized_responses::{
RawAnySyncOrStrippedState, RawSyncOrStrippedState, SyncOrStrippedState,
Expand Down Expand Up @@ -1308,6 +1311,23 @@ impl Room {
Ok(event)
}

/// Fetches the [`EncryptionInfo`] for the supplied session_id.
///
/// This may be used when we receive an update for a session, and we want to
/// reflect the changes in messages we have received that were encrypted
/// with that session, e.g. to remove a warning shield because a device is
/// now verified.
#[cfg(feature = "e2e-encryption")]
pub async fn get_encryption_info(
&self,
session_id: &str,
sender: &UserId,
) -> Option<EncryptionInfo> {
let machine = self.client.olm_machine().await;
let machine = machine.as_ref()?;
machine.get_session_encryption_info(self.room_id(), session_id, sender).await.ok()
}

/// Forces the currently active room key, which is used to encrypt messages,
/// to be rotated.
///
Expand Down