From 44cc1cef71ec03144c0d0763d00bd2eb63e07ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 30 Oct 2020 11:41:48 +0100 Subject: [PATCH] crypto: Let devices hold on to the private identity. --- matrix_sdk_crypto/src/identities/device.rs | 6 +++++- matrix_sdk_crypto/src/identities/user.rs | 4 +++- matrix_sdk_crypto/src/store/mod.rs | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/matrix_sdk_crypto/src/identities/device.rs b/matrix_sdk_crypto/src/identities/device.rs index f9af780d..568d80f9 100644 --- a/matrix_sdk_crypto/src/identities/device.rs +++ b/matrix_sdk_crypto/src/identities/device.rs @@ -40,7 +40,7 @@ use serde_json::{json, Value}; use tracing::warn; use crate::{ - olm::{InboundGroupSession, Session}, + olm::{InboundGroupSession, PrivateCrossSigningIdentity, Session}, store::{Changes, DeviceChanges}, }; #[cfg(test)] @@ -72,6 +72,7 @@ pub struct ReadOnlyDevice { /// A device represents a E2EE capable client of an user. pub struct Device { pub(crate) inner: ReadOnlyDevice, + pub(crate) private_identity: Arc>, pub(crate) verification_machine: VerificationMachine, pub(crate) own_identity: Option, pub(crate) device_owner_identity: Option, @@ -179,6 +180,7 @@ impl Device { #[derive(Debug)] pub struct UserDevices { pub(crate) inner: HashMap, + pub(crate) private_identity: Arc>, pub(crate) verification_machine: VerificationMachine, pub(crate) own_identity: Option, pub(crate) device_owner_identity: Option, @@ -189,6 +191,7 @@ impl UserDevices { pub fn get(&self, device_id: &DeviceId) -> Option { self.inner.get(device_id).map(|d| Device { inner: d.clone(), + private_identity: self.private_identity.clone(), verification_machine: self.verification_machine.clone(), own_identity: self.own_identity.clone(), device_owner_identity: self.device_owner_identity.clone(), @@ -204,6 +207,7 @@ impl UserDevices { pub fn devices(&self) -> impl Iterator + '_ { self.inner.values().map(move |d| Device { inner: d.clone(), + private_identity: self.private_identity.clone(), verification_machine: self.verification_machine.clone(), own_identity: self.own_identity.clone(), device_owner_identity: self.device_owner_identity.clone(), diff --git a/matrix_sdk_crypto/src/identities/user.rs b/matrix_sdk_crypto/src/identities/user.rs index 6d34dc62..02d80297 100644 --- a/matrix_sdk_crypto/src/identities/user.rs +++ b/matrix_sdk_crypto/src/identities/user.rs @@ -788,13 +788,14 @@ pub(crate) mod test { ))); let verification_machine = VerificationMachine::new( ReadOnlyAccount::new(second.user_id(), second.device_id()), - private_identity, + private_identity.clone(), Arc::new(Box::new(MemoryStore::new())), ); let first = Device { inner: first, verification_machine: verification_machine.clone(), + private_identity: private_identity.clone(), own_identity: Some(identity.clone()), device_owner_identity: Some(UserIdentities::Own(identity.clone())), }; @@ -802,6 +803,7 @@ pub(crate) mod test { let second = Device { inner: second, verification_machine, + private_identity: private_identity.clone(), own_identity: Some(identity.clone()), device_owner_identity: Some(UserIdentities::Own(identity.clone())), }; diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index e5400081..3fda11ba 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -219,6 +219,7 @@ impl Store { Ok(UserDevices { inner: devices, + private_identity: self.identity.clone(), verification_machine: self.verification_machine.clone(), own_identity, device_owner_identity, @@ -243,6 +244,7 @@ impl Store { .await? .map(|d| Device { inner: d, + private_identity: self.identity.clone(), verification_machine: self.verification_machine.clone(), own_identity, device_owner_identity,