crypto: Let devices hold on to the private identity.

master
Damir Jelić 2020-10-30 11:41:48 +01:00
parent 34bec59389
commit 44cc1cef71
3 changed files with 10 additions and 2 deletions

View File

@ -40,7 +40,7 @@ use serde_json::{json, Value};
use tracing::warn; use tracing::warn;
use crate::{ use crate::{
olm::{InboundGroupSession, Session}, olm::{InboundGroupSession, PrivateCrossSigningIdentity, Session},
store::{Changes, DeviceChanges}, store::{Changes, DeviceChanges},
}; };
#[cfg(test)] #[cfg(test)]
@ -72,6 +72,7 @@ pub struct ReadOnlyDevice {
/// A device represents a E2EE capable client of an user. /// A device represents a E2EE capable client of an user.
pub struct Device { pub struct Device {
pub(crate) inner: ReadOnlyDevice, pub(crate) inner: ReadOnlyDevice,
pub(crate) private_identity: Arc<Mutex<PrivateCrossSigningIdentity>>,
pub(crate) verification_machine: VerificationMachine, pub(crate) verification_machine: VerificationMachine,
pub(crate) own_identity: Option<OwnUserIdentity>, pub(crate) own_identity: Option<OwnUserIdentity>,
pub(crate) device_owner_identity: Option<UserIdentities>, pub(crate) device_owner_identity: Option<UserIdentities>,
@ -179,6 +180,7 @@ impl Device {
#[derive(Debug)] #[derive(Debug)]
pub struct UserDevices { pub struct UserDevices {
pub(crate) inner: HashMap<DeviceIdBox, ReadOnlyDevice>, pub(crate) inner: HashMap<DeviceIdBox, ReadOnlyDevice>,
pub(crate) private_identity: Arc<Mutex<PrivateCrossSigningIdentity>>,
pub(crate) verification_machine: VerificationMachine, pub(crate) verification_machine: VerificationMachine,
pub(crate) own_identity: Option<OwnUserIdentity>, pub(crate) own_identity: Option<OwnUserIdentity>,
pub(crate) device_owner_identity: Option<UserIdentities>, pub(crate) device_owner_identity: Option<UserIdentities>,
@ -189,6 +191,7 @@ impl UserDevices {
pub fn get(&self, device_id: &DeviceId) -> Option<Device> { pub fn get(&self, device_id: &DeviceId) -> Option<Device> {
self.inner.get(device_id).map(|d| Device { self.inner.get(device_id).map(|d| Device {
inner: d.clone(), inner: d.clone(),
private_identity: self.private_identity.clone(),
verification_machine: self.verification_machine.clone(), verification_machine: self.verification_machine.clone(),
own_identity: self.own_identity.clone(), own_identity: self.own_identity.clone(),
device_owner_identity: self.device_owner_identity.clone(), device_owner_identity: self.device_owner_identity.clone(),
@ -204,6 +207,7 @@ impl UserDevices {
pub fn devices(&self) -> impl Iterator<Item = Device> + '_ { pub fn devices(&self) -> impl Iterator<Item = Device> + '_ {
self.inner.values().map(move |d| Device { self.inner.values().map(move |d| Device {
inner: d.clone(), inner: d.clone(),
private_identity: self.private_identity.clone(),
verification_machine: self.verification_machine.clone(), verification_machine: self.verification_machine.clone(),
own_identity: self.own_identity.clone(), own_identity: self.own_identity.clone(),
device_owner_identity: self.device_owner_identity.clone(), device_owner_identity: self.device_owner_identity.clone(),

View File

@ -788,13 +788,14 @@ pub(crate) mod test {
))); )));
let verification_machine = VerificationMachine::new( let verification_machine = VerificationMachine::new(
ReadOnlyAccount::new(second.user_id(), second.device_id()), ReadOnlyAccount::new(second.user_id(), second.device_id()),
private_identity, private_identity.clone(),
Arc::new(Box::new(MemoryStore::new())), Arc::new(Box::new(MemoryStore::new())),
); );
let first = Device { let first = Device {
inner: first, inner: first,
verification_machine: verification_machine.clone(), verification_machine: verification_machine.clone(),
private_identity: private_identity.clone(),
own_identity: Some(identity.clone()), own_identity: Some(identity.clone()),
device_owner_identity: Some(UserIdentities::Own(identity.clone())), device_owner_identity: Some(UserIdentities::Own(identity.clone())),
}; };
@ -802,6 +803,7 @@ pub(crate) mod test {
let second = Device { let second = Device {
inner: second, inner: second,
verification_machine, verification_machine,
private_identity: private_identity.clone(),
own_identity: Some(identity.clone()), own_identity: Some(identity.clone()),
device_owner_identity: Some(UserIdentities::Own(identity.clone())), device_owner_identity: Some(UserIdentities::Own(identity.clone())),
}; };

View File

@ -219,6 +219,7 @@ impl Store {
Ok(UserDevices { Ok(UserDevices {
inner: devices, inner: devices,
private_identity: self.identity.clone(),
verification_machine: self.verification_machine.clone(), verification_machine: self.verification_machine.clone(),
own_identity, own_identity,
device_owner_identity, device_owner_identity,
@ -243,6 +244,7 @@ impl Store {
.await? .await?
.map(|d| Device { .map(|d| Device {
inner: d, inner: d,
private_identity: self.identity.clone(),
verification_machine: self.verification_machine.clone(), verification_machine: self.verification_machine.clone(),
own_identity, own_identity,
device_owner_identity, device_owner_identity,