crypto: Rename TrustState to LocalTrust since.
We might still trust the device event if our local trust isn't set, so rename the enum to better reflect that meaning.master
parent
a42af5da69
commit
90ea0229f2
|
@ -15,7 +15,7 @@
|
||||||
use std::{ops::Deref, result::Result as StdResult};
|
use std::{ops::Deref, result::Result as StdResult};
|
||||||
|
|
||||||
use matrix_sdk_base::{
|
use matrix_sdk_base::{
|
||||||
CryptoStoreError, Device as BaseDevice, ReadOnlyDevice, TrustState,
|
CryptoStoreError, Device as BaseDevice, LocalTrust, ReadOnlyDevice,
|
||||||
UserDevices as BaseUserDevices,
|
UserDevices as BaseUserDevices,
|
||||||
};
|
};
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
|
@ -83,7 +83,7 @@ impl Device {
|
||||||
/// * `trust_state` - The new trust state that should be set for the device.
|
/// * `trust_state` - The new trust state that should be set for the device.
|
||||||
pub async fn set_trust_state(
|
pub async fn set_trust_state(
|
||||||
&self,
|
&self,
|
||||||
trust_state: TrustState,
|
trust_state: LocalTrust,
|
||||||
) -> StdResult<(), CryptoStoreError> {
|
) -> StdResult<(), CryptoStoreError> {
|
||||||
self.inner.set_trust_state(trust_state).await
|
self.inner.set_trust_state(trust_state).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
pub use matrix_sdk_base::JsonStore;
|
pub use matrix_sdk_base::JsonStore;
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
#[cfg_attr(feature = "docs", doc(cfg(encryption)))]
|
#[cfg_attr(feature = "docs", doc(cfg(encryption)))]
|
||||||
pub use matrix_sdk_base::TrustState;
|
pub use matrix_sdk_base::LocalTrust;
|
||||||
pub use matrix_sdk_base::{
|
pub use matrix_sdk_base::{
|
||||||
CustomEvent, Error as BaseError, EventEmitter, Room, RoomState, Session, StateStore, SyncRoom,
|
CustomEvent, Error as BaseError, EventEmitter, Room, RoomState, Session, StateStore, SyncRoom,
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,7 +57,7 @@ pub use state::{AllRooms, ClientState};
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
#[cfg_attr(feature = "docs", doc(cfg(encryption)))]
|
#[cfg_attr(feature = "docs", doc(cfg(encryption)))]
|
||||||
pub use matrix_sdk_crypto::{
|
pub use matrix_sdk_crypto::{
|
||||||
CryptoStoreError, Device, ReadOnlyDevice, Sas, TrustState, UserDevices,
|
CryptoStoreError, Device, LocalTrust, ReadOnlyDevice, Sas, UserDevices,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "messages")]
|
#[cfg(feature = "messages")]
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub struct ReadOnlyDevice {
|
||||||
signatures: Arc<BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>>,
|
signatures: Arc<BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>>,
|
||||||
display_name: Arc<Option<String>>,
|
display_name: Arc<Option<String>>,
|
||||||
deleted: Arc<AtomicBool>,
|
deleted: Arc<AtomicBool>,
|
||||||
trust_state: Arc<Atomic<TrustState>>,
|
trust_state: Arc<Atomic<LocalTrust>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -88,7 +88,7 @@ impl Device {
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `trust_state` - The new trust state that should be set for the device.
|
/// * `trust_state` - The new trust state that should be set for the device.
|
||||||
pub async fn set_trust_state(&self, trust_state: TrustState) -> StoreResult<()> {
|
pub async fn set_trust_state(&self, trust_state: LocalTrust) -> StoreResult<()> {
|
||||||
self.inner.set_trust_state(trust_state);
|
self.inner.set_trust_state(trust_state);
|
||||||
self.verification_machine
|
self.verification_machine
|
||||||
.store
|
.store
|
||||||
|
@ -134,8 +134,8 @@ impl UserDevices {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
/// The trust state of a device.
|
/// The local trust state of a device.
|
||||||
pub enum TrustState {
|
pub enum LocalTrust {
|
||||||
/// The device has been verified and is trusted.
|
/// The device has been verified and is trusted.
|
||||||
Verified = 0,
|
Verified = 0,
|
||||||
/// The device been blacklisted from communicating.
|
/// The device been blacklisted from communicating.
|
||||||
|
@ -146,14 +146,14 @@ pub enum TrustState {
|
||||||
Unset = 3,
|
Unset = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<i64> for TrustState {
|
impl From<i64> for LocalTrust {
|
||||||
fn from(state: i64) -> Self {
|
fn from(state: i64) -> Self {
|
||||||
match state {
|
match state {
|
||||||
0 => TrustState::Verified,
|
0 => LocalTrust::Verified,
|
||||||
1 => TrustState::BlackListed,
|
1 => LocalTrust::BlackListed,
|
||||||
2 => TrustState::Ignored,
|
2 => LocalTrust::Ignored,
|
||||||
3 => TrustState::Unset,
|
3 => LocalTrust::Unset,
|
||||||
_ => TrustState::Unset,
|
_ => LocalTrust::Unset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ impl ReadOnlyDevice {
|
||||||
user_id: UserId,
|
user_id: UserId,
|
||||||
device_id: Box<DeviceId>,
|
device_id: Box<DeviceId>,
|
||||||
display_name: Option<String>,
|
display_name: Option<String>,
|
||||||
trust_state: TrustState,
|
trust_state: LocalTrust,
|
||||||
algorithms: Vec<EventEncryptionAlgorithm>,
|
algorithms: Vec<EventEncryptionAlgorithm>,
|
||||||
keys: BTreeMap<DeviceKeyId, String>,
|
keys: BTreeMap<DeviceKeyId, String>,
|
||||||
signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
|
signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
|
||||||
|
@ -213,27 +213,27 @@ impl ReadOnlyDevice {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the trust state of the device.
|
/// Get the trust state of the device.
|
||||||
pub fn trust_state(&self) -> TrustState {
|
pub fn trust_state(&self) -> LocalTrust {
|
||||||
self.trust_state.load(Ordering::Relaxed)
|
self.trust_state.load(Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the device locally marked as trusted.
|
/// Is the device locally marked as trusted.
|
||||||
pub fn is_trusted(&self) -> bool {
|
pub fn is_trusted(&self) -> bool {
|
||||||
self.trust_state() == TrustState::Verified
|
self.trust_state() == LocalTrust::Verified
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the device locally marked as blacklisted.
|
/// Is the device locally marked as blacklisted.
|
||||||
///
|
///
|
||||||
/// Blacklisted devices won't receive any group sessions.
|
/// Blacklisted devices won't receive any group sessions.
|
||||||
pub fn is_blacklisted(&self) -> bool {
|
pub fn is_blacklisted(&self) -> bool {
|
||||||
self.trust_state() == TrustState::BlackListed
|
self.trust_state() == LocalTrust::BlackListed
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the trust state of the device to the given state.
|
/// Set the trust state of the device to the given state.
|
||||||
///
|
///
|
||||||
/// Note: This should only done in the cryptostore where the trust state can
|
/// Note: This should only done in the cryptostore where the trust state can
|
||||||
/// be stored.
|
/// be stored.
|
||||||
pub(crate) fn set_trust_state(&self, state: TrustState) {
|
pub(crate) fn set_trust_state(&self, state: LocalTrust) {
|
||||||
self.trust_state.store(state, Ordering::Relaxed)
|
self.trust_state.store(state, Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ impl TryFrom<&DeviceKeys> for ReadOnlyDevice {
|
||||||
.flatten(),
|
.flatten(),
|
||||||
),
|
),
|
||||||
deleted: Arc::new(AtomicBool::new(false)),
|
deleted: Arc::new(AtomicBool::new(false)),
|
||||||
trust_state: Arc::new(Atomic::new(TrustState::Unset)),
|
trust_state: Arc::new(Atomic::new(LocalTrust::Unset)),
|
||||||
};
|
};
|
||||||
|
|
||||||
device.verify_device_keys(device_keys)?;
|
device.verify_device_keys(device_keys)?;
|
||||||
|
@ -358,7 +358,7 @@ pub(crate) mod test {
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use crate::device::{ReadOnlyDevice, TrustState};
|
use crate::device::{LocalTrust, ReadOnlyDevice};
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
encryption::DeviceKeys,
|
encryption::DeviceKeys,
|
||||||
identifiers::{user_id, DeviceKeyAlgorithm},
|
identifiers::{user_id, DeviceKeyAlgorithm},
|
||||||
|
@ -404,7 +404,7 @@ pub(crate) mod test {
|
||||||
assert_eq!(&user_id, device.user_id());
|
assert_eq!(&user_id, device.user_id());
|
||||||
assert_eq!(device_id, device.device_id());
|
assert_eq!(device_id, device.device_id());
|
||||||
assert_eq!(device.algorithms.len(), 2);
|
assert_eq!(device.algorithms.len(), 2);
|
||||||
assert_eq!(TrustState::Unset, device.trust_state());
|
assert_eq!(LocalTrust::Unset, device.trust_state());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"Alice's mobile phone",
|
"Alice's mobile phone",
|
||||||
device.display_name().as_ref().unwrap()
|
device.display_name().as_ref().unwrap()
|
||||||
|
|
|
@ -37,7 +37,7 @@ mod store;
|
||||||
mod user_identity;
|
mod user_identity;
|
||||||
mod verification;
|
mod verification;
|
||||||
|
|
||||||
pub use device::{Device, ReadOnlyDevice, TrustState, UserDevices};
|
pub use device::{Device, LocalTrust, ReadOnlyDevice, UserDevices};
|
||||||
pub use error::{MegolmError, OlmError};
|
pub use error::{MegolmError, OlmError};
|
||||||
pub use machine::{OlmMachine, OneTimeKeys};
|
pub use machine::{OlmMachine, OneTimeKeys};
|
||||||
pub use memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore};
|
pub use memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore};
|
||||||
|
|
|
@ -36,7 +36,7 @@ use zeroize::Zeroizing;
|
||||||
|
|
||||||
use super::{CryptoStore, CryptoStoreError, Result};
|
use super::{CryptoStore, CryptoStoreError, Result};
|
||||||
use crate::{
|
use crate::{
|
||||||
device::{ReadOnlyDevice, TrustState},
|
device::{LocalTrust, ReadOnlyDevice},
|
||||||
memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore},
|
memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore},
|
||||||
user_identity::UserIdentities,
|
user_identity::UserIdentities,
|
||||||
Account, IdentityKeys, InboundGroupSession, Session,
|
Account, IdentityKeys, InboundGroupSession, Session,
|
||||||
|
@ -486,7 +486,7 @@ impl SqliteStore {
|
||||||
|
|
||||||
let device_id = &row.2.to_string();
|
let device_id = &row.2.to_string();
|
||||||
let display_name = &row.3;
|
let display_name = &row.3;
|
||||||
let trust_state = TrustState::from(row.4);
|
let trust_state = LocalTrust::from(row.4);
|
||||||
|
|
||||||
let algorithm_rows: Vec<(String,)> =
|
let algorithm_rows: Vec<(String,)> =
|
||||||
query_as("SELECT algorithm FROM algorithms WHERE device_id = ?")
|
query_as("SELECT algorithm FROM algorithms WHERE device_id = ?")
|
||||||
|
|
|
@ -34,8 +34,8 @@ use matrix_sdk_common::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
user_identity::UserIdentities, Account, CryptoStore, CryptoStoreError, ReadOnlyDevice,
|
user_identity::UserIdentities, Account, CryptoStore, CryptoStoreError, LocalTrust,
|
||||||
TrustState,
|
ReadOnlyDevice,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use helpers::content_to_request;
|
pub use helpers::content_to_request;
|
||||||
|
@ -216,7 +216,7 @@ impl Sas {
|
||||||
device.device_id()
|
device.device_id()
|
||||||
);
|
);
|
||||||
|
|
||||||
device.set_trust_state(TrustState::Verified);
|
device.set_trust_state(LocalTrust::Verified);
|
||||||
self.store.save_devices(&[device]).await?;
|
self.store.save_devices(&[device]).await?;
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
|
|
Loading…
Reference in New Issue