From b8017b1fb0262a974cb3ee75c7c93f0d13d01c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 7 May 2021 13:22:32 +0200 Subject: [PATCH] bump ruma to 24154195a00390a33542603b968e94022487587c --- matrix_sdk_common/Cargo.toml | 2 +- matrix_sdk_crypto/src/machine.rs | 11 ++++++----- matrix_sdk_crypto/src/olm/account.rs | 10 +++++++--- .../src/olm/group_sessions/inbound.rs | 11 +++++++---- .../src/olm/group_sessions/outbound.rs | 17 ++++++++++------- matrix_sdk_crypto/src/olm/session.rs | 17 +++++++++++++---- 6 files changed, 44 insertions(+), 24 deletions(-) diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index 5224a032..0f258e78 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -21,7 +21,7 @@ async-trait = "0.1.42" [dependencies.ruma] version = "0.0.3" git = "https://github.com/ruma/ruma" -rev = "1e005f576e4640ee5ce6e357bcf33293819502d1" +rev = "24154195a00390a33542603b968e94022487587c" features = ["client-api-c", "compat", "unstable-pre-spec"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index a144a3cd..4bf422e3 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -32,7 +32,8 @@ use matrix_sdk_common::{ assign, deserialized_responses::{AlgorithmInfo, EncryptionInfo, SyncRoomEvent, VerificationState}, events::{ - room::encrypted::EncryptedEventContent, room_key::RoomKeyEventContent, + room::encrypted::{EncryptedEventContent, EncryptedEventScheme}, + room_key::RoomKeyEventContent, AnyMessageEventContent, AnyToDeviceEvent, SyncMessageEvent, ToDeviceEvent, }, identifiers::{ @@ -939,8 +940,8 @@ impl OlmMachine { event: &SyncMessageEvent, room_id: &RoomId, ) -> MegolmResult<(Option, OutgoingRequest)> { - let content = match &event.content { - EncryptedEventContent::MegolmV1AesSha2(c) => c, + let content = match &event.content.scheme { + EncryptedEventScheme::MegolmV1AesSha2(c) => c, _ => return Err(EventError::UnsupportedAlgorithm.into()), }; @@ -1000,8 +1001,8 @@ impl OlmMachine { event: &SyncMessageEvent, room_id: &RoomId, ) -> MegolmResult { - let content = match &event.content { - EncryptedEventContent::MegolmV1AesSha2(c) => c, + let content = match &event.content.scheme { + EncryptedEventScheme::MegolmV1AesSha2(c) => c, _ => return Err(EventError::UnsupportedAlgorithm.into()), }; diff --git a/matrix_sdk_crypto/src/olm/account.rs b/matrix_sdk_crypto/src/olm/account.rs index 0e9717f1..27f60103 100644 --- a/matrix_sdk_crypto/src/olm/account.rs +++ b/matrix_sdk_crypto/src/olm/account.rs @@ -35,7 +35,10 @@ use matrix_sdk_common::{ upload_keys, upload_signatures::Request as SignatureUploadRequest, OneTimeKey, SignedKey, }, encryption::DeviceKeys, - events::{room::encrypted::EncryptedEventContent, AnyToDeviceEvent}, + events::{ + room::encrypted::{EncryptedEventContent, EncryptedEventScheme}, + AnyToDeviceEvent, + }, identifiers::{ DeviceId, DeviceIdBox, DeviceKeyAlgorithm, DeviceKeyId, EventEncryptionAlgorithm, RoomId, UserId, @@ -124,7 +127,8 @@ impl Account { ) -> OlmResult { debug!("Decrypting to-device event"); - let content = if let EncryptedEventContent::OlmV1Curve25519AesSha2(c) = &event.content { + let content = if let EncryptedEventScheme::OlmV1Curve25519AesSha2(c) = &event.content.scheme + { c } else { warn!("Error, unsupported encryption algorithm"); @@ -1046,7 +1050,7 @@ impl ReadOnlyAccount { .encrypt(&device, EventType::Dummy, json!({})) .await .unwrap(); - let content = if let EncryptedEventContent::OlmV1Curve25519AesSha2(c) = message { + let content = if let EncryptedEventScheme::OlmV1Curve25519AesSha2(c) = message.scheme { c } else { panic!("Invalid encrypted event algorithm"); diff --git a/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs b/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs index a23e4ef5..ee6c1c2c 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs @@ -35,7 +35,10 @@ pub use olm_rs::{ use matrix_sdk_common::{ events::{ forwarded_room_key::ForwardedRoomKeyToDeviceEventContent, - room::{encrypted::EncryptedEventContent, history_visibility::HistoryVisibility}, + room::{ + encrypted::{EncryptedEventContent, EncryptedEventScheme}, + history_visibility::HistoryVisibility, + }, AnySyncRoomEvent, SyncMessageEvent, }, identifiers::{DeviceKeyAlgorithm, EventEncryptionAlgorithm, RoomId}, @@ -305,8 +308,8 @@ impl InboundGroupSession { &self, event: &SyncMessageEvent, ) -> MegolmResult<(Raw, u32)> { - let content = match &event.content { - EncryptedEventContent::MegolmV1AesSha2(c) => c, + let content = match &event.content.scheme { + EncryptedEventScheme::MegolmV1AesSha2(c) => c, _ => return Err(EventError::UnsupportedAlgorithm.into()), }; @@ -340,7 +343,7 @@ impl InboundGroupSession { .flatten() { if !decrypted_content.contains_key("m.relates_to") { - if let Some(relation) = &content.relates_to { + if let Some(relation) = &event.content.relates_to { decrypted_content.insert( "m.relates_to".to_owned(), serde_json::to_value(relation).unwrap_or_default(), diff --git a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs index aec7ad17..ebff3c95 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs @@ -16,8 +16,7 @@ use dashmap::DashMap; use matrix_sdk_common::{ api::r0::to_device::DeviceIdOrAllDevices, events::room::{ - encrypted::{MegolmV1AesSha2Content, MegolmV1AesSha2ContentInit}, - history_visibility::HistoryVisibility, + encrypted::MegolmV1AesSha2ContentInit, history_visibility::HistoryVisibility, message::Relation, }, uuid::Uuid, @@ -36,7 +35,10 @@ use tracing::{debug, error, trace}; use matrix_sdk_common::{ events::{ - room::{encrypted::EncryptedEventContent, encryption::EncryptionEventContent}, + room::{ + encrypted::{EncryptedEventContent, EncryptedEventScheme}, + encryption::EncryptionEventContent, + }, AnyMessageEventContent, EventContent, }, identifiers::{DeviceId, DeviceIdBox, EventEncryptionAlgorithm, RoomId, UserId}, @@ -306,7 +308,7 @@ impl OutboundGroupSession { let ciphertext = self.encrypt_helper(plaintext).await; - let mut encrypted_content: MegolmV1AesSha2Content = MegolmV1AesSha2ContentInit { + let encrypted_content = MegolmV1AesSha2ContentInit { ciphertext, sender_key: self.account_identity_keys.curve25519().to_owned(), session_id: self.session_id().to_owned(), @@ -314,9 +316,10 @@ impl OutboundGroupSession { } .into(); - encrypted_content.relates_to = relates_to; - - EncryptedEventContent::MegolmV1AesSha2(encrypted_content) + EncryptedEventContent::new( + EncryptedEventScheme::MegolmV1AesSha2(encrypted_content), + relates_to, + ) } /// Check if the session has expired and if it should be rotated. diff --git a/matrix_sdk_crypto/src/olm/session.rs b/matrix_sdk_crypto/src/olm/session.rs index f0291d5a..aa5ed764 100644 --- a/matrix_sdk_crypto/src/olm/session.rs +++ b/matrix_sdk_crypto/src/olm/session.rs @@ -16,7 +16,10 @@ use std::{collections::BTreeMap, fmt, sync::Arc}; use matrix_sdk_common::{ events::{ - room::encrypted::{CiphertextInfo, EncryptedEventContent, OlmV1Curve25519AesSha2Content}, + room::encrypted::{ + CiphertextInfo, EncryptedEventContent, EncryptedEventScheme, + OlmV1Curve25519AesSha2Content, + }, EventType, }, identifiers::{DeviceId, DeviceKeyAlgorithm, UserId}, @@ -118,6 +121,11 @@ impl Session { .get_key(DeviceKeyAlgorithm::Ed25519) .ok_or(EventError::MissingSigningKey)?; + let relates_to = content + .get("m.relates_to") + .cloned() + .and_then(|v| serde_json::from_value(v).ok()); + let payload = json!({ "sender": self.user_id.as_str(), "sender_device": self.device_id.as_ref(), @@ -141,11 +149,12 @@ impl Session { let mut content = BTreeMap::new(); content.insert((&*self.sender_key).to_owned(), ciphertext); - Ok(EncryptedEventContent::OlmV1Curve25519AesSha2( - OlmV1Curve25519AesSha2Content::new( + Ok(EncryptedEventContent::new( + EncryptedEventScheme::OlmV1Curve25519AesSha2(OlmV1Curve25519AesSha2Content::new( content, self.our_identity_keys.curve25519().to_string(), - ), + )), + relates_to, )) }