diff --git a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/E2EIClientImpl.kt b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/E2EIClientImpl.kt index fc3ceb4d69b..0d9714a8bc6 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/E2EIClientImpl.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/E2EIClientImpl.kt @@ -51,7 +51,7 @@ class E2EIClientImpl( toNewAcmeAuthz(wireE2eIdentity.newAuthzResponse(toUByteList(authz))) override fun createDpopToken(backendNonce: String) = - TODO("Not implemented") + wireE2eIdentity.createDpopToken(expirySecs = defaultDPoPTokenExpiry, backendNonce) override fun getNewDpopChallengeRequest(accessToken: String, previousNonce: String) = toByteArray(wireE2eIdentity.newDpopChallengeRequest(accessToken, previousNonce)) @@ -66,13 +66,13 @@ class E2EIClientImpl( toByteArray(wireE2eIdentity.checkOrderRequest(orderUrl, previousNonce)) override fun checkOrderResponse(order: JsonRawData) = - TODO("Not implemented") + wireE2eIdentity.checkOrderResponse(toUByteList(order)) override fun finalizeRequest(previousNonce: String) = toByteArray(wireE2eIdentity.finalizeRequest(previousNonce)) override fun finalizeResponse(finalize: JsonRawData) = - TODO("Not implemented") + wireE2eIdentity.finalizeResponse(toUByteList(finalize)) override fun certificateRequest(previousNonce: String) = toByteArray(wireE2eIdentity.certificateRequest(previousNonce)) 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 3a00f9dba95..0d35bc2f55f 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt @@ -27,9 +27,11 @@ import com.wire.crypto.CoreCryptoCallbacks import com.wire.crypto.CustomConfiguration import com.wire.crypto.DecryptedMessage import com.wire.crypto.Invitee -import com.wire.crypto.MlsPublicGroupStateEncryptionType +import com.wire.crypto.MlsCredentialType +import com.wire.crypto.MlsGroupInfoEncryptionType import com.wire.crypto.MlsRatchetTreeType import com.wire.crypto.MlsWirePolicy +import com.wire.crypto.client.CoreCryptoCentral.Companion.lower import io.ktor.util.decodeBase64Bytes import io.ktor.util.encodeBase64 import java.io.File @@ -86,11 +88,12 @@ actual class MLSClientImpl actual constructor( private val coreCrypto: CoreCrypto private val keyRotationDuration: Duration = 30.toDuration(DurationUnit.DAYS) private val defaultGroupConfiguration = CustomConfiguration(keyRotationDuration.toJavaDuration(), MlsWirePolicy.PLAINTEXT) + private val defaultCiphersuite = CiphersuiteName.MLS_128_DHKEMX25519_AES128GCM_SHA256_ED25519.lower() private val defaultE2EIExpiry: UInt = 90U -// private val defaultMLSCredentialType: MlsCredentialType = MlsCredentialType.BASIC + private val defaultMLSCredentialType: MlsCredentialType = MlsCredentialType.BASIC init { - coreCrypto = CoreCrypto(rootDir, databaseKey.value, toUByteList(clientId.toString()), null) + coreCrypto = CoreCrypto(rootDir, databaseKey.value, toUByteList(clientId.toString()), listOf(defaultCiphersuite)) coreCrypto.setCallbacks(Callbacks()) } @@ -99,16 +102,16 @@ actual class MLSClientImpl actual constructor( } override fun getPublicKey(): ByteArray { - return coreCrypto.clientPublicKey().toUByteArray().asByteArray() + return coreCrypto.clientPublicKey(defaultCiphersuite).toUByteArray().asByteArray() } override fun generateKeyPackages(amount: Int): List { - return coreCrypto.clientKeypackages(amount.toUInt()) + return coreCrypto.clientKeypackages(defaultCiphersuite, defaultMLSCredentialType, amount.toUInt()) .map { it.toUByteArray().asByteArray() } } override fun validKeyPackageCount(): ULong { - return coreCrypto.clientValidKeypackagesCount() + return coreCrypto.clientValidKeypackagesCount(defaultCiphersuite, defaultMLSCredentialType) } override fun updateKeyingMaterial(groupId: MLSGroupId): CommitBundle { @@ -127,7 +130,9 @@ actual class MLSClientImpl actual constructor( return toByteArray( coreCrypto.newExternalAddProposal( conversationId = toUByteList(groupId.decodeBase64Bytes()), - epoch = epoch + epoch = epoch, + ciphersuite = defaultCiphersuite, + credentialType = MlsCredentialType.BASIC ) ) } @@ -135,8 +140,9 @@ actual class MLSClientImpl actual constructor( override fun joinByExternalCommit(publicGroupState: ByteArray): CommitBundle { return toCommitBundle(coreCrypto.joinByExternalCommit( toUByteList(publicGroupState), - defaultGroupConfiguration - )) + defaultGroupConfiguration, + MlsCredentialType.BASIC) + ) } override fun mergePendingGroupFromExternalCommit(groupId: MLSGroupId) { @@ -153,13 +159,13 @@ actual class MLSClientImpl actual constructor( externalSenders: List ) { val conf = ConversationConfiguration( - CiphersuiteName.MLS_128_DHKEMX25519_AES128GCM_SHA256_ED25519, + defaultCiphersuite, externalSenders.map { toUByteList(it.value) }, defaultGroupConfiguration ) val groupIdAsBytes = toUByteList(groupId.decodeBase64Bytes()) - coreCrypto.createConversation(groupIdAsBytes, conf) + coreCrypto.createConversation(groupIdAsBytes, MlsCredentialType.BASIC, conf) } override fun wipeConversation(groupId: MLSGroupId) { @@ -240,25 +246,47 @@ actual class MLSClientImpl actual constructor( } override fun newAcmeEnrollment(clientId: E2EIQualifiedClientId, displayName: String, handle: String): E2EIClient { - TODO("not implemented") + return E2EIClientImpl( + coreCrypto.e2eiNewEnrollment( + clientId.toString(), + displayName, + handle, + defaultE2EIExpiry, + defaultCiphersuite + ) + ) } override fun e2eiNewActivationEnrollment( displayName: String, handle: String ): E2EIClient { - TODO("not implemented") + return E2EIClientImpl( + coreCrypto.e2eiNewActivationEnrollment( + displayName, + handle, + defaultE2EIExpiry, + defaultCiphersuite + ) + ) } override fun e2eiNewRotateEnrollment( displayName: String?, handle: String? ): E2EIClient { - TODO("not implemented") + return E2EIClientImpl( + coreCrypto.e2eiNewRotateEnrollment( + displayName, + handle, + defaultE2EIExpiry, + defaultCiphersuite + ) + ) } override fun e2eiMlsInitOnly(enrollment: E2EIClient, certificateChain: CertificateChain) { - TODO("not implemented") + coreCrypto.e2eiMlsInitOnly((enrollment as E2EIClientImpl).wireE2eIdentity, certificateChain) } override fun e2eiRotateAll( @@ -266,11 +294,15 @@ actual class MLSClientImpl actual constructor( certificateChain: CertificateChain, newMLSKeyPackageCount: UInt ) { - TODO("not implemented") + coreCrypto.e2eiRotateAll( + (enrollment as E2EIClientImpl).wireE2eIdentity, + certificateChain, + newMLSKeyPackageCount + ) } override fun isGroupVerified(groupId: MLSGroupId): Boolean = - TODO("not implemented") + !coreCrypto.e2eiIsDegraded(toUByteList(groupId.decodeBase64Bytes())) companion object { fun toUByteList(value: ByteArray): List = value.asUByteArray().asList() @@ -280,30 +312,30 @@ actual class MLSClientImpl actual constructor( fun toCommitBundle(value: com.wire.crypto.MemberAddedMessages) = CommitBundle( toByteArray(value.commit), toByteArray(value.welcome), - toGroupInfoBundle(value.publicGroupState) + toGroupInfoBundle(value.groupInfo) ) fun toCommitBundle(value: com.wire.crypto.CommitBundle) = CommitBundle( toByteArray(value.commit), value.welcome?.let { toByteArray(it) }, - toGroupInfoBundle(value.publicGroupState) + toGroupInfoBundle(value.groupInfo) ) fun toCommitBundle(value: com.wire.crypto.ConversationInitBundle) = CommitBundle( toByteArray(value.commit), null, - toGroupInfoBundle(value.publicGroupState) + toGroupInfoBundle(value.groupInfo) ) - fun toGroupInfoBundle(value: com.wire.crypto.PublicGroupStateBundle) = GroupInfoBundle( + fun toGroupInfoBundle(value: com.wire.crypto.GroupInfoBundle) = GroupInfoBundle( toEncryptionType(value.encryptionType), toRatchetTreeType(value.ratchetTreeType), toByteArray(value.payload) ) - fun toEncryptionType(value: MlsPublicGroupStateEncryptionType) = when (value) { - MlsPublicGroupStateEncryptionType.PLAINTEXT -> GroupInfoEncryptionType.PLAINTEXT - MlsPublicGroupStateEncryptionType.JWE_ENCRYPTED -> GroupInfoEncryptionType.JWE_ENCRYPTED + fun toEncryptionType(value: MlsGroupInfoEncryptionType) = when (value) { + MlsGroupInfoEncryptionType.PLAINTEXT -> GroupInfoEncryptionType.PLAINTEXT + MlsGroupInfoEncryptionType.JWE_ENCRYPTED -> GroupInfoEncryptionType.JWE_ENCRYPTED } fun toRatchetTreeType(value: MlsRatchetTreeType) = when (value) { diff --git a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt index 511d3b6f1e0..c3502bcc819 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt @@ -18,8 +18,10 @@ package com.wire.kalium.cryptography +import com.wire.crypto.CiphersuiteName import com.wire.crypto.CoreCrypto import com.wire.crypto.CryptoException +import com.wire.crypto.client.CoreCryptoCentral.Companion.lower import com.wire.kalium.cryptography.exceptions.ProteusException import io.ktor.util.decodeBase64Bytes import io.ktor.util.encodeBase64 @@ -32,6 +34,7 @@ class ProteusClientCoreCryptoImpl internal constructor( private val databaseKey: ProteusDBSecret ) : ProteusClient { + private val defaultCiphersuite = CiphersuiteName.MLS_128_DHKEMX25519_AES128GCM_SHA256_ED25519.lower() private val path: String = "$rootDir/$KEYSTORE_NAME" private lateinit var coreCrypto: CoreCrypto @@ -52,7 +55,7 @@ class ProteusClientCoreCryptoImpl internal constructor( coreCrypto = CoreCrypto.deferredInit( path, databaseKey.value, - null + listOf(defaultCiphersuite) ) migrateFromCryptoBoxIfNecessary(coreCrypto) coreCrypto.proteusInit() @@ -67,7 +70,7 @@ class ProteusClientCoreCryptoImpl internal constructor( coreCrypto = CoreCrypto.deferredInit( path, databaseKey.value, - null + listOf(defaultCiphersuite) ) migrateFromCryptoBoxIfNecessary(coreCrypto) coreCrypto.proteusInit() 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 d6815de6c8d..c03fd692386 100644 --- a/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/E2EIClientTest.kt +++ b/cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/E2EIClientTest.kt @@ -24,8 +24,6 @@ import kotlin.test.assertTrue @IgnoreJS @IgnoreIOS -@IgnoreJvm -@IgnoreAndroidInstrumented class E2EIClientTest : BaseMLSClientTest() { data class SampleUser( val id: CryptoQualifiedID, val clientId: CryptoClientId, val name: String, val handle: String diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d9bbb726906..b77781860da 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.2.22" jna = "5.6.0" -core-crypto = "0.8.2" +core-crypto = "1.0.0-pre.6+v1-schemafix-002" core-crypto-multiplatform = "0.6.0-rc.3-multiplatform-pre1" completeKotlin = "1.1.0" desugar-jdk = "1.1.5"