Skip to content

Commit

Permalink
Merge branch 'release/candidate' into fix/pick-oneonone-migration-tar…
Browse files Browse the repository at this point in the history
…get-alphabetically-cherry-pick
  • Loading branch information
borichellow committed Sep 4, 2024
2 parents 2103c21 + b12a05b commit 943170b
Show file tree
Hide file tree
Showing 38 changed files with 7,028 additions and 204 deletions.
79 changes: 79 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,82 @@ moduleGraphConfig {
readmePath.set("./README.md")
heading.set("#### Dependency Graph")
}

tasks.register("runAllUnitTests") {
description = "Runs all Unit Tests."

rootProject.subprojects {
if (tasks.findByName("testDebugUnitTest") != null) {
println("Adding $name to runUnitTests")
dependsOn(":$name:testDebugUnitTest")
}
if (name != "cryptography") {
if (tasks.findByName("jvmTest") != null) {
println("Adding $name to jvmTest")
dependsOn(":$name:jvmTest")
}
}
}
}

tasks.register("aggregateTestResults") {
description = "Aggregates all Unit Test results into a single report."

doLast {
val testResultsDir = rootProject.layout.buildDirectory.dir("testResults").get().asFile
testResultsDir.deleteRecursively()
testResultsDir.mkdirs()

val indexHtmlFile = File(testResultsDir, "index.html")
indexHtmlFile.writeText(
"""
<html>
<head>
<title>Aggregated Test Reports</title>
</head>
<body>
<h1>Aggregated Test Reports</h1>
<ul>
""".trimIndent()
)

rootProject.subprojects {
val testResultsParentDir = layout.buildDirectory.dir("reports/tests").get().asFile

if (testResultsParentDir.exists()) {
testResultsParentDir.listFiles()?.forEach { testDir ->
if (testDir.isDirectory) {
val subprojectDir = File(testResultsDir, "$name/${testDir.name}")
subprojectDir.mkdirs()

testDir.copyRecursively(subprojectDir, overwrite = true)

indexHtmlFile.appendText(
"""
<li><a href="./$name/${testDir.name}/index.html">$name - ${testDir.name} Report</a></li>
""".trimIndent()
)
}
}
}
}

indexHtmlFile.appendText(
"""
</ul>
</body>
</html>
""".trimIndent()
)

// Print the location of the aggregated test results directory
// relative to the current terminal working dir
val currentWorkingDir = File(System.getProperty("user.dir"))
val relativePath = testResultsDir.relativeTo(currentWorkingDir).path
println("Aggregated test reports are available at: $relativePath")
}
}

tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ class ProteusClientCoreCryptoImpl private constructor(private val coreCrypto: Co

override suspend fun encryptBatched(message: ByteArray, sessionIds: List<CryptoSessionId>): Map<CryptoSessionId, ByteArray> {
return wrapException {
coreCrypto.proteusEncryptBatched(sessionIds.map { it.value }, toUByteList((message))).mapNotNull { entry ->
coreCrypto.proteusEncryptBatched(
sessionId = sessionIds.map { it.value },
plaintext = toUByteList((message))
).mapNotNull { entry ->
CryptoSessionId.fromEncodedString(entry.key)?.let { sessionId ->
sessionId to toByteArray(entry.value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ actual suspend fun coreCryptoCentral(
File(rootDir).mkdirs()
val coreCrypto = coreCryptoDeferredInit(
path = path,
key = databaseKey,
ciphersuites = emptyList(),
nbKeyPackage = null
key = databaseKey
)
coreCrypto.setCallbacks(Callbacks())
return CoreCryptoCentralImpl(
Expand All @@ -45,14 +43,13 @@ 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(
conversationId: ConversationId,
override suspend fun clientIsExistingGroupUser(
conversationId: ByteArray,
clientId: ClientId,
existingClients: List<ClientId>,
parentConversationClients: List<ClientId>?
Expand All @@ -61,11 +58,7 @@ private class Callbacks : CoreCryptoCallbacks {
return true
}

override fun userAuthorize(
conversationId: ConversationId,
externalClientId: ClientId,
existingClients: List<ClientId>
): Boolean {
override suspend fun userAuthorize(conversationId: ByteArray, externalClientId: ClientId, existingClients: List<ClientId>): Boolean {
// We always return true because our BE is currently enforcing that this constraint is always true
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ import com.wire.crypto.client.toByteArray
import com.wire.kalium.cryptography.exceptions.ProteusException
import io.ktor.util.decodeBase64Bytes
import io.ktor.util.encodeBase64
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import java.io.File

@Suppress("TooManyFunctions")
class ProteusClientCoreCryptoImpl private constructor(
private val coreCrypto: CoreCrypto,
) : ProteusClient {

private val mutex = Mutex()
private val existingSessionsCache = mutableSetOf<CryptoSessionId>()

override suspend fun close() {
coreCrypto.close()
}
Expand All @@ -46,6 +51,7 @@ class ProteusClientCoreCryptoImpl private constructor(
override suspend fun remoteFingerPrint(sessionId: CryptoSessionId): ByteArray = wrapException {
coreCrypto.proteusFingerprintRemote(sessionId.value).toByteArray()
}

override suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray = wrapException {
coreCrypto.proteusFingerprintPrekeybundle(preKey.encodedData.decodeBase64Bytes()).toByteArray()
}
Expand All @@ -62,9 +68,16 @@ class ProteusClientCoreCryptoImpl private constructor(
return wrapException { toPreKey(coreCrypto.proteusLastResortPrekeyId().toInt(), coreCrypto.proteusLastResortPrekey()) }
}

override suspend fun doesSessionExist(sessionId: CryptoSessionId): Boolean {
return wrapException {
override suspend fun doesSessionExist(sessionId: CryptoSessionId): Boolean = mutex.withLock {
if (existingSessionsCache.contains(sessionId)) {
return@withLock true
}
wrapException {
coreCrypto.proteusSessionExists(sessionId.value)
}.also { exists ->
if (exists) {
existingSessionsCache.add(sessionId)
}
}
}

Expand All @@ -77,13 +90,9 @@ class ProteusClientCoreCryptoImpl private constructor(

return wrapException {
if (sessionExists) {
val decryptedMessage = coreCrypto.proteusDecrypt(sessionId.value, message)
coreCrypto.proteusSessionSave(sessionId.value)
decryptedMessage
coreCrypto.proteusDecrypt(sessionId.value, message)
} else {
val decryptedMessage = coreCrypto.proteusSessionFromMessage(sessionId.value, message)
coreCrypto.proteusSessionSave(sessionId.value)
decryptedMessage
coreCrypto.proteusSessionFromMessage(sessionId.value, message)
}
}
}
Expand Down Expand Up @@ -119,7 +128,8 @@ class ProteusClientCoreCryptoImpl private constructor(
}
}

override suspend fun deleteSession(sessionId: CryptoSessionId) {
override suspend fun deleteSession(sessionId: CryptoSessionId) = mutex.withLock {
existingSessionsCache.remove(sessionId)
wrapException {
coreCrypto.proteusSessionDelete(sessionId.value)
}
Expand Down
3 changes: 3 additions & 0 deletions docs/notebooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A place to store [Jupyter Notebook](https://jupyter.org/) files of ongoing studies.

You can use Kotlin and run it directly in the IDE, thanks to [Kotlin Notebook](https://kotlinlang.org/docs/kotlin-notebook-overview.html).
Loading

0 comments on commit 943170b

Please sign in to comment.