From 7c3751f568594185fb50d78eeb7ab709acad0493 Mon Sep 17 00:00:00 2001 From: valere Date: Fri, 21 Apr 2023 18:09:13 +0200 Subject: [PATCH] bump rust crypto to 0.3.5 (withheld) --- matrix-sdk-android/build.gradle | 2 +- .../internal/crypto/gossiping/WithHeldTests.kt | 13 +++++++------ .../android/sdk/internal/crypto/OlmMachine.kt | 17 +++++++---------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 9b5ff72f32..d48f6ff8e9 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -216,7 +216,7 @@ dependencies { implementation libs.google.phonenumber - rustCryptoImplementation("org.matrix.rustcomponents:crypto-android:0.3.1") + rustCryptoImplementation("org.matrix.rustcomponents:crypto-android:0.3.5") // rustCryptoApi project(":library:rustCrypto") testImplementation libs.tests.junit diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt index 5d072a6124..e0df83924f 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt @@ -80,14 +80,14 @@ class WithHeldTests : InstrumentedTest { // Alice decide to not send to unverified sessions aliceSession.cryptoService().setGlobalBlacklistUnverifiedDevices(true) - val timelineEvent = testHelper.sendTextMessage(roomAlicePOV, "Hello Bob", 1).first() + val eventId = testHelper.sendMessageInRoom(roomAlicePOV, "Hello Bob") // await for bob unverified session to get the message testHelper.retryWithBackoff { - bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(timelineEvent.eventId) != null + bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(eventId) != null } - val eventBobPOV = bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(timelineEvent.eventId)!! + val eventBobPOV = bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(eventId)!! val megolmSessionId = eventBobPOV.root.content.toModel()!!.sessionId!! // ============================= @@ -96,6 +96,7 @@ class WithHeldTests : InstrumentedTest { // Bob should not be able to decrypt because the keys is withheld // .. might need to wait a bit for stability? + // WILL FAIL for rust until this fixed https://github.com/matrix-org/matrix-rust-sdk/issues/1806 mustFail( message = "This session should not be able to decrypt", failureBlock = { failure -> @@ -108,7 +109,7 @@ class WithHeldTests : InstrumentedTest { bobUnverifiedSession.cryptoService().decryptEvent(eventBobPOV.root, "") } - if (bobUnverifiedSession.cryptoService().supportsForwardedKeyWiththeld()) { + if (bobUnverifiedSession.cryptoService().supportKeyRequestInspection()) { // Let's see if the reply we got from bob first session is unverified testHelper.retryWithBackoff { bobUnverifiedSession.cryptoService().getOutgoingRoomKeyRequests() @@ -125,10 +126,10 @@ class WithHeldTests : InstrumentedTest { // enable back sending to unverified aliceSession.cryptoService().setGlobalBlacklistUnverifiedDevices(false) - val secondEvent = testHelper.sendTextMessage(roomAlicePOV, "Verify your device!!", 1).first() + val secondEventId = testHelper.sendMessageInRoom(roomAlicePOV, "Verify your device!!") testHelper.retryWithBackoff { - val ev = bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(secondEvent.eventId) + val ev = bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(secondEventId) // wait until it's decrypted ev?.root?.getClearType() == EventType.MESSAGE } diff --git a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt index a983aac114..fc21d49d0d 100644 --- a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt +++ b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt @@ -472,19 +472,16 @@ internal class OlmMachine @Inject constructor( } catch (throwable: Throwable) { val reThrow = when (throwable) { is DecryptionException.MissingRoomKey -> { - // Revert when witheld PR merged -// if (throwable.withheldCode != null) { -// MXCryptoError.Base(MXCryptoError.ErrorType.KEYS_WITHHELD, throwable.withheldCode!!) -// } else { -// MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID, throwable.error) -// } - - MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID, throwable.message.orEmpty()) + if (throwable.withheldCode != null) { + MXCryptoError.Base(MXCryptoError.ErrorType.KEYS_WITHHELD, throwable.withheldCode!!) + } else { + MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID, throwable.error) + } } is DecryptionException.Megolm -> { // TODO check if it's the correct binding? -// MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX, throwable.error) - MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX, throwable.message.orEmpty()) + // Could encapsulate more than that, need to update sdk + MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX, throwable.error) } is DecryptionException.Identifier -> { MXCryptoError.Base(MXCryptoError.ErrorType.BAD_EVENT_FORMAT, MXCryptoError.BAD_EVENT_FORMAT_TEXT_REASON)