crypto: Let the device hold on to identities.
This makes it possible to check the verification state of the device directly.
This commit is contained in:
parent
f63a01a85b
commit
a42af5da69
3 changed files with 65 additions and 4 deletions
|
@ -36,7 +36,10 @@ use serde_json::{json, Value};
|
|||
use super::{Account, OlmMachine};
|
||||
|
||||
use crate::{
|
||||
error::SignatureError, store::Result as StoreResult, verification::VerificationMachine,
|
||||
error::SignatureError,
|
||||
store::Result as StoreResult,
|
||||
user_identity::{OwnUserIdentity, UserIdentity},
|
||||
verification::VerificationMachine,
|
||||
verify_json, ReadOnlyUserDevices, Sas,
|
||||
};
|
||||
|
||||
|
@ -58,6 +61,8 @@ pub struct ReadOnlyDevice {
|
|||
pub struct Device {
|
||||
pub(crate) inner: ReadOnlyDevice,
|
||||
pub(crate) verification_machine: VerificationMachine,
|
||||
pub(crate) own_identity: Option<OwnUserIdentity>,
|
||||
pub(crate) device_owner_identity: Option<UserIdentity>,
|
||||
}
|
||||
|
||||
impl Deref for Device {
|
||||
|
@ -97,6 +102,8 @@ impl Device {
|
|||
pub struct UserDevices {
|
||||
pub(crate) inner: ReadOnlyUserDevices,
|
||||
pub(crate) verification_machine: VerificationMachine,
|
||||
pub(crate) own_identity: Option<OwnUserIdentity>,
|
||||
pub(crate) device_owner_identity: Option<UserIdentity>,
|
||||
}
|
||||
|
||||
impl UserDevices {
|
||||
|
@ -105,6 +112,8 @@ impl UserDevices {
|
|||
self.inner.get(device_id).map(|d| Device {
|
||||
inner: d,
|
||||
verification_machine: self.verification_machine.clone(),
|
||||
own_identity: self.own_identity.clone(),
|
||||
device_owner_identity: self.device_owner_identity.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -115,11 +124,11 @@ impl UserDevices {
|
|||
|
||||
/// Iterator over all the devices of the user devices.
|
||||
pub fn devices(&self) -> impl Iterator<Item = Device> + '_ {
|
||||
let machine = self.verification_machine.clone();
|
||||
|
||||
self.inner.devices().map(move |d| Device {
|
||||
inner: d.clone(),
|
||||
verification_machine: machine.clone(),
|
||||
verification_machine: self.verification_machine.clone(),
|
||||
own_identity: self.own_identity.clone(),
|
||||
device_owner_identity: self.device_owner_identity.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1423,9 +1423,28 @@ impl OlmMachine {
|
|||
.ok()
|
||||
.flatten()?;
|
||||
|
||||
let own_identity = self
|
||||
.store
|
||||
.get_user_identity(self.user_id())
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|i| i.own().cloned())
|
||||
.flatten();
|
||||
let device_owner_identity = self
|
||||
.store
|
||||
.get_user_identity(user_id)
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|i| i.other().cloned())
|
||||
.flatten();
|
||||
|
||||
Some(Device {
|
||||
inner: device,
|
||||
verification_machine: self.verification_machine.clone(),
|
||||
own_identity,
|
||||
device_owner_identity,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1455,9 +1474,28 @@ impl OlmMachine {
|
|||
pub async fn get_user_devices(&self, user_id: &UserId) -> StoreResult<UserDevices> {
|
||||
let devices = self.store.get_user_devices(user_id).await?;
|
||||
|
||||
let own_identity = self
|
||||
.store
|
||||
.get_user_identity(self.user_id())
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|i| i.own().cloned())
|
||||
.flatten();
|
||||
let device_owner_identity = self
|
||||
.store
|
||||
.get_user_identity(user_id)
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|i| i.other().cloned())
|
||||
.flatten();
|
||||
|
||||
Ok(UserDevices {
|
||||
inner: devices,
|
||||
verification_machine: self.verification_machine.clone(),
|
||||
own_identity,
|
||||
device_owner_identity,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,6 +166,20 @@ impl UserIdentities {
|
|||
UserIdentities::Other(i) => i.master_key(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn own(&self) -> Option<&OwnUserIdentity> {
|
||||
match self {
|
||||
UserIdentities::Own(i) => Some(i),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn other(&self) -> Option<&UserIdentity> {
|
||||
match self {
|
||||
UserIdentities::Other(i) => Some(i),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
Loading…
Reference in a new issue