Skip to content

bump rust crypto to 0.3.5 (withheld) #8354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7628.sdk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
First integration of rust crypto module. See documentation for details `docs/rust_crypto_integration.md`
1 change: 1 addition & 0 deletions changelog.d/8354.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump rust crypto crate to 0.3.5
2 changes: 1 addition & 1 deletion matrix-sdk-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EncryptedEventContent>()!!.sessionId!!
// =============================
Expand All @@ -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 ->
Expand All @@ -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()
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down