Merge branch 'master' into sas-verification

master
Damir Jelić 2020-07-25 10:31:20 +02:00
commit 094b2f90d6
5 changed files with 32 additions and 48 deletions

View File

@ -966,18 +966,14 @@ impl Client {
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # use matrix_sdk::identifiers::RoomId; /// # use matrix_sdk::identifiers::RoomId;
/// # use std::convert::TryFrom; /// # use std::convert::TryFrom;
/// use matrix_sdk::events::room::message::{FormattedBody, MessageEventContent, TextMessageEventContent}; /// use matrix_sdk::events::room::message::{MessageEventContent, TextMessageEventContent};
/// # block_on(async { /// # block_on(async {
/// # let homeserver = Url::parse("http://localhost:8080").unwrap(); /// # let homeserver = Url::parse("http://localhost:8080").unwrap();
/// # let mut client = Client::new(homeserver).unwrap(); /// # let mut client = Client::new(homeserver).unwrap();
/// # let room_id = RoomId::try_from("!test:localhost").unwrap(); /// # let room_id = RoomId::try_from("!test:localhost").unwrap();
/// use matrix_sdk_common::uuid::Uuid; /// use matrix_sdk_common::uuid::Uuid;
/// ///
/// let content = MessageEventContent::Text(TextMessageEventContent { /// let content = MessageEventContent::Text(TextMessageEventContent::plain("Hello world"));
/// body: "Hello world".to_owned(),
/// formatted: None,
/// relates_to: None,
/// });
/// let txn_id = Uuid::new_v4(); /// let txn_id = Uuid::new_v4();
/// client.room_send(&room_id, content, Some(txn_id)).await.unwrap(); /// client.room_send(&room_id, content, Some(txn_id)).await.unwrap();
/// # }) /// # })

View File

@ -469,13 +469,11 @@ impl BaseClient {
// a store path was provided. // a store path was provided.
if self.state_store.read().await.is_none() { if self.state_store.read().await.is_none() {
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
{
if let Some(path) = &*self.store_path { if let Some(path) = &*self.store_path {
let store = JsonStore::open(path)?; let store = JsonStore::open(path)?;
*self.state_store.write().await = Some(Box::new(store)); *self.state_store.write().await = Some(Box::new(store));
} }
} }
}
self.sync_with_state_store(&session).await?; self.sync_with_state_store(&session).await?;
@ -719,7 +717,6 @@ impl BaseClient {
#[allow(unused_mut)] #[allow(unused_mut)]
Ok(mut e) => { Ok(mut e) => {
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
{
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomEncrypted( if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomEncrypted(
ref mut encrypted_event, ref mut encrypted_event,
)) = e )) = e
@ -727,8 +724,7 @@ impl BaseClient {
let mut olm = self.olm.lock().await; let mut olm = self.olm.lock().await;
if let Some(o) = &mut *olm { if let Some(o) = &mut *olm {
if let Ok(decrypted) = if let Ok(decrypted) = o.decrypt_room_event(&encrypted_event, room_id).await
o.decrypt_room_event(&encrypted_event, room_id).await
{ {
if let Ok(d) = decrypted.deserialize() { if let Ok(d) = decrypted.deserialize() {
e = d e = d
@ -737,7 +733,6 @@ impl BaseClient {
} }
} }
} }
}
let room_lock = self.get_or_create_joined_room(&room_id).await?; let room_lock = self.get_or_create_joined_room(&room_id).await?;
let mut room = room_lock.write().await; let mut room = room_lock.write().await;
@ -1199,10 +1194,9 @@ impl BaseClient {
// send the `prev_content` field as part of the unsigned field. // send the `prev_content` field as part of the unsigned field.
if let AnyStrippedStateEvent::RoomMember(_) = &mut e { if let AnyStrippedStateEvent::RoomMember(_) = &mut e {
if let Some(raw_content) = stripped_deserialize_prev_content(event) { if let Some(raw_content) = stripped_deserialize_prev_content(event) {
let prev_content = match raw_content.prev_content { let prev_content = raw_content
Some(json) => json.deserialize().ok(), .prev_content
None => None, .and_then(|json| json.deserialize().ok());
};
self.emit_stripped_state_event( self.emit_stripped_state_event(
&room_id, &room_id,
&e, &e,

View File

@ -17,7 +17,7 @@ js_int = "0.1.8"
[dependencies.ruma] [dependencies.ruma]
git = "https://github.com/ruma/ruma" git = "https://github.com/ruma/ruma"
features = ["client-api"] features = ["client-api"]
rev = "9190bff1d03fb188aa1d24502129f9dd19a824e6" rev = "ea2992a4120d34495d6f07f141350d8f2a3429d3"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
uuid = { version = "0.8.1", features = ["v4"] } uuid = { version = "0.8.1", features = ["v4"] }

View File

@ -302,18 +302,14 @@ impl OlmMachine {
for (user_id, user_devices) in &response.one_time_keys { for (user_id, user_devices) in &response.one_time_keys {
for (device_id, key_map) in user_devices { for (device_id, key_map) in user_devices {
let device: Device = match self.store.get_device(&user_id, device_id).await { let device: Device = match self.store.get_device(&user_id, device_id).await {
Ok(d) => { Ok(Some(d)) => d,
if let Some(d) = d { Ok(None) => {
d
} else {
warn!( warn!(
"Tried to create an Olm session for {} {}, but \ "Tried to create an Olm session for {} {}, but the device is unknown",
the device is unknown",
user_id, device_id user_id, device_id
); );
continue; continue;
} }
}
Err(e) => { Err(e) => {
warn!( warn!(
"Tried to create an Olm session for {} {}, but \ "Tried to create an Olm session for {} {}, but \
@ -1683,7 +1679,7 @@ mod test {
let plaintext = "It is a secret to everybody"; let plaintext = "It is a secret to everybody";
let content = MessageEventContent::Text(TextMessageEventContent::new_plain(plaintext)); let content = MessageEventContent::Text(TextMessageEventContent::plain(plaintext));
let encrypted_content = alice.encrypt(&room_id, content.clone()).await.unwrap(); let encrypted_content = alice.encrypt(&room_id, content.clone()).await.unwrap();

View File

@ -37,10 +37,7 @@ pub use olm_rs::{
use matrix_sdk_common::{ use matrix_sdk_common::{
events::{ events::{
room::{ room::{encrypted::EncryptedEventContent, message::MessageEventContent},
encrypted::{EncryptedEventContent, MegolmV1AesSha2Content},
message::MessageEventContent,
},
Algorithm, AnySyncRoomEvent, EventJson, EventType, SyncMessageEvent, Algorithm, AnySyncRoomEvent, EventJson, EventType, SyncMessageEvent,
}, },
identifiers::{DeviceId, RoomId}, identifiers::{DeviceId, RoomId},
@ -332,14 +329,15 @@ impl OutboundGroupSession {
let ciphertext = self.encrypt_helper(plaintext).await; let ciphertext = self.encrypt_helper(plaintext).await;
EncryptedEventContent::MegolmV1AesSha2(MegolmV1AesSha2Content::new( EncryptedEventContent::MegolmV1AesSha2(
matrix_sdk_common::events::room::encrypted::MegolmV1AesSha2ContentInit { matrix_sdk_common::events::room::encrypted::MegolmV1AesSha2ContentInit {
ciphertext, ciphertext,
sender_key: self.account_identity_keys.curve25519().to_owned(), sender_key: self.account_identity_keys.curve25519().to_owned(),
session_id: self.session_id().to_owned(), session_id: self.session_id().to_owned(),
device_id: (&*self.device_id).to_owned(), device_id: (&*self.device_id).to_owned(),
}, }
)) .into(),
)
} }
/// Check if the session has expired and if it should be rotated. /// Check if the session has expired and if it should be rotated.