Add RequestDeviceVerification method

This commit is contained in:
ganfra 2022-05-30 19:55:48 +02:00
parent 466260bc6a
commit 3e116ad065
3 changed files with 27 additions and 3 deletions

View File

@ -45,6 +45,18 @@ interface VerificationService {
fun getExistingVerificationRequestInRoom(roomId: String, tid: String?): PendingVerificationRequest?
/**
* Request an interactive verification to begin
*
* This sends out a m.key.verification.request event over to-device messaging to
* to this device.
*
* If no specific device should be verified, but we would like to request
* verification from all our devices, use [requestSelfKeyVerification] instead.
*/
suspend fun requestDeviceVerification(methods: List<VerificationMethod>, otherUserId: String, otherDeviceId: String): PendingVerificationRequest?
/**
* Request key verification with another user via room events (instead of the to-device API).
*/

View File

@ -28,7 +28,6 @@ import org.matrix.android.sdk.internal.crypto.verification.prepareMethods
import uniffi.olm.CryptoStoreException
import uniffi.olm.OlmMachine
import uniffi.olm.SignatureException
import uniffi.olm.VerificationRequest
import uniffi.olm.Device as InnerDevice
/** Class representing a device that supports E2EE in the Matrix world
@ -71,10 +70,15 @@ internal class Device(
val result = withContext(coroutineDispatchers.io) {
machine.requestVerificationWithDevice(inner.userId, inner.deviceId, stringMethods)
}
return if (result != null) {
sender.sendVerificationRequest(result.request)
result.verification
VerificationRequest(
machine = machine,
inner = result.verification,
sender = sender,
coroutineDispatchers = coroutineDispatchers,
listeners = listeners
)
} else {
null
}

View File

@ -254,6 +254,14 @@ internal class RustVerificationService @Inject constructor(private val olmMachin
return verification.toPendingVerificationRequest()
}
override suspend fun requestDeviceVerification(methods: List<VerificationMethod>, otherUserId: String, otherDeviceId: String): PendingVerificationRequest? {
olmMachine.ensureUsersKeys(listOf(otherUserId))
val otherDevice = olmMachine.getDevice(otherUserId, otherDeviceId)
val verificationRequest = otherDevice?.requestVerification(methods)
return verificationRequest?.toPendingVerificationRequest()
}
override suspend fun readyPendingVerification(
methods: List<VerificationMethod>,
otherUserId: String,