Skip to content

Commit

Permalink
crypto: Storage changes for keeping sender data with InboundGroupSess…
Browse files Browse the repository at this point in the history
…ions (#3556)

Signed-off-by: Andy Balaam <[email protected]>
Co-authored-by: Damir Jelić <[email protected]>
  • Loading branch information
andybalaam and poljar authored Jun 28, 2024
1 parent cb4c575 commit 6464d21
Show file tree
Hide file tree
Showing 15 changed files with 397 additions and 20 deletions.
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ extend-exclude = [
"crates/matrix-sdk-ui/tests/integration/room_list_service.rs",
# Hand-crafted base64 session keys that are understood as typos.
"crates/matrix-sdk-indexeddb/src/crypto_store/migrations/mod.rs",
"crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs",
]
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 @@ -35,7 +35,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::{
DeviceKey, DeviceKeys, EventEncryptionAlgorithm as RustEventEncryptionAlgorithm, SigningKey,
Expand Down Expand Up @@ -501,6 +501,7 @@ fn collect_sessions(
Ok((algorithm, key))
})
.collect::<anyhow::Result<_>>()?,
sender_data: SenderData::legacy(),
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 @@ -66,7 +66,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 @@ -816,11 +816,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 @@ -2417,7 +2420,8 @@ pub(crate) mod tests {
error::{EventError, SetRoomSettingsError},
machine::{EncryptionSyncChanges, OlmMachine},
olm::{
BackedUpRoomKey, ExportedRoomKey, InboundGroupSession, OutboundGroupSession, VerifyJson,
BackedUpRoomKey, ExportedRoomKey, InboundGroupSession, OutboundGroupSession,
SenderData, VerifyJson,
},
session_manager::CollectStrategy,
store::{BackupDecryptionKey, Changes, CryptoStore, MemoryStore, RoomSettings},
Expand Down Expand Up @@ -3713,6 +3717,7 @@ pub(crate) mod tests {
Ed25519PublicKey::from_base64("loz5i40dP+azDtWvsD0L/xpnCjNkmrcvtXVXzCHX8Vw").unwrap(),
fake_room_id,
&olm,
SenderData::unknown(),
EventEncryptionAlgorithm::MegolmV1AesSha2,
None,
)
Expand All @@ -3730,6 +3735,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, DeviceChanges, Store},
types::{
Expand Down Expand Up @@ -220,6 +221,7 @@ impl StaticAccountData {
signing_key,
room_id,
&outbound.session_key().await,
SenderData::unknown(),
algorithm,
Some(visibility),
)?;
Expand Down
Loading

0 comments on commit 6464d21

Please sign in to comment.