Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/github_actions/EnricoMi/publis…
Browse files Browse the repository at this point in the history
…h-unit-test-result-action-2.7
  • Loading branch information
yamilmedina authored Nov 30, 2023
2 parents 662e81a + e2f290b commit a57a1e7
Show file tree
Hide file tree
Showing 183 changed files with 4,738 additions and 1,706 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cherry-pick-rc-to-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
cd ..
git add ${{ env.SUBMODULE_NAME }}
git commit -m "Update submodule ${{ env.SUBMODULE_NAME }} to latest from ${{ env.TARGET_BRANCH }}"
echo "lastCommitMessage=LAST_COMMIT_MESSAGE" >> $GITHUB_ENV
echo "lastCommitMessage=$LAST_COMMIT_MESSAGE" >> $GITHUB_ENV
- name: Get Cherry-pick commit
id: get-cherry
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

### Supported Platforms

- Android (see the [Android Reloaded](https://github.com/wireapp/wire-android-reloaded) module)
- Android (see the [Android](https://github.com/wireapp/wire-android) module)
- JVM (see the [cli](https://github.com/wireapp/kalium/tree/develop/cli) module)
- iOS (partially)
- JavaScript (just a tiny bit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ package com.wire.kalium.cryptography

import android.util.Base64
import com.wire.cryptobox.CryptoBox
import com.wire.cryptobox.CryptoBox.getFingerprintFromPrekey
import com.wire.cryptobox.CryptoException
import com.wire.kalium.cryptography.exceptions.ProteusException
import io.ktor.util.decodeBase64Bytes
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
import java.io.File
import kotlin.coroutines.CoroutineContext
import com.wire.cryptobox.PreKey as CryptoBoxPreKey

@Suppress("TooManyFunctions")
class ProteusClientCryptoBoxImpl constructor(
Expand Down Expand Up @@ -54,6 +57,12 @@ class ProteusClientCryptoBoxImpl constructor(
wrapException { box.getSession(sessionId.value).remoteFingerprint }
}

override suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray =
withContext(defaultContext) {
val cryptoBoxPreKey = CryptoBoxPreKey(preKey.id, preKey.encodedData.decodeBase64Bytes())
getFingerprintFromPrekey(cryptoBoxPreKey)
}

/**
* Create the crypto files if missing and call box.open
* this must be called only one time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ class MLSClientImpl(
TODO("Not supported on apple devices")
}

override suspend fun getUserIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): List<WireIdentity> {
override suspend fun getDeviceIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): List<WireIdentity> {
TODO("Not yet implemented")
}

override suspend fun getUserIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): Map<String, List<WireIdentity>> {
TODO("Not yet implemented")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class ProteusClientCoreCryptoImpl private constructor(private val coreCrypto: Co
return wrapException { coreCrypto.proteusFingerprintRemote(sessionId.value).toByteArray() }
}

override suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray {
// TODO this is a hack, we need to expose the fingerprint from the core
return "".toByteArray()
}

override suspend fun newPreKeys(from: Int, count: Int): ArrayList<PreKeyCrypto> {
return wrapException {
from.until(from + count).map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class E2EIClientImpl(
)

private fun toAcmeChallenge(value: com.wire.crypto.AcmeChallenge) = AcmeChallenge(
value.delegate.toUByteArray().asByteArray(), value.url
value.delegate.toUByteArray().asByteArray(),
value.url,
value.target
)

fun toNewAcmeAuthz(value: com.wire.crypto.NewAcmeAuthz) = NewAcmeAuthz(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,24 @@ class MLSClientImpl(
override suspend fun isGroupVerified(groupId: MLSGroupId): E2EIConversationState =
toE2EIConversationState(coreCrypto.e2eiConversationState(groupId.decodeBase64Bytes()))

override suspend fun getUserIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): List<WireIdentity> {
override suspend fun getDeviceIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): List<WireIdentity> {
val clientIds = clients.map {
it.toString().encodeToByteArray()
}
return coreCrypto.getUserIdentities(groupId.decodeBase64Bytes(), clientIds).map {
return coreCrypto.getDeviceIdentities(groupId.decodeBase64Bytes(), clientIds).map {
toIdentity(it)
}
}

override suspend fun getUserIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): Map<String, List<WireIdentity>> {
val usersIds = clients.map {
it.getEncodedUserID()
}
return coreCrypto.getUserIdentities(groupId.decodeBase64Bytes(), usersIds).mapValues {
it.value.map { identity -> toIdentity(identity) }
}
}

companion object {
fun toUByteList(value: ByteArray): List<UByte> = value.asUByteArray().asList()
fun toUByteList(value: String): List<UByte> = value.encodeToByteArray().asUByteArray().asList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.wire.kalium.cryptography

import com.wire.crypto.CoreCrypto
import com.wire.crypto.CoreCryptoException
import com.wire.crypto.client.toByteArray
import com.wire.kalium.cryptography.exceptions.ProteusException
import io.ktor.util.decodeBase64Bytes
import io.ktor.util.encodeBase64
Expand All @@ -45,6 +46,9 @@ 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()
}

override suspend fun newPreKeys(from: Int, count: Int): ArrayList<PreKeyCrypto> {
return wrapException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ data class NewAcmeOrder(

data class AcmeChallenge(
var delegate: JsonRawData,
var url: String
var url: String,
var target: String
)

data class NewAcmeAuthz(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ data class CryptoQualifiedClientId(
}

data class WireIdentity(
var clientId: String,
var handle: String,
var displayName: String,
var domain: String,
var certificate: String
val clientId: String,
val handle: String,
val displayName: String,
val domain: String,
val certificate: String
)

@Suppress("MagicNumber")
data class E2EIQualifiedClientId(
val value: String,
val userId: CryptoQualifiedID
) {
override fun toString(): String {
fun getEncodedUserID(): String {
val sourceUUID = uuidFrom(userId.value)

// Convert the UUID to bytes
Expand All @@ -100,8 +100,10 @@ data class E2EIQualifiedClientId(
}

// Base64url encode the UUID bytes without padding
val base64UrlEncoded = uuidBytes.encodeBase64().removeSuffix("==")
return uuidBytes.encodeBase64().removeSuffix("==")
}

return "${base64UrlEncoded}:${value}@${userId.domain}"
override fun toString(): String {
return "${getEncodedUserID()}:${value}@${userId.domain}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,5 +343,15 @@ interface MLSClient {
*
* @return the exist identities for requested clients
*/
suspend fun getUserIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): List<WireIdentity>
suspend fun getDeviceIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): List<WireIdentity>

/**
* Get the identity of given users in the given conversation
*
* @param clients a list of clients of the requested users
* @param groupId MLS group ID for an existing conversation
*
* @return the exist identities for requested clients
*/
suspend fun getUserIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): Map<String, List<WireIdentity>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ interface ProteusClient {
@Throws(ProteusException::class, CancellationException::class)
suspend fun remoteFingerPrint(sessionId: CryptoSessionId): ByteArray

@Throws(ProteusException::class, CancellationException::class)
suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray

suspend fun newPreKeys(from: Int, count: Int): List<PreKeyCrypto>

@Throws(ProteusException::class, CancellationException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ class MLSClientImpl : MLSClient {
TODO("Not supported on js")
}

override suspend fun getUserIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): List<WireIdentity> {
override suspend fun getDeviceIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): List<WireIdentity> {
TODO("Not yet implemented")
}

override suspend fun getUserIdentities(groupId: MLSGroupId, clients: List<E2EIQualifiedClientId>): Map<String, List<WireIdentity>> {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.wire.kalium.cryptography.externals.PreKeyBundle
import io.ktor.util.InternalAPI
import io.ktor.util.decodeBase64Bytes
import io.ktor.util.encodeBase64
import io.ktor.utils.io.core.toByteArray
import kotlinx.coroutines.await
import org.khronos.webgl.ArrayBuffer
import org.khronos.webgl.Int8Array
Expand Down Expand Up @@ -57,6 +58,11 @@ class ProteusClientCryptoBoxImpl : ProteusClient {
return box.identity.public_key.fingerprint().encodeToByteArray()
}

override suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray {
// TODO ("we need to expose the fingerprint from the core")
return "".toByteArray()
}

override suspend fun remoteFingerPrint(sessionId: CryptoSessionId): ByteArray {
return box.session_load(sessionId.value).await().fingerprint_remote().encodeToByteArray()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.wire.kalium.cryptography

import com.wire.bots.cryptobox.CryptoBox
import com.wire.bots.cryptobox.CryptoBox.getFingerprintFromPrekey
import com.wire.bots.cryptobox.CryptoException
import com.wire.kalium.cryptography.exceptions.ProteusException
import java.io.File
Expand Down Expand Up @@ -63,6 +64,10 @@ class ProteusClientCryptoBoxImpl constructor(
TODO("get session is private in Cryptobox4j")
}

override suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray = wrapException {
getFingerprintFromPrekey(toPreKey(preKey))
}

override suspend fun newLastResortPreKey(): PreKeyCrypto {
return wrapException { toPreKey(box.newLastPreKey()) }
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ sqldelight = "2.0.0"
sqlcipher-android = "4.5.5"
pbandk = "0.14.2"
turbine = "1.0.0"
avs = "9.5.4"
avs = "9.5.7"
jna = "5.13.0"
core-crypto = "1.0.0-rc.17"
core-crypto = "1.0.0-rc.19"
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 @@ -22,14 +22,19 @@ import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.data.asset.KaliumFileSystem
import com.wire.kalium.logic.functional.Either
import okio.BufferedSource
import okio.Source
import okio.Sink
import okio.Path
import okio.Sink
import okio.Source

actual fun createCompressedFile(files: List<Pair<Source, String>>, outputSink: Sink): Either<CoreFailure, Long> =
TODO("Implement own iOS compression method")

actual fun extractCompressedFile(inputSource: Source, outputRootPath: Path, fileSystem: KaliumFileSystem): Either<CoreFailure, Long> =
actual fun extractCompressedFile(
inputSource: Source,
outputRootPath: Path,
param: ExtractFilesParam,
fileSystem: KaliumFileSystem
): Either<CoreFailure, Long> =
TODO("Implement own iOS compression method")

actual fun checkIfCompressedFileContainsFileTypes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,45 @@ private fun addToCompressedFile(zipOutputStream: ZipOutputStream, fileSource: So
}

@Suppress("TooGenericExceptionCaught", "NestedBlockDepth")
actual fun extractCompressedFile(inputSource: Source, outputRootPath: Path, fileSystem: KaliumFileSystem): Either<CoreFailure, Long> = try {
actual fun extractCompressedFile(
inputSource: Source,
outputRootPath: Path,
param: ExtractFilesParam,
fileSystem: KaliumFileSystem
): Either<CoreFailure, Long> = try {
var totalExtractedFilesSize = 0L
ZipInputStream(inputSource.buffer().inputStream()).use { zipInputStream ->
var entry: ZipEntry? = zipInputStream.nextEntry
while (entry != null) {
readCompressedEntry(zipInputStream, outputRootPath, fileSystem, entry).let {
totalExtractedFilesSize += it.first
entry = it.second
totalExtractedFilesSize += when (param) {
is ExtractFilesParam.All -> readCompressedEntry(zipInputStream, outputRootPath, fileSystem, entry)
is ExtractFilesParam.Only -> readAndExtractIfMatch(zipInputStream, outputRootPath, fileSystem, entry, param.files)
}
zipInputStream.closeEntry()
entry = zipInputStream.nextEntry
}
}
Either.Right(totalExtractedFilesSize)
} catch (e: Exception) {
Either.Left(StorageFailure.Generic(RuntimeException("There was an error trying to extract the provided compressed file", e)))
}

private fun readAndExtractIfMatch(
zipInputStream: ZipInputStream,
outputRootPath: Path,
fileSystem: KaliumFileSystem,
entry: ZipEntry,
fileNames: Set<String>
): Long {
return entry.name.let {
if (fileNames.contains(it)) {
readCompressedEntry(zipInputStream, outputRootPath, fileSystem, entry)
} else {
0L
}
}
}

@Suppress("TooGenericExceptionCaught", "NestedBlockDepth")
actual fun checkIfCompressedFileContainsFileTypes(
compressedFilePath: Path,
Expand Down Expand Up @@ -121,11 +144,7 @@ private fun readCompressedEntry(
outputRootPath: Path,
fileSystem: KaliumFileSystem,
entry: ZipEntry
): Pair<Long, ZipEntry?> {
if (isInvalidEntryPathDestination(entry.name)) {
throw RuntimeException("The provided zip file is invalid or has invalid data")
}

): Long {
var totalExtractedFilesSize = 0L
var byteCount: Int
val entryPathName = "$outputRootPath/${entry.name}"
Expand All @@ -137,8 +156,7 @@ private fun readCompressedEntry(
}
output.write(zipInputStream.readBytes())
}
zipInputStream.closeEntry()
return totalExtractedFilesSize to zipInputStream.nextEntry
return totalExtractedFilesSize
}

/**
Expand Down
Loading

0 comments on commit a57a1e7

Please sign in to comment.