Skip to content

Commit 46a49d8

Browse files
authored
Merge pull request #8354 from vector-im/feature/bca/upgrade_crypto_crate
bump rust crypto to 0.3.5 (withheld)
2 parents 6345161 + 2145926 commit 46a49d8

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

changelog.d/7628.sdk

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
First integration of rust crypto module. See documentation for details `docs/rust_crypto_integration.md`

changelog.d/8354.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bump rust crypto crate to 0.3.5

matrix-sdk-android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ dependencies {
216216

217217
implementation libs.google.phonenumber
218218

219-
rustCryptoImplementation("org.matrix.rustcomponents:crypto-android:0.3.1")
219+
rustCryptoImplementation("org.matrix.rustcomponents:crypto-android:0.3.5")
220220
// rustCryptoApi project(":library:rustCrypto")
221221

222222
testImplementation libs.tests.junit

matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt

+7-6
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ class WithHeldTests : InstrumentedTest {
8080
// Alice decide to not send to unverified sessions
8181
aliceSession.cryptoService().setGlobalBlacklistUnverifiedDevices(true)
8282

83-
val timelineEvent = testHelper.sendTextMessage(roomAlicePOV, "Hello Bob", 1).first()
83+
val eventId = testHelper.sendMessageInRoom(roomAlicePOV, "Hello Bob")
8484

8585
// await for bob unverified session to get the message
8686
testHelper.retryWithBackoff {
87-
bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(timelineEvent.eventId) != null
87+
bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(eventId) != null
8888
}
8989

90-
val eventBobPOV = bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(timelineEvent.eventId)!!
90+
val eventBobPOV = bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(eventId)!!
9191

9292
val megolmSessionId = eventBobPOV.root.content.toModel<EncryptedEventContent>()!!.sessionId!!
9393
// =============================
@@ -96,6 +96,7 @@ class WithHeldTests : InstrumentedTest {
9696

9797
// Bob should not be able to decrypt because the keys is withheld
9898
// .. might need to wait a bit for stability?
99+
// WILL FAIL for rust until this fixed https://github.com./matrix-org/matrix-rust-sdk/issues/1806
99100
mustFail(
100101
message = "This session should not be able to decrypt",
101102
failureBlock = { failure ->
@@ -108,7 +109,7 @@ class WithHeldTests : InstrumentedTest {
108109
bobUnverifiedSession.cryptoService().decryptEvent(eventBobPOV.root, "")
109110
}
110111

111-
if (bobUnverifiedSession.cryptoService().supportsForwardedKeyWiththeld()) {
112+
if (bobUnverifiedSession.cryptoService().supportKeyRequestInspection()) {
112113
// Let's see if the reply we got from bob first session is unverified
113114
testHelper.retryWithBackoff {
114115
bobUnverifiedSession.cryptoService().getOutgoingRoomKeyRequests()
@@ -125,10 +126,10 @@ class WithHeldTests : InstrumentedTest {
125126
// enable back sending to unverified
126127
aliceSession.cryptoService().setGlobalBlacklistUnverifiedDevices(false)
127128

128-
val secondEvent = testHelper.sendTextMessage(roomAlicePOV, "Verify your device!!", 1).first()
129+
val secondEventId = testHelper.sendMessageInRoom(roomAlicePOV, "Verify your device!!")
129130

130131
testHelper.retryWithBackoff {
131-
val ev = bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(secondEvent.eventId)
132+
val ev = bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(secondEventId)
132133
// wait until it's decrypted
133134
ev?.root?.getClearType() == EventType.MESSAGE
134135
}

matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt

+7-10
Original file line numberDiff line numberDiff line change
@@ -472,19 +472,16 @@ internal class OlmMachine @Inject constructor(
472472
} catch (throwable: Throwable) {
473473
val reThrow = when (throwable) {
474474
is DecryptionException.MissingRoomKey -> {
475-
// Revert when witheld PR merged
476-
// if (throwable.withheldCode != null) {
477-
// MXCryptoError.Base(MXCryptoError.ErrorType.KEYS_WITHHELD, throwable.withheldCode!!)
478-
// } else {
479-
// MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID, throwable.error)
480-
// }
481-
482-
MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID, throwable.message.orEmpty())
475+
if (throwable.withheldCode != null) {
476+
MXCryptoError.Base(MXCryptoError.ErrorType.KEYS_WITHHELD, throwable.withheldCode!!)
477+
} else {
478+
MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID, throwable.error)
479+
}
483480
}
484481
is DecryptionException.Megolm -> {
485482
// TODO check if it's the correct binding?
486-
// MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX, throwable.error)
487-
MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX, throwable.message.orEmpty())
483+
// Could encapsulate more than that, need to update sdk
484+
MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX, throwable.error)
488485
}
489486
is DecryptionException.Identifier -> {
490487
MXCryptoError.Base(MXCryptoError.ErrorType.BAD_EVENT_FORMAT, MXCryptoError.BAD_EVENT_FORMAT_TEXT_REASON)

0 commit comments

Comments
 (0)