Skip to content

Commit

Permalink
fix: some end points are not routed through the proxy server v4.5 (#2485
Browse files Browse the repository at this point in the history
)

* fix: some end points are not routed through the proxy server (#2400)

* fix: some end points are not routed through the proxy server

* fix cli

* fix android sample

* fix test service

* detekt

* fix ios target

* fix tests

* refactor: reimplement update api versions usecase to use proxy (#2414)

* refactor: implement UpdateApiVersionsUseCaseImpl to be proxy safe

* feat: add proxy URL and need auth indication to custom server dialogs

* fix tests

(cherry picked from commit b1f1457)

* fix cherry pick issues

* detekt

* trigger CI

* fix import

* fix test
  • Loading branch information
MohamadJaara authored Feb 19, 2024
1 parent e888167 commit 5651bb1
Show file tree
Hide file tree
Showing 64 changed files with 1,244 additions and 791 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class MainActivity : ComponentActivity() {
}

private suspend fun provideAuthScope(coreLogic: CoreLogic, backendLinks: ServerConfig.Links): AuthenticationScope =
when (val result = coreLogic.versionedAuthenticationScope(backendLinks).invoke()) {
when (val result = coreLogic.versionedAuthenticationScope(backendLinks).invoke(null)) {
is AutoVersionAuthScopeUseCase.Result.Failure.Generic -> error("Generic failure")
AutoVersionAuthScopeUseCase.Result.Failure.TooNewVersion -> error("Too new version")
AutoVersionAuthScopeUseCase.Result.Failure.UnknownServerVersion -> error("Unknown server version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class LoginCommand : CliktCommand(name = "login") {
}

private suspend fun provideVersionedAuthenticationScope(serverLinks: ServerConfig.Links): AuthenticationScope =
when (val result = coreLogic.versionedAuthenticationScope(serverLinks).invoke()) {
// CLI does not support proxy mode so we can pass null here
when (val result = coreLogic.versionedAuthenticationScope(serverLinks).invoke(null)) {
is AutoVersionAuthScopeUseCase.Result.Failure.Generic ->
throw PrintMessage("failed to create authentication scope: ${result.genericFailure}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import com.wire.kalium.logic.feature.UserSessionScopeProvider
import com.wire.kalium.logic.feature.UserSessionScopeProviderImpl
import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.logic.network.NetworkStateObserverImpl
import com.wire.kalium.logic.sync.GlobalWorkScheduler
import com.wire.kalium.logic.sync.GlobalWorkSchedulerImpl
import com.wire.kalium.logic.util.PlatformContext
import com.wire.kalium.logic.util.SecurityHelperImpl
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.persistence.db.GlobalDatabaseProvider
import com.wire.kalium.persistence.kmmSettings.GlobalPrefProvider
import kotlinx.coroutines.cancel
Expand Down Expand Up @@ -83,6 +83,7 @@ actual class CoreLogic(
rootPathsProvider,
appContext,
getGlobalScope(),
globalDatabase,
kaliumConfigs,
globalPreferences,
globalCallManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ import com.wire.kalium.logic.feature.auth.AuthenticationScopeProvider
import com.wire.kalium.logic.feature.auth.LogoutCallback
import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.logic.sync.UserSessionWorkScheduler
import com.wire.kalium.logic.util.SecurityHelperImpl
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.persistence.db.GlobalDatabaseProvider
import com.wire.kalium.persistence.kmmSettings.GlobalPrefProvider

@Suppress("LongParameterList")
Expand All @@ -43,6 +44,7 @@ internal fun UserSessionScope(
userAgent: String,
userId: UserId,
globalScope: GlobalKaliumScope,
globalDatabaseProvider: GlobalDatabaseProvider,
globalCallManager: GlobalCallManager,
globalPreferences: GlobalPrefProvider,
authenticationScopeProvider: AuthenticationScopeProvider,
Expand All @@ -65,6 +67,7 @@ internal fun UserSessionScope(
userId,
globalScope,
globalCallManager,
globalDatabaseProvider,
globalPreferences,
authenticationScopeProvider,
userSessionWorkScheduler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ import com.wire.kalium.logic.feature.auth.AuthenticationScopeProvider
import com.wire.kalium.logic.feature.auth.LogoutCallback
import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.logic.sync.UserSessionWorkSchedulerImpl
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.persistence.db.GlobalDatabaseProvider
import com.wire.kalium.persistence.kmmSettings.GlobalPrefProvider
import com.wire.kalium.persistence.util.FileNameUtil

Expand All @@ -44,6 +45,7 @@ internal actual class UserSessionScopeProviderImpl(
private val rootPathsProvider: RootPathsProvider,
private val appContext: Context,
private val globalScope: GlobalKaliumScope,
private val globalDatabaseProvider: GlobalDatabaseProvider,
private val kaliumConfigs: KaliumConfigs,
private val globalPreferences: GlobalPrefProvider,
private val globalCallManager: GlobalCallManager,
Expand All @@ -67,6 +69,7 @@ internal actual class UserSessionScopeProviderImpl(
globalScope = globalScope,
globalCallManager = globalCallManager,
globalPreferences = globalPreferences,
globalDatabaseProvider = globalDatabaseProvider,
authenticationScopeProvider = authenticationScopeProvider,
userSessionWorkScheduler = userSessionWorkScheduler,
rootPathsProvider = rootPathsProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ actual class CoreLogic(
kaliumConfigs,
globalPreferences,
globalCallManager,
globalDatabase,
userStorageProvider,
networkStateObserver,
logoutCallbackManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.logic.sync.UserSessionWorkScheduler
import com.wire.kalium.persistence.db.GlobalDatabaseProvider
import com.wire.kalium.persistence.kmmSettings.GlobalPrefProvider

@Suppress("LongParameterList")
Expand All @@ -42,6 +43,7 @@ internal fun UserSessionScope(
globalScope: GlobalKaliumScope,
globalCallManager: GlobalCallManager,
globalPreferences: GlobalPrefProvider,
globalDatabaseProvider: GlobalDatabaseProvider,
authenticationScopeProvider: AuthenticationScopeProvider,
userSessionWorkScheduler: UserSessionWorkScheduler,
rootPathsProvider: RootPathsProvider,
Expand All @@ -61,6 +63,7 @@ internal fun UserSessionScope(
userId,
globalScope,
globalCallManager,
globalDatabaseProvider,
globalPreferences,
authenticationScopeProvider,
userSessionWorkScheduler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.logic.sync.UserSessionWorkSchedulerImpl
import com.wire.kalium.persistence.db.GlobalDatabaseProvider
import com.wire.kalium.persistence.kmmSettings.GlobalPrefProvider

@Suppress("LongParameterList")
Expand All @@ -44,6 +45,7 @@ internal actual class UserSessionScopeProviderImpl(
private val kaliumConfigs: KaliumConfigs,
private val globalPreferences: GlobalPrefProvider,
private val globalCallManager: GlobalCallManager,
private val globalDatabaseProvider: GlobalDatabaseProvider,
private val userStorageProvider: UserStorageProvider,
private val networkStateObserver: NetworkStateObserver,
private val logoutCallback: LogoutCallback,
Expand All @@ -63,6 +65,7 @@ internal actual class UserSessionScopeProviderImpl(
globalScope,
globalCallManager,
globalPreferences,
globalDatabaseProvider,
authenticationScopeProvider,
userSessionWorkScheduler,
rootPathsProvider,
Expand Down
17 changes: 10 additions & 7 deletions logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class CoreLogicCommon internal constructor(
protected val idMapper: IdMapper = MapperProvider.idMapper()
) {
protected abstract val globalPreferences: GlobalPrefProvider
protected abstract val globalDatabase: GlobalDatabaseProvider
internal abstract val globalDatabase: GlobalDatabaseProvider
protected abstract val userSessionScopeProvider: Lazy<UserSessionScopeProvider>
protected val userStorageProvider: UserStorageProvider = PlatformUserStorageProvider()

Expand All @@ -75,15 +75,14 @@ abstract class CoreLogicCommon internal constructor(
@Suppress("MemberVisibilityCanBePrivate") // Can be used by other targets like iOS and JS
fun getAuthenticationScope(
serverConfig: ServerConfig,
proxyCredentials: ProxyCredentials? = null
proxyCredentials: ProxyCredentials?
): AuthenticationScope =
authenticationScopeProvider.provide(
serverConfig,
proxyCredentials,
getGlobalScope().serverConfigRepository,
networkStateObserver,
kaliumConfigs::certPinningConfig,
kaliumConfigs.kaliumMockEngine?.mockEngine
globalDatabase,
kaliumConfigs
)

@Suppress("MemberVisibilityCanBePrivate") // Can be used by other targets like iOS and JS
Expand All @@ -94,8 +93,12 @@ abstract class CoreLogicCommon internal constructor(
// TODO: make globalScope a singleton
inline fun <T> globalScope(action: GlobalKaliumScope.() -> T): T = getGlobalScope().action()

inline fun <T> authenticationScope(serverConfig: ServerConfig, action: AuthenticationScope.() -> T): T =
getAuthenticationScope(serverConfig).action()
inline fun <T> authenticationScope(
serverConfig: ServerConfig,
proxyCredentials: ProxyCredentials?,
action: AuthenticationScope.() -> T
): T =
getAuthenticationScope(serverConfig, proxyCredentials).action()

inline fun <T> sessionScope(
userId: UserId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package com.wire.kalium.logic

import com.wire.kalium.logic.configuration.notification.NotificationTokenDataSource
import com.wire.kalium.logic.configuration.notification.NotificationTokenRepository
import com.wire.kalium.logic.configuration.server.ServerConfigDataSource
import com.wire.kalium.logic.configuration.server.ServerConfigRepository
import com.wire.kalium.logic.configuration.server.CustomServerConfigDataSource
import com.wire.kalium.logic.configuration.server.CustomServerConfigRepository
import com.wire.kalium.logic.data.client.UserClientRepositoryProvider
import com.wire.kalium.logic.data.client.UserClientRepositoryProviderImpl
import com.wire.kalium.logic.data.session.SessionDataSource
Expand Down Expand Up @@ -49,10 +49,7 @@ import com.wire.kalium.logic.feature.notificationToken.SaveNotificationTokenUseC
import com.wire.kalium.logic.feature.rootDetection.CheckSystemIntegrityUseCase
import com.wire.kalium.logic.feature.rootDetection.CheckSystemIntegrityUseCaseImpl
import com.wire.kalium.logic.feature.rootDetection.RootDetectorImpl
import com.wire.kalium.logic.feature.server.FetchApiVersionUseCase
import com.wire.kalium.logic.feature.server.FetchApiVersionUseCaseImpl
import com.wire.kalium.logic.feature.server.GetServerConfigUseCase
import com.wire.kalium.logic.feature.server.ObserveServerConfigUseCase
import com.wire.kalium.logic.feature.server.ServerConfigForAccountUseCase
import com.wire.kalium.logic.feature.server.StoreServerConfigUseCase
import com.wire.kalium.logic.feature.server.StoreServerConfigUseCaseImpl
Expand Down Expand Up @@ -102,27 +99,17 @@ class GlobalKaliumScope internal constructor(
val unboundNetworkContainer: UnboundNetworkContainer by lazy {
UnboundNetworkContainerCommon(
networkStateObserver,
kaliumConfigs.developmentApiEnabled,
userAgent,
kaliumConfigs.ignoreSSLCertificatesForUnboundCalls,
kaliumConfigs.certPinningConfig,
kaliumConfigs.kaliumMockEngine?.mockEngine
)
}

internal val serverConfigRepository: ServerConfigRepository
get() = ServerConfigDataSource(
unboundNetworkContainer.serverConfigApi,
globalDatabase.serverConfigurationDAO,
unboundNetworkContainer.remoteVersion,
kaliumConfigs.developmentApiEnabled
)

val sessionRepository: SessionRepository
get() = SessionDataSource(
globalDatabase.accountsDAO,
globalPreferences.authTokenStorage,
serverConfigRepository,
globalDatabase.serverConfigurationDAO,
kaliumConfigs
)

Expand All @@ -133,24 +120,41 @@ class GlobalKaliumScope internal constructor(
get() =
NotificationTokenDataSource(globalPreferences.tokenStorage)

private val customServerConfigRepository: CustomServerConfigRepository
get() = CustomServerConfigDataSource(
unboundNetworkContainer.serverConfigApi,
developmentApiEnabled = kaliumConfigs.developmentApiEnabled,
globalDatabase.serverConfigurationDAO
)
val validateEmailUseCase: ValidateEmailUseCase get() = ValidateEmailUseCaseImpl()
val validateUserHandleUseCase: ValidateUserHandleUseCase get() = ValidateUserHandleUseCaseImpl()
val validatePasswordUseCase: ValidatePasswordUseCase get() = ValidatePasswordUseCaseImpl()

val addAuthenticatedAccount: AddAuthenticatedUserUseCase
get() =
AddAuthenticatedUserUseCase(sessionRepository, serverConfigRepository)
AddAuthenticatedUserUseCase(sessionRepository, globalDatabase.serverConfigurationDAO)
val getSessions: GetSessionsUseCase get() = GetSessionsUseCase(sessionRepository)
val doesValidSessionExist: DoesValidSessionExistUseCase get() = DoesValidSessionExistUseCase(sessionRepository)
val observeValidAccounts: ObserveValidAccountsUseCase
get() = ObserveValidAccountsUseCaseImpl(sessionRepository, userSessionScopeProvider.value)

val session: SessionScope get() = SessionScope(sessionRepository)
val fetchServerConfigFromDeepLink: GetServerConfigUseCase get() = GetServerConfigUseCase(serverConfigRepository)
val fetchApiVersion: FetchApiVersionUseCase get() = FetchApiVersionUseCaseImpl(serverConfigRepository)
val observeServerConfig: ObserveServerConfigUseCase get() = ObserveServerConfigUseCase(serverConfigRepository)
val updateApiVersions: UpdateApiVersionsUseCase get() = UpdateApiVersionsUseCaseImpl(serverConfigRepository)
val storeServerConfig: StoreServerConfigUseCase get() = StoreServerConfigUseCaseImpl(serverConfigRepository)
val fetchServerConfigFromDeepLink: GetServerConfigUseCase get() = GetServerConfigUseCase(customServerConfigRepository)
val updateApiVersions: UpdateApiVersionsUseCase
get() = UpdateApiVersionsUseCaseImpl(
sessionRepository,
globalPreferences.authTokenStorage,
{ serverConfig, proxyCredentials ->
authenticationScopeProvider.provide(
serverConfig,
proxyCredentials,
networkStateObserver,
globalDatabase = globalDatabase,
kaliumConfigs = kaliumConfigs,
).serverConfigRepository
},
)
val storeServerConfig: StoreServerConfigUseCase get() = StoreServerConfigUseCaseImpl(customServerConfigRepository)

val saveNotificationToken: SaveNotificationTokenUseCase
get() = SaveNotificationTokenUseCaseImpl(
Expand All @@ -163,15 +167,15 @@ class GlobalKaliumScope internal constructor(
get() = DeleteSessionUseCase(sessionRepository, userSessionScopeProvider.value)

val serverConfigForAccounts: ServerConfigForAccountUseCase
get() =
ServerConfigForAccountUseCase(serverConfigRepository)
get() = ServerConfigForAccountUseCase(globalDatabase.serverConfigurationDAO)

val observeIfAppUpdateRequired: ObserveIfAppUpdateRequiredUseCase
get() = ObserveIfAppUpdateRequiredUseCaseImpl(
serverConfigRepository,
customServerConfigRepository,
authenticationScopeProvider,
userSessionScopeProvider.value,
networkStateObserver,
globalDatabase,
kaliumConfigs
)

Expand Down
Loading

0 comments on commit 5651bb1

Please sign in to comment.