crypto: Don't track users on the kotlin side of things

This commit is contained in:
Damir Jelić 2021-03-24 13:45:15 +01:00
parent 669a5f9815
commit e4ac5f6c13
3 changed files with 9 additions and 45 deletions

View File

@ -440,22 +440,16 @@ internal class DefaultCryptoService @Inject constructor(
/**
* A sync response has been received
*
* @param syncResponse the syncResponse
*/
suspend fun onSyncCompleted(syncResponse: SyncResponse) {
suspend fun onSyncCompleted() {
if (isStarted()) {
sendOutgoingRequests()
}
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
runCatching {
if (syncResponse.deviceLists != null) {
deviceListManager.handleDeviceListsChanges(syncResponse.deviceLists.changed, syncResponse.deviceLists.left)
}
if (isStarted()) {
// Make sure we process to-device messages before generating new one-time-keys #2782
deviceListManager.refreshOutdatedDeviceLists()
incomingGossipingRequestManager.processReceivedGossipingRequests()
}
}
@ -566,13 +560,11 @@ internal class DefaultCryptoService @Inject constructor(
*
* @param roomId the room id to enable encryption in.
* @param algorithm the encryption config for the room.
* @param inhibitDeviceQuery true to suppress device list query for users in the room (for now)
* @param membersId list of members to start tracking their devices
* @return true if the operation succeeds.
*/
private suspend fun setEncryptionInRoom(roomId: String,
algorithm: String?,
inhibitDeviceQuery: Boolean,
membersId: List<String>): Boolean {
// If we already have encryption in this room, we should ignore this event
// (for now at least. Maybe we should alert the user somehow?)
@ -608,12 +600,7 @@ internal class DefaultCryptoService @Inject constructor(
Timber.v("Enabling encryption in $roomId for the first time; invalidating device lists for all users therein")
val userIds = ArrayList(membersId)
deviceListManager.startTrackingDeviceList(userIds)
if (!inhibitDeviceQuery) {
deviceListManager.refreshOutdatedDeviceLists()
}
olmMachine!!.updateTrackedUsers(userIds)
}
return true
@ -675,7 +662,7 @@ internal class DefaultCryptoService @Inject constructor(
if (alg == null) {
val algorithm = getEncryptionAlgorithm(roomId)
if (algorithm != null) {
if (setEncryptionInRoom(roomId, algorithm, false, userIds)) {
if (setEncryptionInRoom(roomId, algorithm, userIds)) {
alg = roomEncryptorsStore.get(roomId)
}
}
@ -889,7 +876,7 @@ internal class DefaultCryptoService @Inject constructor(
} finally {
val userIds = getRoomUserIds(roomId)
olmMachine!!.updateTrackedUsers(userIds)
setEncryptionInRoom(roomId, event.content?.get("algorithm")?.toString(), true, userIds)
setEncryptionInRoom(roomId, event.content?.get("algorithm")?.toString(), userIds)
}
}
}
@ -912,9 +899,8 @@ internal class DefaultCryptoService @Inject constructor(
val roomMember: RoomMemberContent? = event.content.toModel()
val membership = roomMember?.membership
if (membership == Membership.JOIN) {
olmMachine!!.updateTrackedUsers(listOf(userId))
// make sure we are tracking the deviceList for this user.
deviceListManager.startTrackingDeviceList(listOf(userId))
olmMachine!!.updateTrackedUsers(listOf(userId))
} else if (membership == Membership.INVITE
&& shouldEncryptForInvitedMembers(roomId)
&& isEncryptionEnabledForInvitedUser()) {
@ -923,7 +909,7 @@ internal class DefaultCryptoService @Inject constructor(
// know what other servers are in the room at the time they've been invited.
// They therefore will not send device updates if a user logs in whilst
// their state is invite.
deviceListManager.startTrackingDeviceList(listOf(userId))
olmMachine!!.updateTrackedUsers(listOf(userId))
}
}
}
@ -1130,28 +1116,6 @@ internal class DefaultCryptoService @Inject constructor(
warnOnUnknownDevicesRepository.setWarnOnUnknownDevices(warn)
}
/**
* Check if the user ids list have some unknown devices.
* A success means there is no unknown devices.
* If there are some unknown devices, a MXCryptoError.UnknownDevice exception is triggered.
*
* @param userIds the user ids list
* @param callback the asynchronous callback.
*/
fun checkUnknownDevices(userIds: List<String>, callback: MatrixCallback<Unit>) {
// force the refresh to ensure that the devices list is up-to-date
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
runCatching {
val keys = deviceListManager.downloadKeys(userIds, true)
val unknownDevices = getUnknownDevices(keys)
if (unknownDevices.map.isNotEmpty()) {
// trigger an an unknown devices exception
throw Failure.CryptoError(MXCryptoError.UnknownDevice(unknownDevices))
}
}.foldToCallback(callback)
}
}
/**
* Set the global override for whether the client should ever send encrypted
* messages to unverified devices.

View File

@ -52,8 +52,8 @@ internal class CryptoSyncHandler @Inject constructor(private val cryptoService:
}
}
suspend fun onSyncCompleted(syncResponse: SyncResponse) {
cryptoService.onSyncCompleted(syncResponse)
suspend fun onSyncCompleted() {
cryptoService.onSyncCompleted()
}
/**

View File

@ -127,7 +127,7 @@ internal class SyncResponseHandler @Inject constructor(@SessionDatabase private
}
Timber.v("On sync completed")
cryptoSyncHandler.onSyncCompleted(syncResponse)
cryptoSyncHandler.onSyncCompleted()
}
/**