diff --git a/crates/matrix-sdk-crypto/src/store/memorystore.rs b/crates/matrix-sdk-crypto/src/store/memorystore.rs index 0ff60f6b106..dde91cda174 100644 --- a/crates/matrix-sdk-crypto/src/store/memorystore.rs +++ b/crates/matrix-sdk-crypto/src/store/memorystore.rs @@ -26,16 +26,18 @@ use ruma::{ }; use tokio::sync::{Mutex, RwLock}; use tracing::warn; +use vodozemac::Curve25519PublicKey; use super::{ caches::{DeviceStore, GroupSessionStore, SessionStore}, + traits::InboundGroupSessionStream, Account, BackupKeys, Changes, CryptoStore, InboundGroupSession, PendingChanges, RoomKeyCounts, RoomSettings, Session, }; use crate::{ gossiping::{GossipRequest, GossippedSecret, SecretInfo}, identities::{DeviceData, UserIdentityData}, - olm::{OutboundGroupSession, PrivateCrossSigningIdentity}, + olm::{OutboundGroupSession, PrivateCrossSigningIdentity, SenderDataType}, types::events::room_key_withheld::RoomKeyWithheldEvent, TrackedUser, }; @@ -377,6 +379,14 @@ impl CryptoStore for MemoryStore { Ok(RoomKeyCounts { total: self.inbound_group_sessions.count(), backed_up }) } + async fn get_inbound_group_sessions_for_device( + &self, + _device_key: Curve25519PublicKey, + _sender_data_type: SenderDataType, + ) -> Result { + todo!() + } + async fn inbound_group_sessions_for_backup( &self, backup_version: &str, @@ -1093,15 +1103,19 @@ mod integration_tests { use ruma::{ events::secret::request::SecretName, DeviceId, OwnedDeviceId, RoomId, TransactionId, UserId, }; + use vodozemac::Curve25519PublicKey; use super::MemoryStore; use crate::{ cryptostore_integration_tests, cryptostore_integration_tests_time, olm::{ InboundGroupSession, OlmMessageHash, OutboundGroupSession, PrivateCrossSigningIdentity, - StaticAccountData, + SenderDataType, StaticAccountData, + }, + store::{ + traits::InboundGroupSessionStream, BackupKeys, Changes, CryptoStore, PendingChanges, + RoomKeyCounts, RoomSettings, }, - store::{BackupKeys, Changes, CryptoStore, PendingChanges, RoomKeyCounts, RoomSettings}, types::events::room_key_withheld::RoomKeyWithheldEvent, Account, DeviceData, GossipRequest, GossippedSecret, SecretInfo, Session, TrackedUser, UserIdentityData, @@ -1225,6 +1239,13 @@ mod integration_tests { self.0.inbound_group_session_counts(backup_version).await } + async fn get_inbound_group_sessions_for_device( + &self, + device_key: Curve25519PublicKey, + sender_data_type: SenderDataType, + ) -> Result { + self.0.get_inbound_group_sessions_for_device(device_key, sender_data_type).await + } async fn inbound_group_sessions_for_backup( &self, backup_version: &str, diff --git a/crates/matrix-sdk-crypto/src/store/mod.rs b/crates/matrix-sdk-crypto/src/store/mod.rs index 6e715eda2d4..ac60ea8f6fe 100644 --- a/crates/matrix-sdk-crypto/src/store/mod.rs +++ b/crates/matrix-sdk-crypto/src/store/mod.rs @@ -94,7 +94,7 @@ pub(crate) use crypto_store_wrapper::CryptoStoreWrapper; pub use error::{CryptoStoreError, Result}; use matrix_sdk_common::{store_locks::CrossProcessStoreLock, timeout::timeout}; pub use memorystore::MemoryStore; -pub use traits::{CryptoStore, DynCryptoStore, IntoCryptoStore}; +pub use traits::{CryptoStore, DynCryptoStore, InboundGroupSessionStream, IntoCryptoStore}; pub use crate::gossiping::{GossipRequest, SecretInfo}; diff --git a/crates/matrix-sdk-crypto/src/store/traits.rs b/crates/matrix-sdk-crypto/src/store/traits.rs index 390104c9a10..a8e062a32bb 100644 --- a/crates/matrix-sdk-crypto/src/store/traits.rs +++ b/crates/matrix-sdk-crypto/src/store/traits.rs @@ -15,11 +15,13 @@ use std::{collections::HashMap, fmt, sync::Arc}; use async_trait::async_trait; +use futures_core::Stream; use matrix_sdk_common::AsyncTraitDeps; use ruma::{ events::secret::request::SecretName, DeviceId, OwnedDeviceId, RoomId, TransactionId, UserId, }; use tokio::sync::Mutex; +use vodozemac::Curve25519PublicKey; use super::{ BackupKeys, Changes, CryptoStoreError, PendingChanges, Result, RoomKeyCounts, RoomSettings, @@ -27,7 +29,7 @@ use super::{ use crate::{ olm::{ InboundGroupSession, OlmMessageHash, OutboundGroupSession, PrivateCrossSigningIdentity, - Session, + SenderDataType, Session, }, types::events::room_key_withheld::RoomKeyWithheldEvent, Account, DeviceData, GossipRequest, GossippedSecret, SecretInfo, TrackedUser, UserIdentityData, @@ -125,6 +127,17 @@ pub trait CryptoStore: AsyncTraitDeps { backup_version: Option<&str>, ) -> Result; + /// Get all the inbound group sessions for the device with the supplied + /// curve key, whose sender data is of the supplied type. + /// + /// Used when the device information is updated via a /keys/query response + /// and we want to update the sender data based on the new information. + async fn get_inbound_group_sessions_for_device( + &self, + device_key: Curve25519PublicKey, + sender_data_type: SenderDataType, + ) -> Result; + /// Return a batch of ['InboundGroupSession'] ("room keys") that have not /// yet been backed up in the supplied backup version. /// @@ -333,6 +346,21 @@ pub trait CryptoStore: AsyncTraitDeps { async fn clear_caches(&self); } +/// A stream of [`InboundGroupSession`]s +#[derive(Debug)] +pub struct InboundGroupSessionStream {} + +impl Stream for InboundGroupSessionStream { + type Item = InboundGroupSession; + + fn poll_next( + self: std::pin::Pin<&mut Self>, + _cx: &mut std::task::Context<'_>, + ) -> std::task::Poll> { + todo!() + } +} + #[repr(transparent)] struct EraseCryptoStoreError(T); @@ -392,6 +420,17 @@ impl CryptoStore for EraseCryptoStoreError { self.0.get_inbound_group_sessions().await.map_err(Into::into) } + async fn get_inbound_group_sessions_for_device( + &self, + device_key: Curve25519PublicKey, + sender_data_type: SenderDataType, + ) -> Result { + self.0 + .get_inbound_group_sessions_for_device(device_key, sender_data_type) + .await + .map_err(Into::into) + } + async fn inbound_group_session_counts( &self, backup_version: Option<&str>, diff --git a/crates/matrix-sdk-sqlite/src/crypto_store.rs b/crates/matrix-sdk-sqlite/src/crypto_store.rs index 474a7dddc1b..f4b4b82a8e5 100644 --- a/crates/matrix-sdk-sqlite/src/crypto_store.rs +++ b/crates/matrix-sdk-sqlite/src/crypto_store.rs @@ -25,11 +25,11 @@ use deadpool_sqlite::{Object as SqliteConn, Pool as SqlitePool, Runtime}; use matrix_sdk_crypto::{ olm::{ InboundGroupSession, OutboundGroupSession, PickledInboundGroupSession, - PrivateCrossSigningIdentity, Session, StaticAccountData, + PrivateCrossSigningIdentity, SenderDataType, Session, StaticAccountData, }, store::{ - caches::SessionStore, BackupKeys, Changes, CryptoStore, PendingChanges, RoomKeyCounts, - RoomSettings, + caches::SessionStore, BackupKeys, Changes, CryptoStore, InboundGroupSessionStream, + PendingChanges, RoomKeyCounts, RoomSettings, }, types::events::room_key_withheld::RoomKeyWithheldEvent, Account, DeviceData, GossipRequest, GossippedSecret, SecretInfo, TrackedUser, UserIdentityData, @@ -43,6 +43,7 @@ use rusqlite::{params_from_iter, OptionalExtension}; use serde::{de::DeserializeOwned, Serialize}; use tokio::{fs, sync::Mutex}; use tracing::{debug, instrument, warn}; +use vodozemac::Curve25519PublicKey; use crate::{ error::{Error, Result}, @@ -993,6 +994,14 @@ impl CryptoStore for SqliteCryptoStore { .collect() } + async fn get_inbound_group_sessions_for_device( + &self, + _device_key: Curve25519PublicKey, + _sender_data_type: SenderDataType, + ) -> Result { + todo!() + } + async fn inbound_group_session_counts( &self, backup_version: Option<&str>,