Skip to content

Commit

Permalink
Add 'get_inbound_group_sessions_for_device' to CryptoStore
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam authored and richvdh committed Aug 7, 2024
1 parent bc3fdcf commit 97c11ae
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
27 changes: 24 additions & 3 deletions crates/matrix-sdk-crypto/src/store/memorystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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<InboundGroupSessionStream> {
todo!()
}

async fn inbound_group_sessions_for_backup(
&self,
backup_version: &str,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<InboundGroupSessionStream, Self::Error> {
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,
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-crypto/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
41 changes: 40 additions & 1 deletion crates/matrix-sdk-crypto/src/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@
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,
};
use crate::{
olm::{
InboundGroupSession, OlmMessageHash, OutboundGroupSession, PrivateCrossSigningIdentity,
Session,
SenderDataType, Session,
},
types::events::room_key_withheld::RoomKeyWithheldEvent,
Account, DeviceData, GossipRequest, GossippedSecret, SecretInfo, TrackedUser, UserIdentityData,
Expand Down Expand Up @@ -125,6 +127,17 @@ pub trait CryptoStore: AsyncTraitDeps {
backup_version: Option<&str>,
) -> Result<RoomKeyCounts, Self::Error>;

/// 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<InboundGroupSessionStream, Self::Error>;

/// Return a batch of ['InboundGroupSession'] ("room keys") that have not
/// yet been backed up in the supplied backup version.
///
Expand Down Expand Up @@ -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<Option<Self::Item>> {
todo!()
}
}

#[repr(transparent)]
struct EraseCryptoStoreError<T>(T);

Expand Down Expand Up @@ -392,6 +420,17 @@ impl<T: CryptoStore> CryptoStore for EraseCryptoStoreError<T> {
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<InboundGroupSessionStream> {
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>,
Expand Down
15 changes: 12 additions & 3 deletions crates/matrix-sdk-sqlite/src/crypto_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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},
Expand Down Expand Up @@ -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<InboundGroupSessionStream> {
todo!()
}

async fn inbound_group_session_counts(
&self,
backup_version: Option<&str>,
Expand Down

0 comments on commit 97c11ae

Please sign in to comment.