crypto: Allow devices to be marked manually as verified
This commit is contained in:
parent
02b8b1f5b1
commit
05119bcf90
|
@ -632,6 +632,12 @@ internal class OlmMachine(
|
||||||
return plainDevices
|
return plainDevices
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Throws(CryptoStoreErrorException::class)
|
||||||
|
internal suspend fun markDeviceAsTrusted(userId: String, deviceId: String) =
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
inner.markDeviceAsTrusted(userId, deviceId)
|
||||||
|
}
|
||||||
|
|
||||||
/** Update all of our live device listeners. */
|
/** Update all of our live device listeners. */
|
||||||
private suspend fun updateLiveDevices() {
|
private suspend fun updateLiveDevices() {
|
||||||
for ((liveDevice, users) in deviceUpdateObserver.listeners) {
|
for ((liveDevice, users) in deviceUpdateObserver.listeners) {
|
||||||
|
|
|
@ -102,18 +102,7 @@ constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun markedLocallyAsManuallyVerified(userId: String, deviceID: String) {
|
override fun markedLocallyAsManuallyVerified(userId: String, deviceID: String) {
|
||||||
TODO()
|
runBlocking { olmMachine.markDeviceAsTrusted(userId, deviceID) }
|
||||||
// setDeviceVerificationAction.handle(DeviceTrustLevel(false, true),
|
|
||||||
// userId,
|
|
||||||
// deviceID)
|
|
||||||
|
|
||||||
// listeners.forEach {
|
|
||||||
// try {
|
|
||||||
// it.markedAsManuallyVerified(userId, deviceID)
|
|
||||||
// } catch (e: Throwable) {
|
|
||||||
// Timber.e(e, "## Error while notifying listeners")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onEvent(event: Event) = when (event.getClearType()) {
|
fun onEvent(event: Event) = when (event.getClearType()) {
|
||||||
|
|
|
@ -7,7 +7,9 @@ mod responses;
|
||||||
pub use device::Device;
|
pub use device::Device;
|
||||||
pub use error::{CryptoStoreError, DecryptionError, KeyImportError, MachineCreationError};
|
pub use error::{CryptoStoreError, DecryptionError, KeyImportError, MachineCreationError};
|
||||||
pub use logger::{set_logger, Logger};
|
pub use logger::{set_logger, Logger};
|
||||||
pub use machine::{KeyRequestPair, OlmMachine, Sas, StartSasResult, VerificationRequest, QrCode, Verification};
|
pub use machine::{
|
||||||
|
KeyRequestPair, OlmMachine, QrCode, Sas, StartSasResult, Verification, VerificationRequest,
|
||||||
|
};
|
||||||
pub use responses::{
|
pub use responses::{
|
||||||
DeviceLists, KeysImportResult, OutgoingVerificationRequest, Request, RequestType,
|
DeviceLists, KeysImportResult, OutgoingVerificationRequest, Request, RequestType,
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,8 +4,8 @@ use std::{
|
||||||
io::Cursor,
|
io::Cursor,
|
||||||
};
|
};
|
||||||
|
|
||||||
use js_int::UInt;
|
|
||||||
use base64::encode;
|
use base64::encode;
|
||||||
|
use js_int::UInt;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{
|
api::{
|
||||||
client::r0::{
|
client::r0::{
|
||||||
|
@ -30,9 +30,9 @@ use tokio::runtime::Runtime;
|
||||||
|
|
||||||
use matrix_sdk_common::{deserialized_responses::AlgorithmInfo, uuid::Uuid};
|
use matrix_sdk_common::{deserialized_responses::AlgorithmInfo, uuid::Uuid};
|
||||||
use matrix_sdk_crypto::{
|
use matrix_sdk_crypto::{
|
||||||
decrypt_key_export, encrypt_key_export, EncryptionSettings, OlmMachine as InnerMachine,
|
decrypt_key_export, encrypt_key_export, EncryptionSettings, LocalTrust,
|
||||||
QrVerification as InnerQr, Sas as InnerSas, Verification as RustVerification,
|
OlmMachine as InnerMachine, QrVerification as InnerQr, Sas as InnerSas,
|
||||||
VerificationRequest as InnerVerificationRequest,
|
Verification as RustVerification, VerificationRequest as InnerVerificationRequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -227,6 +227,25 @@ impl OlmMachine {
|
||||||
.map(|d| d.into()))
|
.map(|d| d.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn mark_device_as_trusted(
|
||||||
|
&self,
|
||||||
|
user_id: &str,
|
||||||
|
device_id: &str,
|
||||||
|
) -> Result<(), CryptoStoreError> {
|
||||||
|
let user_id = UserId::try_from(user_id)?;
|
||||||
|
|
||||||
|
let device = self
|
||||||
|
.runtime
|
||||||
|
.block_on(self.inner.get_device(&user_id, device_id.into()))?;
|
||||||
|
|
||||||
|
if let Some(device) = device {
|
||||||
|
self.runtime
|
||||||
|
.block_on(device.set_local_trust(LocalTrust::Verified))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Get all devices of an user.
|
/// Get all devices of an user.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
@ -731,7 +750,10 @@ impl OlmMachine {
|
||||||
let user_id = UserId::try_from(user_id).ok()?;
|
let user_id = UserId::try_from(user_id).ok()?;
|
||||||
self.inner
|
self.inner
|
||||||
.get_verification(&user_id, flow_id)
|
.get_verification(&user_id, flow_id)
|
||||||
.and_then(|v| v.qr_v1().and_then(|qr| qr.to_bytes().map(|b| encode(b)).ok()))
|
.and_then(|v| {
|
||||||
|
v.qr_v1()
|
||||||
|
.and_then(|qr| qr.to_bytes().map(|b| encode(b)).ok())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_sas_verification(
|
pub fn start_sas_verification(
|
||||||
|
|
|
@ -177,6 +177,8 @@ interface OlmMachine {
|
||||||
[Throws=CryptoStoreError]
|
[Throws=CryptoStoreError]
|
||||||
Device? get_device([ByRef] string user_id, [ByRef] string device_id);
|
Device? get_device([ByRef] string user_id, [ByRef] string device_id);
|
||||||
[Throws=CryptoStoreError]
|
[Throws=CryptoStoreError]
|
||||||
|
void mark_device_as_trusted([ByRef] string user_id, [ByRef] string device_id);
|
||||||
|
[Throws=CryptoStoreError]
|
||||||
sequence<Device> get_user_devices([ByRef] string user_id);
|
sequence<Device> get_user_devices([ByRef] string user_id);
|
||||||
|
|
||||||
void update_tracked_users(sequence<string> users);
|
void update_tracked_users(sequence<string> users);
|
||||||
|
|
Loading…
Reference in New Issue