Skip to content

Commit

Permalink
crypto: Store sender_data in InboundGroupSessions
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam committed Jun 24, 2024
1 parent 3ffeef5 commit 626c497
Show file tree
Hide file tree
Showing 12 changed files with 405 additions and 19 deletions.
3 changes: 2 additions & 1 deletion bindings/matrix-sdk-crypto-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub use logger::{set_logger, Logger};
pub use machine::{KeyRequestPair, OlmMachine, SignatureVerification};
use matrix_sdk_common::deserialized_responses::ShieldState as RustShieldState;
use matrix_sdk_crypto::{
olm::{IdentityKeys, InboundGroupSession, Session},
olm::{IdentityKeys, InboundGroupSession, SenderData, Session},
store::{Changes, CryptoStore, PendingChanges, RoomSettings as RustRoomSettings},
types::{EventEncryptionAlgorithm as RustEventEncryptionAlgorithm, SigningKey},
EncryptionSettings as RustEncryptionSettings,
Expand Down Expand Up @@ -471,6 +471,7 @@ fn collect_sessions(
Ok((algorithm, key))
})
.collect::<anyhow::Result<_>>()?,
sender_data: SenderData::unknown(), // TODO: what should happen here?
room_id: RoomId::parse(session.room_id)?,
imported: session.imported,
backed_up: session.backed_up,
Expand Down
10 changes: 8 additions & 2 deletions crates/matrix-sdk-crypto/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use crate::{
identities::{user::UserIdentities, Device, IdentityManager, UserDevices},
olm::{
Account, CrossSigningStatus, EncryptionSettings, IdentityKeys, InboundGroupSession,
OlmDecryptionInfo, PrivateCrossSigningIdentity, SessionType, StaticAccountData,
OlmDecryptionInfo, PrivateCrossSigningIdentity, SenderData, SessionType, StaticAccountData,
},
requests::{IncomingResponse, OutgoingRequest, UploadSigningKeysRequest},
session_manager::{GroupSessionManager, SessionManager},
Expand Down Expand Up @@ -806,11 +806,14 @@ impl OlmMachine {
event: &DecryptedRoomKeyEvent,
content: &MegolmV1AesSha2Content,
) -> OlmResult<Option<InboundGroupSession>> {
let sender_data = SenderData::unknown();

let session = InboundGroupSession::new(
sender_key,
event.keys.ed25519,
&content.room_id,
&content.session_key,
sender_data,
event.content.algorithm(),
None,
);
Expand Down Expand Up @@ -2263,7 +2266,8 @@ pub(crate) mod tests {
error::{EventError, SetRoomSettingsError},
machine::{EncryptionSyncChanges, OlmMachine},
olm::{
BackedUpRoomKey, ExportedRoomKey, InboundGroupSession, OutboundGroupSession, VerifyJson,
BackedUpRoomKey, ExportedRoomKey, InboundGroupSession, OutboundGroupSession,
SenderData, VerifyJson,
},
store::{BackupDecryptionKey, Changes, CryptoStore, MemoryStore, RoomSettings},
types::{
Expand Down Expand Up @@ -3556,6 +3560,7 @@ pub(crate) mod tests {
Ed25519PublicKey::from_base64("loz5i40dP+azDtWvsD0L/xpnCjNkmrcvtXVXzCHX8Vw").unwrap(),
fake_room_id,
&olm,
SenderData::unknown(),
EventEncryptionAlgorithm::MegolmV1AesSha2,
None,
)
Expand All @@ -3573,6 +3578,7 @@ pub(crate) mod tests {
Ed25519PublicKey::from_base64("48f3WQAMGwYLBg5M5qUhqnEVA8yeibjZpPsShoWMFT8").unwrap(),
fake_room_id,
&olm,
SenderData::unknown(),
EventEncryptionAlgorithm::MegolmV1AesSha2,
None,
)
Expand Down
2 changes: 2 additions & 0 deletions crates/matrix-sdk-crypto/src/olm/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use crate::{
dehydrated_devices::DehydrationError,
error::{EventError, OlmResult, SessionCreationError},
identities::ReadOnlyDevice,
olm::SenderData,
requests::UploadSigningKeysRequest,
store::{Changes, Store},
types::{
Expand Down Expand Up @@ -220,6 +221,7 @@ impl StaticAccountData {
signing_key,
room_id,
&outbound.session_key().await,
SenderData::unknown(), // TODO: provide sender data about ourself
algorithm,
Some(visibility),
)?;
Expand Down
Loading

0 comments on commit 626c497

Please sign in to comment.