From 7c3751f568594185fb50d78eeb7ab709acad0493 Mon Sep 17 00:00:00 2001 From: valere Date: Fri, 21 Apr 2023 18:09:13 +0200 Subject: [PATCH 1/3] 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) From f02cd0d77fd9d4c89cf144ef685a8de4f1b71026 Mon Sep 17 00:00:00 2001 From: valere Date: Fri, 21 Apr 2023 18:10:37 +0200 Subject: [PATCH 2/3] Add changelog --- changelog.d/8354.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/8354.misc diff --git a/changelog.d/8354.misc b/changelog.d/8354.misc new file mode 100644 index 0000000000..f26be92ed6 --- /dev/null +++ b/changelog.d/8354.misc @@ -0,0 +1 @@ +Bump rust crypto crate to 0.3.5 From 21459261a26b2bd8f8c3ef19d3cf7a6905192eaf Mon Sep 17 00:00:00 2001 From: valere Date: Fri, 21 Apr 2023 19:56:29 +0200 Subject: [PATCH 3/3] add changelog for rust sdk module --- changelog.d/7628.sdk | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7628.sdk diff --git a/changelog.d/7628.sdk b/changelog.d/7628.sdk new file mode 100644 index 0000000000..d9886730fd --- /dev/null +++ b/changelog.d/7628.sdk @@ -0,0 +1 @@ +First integration of rust crypto module. See documentation for details `docs/rust_crypto_integration.md`