Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mchenani committed May 27, 2024
2 parents fe84a90 + 66a4fed commit efd89ce
Show file tree
Hide file tree
Showing 83 changed files with 1,507 additions and 712 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ actual open class BaseMLSClientTest {
allowedCipherSuites: List<UShort>,
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<UShort>,
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")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ actual open class BaseMLSClientTest {
allowedCipherSuites: List<UShort>,
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<UShort>,
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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import kotlin.time.Duration

actual suspend fun coreCryptoCentral(
rootDir: String,
databaseKey: String,
allowedCipherSuites: List<UShort>,
defaultCipherSuite: UShort?
databaseKey: String
): CoreCryptoCentral {
val path = "$rootDir/${CoreCryptoCentralImpl.KEYSTORE_NAME}"
NSFileManager.defaultManager.createDirectoryAtPath(rootDir, withIntermediateDirectories = true, null, null)
Expand Down Expand Up @@ -59,17 +57,25 @@ private class Callbacks : CoreCryptoCallbacks {
}
}

class CoreCryptoCentralImpl(private val cc: CoreCrypto, private val rootDir: String) : CoreCryptoCentral {
class CoreCryptoCentralImpl(
private val cc: CoreCrypto,
private val rootDir: String
) : CoreCryptoCentral {

override suspend fun mlsClient(clientId: CryptoQualifiedClientId): MLSClient {
override suspend fun mlsClient(
clientId: CryptoQualifiedClientId,
allowedCipherSuites: List<UShort>,
defaultCipherSuite: UShort
): MLSClient {
cc.mlsInit(MLSClientImpl.toUByteList(clientId.toString()))
return MLSClientImpl(cc)
return MLSClientImpl(cc, defaultCipherSuite = defaultCipherSuite)
}

override suspend fun mlsClient(
enrollment: E2EIClient,
certificateChain: CertificateChain,
newMLSKeyPackageCount: UInt
newMLSKeyPackageCount: UInt,
defaultCipherSuite: UShort
): MLSClient {
TODO("Not yet implemented")
}
Expand All @@ -83,7 +89,8 @@ class CoreCryptoCentralImpl(private val cc: CoreCrypto, private val rootDir: Str
displayName: String,
handle: String,
teamId: String?,
expiry: Duration
expiry: Duration,
defaultCipherSuite: UShort
): E2EIClient {
TODO("Not yet implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ import kotlin.time.toDuration
@Suppress("TooManyFunctions")
@OptIn(ExperimentalUnsignedTypes::class)
class MLSClientImpl(
private val coreCrypto: CoreCrypto
private val coreCrypto: CoreCrypto,
private val defaultCipherSuite: UShort
) : MLSClient {

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() {
}

override suspend fun getPublicKey(): ByteArray {
return coreCrypto.clientPublicKey().toUByteArray().asByteArray()
override suspend fun getPublicKey(): Pair<ByteArray, UShort> {
return coreCrypto.clientPublicKey().toUByteArray().asByteArray() to defaultCipherSuite
}

override suspend fun generateKeyPackages(amount: Int): List<ByteArray> {
Expand Down Expand Up @@ -96,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 @@ -29,17 +29,15 @@ actual open class BaseMLSClientTest actual constructor() {
allowedCipherSuites: List<UShort>,
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<UShort>,
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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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!!)
Expand All @@ -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()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.wire.kalium.cryptography

import com.wire.crypto.Ciphersuites
import com.wire.crypto.ClientId
import com.wire.crypto.CoreCrypto
import com.wire.crypto.CoreCryptoCallbacks
Expand All @@ -28,19 +27,20 @@ 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()
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,
rootDir = rootDir,
cipherSuite = allowedCipherSuites,
defaultCipherSuite = defaultCipherSuite
rootDir = rootDir
)
}

Expand Down Expand Up @@ -73,29 +73,35 @@ 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 {
cc.mlsInit(clientId.toString().encodeToByteArray(), cipherSuite, null)
return MLSClientImpl(cc, defaultCipherSuite!!)
override suspend fun mlsClient(
clientId: CryptoQualifiedClientId,
allowedCipherSuites: List<UShort>,
defaultCipherSuite: UShort
): MLSClient {
cc.mlsInit(
clientId.toString().encodeToByteArray(),
allowedCipherSuites,
nbKeyPackage = null
)
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 {
Expand All @@ -107,7 +113,8 @@ class CoreCryptoCentralImpl(
displayName: String,
handle: String,
teamId: String?,
expiry: kotlin.time.Duration
expiry: kotlin.time.Duration,
defaultCipherSuite: UShort
): E2EIClient {
return E2EIClientImpl(
cc.e2eiNewEnrollment(
Expand All @@ -116,7 +123,7 @@ class CoreCryptoCentralImpl(
handle,
teamId,
expiry.inWholeSeconds.toUInt(),
defaultCipherSuite!!
defaultCipherSuite
)

)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ 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()
}

override suspend fun getPublicKey(): ByteArray {
return coreCrypto.clientPublicKey(defaultCipherSuite, toCredentialType(getMLSCredentials()))
override suspend fun getPublicKey(): Pair<ByteArray, Ciphersuite> {
return coreCrypto.clientPublicKey(defaultCipherSuite, toCredentialType(getMLSCredentials())) to defaultCipherSuite
}

override suspend fun generateKeyPackages(amount: Int): List<ByteArray> {
Expand Down Expand Up @@ -104,11 +108,12 @@ class MLSClientImpl(

override suspend fun createConversation(
groupId: MLSGroupId,
externalSenders: List<Ed22519Key>
externalSenders: ByteArray
) {
kaliumLogger.d("createConversation: using defaultCipherSuite=$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 @@ -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<UShort>,
defaultCipherSuite: UShort
): MLSClient

suspend fun mlsClient(
enrollment: E2EIClient,
certificateChain: CertificateChain,
newMLSKeyPackageCount: UInt
newMLSKeyPackageCount: UInt,
defaultCipherSuite: UShort
): MLSClient

suspend fun proteusClient(): ProteusClient
Expand All @@ -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

/**
Expand All @@ -65,7 +72,5 @@ interface CoreCryptoCentral {

expect suspend fun coreCryptoCentral(
rootDir: String,
databaseKey: String,
allowedCipherSuites: List<UShort>,
defaultCipherSuite: UShort?
databaseKey: String
): CoreCryptoCentral
Loading

0 comments on commit efd89ce

Please sign in to comment.