Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set the correct external sender key when creating MLS conversation #2735

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d50e325
feat: set the correct external sender key when creating MLS conversation
MohamadJaara May 2, 2024
dc30b82
cleanup
MohamadJaara May 2, 2024
519b00e
fix ios and js target
MohamadJaara May 2, 2024
b823681
mls client test
MohamadJaara May 2, 2024
a5049f2
print generic MLS errors
MohamadJaara May 2, 2024
de14bfa
fix: fetch mls feature config from remote
MohamadJaara May 2, 2024
38819c6
chore: cc to rc.59
MohamadJaara May 2, 2024
011eb1b
feat: fetch mls config form remote when missing
MohamadJaara May 3, 2024
bbd2206
Merge branch 'release/android-cycle-4.6' into chore/update-CC-to-RC-59
MohamadJaara May 3, 2024
3e129cb
Merge branch 'refs/heads/fix/fetch-MLS-config-when-not-avilable-local…
MohamadJaara May 3, 2024
6d1857f
revert CC version to 56-hotfix1
MohamadJaara May 3, 2024
c6f6f7f
detekt
MohamadJaara May 3, 2024
7811a02
cleanup
MohamadJaara May 3, 2024
43c4205
address PR comment
MohamadJaara May 3, 2024
9a2c0fc
cleanup
MohamadJaara May 3, 2024
fe8cf4f
fix test
MohamadJaara May 6, 2024
ec0a547
Merge branch 'release/android-cycle-4.6' into chore/update-CC-to-RC-59
MohamadJaara May 6, 2024
a50a929
use CC vrc.56.hotfix.2
MohamadJaara May 6, 2024
0734891
Merge branch 'refs/heads/chore/update-CC-to-RC-59' into fix/fetch-MLS…
MohamadJaara May 6, 2024
32d5c4f
Merge branch 'refs/heads/release/android-cycle-4.6' into fix/fetch-ML…
MohamadJaara May 6, 2024
e165154
fix merge issue
MohamadJaara May 6, 2024
8b34620
fix merge issue
MohamadJaara May 6, 2024
d751ced
Trigger CI
MohamadJaara May 6, 2024
3e80a5c
fix test
MohamadJaara May 6, 2024
7514e20
fix test
MohamadJaara May 6, 2024
67c7272
Merge branch 'refs/heads/fix/fetch-MLS-config-when-not-avilable-local…
MohamadJaara May 6, 2024
b869ef3
fix test
MohamadJaara May 6, 2024
da602d1
fix test
MohamadJaara May 6, 2024
f1e3862
Merge branch 'refs/heads/fix/fetch-MLS-config-when-not-avilable-local…
MohamadJaara May 6, 2024
c6feb00
detekt
MohamadJaara May 6, 2024
f43874a
Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/mlspubl…
MohamadJaara May 7, 2024
e841329
Merge remote-tracking branch 'refs/remotes/origin/release/android-cyc…
MohamadJaara May 7, 2024
1e4c9c6
address PR comments
MohamadJaara May 7, 2024
8094880
clean up logs
MohamadJaara May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -97,11 +100,11 @@ class MLSClientImpl(

override suspend fun createConversation(
groupId: MLSGroupId,
externalSenders: List<Ed22519Key>
externalSenders: ByteArray
) {
val conf = ConversationConfiguration(
CiphersuiteName.MLS_128_DHKEMX25519_AES128GCM_SHA256_ED25519,
externalSenders.map { toUByteList(it.value) },
listOf(toUByteList(externalSenders)),
defaultGroupConfiguration
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<ClientId>,
Expand All @@ -61,7 +61,7 @@ private class Callbacks : CoreCryptoCallbacks {
return true
}

override fun userAuthorize(
override suspend fun userAuthorize(
conversationId: ConversationId,
externalClientId: ClientId,
existingClients: List<ClientId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -104,11 +108,12 @@ class MLSClientImpl(

override suspend fun createConversation(
groupId: MLSGroupId,
externalSenders: List<Ed22519Key>
externalSenders: ByteArray
) {
kaliumLogger.d("createConversation: $defaultCipherSuite")
val conf = ConversationConfiguration(
defaultCipherSuite,
externalSenders.map { it.value },
listOf(externalSenders),
defaultGroupConfiguration
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ data class DecryptedMessageBundle(
}
}

@JvmInline
value class Ed22519Key(
val value: ByteArray
)

@JvmInline
value class ExternalSenderKey(
val value: ByteArray
Expand All @@ -153,6 +148,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.
Expand Down Expand Up @@ -253,7 +253,7 @@ interface MLSClient {
*/
suspend fun createConversation(
groupId: MLSGroupId,
externalSenders: List<Ed22519Key> = emptyList()
externalSenders: ByteArray
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
}

Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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())
Expand All @@ -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)
Expand All @@ -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="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -66,7 +70,7 @@ class MLSClientImpl : MLSClient {
TODO("Not yet implemented")
}

override suspend fun createConversation(groupId: MLSGroupId, externalSenders: List<Ed22519Key>) {
override suspend fun createConversation(groupId: MLSGroupId, externalSenders: ByteArray) {
TODO("Not yet implemented")
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {

Expand All @@ -83,7 +87,11 @@ class MLSClientProviderImpl(

override suspend fun getMLSClient(clientId: ClientId?): Either<CoreFailure, MLSClient> = 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)
Expand Down Expand Up @@ -133,7 +141,14 @@ class MLSClientProviderImpl(
override suspend fun getCoreCrypto(clientId: ClientId?): Either<CoreFailure, CoreCryptoCentral> = coreCryptoCentralMutex.withLock {
withContext(dispatchers.io) {
val (supportedCipherSuite, defaultCipherSuite) = userConfigRepository.getSupportedCipherSuite()
.getOrElse { return@withContext Either.Left(it) }
.flatMapLeft<CoreFailure, SupportedCipherSuite> {
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 })

Expand Down
Loading
Loading