Make outbound key sharing strategy configurable.
This commit is contained in:
parent
d504a1f266
commit
ae648c3e11
@ -41,6 +41,7 @@ Improvements 🙌:
|
|||||||
- Improve room profile UX
|
- Improve room profile UX
|
||||||
- Upgrade Jitsi library from 2.9.3 to 3.1.0
|
- Upgrade Jitsi library from 2.9.3 to 3.1.0
|
||||||
- a11y improvements
|
- a11y improvements
|
||||||
|
- Pre-share session keys when opening a room or start typing (#2771)
|
||||||
|
|
||||||
Bugfix 🐛:
|
Bugfix 🐛:
|
||||||
- VoIP : fix audio devices output
|
- VoIP : fix audio devices output
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package org.matrix.android.sdk.api
|
package org.matrix.android.sdk.api
|
||||||
|
|
||||||
import org.matrix.android.sdk.api.crypto.MXCryptoConfig
|
import org.matrix.android.sdk.api.crypto.MXCryptoConfig
|
||||||
|
import org.matrix.android.sdk.api.crypto.OutboundSessionKeySharingStrategy
|
||||||
import java.net.Proxy
|
import java.net.Proxy
|
||||||
|
|
||||||
data class MatrixConfiguration(
|
data class MatrixConfiguration(
|
||||||
@ -40,6 +41,7 @@ data class MatrixConfiguration(
|
|||||||
* True to advertise support for call transfers to other parties on Matrix calls.
|
* True to advertise support for call transfers to other parties on Matrix calls.
|
||||||
*/
|
*/
|
||||||
val supportsCallTransfer: Boolean = false
|
val supportsCallTransfer: Boolean = false
|
||||||
|
val outboundSessionKeySharingStrategy: OutboundSessionKeySharingStrategy = OutboundSessionKeySharingStrategy.WhenSendingEvent
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.api.crypto
|
||||||
|
|
||||||
|
enum class OutboundSessionKeySharingStrategy {
|
||||||
|
/**
|
||||||
|
* Keys will be sent for the first time when the first message is sent
|
||||||
|
*/
|
||||||
|
WhenSendingEvent,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keys will be sent for the first time when the timeline displayed
|
||||||
|
*/
|
||||||
|
WhenEnteringRoom,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keys will be sent for the first time when a typing started
|
||||||
|
*/
|
||||||
|
WhenTyping
|
||||||
|
}
|
@ -156,4 +156,6 @@ interface CryptoService {
|
|||||||
fun getWithHeldMegolmSession(roomId: String, sessionId: String): RoomKeyWithHeldContent?
|
fun getWithHeldMegolmSession(roomId: String, sessionId: String): RoomKeyWithHeldContent?
|
||||||
|
|
||||||
fun logDbUsageInfo()
|
fun logDbUsageInfo()
|
||||||
|
|
||||||
|
fun ensureOutboundSession(roomId: String)
|
||||||
}
|
}
|
||||||
|
@ -1290,6 +1290,21 @@ internal class DefaultCryptoService @Inject constructor(
|
|||||||
cryptoStore.logDbUsageInfo()
|
cryptoStore.logDbUsageInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun ensureOutboundSession(roomId: String) {
|
||||||
|
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
|
||||||
|
roomEncryptorsStore
|
||||||
|
.get(roomId)
|
||||||
|
?.let {
|
||||||
|
getEncryptionAlgorithm(roomId)?.let { safeAlgorithm ->
|
||||||
|
val userIds = getRoomUserIds(roomId)
|
||||||
|
if (setEncryptionInRoom(roomId, safeAlgorithm, false, userIds)) {
|
||||||
|
roomEncryptorsStore.get(roomId)?.ensureOutboundSession(getRoomUserIds(roomId))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ==========================================================================================
|
/* ==========================================================================================
|
||||||
* For test only
|
* For test only
|
||||||
* ========================================================================================== */
|
* ========================================================================================== */
|
||||||
|
@ -62,4 +62,11 @@ internal interface IMXEncrypting {
|
|||||||
userId: String,
|
userId: String,
|
||||||
deviceId: String,
|
deviceId: String,
|
||||||
senderKey: String): Boolean
|
senderKey: String): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure the outbound session
|
||||||
|
*
|
||||||
|
* @param usersInRoom the users in the room
|
||||||
|
*/
|
||||||
|
suspend fun ensureOutboundSession(usersInRoom: List<String>)
|
||||||
}
|
}
|
||||||
|
@ -137,11 +137,10 @@ internal class MXMegolmEncryption(
|
|||||||
return MXOutboundSessionInfo(sessionId, SharedWithHelper(roomId, sessionId, cryptoStore))
|
return MXOutboundSessionInfo(sessionId, SharedWithHelper(roomId, sessionId, cryptoStore))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
override suspend fun ensureOutboundSession(usersInRoom: List<String>) {
|
||||||
* Ensure the outbound session
|
getDevicesInRoom(usersInRoom).allowedDevices
|
||||||
*
|
}
|
||||||
* @param devicesInRoom the devices list
|
|
||||||
*/
|
|
||||||
private suspend fun ensureOutboundSession(devicesInRoom: MXUsersDevicesMap<CryptoDeviceInfo>): MXOutboundSessionInfo {
|
private suspend fun ensureOutboundSession(devicesInRoom: MXUsersDevicesMap<CryptoDeviceInfo>): MXOutboundSessionInfo {
|
||||||
Timber.v("## CRYPTO | ensureOutboundSession start")
|
Timber.v("## CRYPTO | ensureOutboundSession start")
|
||||||
var session = outboundSession
|
var session = outboundSession
|
||||||
|
@ -85,4 +85,8 @@ internal class MXOlmEncryption(
|
|||||||
// No need for olm
|
// No need for olm
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun ensureOutboundSession(usersInRoom: List<String>) {
|
||||||
|
// NOOP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,13 @@ import io.realm.RealmQuery
|
|||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
import io.realm.Sort
|
import io.realm.Sort
|
||||||
import org.matrix.android.sdk.api.MatrixCallback
|
import org.matrix.android.sdk.api.MatrixCallback
|
||||||
|
import org.matrix.android.sdk.api.MatrixConfiguration
|
||||||
import org.matrix.android.sdk.api.NoOpMatrixCallback
|
import org.matrix.android.sdk.api.NoOpMatrixCallback
|
||||||
|
import org.matrix.android.sdk.api.crypto.OutboundSessionKeySharingStrategy
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
||||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||||
import org.matrix.android.sdk.api.session.events.model.RelationType
|
import org.matrix.android.sdk.api.session.events.model.RelationType
|
||||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||||
@ -80,8 +84,11 @@ internal class DefaultTimeline(
|
|||||||
private val timelineInput: TimelineInput,
|
private val timelineInput: TimelineInput,
|
||||||
private val eventDecryptor: TimelineEventDecryptor,
|
private val eventDecryptor: TimelineEventDecryptor,
|
||||||
private val realmSessionProvider: RealmSessionProvider,
|
private val realmSessionProvider: RealmSessionProvider,
|
||||||
private val loadRoomMembersTask: LoadRoomMembersTask
|
private val loadRoomMembersTask: LoadRoomMembersTask,
|
||||||
) : Timeline,
|
private val session: Session,
|
||||||
|
private val matrixConfiguration: MatrixConfiguration,
|
||||||
|
private val cryptoService: CryptoService
|
||||||
|
) : Timeline,
|
||||||
TimelineHiddenReadReceipts.Delegate,
|
TimelineHiddenReadReceipts.Delegate,
|
||||||
TimelineInput.Listener {
|
TimelineInput.Listener {
|
||||||
|
|
||||||
@ -188,6 +195,11 @@ internal class DefaultTimeline(
|
|||||||
}
|
}
|
||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
|
|
||||||
|
if (session.getRoom(roomId)?.isEncrypted().orFalse()
|
||||||
|
&& matrixConfiguration.outboundSessionKeySharingStrategy == OutboundSessionKeySharingStrategy.WhenEnteringRoom) {
|
||||||
|
cryptoService.ensureOutboundSession(roomId)
|
||||||
|
}
|
||||||
|
|
||||||
isReady.set(true)
|
isReady.set(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,11 @@ import org.matrix.android.sdk.internal.network.executeRequest
|
|||||||
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
||||||
import org.matrix.android.sdk.internal.task.Task
|
import org.matrix.android.sdk.internal.task.Task
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import org.matrix.android.sdk.api.MatrixConfiguration
|
||||||
|
import org.matrix.android.sdk.api.crypto.OutboundSessionKeySharingStrategy
|
||||||
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
||||||
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -38,12 +43,21 @@ internal interface SendTypingTask : Task<SendTypingTask.Params, Unit> {
|
|||||||
internal class DefaultSendTypingTask @Inject constructor(
|
internal class DefaultSendTypingTask @Inject constructor(
|
||||||
private val roomAPI: RoomAPI,
|
private val roomAPI: RoomAPI,
|
||||||
@UserId private val userId: String,
|
@UserId private val userId: String,
|
||||||
private val globalErrorReceiver: GlobalErrorReceiver
|
private val globalErrorReceiver: GlobalErrorReceiver,
|
||||||
|
private val matrixConfiguration: MatrixConfiguration,
|
||||||
|
private val session: Session,
|
||||||
|
private val cryptoService: CryptoService
|
||||||
) : SendTypingTask {
|
) : SendTypingTask {
|
||||||
|
|
||||||
override suspend fun execute(params: SendTypingTask.Params) {
|
override suspend fun execute(params: SendTypingTask.Params) {
|
||||||
delay(params.delay ?: -1)
|
delay(params.delay ?: -1)
|
||||||
|
|
||||||
|
if (params.isTyping
|
||||||
|
&& session.getRoom(params.roomId)?.isEncrypted().orFalse()
|
||||||
|
&& matrixConfiguration.outboundSessionKeySharingStrategy == OutboundSessionKeySharingStrategy.WhenTyping) {
|
||||||
|
cryptoService.ensureOutboundSession(params.roomId)
|
||||||
|
}
|
||||||
|
|
||||||
executeRequest<Unit>(globalErrorReceiver) {
|
executeRequest<Unit>(globalErrorReceiver) {
|
||||||
apiCall = roomAPI.sendTypingState(
|
apiCall = roomAPI.sendTypingState(
|
||||||
params.roomId,
|
params.roomId,
|
||||||
|
@ -136,6 +136,8 @@ android {
|
|||||||
buildConfigField "String", "BUILD_NUMBER", "\"${buildNumber}\""
|
buildConfigField "String", "BUILD_NUMBER", "\"${buildNumber}\""
|
||||||
resValue "string", "build_number", "\"${buildNumber}\""
|
resValue "string", "build_number", "\"${buildNumber}\""
|
||||||
|
|
||||||
|
buildConfigField "org.matrix.android.sdk.api.crypto.OutboundSessionKeySharingStrategy", "OutboundSessionKeySharingStrategy", "org.matrix.android.sdk.api.crypto.OutboundSessionKeySharingStrategy.WhenTyping"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
// Keep abiFilter for the universalApk
|
// Keep abiFilter for the universalApk
|
||||||
|
@ -205,7 +205,7 @@ class VectorApplication :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun providesMatrixConfiguration() = MatrixConfiguration(BuildConfig.FLAVOR_DESCRIPTION)
|
override fun providesMatrixConfiguration() = MatrixConfiguration(applicationFlavor = BuildConfig.FLAVOR_DESCRIPTION, outboundSessionKeySharingStrategy = BuildConfig.OutboundSessionKeySharingStrategy)
|
||||||
|
|
||||||
override fun getWorkManagerConfiguration(): WorkConfiguration {
|
override fun getWorkManagerConfiguration(): WorkConfiguration {
|
||||||
return WorkConfiguration.Builder()
|
return WorkConfiguration.Builder()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user