mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-29 14:38:45 +03:00
crypto: Don't track users on the kotlin side of things
This commit is contained in:
parent
669a5f9815
commit
e4ac5f6c13
3 changed files with 9 additions and 45 deletions
|
@ -440,22 +440,16 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A sync response has been received
|
* A sync response has been received
|
||||||
*
|
|
||||||
* @param syncResponse the syncResponse
|
|
||||||
*/
|
*/
|
||||||
suspend fun onSyncCompleted(syncResponse: SyncResponse) {
|
suspend fun onSyncCompleted() {
|
||||||
if (isStarted()) {
|
if (isStarted()) {
|
||||||
sendOutgoingRequests()
|
sendOutgoingRequests()
|
||||||
}
|
}
|
||||||
|
|
||||||
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
|
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
|
||||||
runCatching {
|
runCatching {
|
||||||
if (syncResponse.deviceLists != null) {
|
|
||||||
deviceListManager.handleDeviceListsChanges(syncResponse.deviceLists.changed, syncResponse.deviceLists.left)
|
|
||||||
}
|
|
||||||
if (isStarted()) {
|
if (isStarted()) {
|
||||||
// Make sure we process to-device messages before generating new one-time-keys #2782
|
// Make sure we process to-device messages before generating new one-time-keys #2782
|
||||||
deviceListManager.refreshOutdatedDeviceLists()
|
|
||||||
incomingGossipingRequestManager.processReceivedGossipingRequests()
|
incomingGossipingRequestManager.processReceivedGossipingRequests()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -566,13 +560,11 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
*
|
*
|
||||||
* @param roomId the room id to enable encryption in.
|
* @param roomId the room id to enable encryption in.
|
||||||
* @param algorithm the encryption config for the room.
|
* @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
|
* @param membersId list of members to start tracking their devices
|
||||||
* @return true if the operation succeeds.
|
* @return true if the operation succeeds.
|
||||||
*/
|
*/
|
||||||
private suspend fun setEncryptionInRoom(roomId: String,
|
private suspend fun setEncryptionInRoom(roomId: String,
|
||||||
algorithm: String?,
|
algorithm: String?,
|
||||||
inhibitDeviceQuery: Boolean,
|
|
||||||
membersId: List<String>): Boolean {
|
membersId: List<String>): Boolean {
|
||||||
// If we already have encryption in this room, we should ignore this event
|
// If we already have encryption in this room, we should ignore this event
|
||||||
// (for now at least. Maybe we should alert the user somehow?)
|
// (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")
|
Timber.v("Enabling encryption in $roomId for the first time; invalidating device lists for all users therein")
|
||||||
|
|
||||||
val userIds = ArrayList(membersId)
|
val userIds = ArrayList(membersId)
|
||||||
|
olmMachine!!.updateTrackedUsers(userIds)
|
||||||
deviceListManager.startTrackingDeviceList(userIds)
|
|
||||||
|
|
||||||
if (!inhibitDeviceQuery) {
|
|
||||||
deviceListManager.refreshOutdatedDeviceLists()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -675,7 +662,7 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
if (alg == null) {
|
if (alg == null) {
|
||||||
val algorithm = getEncryptionAlgorithm(roomId)
|
val algorithm = getEncryptionAlgorithm(roomId)
|
||||||
if (algorithm != null) {
|
if (algorithm != null) {
|
||||||
if (setEncryptionInRoom(roomId, algorithm, false, userIds)) {
|
if (setEncryptionInRoom(roomId, algorithm, userIds)) {
|
||||||
alg = roomEncryptorsStore.get(roomId)
|
alg = roomEncryptorsStore.get(roomId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -889,7 +876,7 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
} finally {
|
} finally {
|
||||||
val userIds = getRoomUserIds(roomId)
|
val userIds = getRoomUserIds(roomId)
|
||||||
olmMachine!!.updateTrackedUsers(userIds)
|
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 roomMember: RoomMemberContent? = event.content.toModel()
|
||||||
val membership = roomMember?.membership
|
val membership = roomMember?.membership
|
||||||
if (membership == Membership.JOIN) {
|
if (membership == Membership.JOIN) {
|
||||||
olmMachine!!.updateTrackedUsers(listOf(userId))
|
|
||||||
// make sure we are tracking the deviceList for this user.
|
// make sure we are tracking the deviceList for this user.
|
||||||
deviceListManager.startTrackingDeviceList(listOf(userId))
|
olmMachine!!.updateTrackedUsers(listOf(userId))
|
||||||
} else if (membership == Membership.INVITE
|
} else if (membership == Membership.INVITE
|
||||||
&& shouldEncryptForInvitedMembers(roomId)
|
&& shouldEncryptForInvitedMembers(roomId)
|
||||||
&& isEncryptionEnabledForInvitedUser()) {
|
&& 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.
|
// 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
|
// They therefore will not send device updates if a user logs in whilst
|
||||||
// their state is invite.
|
// their state is invite.
|
||||||
deviceListManager.startTrackingDeviceList(listOf(userId))
|
olmMachine!!.updateTrackedUsers(listOf(userId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1130,28 +1116,6 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
warnOnUnknownDevicesRepository.setWarnOnUnknownDevices(warn)
|
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
|
* Set the global override for whether the client should ever send encrypted
|
||||||
* messages to unverified devices.
|
* messages to unverified devices.
|
||||||
|
|
|
@ -52,8 +52,8 @@ internal class CryptoSyncHandler @Inject constructor(private val cryptoService:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun onSyncCompleted(syncResponse: SyncResponse) {
|
suspend fun onSyncCompleted() {
|
||||||
cryptoService.onSyncCompleted(syncResponse)
|
cryptoService.onSyncCompleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -127,7 +127,7 @@ internal class SyncResponseHandler @Inject constructor(@SessionDatabase private
|
||||||
}
|
}
|
||||||
|
|
||||||
Timber.v("On sync completed")
|
Timber.v("On sync completed")
|
||||||
cryptoSyncHandler.onSyncCompleted(syncResponse)
|
cryptoSyncHandler.onSyncCompleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue