Keep MXCryptoConfig, but do a correct usage of it

This commit is contained in:
Benoit Marty 2020-02-04 15:31:47 +01:00
parent bd033866a8
commit 6bff951c72
7 changed files with 61 additions and 14 deletions

View file

@ -23,6 +23,8 @@ import androidx.work.WorkManager
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.BuildConfig import im.vector.matrix.android.BuildConfig
import im.vector.matrix.android.api.auth.AuthenticationService import im.vector.matrix.android.api.auth.AuthenticationService
import im.vector.matrix.android.api.crypto.MXCryptoConfig
import im.vector.matrix.android.internal.MatrixConfigurationHolder
import im.vector.matrix.android.internal.SessionManager import im.vector.matrix.android.internal.SessionManager
import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt
import im.vector.matrix.android.internal.crypto.attachments.MXEncryptedAttachments import im.vector.matrix.android.internal.crypto.attachments.MXEncryptedAttachments
@ -35,7 +37,8 @@ import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject import javax.inject.Inject
data class MatrixConfiguration( data class MatrixConfiguration(
val applicationFlavor: String = "Default-application-flavor" val applicationFlavor: String = "Default-application-flavor",
val cryptoConfig: MXCryptoConfig = MXCryptoConfig()
) { ) {
interface Provider { interface Provider {
@ -51,6 +54,7 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo
@Inject internal lateinit var authenticationService: AuthenticationService @Inject internal lateinit var authenticationService: AuthenticationService
@Inject internal lateinit var userAgentHolder: UserAgentHolder @Inject internal lateinit var userAgentHolder: UserAgentHolder
@Inject internal lateinit var matrixConfigurationHolder: MatrixConfigurationHolder
@Inject internal lateinit var backgroundDetectionObserver: BackgroundDetectionObserver @Inject internal lateinit var backgroundDetectionObserver: BackgroundDetectionObserver
@Inject internal lateinit var olmManager: OlmManager @Inject internal lateinit var olmManager: OlmManager
@Inject internal lateinit var sessionManager: SessionManager @Inject internal lateinit var sessionManager: SessionManager
@ -62,6 +66,7 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo
WorkManager.initialize(context, Configuration.Builder().build()) WorkManager.initialize(context, Configuration.Builder().build())
} }
ProcessLifecycleOwner.get().lifecycle.addObserver(backgroundDetectionObserver) ProcessLifecycleOwner.get().lifecycle.addObserver(backgroundDetectionObserver)
matrixConfigurationHolder.matrixConfiguration = matrixConfiguration.copy()
userAgentHolder.setApplicationFlavor(matrixConfiguration.applicationFlavor) userAgentHolder.setApplicationFlavor(matrixConfiguration.applicationFlavor)
} }

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package im.vector.matrix.android.internal.crypto package im.vector.matrix.android.api.crypto
/** /**
* Class to define the parameters used to customize or configure the end-to-end crypto. * Class to define the parameters used to customize or configure the end-to-end crypto.

View file

@ -0,0 +1,27 @@
/*
* Copyright 2020 New Vector Ltd
*
* 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 im.vector.matrix.android.internal
import im.vector.matrix.android.api.MatrixConfiguration
import im.vector.matrix.android.internal.di.MatrixScope
import javax.inject.Inject
@MatrixScope
internal class MatrixConfigurationHolder @Inject constructor() {
var matrixConfiguration: MatrixConfiguration? = null
}

View file

@ -159,13 +159,6 @@ internal abstract class CryptoModule {
fun providesRoomKeysAPI(retrofit: Retrofit): RoomKeysApi { fun providesRoomKeysAPI(retrofit: Retrofit): RoomKeysApi {
return retrofit.create(RoomKeysApi::class.java) return retrofit.create(RoomKeysApi::class.java)
} }
@JvmStatic
@Provides
@SessionScope
fun providesCryptoConfig(): MXCryptoConfig {
return MXCryptoConfig()
}
} }
@Binds @Binds

View file

@ -27,6 +27,7 @@ import com.zhuinden.monarchy.Monarchy
import dagger.Lazy import dagger.Lazy
import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.api.crypto.MXCryptoConfig
import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.failure.Failure
import im.vector.matrix.android.api.listeners.ProgressListener import im.vector.matrix.android.api.listeners.ProgressListener
import im.vector.matrix.android.api.session.crypto.CryptoService import im.vector.matrix.android.api.session.crypto.CryptoService
@ -116,7 +117,7 @@ internal class DefaultCryptoService @Inject constructor(
// Olm device // Olm device
private val olmDevice: MXOlmDevice, private val olmDevice: MXOlmDevice,
// Set of parameters used to configure/customize the end-to-end crypto. // Set of parameters used to configure/customize the end-to-end crypto.
private val cryptoConfig: MXCryptoConfig = MXCryptoConfig(), private val mxCryptoConfig: MXCryptoConfig,
// Device list manager // Device list manager
private val deviceListManager: DeviceListManager, private val deviceListManager: DeviceListManager,
// The key backup service. // The key backup service.
@ -399,6 +400,7 @@ internal class DefaultCryptoService @Inject constructor(
null null
} }
} }
override fun getCryptoDeviceInfo(userId: String): List<CryptoDeviceInfo> { override fun getCryptoDeviceInfo(userId: String): List<CryptoDeviceInfo> {
return cryptoStore.getUserDevices(userId)?.map { it.value } ?: emptyList() return cryptoStore.getUserDevices(userId)?.map { it.value } ?: emptyList()
} }
@ -545,8 +547,8 @@ internal class DefaultCryptoService @Inject constructor(
return cryptoStore.getUserDevices(userId)?.values?.toMutableList() ?: ArrayList() return cryptoStore.getUserDevices(userId)?.values?.toMutableList() ?: ArrayList()
} }
fun isEncryptionEnabledForInvitedUser(): Boolean { private fun isEncryptionEnabledForInvitedUser(): Boolean {
return cryptoConfig.enableEncryptionForInvitedMembers return mxCryptoConfig.enableEncryptionForInvitedMembers
} }
override fun getEncryptionAlgorithm(roomId: String): String? { override fun getEncryptionAlgorithm(roomId: String): String? {
@ -779,7 +781,7 @@ internal class DefaultCryptoService @Inject constructor(
deviceListManager.startTrackingDeviceList(listOf(userId)) deviceListManager.startTrackingDeviceList(listOf(userId))
} else if (membership == Membership.INVITE } else if (membership == Membership.INVITE
&& shouldEncryptForInvitedMembers(roomId) && shouldEncryptForInvitedMembers(roomId)
&& cryptoConfig.enableEncryptionForInvitedMembers) { && isEncryptionEnabledForInvitedUser()) {
// track the deviceList for this invited user. // track the deviceList for this invited user.
// Caution: there's a big edge case here in that federated servers do not // Caution: there's a big edge case here in that federated servers do not
// 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.

View file

@ -23,6 +23,7 @@ import dagger.BindsInstance
import dagger.Component import dagger.Component
import im.vector.matrix.android.api.Matrix import im.vector.matrix.android.api.Matrix
import im.vector.matrix.android.api.auth.AuthenticationService import im.vector.matrix.android.api.auth.AuthenticationService
import im.vector.matrix.android.internal.MatrixConfigurationHolder
import im.vector.matrix.android.internal.SessionManager import im.vector.matrix.android.internal.SessionManager
import im.vector.matrix.android.internal.auth.AuthModule import im.vector.matrix.android.internal.auth.AuthModule
import im.vector.matrix.android.internal.auth.SessionParamsStore import im.vector.matrix.android.internal.auth.SessionParamsStore
@ -46,6 +47,8 @@ internal interface MatrixComponent {
fun authenticationService(): AuthenticationService fun authenticationService(): AuthenticationService
fun matrixConfigurationHolder(): MatrixConfigurationHolder
fun context(): Context fun context(): Context
fun resources(): Resources fun resources(): Resources

View file

@ -27,14 +27,24 @@ import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.auth.data.SessionParams
import im.vector.matrix.android.api.auth.data.sessionId import im.vector.matrix.android.api.auth.data.sessionId
import im.vector.matrix.android.api.crypto.MXCryptoConfig
import im.vector.matrix.android.api.session.InitialSyncProgressService import im.vector.matrix.android.api.session.InitialSyncProgressService
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilitiesService import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilitiesService
import im.vector.matrix.android.api.session.securestorage.SecureStorageService import im.vector.matrix.android.api.session.securestorage.SecureStorageService
import im.vector.matrix.android.internal.MatrixConfigurationHolder
import im.vector.matrix.android.internal.crypto.verification.VerificationMessageLiveObserver import im.vector.matrix.android.internal.crypto.verification.VerificationMessageLiveObserver
import im.vector.matrix.android.internal.database.LiveEntityObserver import im.vector.matrix.android.internal.database.LiveEntityObserver
import im.vector.matrix.android.internal.database.SessionRealmConfigurationFactory import im.vector.matrix.android.internal.database.SessionRealmConfigurationFactory
import im.vector.matrix.android.internal.di.* import im.vector.matrix.android.internal.di.Authenticated
import im.vector.matrix.android.internal.di.DeviceId
import im.vector.matrix.android.internal.di.SessionCacheDirectory
import im.vector.matrix.android.internal.di.SessionDatabase
import im.vector.matrix.android.internal.di.SessionFilesDirectory
import im.vector.matrix.android.internal.di.SessionId
import im.vector.matrix.android.internal.di.Unauthenticated
import im.vector.matrix.android.internal.di.UserId
import im.vector.matrix.android.internal.di.UserMd5
import im.vector.matrix.android.internal.network.AccessTokenInterceptor import im.vector.matrix.android.internal.network.AccessTokenInterceptor
import im.vector.matrix.android.internal.network.RetrofitFactory import im.vector.matrix.android.internal.network.RetrofitFactory
import im.vector.matrix.android.internal.network.interceptors.CurlLoggingInterceptor import im.vector.matrix.android.internal.network.interceptors.CurlLoggingInterceptor
@ -178,6 +188,13 @@ internal abstract class SessionModule {
fun providesEventBus(): EventBus { fun providesEventBus(): EventBus {
return EventBus.builder().build() return EventBus.builder().build()
} }
@JvmStatic
@Provides
@SessionScope
fun providesMxCryptoConfig(matrixConfigurationHolder: MatrixConfigurationHolder): MXCryptoConfig {
return matrixConfigurationHolder.matrixConfiguration?.cryptoConfig ?: MXCryptoConfig()
}
} }
@Binds @Binds