Merge pull request #8354 from vector-im/feature/bca/upgrade_crypto_crate

bump rust crypto to 0.3.5 (withheld)
This commit is contained in:
Valere 2023-04-24 17:53:43 +02:00 committed by GitHub
commit 46a49d899c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 17 deletions

1
changelog.d/7628.sdk Normal file
View File

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

1
changelog.d/8354.misc Normal file
View File

@ -0,0 +1 @@
Bump rust crypto crate to 0.3.5

View File

@ -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

View File

@ -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!!
// =============================
@ -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
}

View File

@ -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)