From d50e3255a08926a9b0f62a46a55caf3dc348ee2a Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Thu, 2 May 2024 12:27:28 +0200 Subject: [PATCH 01/26] feat: set the correct external sender key when creating MLS conversation --- .../MLSClientImpl.kt | 8 ++- .../com/wire/kalium/cryptography/MLSClient.kt | 7 +- .../conversation/MLSConversationRepository.kt | 36 +++++++---- .../data/mlspublickeys/MLSPublicKeysMapper.kt | 64 +++++++++++++++---- .../mlspublickeys/MLSPublicKeysRepository.kt | 21 +++--- 5 files changed, 99 insertions(+), 37 deletions(-) diff --git a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt index 0586fa3a60f..4e47f94806e 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt @@ -47,6 +47,10 @@ class MLSClientImpl( private val keyRotationDuration: Duration = 30.toDuration(DurationUnit.DAYS) private val defaultGroupConfiguration = CustomConfiguration(keyRotationDuration.toJavaDuration(), MlsWirePolicy.PLAINTEXT) + override fun getDefaultCipherSuite(): UShort { + return defaultCipherSuite + } + override suspend fun close() { coreCrypto.close() } @@ -104,11 +108,11 @@ class MLSClientImpl( override suspend fun createConversation( groupId: MLSGroupId, - externalSenders: List + externalSenders: ByteArray ) { val conf = ConversationConfiguration( defaultCipherSuite, - externalSenders.map { it.value }, + listOf(externalSenders), defaultGroupConfiguration ) diff --git a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/MLSClient.kt b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/MLSClient.kt index 6698ad01e03..7133f49127c 100644 --- a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/MLSClient.kt +++ b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/MLSClient.kt @@ -153,6 +153,11 @@ data class CrlRegistration( @Suppress("TooManyFunctions") interface MLSClient { + /** + * Get the default ciphersuite for the client. + * the Default ciphersuite is set when creating the mls client. + */ + fun getDefaultCipherSuite(): UShort /** * Free up any resources and shutdown the client. @@ -253,7 +258,7 @@ interface MLSClient { */ suspend fun createConversation( groupId: MLSGroupId, - externalSenders: List = emptyList() + externalSenders: ByteArray ) /** diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt index bf29065fa2f..6089c9a96da 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt @@ -23,7 +23,6 @@ import com.wire.kalium.cryptography.CommitBundle import com.wire.kalium.cryptography.CryptoCertificateStatus import com.wire.kalium.cryptography.CryptoQualifiedClientId import com.wire.kalium.cryptography.E2EIClient -import com.wire.kalium.cryptography.Ed22519Key import com.wire.kalium.cryptography.MLSClient import com.wire.kalium.cryptography.WireIdentity import com.wire.kalium.logger.obfuscateId @@ -48,6 +47,7 @@ import com.wire.kalium.logic.data.id.toDao import com.wire.kalium.logic.data.id.toModel import com.wire.kalium.logic.data.keypackage.KeyPackageLimitsProvider import com.wire.kalium.logic.data.keypackage.KeyPackageRepository +import com.wire.kalium.logic.data.mls.CipherSuite import com.wire.kalium.logic.data.mlspublickeys.MLSPublicKeysMapper import com.wire.kalium.logic.data.mlspublickeys.MLSPublicKeysRepository import com.wire.kalium.logic.data.user.UserId @@ -572,14 +572,28 @@ internal class MLSConversationDataSource( allowSkippingUsersWithoutKeyPackages: Boolean, ): Either = withContext(serialDispatcher) { mlsPublicKeysRepository.getKeys().flatMap { publicKeys -> - val keys = publicKeys.map { mlsPublicKeysMapper.toCrypto(it) } - establishMLSGroup( - groupID = groupID, - members = members, - keys = keys, - allowPartialMemberList = allowSkippingUsersWithoutKeyPackages - ) + mlsClientProvider.getMLSClient().flatMap { + val keySignature = CipherSuite.fromTag(it.getDefaultCipherSuite()).let { + mlsPublicKeysMapper.fromCipherSuite(it) + } + val key = publicKeys.removal?.let { removalKeys -> + removalKeys[keySignature.value] + } + + if (key == null) { + return@flatMap MLSFailure + .Generic(IllegalArgumentException("No key found for $keySignature, isNullOrEmpty= ${publicKeys.removal.isNullOrEmpty()}")) + .left() + } + establishMLSGroup( + groupID = groupID, + members = members, + externalSenders = key.decodeBase64Bytes(), + allowPartialMemberList = allowSkippingUsersWithoutKeyPackages + ) + } } + } override suspend fun establishMLSSubConversationGroup( @@ -592,7 +606,7 @@ internal class MLSConversationDataSource( establishMLSGroup( groupID = groupID, members = emptyList(), - keys = listOf(mlsPublicKeysMapper.toCrypto(externalSenderKey)), + externalSenders = externalSenderKey.value, allowPartialMemberList = false ).map { Unit } } ?: Either.Left(StorageFailure.DataNotFound) @@ -602,14 +616,14 @@ internal class MLSConversationDataSource( private suspend fun establishMLSGroup( groupID: GroupID, members: List, - keys: List, + externalSenders: ByteArray, allowPartialMemberList: Boolean = false, ): Either = withContext(serialDispatcher) { mlsClientProvider.getMLSClient().flatMap { mlsClient -> wrapMLSRequest { mlsClient.createConversation( idMapper.toCryptoModel(groupID), - keys + externalSenders ) }.flatMapLeft { if (it is MLSFailure.ConversationAlreadyExists) { diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt index 1da7edbae7c..39c116adf1c 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt @@ -19,25 +19,15 @@ package com.wire.kalium.logic.data.mlspublickeys import com.wire.kalium.cryptography.ExternalSenderKey -import com.wire.kalium.network.api.base.authenticated.serverpublickey.MLSPublicKeysDTO -import io.ktor.util.decodeBase64Bytes +import com.wire.kalium.logic.data.mls.CipherSuite interface MLSPublicKeysMapper { - fun fromDTO(publicKeys: MLSPublicKeysDTO): List fun toCrypto(publicKey: MLSPublicKey): com.wire.kalium.cryptography.Ed22519Key fun toCrypto(externalSenderKey: ExternalSenderKey): com.wire.kalium.cryptography.Ed22519Key + fun fromCipherSuite(cipherSuite: CipherSuite): MLSPublicKeyType } class MLSPublicKeysMapperImpl : MLSPublicKeysMapper { - override fun fromDTO(publicKeys: MLSPublicKeysDTO) = with(publicKeys) { - removal?.entries?.mapNotNull { - when (it.key) { - ED25519 -> MLSPublicKey(Ed25519Key(it.value.decodeBase64Bytes()), KeyType.REMOVAL) - else -> null - } - } ?: emptyList() - } - override fun toCrypto(publicKey: MLSPublicKey) = with(publicKey) { com.wire.kalium.cryptography.Ed22519Key(key.value) } @@ -46,8 +36,54 @@ class MLSPublicKeysMapperImpl : MLSPublicKeysMapper { com.wire.kalium.cryptography.Ed22519Key(this.value) } - companion object { - const val ED25519 = "ed25519" + override fun fromCipherSuite(cipherSuite: CipherSuite): MLSPublicKeyType { + return when (cipherSuite) { + CipherSuite.MLS_128_DHKEMP256_AES128GCM_SHA256_P256 -> MLSPublicKeyType.P256 + CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519 -> MLSPublicKeyType.ED25519 + CipherSuite.MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 -> MLSPublicKeyType.ED25519 + CipherSuite.MLS_128_X25519KYBER768DRAFT00_AES128GCM_SHA256_ED25519 -> MLSPublicKeyType.ED25519 + CipherSuite.MLS_256_DHKEMP384_AES256GCM_SHA384_P384 -> MLSPublicKeyType.P384 + CipherSuite.MLS_256_DHKEMP521_AES256GCM_SHA512_P521 -> MLSPublicKeyType.P521 + CipherSuite.MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448 -> MLSPublicKeyType.ED448 + CipherSuite.MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 -> MLSPublicKeyType.ED448 + is CipherSuite.UNKNOWN -> MLSPublicKeyType.Unknown(null) + } + } +} + +sealed class MLSPublicKeyType { + abstract val value: String? + + data object P256 : MLSPublicKeyType() { + override val value: String = "p256" + } + + data object P384 : MLSPublicKeyType() { + override val value: String = "p384" } + data object P521 : MLSPublicKeyType() { + override val value: String = "p521" + } + + data object ED448 : MLSPublicKeyType() { + override val value: String = "ed448" + } + + data object ED25519 : MLSPublicKeyType() { + override val value: String = "ed25519" + } + + data class Unknown(override val value: String?) : MLSPublicKeyType() + + companion object { + fun from(value: String) = when (value) { + P256.value -> P256 + P384.value -> P384 + P521.value -> P521 + ED448.value -> ED448 + ED25519.value -> ED25519 + else -> Unknown(value) + } + } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt index 82c1ef7bf2a..83ee62ea3a3 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt @@ -24,29 +24,32 @@ import com.wire.kalium.logic.functional.map import com.wire.kalium.logic.wrapApiRequest import com.wire.kalium.network.api.base.authenticated.serverpublickey.MLSPublicKeyApi + +data class MLSPublicKeys( + val removal: Map? +) + + interface MLSPublicKeysRepository { - suspend fun fetchKeys(): Either> - suspend fun getKeys(): Either> + suspend fun fetchKeys(): Either + suspend fun getKeys(): Either } class MLSPublicKeysRepositoryImpl( private val mlsPublicKeyApi: MLSPublicKeyApi, - private val mapper: MLSPublicKeysMapper = MLSPublicKeysMapperImpl() ) : MLSPublicKeysRepository { - var publicKeys: List? = null + // TODO: make it thread safe + var publicKeys: MLSPublicKeys? = null override suspend fun fetchKeys() = wrapApiRequest { mlsPublicKeyApi.getMLSPublicKeys() }.map { - val keys = mapper.fromDTO(it) - publicKeys = keys - keys + MLSPublicKeys(removal = it.removal) } - override suspend fun getKeys(): Either> { + override suspend fun getKeys(): Either { return publicKeys?.let { Either.Right(it) } ?: fetchKeys() } - } From dc30b824700bd0aff10a0431313e8a7372b23adc Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Thu, 2 May 2024 13:50:01 +0200 Subject: [PATCH 02/26] cleanup --- .../com/wire/kalium/cryptography/MLSClient.kt | 5 -- .../conversation/MLSConversationRepository.kt | 21 ++---- .../logic/data/mlspublickeys/MLSPublicKey.kt | 33 --------- .../data/mlspublickeys/MLSPublicKeysMapper.kt | 10 --- .../mlspublickeys/MLSPublicKeysRepository.kt | 21 +++++- .../MLSConversationRepositoryTest.kt | 73 +++++++++++-------- 6 files changed, 67 insertions(+), 96 deletions(-) delete mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKey.kt diff --git a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/MLSClient.kt b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/MLSClient.kt index 7133f49127c..818946514f1 100644 --- a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/MLSClient.kt +++ b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/MLSClient.kt @@ -127,11 +127,6 @@ data class DecryptedMessageBundle( } } -@JvmInline -value class Ed22519Key( - val value: ByteArray -) - @JvmInline value class ExternalSenderKey( val value: ByteArray diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt index 6089c9a96da..4606316aa94 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt @@ -571,29 +571,18 @@ internal class MLSConversationDataSource( members: List, allowSkippingUsersWithoutKeyPackages: Boolean, ): Either = withContext(serialDispatcher) { - mlsPublicKeysRepository.getKeys().flatMap { publicKeys -> - mlsClientProvider.getMLSClient().flatMap { - val keySignature = CipherSuite.fromTag(it.getDefaultCipherSuite()).let { - mlsPublicKeysMapper.fromCipherSuite(it) - } - val key = publicKeys.removal?.let { removalKeys -> - removalKeys[keySignature.value] - } - - if (key == null) { - return@flatMap MLSFailure - .Generic(IllegalArgumentException("No key found for $keySignature, isNullOrEmpty= ${publicKeys.removal.isNullOrEmpty()}")) - .left() - } + mlsClientProvider.getMLSClient().flatMap { + mlsPublicKeysRepository.keyForCipherSuite( + CipherSuite.fromTag(it.getDefaultCipherSuite()) + ).flatMap { key -> establishMLSGroup( groupID = groupID, members = members, - externalSenders = key.decodeBase64Bytes(), + externalSenders = key, allowPartialMemberList = allowSkippingUsersWithoutKeyPackages ) } } - } override suspend fun establishMLSSubConversationGroup( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKey.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKey.kt deleted file mode 100644 index e66f72e2934..00000000000 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKey.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Wire - * Copyright (C) 2024 Wire Swiss GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. - */ - -package com.wire.kalium.logic.data.mlspublickeys - -import kotlin.jvm.JvmInline - -@JvmInline -value class Ed25519Key( - val value: ByteArray -) - -data class MLSPublicKey( - val key: Ed25519Key, - val keyType: KeyType -) - -enum class KeyType { REMOVAL } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt index 39c116adf1c..063b5bacc34 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt @@ -18,23 +18,13 @@ package com.wire.kalium.logic.data.mlspublickeys -import com.wire.kalium.cryptography.ExternalSenderKey import com.wire.kalium.logic.data.mls.CipherSuite interface MLSPublicKeysMapper { - fun toCrypto(publicKey: MLSPublicKey): com.wire.kalium.cryptography.Ed22519Key - fun toCrypto(externalSenderKey: ExternalSenderKey): com.wire.kalium.cryptography.Ed22519Key fun fromCipherSuite(cipherSuite: CipherSuite): MLSPublicKeyType } class MLSPublicKeysMapperImpl : MLSPublicKeysMapper { - override fun toCrypto(publicKey: MLSPublicKey) = with(publicKey) { - com.wire.kalium.cryptography.Ed22519Key(key.value) - } - - override fun toCrypto(externalSenderKey: ExternalSenderKey) = with(externalSenderKey) { - com.wire.kalium.cryptography.Ed22519Key(this.value) - } override fun fromCipherSuite(cipherSuite: CipherSuite): MLSPublicKeyType { return when (cipherSuite) { diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt index 83ee62ea3a3..c4bbc877683 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt @@ -19,24 +19,30 @@ package com.wire.kalium.logic.data.mlspublickeys import com.wire.kalium.logic.CoreFailure +import com.wire.kalium.logic.MLSFailure +import com.wire.kalium.logic.data.mls.CipherSuite +import com.wire.kalium.logic.di.MapperProvider import com.wire.kalium.logic.functional.Either +import com.wire.kalium.logic.functional.flatMap import com.wire.kalium.logic.functional.map +import com.wire.kalium.logic.functional.right import com.wire.kalium.logic.wrapApiRequest import com.wire.kalium.network.api.base.authenticated.serverpublickey.MLSPublicKeyApi - +import io.ktor.util.decodeBase64Bytes data class MLSPublicKeys( val removal: Map? ) - interface MLSPublicKeysRepository { suspend fun fetchKeys(): Either suspend fun getKeys(): Either + suspend fun keyForCipherSuite(cipherSuite: CipherSuite): Either } class MLSPublicKeysRepositoryImpl( private val mlsPublicKeyApi: MLSPublicKeyApi, + private val mlsPublicKeysMapper: MLSPublicKeysMapper = MapperProvider.mlsPublicKeyMapper() ) : MLSPublicKeysRepository { // TODO: make it thread safe @@ -52,4 +58,15 @@ class MLSPublicKeysRepositoryImpl( override suspend fun getKeys(): Either { return publicKeys?.let { Either.Right(it) } ?: fetchKeys() } + + override suspend fun keyForCipherSuite(cipherSuite: CipherSuite): Either = + getKeys().flatMap { serverPublicKeys -> + val keySignature = mlsPublicKeysMapper.fromCipherSuite(cipherSuite) + + val key = serverPublicKeys.removal?.let { removalKeys -> + removalKeys[keySignature.value] + } ?: return Either.Left(MLSFailure.Generic(IllegalStateException("No key found for cipher suite $cipherSuite"))) + + key.decodeBase64Bytes().right() + } } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt index bfbfe2b9451..8351048870d 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt @@ -51,12 +51,10 @@ import com.wire.kalium.logic.data.id.QualifiedClientID import com.wire.kalium.logic.data.id.toCrypto import com.wire.kalium.logic.data.keypackage.KeyPackageLimitsProvider import com.wire.kalium.logic.data.keypackage.KeyPackageRepository -import com.wire.kalium.logic.data.mlspublickeys.Ed25519Key -import com.wire.kalium.logic.data.mlspublickeys.KeyType -import com.wire.kalium.logic.data.mlspublickeys.MLSPublicKey +import com.wire.kalium.logic.data.mls.CipherSuite +import com.wire.kalium.logic.data.mlspublickeys.MLSPublicKeys import com.wire.kalium.logic.data.mlspublickeys.MLSPublicKeysRepository import com.wire.kalium.logic.data.user.UserId -import com.wire.kalium.logic.di.MapperProvider import com.wire.kalium.logic.feature.e2ei.usecase.CheckRevocationListUseCase import com.wire.kalium.logic.framework.TestClient import com.wire.kalium.logic.framework.TestConversation @@ -165,10 +163,11 @@ class MLSConversationRepositoryTest { @Test fun givenSuccessfulResponses_whenCallingEstablishMLSGroup_thenGroupIsCreatedAndCommitBundleIsSentAndAccepted() = runTest { val (arrangement, mlsConversationRepository) = Arrangement() + .withGetDefaultCipherSuite(CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519) .withCommitPendingProposalsReturningNothing() .withClaimKeyPackagesSuccessful() .withGetMLSClientSuccessful() - .withGetPublicKeysSuccessful() + .withKeyForCipherSuite() .withAddMLSMemberSuccessful() .withSendCommitBundleSuccessful() .arrange() @@ -177,8 +176,8 @@ class MLSConversationRepositoryTest { result.shouldSucceed() verify(arrangement.mlsClient) - .function(arrangement.mlsClient::createConversation) - .with(eq(Arrangement.RAW_GROUP_ID), eq(listOf(Arrangement.CRYPTO_MLS_PUBLIC_KEY))) + .suspendFunction(arrangement.mlsClient::createConversation) + .with(eq(Arrangement.RAW_GROUP_ID), eq(Arrangement.CRYPTO_MLS_PUBLIC_KEY)) .wasInvoked(once) verify(arrangement.mlsClient) @@ -202,10 +201,11 @@ class MLSConversationRepositoryTest { val userMissingKeyPackage = TestUser.USER_ID.copy(value = "missingKP") val usersMissingKeyPackages = setOf(userMissingKeyPackage) val (arrangement, mlsConversationRepository) = Arrangement() + .withGetDefaultCipherSuite(CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519) .withCommitPendingProposalsReturningNothing() .withClaimKeyPackagesSuccessful(usersWithoutKeyPackages = usersMissingKeyPackages) .withGetMLSClientSuccessful() - .withGetPublicKeysSuccessful() + .withKeyForCipherSuite() .withAddMLSMemberSuccessful() .withSendCommitBundleSuccessful() .arrange() @@ -220,8 +220,8 @@ class MLSConversationRepositoryTest { } verify(arrangement.mlsClient) - .function(arrangement.mlsClient::createConversation) - .with(eq(Arrangement.RAW_GROUP_ID), eq(listOf(Arrangement.CRYPTO_MLS_PUBLIC_KEY))) + .suspendFunction(arrangement.mlsClient::createConversation) + .with(eq(Arrangement.RAW_GROUP_ID), eq(Arrangement.CRYPTO_MLS_PUBLIC_KEY)) .wasInvoked(once) verify(arrangement.mlsClient) @@ -253,10 +253,11 @@ class MLSConversationRepositoryTest { val usersWithKeyPackages = setOf(userWithKeyPackage) val keyPackageSuccess = KEY_PACKAGE.copy(userId = userWithKeyPackage.value, domain = userWithKeyPackage.domain) val (arrangement, mlsConversationRepository) = Arrangement() + .withGetDefaultCipherSuite(CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519) .withCommitPendingProposalsReturningNothing() .withClaimKeyPackagesSuccessful(keyPackages = listOf(keyPackageSuccess), usersWithoutKeyPackages = usersMissingKeyPackages) .withGetMLSClientSuccessful() - .withGetPublicKeysSuccessful() + .withKeyForCipherSuite() .withAddMLSMemberSuccessful() .withSendCommitBundleSuccessful() .arrange() @@ -273,7 +274,7 @@ class MLSConversationRepositoryTest { verify(arrangement.mlsClient) .function(arrangement.mlsClient::createConversation) - .with(eq(Arrangement.RAW_GROUP_ID), eq(listOf(Arrangement.CRYPTO_MLS_PUBLIC_KEY))) + .with(eq(Arrangement.RAW_GROUP_ID), eq(Arrangement.CRYPTO_MLS_PUBLIC_KEY)) .wasInvoked(once) verify(arrangement.mlsClient) @@ -303,7 +304,7 @@ class MLSConversationRepositoryTest { .withCommitPendingProposalsReturningNothing() .withClaimKeyPackagesSuccessful() .withGetMLSClientSuccessful() - .withGetPublicKeysSuccessful() + .withKeyForCipherSuite() .withAddMLSMemberSuccessful() .withSendCommitBundleSuccessful() .arrange() @@ -316,7 +317,7 @@ class MLSConversationRepositoryTest { .withCommitPendingProposalsReturningNothing() .withClaimKeyPackagesSuccessful() .withGetMLSClientSuccessful() - .withGetPublicKeysSuccessful() + .withKeyForCipherSuite() .withAddMLSMemberSuccessful(COMMIT_BUNDLE.copy(crlNewDistributionPoints = listOf("url"))) .withCheckRevocationListResult() .withSendCommitBundleSuccessful() @@ -338,10 +339,11 @@ class MLSConversationRepositoryTest { @Test fun givenMlsClientMismatchError_whenCallingEstablishMLSGroup_thenClearCommitAndRetry() = runTest { val (arrangement, mlsConversationRepository) = Arrangement() + .withGetDefaultCipherSuite(CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519) .withCommitPendingProposalsReturningNothing() .withClaimKeyPackagesSuccessful() .withGetMLSClientSuccessful() - .withGetPublicKeysSuccessful() + .withKeyForCipherSuite() .withAddMLSMemberSuccessful() .withSendCommitBundleFailing(Arrangement.MLS_CLIENT_MISMATCH_ERROR, times = 1) .withWaitUntilLiveSuccessful() @@ -369,10 +371,11 @@ class MLSConversationRepositoryTest { @Test fun givenMlsStaleMessageError_whenCallingEstablishMLSGroup_thenAbortCommitAndWipeData() = runTest { val (arrangement, mlsConversationRepository) = Arrangement() + .withGetDefaultCipherSuite(CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519) .withCommitPendingProposalsReturningNothing() .withClaimKeyPackagesSuccessful() .withGetMLSClientSuccessful() - .withGetPublicKeysSuccessful() + .withKeyForCipherSuite() .withAddMLSMemberSuccessful() .withSendCommitBundleFailing(Arrangement.MLS_STALE_MESSAGE_ERROR) .arrange() @@ -399,10 +402,11 @@ class MLSConversationRepositoryTest { @Test fun givenSuccessfulResponses_whenCallingEstablishMLSGroup_thenKeyPackagesAreClaimedForMembers() = runTest { val (arrangement, mlsConversationRepository) = Arrangement() + .withGetDefaultCipherSuite(CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519) .withCommitPendingProposalsReturningNothing() .withClaimKeyPackagesSuccessful() .withGetMLSClientSuccessful() - .withGetPublicKeysSuccessful() + .withKeyForCipherSuite() .withAddMLSMemberSuccessful() .withSendCommitBundleSuccessful() .arrange() @@ -419,10 +423,11 @@ class MLSConversationRepositoryTest { @Test fun givenNoOtherClients_whenCallingEstablishMLSGroup_thenCommitIsCreatedByUpdatingKeyMaterial() = runTest { val (arrangement, mlsConversationRepository) = Arrangement() + .withGetDefaultCipherSuite(CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519) .withCommitPendingProposalsReturningNothing() .withClaimKeyPackagesSuccessful(keyPackages = emptyList()) .withGetMLSClientSuccessful() - .withGetPublicKeysSuccessful() + .withKeyForCipherSuite() .withUpdateKeyingMaterialSuccessful() .withSendCommitBundleSuccessful() .arrange() @@ -1550,7 +1555,7 @@ class MLSConversationRepositoryTest { .withGetMLSClientSuccessful() .withGetMLSGroupIdByConversationIdReturns(Arrangement.GROUP_ID.value) .withGetExternalSenderKeySuccessful() - .withGetPublicKeysSuccessful() + .withKeyForCipherSuite() .withUpdateKeyingMaterialSuccessful() .withSendCommitBundleSuccessful() .arrange() @@ -1559,8 +1564,8 @@ class MLSConversationRepositoryTest { result.shouldSucceed() verify(arrangement.mlsClient) - .function(arrangement.mlsClient::createConversation) - .with(eq(Arrangement.RAW_GROUP_ID), eq(listOf(Arrangement.CRYPTO_MLS_EXTERNAL_KEY))) + .suspendFunction(arrangement.mlsClient::createConversation) + .with(eq(Arrangement.RAW_GROUP_ID), eq(Arrangement.EXTERNAL_SENDER_KEY.value)) .wasInvoked(once) verify(arrangement.mlsMessageApi) @@ -1753,11 +1758,11 @@ class MLSConversationRepositoryTest { .thenReturn(result) } - fun withGetPublicKeysSuccessful() = apply { + fun withKeyForCipherSuite() = apply { given(mlsPublicKeysRepository) - .suspendFunction(mlsPublicKeysRepository::getKeys) - .whenInvoked() - .then { Either.Right(listOf(MLS_PUBLIC_KEY)) } + .suspendFunction(mlsPublicKeysRepository::keyForCipherSuite) + .whenInvokedWith(any()) + .then { Either.Right(CRYPTO_MLS_PUBLIC_KEY) } } fun withGetMLSClientSuccessful() = apply { @@ -1960,6 +1965,13 @@ class MLSConversationRepositoryTest { .thenReturn(identitiesMap) } + fun withGetDefaultCipherSuite(cipherSuite: CipherSuite) = apply { + given(mlsClient) + .function(mlsClient::getDefaultCipherSuite) + .whenInvoked() + .thenReturn(cipherSuite.tag.toUShort()) + } + companion object { val TEST_FAILURE = Either.Left(CoreFailure.Unknown(Throwable("an error"))) const val EPOCH = 5UL @@ -1970,11 +1982,13 @@ class MLSConversationRepositoryTest { val INVALID_REQUEST_ERROR = KaliumException.InvalidRequestError(ErrorResponse(405, "", "")) val MLS_STALE_MESSAGE_ERROR = KaliumException.InvalidRequestError(ErrorResponse(409, "", "mls-stale-message")) val MLS_CLIENT_MISMATCH_ERROR = KaliumException.InvalidRequestError(ErrorResponse(409, "", "mls-client-mismatch")) - val MLS_PUBLIC_KEY = MLSPublicKey( - Ed25519Key("gRNvFYReriXbzsGu7zXiPtS8kaTvhU1gUJEV9rdFHVw=".decodeBase64Bytes()), - KeyType.REMOVAL + val MLS_PUBLIC_KEY = MLSPublicKeys( + removal = mapOf( + "ed25519" to "gRNvFYReriXbzsGu7zXiPtS8kaTvhU1gUJEV9rdFHVw=" + ) ) - val CRYPTO_MLS_PUBLIC_KEY = MapperProvider.mlsPublicKeyMapper().toCrypto(MLS_PUBLIC_KEY) + + val CRYPTO_MLS_PUBLIC_KEY: ByteArray = MLS_PUBLIC_KEY.removal?.get("ed25519")!!.decodeBase64Bytes() val KEY_PACKAGE = KeyPackageDTO( "client1", "wire.com", @@ -1984,7 +1998,6 @@ class MLSConversationRepositoryTest { ) val WELCOME = "welcome".encodeToByteArray() val EXTERNAL_SENDER_KEY = ExternalSenderKey("externalSenderKey".encodeToByteArray()) - val CRYPTO_MLS_EXTERNAL_KEY = MapperProvider.mlsPublicKeyMapper().toCrypto(EXTERNAL_SENDER_KEY) val COMMIT = "commit".encodeToByteArray() val PUBLIC_GROUP_STATE = "public_group_state".encodeToByteArray() val PUBLIC_GROUP_STATE_BUNDLE = GroupInfoBundle( From 519b00e9eb463fc3567d2b2fd262c5d10eee5a69 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Thu, 2 May 2024 13:54:11 +0200 Subject: [PATCH 03/26] fix ios and js target --- .../kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt | 7 +++++-- .../kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt b/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt index 248524ed8cc..10939a53fb7 100644 --- a/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt +++ b/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt @@ -44,6 +44,9 @@ class MLSClientImpl( private val keyRotationDuration: Duration = 30.toDuration(DurationUnit.DAYS) private val defaultGroupConfiguration = CustomConfiguration(keyRotationDuration, MlsWirePolicy.PLAINTEXT) + override fun getDefaultCipherSuite(): UShort { + return defaultCipherSuite + } @Suppress("EmptyFunctionBlock") override suspend fun close() { @@ -97,11 +100,11 @@ class MLSClientImpl( override suspend fun createConversation( groupId: MLSGroupId, - externalSenders: List + externalSenders: ByteArray ) { val conf = ConversationConfiguration( CiphersuiteName.MLS_128_DHKEMX25519_AES128GCM_SHA256_ED25519, - externalSenders.map { toUByteList(it.value) }, + listOf(toUByteList(externalSenders)), defaultGroupConfiguration ) diff --git a/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt b/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt index f2267bbe925..90e782d9c2a 100644 --- a/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt +++ b/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt @@ -22,6 +22,10 @@ import kotlin.time.Duration @Suppress("TooManyFunctions") class MLSClientImpl : MLSClient { + override fun getDefaultCipherSuite(): UShort { + TODO("Not yet implemented") + } + override suspend fun close() { TODO("Not yet implemented") } @@ -66,7 +70,7 @@ class MLSClientImpl : MLSClient { TODO("Not yet implemented") } - override suspend fun createConversation(groupId: MLSGroupId, externalSenders: List) { + override suspend fun createConversation(groupId: MLSGroupId, externalSenders: ByteArray) { TODO("Not yet implemented") } From b823681c4c0568a6727f9226f9e930b141475257 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Thu, 2 May 2024 14:06:00 +0200 Subject: [PATCH 04/26] mls client test --- .../wire/kalium/cryptography/MLSClientTest.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/MLSClientTest.kt b/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/MLSClientTest.kt index 1c7dbddf330..1099bd4038b 100644 --- a/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/MLSClientTest.kt +++ b/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/MLSClientTest.kt @@ -36,6 +36,12 @@ class MLSClientTest : BaseMLSClientTest() { return createMLSClient(user.qualifiedClientId, ALLOWED_CIPHER_SUITES, DEFAULT_CIPHER_SUITES) } + @Test + fun givemMlsClient_whenCallingGetDefaultCipherSuite_ReturnExpectedValue() = runTest { + val mlsClient = createClient(ALICE1) + assertEquals(DEFAULT_CIPHER_SUITES, mlsClient.getDefaultCipherSuite()) + } + @Test fun givenClient_whenCallingGetPublicKey_ReturnNonEmptyResult() = runTest { val mlsClient = createClient(ALICE1) @@ -51,7 +57,7 @@ class MLSClientTest : BaseMLSClientTest() { @Test fun givenNewConversation_whenCallingConversationEpoch_ReturnZeroEpoch() = runTest { val mlsClient = createClient(ALICE1) - mlsClient.createConversation(MLS_CONVERSATION_ID) + mlsClient.createConversation(MLS_CONVERSATION_ID, externalSenderKey) assertEquals(0UL, mlsClient.conversationEpoch(MLS_CONVERSATION_ID)) } @@ -64,7 +70,7 @@ class MLSClientTest : BaseMLSClientTest() { val aliceKeyPackage = aliceClient.generateKeyPackages(1).first() val clientKeyPackageList = listOf(aliceKeyPackage) - bobClient.createConversation(MLS_CONVERSATION_ID) + bobClient.createConversation(MLS_CONVERSATION_ID, externalSenderKey) val welcome = bobClient.addMember(MLS_CONVERSATION_ID, clientKeyPackageList)?.welcome!! bobClient.commitAccepted(MLS_CONVERSATION_ID) val welcomeBundle = aliceClient.processWelcomeMessage(welcome) @@ -82,7 +88,7 @@ class MLSClientTest : BaseMLSClientTest() { val aliceKeyPackage = aliceClient.generateKeyPackages(1).first() val clientKeyPackageList = listOf(aliceKeyPackage) - bobClient.createConversation(MLS_CONVERSATION_ID) + bobClient.createConversation(MLS_CONVERSATION_ID, externalSenderKey) val welcome = bobClient.addMember(MLS_CONVERSATION_ID, clientKeyPackageList)!!.welcome!! val welcomeBundle = aliceClient.processWelcomeMessage(welcome) @@ -98,7 +104,7 @@ class MLSClientTest : BaseMLSClientTest() { val alice1KeyPackage = alice1Client.generateKeyPackages(1).first() val clientKeyPackageList = listOf(alice1KeyPackage) - bobClient.createConversation(MLS_CONVERSATION_ID) + bobClient.createConversation(MLS_CONVERSATION_ID, externalSenderKey) bobClient.addMember(MLS_CONVERSATION_ID, clientKeyPackageList) bobClient.commitAccepted(MLS_CONVERSATION_ID) val proposal = alice2Client.joinConversation(MLS_CONVERSATION_ID, 1UL) @@ -117,7 +123,7 @@ class MLSClientTest : BaseMLSClientTest() { val clientKeyPackageList = listOf(aliceClient.generateKeyPackages(1).first()) - bobClient.createConversation(MLS_CONVERSATION_ID) + bobClient.createConversation(MLS_CONVERSATION_ID, externalSenderKey) val welcome = bobClient.addMember(MLS_CONVERSATION_ID, clientKeyPackageList)?.welcome!! bobClient.commitAccepted(MLS_CONVERSATION_ID) val welcomeBundle = aliceClient.processWelcomeMessage(welcome) @@ -135,7 +141,7 @@ class MLSClientTest : BaseMLSClientTest() { val clientKeyPackageList = listOf(aliceClient.generateKeyPackages(1).first()) - bobClient.createConversation(MLS_CONVERSATION_ID) + bobClient.createConversation(MLS_CONVERSATION_ID, externalSenderKey) val welcome = bobClient.addMember(MLS_CONVERSATION_ID, clientKeyPackageList)?.welcome!! bobClient.commitAccepted((MLS_CONVERSATION_ID)) val welcomeBundle = aliceClient.processWelcomeMessage(welcome) @@ -149,7 +155,7 @@ class MLSClientTest : BaseMLSClientTest() { val bobClient = createClient(BOB1) val carolClient = createClient(CAROL1) - bobClient.createConversation(MLS_CONVERSATION_ID) + bobClient.createConversation(MLS_CONVERSATION_ID, externalSenderKey) val welcome = bobClient.addMember( MLS_CONVERSATION_ID, listOf(aliceClient.generateKeyPackages(1).first()) @@ -176,7 +182,7 @@ class MLSClientTest : BaseMLSClientTest() { aliceClient.generateKeyPackages(1).first(), carolClient.generateKeyPackages(1).first() ) - bobClient.createConversation(MLS_CONVERSATION_ID) + bobClient.createConversation(MLS_CONVERSATION_ID, externalSenderKey) val welcome = bobClient.addMember(MLS_CONVERSATION_ID, clientKeyPackageList)?.welcome!! bobClient.commitAccepted(MLS_CONVERSATION_ID) val welcomeBundle = aliceClient.processWelcomeMessage(welcome) @@ -188,6 +194,7 @@ class MLSClientTest : BaseMLSClientTest() { } companion object { + val externalSenderKey = ByteArray(32) val ALLOWED_CIPHER_SUITES = listOf(1.toUShort()) val DEFAULT_CIPHER_SUITES = 1.toUShort() const val MLS_CONVERSATION_ID = "JfflcPtUivbg+1U3Iyrzsh5D2ui/OGS5Rvf52ipH5KY=" From a5049f208d22d89a7b39331a75d2595bfcda35b1 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Thu, 2 May 2024 15:19:06 +0200 Subject: [PATCH 05/26] print generic MLS errors --- .../src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt index 9660afa8f0f..8dbabc4f59f 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt @@ -189,7 +189,7 @@ interface MLSFailure : CoreFailure { data object StaleProposal : MLSFailure data object StaleCommit : MLSFailure - class Generic(internal val exception: Exception) : MLSFailure { + data class Generic(internal val exception: Exception) : MLSFailure { val rootCause: Throwable get() = exception } } From de14bfa589f4681a77d5e6a2e7821138bc318adb Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Thu, 2 May 2024 21:30:04 +0200 Subject: [PATCH 06/26] fix: fetch mls feature config from remote --- .../CoreCryptoCentral.kt | 8 +++---- .../MLSClientImpl.kt | 1 + gradle/libs.versions.toml | 2 +- .../kalium/logic/CoreCryptoExceptionMapper.kt | 18 +++++++------- .../logic/data/client/MLSClientProvider.kt | 19 +++++++++++++-- .../conversation/MLSConversationRepository.kt | 10 ++++---- .../wire/kalium/logic/data/mls/CipherSuite.kt | 6 ++--- .../data/mlspublickeys/MLSPublicKeysMapper.kt | 24 +++++++++---------- .../mlspublickeys/MLSPublicKeysRepository.kt | 11 +++++++-- .../kalium/logic/feature/UserSessionScope.kt | 3 ++- .../client/RegisterMLSClientUseCase.kt | 15 ++++++++++-- .../authenticated/client/ClientRequest.kt | 12 +++++----- .../api/v0/authenticated/ClientApiV0.kt | 9 ++++++- .../kalium/persistence/dao/MigrationDAO.kt | 1 - 14 files changed, 91 insertions(+), 48 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 5eefcb16f63..b3e831bf892 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt @@ -34,7 +34,7 @@ actual suspend fun coreCryptoCentral( ): CoreCryptoCentral { val path = "$rootDir/${CoreCryptoCentralImpl.KEYSTORE_NAME}" File(rootDir).mkdirs() - val coreCrypto = coreCryptoDeferredInit(path, databaseKey, allowedCipherSuites, null) + val coreCrypto = coreCryptoDeferredInit(path, databaseKey) coreCrypto.setCallbacks(Callbacks()) return CoreCryptoCentralImpl( cc = coreCrypto, @@ -46,12 +46,12 @@ actual suspend fun coreCryptoCentral( private class Callbacks : CoreCryptoCallbacks { - override fun authorize(conversationId: ByteArray, clientId: ClientId): Boolean { + override suspend fun authorize(conversationId: ByteArray, clientId: ClientId): Boolean { // We always return true because our BE is currently enforcing that this constraint is always true return true } - override fun clientIsExistingGroupUser( + override suspend fun clientIsExistingGroupUser( conversationId: ConversationId, clientId: ClientId, existingClients: List, @@ -61,7 +61,7 @@ private class Callbacks : CoreCryptoCallbacks { return true } - override fun userAuthorize( + override suspend fun userAuthorize( conversationId: ConversationId, externalClientId: ClientId, existingClients: List diff --git a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt index 4e47f94806e..96e7528634b 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt @@ -110,6 +110,7 @@ class MLSClientImpl( groupId: MLSGroupId, externalSenders: ByteArray ) { + kaliumLogger.d("createConversation: $defaultCipherSuite") val conf = ConversationConfiguration( defaultCipherSuite, listOf(externalSenders), diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 56277f7296b..9aa75fe1766 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -37,7 +37,7 @@ pbandk = "0.14.2" turbine = "1.0.0" avs = "9.6.13" jna = "5.14.0" -core-crypto = "1.0.0-rc.56-hotfix.1" +core-crypto = "1.0.0-rc.59" core-crypto-multiplatform = "0.6.0-rc.3-multiplatform-pre1" completeKotlin = "1.1.0" desugar-jdk = "2.0.4" diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt index c67d4c181f0..78f27826907 100644 --- a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt @@ -23,15 +23,15 @@ import uniffi.core_crypto.CryptoError actual fun mapMLSException(exception: Exception): MLSFailure = if (exception is CoreCryptoException.CryptoException) { when (exception.error) { - is CryptoError.WrongEpoch -> MLSFailure.WrongEpoch - is CryptoError.DuplicateMessage -> MLSFailure.DuplicateMessage - is CryptoError.BufferedFutureMessage -> MLSFailure.BufferedFutureMessage - is CryptoError.SelfCommitIgnored -> MLSFailure.SelfCommitIgnored - is CryptoError.UnmergedPendingGroup -> MLSFailure.UnmergedPendingGroup - is CryptoError.StaleProposal -> MLSFailure.StaleProposal - is CryptoError.StaleCommit -> MLSFailure.StaleCommit - is CryptoError.ConversationAlreadyExists -> MLSFailure.ConversationAlreadyExists - is CryptoError.MessageEpochTooOld -> MLSFailure.MessageEpochTooOld + CryptoError.WRONG_EPOCH -> MLSFailure.WrongEpoch + CryptoError.DUPLICATE_MESSAGE -> MLSFailure.DuplicateMessage + CryptoError.BUFFERED_FUTURE_MESSAGE -> MLSFailure.BufferedFutureMessage + CryptoError.SELF_COMMIT_IGNORED -> MLSFailure.SelfCommitIgnored + CryptoError.UNMERGED_PENDING_GROUP -> MLSFailure.UnmergedPendingGroup + CryptoError.STALE_PROPOSAL -> MLSFailure.StaleProposal + CryptoError.STALE_COMMIT -> MLSFailure.StaleCommit + CryptoError.CONVERSATION_ALREADY_EXISTS -> MLSFailure.ConversationAlreadyExists + CryptoError.MESSAGE_EPOCH_TOO_OLD -> MLSFailure.MessageEpochTooOld else -> MLSFailure.Generic(exception) } } else { 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 d41ef34e27d..f82842dd743 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 @@ -30,9 +30,12 @@ import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.E2EIFailure import com.wire.kalium.logic.configuration.UserConfigRepository import com.wire.kalium.logic.data.conversation.ClientId +import com.wire.kalium.logic.data.featureConfig.FeatureConfigRepository import com.wire.kalium.logic.data.id.CurrentClientIdProvider +import com.wire.kalium.logic.data.mls.SupportedCipherSuite import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.functional.Either +import com.wire.kalium.logic.functional.flatMapLeft import com.wire.kalium.logic.functional.fold import com.wire.kalium.logic.functional.getOrElse import com.wire.kalium.logic.functional.left @@ -70,6 +73,7 @@ class MLSClientProviderImpl( private val currentClientIdProvider: CurrentClientIdProvider, private val passphraseStorage: PassphraseStorage, private val userConfigRepository: UserConfigRepository, + private val featureConfigRepository: FeatureConfigRepository, private val dispatchers: KaliumDispatcher = KaliumDispatcherImpl ) : MLSClientProvider { @@ -83,7 +87,11 @@ class MLSClientProviderImpl( override suspend fun getMLSClient(clientId: ClientId?): Either = mlsClientMutex.withLock { withContext(dispatchers.io) { - val currentClientId = clientId ?: currentClientIdProvider().fold({ return@withContext Either.Left(it) }, { it }) + val currentClientId = clientId ?: currentClientIdProvider().fold({ + kaliumLogger.d("$TAG: Failed to get current client id: $it") + return@withContext Either.Left(it) + }, + { it }) val cryptoUserId = CryptoUserID(value = userId.value, domain = userId.domain) return@withContext mlsClient?.let { Either.Right(it) @@ -133,7 +141,14 @@ class MLSClientProviderImpl( override suspend fun getCoreCrypto(clientId: ClientId?): Either = coreCryptoCentralMutex.withLock { withContext(dispatchers.io) { val (supportedCipherSuite, defaultCipherSuite) = userConfigRepository.getSupportedCipherSuite() - .getOrElse { return@withContext Either.Left(it) } + .flatMapLeft { + featureConfigRepository.getFeatureConfigs().map { + it.mlsModel.supportedCipherSuite!! + } + }.getOrElse { + kaliumLogger.e("$TAG: Failed to get supported cipher suite") + return@withContext Either.Left(CoreFailure.Unknown(IllegalStateException("Failed to get supported cipher suite"))) + } val currentClientId = clientId ?: currentClientIdProvider().fold({ return@withContext Either.Left(it) }, { it }) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt index 4606316aa94..9620ad5d041 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt @@ -333,10 +333,12 @@ internal class MLSConversationDataSource( } sendCommitBundleForExternalCommit(groupID, commitBundle) }.onSuccess { - conversationDAO.updateConversationGroupState( - ConversationEntity.GroupState.ESTABLISHED, - idMapper.toCryptoModel(groupID) - ) + wrapStorageRequest { + conversationDAO.updateConversationGroupState( + ConversationEntity.GroupState.ESTABLISHED, + idMapper.toCryptoModel(groupID) + ) + } } } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mls/CipherSuite.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mls/CipherSuite.kt index 530e0494020..c90f9e29b67 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mls/CipherSuite.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mls/CipherSuite.kt @@ -102,12 +102,12 @@ sealed class CipherSuite(open val tag: Int) { } fun CipherSuite.signatureAlgorithm(): MLSPublicKeyTypeDTO? = when (this) { - CipherSuite.MLS_128_DHKEMP256_AES128GCM_SHA256_P256 -> MLSPublicKeyTypeDTO.P256 + CipherSuite.MLS_128_DHKEMP256_AES128GCM_SHA256_P256 -> MLSPublicKeyTypeDTO.ECDSA_SECP256R1_SHA256 CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519 -> MLSPublicKeyTypeDTO.ED25519 CipherSuite.MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 -> MLSPublicKeyTypeDTO.ED25519 CipherSuite.MLS_128_X25519KYBER768DRAFT00_AES128GCM_SHA256_ED25519 -> MLSPublicKeyTypeDTO.ED25519 - CipherSuite.MLS_256_DHKEMP384_AES256GCM_SHA384_P384 -> MLSPublicKeyTypeDTO.P384 - CipherSuite.MLS_256_DHKEMP521_AES256GCM_SHA512_P521 -> MLSPublicKeyTypeDTO.P521 + CipherSuite.MLS_256_DHKEMP384_AES256GCM_SHA384_P384 -> MLSPublicKeyTypeDTO.ECDSA_SECP384R1_SHA384 + CipherSuite.MLS_256_DHKEMP521_AES256GCM_SHA512_P521 -> MLSPublicKeyTypeDTO.ECDSA_SECP521R1_SHA512 CipherSuite.MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448 -> MLSPublicKeyTypeDTO.ED448 CipherSuite.MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 -> MLSPublicKeyTypeDTO.ED448 is CipherSuite.UNKNOWN -> null diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt index 063b5bacc34..3687fb5be6e 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt @@ -28,12 +28,12 @@ class MLSPublicKeysMapperImpl : MLSPublicKeysMapper { override fun fromCipherSuite(cipherSuite: CipherSuite): MLSPublicKeyType { return when (cipherSuite) { - CipherSuite.MLS_128_DHKEMP256_AES128GCM_SHA256_P256 -> MLSPublicKeyType.P256 + CipherSuite.MLS_128_DHKEMP256_AES128GCM_SHA256_P256 -> MLSPublicKeyType.ECDSA_SECP256R1_SHA256 CipherSuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519 -> MLSPublicKeyType.ED25519 CipherSuite.MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 -> MLSPublicKeyType.ED25519 CipherSuite.MLS_128_X25519KYBER768DRAFT00_AES128GCM_SHA256_ED25519 -> MLSPublicKeyType.ED25519 - CipherSuite.MLS_256_DHKEMP384_AES256GCM_SHA384_P384 -> MLSPublicKeyType.P384 - CipherSuite.MLS_256_DHKEMP521_AES256GCM_SHA512_P521 -> MLSPublicKeyType.P521 + CipherSuite.MLS_256_DHKEMP384_AES256GCM_SHA384_P384 -> MLSPublicKeyType.ECDSA_SECP384R1_SHA384 + CipherSuite.MLS_256_DHKEMP521_AES256GCM_SHA512_P521 -> MLSPublicKeyType.ECDSA_SECP521R1_SHA512 CipherSuite.MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448 -> MLSPublicKeyType.ED448 CipherSuite.MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 -> MLSPublicKeyType.ED448 is CipherSuite.UNKNOWN -> MLSPublicKeyType.Unknown(null) @@ -44,16 +44,16 @@ class MLSPublicKeysMapperImpl : MLSPublicKeysMapper { sealed class MLSPublicKeyType { abstract val value: String? - data object P256 : MLSPublicKeyType() { - override val value: String = "p256" + data object ECDSA_SECP256R1_SHA256 : MLSPublicKeyType() { + override val value: String = "ecdsa_secp256r1_sha256" } - data object P384 : MLSPublicKeyType() { - override val value: String = "p384" + data object ECDSA_SECP384R1_SHA384 : MLSPublicKeyType() { + override val value: String = "ecdsa_secp384r1_sha384" } - data object P521 : MLSPublicKeyType() { - override val value: String = "p521" + data object ECDSA_SECP521R1_SHA512 : MLSPublicKeyType() { + override val value: String = "ecdsa_secp521r1_sha512" } data object ED448 : MLSPublicKeyType() { @@ -68,9 +68,9 @@ sealed class MLSPublicKeyType { companion object { fun from(value: String) = when (value) { - P256.value -> P256 - P384.value -> P384 - P521.value -> P521 + ECDSA_SECP256R1_SHA256.value -> ECDSA_SECP256R1_SHA256 + ECDSA_SECP384R1_SHA384.value -> ECDSA_SECP384R1_SHA384 + ECDSA_SECP521R1_SHA512.value -> ECDSA_SECP521R1_SHA512 ED448.value -> ED448 ED25519.value -> ED25519 else -> Unknown(value) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt index c4bbc877683..21ffc48638b 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt @@ -26,6 +26,7 @@ import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.flatMap import com.wire.kalium.logic.functional.map import com.wire.kalium.logic.functional.right +import com.wire.kalium.logic.kaliumLogger import com.wire.kalium.logic.wrapApiRequest import com.wire.kalium.network.api.base.authenticated.serverpublickey.MLSPublicKeyApi import io.ktor.util.decodeBase64Bytes @@ -59,14 +60,20 @@ class MLSPublicKeysRepositoryImpl( return publicKeys?.let { Either.Right(it) } ?: fetchKeys() } - override suspend fun keyForCipherSuite(cipherSuite: CipherSuite): Either = - getKeys().flatMap { serverPublicKeys -> + override suspend fun keyForCipherSuite(cipherSuite: CipherSuite): Either { + + return getKeys().flatMap { serverPublicKeys -> + kaliumLogger.d("serverPublicKeys: $serverPublicKeys") val keySignature = mlsPublicKeysMapper.fromCipherSuite(cipherSuite) + kaliumLogger.d("keySignature: $keySignature") val key = serverPublicKeys.removal?.let { removalKeys -> removalKeys[keySignature.value] } ?: return Either.Left(MLSFailure.Generic(IllegalStateException("No key found for cipher suite $cipherSuite"))) + kaliumLogger.d("key: $key") key.decodeBase64Bytes().right() } + } + } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index 448306225fc..e6792384aef 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -630,7 +630,8 @@ class UserSessionScope internal constructor( userId = userId, currentClientIdProvider = clientIdProvider, passphraseStorage = globalPreferences.passphraseStorage, - userConfigRepository = userConfigRepository + userConfigRepository = userConfigRepository, + featureConfigRepository = featureConfigRepository, ) } 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 27043e05357..f323c32c762 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 @@ -30,6 +30,7 @@ import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.flatMap import com.wire.kalium.logic.functional.onFailure import com.wire.kalium.logic.functional.right +import com.wire.kalium.logic.kaliumLogger import com.wire.kalium.logic.wrapMLSRequest sealed class RegisterMLSClientResult { @@ -53,23 +54,33 @@ internal class RegisterMLSClientUseCaseImpl( private val userConfigRepository: UserConfigRepository ) : RegisterMLSClientUseCase { - override suspend operator fun invoke(clientId: ClientId): Either = - userConfigRepository.getE2EISettings().flatMap { e2eiSettings -> + override suspend operator fun invoke(clientId: ClientId): Either { + kaliumLogger.d("Registering MLS client with client ID: $clientId") + return userConfigRepository.getE2EISettings().flatMap { e2eiSettings -> + kaliumLogger.d("Registering MLS client with E2EI settings") if (e2eiSettings.isRequired && !mlsClientProvider.isMLSClientInitialised()) { + kaliumLogger.d("E2EI settings are required but MLS client is not initialised") return RegisterMLSClientResult.E2EICertificateRequired.right() } else { mlsClientProvider.getMLSClient(clientId) } }.onFailure { + kaliumLogger.e("Failed to get MLS client: $it") mlsClientProvider.getMLSClient(clientId) }.flatMap { mlsClient -> + kaliumLogger.d("Getting public key from MLS client") wrapMLSRequest { mlsClient.getPublicKey() } }.flatMap { (publicKey, cipherSuite) -> + kaliumLogger.d("Registering MLS client with public key: $publicKey") clientRepository.registerMLSClient(clientId, publicKey, CipherSuite.fromTag(cipherSuite)) }.flatMap { + kaliumLogger.d("Uploading new key packages") keyPackageRepository.uploadNewKeyPackages(clientId, keyPackageLimitsProvider.refillAmount()) Either.Right(RegisterMLSClientResult.Success) + }.onFailure { + kaliumLogger.e("Failed to register MLS client: $it") } + } } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/client/ClientRequest.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/client/ClientRequest.kt index ce9219916e6..3929dce2e0d 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/client/ClientRequest.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/client/ClientRequest.kt @@ -118,12 +118,12 @@ data class UpdateClientCapabilitiesRequest( @Serializable enum class MLSPublicKeyTypeDTO { - @SerialName("p256") - P256, - @SerialName("p384") - P384, - @SerialName("p521") - P521, + @SerialName("ecdsa_secp256r1_sha256") + ECDSA_SECP256R1_SHA256, + @SerialName("ecdsa_secp384r1_sha384") + ECDSA_SECP384R1_SHA384, + @SerialName("ecdsa_secp521r1_sha512") + ECDSA_SECP521R1_SHA512, @SerialName("ed448") ED448, @SerialName("ed25519") diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt index 2ac46b3932a..c97a788e78a 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt @@ -31,8 +31,11 @@ import com.wire.kalium.network.api.base.authenticated.client.UpdateClientMlsPubl import com.wire.kalium.network.api.base.model.PushTokenBody import com.wire.kalium.network.api.base.model.QualifiedID import com.wire.kalium.network.api.base.model.UserId +import com.wire.kalium.network.kaliumLogger import com.wire.kalium.network.utils.NetworkResponse import com.wire.kalium.network.utils.mapSuccess +import com.wire.kalium.network.utils.onFailure +import com.wire.kalium.network.utils.onSuccess import com.wire.kalium.network.utils.wrapKaliumResponse import io.ktor.client.request.delete import io.ktor.client.request.get @@ -85,10 +88,14 @@ internal open class ClientApiV0 internal constructor( updateClientMlsPublicKeysRequest: UpdateClientMlsPublicKeysRequest, clientID: String ): NetworkResponse = - wrapKaliumResponse { + wrapKaliumResponse { httpClient.put("$PATH_CLIENTS/$clientID") { setBody(updateClientMlsPublicKeysRequest) } + }.onSuccess { + kaliumLogger.d("Updated MLS public keys for client ${it.value}") + }.onFailure { + kaliumLogger.e("Failed to update MLS public keys for client ${it.kException}") } override suspend fun updateClientCapabilities( diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MigrationDAO.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MigrationDAO.kt index 4c4bdbf1c16..757fe54ef35 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MigrationDAO.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MigrationDAO.kt @@ -24,7 +24,6 @@ import com.wire.kalium.persistence.MigrationQueries import com.wire.kalium.persistence.UnreadEventsQueries import com.wire.kalium.persistence.content.ButtonContentQueries import com.wire.kalium.persistence.dao.conversation.ConversationEntity -import com.wire.kalium.persistence.dao.conversation.MLS_DEFAULT_CIPHER_SUITE import com.wire.kalium.persistence.dao.conversation.MLS_DEFAULT_EPOCH import com.wire.kalium.persistence.dao.conversation.MLS_DEFAULT_LAST_KEY_MATERIAL_UPDATE_MILLI import com.wire.kalium.persistence.dao.message.MessageEntity From 38819c6ef38d9dbf0591f65adad4a9ae354afa12 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Thu, 2 May 2024 21:45:19 +0200 Subject: [PATCH 07/26] chore: cc to rc.59 --- .../CoreCryptoCentral.kt | 8 ++++---- gradle/libs.versions.toml | 2 +- .../kalium/logic/CoreCryptoExceptionMapper.kt | 18 +++++++++--------- 3 files changed, 14 insertions(+), 14 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 5eefcb16f63..b3e831bf892 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt @@ -34,7 +34,7 @@ actual suspend fun coreCryptoCentral( ): CoreCryptoCentral { val path = "$rootDir/${CoreCryptoCentralImpl.KEYSTORE_NAME}" File(rootDir).mkdirs() - val coreCrypto = coreCryptoDeferredInit(path, databaseKey, allowedCipherSuites, null) + val coreCrypto = coreCryptoDeferredInit(path, databaseKey) coreCrypto.setCallbacks(Callbacks()) return CoreCryptoCentralImpl( cc = coreCrypto, @@ -46,12 +46,12 @@ actual suspend fun coreCryptoCentral( private class Callbacks : CoreCryptoCallbacks { - override fun authorize(conversationId: ByteArray, clientId: ClientId): Boolean { + override suspend fun authorize(conversationId: ByteArray, clientId: ClientId): Boolean { // We always return true because our BE is currently enforcing that this constraint is always true return true } - override fun clientIsExistingGroupUser( + override suspend fun clientIsExistingGroupUser( conversationId: ConversationId, clientId: ClientId, existingClients: List, @@ -61,7 +61,7 @@ private class Callbacks : CoreCryptoCallbacks { return true } - override fun userAuthorize( + override suspend fun userAuthorize( conversationId: ConversationId, externalClientId: ClientId, existingClients: List diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 56277f7296b..9aa75fe1766 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -37,7 +37,7 @@ pbandk = "0.14.2" turbine = "1.0.0" avs = "9.6.13" jna = "5.14.0" -core-crypto = "1.0.0-rc.56-hotfix.1" +core-crypto = "1.0.0-rc.59" core-crypto-multiplatform = "0.6.0-rc.3-multiplatform-pre1" completeKotlin = "1.1.0" desugar-jdk = "2.0.4" diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt index c67d4c181f0..78f27826907 100644 --- a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt @@ -23,15 +23,15 @@ import uniffi.core_crypto.CryptoError actual fun mapMLSException(exception: Exception): MLSFailure = if (exception is CoreCryptoException.CryptoException) { when (exception.error) { - is CryptoError.WrongEpoch -> MLSFailure.WrongEpoch - is CryptoError.DuplicateMessage -> MLSFailure.DuplicateMessage - is CryptoError.BufferedFutureMessage -> MLSFailure.BufferedFutureMessage - is CryptoError.SelfCommitIgnored -> MLSFailure.SelfCommitIgnored - is CryptoError.UnmergedPendingGroup -> MLSFailure.UnmergedPendingGroup - is CryptoError.StaleProposal -> MLSFailure.StaleProposal - is CryptoError.StaleCommit -> MLSFailure.StaleCommit - is CryptoError.ConversationAlreadyExists -> MLSFailure.ConversationAlreadyExists - is CryptoError.MessageEpochTooOld -> MLSFailure.MessageEpochTooOld + CryptoError.WRONG_EPOCH -> MLSFailure.WrongEpoch + CryptoError.DUPLICATE_MESSAGE -> MLSFailure.DuplicateMessage + CryptoError.BUFFERED_FUTURE_MESSAGE -> MLSFailure.BufferedFutureMessage + CryptoError.SELF_COMMIT_IGNORED -> MLSFailure.SelfCommitIgnored + CryptoError.UNMERGED_PENDING_GROUP -> MLSFailure.UnmergedPendingGroup + CryptoError.STALE_PROPOSAL -> MLSFailure.StaleProposal + CryptoError.STALE_COMMIT -> MLSFailure.StaleCommit + CryptoError.CONVERSATION_ALREADY_EXISTS -> MLSFailure.ConversationAlreadyExists + CryptoError.MESSAGE_EPOCH_TOO_OLD -> MLSFailure.MessageEpochTooOld else -> MLSFailure.Generic(exception) } } else { From 011eb1b4a70d74ea79f1d37e48ee9c55c3faa205 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Fri, 3 May 2024 09:32:42 +0200 Subject: [PATCH 08/26] feat: fetch mls config form remote when missing --- .../CoreCryptoCentral.kt | 31 +++-- .../kalium/cryptography/CoreCryptoCentral.kt | 17 ++- .../logic/data/client/E2EIClientProvider.kt | 107 +++++++++++------- .../logic/data/client/MLSClientProvider.kt | 46 ++++++-- .../data/client/ProteusClientProvider.kt | 4 +- .../kalium/logic/feature/UserSessionScope.kt | 3 +- .../logic/client/E2EIClientProviderTest.kt | 2 +- 7 files changed, 132 insertions(+), 78 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 b3e831bf892..64753c55ba1 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt @@ -28,9 +28,7 @@ import java.io.File actual suspend fun coreCryptoCentral( rootDir: String, - databaseKey: String, - allowedCipherSuites: Ciphersuites, - defaultCipherSuite: UShort? + databaseKey: String ): CoreCryptoCentral { val path = "$rootDir/${CoreCryptoCentralImpl.KEYSTORE_NAME}" File(rootDir).mkdirs() @@ -38,9 +36,7 @@ actual suspend fun coreCryptoCentral( coreCrypto.setCallbacks(Callbacks()) return CoreCryptoCentralImpl( cc = coreCrypto, - rootDir = rootDir, - cipherSuite = allowedCipherSuites, - defaultCipherSuite = defaultCipherSuite + rootDir = rootDir ) } @@ -73,29 +69,31 @@ private class Callbacks : CoreCryptoCallbacks { class CoreCryptoCentralImpl( private val cc: CoreCrypto, - private val rootDir: String, - // TODO: remove one they are removed from the CC api - private val cipherSuite: Ciphersuites, - private val defaultCipherSuite: UShort? + private val rootDir: String ) : CoreCryptoCentral { fun getCoreCrypto() = cc - override suspend fun mlsClient(clientId: CryptoQualifiedClientId): MLSClient { + override suspend fun mlsClient( + clientId: CryptoQualifiedClientId, + cipherSuite: Ciphersuites, + defaultCipherSuite: UShort + ): MLSClient { cc.mlsInit(clientId.toString().encodeToByteArray(), cipherSuite, null) - return MLSClientImpl(cc, defaultCipherSuite!!) + return MLSClientImpl(cc, defaultCipherSuite) } override suspend fun mlsClient( enrollment: E2EIClient, certificateChain: CertificateChain, - newMLSKeyPackageCount: UInt + newMLSKeyPackageCount: UInt, + defaultCipherSuite: UShort ): MLSClient { // todo: use DPs list from here, and return alongside with the mls client cc.e2eiMlsInitOnly( (enrollment as E2EIClientImpl).wireE2eIdentity, certificateChain, newMLSKeyPackageCount ) - return MLSClientImpl(cc, defaultCipherSuite!!) + return MLSClientImpl(cc, defaultCipherSuite) } override suspend fun proteusClient(): ProteusClient { @@ -107,7 +105,8 @@ class CoreCryptoCentralImpl( displayName: String, handle: String, teamId: String?, - expiry: kotlin.time.Duration + expiry: kotlin.time.Duration, + defaultCipherSuite: UShort ): E2EIClient { return E2EIClientImpl( cc.e2eiNewEnrollment( @@ -116,7 +115,7 @@ class CoreCryptoCentralImpl( handle, teamId, expiry.inWholeSeconds.toUInt(), - defaultCipherSuite!! + defaultCipherSuite ) ) 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 10fc3146a48..6231e9f1625 100644 --- a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt @@ -20,12 +20,17 @@ package com.wire.kalium.cryptography import kotlin.time.Duration interface CoreCryptoCentral { - suspend fun mlsClient(clientId: CryptoQualifiedClientId): MLSClient + suspend fun mlsClient( + clientId: CryptoQualifiedClientId, + allowedCipherSuites: List, + defaultCipherSuite: UShort + ): MLSClient suspend fun mlsClient( enrollment: E2EIClient, certificateChain: CertificateChain, - newMLSKeyPackageCount: UInt + newMLSKeyPackageCount: UInt, + defaultCipherSuite: UShort ): MLSClient suspend fun proteusClient(): ProteusClient @@ -35,12 +40,14 @@ interface CoreCryptoCentral { * * @return wire end to end identity client */ + @Suppress("LongParameterList") suspend fun newAcmeEnrollment( clientId: CryptoQualifiedClientId, displayName: String, handle: String, teamId: String?, - expiry: Duration + expiry: Duration, + defaultCipherSuite: UShort ): E2EIClient /** @@ -65,7 +72,5 @@ interface CoreCryptoCentral { expect suspend fun coreCryptoCentral( rootDir: String, - databaseKey: String, - allowedCipherSuites: List, - defaultCipherSuite: UShort? + databaseKey: String ): 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 b115a3dcd8d..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 @@ -30,6 +30,7 @@ import com.wire.kalium.logic.data.user.UserRepository import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.flatMap import com.wire.kalium.logic.functional.fold +import com.wire.kalium.logic.functional.getOrElse import com.wire.kalium.logic.functional.left import com.wire.kalium.logic.functional.right import com.wire.kalium.logic.kaliumLogger @@ -57,7 +58,10 @@ internal class EI2EIClientProviderImpl( private val mutex = Mutex() - override suspend fun getE2EIClient(clientId: ClientId?, isNewClient: Boolean): Either = mutex.withLock { + override suspend fun getE2EIClient( + clientId: ClientId?, + isNewClient: Boolean + ): Either = mutex.withLock { withContext(dispatchers.io) { val currentClientId = clientId ?: currentClientIdProvider().fold({ return@withContext E2EIFailure.GettingE2EIClient(it).left() }, { it }) @@ -67,54 +71,73 @@ internal class EI2EIClientProviderImpl( } ?: run { getSelfUserInfo().flatMap { selfUser -> if (isNewClient) { - kaliumLogger.w("initial E2EI client without MLS client") - mlsClientProvider.getCoreCrypto(currentClientId).fold({ - E2EIFailure.GettingE2EIClient(it).left() - }, { - val cryptoQualifiedClientId = CryptoQualifiedClientId( - currentClientId.value, - selfUser.id.toCrypto() - ) - val newE2EIClient = it.newAcmeEnrollment( - clientId = cryptoQualifiedClientId, - displayName = selfUser.name!!, - handle = selfUser.handle!!, - teamId = selfUser.teamId?.value, - expiry = defaultE2EIExpiry - ) - e2EIClient = newE2EIClient - Either.Right(newE2EIClient) - }) + createNewE2EIClient(currentClientId, selfUser) } else { - mlsClientProvider.getMLSClient(currentClientId).fold({ - E2EIFailure.GettingE2EIClient(it).left() - }, { - val newE2EIClient = if (it.isE2EIEnabled()) { - kaliumLogger.w("initial E2EI client for MLS client that already has E2EI enabled") - it.e2eiNewRotateEnrollment( - selfUser.name, - selfUser.handle, - selfUser.teamId?.value, - defaultE2EIExpiry - ) - } else { - kaliumLogger.w("initial E2EI client for MLS client without E2EI") - it.e2eiNewActivationEnrollment( - selfUser.name!!, - selfUser.handle!!, - selfUser.teamId?.value, - defaultE2EIExpiry - ) - } - e2EIClient = newE2EIClient - Either.Right(newE2EIClient) - }) + getE2EIClientFromMLSClient(currentClientId, selfUser) } } } } } + private suspend fun getE2EIClientFromMLSClient( + currentClientId: ClientId, + selfUser: SelfUser + ): Either { + return mlsClientProvider.getMLSClient(currentClientId).fold({ + E2EIFailure.GettingE2EIClient(it).left() + }, { + val newE2EIClient = if (it.isE2EIEnabled()) { + kaliumLogger.w("initial E2EI client for MLS client that already has E2EI enabled") + it.e2eiNewRotateEnrollment( + selfUser.name, + selfUser.handle, + selfUser.teamId?.value, + defaultE2EIExpiry + ) + } else { + kaliumLogger.w("initial E2EI client for MLS client without E2EI") + it.e2eiNewActivationEnrollment( + selfUser.name!!, + selfUser.handle!!, + selfUser.teamId?.value, + defaultE2EIExpiry + ) + } + e2EIClient = newE2EIClient + Either.Right(newE2EIClient) + }) + } + + private suspend fun createNewE2EIClient( + currentClientId: ClientId, + selfUser: SelfUser + ): Either { + kaliumLogger.w("initial E2EI client without MLS client") + return mlsClientProvider.getCoreCrypto(currentClientId).fold({ + E2EIFailure.GettingE2EIClient(it).left() + }, { + val cryptoQualifiedClientId = CryptoQualifiedClientId( + currentClientId.value, + selfUser.id.toCrypto() + ) + val (_, defaultCipherSuite) = mlsClientProvider.getOrFetchMLSConfig().getOrElse { error -> + return E2EIFailure.GettingE2EIClient(error).left() + } + + val newE2EIClient = it.newAcmeEnrollment( + clientId = cryptoQualifiedClientId, + displayName = selfUser.name!!, + handle = selfUser.handle!!, + teamId = selfUser.teamId?.value, + expiry = defaultE2EIExpiry, + defaultCipherSuite = defaultCipherSuite.tag.toUShort() + ) + e2EIClient = newE2EIClient + Either.Right(newE2EIClient) + }) + } + private suspend fun getSelfUserInfo(): Either { val selfUser = userRepository.getSelfUser() ?: return E2EIFailure.GettingE2EIClient(StorageFailure.DataNotFound).left() return if (selfUser.name == null || selfUser.handle == null) 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 d41ef34e27d..c5afd316cf8 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 @@ -30,9 +30,13 @@ import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.E2EIFailure import com.wire.kalium.logic.configuration.UserConfigRepository import com.wire.kalium.logic.data.conversation.ClientId +import com.wire.kalium.logic.data.featureConfig.FeatureConfigRepository import com.wire.kalium.logic.data.id.CurrentClientIdProvider +import com.wire.kalium.logic.data.mls.SupportedCipherSuite import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.functional.Either +import com.wire.kalium.logic.functional.flatMap +import com.wire.kalium.logic.functional.flatMapLeft import com.wire.kalium.logic.functional.fold import com.wire.kalium.logic.functional.getOrElse import com.wire.kalium.logic.functional.left @@ -62,14 +66,18 @@ interface MLSClientProvider { certificateChain: CertificateChain, clientId: ClientId? ): Either + + suspend fun getOrFetchMLSConfig(): Either } +@Suppress("LongParameterList") class MLSClientProviderImpl( private val rootKeyStorePath: String, private val userId: UserId, private val currentClientIdProvider: CurrentClientIdProvider, private val passphraseStorage: PassphraseStorage, private val userConfigRepository: UserConfigRepository, + private val featureConfigRepository: FeatureConfigRepository, private val dispatchers: KaliumDispatcher = KaliumDispatcherImpl ) : MLSClientProvider { @@ -121,6 +129,16 @@ class MLSClientProviderImpl( } } + override suspend fun getOrFetchMLSConfig(): Either { + return userConfigRepository.getSupportedCipherSuite().flatMapLeft { + featureConfigRepository.getFeatureConfigs().map { + it.mlsModel.supportedCipherSuite + }.flatMap { + it?.right() ?: CoreFailure.Unknown(Exception("No supported cipher suite found")).left() + } + } + } + override suspend fun clearLocalFiles() { mlsClientMutex.withLock { mlsClient?.close() @@ -132,9 +150,6 @@ class MLSClientProviderImpl( @Suppress("TooGenericExceptionCaught") override suspend fun getCoreCrypto(clientId: ClientId?): Either = coreCryptoCentralMutex.withLock { withContext(dispatchers.io) { - val (supportedCipherSuite, defaultCipherSuite) = userConfigRepository.getSupportedCipherSuite() - .getOrElse { return@withContext Either.Left(it) } - val currentClientId = clientId ?: currentClientIdProvider().fold({ return@withContext Either.Left(it) }, { it }) val location = "$rootKeyStorePath/${currentClientId.value}".also { @@ -148,9 +163,7 @@ class MLSClientProviderImpl( val cc = try { coreCryptoCentral( rootDir = "$location/$KEYSTORE_NAME", - databaseKey = passphrase, - allowedCipherSuites = supportedCipherSuite.map { it.tag.toUShort() }, - defaultCipherSuite = defaultCipherSuite.tag.toUShort() + databaseKey = passphrase ) } catch (e: Exception) { @@ -170,8 +183,14 @@ class MLSClientProviderImpl( } private suspend fun mlsClient(userId: CryptoUserID, clientId: ClientId): Either { - return getCoreCrypto(clientId).map { - it.mlsClient(CryptoQualifiedClientId(clientId.value, userId)) + 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() + ) + } } } @@ -180,11 +199,20 @@ class MLSClientProviderImpl( certificateChain: CertificateChain, clientId: ClientId ): Either { + val (_, defaultCipherSuite) = getOrFetchMLSConfig().getOrElse { + return E2EIFailure.GettingE2EIClient(it).left() + } + return getCoreCrypto(clientId).fold({ E2EIFailure.GettingE2EIClient(it).left() }, { // MLS Keypackages taken care somewhere else, here we don't need to generate any - it.mlsClient(enrollment, certificateChain, 0U).right() + it.mlsClient( + enrollment = enrollment, + certificateChain = certificateChain, + newMLSKeyPackageCount = 0U, + defaultCipherSuite = defaultCipherSuite.tag.toUShort() + ).right() }) } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ProteusClientProvider.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ProteusClientProvider.kt index f697f679eed..013deac601f 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ProteusClientProvider.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ProteusClientProvider.kt @@ -106,9 +106,7 @@ class ProteusClientProviderImpl( val central = try { coreCryptoCentral( rootDir = rootProteusPath, - databaseKey = SecurityHelperImpl(passphraseStorage).proteusDBSecret(userId).value, - allowedCipherSuites = emptyList(), - defaultCipherSuite = null + databaseKey = SecurityHelperImpl(passphraseStorage).proteusDBSecret(userId).value ) } catch (e: Exception) { diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index 448306225fc..5fe3e8efd44 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -630,7 +630,8 @@ class UserSessionScope internal constructor( userId = userId, currentClientIdProvider = clientIdProvider, passphraseStorage = globalPreferences.passphraseStorage, - userConfigRepository = userConfigRepository + userConfigRepository = userConfigRepository, + featureConfigRepository = featureConfigRepository ) } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/client/E2EIClientProviderTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/client/E2EIClientProviderTest.kt index 2e1e9afe546..8f4e421eb3e 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/client/E2EIClientProviderTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/client/E2EIClientProviderTest.kt @@ -126,7 +126,7 @@ class E2EIClientProviderTest { } @Test - fun givenIsNewClientTrue_whenGettingE2EIClient_newAcmeEnrollmentCalled()= runTest { + fun givenIsNewClientTrue_whenGettingE2EIClient_newAcmeEnrollmentCalled() = runTest { val (arrangement, e2eiClientProvider) = Arrangement() .arrange { withGettingCoreCryptoSuccessful() From 6d1857fdbacf90eff3881407c2a1168271ffad0e Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Fri, 3 May 2024 12:27:52 +0200 Subject: [PATCH 09/26] revert CC version to 56-hotfix1 --- .../CoreCryptoCentral.kt | 17 +++++++---- gradle/libs.versions.toml | 2 +- .../kalium/logic/CoreCryptoExceptionMapper.kt | 30 +++++++++---------- .../kalium/persistence/dao/MigrationDAO.kt | 1 + 4 files changed, 28 insertions(+), 22 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 64753c55ba1..6550756b165 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt @@ -32,7 +32,12 @@ actual suspend fun coreCryptoCentral( ): CoreCryptoCentral { val path = "$rootDir/${CoreCryptoCentralImpl.KEYSTORE_NAME}" File(rootDir).mkdirs() - val coreCrypto = coreCryptoDeferredInit(path, databaseKey) + val coreCrypto = coreCryptoDeferredInit( + path = path, + key = databaseKey, + ciphersuites = emptyList(), + nbKeyPackage = null + ) coreCrypto.setCallbacks(Callbacks()) return CoreCryptoCentralImpl( cc = coreCrypto, @@ -42,12 +47,12 @@ actual suspend fun coreCryptoCentral( private class Callbacks : CoreCryptoCallbacks { - override suspend fun authorize(conversationId: ByteArray, clientId: ClientId): Boolean { + override fun authorize(conversationId: ByteArray, clientId: ClientId): Boolean { // We always return true because our BE is currently enforcing that this constraint is always true return true } - override suspend fun clientIsExistingGroupUser( + override fun clientIsExistingGroupUser( conversationId: ConversationId, clientId: ClientId, existingClients: List, @@ -57,7 +62,7 @@ private class Callbacks : CoreCryptoCallbacks { return true } - override suspend fun userAuthorize( + override fun userAuthorize( conversationId: ConversationId, externalClientId: ClientId, existingClients: List @@ -75,10 +80,10 @@ class CoreCryptoCentralImpl( override suspend fun mlsClient( clientId: CryptoQualifiedClientId, - cipherSuite: Ciphersuites, + allowedCipherSuites: Ciphersuites, defaultCipherSuite: UShort ): MLSClient { - cc.mlsInit(clientId.toString().encodeToByteArray(), cipherSuite, null) + cc.mlsInit(clientId.toString().encodeToByteArray(), allowedCipherSuites, null) return MLSClientImpl(cc, defaultCipherSuite) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9aa75fe1766..56277f7296b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -37,7 +37,7 @@ pbandk = "0.14.2" turbine = "1.0.0" avs = "9.6.13" jna = "5.14.0" -core-crypto = "1.0.0-rc.59" +core-crypto = "1.0.0-rc.56-hotfix.1" core-crypto-multiplatform = "0.6.0-rc.3-multiplatform-pre1" completeKotlin = "1.1.0" desugar-jdk = "2.0.4" diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt index 78f27826907..d4ba1b1e45e 100644 --- a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt @@ -21,19 +21,19 @@ import com.wire.crypto.CoreCryptoException import uniffi.core_crypto.CryptoError actual fun mapMLSException(exception: Exception): MLSFailure = - if (exception is CoreCryptoException.CryptoException) { - when (exception.error) { - CryptoError.WRONG_EPOCH -> MLSFailure.WrongEpoch - CryptoError.DUPLICATE_MESSAGE -> MLSFailure.DuplicateMessage - CryptoError.BUFFERED_FUTURE_MESSAGE -> MLSFailure.BufferedFutureMessage - CryptoError.SELF_COMMIT_IGNORED -> MLSFailure.SelfCommitIgnored - CryptoError.UNMERGED_PENDING_GROUP -> MLSFailure.UnmergedPendingGroup - CryptoError.STALE_PROPOSAL -> MLSFailure.StaleProposal - CryptoError.STALE_COMMIT -> MLSFailure.StaleCommit - CryptoError.CONVERSATION_ALREADY_EXISTS -> MLSFailure.ConversationAlreadyExists - CryptoError.MESSAGE_EPOCH_TOO_OLD -> MLSFailure.MessageEpochTooOld - else -> MLSFailure.Generic(exception) - } - } else { - MLSFailure.Generic(exception) + if (exception is CoreCryptoException.CryptoException) { + when (exception.error) { + is CryptoError.WrongEpoch -> MLSFailure.WrongEpoch + is CryptoError.DuplicateMessage -> MLSFailure.DuplicateMessage + is CryptoError.BufferedFutureMessage -> MLSFailure.BufferedFutureMessage + is CryptoError.SelfCommitIgnored -> MLSFailure.SelfCommitIgnored + is CryptoError.UnmergedPendingGroup -> MLSFailure.UnmergedPendingGroup + is CryptoError.StaleProposal -> MLSFailure.StaleProposal + is CryptoError.StaleCommit -> MLSFailure.StaleCommit + is CryptoError.ConversationAlreadyExists -> MLSFailure.ConversationAlreadyExists + is CryptoError.MessageEpochTooOld -> MLSFailure.MessageEpochTooOld + else -> MLSFailure.Generic(exception) } + } else { + MLSFailure.Generic(exception) + } diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MigrationDAO.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MigrationDAO.kt index 757fe54ef35..4c4bdbf1c16 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MigrationDAO.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MigrationDAO.kt @@ -24,6 +24,7 @@ import com.wire.kalium.persistence.MigrationQueries import com.wire.kalium.persistence.UnreadEventsQueries import com.wire.kalium.persistence.content.ButtonContentQueries import com.wire.kalium.persistence.dao.conversation.ConversationEntity +import com.wire.kalium.persistence.dao.conversation.MLS_DEFAULT_CIPHER_SUITE import com.wire.kalium.persistence.dao.conversation.MLS_DEFAULT_EPOCH import com.wire.kalium.persistence.dao.conversation.MLS_DEFAULT_LAST_KEY_MATERIAL_UPDATE_MILLI import com.wire.kalium.persistence.dao.message.MessageEntity From c6f6f7f2df28c561476d6709f341bf133f49912d Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Fri, 3 May 2024 12:33:03 +0200 Subject: [PATCH 10/26] detekt --- .../wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt index 3687fb5be6e..af06d56d0af 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt @@ -41,6 +41,7 @@ class MLSPublicKeysMapperImpl : MLSPublicKeysMapper { } } +@Suppress("ClassNaming") sealed class MLSPublicKeyType { abstract val value: String? From 7811a02dd2115087078d2a90e5196d1c0caa8495 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Fri, 3 May 2024 12:35:04 +0200 Subject: [PATCH 11/26] cleanup --- .../logic/feature/client/RegisterMLSClientUseCase.kt | 7 ------- 1 file changed, 7 deletions(-) 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 f323c32c762..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 @@ -55,28 +55,21 @@ internal class RegisterMLSClientUseCaseImpl( ) : RegisterMLSClientUseCase { override suspend operator fun invoke(clientId: ClientId): Either { - kaliumLogger.d("Registering MLS client with client ID: $clientId") return userConfigRepository.getE2EISettings().flatMap { e2eiSettings -> - kaliumLogger.d("Registering MLS client with E2EI settings") if (e2eiSettings.isRequired && !mlsClientProvider.isMLSClientInitialised()) { - kaliumLogger.d("E2EI settings are required but MLS client is not initialised") return RegisterMLSClientResult.E2EICertificateRequired.right() } else { mlsClientProvider.getMLSClient(clientId) } }.onFailure { - kaliumLogger.e("Failed to get MLS client: $it") mlsClientProvider.getMLSClient(clientId) }.flatMap { mlsClient -> - kaliumLogger.d("Getting public key from MLS client") wrapMLSRequest { mlsClient.getPublicKey() } }.flatMap { (publicKey, cipherSuite) -> - kaliumLogger.d("Registering MLS client with public key: $publicKey") clientRepository.registerMLSClient(clientId, publicKey, CipherSuite.fromTag(cipherSuite)) }.flatMap { - kaliumLogger.d("Uploading new key packages") keyPackageRepository.uploadNewKeyPackages(clientId, keyPackageLimitsProvider.refillAmount()) Either.Right(RegisterMLSClientResult.Success) }.onFailure { From 43c42054b767de4a22b80f1ae98c79c9b1e88316 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Fri, 3 May 2024 12:36:05 +0200 Subject: [PATCH 12/26] address PR comment --- .../logic/data/conversation/MLSConversationRepository.kt | 2 +- .../logic/data/mlspublickeys/MLSPublicKeysRepository.kt | 4 ++-- .../logic/data/conversation/MLSConversationRepositoryTest.kt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt index 9620ad5d041..abb5179a81f 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt @@ -574,7 +574,7 @@ internal class MLSConversationDataSource( allowSkippingUsersWithoutKeyPackages: Boolean, ): Either = withContext(serialDispatcher) { mlsClientProvider.getMLSClient().flatMap { - mlsPublicKeysRepository.keyForCipherSuite( + mlsPublicKeysRepository.getKeyForCipherSuite( CipherSuite.fromTag(it.getDefaultCipherSuite()) ).flatMap { key -> establishMLSGroup( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt index 21ffc48638b..ecb9a6099be 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt @@ -38,7 +38,7 @@ data class MLSPublicKeys( interface MLSPublicKeysRepository { suspend fun fetchKeys(): Either suspend fun getKeys(): Either - suspend fun keyForCipherSuite(cipherSuite: CipherSuite): Either + suspend fun getKeyForCipherSuite(cipherSuite: CipherSuite): Either } class MLSPublicKeysRepositoryImpl( @@ -60,7 +60,7 @@ class MLSPublicKeysRepositoryImpl( return publicKeys?.let { Either.Right(it) } ?: fetchKeys() } - override suspend fun keyForCipherSuite(cipherSuite: CipherSuite): Either { + override suspend fun getKeyForCipherSuite(cipherSuite: CipherSuite): Either { return getKeys().flatMap { serverPublicKeys -> kaliumLogger.d("serverPublicKeys: $serverPublicKeys") diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt index 8351048870d..7ec0caeea79 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt @@ -1760,7 +1760,7 @@ class MLSConversationRepositoryTest { fun withKeyForCipherSuite() = apply { given(mlsPublicKeysRepository) - .suspendFunction(mlsPublicKeysRepository::keyForCipherSuite) + .suspendFunction(mlsPublicKeysRepository::getKeyForCipherSuite) .whenInvokedWith(any()) .then { Either.Right(CRYPTO_MLS_PUBLIC_KEY) } } From 9a2c0fc484c0b92dcab3f1b91b2c982c6b12e62b Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Fri, 3 May 2024 12:37:26 +0200 Subject: [PATCH 13/26] cleanup --- .../wire/kalium/network/api/v0/authenticated/ClientApiV0.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt index c97a788e78a..8b706e243fc 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt @@ -92,10 +92,6 @@ internal open class ClientApiV0 internal constructor( httpClient.put("$PATH_CLIENTS/$clientID") { setBody(updateClientMlsPublicKeysRequest) } - }.onSuccess { - kaliumLogger.d("Updated MLS public keys for client ${it.value}") - }.onFailure { - kaliumLogger.e("Failed to update MLS public keys for client ${it.kException}") } override suspend fun updateClientCapabilities( From fe8cf4ffe722de589bb4d2302a4a20dfb070a361 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Mon, 6 May 2024 12:43:16 +0200 Subject: [PATCH 14/26] fix test --- .../kotlin/com/wire/kalium/cryptography/ProteusClientTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/ProteusClientTest.kt b/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/ProteusClientTest.kt index 82eca15fece..ec4f95be564 100644 --- a/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/ProteusClientTest.kt +++ b/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/ProteusClientTest.kt @@ -39,7 +39,7 @@ class ProteusClientTest : BaseProteusClientTest() { private val alice = SampleUser(CryptoUserID("aliceId", "aliceDomain"), "Alice") private val bob = SampleUser(CryptoUserID("bobId", "bobDomain"), "Bob") private val aliceSessionId = CryptoSessionId(alice.id, CryptoClientId("aliceClient")) - private val bobSessionId = CryptoSessionId(alice.id, CryptoClientId("aliceClient")) + private val bobSessionId = CryptoSessionId(bob.id, CryptoClientId("bobClient")) @BeforeTest fun before() { From a50a9298c07676f709d6b060cee6c1791896f4a6 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Mon, 6 May 2024 20:51:52 +0200 Subject: [PATCH 15/26] use CC vrc.56.hotfix.2 --- .../CoreCryptoCentral.kt | 8 ++--- gradle/libs.versions.toml | 2 +- .../kalium/logic/CoreCryptoExceptionMapper.kt | 30 +++++++++---------- 3 files changed, 20 insertions(+), 20 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 b3e831bf892..5eefcb16f63 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt @@ -34,7 +34,7 @@ actual suspend fun coreCryptoCentral( ): CoreCryptoCentral { val path = "$rootDir/${CoreCryptoCentralImpl.KEYSTORE_NAME}" File(rootDir).mkdirs() - val coreCrypto = coreCryptoDeferredInit(path, databaseKey) + val coreCrypto = coreCryptoDeferredInit(path, databaseKey, allowedCipherSuites, null) coreCrypto.setCallbacks(Callbacks()) return CoreCryptoCentralImpl( cc = coreCrypto, @@ -46,12 +46,12 @@ actual suspend fun coreCryptoCentral( private class Callbacks : CoreCryptoCallbacks { - override suspend fun authorize(conversationId: ByteArray, clientId: ClientId): Boolean { + override fun authorize(conversationId: ByteArray, clientId: ClientId): Boolean { // We always return true because our BE is currently enforcing that this constraint is always true return true } - override suspend fun clientIsExistingGroupUser( + override fun clientIsExistingGroupUser( conversationId: ConversationId, clientId: ClientId, existingClients: List, @@ -61,7 +61,7 @@ private class Callbacks : CoreCryptoCallbacks { return true } - override suspend fun userAuthorize( + override fun userAuthorize( conversationId: ConversationId, externalClientId: ClientId, existingClients: List diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9aa75fe1766..25b0685c396 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -37,7 +37,7 @@ pbandk = "0.14.2" turbine = "1.0.0" avs = "9.6.13" jna = "5.14.0" -core-crypto = "1.0.0-rc.59" +core-crypto = "1.0.0-rc.56-hotfix.2" core-crypto-multiplatform = "0.6.0-rc.3-multiplatform-pre1" completeKotlin = "1.1.0" desugar-jdk = "2.0.4" diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt index 78f27826907..d4ba1b1e45e 100644 --- a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt @@ -21,19 +21,19 @@ import com.wire.crypto.CoreCryptoException import uniffi.core_crypto.CryptoError actual fun mapMLSException(exception: Exception): MLSFailure = - if (exception is CoreCryptoException.CryptoException) { - when (exception.error) { - CryptoError.WRONG_EPOCH -> MLSFailure.WrongEpoch - CryptoError.DUPLICATE_MESSAGE -> MLSFailure.DuplicateMessage - CryptoError.BUFFERED_FUTURE_MESSAGE -> MLSFailure.BufferedFutureMessage - CryptoError.SELF_COMMIT_IGNORED -> MLSFailure.SelfCommitIgnored - CryptoError.UNMERGED_PENDING_GROUP -> MLSFailure.UnmergedPendingGroup - CryptoError.STALE_PROPOSAL -> MLSFailure.StaleProposal - CryptoError.STALE_COMMIT -> MLSFailure.StaleCommit - CryptoError.CONVERSATION_ALREADY_EXISTS -> MLSFailure.ConversationAlreadyExists - CryptoError.MESSAGE_EPOCH_TOO_OLD -> MLSFailure.MessageEpochTooOld - else -> MLSFailure.Generic(exception) - } - } else { - MLSFailure.Generic(exception) + if (exception is CoreCryptoException.CryptoException) { + when (exception.error) { + is CryptoError.WrongEpoch -> MLSFailure.WrongEpoch + is CryptoError.DuplicateMessage -> MLSFailure.DuplicateMessage + is CryptoError.BufferedFutureMessage -> MLSFailure.BufferedFutureMessage + is CryptoError.SelfCommitIgnored -> MLSFailure.SelfCommitIgnored + is CryptoError.UnmergedPendingGroup -> MLSFailure.UnmergedPendingGroup + is CryptoError.StaleProposal -> MLSFailure.StaleProposal + is CryptoError.StaleCommit -> MLSFailure.StaleCommit + is CryptoError.ConversationAlreadyExists -> MLSFailure.ConversationAlreadyExists + is CryptoError.MessageEpochTooOld -> MLSFailure.MessageEpochTooOld + else -> MLSFailure.Generic(exception) } + } else { + MLSFailure.Generic(exception) + } From e165154af578e929b42d0e3f340c1c9517129396 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Mon, 6 May 2024 21:56:50 +0200 Subject: [PATCH 16/26] fix merge issue --- .../com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt | 6 ++---- .../com.wire.kalium.cryptography/CoreCryptoCentral.kt | 7 ++++++- .../com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt | 4 +--- 3 files changed, 9 insertions(+), 8 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 3516966da67..f112060a064 100644 --- a/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt +++ b/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt @@ -26,15 +26,13 @@ import kotlin.time.Duration actual suspend fun coreCryptoCentral( rootDir: String, - databaseKey: String, - allowedCipherSuites: List, - defaultCipherSuite: UShort? + databaseKey: String ): CoreCryptoCentral { val path = "$rootDir/${CoreCryptoCentralImpl.KEYSTORE_NAME}" NSFileManager.defaultManager.createDirectoryAtPath(rootDir, withIntermediateDirectories = true, null, null) val coreCrypto = CoreCrypto.deferredInit(path, databaseKey, null) coreCrypto.setCallbacks(Callbacks()) - return CoreCryptoCentralImpl(coreCrypto, rootDir, defaultCipherSuite) + return CoreCryptoCentralImpl(coreCrypto, rootDir, null) } private class Callbacks : CoreCryptoCallbacks { 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 5d4fbf64f4d..d512afc4b62 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt @@ -32,7 +32,12 @@ actual suspend fun coreCryptoCentral( ): CoreCryptoCentral { val path = "$rootDir/${CoreCryptoCentralImpl.KEYSTORE_NAME}" File(rootDir).mkdirs() - val coreCrypto = coreCryptoDeferredInit(path, databaseKey, allowedCipherSuites, null) + val coreCrypto = coreCryptoDeferredInit( + path = path, + key = databaseKey, + ciphersuites = emptyList(), + nbKeyPackage = null + ) coreCrypto.setCallbacks(Callbacks()) return CoreCryptoCentralImpl( cc = coreCrypto, diff --git a/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt b/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt index 1e007c05b53..b5d3a4e1431 100644 --- a/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt +++ b/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt @@ -19,7 +19,5 @@ package com.wire.kalium.cryptography actual suspend fun coreCryptoCentral( rootDir: String, - databaseKey: String, - allowedCipherSuites: List, - defaultCipherSuite: UShort? + databaseKey: String ): CoreCryptoCentral = TODO("Not yet implemented") From 8b34620b323ea5f92c2ebe8b4db36d6ca15e3b4d Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Mon, 6 May 2024 22:05:06 +0200 Subject: [PATCH 17/26] fix merge issue --- .../cryptography/CoreCryptoCentralImpl.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 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 f112060a064..b63e0e0a8d4 100644 --- a/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt +++ b/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt @@ -32,7 +32,7 @@ actual suspend fun coreCryptoCentral( NSFileManager.defaultManager.createDirectoryAtPath(rootDir, withIntermediateDirectories = true, null, null) val coreCrypto = CoreCrypto.deferredInit(path, databaseKey, null) coreCrypto.setCallbacks(Callbacks()) - return CoreCryptoCentralImpl(coreCrypto, rootDir, null) + return CoreCryptoCentralImpl(coreCrypto, rootDir) } private class Callbacks : CoreCryptoCallbacks { @@ -59,11 +59,14 @@ private class Callbacks : CoreCryptoCallbacks { class CoreCryptoCentralImpl( private val cc: CoreCrypto, - private val rootDir: String, - private val defaultCipherSuite: UShort? + private val rootDir: String ) : CoreCryptoCentral { - override suspend fun mlsClient(clientId: CryptoQualifiedClientId): MLSClient { + override suspend fun mlsClient( + clientId: CryptoQualifiedClientId, + allowedCipherSuites: List, + defaultCipherSuite: UShort + ): MLSClient { cc.mlsInit(MLSClientImpl.toUByteList(clientId.toString())) return MLSClientImpl(cc, defaultCipherSuite = defaultCipherSuite!!) } @@ -71,7 +74,8 @@ class CoreCryptoCentralImpl( override suspend fun mlsClient( enrollment: E2EIClient, certificateChain: CertificateChain, - newMLSKeyPackageCount: UInt + newMLSKeyPackageCount: UInt, + defaultCipherSuite: UShort ): MLSClient { TODO("Not yet implemented") } @@ -85,7 +89,8 @@ class CoreCryptoCentralImpl( displayName: String, handle: String, teamId: String?, - expiry: Duration + expiry: Duration, + defaultCipherSuite: UShort ): E2EIClient { TODO("Not yet implemented") } From d751ced0983ac9fe1baca89b2e50cadf8f9ce850 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Mon, 6 May 2024 22:15:41 +0200 Subject: [PATCH 18/26] Trigger CI Signed-off-by: MohamadJaara From 3e80a5c5d1f5e35925711a4a1eb6c30d768dadab Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Mon, 6 May 2024 22:30:41 +0200 Subject: [PATCH 19/26] fix test --- .../com/wire/kalium/cryptography/BaseMLSClientTest.kt | 8 +++----- .../com/wire/kalium/cryptography/BaseMLSClientTest.kt | 8 +++----- .../com/wire/kalium/cryptography/BaseMLSClientTest.kt | 8 +++----- .../com/wire/kalium/cryptography/BaseMLSClientTest.kt | 4 +--- .../com/wire/kalium/cryptography/BaseMLSClientTest.kt | 4 +--- .../com/wire/kalium/cryptography/BaseMLSClientTest.kt | 8 +++----- 6 files changed, 14 insertions(+), 26 deletions(-) diff --git a/cryptography/src/androidInstrumentedTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt b/cryptography/src/androidInstrumentedTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt index e81b6fa10c2..0338d1b0c8d 100644 --- a/cryptography/src/androidInstrumentedTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt +++ b/cryptography/src/androidInstrumentedTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt @@ -27,17 +27,15 @@ actual open class BaseMLSClientTest { allowedCipherSuites: List, defaultCipherSuite: UShort ): MLSClient { - return createCoreCrypto(clientId, allowedCipherSuites, defaultCipherSuite).mlsClient(clientId) + return createCoreCrypto(clientId).mlsClient(clientId, allowedCipherSuites, defaultCipherSuite) } actual suspend fun createCoreCrypto( - clientId: CryptoQualifiedClientId, - allowedCipherSuites: List, - defaultCipherSuite: UShort + clientId: CryptoQualifiedClientId ): CoreCryptoCentral { val root = Files.createTempDirectory("mls").toFile() val keyStore = root.resolve("keystore-$clientId") - return coreCryptoCentral(keyStore.absolutePath, "test", allowedCipherSuites, defaultCipherSuite) + return coreCryptoCentral(keyStore.absolutePath, "test") } } diff --git a/cryptography/src/androidUnitTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt b/cryptography/src/androidUnitTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt index f713c82dfa7..59b082f6812 100644 --- a/cryptography/src/androidUnitTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt +++ b/cryptography/src/androidUnitTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt @@ -26,16 +26,14 @@ actual open class BaseMLSClientTest { allowedCipherSuites: List, defaultCipherSuite: UShort ): MLSClient { - return createCoreCrypto(clientId, allowedCipherSuites, defaultCipherSuite).mlsClient(clientId) + return createCoreCrypto(clientId).mlsClient(clientId, allowedCipherSuites, defaultCipherSuite) } actual suspend fun createCoreCrypto( - clientId: CryptoQualifiedClientId, - allowedCipherSuites: List, - defaultCipherSuite: UShort + clientId: CryptoQualifiedClientId ): CoreCryptoCentral { val root = Files.createTempDirectory("mls").toFile() val keyStore = root.resolve("keystore-$clientId") - return coreCryptoCentral(keyStore.absolutePath, "test", allowedCipherSuites, defaultCipherSuite) + return coreCryptoCentral(keyStore.absolutePath, "test") } } diff --git a/cryptography/src/appleTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt b/cryptography/src/appleTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt index dbdb6e0bf3a..a7cb5cce875 100644 --- a/cryptography/src/appleTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt +++ b/cryptography/src/appleTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt @@ -29,17 +29,15 @@ actual open class BaseMLSClientTest actual constructor() { allowedCipherSuites: List, defaultCipherSuite: UShort ): MLSClient { - return createCoreCrypto(clientId, allowedCipherSuites, defaultCipherSuite).mlsClient(clientId) + return createCoreCrypto(clientId).mlsClient(clientId, allowedCipherSuites, defaultCipherSuite) } actual suspend fun createCoreCrypto( - clientId: CryptoQualifiedClientId, - allowedCipherSuites: List, - defaultCipherSuite: UShort + clientId: CryptoQualifiedClientId ): CoreCryptoCentral { val rootDir = NSURL.fileURLWithPath(NSTemporaryDirectory() + "/mls", isDirectory = true) NSFileManager.defaultManager.createDirectoryAtURL(rootDir, true, null, null) val keyStore = rootDir.URLByAppendingPathComponent("keystore-$clientId")!! - return coreCryptoCentral(keyStore.path!!, "test", allowedCipherSuites, defaultCipherSuite) + return coreCryptoCentral(keyStore.path!!, "test") } } diff --git a/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt b/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt index 7957f86f271..589282a3d99 100644 --- a/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt +++ b/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt @@ -27,9 +27,7 @@ expect open class BaseMLSClientTest() { ): MLSClient suspend fun createCoreCrypto( - clientId: CryptoQualifiedClientId, - allowedCipherSuites: List, - defaultCipherSuite: UShort + clientId: CryptoQualifiedClientId ): CoreCryptoCentral } diff --git a/cryptography/src/jsTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt b/cryptography/src/jsTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt index 32d073968a9..31d77c0dd80 100644 --- a/cryptography/src/jsTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt +++ b/cryptography/src/jsTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt @@ -28,9 +28,7 @@ actual open class BaseMLSClientTest actual constructor() { } actual suspend fun createCoreCrypto( - clientId: CryptoQualifiedClientId, - allowedCipherSuites: List, - defaultCipherSuite: UShort + clientId: CryptoQualifiedClientId ): CoreCryptoCentral { TODO("Not yet implemented") } diff --git a/cryptography/src/jvmTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt b/cryptography/src/jvmTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt index e8f67f7377d..0ff82832919 100644 --- a/cryptography/src/jvmTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt +++ b/cryptography/src/jvmTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt @@ -27,16 +27,14 @@ actual open class BaseMLSClientTest { allowedCipherSuites: List, defaultCipherSuite: UShort ): MLSClient { - return createCoreCrypto(clientId, allowedCipherSuites, defaultCipherSuite).mlsClient(clientId) + return createCoreCrypto(clientId).mlsClient(clientId, allowedCipherSuites, defaultCipherSuite) } actual suspend fun createCoreCrypto( - clientId: CryptoQualifiedClientId, - allowedCipherSuites: List, - defaultCipherSuite: UShort + clientId: CryptoQualifiedClientId ): CoreCryptoCentral { val root = Files.createTempDirectory("mls").toFile() val keyStore = root.resolve("keystore-$clientId") - return coreCryptoCentral(keyStore.absolutePath, "test", allowedCipherSuites, defaultCipherSuite) + return coreCryptoCentral(keyStore.absolutePath, "test") } } From 7514e2079ac2e9be75bb60feeeee6cd9b80ad97c Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Mon, 6 May 2024 22:40:02 +0200 Subject: [PATCH 20/26] fix test --- .../com/wire/kalium/cryptography/E2EIClientTest.kt | 6 +++--- .../wire/kalium/cryptography/BaseProteusClientTest.kt | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/E2EIClientTest.kt b/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/E2EIClientTest.kt index 3863baca4ea..5633970d968 100644 --- a/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/E2EIClientTest.kt +++ b/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/E2EIClientTest.kt @@ -112,7 +112,7 @@ class E2EIClientTest : BaseMLSClientTest() { @Test fun givenClient_whenCallingCheckOrderRequest_ReturnNonEmptyResult() = runTest { - val coreCryptoCentral = createCoreCrypto(ALICE1.qualifiedClientId, ALLOWED_CIPHER_SUITES, DEFAULT_CIPHER_SUITE) + val coreCryptoCentral = createCoreCrypto(ALICE1.qualifiedClientId) val e2eiClient = createE2EIClient(ALICE1) e2eiClient.directoryResponse(ACME_DIRECTORY_API_RESPONSE) e2eiClient.setAccountResponse(NEW_ACCOUNT_API_RESPONSE) @@ -130,7 +130,7 @@ class E2EIClientTest : BaseMLSClientTest() { @Test fun givenClient_whenCallingFinalizeRequest_ReturnNonEmptyResult() = runTest { - val coreCryptoCentral = createCoreCrypto(ALICE1.qualifiedClientId, ALLOWED_CIPHER_SUITES, DEFAULT_CIPHER_SUITE) + val coreCryptoCentral = createCoreCrypto(ALICE1.qualifiedClientId) val e2eiClient = createE2EIClient(ALICE1) e2eiClient.directoryResponse(ACME_DIRECTORY_API_RESPONSE) e2eiClient.setAccountResponse(NEW_ACCOUNT_API_RESPONSE) @@ -149,7 +149,7 @@ class E2EIClientTest : BaseMLSClientTest() { @Test fun givenClient_whenCallingCertificateRequest_ReturnNonEmptyResult() = runTest { - val coreCryptoCentral = createCoreCrypto(ALICE1.qualifiedClientId, ALLOWED_CIPHER_SUITES, DEFAULT_CIPHER_SUITE) + val coreCryptoCentral = createCoreCrypto(ALICE1.qualifiedClientId) val e2eiClient = createE2EIClient(ALICE1) e2eiClient.directoryResponse(ACME_DIRECTORY_API_RESPONSE) e2eiClient.setAccountResponse(NEW_ACCOUNT_API_RESPONSE) diff --git a/cryptography/src/jvmTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt b/cryptography/src/jvmTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt index 20b5c3f3658..6e62c7f7246 100644 --- a/cryptography/src/jvmTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt +++ b/cryptography/src/jvmTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt @@ -31,9 +31,12 @@ actual open class BaseProteusClientTest { return ProteusStoreRef(keyStore.absolutePath) } - actual suspend fun createProteusClient(proteusStore: ProteusStoreRef, databaseKey: ProteusDBSecret?): ProteusClient { + actual suspend fun createProteusClient( + proteusStore: ProteusStoreRef, + databaseKey: ProteusDBSecret? + ): ProteusClient { return databaseKey?.let { - coreCryptoCentral(proteusStore.value, it.value, emptyList(), null).proteusClient() - } ?: cryptoboxProteusClient(proteusStore.value, testCoroutineScheduler,testCoroutineScheduler) + coreCryptoCentral(proteusStore.value, it.value).proteusClient() + } ?: cryptoboxProteusClient(proteusStore.value, testCoroutineScheduler, testCoroutineScheduler) } } From b869ef3effd4018f6aaced1d9bf304e6daafa179 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Mon, 6 May 2024 22:50:45 +0200 Subject: [PATCH 21/26] fix test --- .../com/wire/kalium/cryptography/BaseProteusClientTest.kt | 2 +- .../com/wire/kalium/cryptography/BaseProteusClientTest.kt | 2 +- .../com/wire/kalium/cryptography/BaseProteusClientTest.kt | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/cryptography/src/androidInstrumentedTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt b/cryptography/src/androidInstrumentedTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt index 4b8fab41c2c..8a8ad5b6698 100644 --- a/cryptography/src/androidInstrumentedTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt +++ b/cryptography/src/androidInstrumentedTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt @@ -33,7 +33,7 @@ actual open class BaseProteusClientTest { actual suspend fun createProteusClient(proteusStore: ProteusStoreRef, databaseKey: ProteusDBSecret?): ProteusClient { return databaseKey?.let { - coreCryptoCentral(proteusStore.value, it.value, emptyList(), 0.toUShort()).proteusClient() + coreCryptoCentral(proteusStore.value, it.value).proteusClient() } ?: cryptoboxProteusClient(proteusStore.value, testCoroutineScheduler, testCoroutineScheduler) } } diff --git a/cryptography/src/androidUnitTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt b/cryptography/src/androidUnitTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt index 20b5c3f3658..5e686e24443 100644 --- a/cryptography/src/androidUnitTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt +++ b/cryptography/src/androidUnitTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt @@ -33,7 +33,7 @@ actual open class BaseProteusClientTest { actual suspend fun createProteusClient(proteusStore: ProteusStoreRef, databaseKey: ProteusDBSecret?): ProteusClient { return databaseKey?.let { - coreCryptoCentral(proteusStore.value, it.value, emptyList(), null).proteusClient() + coreCryptoCentral(proteusStore.value, it.value).proteusClient() } ?: cryptoboxProteusClient(proteusStore.value, testCoroutineScheduler,testCoroutineScheduler) } } diff --git a/cryptography/src/appleTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt b/cryptography/src/appleTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt index 23b47c90120..1246c953cf8 100644 --- a/cryptography/src/appleTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt +++ b/cryptography/src/appleTest/kotlin/com/wire/kalium/cryptography/BaseProteusClientTest.kt @@ -24,8 +24,6 @@ import platform.Foundation.NSURL actual open class BaseProteusClientTest actual constructor() { - private val testCoroutineScheduler = TestCoroutineScheduler() - actual fun createProteusStoreRef(userId: CryptoUserID): ProteusStoreRef { val rootDir = NSURL.fileURLWithPath(NSTemporaryDirectory() + "proteus/${userId.value}", isDirectory = true) return ProteusStoreRef(rootDir.path!!) @@ -35,7 +33,7 @@ actual open class BaseProteusClientTest actual constructor() { proteusStore: ProteusStoreRef, databaseKey: ProteusDBSecret? ): ProteusClient { - return coreCryptoCentral(proteusStore.value, "secret", emptyList(), null).proteusClient() + return coreCryptoCentral(proteusStore.value, "secret").proteusClient() } } From da602d1337b3d8b960f883e22dcdcd2e287604b1 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Mon, 6 May 2024 23:51:58 +0200 Subject: [PATCH 22/26] fix test --- .../logic/client/E2EIClientProviderTest.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/client/E2EIClientProviderTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/client/E2EIClientProviderTest.kt index 8f4e421eb3e..a06517ba648 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/client/E2EIClientProviderTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/client/E2EIClientProviderTest.kt @@ -20,14 +20,18 @@ package com.wire.kalium.logic.client import com.wire.kalium.logic.data.client.E2EIClientProvider import com.wire.kalium.logic.data.client.EI2EIClientProviderImpl import com.wire.kalium.logic.data.conversation.ClientId +import com.wire.kalium.logic.data.mls.CipherSuite +import com.wire.kalium.logic.data.mls.SupportedCipherSuite import com.wire.kalium.logic.framework.TestClient import com.wire.kalium.logic.framework.TestUser +import com.wire.kalium.logic.functional.right import com.wire.kalium.logic.util.arrangement.provider.E2EIClientProviderArrangement import com.wire.kalium.logic.util.arrangement.provider.E2EIClientProviderArrangementImpl import com.wire.kalium.logic.util.shouldFail import com.wire.kalium.logic.util.shouldSucceed import io.mockative.any import io.mockative.fun1 +import io.mockative.given import io.mockative.once import io.mockative.verify import kotlinx.coroutines.test.runTest @@ -127,11 +131,19 @@ class E2EIClientProviderTest { @Test fun givenIsNewClientTrue_whenGettingE2EIClient_newAcmeEnrollmentCalled() = runTest { + val supportedCipherSuite = SupportedCipherSuite( + supported = listOf( + CipherSuite.MLS_128_DHKEMP256_AES128GCM_SHA256_P256, + CipherSuite.MLS_128_DHKEMP256_AES128GCM_SHA256_P256 + ), + default = CipherSuite.MLS_128_DHKEMP256_AES128GCM_SHA256_P256 + ) val (arrangement, e2eiClientProvider) = Arrangement() .arrange { withGettingCoreCryptoSuccessful() withGetNewAcmeEnrollmentSuccessful() withSelfUser(TestUser.SELF) + withGetOrFetchMLSConfig(supportedCipherSuite) } e2eiClientProvider.getE2EIClient(TestClient.CLIENT_ID,isNewClient = true).shouldSucceed() @@ -160,5 +172,12 @@ class E2EIClientProviderTest { return this to e2eiClientProvider } + + fun withGetOrFetchMLSConfig(result: SupportedCipherSuite) { + given(mlsClientProvider) + .suspendFunction(mlsClientProvider::getOrFetchMLSConfig) + .whenInvoked() + .thenReturn(result.right()) + } } } From c6feb00d2c48bf672b45235e6084ba291bc6c201 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Tue, 7 May 2024 00:35:53 +0200 Subject: [PATCH 23/26] detekt --- .../wire/kalium/network/api/v0/authenticated/ClientApiV0.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt index 8b706e243fc..b65532c5886 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ClientApiV0.kt @@ -31,11 +31,8 @@ import com.wire.kalium.network.api.base.authenticated.client.UpdateClientMlsPubl import com.wire.kalium.network.api.base.model.PushTokenBody import com.wire.kalium.network.api.base.model.QualifiedID import com.wire.kalium.network.api.base.model.UserId -import com.wire.kalium.network.kaliumLogger import com.wire.kalium.network.utils.NetworkResponse import com.wire.kalium.network.utils.mapSuccess -import com.wire.kalium.network.utils.onFailure -import com.wire.kalium.network.utils.onSuccess import com.wire.kalium.network.utils.wrapKaliumResponse import io.ktor.client.request.delete import io.ktor.client.request.get From f43874a13bd01b990826c27f3c7a8999b83c1c69 Mon Sep 17 00:00:00 2001 From: Mohamad Jaara Date: Tue, 7 May 2024 10:48:16 +0200 Subject: [PATCH 24/26] Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt Co-authored-by: Vitor Hugo Schwaab --- .../kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt index af06d56d0af..881a66e5774 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt @@ -42,8 +42,8 @@ class MLSPublicKeysMapperImpl : MLSPublicKeysMapper { } @Suppress("ClassNaming") -sealed class MLSPublicKeyType { - abstract val value: String? +sealed interface MLSPublicKeyType { + val value: String? data object ECDSA_SECP256R1_SHA256 : MLSPublicKeyType() { override val value: String = "ecdsa_secp256r1_sha256" From 1e4c9c6b36ab7edd609552febf0bfa67a867baf1 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Tue, 7 May 2024 11:19:27 +0200 Subject: [PATCH 25/26] address PR comments --- .../logic/data/mlspublickeys/MLSPublicKeysMapper.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt index 881a66e5774..48d840103c9 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysMapper.kt @@ -45,27 +45,27 @@ class MLSPublicKeysMapperImpl : MLSPublicKeysMapper { sealed interface MLSPublicKeyType { val value: String? - data object ECDSA_SECP256R1_SHA256 : MLSPublicKeyType() { + data object ECDSA_SECP256R1_SHA256 : MLSPublicKeyType { override val value: String = "ecdsa_secp256r1_sha256" } - data object ECDSA_SECP384R1_SHA384 : MLSPublicKeyType() { + data object ECDSA_SECP384R1_SHA384 : MLSPublicKeyType { override val value: String = "ecdsa_secp384r1_sha384" } - data object ECDSA_SECP521R1_SHA512 : MLSPublicKeyType() { + data object ECDSA_SECP521R1_SHA512 : MLSPublicKeyType { override val value: String = "ecdsa_secp521r1_sha512" } - data object ED448 : MLSPublicKeyType() { + data object ED448 : MLSPublicKeyType { override val value: String = "ed448" } - data object ED25519 : MLSPublicKeyType() { + data object ED25519 : MLSPublicKeyType { override val value: String = "ed25519" } - data class Unknown(override val value: String?) : MLSPublicKeyType() + data class Unknown(override val value: String?) : MLSPublicKeyType companion object { fun from(value: String) = when (value) { From 8094880e701f1134bf5e59ab96d33b6eb21b51f1 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Tue, 7 May 2024 11:40:48 +0200 Subject: [PATCH 26/26] clean up logs --- .../kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt | 2 +- .../logic/data/mlspublickeys/MLSPublicKeysRepository.kt | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt index 96e7528634b..16fd35d87d6 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt @@ -110,7 +110,7 @@ class MLSClientImpl( groupId: MLSGroupId, externalSenders: ByteArray ) { - kaliumLogger.d("createConversation: $defaultCipherSuite") + kaliumLogger.d("createConversation: using defaultCipherSuite=$defaultCipherSuite") val conf = ConversationConfiguration( defaultCipherSuite, listOf(externalSenders), diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt index ecb9a6099be..48709255f9b 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspublickeys/MLSPublicKeysRepository.kt @@ -26,7 +26,6 @@ import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.flatMap import com.wire.kalium.logic.functional.map import com.wire.kalium.logic.functional.right -import com.wire.kalium.logic.kaliumLogger import com.wire.kalium.logic.wrapApiRequest import com.wire.kalium.network.api.base.authenticated.serverpublickey.MLSPublicKeyApi import io.ktor.util.decodeBase64Bytes @@ -63,15 +62,10 @@ class MLSPublicKeysRepositoryImpl( override suspend fun getKeyForCipherSuite(cipherSuite: CipherSuite): Either { return getKeys().flatMap { serverPublicKeys -> - kaliumLogger.d("serverPublicKeys: $serverPublicKeys") val keySignature = mlsPublicKeysMapper.fromCipherSuite(cipherSuite) - kaliumLogger.d("keySignature: $keySignature") - val key = serverPublicKeys.removal?.let { removalKeys -> removalKeys[keySignature.value] } ?: return Either.Left(MLSFailure.Generic(IllegalStateException("No key found for cipher suite $cipherSuite"))) - - kaliumLogger.d("key: $key") key.decodeBase64Bytes().right() } }