mirror of
https://github.com/element-hq/element-android
synced 2024-12-21 00:42:04 +03:00
crypto: Allow devices to be marked manually as verified
This commit is contained in:
parent
02b8b1f5b1
commit
05119bcf90
5 changed files with 39 additions and 18 deletions
|
@ -632,6 +632,12 @@ internal class OlmMachine(
|
|||
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. */
|
||||
private suspend fun updateLiveDevices() {
|
||||
for ((liveDevice, users) in deviceUpdateObserver.listeners) {
|
||||
|
|
|
@ -102,18 +102,7 @@ constructor(
|
|||
}
|
||||
|
||||
override fun markedLocallyAsManuallyVerified(userId: String, deviceID: String) {
|
||||
TODO()
|
||||
// setDeviceVerificationAction.handle(DeviceTrustLevel(false, true),
|
||||
// userId,
|
||||
// deviceID)
|
||||
|
||||
// listeners.forEach {
|
||||
// try {
|
||||
// it.markedAsManuallyVerified(userId, deviceID)
|
||||
// } catch (e: Throwable) {
|
||||
// Timber.e(e, "## Error while notifying listeners")
|
||||
// }
|
||||
// }
|
||||
runBlocking { olmMachine.markDeviceAsTrusted(userId, deviceID) }
|
||||
}
|
||||
|
||||
fun onEvent(event: Event) = when (event.getClearType()) {
|
||||
|
|
|
@ -7,7 +7,9 @@ mod responses;
|
|||
pub use device::Device;
|
||||
pub use error::{CryptoStoreError, DecryptionError, KeyImportError, MachineCreationError};
|
||||
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::{
|
||||
DeviceLists, KeysImportResult, OutgoingVerificationRequest, Request, RequestType,
|
||||
};
|
||||
|
|
|
@ -4,8 +4,8 @@ use std::{
|
|||
io::Cursor,
|
||||
};
|
||||
|
||||
use js_int::UInt;
|
||||
use base64::encode;
|
||||
use js_int::UInt;
|
||||
use ruma::{
|
||||
api::{
|
||||
client::r0::{
|
||||
|
@ -30,9 +30,9 @@ use tokio::runtime::Runtime;
|
|||
|
||||
use matrix_sdk_common::{deserialized_responses::AlgorithmInfo, uuid::Uuid};
|
||||
use matrix_sdk_crypto::{
|
||||
decrypt_key_export, encrypt_key_export, EncryptionSettings, OlmMachine as InnerMachine,
|
||||
QrVerification as InnerQr, Sas as InnerSas, Verification as RustVerification,
|
||||
VerificationRequest as InnerVerificationRequest,
|
||||
decrypt_key_export, encrypt_key_export, EncryptionSettings, LocalTrust,
|
||||
OlmMachine as InnerMachine, QrVerification as InnerQr, Sas as InnerSas,
|
||||
Verification as RustVerification, VerificationRequest as InnerVerificationRequest,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -227,6 +227,25 @@ impl OlmMachine {
|
|||
.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.
|
||||
///
|
||||
/// # Arguments
|
||||
|
@ -731,7 +750,10 @@ impl OlmMachine {
|
|||
let user_id = UserId::try_from(user_id).ok()?;
|
||||
self.inner
|
||||
.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(
|
||||
|
|
|
@ -177,6 +177,8 @@ interface OlmMachine {
|
|||
[Throws=CryptoStoreError]
|
||||
Device? get_device([ByRef] string user_id, [ByRef] string device_id);
|
||||
[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);
|
||||
|
||||
void update_tracked_users(sequence<string> users);
|
||||
|
|
Loading…
Reference in a new issue