Merge branch 'master' into crypto-improvements

master
Damir Jelić 2020-11-26 13:24:57 +01:00
commit 7ec5a5ad1a
27 changed files with 144 additions and 267 deletions

View File

@ -72,7 +72,7 @@ async-trait = "0.1.41"
async-std = { version = "1.6.5", features = ["unstable"] } async-std = { version = "1.6.5", features = ["unstable"] }
dirs = "3.0.1" dirs = "3.0.1"
matrix-sdk-test = { version = "0.1.0", path = "../matrix_sdk_test" } matrix-sdk-test = { version = "0.1.0", path = "../matrix_sdk_test" }
tokio = { version = "0.2.22", features = ["rt-threaded", "macros"] } tokio = { version = "0.2.22", default-features = false, features = ["rt-threaded", "macros"] }
serde_json = "1.0.59" serde_json = "1.0.59"
tracing-subscriber = "0.2.13" tracing-subscriber = "0.2.13"
tempfile = "3.1.0" tempfile = "3.1.0"

View File

@ -38,12 +38,8 @@ impl EventEmitter for CommandBot {
}; };
if msg_body.contains("!party") { if msg_body.contains("!party") {
let content = AnyMessageEventContent::RoomMessage(MessageEventContent::Text( let content = AnyMessageEventContent::RoomMessage(MessageEventContent::text_plain(
TextMessageEventContent { "🎉🎊🥳 let's PARTY!! 🥳🎊🎉",
body: "🎉🎊🥳 let's PARTY!! 🥳🎊🎉".to_string(),
formatted: None,
relates_to: None,
},
)); ));
// we clone here to hold the lock for as little time as possible. // we clone here to hold the lock for as little time as possible.
let room_id = room.read().await.room_id.clone(); let room_id = room.read().await.room_id.clone();

View File

@ -1467,10 +1467,10 @@ impl Client {
sync_settings: SyncSettings<'_>, sync_settings: SyncSettings<'_>,
) -> Result<sync_events::Response> { ) -> Result<sync_events::Response> {
let request = assign!(sync_events::Request::new(), { let request = assign!(sync_events::Request::new(), {
filter: sync_settings.filter, filter: sync_settings.filter.as_ref(),
since: sync_settings.token.as_deref(), since: sync_settings.token.as_deref(),
full_state: sync_settings.full_state, full_state: sync_settings.full_state,
set_presence: PresenceState::Online, set_presence: &PresenceState::Online,
timeout: sync_settings.timeout, timeout: sync_settings.timeout,
}); });
@ -1561,13 +1561,11 @@ impl Client {
#[instrument(skip(callback))] #[instrument(skip(callback))]
pub async fn sync_with_callback<C>( pub async fn sync_with_callback<C>(
&self, &self,
sync_settings: SyncSettings<'_>, mut sync_settings: SyncSettings<'_>,
callback: impl Fn(sync_events::Response) -> C, callback: impl Fn(sync_events::Response) -> C,
) where ) where
C: Future<Output = LoopCtrl>, C: Future<Output = LoopCtrl>,
{ {
let mut sync_settings = sync_settings;
let filter = sync_settings.filter;
let mut last_sync_time: Option<Instant> = None; let mut last_sync_time: Option<Instant> = None;
if sync_settings.token.is_none() { if sync_settings.token.is_none() {
@ -1575,6 +1573,7 @@ impl Client {
} }
loop { loop {
let filter = sync_settings.filter.clone();
let response = self.sync_once(sync_settings.clone()).await; let response = self.sync_once(sync_settings.clone()).await;
let response = match response { let response = match response {
@ -1651,8 +1650,8 @@ impl Client {
.await .await
.expect("No sync token found after initial sync"), .expect("No sync token found after initial sync"),
); );
if let Some(f) = filter.as_ref() { if let Some(f) = filter {
sync_settings = sync_settings.filter(*f); sync_settings = sync_settings.filter(f);
} }
} }
} }
@ -1895,12 +1894,12 @@ impl Client {
let (request, signature_request) = olm.bootstrap_cross_signing(false).await?; let (request, signature_request) = olm.bootstrap_cross_signing(false).await?;
let request = UploadSigningKeysRequest { let request = assign!(UploadSigningKeysRequest::new(), {
auth: auth_data, auth: auth_data,
master_key: request.master_key, master_key: request.master_key,
self_signing_key: request.self_signing_key, self_signing_key: request.self_signing_key,
user_signing_key: request.user_signing_key, user_signing_key: request.user_signing_key,
}; });
self.send(request).await?; self.send(request).await?;
self.send(signature_request).await?; self.send(signature_request).await?;
@ -2107,10 +2106,7 @@ mod test {
}, },
assign, assign,
directory::Filter, directory::Filter,
events::{ events::{room::message::MessageEventContent, AnyMessageEventContent},
room::message::{MessageEventContent, TextMessageEventContent},
AnyMessageEventContent,
},
identifiers::{event_id, room_id, user_id}, identifiers::{event_id, room_id, user_id},
thirdparty, thirdparty,
}; };
@ -2655,13 +2651,8 @@ mod test {
let room_id = room_id!("!testroom:example.org"); let room_id = room_id!("!testroom:example.org");
let content = AnyMessageEventContent::RoomMessage(MessageEventContent::Text( let content =
TextMessageEventContent { AnyMessageEventContent::RoomMessage(MessageEventContent::text_plain("Hello world"));
body: "Hello world".to_owned(),
relates_to: None,
formatted: None,
},
));
let txn_id = Uuid::new_v4(); let txn_id = Uuid::new_v4();
let response = client let response = client
.room_send(&room_id, content, Some(txn_id)) .room_send(&room_id, content, Some(txn_id))

View File

@ -25,7 +25,7 @@ docs = ["encryption", "sqlite_cryptostore", "messages"]
[dependencies] [dependencies]
async-trait = "0.1.41" async-trait = "0.1.41"
serde = "1.0.116" serde = "1.0.117"
serde_json = "1.0.59" serde_json = "1.0.59"
zeroize = "1.1.1" zeroize = "1.1.1"
tracing = "0.1.21" tracing = "0.1.21"
@ -51,7 +51,7 @@ tempfile = "3.1.0"
mockito = "0.27.0" mockito = "0.27.0"
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tokio = { version = "0.2.22", features = ["rt-threaded", "macros"] } tokio = { version = "0.2.22", default-features = false, features = ["rt-threaded", "macros"] }
[target.'cfg(target_arch = "wasm32")'.dev-dependencies] [target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.18" wasm-bindgen-test = "0.3.18"

View File

@ -2387,97 +2387,6 @@ mod test {
assert!(passed.load(Ordering::SeqCst)) assert!(passed.load(Ordering::SeqCst))
} }
#[async_test]
async fn test_unrecognized_custom_event() {
use super::*;
use crate::{EventEmitter, SyncRoom};
use matrix_sdk_common::{api::r0::sync::sync_events, locks::RwLock};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
struct EE(Arc<AtomicBool>);
#[async_trait]
impl EventEmitter for EE {
async fn on_custom_event(&self, room: SyncRoom, event: &CustomEvent<'_>) {
if let SyncRoom::Joined(_) = room {
if let CustomEvent::Message(custom) = event {
if custom.content.event_type == "m.reaction"
&& custom.content.json.get("m.relates_to").is_some()
{
self.0.swap(true, Ordering::SeqCst);
}
}
}
}
}
let room_id = get_room_id();
let passed = Arc::new(AtomicBool::default());
let emitter = EE(Arc::clone(&passed));
let mut client = get_client().await;
client.event_emitter = Arc::new(RwLock::new(Some(Box::new(emitter))));
// This is needed other wise the `EventBuilder` goes through a de/ser cycle and the `prev_content` is lost.
let event: &serde_json::Value = &test_json::REACTION;
let mut joined_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
let joined_room = serde_json::json!({
"summary": {},
"account_data": {
"events": [],
},
"ephemeral": {
"events": [],
},
"state": {
"events": [],
},
"timeline": {
"events": vec![ event ],
"limited": true,
"prev_batch": "t392-516_47314_0_7_1_1_1_11444_1"
},
"unread_notifications": {
"highlight_count": 0,
"notification_count": 11
}
});
joined_rooms.insert(room_id, joined_room);
let empty_room: HashMap<RoomId, serde_json::Value> = HashMap::new();
let body = serde_json::json!({
"device_one_time_keys_count": {},
"next_batch": "s526_47314_0_7_1_1_1_11444_1",
"device_lists": {
"changed": [],
"left": []
},
"rooms": {
"invite": empty_room,
"join": joined_rooms,
"leave": empty_room,
},
"to_device": {
"events": []
},
"presence": {
"events": []
}
});
let response = http::Response::builder()
.body(serde_json::to_vec(&body).unwrap())
.unwrap();
let mut sync = sync_events::Response::try_from(response).unwrap();
client.receive_sync_response(&mut sync).await.unwrap();
assert!(passed.load(Ordering::SeqCst))
}
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
#[async_test] #[async_test]
async fn message_queue_redaction_event_store_deser() { async fn message_queue_redaction_event_store_deser() {

View File

@ -934,7 +934,7 @@ impl Room {
member.currently_active = *currently_active; member.currently_active = *currently_active;
member.display_name = displayname.clone(); member.display_name = displayname.clone();
member.last_active_ago = *last_active_ago; member.last_active_ago = *last_active_ago;
member.presence = Some(*presence); member.presence = Some(presence.clone());
member.status_msg = status_msg.clone(); member.status_msg = status_msg.clone();
true true
@ -1091,6 +1091,7 @@ impl Describe for MembershipState {
Self::Join => "is a member of", Self::Join => "is a member of",
Self::Knock => "is requesting access to", Self::Knock => "is requesting access to",
Self::Leave => "has left", Self::Leave => "has left",
_ => "unhandled case of MembershipState",
} }
.to_string() .to_string()
} }
@ -1123,6 +1124,7 @@ impl Describe for MembershipChange {
Self::None => "did nothing in", Self::None => "did nothing in",
Self::NotImplemented => "NOT IMPLEMENTED", Self::NotImplemented => "NOT IMPLEMENTED",
Self::Error => "ERROR", Self::Error => "ERROR",
_ => "unhandled case of MembershipChange",
} }
.to_string() .to_string()
} }

View File

@ -21,17 +21,17 @@ js_int = "0.1.9"
[dependencies.ruma] [dependencies.ruma]
version = "0.0.1" version = "0.0.1"
git = "https://github.com/ruma/ruma" git = "https://github.com/ruma/ruma"
rev = "c0eee624311c12ee9c3eb14737988e3f0a60fb3f" rev = "48d1c9747561686e1c5627405780f6de01ee17b1"
features = ["client-api", "unstable-pre-spec", "unstable-exhaustive-types"] features = ["client-api", "unstable-pre-spec"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
uuid = { version = "0.8.1", features = ["v4", "serde"] } uuid = { version = "0.8.1", default-features = false, features = ["v4", "serde"] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio]
version = "0.2.22" version = "0.2.22"
default-features = false default-features = false
features = ["sync", "time", "fs"] features = ["sync"]
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
futures-locks = { version = "0.6.0", default-features = false } futures-locks = { version = "0.6.0", default-features = false }
uuid = { version = "0.8.1", features = ["v4", "wasm-bindgen"] } uuid = { version = "0.8.1", default-features = false, features = ["v4", "wasm-bindgen"] }

View File

@ -14,5 +14,5 @@ version = "0.1.0"
proc-macro = true proc-macro = true
[dependencies] [dependencies]
syn = "1.0.44" syn = { version = "1.0.45", features = ["proc-macro"], default-features = false }
quote = "1.0.7" quote = "1.0.7"

View File

@ -27,9 +27,8 @@ matrix-sdk-common = { version = "0.1.0", path = "../matrix_sdk_common" }
olm-rs = { version = "1.0.0", features = ["serde"] } olm-rs = { version = "1.0.0", features = ["serde"] }
getrandom = "0.2.0" getrandom = "0.2.0"
serde = { version = "1.0.116", features = ["derive", "rc"] } serde = { version = "1.0.117", features = ["derive", "rc"] }
serde_json = "1.0.59" serde_json = "1.0.59"
cjson = "0.1.1"
zeroize = { version = "1.1.1", features = ["zeroize_derive"] } zeroize = { version = "1.1.1", features = ["zeroize_derive"] }
url = "2.1.1" url = "2.1.1"
@ -40,17 +39,12 @@ atomic = "0.5.0"
dashmap = "3.11.10" dashmap = "3.11.10"
sha2 = "0.9.1" sha2 = "0.9.1"
aes-gcm = "0.7.0" aes-gcm = "0.7.0"
aes-ctr = "0.5.0" aes-ctr = "0.6.0"
pbkdf2 = { version = "0.5.0", default-features = false } pbkdf2 = { version = "0.6.0", default-features = false }
hmac = "0.9.0" hmac = "0.10.1"
base64 = "0.13.0" base64 = "0.13.0"
byteorder = "1.3.4" byteorder = "1.3.4"
[dependencies.tracing-futures]
version = "0.2.4"
default-features = false
features = ["std", "std-future"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.sqlx] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.sqlx]
git = "https://github.com/launchbadge/sqlx/" git = "https://github.com/launchbadge/sqlx/"
rev = "fd25a7530cf087e1529553ff854f192738db3461" rev = "fd25a7530cf087e1529553ff854f192738db3461"
@ -59,7 +53,7 @@ default-features = false
features = ["runtime-tokio", "sqlite", "macros"] features = ["runtime-tokio", "sqlite", "macros"]
[dev-dependencies] [dev-dependencies]
tokio = { version = "0.2.22", features = ["rt-threaded", "macros"] } tokio = { version = "0.2.22", default-features = false, features = ["rt-threaded", "macros"] }
futures = "0.3.6" futures = "0.3.6"
proptest = "0.10.1" proptest = "0.10.1"
serde_json = "1.0.59" serde_json = "1.0.59"

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use cjson::Error as CjsonError;
use matrix_sdk_common::identifiers::{DeviceId, Error as IdentifierError, UserId}; use matrix_sdk_common::identifiers::{DeviceId, Error as IdentifierError, UserId};
use olm_rs::errors::{OlmGroupSessionError, OlmSessionError}; use olm_rs::errors::{OlmGroupSessionError, OlmSessionError};
use serde_json::Error as SerdeError; use serde_json::Error as SerdeError;
@ -145,14 +144,11 @@ pub enum SignatureError {
#[error("the provided JSON object doesn't contain a signatures field")] #[error("the provided JSON object doesn't contain a signatures field")]
NoSignatureFound, NoSignatureFound,
#[error("the provided JSON object can't be converted to a canonical representation")] #[error("the signature didn't match the provided key")]
CanonicalJsonError(CjsonError), VerificationError,
#[error(transparent)] #[error(transparent)]
JsonError(#[from] SerdeError), JsonError(#[from] SerdeError),
#[error("the signature didn't match the provided key")]
VerificationError,
} }
#[derive(Error, Debug)] #[derive(Error, Debug)]
@ -177,9 +173,3 @@ pub(crate) enum SessionCreationError {
#[error("Error creating new Olm session for {0} {1}: {2:?}")] #[error("Error creating new Olm session for {0} {1}: {2:?}")]
OlmError(UserId, Box<DeviceId>, OlmSessionError), OlmError(UserId, Box<DeviceId>, OlmSessionError),
} }
impl From<CjsonError> for SignatureError {
fn from(error: CjsonError) -> Self {
Self::CanonicalJsonError(error)
}
}

View File

@ -27,7 +27,7 @@ use matrix_sdk_common::events::room::JsonWebKey;
use getrandom::getrandom; use getrandom::getrandom;
use aes_ctr::{ use aes_ctr::{
stream_cipher::{NewStreamCipher, SyncStreamCipher}, cipher::{NewStreamCipher, SyncStreamCipher},
Aes256Ctr, Aes256Ctr,
}; };
use base64::DecodeError; use base64::DecodeError;

View File

@ -20,7 +20,7 @@ use byteorder::{BigEndian, ReadBytesExt};
use getrandom::getrandom; use getrandom::getrandom;
use aes_ctr::{ use aes_ctr::{
stream_cipher::{NewStreamCipher, SyncStreamCipher}, cipher::{NewStreamCipher, SyncStreamCipher},
Aes256Ctr, Aes256Ctr,
}; };
use hmac::{Hmac, Mac, NewMac}; use hmac::{Hmac, Mac, NewMac};

View File

@ -60,7 +60,7 @@ use crate::{
pub struct ReadOnlyDevice { pub struct ReadOnlyDevice {
user_id: Arc<UserId>, user_id: Arc<UserId>,
device_id: Arc<Box<DeviceId>>, device_id: Arc<Box<DeviceId>>,
algorithms: Arc<Vec<EventEncryptionAlgorithm>>, algorithms: Arc<[EventEncryptionAlgorithm]>,
keys: Arc<BTreeMap<DeviceKeyId, String>>, keys: Arc<BTreeMap<DeviceKeyId, String>>,
pub(crate) signatures: Arc<BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>>, pub(crate) signatures: Arc<BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>>,
display_name: Arc<Option<String>>, display_name: Arc<Option<String>>,
@ -257,7 +257,7 @@ impl ReadOnlyDevice {
display_name: Arc::new(display_name), display_name: Arc::new(display_name),
trust_state: Arc::new(Atomic::new(trust_state)), trust_state: Arc::new(Atomic::new(trust_state)),
signatures: Arc::new(signatures), signatures: Arc::new(signatures),
algorithms: Arc::new(algorithms), algorithms: algorithms.into(),
keys: Arc::new(keys), keys: Arc::new(keys),
deleted: Arc::new(AtomicBool::new(false)), deleted: Arc::new(AtomicBool::new(false)),
} }
@ -419,7 +419,7 @@ impl ReadOnlyDevice {
let display_name = Arc::new(device_keys.unsigned.device_display_name.clone()); let display_name = Arc::new(device_keys.unsigned.device_display_name.clone());
self.algorithms = Arc::new(device_keys.algorithms.clone()); self.algorithms = device_keys.algorithms.as_slice().into();
self.keys = Arc::new(device_keys.keys.clone()); self.keys = Arc::new(device_keys.keys.clone());
self.signatures = Arc::new(device_keys.signatures.clone()); self.signatures = Arc::new(device_keys.signatures.clone());
self.display_name = display_name; self.display_name = display_name;
@ -443,14 +443,13 @@ impl ReadOnlyDevice {
} }
pub(crate) fn as_device_keys(&self) -> DeviceKeys { pub(crate) fn as_device_keys(&self) -> DeviceKeys {
DeviceKeys { DeviceKeys::new(
user_id: self.user_id().clone(), self.user_id().clone(),
device_id: self.device_id().into(), self.device_id().into(),
keys: self.keys().clone(), self.algorithms().to_vec(),
algorithms: self.algorithms().to_vec(), self.keys().clone(),
signatures: self.signatures().to_owned(), self.signatures().to_owned(),
unsigned: Default::default(), )
}
} }
pub(crate) fn as_signature_message(&self) -> Value { pub(crate) fn as_signature_message(&self) -> Value {
@ -467,7 +466,8 @@ impl ReadOnlyDevice {
&self, &self,
device_keys: &DeviceKeys, device_keys: &DeviceKeys,
) -> Result<(), SignatureError> { ) -> Result<(), SignatureError> {
self.is_signed_by_device(&mut json!(&device_keys)) let mut device_keys = serde_json::to_value(device_keys).unwrap();
self.is_signed_by_device(&mut device_keys)
} }
pub(crate) fn verify_one_time_key( pub(crate) fn verify_one_time_key(
@ -501,7 +501,7 @@ impl TryFrom<&DeviceKeys> for ReadOnlyDevice {
let device = Self { let device = Self {
user_id: Arc::new(device_keys.user_id.clone()), user_id: Arc::new(device_keys.user_id.clone()),
device_id: Arc::new(device_keys.device_id.clone()), device_id: Arc::new(device_keys.device_id.clone()),
algorithms: Arc::new(device_keys.algorithms.clone()), algorithms: device_keys.algorithms.as_slice().into(),
signatures: Arc::new(device_keys.signatures.clone()), signatures: Arc::new(device_keys.signatures.clone()),
keys: Arc::new(device_keys.keys.clone()), keys: Arc::new(device_keys.keys.clone()),
display_name: Arc::new(device_keys.unsigned.device_display_name.clone()), display_name: Arc::new(device_keys.unsigned.device_display_name.clone()),

View File

@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize};
use serde_json::value::to_raw_value; use serde_json::value::to_raw_value;
use std::{collections::BTreeMap, sync::Arc}; use std::{collections::BTreeMap, sync::Arc};
use thiserror::Error; use thiserror::Error;
use tracing::{error, info, instrument, trace, warn}; use tracing::{error, info, trace, warn};
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::to_device::DeviceIdOrAllDevices, api::r0::to_device::DeviceIdOrAllDevices,
@ -293,12 +293,11 @@ impl KeyRequestMachine {
} }
/// Handle a single incoming key request. /// Handle a single incoming key request.
#[instrument]
async fn handle_key_request( async fn handle_key_request(
&self, &self,
event: &ToDeviceEvent<RoomKeyRequestEventContent>, event: &ToDeviceEvent<RoomKeyRequestEventContent>,
) -> OlmResult<Option<Session>> { ) -> OlmResult<Option<Session>> {
let key_info = match event.content.action { let key_info = match &event.content.action {
Action::Request => { Action::Request => {
if let Some(info) = &event.content.body { if let Some(info) = &event.content.body {
info info
@ -313,6 +312,10 @@ impl KeyRequestMachine {
} }
// We ignore cancellations here since there's nothing to serve. // We ignore cancellations here since there's nothing to serve.
Action::CancelRequest => return Ok(None), Action::CancelRequest => return Ok(None),
action => {
warn!("Unknown room key request action: {:?}", action);
return Ok(None);
}
}; };
let session = self let session = self

View File

@ -17,8 +17,7 @@ use std::path::Path;
use std::{collections::BTreeMap, mem, sync::Arc}; use std::{collections::BTreeMap, mem, sync::Arc};
use dashmap::DashMap; use dashmap::DashMap;
use matrix_sdk_common::locks::Mutex; use tracing::{debug, error, info, trace, warn};
use tracing::{debug, error, info, instrument, trace, warn};
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::{ api::r0::{
@ -40,6 +39,7 @@ use matrix_sdk_common::{
DeviceId, DeviceIdBox, DeviceKeyAlgorithm, EventEncryptionAlgorithm, RoomId, UserId, DeviceId, DeviceIdBox, DeviceKeyAlgorithm, EventEncryptionAlgorithm, RoomId, UserId,
}, },
js_int::UInt, js_int::UInt,
locks::Mutex,
uuid::Uuid, uuid::Uuid,
Raw, Raw,
}; };
@ -262,7 +262,6 @@ impl OlmMachine {
/// ///
/// * `device_id` - The unique id of the device that owns this machine. /// * `device_id` - The unique id of the device that owns this machine.
#[cfg(feature = "sqlite_cryptostore")] #[cfg(feature = "sqlite_cryptostore")]
#[instrument(skip(path, passphrase))]
#[cfg_attr(feature = "docs", doc(cfg(r#sqlite_cryptostore)))] #[cfg_attr(feature = "docs", doc(cfg(r#sqlite_cryptostore)))]
pub async fn new_with_default_store( pub async fn new_with_default_store(
user_id: &UserId, user_id: &UserId,
@ -460,7 +459,6 @@ impl OlmMachine {
/// ///
/// * `response` - The keys upload response of the request that the client /// * `response` - The keys upload response of the request that the client
/// performed. /// performed.
#[instrument]
async fn receive_keys_upload_response( async fn receive_keys_upload_response(
&self, &self,
response: &upload_keys::Response, response: &upload_keys::Response,
@ -777,7 +775,6 @@ impl OlmMachine {
/// * `response` - The sync latest sync response. /// * `response` - The sync latest sync response.
/// ///
/// [`decrypt_room_event`]: #method.decrypt_room_event /// [`decrypt_room_event`]: #method.decrypt_room_event
#[instrument(skip(response))]
pub async fn receive_sync_response(&self, response: &mut SyncResponse) -> OlmResult<()> { pub async fn receive_sync_response(&self, response: &mut SyncResponse) -> OlmResult<()> {
// Remove verification objects that have expired or are done. // Remove verification objects that have expired or are done.
self.verification_machine.garbage_collect(); self.verification_machine.garbage_collect();

View File

@ -52,7 +52,7 @@ use olm_rs::{
}; };
use crate::{ use crate::{
error::{EventError, OlmResult, SessionCreationError, SignatureError}, error::{EventError, OlmResult, SessionCreationError},
identities::ReadOnlyDevice, identities::ReadOnlyDevice,
requests::UploadSigningKeysRequest, requests::UploadSigningKeysRequest,
store::Store, store::Store,
@ -651,7 +651,15 @@ impl ReadOnlyAccount {
/// uploaded. /// uploaded.
pub(crate) async fn device_keys(&self) -> DeviceKeys { pub(crate) async fn device_keys(&self) -> DeviceKeys {
let mut device_keys = self.unsigned_device_keys(); let mut device_keys = self.unsigned_device_keys();
let jsond_device_keys = serde_json::to_value(&device_keys).unwrap();
// Create a copy of the device keys containing only fields that will
// get signed.
let json_device_keys = json!({
"user_id": device_keys.user_id,
"device_id": device_keys.device_id,
"algorithms": device_keys.algorithms,
"keys": device_keys.keys,
});
device_keys device_keys
.signatures .signatures
@ -659,9 +667,7 @@ impl ReadOnlyAccount {
.or_insert_with(BTreeMap::new) .or_insert_with(BTreeMap::new)
.insert( .insert(
DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, &self.device_id), DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, &self.device_id),
self.sign_json(jsond_device_keys) self.sign_json(&json_device_keys).await,
.await
.expect("Can't sign own device keys"),
); );
device_keys device_keys
@ -688,13 +694,8 @@ impl ReadOnlyAccount {
/// # Panic /// # Panic
/// ///
/// Panics if the json value can't be serialized. /// Panics if the json value can't be serialized.
pub async fn sign_json(&self, mut json: Value) -> Result<String, SignatureError> { pub async fn sign_json(&self, json: &Value) -> String {
let json_object = json.as_object_mut().ok_or(SignatureError::NotAnObject)?; self.sign(&json.to_string()).await
let _ = json_object.remove("unsigned");
let _ = json_object.remove("signatures");
let canonical_json = cjson::to_string(&json)?;
Ok(self.sign(&canonical_json).await)
} }
pub(crate) async fn signed_one_time_keys_helper( pub(crate) async fn signed_one_time_keys_helper(
@ -708,10 +709,7 @@ impl ReadOnlyAccount {
"key": key, "key": key,
}); });
let signature = self let signature = self.sign_json(&key_json).await;
.sign_json(key_json)
.await
.expect("Can't sign own one-time keys");
let mut signature_map = BTreeMap::new(); let mut signature_map = BTreeMap::new();
@ -779,8 +777,8 @@ impl ReadOnlyAccount {
device_id: self.device_id.clone(), device_id: self.device_id.clone(),
our_identity_keys: self.identity_keys.clone(), our_identity_keys: self.identity_keys.clone(),
inner: Arc::new(Mutex::new(session)), inner: Arc::new(Mutex::new(session)),
session_id: Arc::new(session_id), session_id: session_id.into(),
sender_key: Arc::new(their_identity_key.to_owned()), sender_key: their_identity_key.into(),
creation_time: Arc::new(now), creation_time: Arc::new(now),
last_use_time: Arc::new(now), last_use_time: Arc::new(now),
}) })
@ -884,8 +882,8 @@ impl ReadOnlyAccount {
device_id: self.device_id.clone(), device_id: self.device_id.clone(),
our_identity_keys: self.identity_keys.clone(), our_identity_keys: self.identity_keys.clone(),
inner: Arc::new(Mutex::new(session)), inner: Arc::new(Mutex::new(session)),
session_id: Arc::new(session_id), session_id: session_id.into(),
sender_key: Arc::new(their_identity_key.to_owned()), sender_key: their_identity_key.into(),
creation_time: Arc::new(now), creation_time: Arc::new(now),
last_use_time: Arc::new(now), last_use_time: Arc::new(now),
}) })

View File

@ -56,8 +56,8 @@ use crate::error::{EventError, MegolmResult};
#[derive(Clone)] #[derive(Clone)]
pub struct InboundGroupSession { pub struct InboundGroupSession {
inner: Arc<Mutex<OlmInboundGroupSession>>, inner: Arc<Mutex<OlmInboundGroupSession>>,
session_id: Arc<String>, session_id: Arc<str>,
pub(crate) sender_key: Arc<String>, pub(crate) sender_key: Arc<str>,
pub(crate) signing_key: Arc<BTreeMap<DeviceKeyAlgorithm, String>>, pub(crate) signing_key: Arc<BTreeMap<DeviceKeyAlgorithm, String>>,
pub(crate) room_id: Arc<RoomId>, pub(crate) room_id: Arc<RoomId>,
forwarding_chains: Arc<Mutex<Option<Vec<String>>>>, forwarding_chains: Arc<Mutex<Option<Vec<String>>>>,
@ -95,8 +95,8 @@ impl InboundGroupSession {
Ok(InboundGroupSession { Ok(InboundGroupSession {
inner: Arc::new(Mutex::new(session)), inner: Arc::new(Mutex::new(session)),
session_id: Arc::new(session_id), session_id: session_id.into(),
sender_key: Arc::new(sender_key.to_owned()), sender_key: sender_key.to_owned().into(),
signing_key: Arc::new(keys), signing_key: Arc::new(keys),
room_id: Arc::new(room_id.clone()), room_id: Arc::new(room_id.clone()),
forwarding_chains: Arc::new(Mutex::new(None)), forwarding_chains: Arc::new(Mutex::new(None)),
@ -145,8 +145,8 @@ impl InboundGroupSession {
Ok(InboundGroupSession { Ok(InboundGroupSession {
inner: Arc::new(Mutex::new(session)), inner: Arc::new(Mutex::new(session)),
session_id: Arc::new(content.session_id.clone()), session_id: content.session_id.as_str().into(),
sender_key: Arc::new(content.sender_key.clone()), sender_key: content.sender_key.as_str().into(),
signing_key: Arc::new(sender_claimed_key), signing_key: Arc::new(sender_claimed_key),
room_id: Arc::new(content.room_id.clone()), room_id: Arc::new(content.room_id.clone()),
forwarding_chains: Arc::new(Mutex::new(Some(forwarding_chains))), forwarding_chains: Arc::new(Mutex::new(Some(forwarding_chains))),
@ -225,8 +225,8 @@ impl InboundGroupSession {
Ok(InboundGroupSession { Ok(InboundGroupSession {
inner: Arc::new(Mutex::new(session)), inner: Arc::new(Mutex::new(session)),
session_id: Arc::new(session_id), session_id: session_id.into(),
sender_key: Arc::new(pickle.sender_key), sender_key: pickle.sender_key.into(),
signing_key: Arc::new(pickle.signing_key), signing_key: Arc::new(pickle.signing_key),
room_id: Arc::new(pickle.room_id), room_id: Arc::new(pickle.room_id),
forwarding_chains: Arc::new(Mutex::new(pickle.forwarding_chains)), forwarding_chains: Arc::new(Mutex::new(pickle.forwarding_chains)),
@ -377,8 +377,8 @@ impl TryFrom<ExportedRoomKey> for InboundGroupSession {
Ok(InboundGroupSession { Ok(InboundGroupSession {
inner: Arc::new(Mutex::new(session)), inner: Arc::new(Mutex::new(session)),
session_id: Arc::new(key.session_id), session_id: key.session_id.into(),
sender_key: Arc::new(key.sender_key), sender_key: key.sender_key.into(),
signing_key: Arc::new(key.sender_claimed_keys), signing_key: Arc::new(key.sender_claimed_keys),
room_id: Arc::new(key.room_id), room_id: Arc::new(key.room_id),
forwarding_chains: Arc::new(Mutex::new(forwarding_chains)), forwarding_chains: Arc::new(Mutex::new(forwarding_chains)),

View File

@ -99,7 +99,7 @@ pub struct OutboundGroupSession {
inner: Arc<Mutex<OlmOutboundGroupSession>>, inner: Arc<Mutex<OlmOutboundGroupSession>>,
device_id: Arc<DeviceIdBox>, device_id: Arc<DeviceIdBox>,
account_identity_keys: Arc<IdentityKeys>, account_identity_keys: Arc<IdentityKeys>,
session_id: Arc<String>, session_id: Arc<str>,
room_id: Arc<RoomId>, room_id: Arc<RoomId>,
pub(crate) creation_time: Arc<Instant>, pub(crate) creation_time: Arc<Instant>,
message_count: Arc<AtomicU64>, message_count: Arc<AtomicU64>,
@ -140,7 +140,7 @@ impl OutboundGroupSession {
room_id: Arc::new(room_id.to_owned()), room_id: Arc::new(room_id.to_owned()),
device_id, device_id,
account_identity_keys: identity_keys, account_identity_keys: identity_keys,
session_id: Arc::new(session_id), session_id: session_id.into(),
creation_time: Arc::new(Instant::now()), creation_time: Arc::new(Instant::now()),
message_count: Arc::new(AtomicU64::new(0)), message_count: Arc::new(AtomicU64::new(0)),
shared: Arc::new(AtomicBool::new(false)), shared: Arc::new(AtomicBool::new(false)),
@ -240,12 +240,7 @@ impl OutboundGroupSession {
"type": content.event_type(), "type": content.event_type(),
}); });
let plaintext = cjson::to_string(&json_content).unwrap_or_else(|_| { let plaintext = json_content.to_string();
panic!(format!(
"Can't serialize {} to canonical JSON",
json_content
))
});
let ciphertext = self.encrypt_helper(plaintext).await; let ciphertext = self.encrypt_helper(plaintext).await;

View File

@ -46,8 +46,8 @@ pub struct Session {
pub(crate) device_id: Arc<Box<DeviceId>>, pub(crate) device_id: Arc<Box<DeviceId>>,
pub(crate) our_identity_keys: Arc<IdentityKeys>, pub(crate) our_identity_keys: Arc<IdentityKeys>,
pub(crate) inner: Arc<Mutex<OlmSession>>, pub(crate) inner: Arc<Mutex<OlmSession>>,
pub(crate) session_id: Arc<String>, pub(crate) session_id: Arc<str>,
pub(crate) sender_key: Arc<String>, pub(crate) sender_key: Arc<str>,
pub(crate) creation_time: Arc<Instant>, pub(crate) creation_time: Arc<Instant>,
pub(crate) last_use_time: Arc<Instant>, pub(crate) last_use_time: Arc<Instant>,
} }
@ -126,7 +126,7 @@ impl Session {
"content": content, "content": content,
}); });
let plaintext = cjson::to_string(&payload) let plaintext = serde_json::to_string(&payload)
.unwrap_or_else(|_| panic!(format!("Can't serialize {} to canonical JSON", payload))); .unwrap_or_else(|_| panic!(format!("Can't serialize {} to canonical JSON", payload)));
let ciphertext = self.encrypt_helper(&plaintext).await.to_tuple(); let ciphertext = self.encrypt_helper(&plaintext).await.to_tuple();
@ -232,8 +232,8 @@ impl Session {
device_id, device_id,
our_identity_keys, our_identity_keys,
inner: Arc::new(Mutex::new(session)), inner: Arc::new(Mutex::new(session)),
session_id: Arc::new(session_id), session_id: session_id.into(),
sender_key: Arc::new(pickle.sender_key), sender_key: pickle.sender_key.into(),
creation_time: Arc::new(creation_time), creation_time: Arc::new(creation_time),
last_use_time: Arc::new(last_use_time), last_use_time: Arc::new(last_use_time),
}) })

View File

@ -149,7 +149,7 @@ impl PrivateCrossSigningIdentity {
.sign_user(&user_identity) .sign_user(&user_identity)
.await?; .await?;
Ok(SignatureUploadRequest { signed_keys }) Ok(SignatureUploadRequest::new(signed_keys))
} }
/// Sign the given device keys with this identity. /// Sign the given device keys with this identity.
@ -192,7 +192,7 @@ impl PrivateCrossSigningIdentity {
serde_json::to_value(device_keys)?, serde_json::to_value(device_keys)?,
); );
Ok(SignatureUploadRequest { signed_keys }) Ok(SignatureUploadRequest::new(signed_keys))
} }
/// Create a new identity for the given Olm Account. /// Create a new identity for the given Olm Account.
@ -215,11 +215,11 @@ impl PrivateCrossSigningIdentity {
master.cross_signing_key(account.user_id().to_owned(), KeyUsage::Master); master.cross_signing_key(account.user_id().to_owned(), KeyUsage::Master);
let signature = account let signature = account
.sign_json( .sign_json(
serde_json::to_value(&public_key) &serde_json::to_value(&public_key)
.expect("Can't convert own public master key to json"), .expect("Can't convert own public master key to json"),
) )
.await .await;
.expect("Can't sign own public master key");
public_key public_key
.signatures .signatures
.entry(account.user_id().to_owned()) .entry(account.user_id().to_owned())

View File

@ -23,7 +23,7 @@ use matrix_sdk_common::{
identifiers::{DeviceKeyAlgorithm, DeviceKeyId}, identifiers::{DeviceKeyAlgorithm, DeviceKeyId},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{Error as JsonError, Value}; use serde_json::{json, Error as JsonError, Value};
use std::{collections::BTreeMap, sync::Arc}; use std::{collections::BTreeMap, sync::Arc};
use thiserror::Error; use thiserror::Error;
use zeroize::Zeroizing; use zeroize::Zeroizing;
@ -171,14 +171,13 @@ impl MasterSigning {
pub async fn sign_subkey<'a>(&self, subkey: &mut CrossSigningKey) { pub async fn sign_subkey<'a>(&self, subkey: &mut CrossSigningKey) {
// TODO create a borrowed version of a cross singing key. // TODO create a borrowed version of a cross singing key.
let subkey_wihtout_signatures = CrossSigningKey { let subkey_wihtout_signatures = json!({
user_id: subkey.user_id.clone(), "user_id": subkey.user_id.clone(),
keys: subkey.keys.clone(), "keys": subkey.keys.clone(),
usage: subkey.usage.clone(), "usage": subkey.usage.clone(),
signatures: BTreeMap::new(), });
};
let message = cjson::to_string(&subkey_wihtout_signatures) let message = serde_json::to_string(&subkey_wihtout_signatures)
.expect("Can't serialize cross signing subkey"); .expect("Can't serialize cross signing subkey");
let signature = self.inner.sign(&message).await; let signature = self.inner.sign(&message).await;
@ -257,7 +256,15 @@ impl SelfSigning {
} }
pub async fn sign_device(&self, device_keys: &mut DeviceKeys) -> Result<(), SignatureError> { pub async fn sign_device(&self, device_keys: &mut DeviceKeys) -> Result<(), SignatureError> {
let json_device = serde_json::to_value(&device_keys)?; // Create a copy of the device keys containing only fields that will
// get signed.
let json_device = json!({
"user_id": device_keys.user_id,
"device_id": device_keys.device_id,
"algorithms": device_keys.algorithms,
"keys": device_keys.keys,
});
let signature = self.sign_device_helper(json_device).await?; let signature = self.sign_device_helper(json_device).await?;
device_keys device_keys
@ -407,7 +414,7 @@ impl Signing {
pub async fn sign_json(&self, mut json: Value) -> Result<Signature, SignatureError> { pub async fn sign_json(&self, mut json: Value) -> Result<Signature, SignatureError> {
let json_object = json.as_object_mut().ok_or(SignatureError::NotAnObject)?; let json_object = json.as_object_mut().ok_or(SignatureError::NotAnObject)?;
let _ = json_object.remove("signatures"); let _ = json_object.remove("signatures");
let canonical_json = cjson::to_string(json_object)?; let canonical_json = serde_json::to_string(json_object)?;
Ok(self.sign(&canonical_json).await) Ok(self.sign(&canonical_json).await)
} }

View File

@ -63,7 +63,7 @@ impl Utility {
let unsigned = json_object.remove("unsigned"); let unsigned = json_object.remove("unsigned");
let signatures = json_object.remove("signatures"); let signatures = json_object.remove("signatures");
let canonical_json = cjson::to_string(json_object)?; let canonical_json = serde_json::to_string(json_object)?;
if let Some(u) = unsigned { if let Some(u) = unsigned {
json_object.insert("unsigned".to_string(), u); json_object.insert("unsigned".to_string(), u);

View File

@ -405,10 +405,7 @@ mod test {
.or_insert_with(BTreeMap::new) .or_insert_with(BTreeMap::new)
.insert(bob.device_id().into(), one_time); .insert(bob.device_id().into(), one_time);
let response = KeyClaimResponse { let response = KeyClaimResponse::new(one_time_keys);
failures: BTreeMap::new(),
one_time_keys,
};
manager manager
.receive_keys_claim_response(&response) .receive_keys_claim_response(&response)
@ -476,10 +473,7 @@ mod test {
.or_insert_with(BTreeMap::new) .or_insert_with(BTreeMap::new)
.insert(bob.device_id().into(), one_time); .insert(bob.device_id().into(), one_time);
let response = KeyClaimResponse { let response = KeyClaimResponse::new(one_time_keys);
failures: BTreeMap::new(),
one_time_keys,
};
assert!(manager.outgoing_to_device_requests.is_empty()); assert!(manager.outgoing_to_device_requests.is_empty());

View File

@ -15,7 +15,7 @@
use std::{ use std::{
collections::{BTreeMap, HashMap, HashSet}, collections::{BTreeMap, HashMap, HashSet},
convert::TryFrom, convert::TryFrom,
path::{Path, PathBuf}, path::Path,
result::Result as StdResult, result::Result as StdResult,
sync::{Arc, Mutex as SyncMutex}, sync::{Arc, Mutex as SyncMutex},
}; };
@ -58,7 +58,7 @@ pub struct SqliteStore {
user_id: Arc<UserId>, user_id: Arc<UserId>,
device_id: Arc<Box<DeviceId>>, device_id: Arc<Box<DeviceId>>,
account_info: Arc<SyncMutex<Option<AccountInfo>>>, account_info: Arc<SyncMutex<Option<AccountInfo>>>,
path: Arc<PathBuf>, path: Arc<Path>,
sessions: SessionStore, sessions: SessionStore,
tracked_users: Arc<DashSet<UserId>>, tracked_users: Arc<DashSet<UserId>>,
@ -155,7 +155,7 @@ impl SqliteStore {
device_id: Arc::new(device_id.into()), device_id: Arc::new(device_id.into()),
account_info: Arc::new(SyncMutex::new(None)), account_info: Arc::new(SyncMutex::new(None)),
sessions: SessionStore::new(), sessions: SessionStore::new(),
path: Arc::new(path), path: path.into(),
connection: Arc::new(Mutex::new(connection)), connection: Arc::new(Mutex::new(connection)),
tracked_users: Arc::new(DashSet::new()), tracked_users: Arc::new(DashSet::new()),
users_for_key_query: Arc::new(DashSet::new()), users_for_key_query: Arc::new(DashSet::new()),

View File

@ -66,7 +66,7 @@ pub struct Sas {
private_identity: PrivateCrossSigningIdentity, private_identity: PrivateCrossSigningIdentity,
other_device: ReadOnlyDevice, other_device: ReadOnlyDevice,
other_identity: Option<UserIdentities>, other_identity: Option<UserIdentities>,
flow_id: Arc<String>, flow_id: Arc<str>,
} }
impl Sas { impl Sas {
@ -524,11 +524,11 @@ impl Sas {
content content
} }
pub(crate) fn verified_devices(&self) -> Option<Arc<Vec<ReadOnlyDevice>>> { pub(crate) fn verified_devices(&self) -> Option<Arc<[ReadOnlyDevice]>> {
self.inner.lock().unwrap().verified_devices() self.inner.lock().unwrap().verified_devices()
} }
pub(crate) fn verified_identities(&self) -> Option<Arc<Vec<UserIdentities>>> { pub(crate) fn verified_identities(&self) -> Option<Arc<[UserIdentities]>> {
self.inner.lock().unwrap().verified_identities() self.inner.lock().unwrap().verified_identities()
} }
@ -723,7 +723,7 @@ impl InnerSas {
} }
} }
fn verification_flow_id(&self) -> Arc<String> { fn verification_flow_id(&self) -> Arc<str> {
match self { match self {
InnerSas::Created(s) => s.verification_flow_id.clone(), InnerSas::Created(s) => s.verification_flow_id.clone(),
InnerSas::Started(s) => s.verification_flow_id.clone(), InnerSas::Started(s) => s.verification_flow_id.clone(),
@ -752,7 +752,7 @@ impl InnerSas {
} }
} }
fn verified_devices(&self) -> Option<Arc<Vec<ReadOnlyDevice>>> { fn verified_devices(&self) -> Option<Arc<[ReadOnlyDevice]>> {
if let InnerSas::Done(s) = self { if let InnerSas::Done(s) = self {
Some(s.verified_devices()) Some(s.verified_devices())
} else { } else {
@ -760,7 +760,7 @@ impl InnerSas {
} }
} }
fn verified_identities(&self) -> Option<Arc<Vec<UserIdentities>>> { fn verified_identities(&self) -> Option<Arc<[UserIdentities]>> {
if let InnerSas::Done(s) = self { if let InnerSas::Done(s) = self {
Some(s.verified_identities()) Some(s.verified_identities())
} else { } else {

View File

@ -144,7 +144,7 @@ pub struct SasState<S: Clone> {
/// ///
/// This will be the transaction id for to-device events and the relates_to /// This will be the transaction id for to-device events and the relates_to
/// field for in-room events. /// field for in-room events.
pub verification_flow_id: Arc<String>, pub verification_flow_id: Arc<str>,
/// The SAS state we're in. /// The SAS state we're in.
state: Arc<S>, state: Arc<S>,
@ -209,8 +209,8 @@ pub struct Confirmed {
pub struct MacReceived { pub struct MacReceived {
we_started: bool, we_started: bool,
their_pubkey: String, their_pubkey: String,
verified_devices: Arc<Vec<ReadOnlyDevice>>, verified_devices: Arc<[ReadOnlyDevice]>,
verified_master_keys: Arc<Vec<UserIdentities>>, verified_master_keys: Arc<[UserIdentities]>,
} }
/// The SAS state indicating that the verification finished successfully. /// The SAS state indicating that the verification finished successfully.
@ -219,8 +219,8 @@ pub struct MacReceived {
/// the master keys in the verified devices list. /// the master keys in the verified devices list.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Done { pub struct Done {
verified_devices: Arc<Vec<ReadOnlyDevice>>, verified_devices: Arc<[ReadOnlyDevice]>,
verified_master_keys: Arc<Vec<UserIdentities>>, verified_master_keys: Arc<[UserIdentities]>,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -269,7 +269,7 @@ impl<S: Clone> SasState<S> {
} }
fn check_event(&self, sender: &UserId, flow_id: &str) -> Result<(), CancelCode> { fn check_event(&self, sender: &UserId, flow_id: &str) -> Result<(), CancelCode> {
if flow_id != *self.verification_flow_id { if *flow_id != *self.verification_flow_id {
Err(CancelCode::UnknownTransaction) Err(CancelCode::UnknownTransaction)
} else if sender != self.ids.other_device.user_id() { } else if sender != self.ids.other_device.user_id() {
Err(CancelCode::UserMismatch) Err(CancelCode::UserMismatch)
@ -303,7 +303,7 @@ impl SasState<Created> {
other_device, other_device,
other_identity, other_identity,
}, },
verification_flow_id: Arc::new(verification_flow_id), verification_flow_id: verification_flow_id.into(),
creation_time: Arc::new(Instant::now()), creation_time: Arc::new(Instant::now()),
last_event_time: Arc::new(Instant::now()), last_event_time: Arc::new(Instant::now()),
@ -351,7 +351,7 @@ impl SasState<Created> {
let accepted_protocols = let accepted_protocols =
AcceptedProtocols::try_from(content.clone()).map_err(|c| self.clone().cancel(c))?; AcceptedProtocols::try_from(content.clone()).map_err(|c| self.clone().cancel(c))?;
let json_start_content = cjson::to_string(&self.as_content()) let json_start_content = serde_json::to_string(&self.as_content())
.expect("Can't deserialize start event content"); .expect("Can't deserialize start event content");
Ok(SasState { Ok(SasState {
@ -396,7 +396,8 @@ impl SasState<Started> {
let sas = OlmSas::new(); let sas = OlmSas::new();
let utility = OlmUtility::new(); let utility = OlmUtility::new();
let json_content = cjson::to_string(&event.content).expect("Can't serialize content"); let json_content =
serde_json::to_string(&event.content).expect("Can't serialize content");
let pubkey = sas.public_key(); let pubkey = sas.public_key();
let commitment = utility.sha256_utf8_msg(&format!("{}{}", pubkey, json_content)); let commitment = utility.sha256_utf8_msg(&format!("{}{}", pubkey, json_content));
@ -412,7 +413,7 @@ impl SasState<Started> {
creation_time: Arc::new(Instant::now()), creation_time: Arc::new(Instant::now()),
last_event_time: Arc::new(Instant::now()), last_event_time: Arc::new(Instant::now()),
verification_flow_id: Arc::new(event.content.transaction_id.clone()), verification_flow_id: event.content.transaction_id.as_str().into(),
state: Arc::new(Started { state: Arc::new(Started {
protocol_definitions: content.clone(), protocol_definitions: content.clone(),
@ -451,7 +452,7 @@ impl SasState<Started> {
other_identity, other_identity,
}, },
verification_flow_id: Arc::new(event.content.transaction_id.clone()), verification_flow_id: event.content.transaction_id.as_str().into(),
state: Arc::new(Canceled::new(CancelCode::UnknownMethod)), state: Arc::new(Canceled::new(CancelCode::UnknownMethod)),
}) })
} }
@ -656,8 +657,8 @@ impl SasState<KeyReceived> {
state: Arc::new(MacReceived { state: Arc::new(MacReceived {
we_started: self.state.we_started, we_started: self.state.we_started,
their_pubkey: self.state.their_pubkey.clone(), their_pubkey: self.state.their_pubkey.clone(),
verified_devices: Arc::new(devices), verified_devices: devices.into(),
verified_master_keys: Arc::new(master_keys), verified_master_keys: master_keys.into(),
}), }),
}) })
} }
@ -711,8 +712,8 @@ impl SasState<Confirmed> {
ids: self.ids, ids: self.ids,
state: Arc::new(Done { state: Arc::new(Done {
verified_devices: Arc::new(devices), verified_devices: devices.into(),
verified_master_keys: Arc::new(master_keys), verified_master_keys: master_keys.into(),
}), }),
}) })
} }
@ -791,12 +792,12 @@ impl SasState<Done> {
} }
/// Get the list of verified devices. /// Get the list of verified devices.
pub fn verified_devices(&self) -> Arc<Vec<ReadOnlyDevice>> { pub fn verified_devices(&self) -> Arc<[ReadOnlyDevice]> {
self.state.verified_devices.clone() self.state.verified_devices.clone()
} }
/// Get the list of verified identities. /// Get the list of verified identities.
pub fn verified_identities(&self) -> Arc<Vec<UserIdentities>> { pub fn verified_identities(&self) -> Arc<[UserIdentities]> {
self.state.verified_master_keys.clone() self.state.verified_master_keys.clone()
} }
} }

View File

@ -16,4 +16,4 @@ http = "0.2.1"
matrix-sdk-common = { version = "0.1.0", path = "../matrix_sdk_common" } matrix-sdk-common = { version = "0.1.0", path = "../matrix_sdk_common" }
matrix-sdk-test-macros = { version = "0.1.0", path = "../matrix_sdk_test_macros" } matrix-sdk-test-macros = { version = "0.1.0", path = "../matrix_sdk_test_macros" }
lazy_static = "1.4.0" lazy_static = "1.4.0"
serde = "1.0.116" serde = "1.0.117"