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

refactor(sdk-crypto): Room key sharing, introduce extensible strategy #3571

Closed
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions 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::{CollectStrategy, IdentityKeys, InboundGroupSession, Session},
store::{Changes, CryptoStore, PendingChanges, RoomSettings as RustRoomSettings},
types::{EventEncryptionAlgorithm as RustEventEncryptionAlgorithm, SigningKey},
EncryptionSettings as RustEncryptionSettings,
Expand Down Expand Up @@ -650,7 +650,7 @@ impl From<EncryptionSettings> for RustEncryptionSettings {
rotation_period: Duration::from_secs(v.rotation_period),
rotation_period_msgs: v.rotation_period_msgs,
history_visibility: v.history_visibility.into(),
only_allow_trusted_devices: v.only_allow_trusted_devices,
sharing_strategy: CollectStrategy::new_device_based(v.only_allow_trusted_devices),
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions crates/matrix-sdk-crypto/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,8 @@ pub(crate) mod tests {
error::{EventError, SetRoomSettingsError},
machine::{EncryptionSyncChanges, OlmMachine},
olm::{
BackedUpRoomKey, ExportedRoomKey, InboundGroupSession, OutboundGroupSession, VerifyJson,
BackedUpRoomKey, CollectStrategy, ExportedRoomKey, InboundGroupSession,
OutboundGroupSession, VerifyJson,
},
store::{BackupDecryptionKey, Changes, CryptoStore, MemoryStore, RoomSettings},
types::{
Expand Down Expand Up @@ -3083,8 +3084,10 @@ pub(crate) mod tests {
let room_id = room_id!("!test:example.org");

let encryption_settings = EncryptionSettings::default();
let encryption_settings =
EncryptionSettings { only_allow_trusted_devices: true, ..encryption_settings };
let encryption_settings = EncryptionSettings {
sharing_strategy: CollectStrategy::new_device_based(true),
..encryption_settings
};

let to_device_requests = alice
.share_room_key(room_id, iter::once(bob.user_id()), encryption_settings)
Expand Down
3 changes: 3 additions & 0 deletions crates/matrix-sdk-crypto/src/olm/group_sessions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ use serde::{Deserialize, Serialize};

mod inbound;
mod outbound;
mod share_strategy;

pub use inbound::{InboundGroupSession, PickledInboundGroupSession};
pub(crate) use outbound::ShareState;
pub use outbound::{
EncryptionSettings, OutboundGroupSession, PickledOutboundGroupSession, ShareInfo,
};
pub use share_strategy::CollectStrategy;
pub(crate) use share_strategy::{CollectRecipientsHelper, CollectRecipientsResult};
use thiserror::Error;
pub use vodozemac::megolm::{ExportedSessionKey, SessionKey};
use vodozemac::{megolm::SessionKeyDecodeError, Curve25519PublicKey};
Expand Down
12 changes: 6 additions & 6 deletions crates/matrix-sdk-crypto/src/olm/group_sessions/outbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub use vodozemac::{
PickleError,
};

use super::SessionCreationError;
use super::{share_strategy::CollectStrategy, SessionCreationError};
#[cfg(feature = "experimental-algorithms")]
use crate::types::events::room::encrypted::MegolmV2AesSha2Content;
use crate::{
Expand Down Expand Up @@ -85,10 +85,10 @@ pub struct EncryptionSettings {
pub rotation_period_msgs: u64,
/// The history visibility of the room when the session was created.
pub history_visibility: HistoryVisibility,
/// Should untrusted devices receive the room key, or should they be
/// excluded from the conversation.
/// The strategy used to distribute the room keys to participant.
/// Default will send to all devices.
#[serde(default)]
pub only_allow_trusted_devices: bool,
pub sharing_strategy: CollectStrategy,
}

impl Default for EncryptionSettings {
Expand All @@ -98,7 +98,7 @@ impl Default for EncryptionSettings {
rotation_period: ROTATION_PERIOD,
rotation_period_msgs: ROTATION_MESSAGES,
history_visibility: HistoryVisibility::Shared,
only_allow_trusted_devices: false,
sharing_strategy: CollectStrategy::default(),
}
}
}
Expand All @@ -122,7 +122,7 @@ impl EncryptionSettings {
rotation_period,
rotation_period_msgs,
history_visibility,
only_allow_trusted_devices,
sharing_strategy: CollectStrategy::new_device_based(only_allow_trusted_devices),
}
}
}
Expand Down
Loading
Loading