From 736aef8c4331899b859c93cf7d0c53a072192965 Mon Sep 17 00:00:00 2001 From: Mohamad Jaara Date: Tue, 24 Sep 2024 10:27:13 +0200 Subject: [PATCH 1/6] revert me:fix login after deleting client --- .../cryptography/CoreCryptoCentralImpl.kt | 4 +++ .../CoreCryptoCentral.kt | 6 ++++ .../kalium/cryptography/CoreCryptoCentral.kt | 2 ++ .../logic/data/client/E2EIClientProvider.kt | 2 ++ .../logic/data/client/MLSClientProvider.kt | 30 +++++++++++++------ .../feature/client/ClearClientDataUseCase.kt | 2 ++ .../client/GetOrRegisterClientUseCase.kt | 5 +++- .../feature/client/RegisterClientUseCase.kt | 10 ++++++- .../client/RegisterMLSClientUseCase.kt | 2 ++ 9 files changed, 52 insertions(+), 11 deletions(-) diff --git a/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt b/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt index 89b42c5ac7f..367c5e5aab3 100644 --- a/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt +++ b/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt @@ -107,6 +107,10 @@ class CoreCryptoCentralImpl( TODO("Not yet implemented") } + override suspend fun wipe() { + TODO("Not yet implemented") + } + companion object { const val KEYSTORE_NAME = "keystore" } diff --git a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt index cc23081cdd7..b27bc6801ce 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt @@ -76,6 +76,7 @@ class CoreCryptoCentralImpl( allowedCipherSuites: Ciphersuites, defaultCipherSuite: UShort ): MLSClient { + kaliumLogger.d("CCCC mlsInit mlsClient") cc.mlsInit(clientId.toString().encodeToByteArray(), allowedCipherSuites, null) return MLSClientImpl(cc, defaultCipherSuite) } @@ -86,6 +87,7 @@ class CoreCryptoCentralImpl( newMLSKeyPackageCount: UInt, defaultCipherSuite: UShort ): MLSClient { + kaliumLogger.d("CCCC e2eiMlsInitOnly mlsClient") // todo: use DPs list from here, and return alongside with the mls client cc.e2eiMlsInitOnly( (enrollment as E2EIClientImpl).wireE2eIdentity, @@ -147,6 +149,10 @@ class CoreCryptoCentralImpl( } } + override suspend fun wipe() { + cc.wipe() + } + companion object { const val KEYSTORE_NAME = "keystore" } diff --git a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt index 6231e9f1625..599dd03815a 100644 --- a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt @@ -68,6 +68,8 @@ interface CoreCryptoCentral { * @param pem fetched certificate chain in pem format from the CA */ suspend fun registerIntermediateCa(pem: CertificateChain) + + suspend fun wipe() } expect suspend fun coreCryptoCentral( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/E2EIClientProvider.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/E2EIClientProvider.kt index 7e3de29d27d..facc8d2c57d 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/E2EIClientProvider.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/E2EIClientProvider.kt @@ -71,8 +71,10 @@ internal class EI2EIClientProviderImpl( } ?: run { getSelfUserInfo().flatMap { selfUser -> if (isNewClient) { + kaliumLogger.d("cccc createNewE2EIClient") createNewE2EIClient(currentClientId, selfUser) } else { + kaliumLogger.d("cccc getE2EIClientFromMLSClient") getE2EIClientFromMLSClient(currentClientId, selfUser) } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/MLSClientProvider.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/MLSClientProvider.kt index c5afd316cf8..e544cd7e7a2 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/MLSClientProvider.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/MLSClientProvider.kt @@ -141,9 +141,16 @@ class MLSClientProviderImpl( override suspend fun clearLocalFiles() { mlsClientMutex.withLock { - mlsClient?.close() - mlsClient = null - FileUtil.deleteDirectory(rootKeyStorePath) + coreCryptoCentralMutex.withLock { + kaliumLogger.d("cccc clearLocalFiles") +// coreCryptoCentral?.wipe() + mlsClient?.close() + mlsClient = null + coreCryptoCentral = null + FileUtil.deleteDirectory(rootKeyStorePath).let { + kaliumLogger.d("cccc clearLocalFiles in path $rootKeyStorePath $it") + } + } } } @@ -184,12 +191,17 @@ class MLSClientProviderImpl( private suspend fun mlsClient(userId: CryptoUserID, clientId: ClientId): Either { return getCoreCrypto(clientId).flatMap { cc -> - getOrFetchMLSConfig().map { (supportedCipherSuite, defaultCipherSuite) -> - cc.mlsClient( - clientId = CryptoQualifiedClientId(clientId.value, userId), - allowedCipherSuites = supportedCipherSuite.map { it.tag.toUShort() }, - defaultCipherSuite = defaultCipherSuite.tag.toUShort() - ) + getOrFetchMLSConfig().flatMap { (supportedCipherSuite, defaultCipherSuite) -> + try { + cc.mlsClient( + clientId = CryptoQualifiedClientId(clientId.value, userId), + allowedCipherSuites = supportedCipherSuite.map { it.tag.toUShort() }, + defaultCipherSuite = defaultCipherSuite.tag.toUShort() + ).right() + } catch (e: Exception) { + kaliumLogger.d("cccc ${e.stackTraceToString()}") + CoreFailure.Unknown(e).left() + } } } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/ClearClientDataUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/ClearClientDataUseCase.kt index 87e3c0c7508..38103f53987 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/ClearClientDataUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/ClearClientDataUseCase.kt @@ -60,8 +60,10 @@ internal class ClearClientDataUseCaseImpl internal constructor( private suspend fun clearCrypto(): Either = wrapProteusRequest { + kaliumLogger.d("cccc Clearing crypto storage") proteusClientProvider.clearLocalFiles() }.flatMap { + kaliumLogger.d("cccc Clearing MLS storage") wrapMLSRequest { mlsClientProvider.clearLocalFiles() } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt index 8d4d55d2ada..adea191b0f3 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt @@ -28,6 +28,7 @@ import com.wire.kalium.logic.feature.featureConfig.SyncFeatureConfigsUseCase import com.wire.kalium.logic.feature.session.UpgradeCurrentSessionUseCase import com.wire.kalium.logic.functional.flatMap import com.wire.kalium.logic.functional.nullableFold +import com.wire.kalium.logic.kaliumLogger /** * This use case is responsible for getting the client. @@ -53,7 +54,8 @@ internal class GetOrRegisterClientUseCaseImpl( ) : GetOrRegisterClientUseCase { override suspend fun invoke(registerClientParam: RegisterClientUseCase.RegisterClientParam): RegisterClientResult { - syncFeatureConfigsUseCase.invoke() + kaliumLogger.d("cccc GetOrRegisterClientUseCaseImpl.invoke") + syncFeatureConfigsUseCase() val result: RegisterClientResult = clientRepository.retainedClientId() .nullableFold( @@ -97,6 +99,7 @@ internal class GetOrRegisterClientUseCaseImpl( } private suspend fun clearOldClientRelatedData() { + kaliumLogger.d("cccc GetOrRegisterClientUseCaseImpl.clearOldClientRelatedData") cachedClientIdClearer() clearClientData() logoutRepository.clearClientRelatedLocalMetadata() diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterClientUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterClientUseCase.kt index 371ff3458bd..0a123c63388 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterClientUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterClientUseCase.kt @@ -135,7 +135,15 @@ class RegisterClientUseCaseImpl @OptIn(DelicateKaliumApi::class) internal constr val verificationCode = registerClientParam.secondFactorVerificationCode ?: currentlyStoredVerificationCode() sessionRepository.cookieLabel(selfUserId) .flatMap { cookieLabel -> - generateProteusPreKeys(preKeysToSend, password, capabilities, clientType, model, cookieLabel, verificationCode) + generateProteusPreKeys( + preKeysToSend, + password, + capabilities, + clientType, + model, + cookieLabel, + verificationCode + ) }.fold({ RegisterClientResult.Failure.Generic(it) }, { registerClientParam -> diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterMLSClientUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterMLSClientUseCase.kt index da1a61a906f..13a5ea83f23 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterMLSClientUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterMLSClientUseCase.kt @@ -57,8 +57,10 @@ internal class RegisterMLSClientUseCaseImpl( override suspend operator fun invoke(clientId: ClientId): Either { return userConfigRepository.getE2EISettings().flatMap { e2eiSettings -> if (e2eiSettings.isRequired && !mlsClientProvider.isMLSClientInitialised()) { + kaliumLogger.d("cccc isMLSClient is not init E2EICertificateRequired") return RegisterMLSClientResult.E2EICertificateRequired.right() } else { + kaliumLogger.d("cccc MLSClient is init") mlsClientProvider.getMLSClient(clientId) } }.onFailure { From 617eadb3f2dd9ac9d8517f0917fc0be829b38e5b Mon Sep 17 00:00:00 2001 From: Mohamad Jaara Date: Wed, 25 Sep 2024 09:33:40 +0200 Subject: [PATCH 2/6] fix: crash when login after deleting client and session expires --- .../CoreCryptoCentral.kt | 2 -- .../configuration/UserConfigRepository.kt | 10 +++---- .../logic/data/client/E2EIClientProvider.kt | 2 -- .../logic/data/client/MLSClientProvider.kt | 28 ++++++++----------- .../feature/client/ClearClientDataUseCase.kt | 2 -- .../client/GetOrRegisterClientUseCase.kt | 2 -- .../client/RegisterMLSClientUseCase.kt | 2 -- .../persistence/config/UserConfigStorage.kt | 10 ------- .../persistence/dao/unread/UserConfigDAO.kt | 10 +++++++ 9 files changed, 26 insertions(+), 42 deletions(-) diff --git a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt index b27bc6801ce..f53cd0b3276 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt @@ -76,7 +76,6 @@ class CoreCryptoCentralImpl( allowedCipherSuites: Ciphersuites, defaultCipherSuite: UShort ): MLSClient { - kaliumLogger.d("CCCC mlsInit mlsClient") cc.mlsInit(clientId.toString().encodeToByteArray(), allowedCipherSuites, null) return MLSClientImpl(cc, defaultCipherSuite) } @@ -87,7 +86,6 @@ class CoreCryptoCentralImpl( newMLSKeyPackageCount: UInt, defaultCipherSuite: UShort ): MLSClient { - kaliumLogger.d("CCCC e2eiMlsInitOnly mlsClient") // todo: use DPs list from here, and return alongside with the mls client cc.e2eiMlsInitOnly( (enrollment as E2EIClientImpl).wireE2eIdentity, diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/UserConfigRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/UserConfigRepository.kt index 29424e92db5..e82f799b4b6 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/UserConfigRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/UserConfigRepository.kt @@ -136,8 +136,8 @@ interface UserConfigRepository { suspend fun setShouldNotifyForRevokedCertificate(shouldNotify: Boolean) suspend fun observeShouldNotifyForRevokedCertificate(): Flow> suspend fun clearE2EISettings() - fun setShouldFetchE2EITrustAnchors(shouldFetch: Boolean) - fun getShouldFetchE2EITrustAnchor(): Boolean + suspend fun setShouldFetchE2EITrustAnchors(shouldFetch: Boolean) + suspend fun getShouldFetchE2EITrustAnchor(): Boolean } @Suppress("TooManyFunctions") @@ -500,9 +500,9 @@ internal class UserConfigDataSource internal constructor( override suspend fun observeShouldNotifyForRevokedCertificate(): Flow> = userConfigDAO.observeShouldNotifyForRevokedCertificate().wrapStorageRequest() - override fun setShouldFetchE2EITrustAnchors(shouldFetch: Boolean) { - userConfigStorage.setShouldFetchE2EITrustAnchors(shouldFetch = shouldFetch) + override suspend fun setShouldFetchE2EITrustAnchors(shouldFetch: Boolean) { + userConfigDAO.setShouldFetchE2EITrustAnchors(shouldFetch = shouldFetch) } - override fun getShouldFetchE2EITrustAnchor(): Boolean = userConfigStorage.getShouldFetchE2EITrustAnchorHasRun() + override suspend fun getShouldFetchE2EITrustAnchor(): Boolean = userConfigDAO.getShouldFetchE2EITrustAnchorHasRun() } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/E2EIClientProvider.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/E2EIClientProvider.kt index facc8d2c57d..7e3de29d27d 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/E2EIClientProvider.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/E2EIClientProvider.kt @@ -71,10 +71,8 @@ internal class EI2EIClientProviderImpl( } ?: run { getSelfUserInfo().flatMap { selfUser -> if (isNewClient) { - kaliumLogger.d("cccc createNewE2EIClient") createNewE2EIClient(currentClientId, selfUser) } else { - kaliumLogger.d("cccc getE2EIClientFromMLSClient") getE2EIClientFromMLSClient(currentClientId, selfUser) } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/MLSClientProvider.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/MLSClientProvider.kt index e544cd7e7a2..ce242232fb1 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/MLSClientProvider.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/MLSClientProvider.kt @@ -142,14 +142,10 @@ class MLSClientProviderImpl( override suspend fun clearLocalFiles() { mlsClientMutex.withLock { coreCryptoCentralMutex.withLock { - kaliumLogger.d("cccc clearLocalFiles") -// coreCryptoCentral?.wipe() mlsClient?.close() mlsClient = null coreCryptoCentral = null - FileUtil.deleteDirectory(rootKeyStorePath).let { - kaliumLogger.d("cccc clearLocalFiles in path $rootKeyStorePath $it") - } + FileUtil.deleteDirectory(rootKeyStorePath) } } } @@ -189,19 +185,17 @@ class MLSClientProviderImpl( } } - private suspend fun mlsClient(userId: CryptoUserID, clientId: ClientId): Either { + private suspend fun mlsClient( + userId: CryptoUserID, + clientId: ClientId + ): Either { return getCoreCrypto(clientId).flatMap { cc -> - getOrFetchMLSConfig().flatMap { (supportedCipherSuite, defaultCipherSuite) -> - try { - cc.mlsClient( - clientId = CryptoQualifiedClientId(clientId.value, userId), - allowedCipherSuites = supportedCipherSuite.map { it.tag.toUShort() }, - defaultCipherSuite = defaultCipherSuite.tag.toUShort() - ).right() - } catch (e: Exception) { - kaliumLogger.d("cccc ${e.stackTraceToString()}") - CoreFailure.Unknown(e).left() - } + getOrFetchMLSConfig().map { (supportedCipherSuite, defaultCipherSuite) -> + cc.mlsClient( + clientId = CryptoQualifiedClientId(clientId.value, userId), + allowedCipherSuites = supportedCipherSuite.map { it.tag.toUShort() }, + defaultCipherSuite = defaultCipherSuite.tag.toUShort() + ) } } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/ClearClientDataUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/ClearClientDataUseCase.kt index 38103f53987..87e3c0c7508 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/ClearClientDataUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/ClearClientDataUseCase.kt @@ -60,10 +60,8 @@ internal class ClearClientDataUseCaseImpl internal constructor( private suspend fun clearCrypto(): Either = wrapProteusRequest { - kaliumLogger.d("cccc Clearing crypto storage") proteusClientProvider.clearLocalFiles() }.flatMap { - kaliumLogger.d("cccc Clearing MLS storage") wrapMLSRequest { mlsClientProvider.clearLocalFiles() } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt index adea191b0f3..70ea86c227c 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt @@ -54,7 +54,6 @@ internal class GetOrRegisterClientUseCaseImpl( ) : GetOrRegisterClientUseCase { override suspend fun invoke(registerClientParam: RegisterClientUseCase.RegisterClientParam): RegisterClientResult { - kaliumLogger.d("cccc GetOrRegisterClientUseCaseImpl.invoke") syncFeatureConfigsUseCase() val result: RegisterClientResult = clientRepository.retainedClientId() @@ -99,7 +98,6 @@ internal class GetOrRegisterClientUseCaseImpl( } private suspend fun clearOldClientRelatedData() { - kaliumLogger.d("cccc GetOrRegisterClientUseCaseImpl.clearOldClientRelatedData") cachedClientIdClearer() clearClientData() logoutRepository.clearClientRelatedLocalMetadata() diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterMLSClientUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterMLSClientUseCase.kt index 13a5ea83f23..da1a61a906f 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterMLSClientUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/RegisterMLSClientUseCase.kt @@ -57,10 +57,8 @@ internal class RegisterMLSClientUseCaseImpl( override suspend operator fun invoke(clientId: ClientId): Either { return userConfigRepository.getE2EISettings().flatMap { e2eiSettings -> if (e2eiSettings.isRequired && !mlsClientProvider.isMLSClientInitialised()) { - kaliumLogger.d("cccc isMLSClient is not init E2EICertificateRequired") return RegisterMLSClientResult.E2EICertificateRequired.right() } else { - kaliumLogger.d("cccc MLSClient is init") mlsClientProvider.getMLSClient(clientId) } }.onFailure { diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/config/UserConfigStorage.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/config/UserConfigStorage.kt index b3542fb10f7..9f24823294d 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/config/UserConfigStorage.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/config/UserConfigStorage.kt @@ -178,8 +178,6 @@ interface UserConfigStorage { fun getE2EINotificationTime(): Long? fun e2EINotificationTimeFlow(): Flow fun updateE2EINotificationTime(timeStamp: Long) - fun setShouldFetchE2EITrustAnchors(shouldFetch: Boolean) - fun getShouldFetchE2EITrustAnchorHasRun(): Boolean } @Serializable @@ -576,13 +574,6 @@ class UserConfigStorageImpl( } } - override fun setShouldFetchE2EITrustAnchors(shouldFetch: Boolean) { - kaliumPreferences.putBoolean(SHOULD_FETCH_E2EI_GET_TRUST_ANCHORS, shouldFetch) - } - - override fun getShouldFetchE2EITrustAnchorHasRun(): Boolean = - kaliumPreferences.getBoolean(SHOULD_FETCH_E2EI_GET_TRUST_ANCHORS, true) - private companion object { const val FILE_SHARING = "file_sharing" const val GUEST_ROOM_LINK = "guest_room_link" @@ -601,6 +592,5 @@ class UserConfigStorageImpl( const val ENABLE_TYPING_INDICATOR = "enable_typing_indicator" const val APP_LOCK = "app_lock" const val DEFAULT_PROTOCOL = "default_protocol" - const val SHOULD_FETCH_E2EI_GET_TRUST_ANCHORS = "should_fetch_e2ei_trust_anchors" } } diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/unread/UserConfigDAO.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/unread/UserConfigDAO.kt index ede3482c411..e5d50626133 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/unread/UserConfigDAO.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/unread/UserConfigDAO.kt @@ -60,6 +60,8 @@ interface UserConfigDAO { suspend fun observeShouldNotifyForRevokedCertificate(): Flow suspend fun setDefaultCipherSuite(cipherSuite: SupportedCipherSuiteEntity) suspend fun getDefaultCipherSuite(): SupportedCipherSuiteEntity? + suspend fun setShouldFetchE2EITrustAnchors(shouldFetch: Boolean) + suspend fun getShouldFetchE2EITrustAnchorHasRun(): Boolean } @Suppress("TooManyFunctions") @@ -186,6 +188,13 @@ internal class UserConfigDAOImpl internal constructor( override suspend fun getDefaultCipherSuite(): SupportedCipherSuiteEntity? = metadataDAO.getSerializable(DEFAULT_CIPHER_SUITE_KEY, SupportedCipherSuiteEntity.serializer()) + override suspend fun setShouldFetchE2EITrustAnchors(shouldFetch: Boolean) { + metadataDAO.insertValue(value = shouldFetch.toString(), key = SHOULD_FETCH_E2EI_GET_TRUST_ANCHORS) + } + + override suspend fun getShouldFetchE2EITrustAnchorHasRun(): Boolean = + metadataDAO.valueByKey(SHOULD_FETCH_E2EI_GET_TRUST_ANCHORS)?.toBoolean() ?: true + private companion object { private const val DEFAULT_CIPHER_SUITE_KEY = "DEFAULT_CIPHER_SUITE" private const val SELF_DELETING_MESSAGES_KEY = "SELF_DELETING_MESSAGES" @@ -196,5 +205,6 @@ internal class UserConfigDAOImpl internal constructor( const val LEGAL_HOLD_CHANGE_NOTIFIED = "legal_hold_change_notified" const val SHOULD_UPDATE_CLIENT_LEGAL_HOLD_CAPABILITY = "should_update_client_legal_hold_capability" + const val SHOULD_FETCH_E2EI_GET_TRUST_ANCHORS = "should_fetch_e2ei_trust_anchors" } } From 3d8c97902529362140fd183fe8ed76b482820b60 Mon Sep 17 00:00:00 2001 From: Mohamad Jaara Date: Wed, 25 Sep 2024 09:35:18 +0200 Subject: [PATCH 3/6] cleanup --- .../com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt | 4 ---- .../kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt | 4 ---- .../kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt | 2 -- 3 files changed, 10 deletions(-) diff --git a/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt b/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt index 367c5e5aab3..89b42c5ac7f 100644 --- a/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt +++ b/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt @@ -107,10 +107,6 @@ class CoreCryptoCentralImpl( TODO("Not yet implemented") } - override suspend fun wipe() { - TODO("Not yet implemented") - } - companion object { const val KEYSTORE_NAME = "keystore" } diff --git a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt index f53cd0b3276..cc23081cdd7 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt @@ -147,10 +147,6 @@ class CoreCryptoCentralImpl( } } - override suspend fun wipe() { - cc.wipe() - } - companion object { const val KEYSTORE_NAME = "keystore" } diff --git a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt index 599dd03815a..6231e9f1625 100644 --- a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt @@ -68,8 +68,6 @@ interface CoreCryptoCentral { * @param pem fetched certificate chain in pem format from the CA */ suspend fun registerIntermediateCa(pem: CertificateChain) - - suspend fun wipe() } expect suspend fun coreCryptoCentral( From dbe2fa13479ba50bbbf765a7f06d4726372e8431 Mon Sep 17 00:00:00 2001 From: Mohamad Jaara Date: Wed, 25 Sep 2024 10:06:01 +0200 Subject: [PATCH 4/6] detekt --- .../kalium/logic/feature/client/GetOrRegisterClientUseCase.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt index 70ea86c227c..85173b1e8cd 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/client/GetOrRegisterClientUseCase.kt @@ -28,7 +28,6 @@ import com.wire.kalium.logic.feature.featureConfig.SyncFeatureConfigsUseCase import com.wire.kalium.logic.feature.session.UpgradeCurrentSessionUseCase import com.wire.kalium.logic.functional.flatMap import com.wire.kalium.logic.functional.nullableFold -import com.wire.kalium.logic.kaliumLogger /** * This use case is responsible for getting the client. From 94757f3fabe5e5702155bc1a25da58e6c3a5d5d8 Mon Sep 17 00:00:00 2001 From: Mohamad Jaara Date: Wed, 25 Sep 2024 11:39:24 +0200 Subject: [PATCH 5/6] tests --- .../com/wire/kalium/logic/data/e2ei/E2EIRepositoryTest.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/e2ei/E2EIRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/e2ei/E2EIRepositoryTest.kt index 26f90778c6c..ad75de19ac1 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/e2ei/E2EIRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/e2ei/E2EIRepositoryTest.kt @@ -1017,7 +1017,7 @@ class E2EIRepositoryTest { result.shouldSucceed() verify(arrangement.userConfigRepository) - .function(arrangement.userConfigRepository::getShouldFetchE2EITrustAnchor) + .suspendFunction(arrangement.userConfigRepository::getShouldFetchE2EITrustAnchor) .wasInvoked(once) } @@ -1203,14 +1203,14 @@ class E2EIRepositoryTest { fun withGetShouldFetchE2EITrustAnchors(result: Boolean) = apply { given(userConfigRepository) - .function(userConfigRepository::getShouldFetchE2EITrustAnchor) + .suspendFunction(userConfigRepository::getShouldFetchE2EITrustAnchor) .whenInvoked() .thenReturn(result) } fun withSetShouldFetchE2EIGetTrustAnchors() = apply { given(userConfigRepository) - .function(userConfigRepository::setShouldFetchE2EITrustAnchors) + .suspendFunction(userConfigRepository::setShouldFetchE2EITrustAnchors) .whenInvokedWith(any()) .thenReturn(Unit) } From 03e0c62989003346bcd42910e3b64b15058a9b9a Mon Sep 17 00:00:00 2001 From: Mohamad Jaara Date: Wed, 25 Sep 2024 11:58:54 +0200 Subject: [PATCH 6/6] tests --- .../persistence/config/UserConfigDAOTest.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/config/UserConfigDAOTest.kt b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/config/UserConfigDAOTest.kt index 8a95cc96f37..a1902160ce8 100644 --- a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/config/UserConfigDAOTest.kt +++ b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/config/UserConfigDAOTest.kt @@ -123,4 +123,21 @@ class UserConfigDAOTest : BaseDatabaseTest() { assertEquals(thirdExpectedValue, thirdValue) } } + + @Test + fun givenNoValueStoredForShouldFetchE2EITrustAnchorHasRun_whenCalled_thenReturnTrue() = runTest { + assertTrue(userConfigDAO.getShouldFetchE2EITrustAnchorHasRun()) + } + + @Test + fun givenShouldFetchE2EITrustAnchorHasRunIsSetToFalse_whenCalled_thenReturnFalse() = runTest { + userConfigDAO.setShouldFetchE2EITrustAnchors(false) + assertFalse(userConfigDAO.getShouldFetchE2EITrustAnchorHasRun()) + } + + @Test + fun givenShouldFetchE2EITrustAnchorHasRunIsSetToTrue_whenCalled_thenReturnTrue() = runTest { + userConfigDAO.setShouldFetchE2EITrustAnchors(true) + assertTrue(userConfigDAO.getShouldFetchE2EITrustAnchorHasRun()) + } }