Skip to content

Commit 94490f8

Browse files
chore: Update CoreCrypto library to v8 #WPB-19225 (#154)
* Update library to v8.0.1 * Make adjustments on newly received typed params * Make use of extension functions or ByteArray and String to GroupId GroupInfo * Adjust tests
1 parent 544db0a commit 94490f8

File tree

13 files changed

+64
-45
lines changed

13 files changed

+64
-45
lines changed

lib/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ dependencies {
5959
implementation("io.ktor:ktor-client-websockets:$ktorVersion")
6060
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
6161
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1-0.6.x-compat")
62-
implementation("com.wire:core-crypto-jvm:7.0.2")
63-
implementation("com.wire:core-crypto-uniffi-jvm:7.0.2")
62+
implementation("com.wire:core-crypto-jvm:8.0.1")
63+
implementation("com.wire:core-crypto-uniffi-jvm:8.0.1")
6464
implementation("app.cash.sqldelight:sqlite-driver:2.1.0")
6565
implementation("app.cash.sqldelight:sqlite-3-24-dialect:2.1.0")
6666
implementation("org.zalando:logbook-core:3.12.2")

lib/src/main/kotlin/com/wire/integrations/jvm/config/Modules.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ internal suspend fun getOrInitCryptoClient(
227227

228228
backendClient.uploadMlsKeyPackages(
229229
appClientId = appClientId,
230-
mlsKeyPackages = cryptoClient.mlsGenerateKeyPackages().map { it.value }
230+
mlsKeyPackages = cryptoClient.mlsGenerateKeyPackages().map { it.value.copyBytes() }
231231
)
232232
}
233233

lib/src/main/kotlin/com/wire/integrations/jvm/crypto/CoreCryptoClient.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ package com.wire.integrations.jvm.crypto
22

33
import com.wire.crypto.Ciphersuite
44
import com.wire.crypto.Ciphersuites
5-
import com.wire.crypto.ClientId
65
import com.wire.crypto.CoreCrypto
76
import com.wire.crypto.DatabaseKey
87
import com.wire.crypto.GroupInfo
98
import com.wire.crypto.MLSGroupId
109
import com.wire.crypto.MLSKeyPackage
11-
import com.wire.crypto.MlsMessage
1210
import com.wire.crypto.MlsTransport
13-
import com.wire.crypto.PlaintextMessage
1411
import com.wire.crypto.Welcome
12+
import com.wire.crypto.toClientId
1513
import com.wire.integrations.jvm.config.IsolatedKoinContext
1614
import com.wire.integrations.jvm.crypto.CryptoClient.Companion.DEFAULT_KEYPACKAGE_COUNT
1715
import com.wire.integrations.jvm.exception.WireException
@@ -47,10 +45,10 @@ internal class CoreCryptoClient private constructor(
4745
coreCrypto.transaction {
4846
it.encryptMessage(
4947
mlsGroupId,
50-
PlaintextMessage(value = message)
48+
message
5149
)
5250
}
53-
return encryptedMessage.value
51+
return encryptedMessage
5452
}
5553

5654
override suspend fun decryptMls(
@@ -62,7 +60,7 @@ internal class CoreCryptoClient private constructor(
6260
coreCrypto.transaction {
6361
it.decryptMessage(
6462
id = mlsGroupId,
65-
message = MlsMessage(encryptedMessageBytes)
63+
message = encryptedMessageBytes
6664
)
6765
}
6866
return decryptedMessage.message
@@ -94,7 +92,7 @@ internal class CoreCryptoClient private constructor(
9492
) {
9593
coreCrypto.transaction {
9694
it.mlsInit(
97-
ClientId(appClientId.value),
95+
appClientId.value.toClientId(),
9896
Ciphersuites(setOf(ciphersuite))
9997
)
10098
}
@@ -107,7 +105,7 @@ internal class CoreCryptoClient private constructor(
107105
override suspend fun mlsGetPublicKey(): MlsPublicKeys {
108106
val key =
109107
coreCrypto.transaction {
110-
it.getPublicKey(ciphersuite = ciphersuite).value
108+
it.getPublicKey(ciphersuite = ciphersuite)
111109
}
112110
val encodedKey = Base64.getEncoder().encodeToString(key)
113111
return when (ciphersuite) {

lib/src/main/kotlin/com/wire/integrations/jvm/crypto/MlsTransportImpl.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package com.wire.integrations.jvm.crypto
1818

1919
import com.wire.crypto.CommitBundle
20+
import com.wire.crypto.HistorySecret
2021
import com.wire.crypto.MlsTransport
22+
import com.wire.crypto.MlsTransportData
2123
import com.wire.crypto.MlsTransportResponse
2224
import com.wire.integrations.jvm.client.BackendClient
2325

@@ -45,8 +47,12 @@ internal class MlsTransportImpl(private val backendClient: BackendClient) : MlsT
4547
* @param bundle the CommitBundle to parse
4648
*/
4749
private fun parseBundleIntoSingleByteArray(bundle: CommitBundle): ByteArray {
48-
return bundle.commit.value +
49-
bundle.groupInfoBundle.payload.value +
50-
(bundle.welcome?.value ?: ByteArray(0))
50+
return bundle.commit +
51+
bundle.groupInfoBundle.payload.copyBytes() +
52+
(bundle.welcome?.copyBytes() ?: ByteArray(0))
53+
}
54+
55+
override suspend fun prepareForTransport(historySecret: HistorySecret): MlsTransportData {
56+
TODO("Not yet implemented")
5157
}
5258
}

lib/src/main/kotlin/com/wire/integrations/jvm/persistence/ConversationSqlLiteStorage.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
package com.wire.integrations.jvm.persistence
1717

18-
import com.wire.crypto.MLSGroupId
18+
import com.wire.crypto.toGroupId
1919
import com.wire.integrations.jvm.AppsSdkDatabase
2020
import com.wire.integrations.jvm.Conversation
2121
import com.wire.integrations.jvm.ConversationMemberQueries
@@ -38,7 +38,8 @@ internal class ConversationSqlLiteStorage(db: AppsSdkDatabase) : ConversationSto
3838
id = conversation.id.id.toString(),
3939
domain = conversation.id.domain,
4040
name = conversation.name,
41-
mls_group_id = Base64.getEncoder().encodeToString(conversation.mlsGroupId.value),
41+
mls_group_id =
42+
Base64.getEncoder().encodeToString(conversation.mlsGroupId.copyBytes()),
4243
team_id = conversation.teamId?.value?.toString(),
4344
type = conversation.type.name
4445
)
@@ -114,7 +115,7 @@ internal class ConversationSqlLiteStorage(db: AppsSdkDatabase) : ConversationSto
114115
id = QualifiedId(UUID.fromString(conv.id), conv.domain),
115116
name = conv.name,
116117
teamId = conv.team_id?.let { TeamId(UUID.fromString(it)) },
117-
mlsGroupId = MLSGroupId(Base64.getDecoder().decode(conv.mls_group_id)),
118+
mlsGroupId = Base64.getDecoder().decode(conv.mls_group_id).toGroupId(),
118119
type = ConversationData.Type.fromString(value = conv.type)
119120
)
120121

lib/src/main/kotlin/com/wire/integrations/jvm/service/EventsRouter.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
package com.wire.integrations.jvm.service
1818

1919
import com.wire.crypto.CoreCryptoException
20-
import com.wire.crypto.GroupInfo
2120
import com.wire.crypto.MLSGroupId
2221
import com.wire.crypto.MlsException
2322
import com.wire.crypto.Welcome
23+
import com.wire.crypto.toGroupInfo
24+
import com.wire.crypto.toWelcome
25+
import com.wire.crypto.uniffi.ConversationId
2426
import com.wire.integrations.jvm.WireEventsHandler
2527
import com.wire.integrations.jvm.WireEventsHandlerDefault
2628
import com.wire.integrations.jvm.WireEventsHandlerSuspending
@@ -125,7 +127,7 @@ internal class EventsRouter internal constructor(
125127

126128
is EventContentDTO.Conversation.MlsWelcome -> {
127129
logger.info("Joining MLS conversation: ${event.qualifiedConversation}")
128-
val welcome = Welcome(Base64.getDecoder().decode(event.data))
130+
val welcome = Base64.getDecoder().decode(event.data).toWelcome()
129131
val groupId = fetchGroupIdFromWelcome(
130132
cryptoClient = cryptoClient,
131133
welcome = welcome,
@@ -188,7 +190,9 @@ internal class EventsRouter internal constructor(
188190
groupId: MLSGroupId?
189191
): MLSGroupId {
190192
val conversation = backendClient.getConversation(qualifiedConversation)
191-
val mlsGroupId = groupId ?: MLSGroupId(Base64.getDecoder().decode(conversation.groupId))
193+
val mlsGroupId = groupId ?: MLSGroupId(
194+
ConversationId(Base64.getDecoder().decode(conversation.groupId))
195+
)
192196

193197
val conversationName = if (conversation.type == ConversationResponse.Type.ONE_TO_ONE) {
194198
backendClient.getUserData(userId = conversation.members.others.first().id).name
@@ -221,7 +225,8 @@ internal class EventsRouter internal constructor(
221225
cryptoClient.getAppClientId()?.let { appClientId ->
222226
backendClient.uploadMlsKeyPackages(
223227
appClientId = appClientId,
224-
mlsKeyPackages = cryptoClient.mlsGenerateKeyPackages().map { it.value }
228+
mlsKeyPackages =
229+
cryptoClient.mlsGenerateKeyPackages().map { it.value.copyBytes() }
225230
)
226231
}
227232
}
@@ -319,7 +324,7 @@ internal class EventsRouter internal constructor(
319324
logger.info("Cannot process welcome, ask to join the conversation")
320325
val groupInfo =
321326
backendClient.getConversationGroupInfo(event.qualifiedConversation)
322-
cryptoClient.joinMlsConversationRequest(GroupInfo(groupInfo))
327+
cryptoClient.joinMlsConversationRequest(groupInfo.toGroupInfo())
323328
} else {
324329
logger.error("Cannot process welcome -- ${ex.exception}", ex)
325330
throw WireException.CryptographicSystemError("Cannot process welcome")

lib/src/main/kotlin/com/wire/integrations/jvm/service/MlsFallbackStrategy.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.wire.integrations.jvm.service
1818

19-
import com.wire.crypto.GroupInfo
2019
import com.wire.crypto.MLSGroupId
20+
import com.wire.crypto.toGroupInfo
2121
import com.wire.integrations.jvm.client.BackendClient
2222
import com.wire.integrations.jvm.crypto.CryptoClient
2323
import com.wire.integrations.jvm.model.QualifiedId
@@ -58,7 +58,7 @@ class MlsFallbackStrategy internal constructor(
5858
conversationId = conversationId
5959
)
6060
cryptoClient.joinMlsConversationRequest(
61-
groupInfo = GroupInfo(value = groupInfo)
61+
groupInfo = groupInfo.toGroupInfo()
6262
)
6363
}
6464
}

lib/src/test/kotlin/com/wire/integrations/jvm/crypto/CoreCryptoClientTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.wire.integrations.jvm.crypto
22

33
import com.wire.crypto.CoreCryptoException
4-
import com.wire.crypto.GroupInfo
54
import com.wire.crypto.MLSGroupId
65
import com.wire.crypto.MLSKeyPackage
76
import com.wire.crypto.MlsException
87
import com.wire.crypto.toGroupId
8+
import com.wire.crypto.toGroupInfo
99
import com.wire.integrations.jvm.config.IsolatedKoinContext
1010
import com.wire.integrations.jvm.model.AppClientId
1111
import com.wire.integrations.jvm.model.QualifiedId
@@ -79,7 +79,7 @@ class CoreCryptoClientTest {
7979
runBlocking {
8080
// GroupInfo of a real conversation, stored in a binary test file
8181
val inputStream: InputStream = FileInputStream("src/test/resources/groupInfo.bin")
82-
val groupInfo = GroupInfo(inputStream.readAllBytes())
82+
val groupInfo = inputStream.readAllBytes().toGroupInfo()
8383

8484
// Create a new client and join the conversation
8585
val userId = UUID.randomUUID().toString()

lib/src/test/kotlin/com/wire/integrations/jvm/service/MlsFallbackStrategyTest.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.wire.integrations.jvm.service
1818

19-
import com.wire.crypto.GroupInfo
20-
import com.wire.crypto.MLSGroupId
19+
import com.wire.crypto.toGroupId
20+
import com.wire.crypto.toGroupInfo
2121
import com.wire.integrations.jvm.client.BackendClientDemo
2222
import com.wire.integrations.jvm.crypto.CryptoClient
2323
import com.wire.integrations.jvm.model.QualifiedId
@@ -39,7 +39,7 @@ class MlsFallbackStrategyTest {
3939
coEvery { conversationExists(mlsGroupId = MLS_GROUP_ID) } returns false
4040
coEvery { conversationEpoch(mlsGroupId = MLS_GROUP_ID) } returns 0UL
4141
coEvery {
42-
joinMlsConversationRequest(groupInfo = GroupInfo(MLS_GROUP_ID.value))
42+
joinMlsConversationRequest(groupInfo = any())
4343
} returns MLS_GROUP_ID
4444
}
4545

@@ -49,7 +49,7 @@ class MlsFallbackStrategyTest {
4949
} returns CONVERSATION_RESPONSE
5050
coEvery {
5151
getConversationGroupInfo(conversationId = CONVERSATION_ID)
52-
} returns MLS_GROUP_ID.value
52+
} returns MLS_GROUP_ID.copyBytes()
5353
}
5454

5555
val fallbackStrategy = MlsFallbackStrategy(
@@ -64,7 +64,7 @@ class MlsFallbackStrategyTest {
6464

6565
coVerify(exactly = 1) {
6666
cryptoClient.joinMlsConversationRequest(
67-
groupInfo = GroupInfo(value = MLS_GROUP_ID.value)
67+
groupInfo = any()
6868
)
6969
}
7070
}
@@ -76,7 +76,7 @@ class MlsFallbackStrategyTest {
7676
coEvery { conversationExists(mlsGroupId = MLS_GROUP_ID) } returns true
7777
coEvery { conversationEpoch(mlsGroupId = MLS_GROUP_ID) } returns 1UL
7878
coEvery {
79-
joinMlsConversationRequest(groupInfo = GroupInfo(MLS_GROUP_ID.value))
79+
joinMlsConversationRequest(groupInfo = any())
8080
} returns MLS_GROUP_ID
8181
}
8282

@@ -86,7 +86,7 @@ class MlsFallbackStrategyTest {
8686
} returns CONVERSATION_RESPONSE.copy(epoch = 2L)
8787
coEvery {
8888
getConversationGroupInfo(conversationId = CONVERSATION_ID)
89-
} returns MLS_GROUP_ID.value
89+
} returns MLS_GROUP_ID.copyBytes()
9090
}
9191

9292
val fallbackStrategy = MlsFallbackStrategy(
@@ -101,7 +101,7 @@ class MlsFallbackStrategyTest {
101101

102102
coVerify(exactly = 1) {
103103
cryptoClient.joinMlsConversationRequest(
104-
groupInfo = GroupInfo(value = MLS_GROUP_ID.value)
104+
groupInfo = any()
105105
)
106106
}
107107
}
@@ -113,7 +113,7 @@ class MlsFallbackStrategyTest {
113113
coEvery { conversationExists(mlsGroupId = MLS_GROUP_ID) } returns true
114114
coEvery { conversationEpoch(mlsGroupId = MLS_GROUP_ID) } returns 1UL
115115
coEvery {
116-
joinMlsConversationRequest(groupInfo = GroupInfo(MLS_GROUP_ID.value))
116+
joinMlsConversationRequest(groupInfo = MLS_GROUP_ID.copyBytes().toGroupInfo())
117117
} returns MLS_GROUP_ID
118118
}
119119

@@ -123,7 +123,7 @@ class MlsFallbackStrategyTest {
123123
} returns CONVERSATION_RESPONSE.copy(epoch = 1L)
124124
coEvery {
125125
getConversationGroupInfo(conversationId = CONVERSATION_ID)
126-
} returns MLS_GROUP_ID.value
126+
} returns MLS_GROUP_ID.copyBytes()
127127
}
128128

129129
val fallbackStrategy = MlsFallbackStrategy(
@@ -138,7 +138,7 @@ class MlsFallbackStrategyTest {
138138

139139
coVerify(exactly = 0) {
140140
cryptoClient.joinMlsConversationRequest(
141-
groupInfo = GroupInfo(value = MLS_GROUP_ID.value)
141+
groupInfo = MLS_GROUP_ID.copyBytes().toGroupInfo()
142142
)
143143
backendClient.getConversationGroupInfo(
144144
conversationId = CONVERSATION_ID
@@ -153,7 +153,7 @@ class MlsFallbackStrategyTest {
153153
domain = "wire.com"
154154
)
155155
private val TEAM_ID = TeamId(UUID.randomUUID())
156-
private val MLS_GROUP_ID = MLSGroupId(ByteArray(32) { 1 })
156+
private val MLS_GROUP_ID = ByteArray(32) { 1 }.toGroupId()
157157
private val CONVERSATION_RESPONSE = ConversationResponse(
158158
id = CONVERSATION_ID,
159159
teamId = TEAM_ID.value,

lib/src/test/kotlin/com/wire/integrations/jvm/service/WireEventsIntegrationTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import java.util.UUID
4848
import kotlin.test.assertEquals
4949
import kotlin.test.assertNull
5050
import kotlin.test.assertTrue
51-
import com.wire.integrations.jvm.utils.MockCoreCryptoClient.Companion.MLS_GROUP_ID
51+
import com.wire.integrations.jvm.utils.MockCoreCryptoClient.Companion.MLS_GROUP_ID_BASE64
5252
import com.wire.integrations.jvm.utils.MockCoreCryptoClient.Companion.GENERIC_TEXT_MESSAGE
5353
import kotlinx.coroutines.test.runTest
5454

@@ -369,7 +369,7 @@ class WireEventsIntegrationTest {
369369
}
370370
]
371371
},
372-
"group_id": "${Base64.getEncoder().encodeToString(MLS_GROUP_ID.value)}",
372+
"group_id": "$MLS_GROUP_ID_BASE64",
373373
"team": "${TEAM_ID.value}",
374374
"type": 0
375375
}
@@ -394,7 +394,7 @@ class WireEventsIntegrationTest {
394394
}
395395
]
396396
},
397-
"group_id": "${Base64.getEncoder().encodeToString(MLS_GROUP_ID.value)}",
397+
"group_id": "$MLS_GROUP_ID_BASE64",
398398
"team": "${TEAM_ID.value}",
399399
"type": 0
400400
}
@@ -444,7 +444,7 @@ class WireEventsIntegrationTest {
444444
}
445445
]
446446
},
447-
"group_id": "${Base64.getEncoder().encodeToString(MLS_GROUP_ID.value)}",
447+
"group_id": "$MLS_GROUP_ID_BASE64",
448448
"team": "${TEAM_ID.value}"
449449
}
450450
""".trimIndent()

0 commit comments

Comments
 (0)