Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ complexity:
ignoreAnnotated: [ 'Composable' ]
LongParameterList:
active: true
functionThreshold: 6
functionThreshold: 7
constructorThreshold: 7
ignoreDefaultParameters: false
ignoreDataClasses: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public actual class CoreLogic(

actual override val globalPreferences: GlobalPrefProvider = GlobalPrefProvider(
appContext,
kaliumConfigs.shouldEncryptData
kaliumConfigs.shouldEncryptData()
)

actual override val globalDatabaseBuilder: GlobalDatabaseBuilder = globalDatabaseProvider(
platformDatabaseData = PlatformDatabaseData(appContext),
queriesContext = KaliumDispatcherImpl.io,
passphrase = if (kaliumConfigs.shouldEncryptData) {
passphrase = if (kaliumConfigs.shouldEncryptData()) {
SecurityHelperImpl(globalPreferences.passphraseStorage).globalDBSecret()
} else {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ public actual class CoreLogic(
actual override val globalPreferences: GlobalPrefProvider =
GlobalPrefProvider(
rootPath = rootPath,
shouldEncryptData = kaliumConfigs.shouldEncryptData
shouldEncryptData = kaliumConfigs.shouldEncryptData()
)

// TODO: add support for encrypted DB on apple platforms
actual override val globalDatabaseBuilder: GlobalDatabaseBuilder = globalDatabaseProvider(
platformDatabaseData = PlatformDatabaseData(
storageData = if (useInMemoryStorage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public class GlobalKaliumScope internal constructor(
get() = SessionDataSource(
globalDatabase.accountsDAO,
globalPreferences.authTokenStorage,
globalDatabase.serverConfigurationDAO,
kaliumConfigs
globalDatabase.serverConfigurationDAO
)

public val observePersistentWebSocketConnectionStatus: ObservePersistentWebSocketConnectionStatusUseCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,14 @@ internal class UserConfigDataSource internal constructor(

override fun isFileSharingEnabled(): Either<StorageFailure, FileSharingStatus> {
val serverSideConfig = wrapStorageRequest { userConfigStorage.isFileSharingEnabled() }
val buildConfig = kaliumConfigs.fileRestrictionState
return deriveFileSharingStatus(serverSideConfig, buildConfig)
return deriveFileSharingStatus(serverSideConfig, kaliumConfigs.fileRestrictionState.value)
}

override fun isFileSharingEnabledFlow(): Flow<Either<StorageFailure, FileSharingStatus>> =
userConfigStorage.isFileSharingEnabledFlow()
.wrapStorageRequest()
.map {
val buildConfig = kaliumConfigs.fileRestrictionState
deriveFileSharingStatus(it, buildConfig)
deriveFileSharingStatus(it, kaliumConfigs.fileRestrictionState.value)
}

private fun deriveFileSharingStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import com.wire.kalium.logic.data.logout.LogoutReason
import com.wire.kalium.logic.data.user.SsoId
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.di.MapperProvider
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.common.functional.Either
import com.wire.kalium.common.functional.flatMap
import com.wire.kalium.common.functional.getOrElse
Expand Down Expand Up @@ -61,6 +60,7 @@ internal interface SessionRepository {
accountTokens: AccountTokens,
proxyCredentials: ProxyCredentials?,
managedBy: SsoManagedBy?,
isPersistentWebSocketEnabled: Boolean,
): Either<StorageFailure, Unit>

suspend fun allSessions(): Either<StorageFailure, List<AccountInfo>>
Expand Down Expand Up @@ -91,7 +91,6 @@ internal class SessionDataSource internal constructor(
private val accountsDAO: AccountsDAO,
private val authTokenStorage: AuthTokenStorage,
private val serverConfigDAO: ServerConfigurationDAO,
private val kaliumConfigs: KaliumConfigs,
private val serverConfigMapper: ServerConfigMapper = MapperProvider.serverConfigMapper(),
private val sessionMapper: SessionMapper = MapperProvider.sessionMapper(),
private val idMapper: IdMapper = MapperProvider.idMapper()
Expand All @@ -103,14 +102,15 @@ internal class SessionDataSource internal constructor(
accountTokens: AccountTokens,
proxyCredentials: ProxyCredentials?,
managedBy: SsoManagedBy?,
isPersistentWebSocketEnabled: Boolean,
): Either<StorageFailure, Unit> =
wrapStorageRequest {
accountsDAO.insertOrReplace(
userIDEntity = accountTokens.userId.toDao(),
ssoIdEntity = sessionMapper.toSsoIdEntity(ssoId),
managedByEntity = managedBy?.toDao(),
serverConfigId = serverConfigId,
isPersistentWebSocketEnabled = kaliumConfigs.isWebSocketEnabledByDefault
isPersistentWebSocketEnabled = isPersistentWebSocketEnabled
)
}.flatMap {
wrapStorageRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public class UserSessionScope internal constructor(
private val userStorage = userStorageProvider.getOrCreate(
userId,
platformUserStorageProperties,
kaliumConfigs.shouldEncryptData,
kaliumConfigs.shouldEncryptData(),
kaliumConfigs.dbInvalidationControlEnabled
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
@file:Suppress("konsist.useCasesShouldNotAccessDaoLayerDirectly",)
@file:Suppress("konsist.useCasesShouldNotAccessDaoLayerDirectly")

package com.wire.kalium.logic.feature.auth

import com.wire.kalium.common.error.CoreFailure
import com.wire.kalium.logic.data.auth.AccountTokens
import com.wire.kalium.common.error.wrapStorageRequest
import com.wire.kalium.common.functional.fold
import com.wire.kalium.common.functional.getOrElse
import com.wire.kalium.common.functional.map
import com.wire.kalium.common.functional.onSuccess
import com.wire.kalium.logic.configuration.server.ServerConfigMapper
import com.wire.kalium.logic.data.auth.AccountTokens
import com.wire.kalium.logic.data.auth.login.ProxyCredentials
import com.wire.kalium.logic.data.session.SessionRepository
import com.wire.kalium.logic.data.user.SsoId
import com.wire.kalium.logic.data.user.SsoManagedBy
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.di.MapperProvider
import com.wire.kalium.common.functional.fold
import com.wire.kalium.common.functional.getOrElse
import com.wire.kalium.common.functional.map
import com.wire.kalium.common.functional.onSuccess
import com.wire.kalium.common.error.wrapStorageRequest
import com.wire.kalium.logic.data.user.SsoManagedBy
import com.wire.kalium.persistence.daokaliumdb.ServerConfigurationDAO

/**
Expand All @@ -59,34 +59,58 @@ public class AddAuthenticatedUserUseCase internal constructor(
ssoId: SsoId?,
authTokens: AccountTokens,
proxyCredentials: ProxyCredentials?,
isPersistentWebSocketEnabled: Boolean,
managedBy: SsoManagedBy? = null,
replace: Boolean = false
): Result = sessionRepository.doesValidSessionExist(authTokens.userId).fold(
{
Result.Failure.Generic(it)
},
{
Result.Failure.Generic(it)
},
{ doesValidSessionExist ->
when (doesValidSessionExist) {
true -> onUserExist(serverConfigId, ssoId, authTokens, proxyCredentials, managedBy, replace)
false -> storeUser(serverConfigId, ssoId, authTokens, proxyCredentials, managedBy)
}
when (doesValidSessionExist) {
true -> onUserExist(
serverConfigId,
ssoId,
authTokens,
proxyCredentials,
managedBy,
replace,
isPersistentWebSocketEnabled,
)

false -> storeUser(
serverConfigId,
ssoId,
authTokens,
proxyCredentials,
managedBy,
isPersistentWebSocketEnabled
)
}
)
}
)

private suspend fun storeUser(
serverConfigId: String,
ssoId: SsoId?,
accountTokens: AccountTokens,
proxyCredentials: ProxyCredentials?,
managedBy: SsoManagedBy?,
isPersistentWebSocketEnabled: Boolean,
): Result =
sessionRepository.storeSession(serverConfigId, ssoId, accountTokens, proxyCredentials, managedBy)
.onSuccess {
sessionRepository.updateCurrentSession(accountTokens.userId)
}.fold(
{ Result.Failure.Generic(it) },
{ Result.Success(accountTokens.userId) }
)
sessionRepository.storeSession(
serverConfigId,
ssoId,
accountTokens,
proxyCredentials,
managedBy,
isPersistentWebSocketEnabled
).onSuccess {
sessionRepository.updateCurrentSession(accountTokens.userId)
}.fold(
{ Result.Failure.Generic(it) },
{ Result.Success(accountTokens.userId) }
)

// In case of the new session have a different server configurations the new session should not be added
@Suppress("LongParameterList")
Expand All @@ -96,7 +120,8 @@ public class AddAuthenticatedUserUseCase internal constructor(
newAccountTokens: AccountTokens,
proxyCredentials: ProxyCredentials?,
managedBy: SsoManagedBy?,
replace: Boolean
replace: Boolean,
isPersistentWebSocketEnabled: Boolean,
): Result =
when (replace) {
true -> {
Expand All @@ -117,6 +142,7 @@ public class AddAuthenticatedUserUseCase internal constructor(
accountTokens = newAccountTokens,
proxyCredentials = proxyCredentials,
managedBy = managedBy,
isPersistentWebSocketEnabled = isPersistentWebSocketEnabled,
)
} else Result.Failure.UserAlreadyExists
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import kotlin.time.Duration.Companion.hours

public data class KaliumConfigs(
val forceConstantBitrateCalls: Boolean = false,
val fileRestrictionState: BuildFileRestrictionState = BuildFileRestrictionState.NoRestriction,
// Lazy provider for file restriction state - evaluated when needed
val fileRestrictionState: Lazy<BuildFileRestrictionState> = lazy { BuildFileRestrictionState.NoRestriction },
// Lazy provider for encryption setting - evaluated when needed
// Disabling db-encryption will crash on android-api level below 30
val shouldEncryptData: Boolean = true,
val shouldEncryptData: () -> Boolean = { true },
val encryptProteusStorage: Boolean = false, // TODO not used can be removed
val lowerKeyPackageLimits: Boolean = false,
val developmentApiEnabled: Boolean = false,
Expand All @@ -38,7 +40,6 @@ public data class KaliumConfigs(
val wipeOnCookieInvalid: Boolean = false,
val wipeOnDeviceRemoval: Boolean = false,
val wipeOnRootedDevice: Boolean = false,
val isWebSocketEnabledByDefault: Boolean = false,
val certPinningConfig: Map<String, List<String>> = emptyMap(),
val mockedRequests: List<TestRequestHandler>? = null,
val mockNetworkStateObserver: NetworkStateObserver? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.wire.kalium.logic.data.session

import com.wire.kalium.logic.di.MapperProvider
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.persistence.client.AuthTokenStorage
import com.wire.kalium.persistence.dao.UserIDEntity
import com.wire.kalium.persistence.daokaliumdb.AccountInfoEntity
Expand Down Expand Up @@ -78,11 +77,10 @@ class SessionRepositoryTest {
val accountsDAO: AccountsDAO = mock(AccountsDAO::class)
val authTokenStorage: AuthTokenStorage = mock(AuthTokenStorage::class)

val kaliumConfigs: KaliumConfigs = KaliumConfigs()
val serverConfigurationDAO: ServerConfigurationDAO = mock(ServerConfigurationDAO::class)

private val sessionRepository =
SessionDataSource(accountsDAO, authTokenStorage, serverConfigurationDAO, kaliumConfigs)
SessionDataSource(accountsDAO, authTokenStorage, serverConfigurationDAO)

val validAccountIndoEntity = AccountInfoEntity(userIDEntity = UserIDEntity("1", "domain"), null)

Expand Down
Loading
Loading