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 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") // rustCryptoApi project(":library:rustCrypto")
testImplementation libs.tests.junit testImplementation libs.tests.junit

View File

@ -80,14 +80,14 @@ class WithHeldTests : InstrumentedTest {
// Alice decide to not send to unverified sessions // Alice decide to not send to unverified sessions
aliceSession.cryptoService().setGlobalBlacklistUnverifiedDevices(true) 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 // await for bob unverified session to get the message
testHelper.retryWithBackoff { 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!! 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 // Bob should not be able to decrypt because the keys is withheld
// .. might need to wait a bit for stability? // .. 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( mustFail(
message = "This session should not be able to decrypt", message = "This session should not be able to decrypt",
failureBlock = { failure -> failureBlock = { failure ->
@ -108,7 +109,7 @@ class WithHeldTests : InstrumentedTest {
bobUnverifiedSession.cryptoService().decryptEvent(eventBobPOV.root, "") 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 // Let's see if the reply we got from bob first session is unverified
testHelper.retryWithBackoff { testHelper.retryWithBackoff {
bobUnverifiedSession.cryptoService().getOutgoingRoomKeyRequests() bobUnverifiedSession.cryptoService().getOutgoingRoomKeyRequests()
@ -125,10 +126,10 @@ class WithHeldTests : InstrumentedTest {
// enable back sending to unverified // enable back sending to unverified
aliceSession.cryptoService().setGlobalBlacklistUnverifiedDevices(false) aliceSession.cryptoService().setGlobalBlacklistUnverifiedDevices(false)
val secondEvent = testHelper.sendTextMessage(roomAlicePOV, "Verify your device!!", 1).first() val secondEventId = testHelper.sendMessageInRoom(roomAlicePOV, "Verify your device!!")
testHelper.retryWithBackoff { testHelper.retryWithBackoff {
val ev = bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(secondEvent.eventId) val ev = bobUnverifiedSession.getRoom(roomId)?.getTimelineEvent(secondEventId)
// wait until it's decrypted // wait until it's decrypted
ev?.root?.getClearType() == EventType.MESSAGE ev?.root?.getClearType() == EventType.MESSAGE
} }

View File

@ -472,19 +472,16 @@ internal class OlmMachine @Inject constructor(
} catch (throwable: Throwable) { } catch (throwable: Throwable) {
val reThrow = when (throwable) { val reThrow = when (throwable) {
is DecryptionException.MissingRoomKey -> { is DecryptionException.MissingRoomKey -> {
// Revert when witheld PR merged if (throwable.withheldCode != null) {
// if (throwable.withheldCode != null) { MXCryptoError.Base(MXCryptoError.ErrorType.KEYS_WITHHELD, throwable.withheldCode!!)
// MXCryptoError.Base(MXCryptoError.ErrorType.KEYS_WITHHELD, throwable.withheldCode!!) } else {
// } else { MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID, throwable.error)
// MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID, throwable.error) }
// }
MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID, throwable.message.orEmpty())
} }
is DecryptionException.Megolm -> { is DecryptionException.Megolm -> {
// TODO check if it's the correct binding? // TODO check if it's the correct binding?
// MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX, throwable.error) // Could encapsulate more than that, need to update sdk
MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX, throwable.message.orEmpty()) MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX, throwable.error)
} }
is DecryptionException.Identifier -> { is DecryptionException.Identifier -> {
MXCryptoError.Base(MXCryptoError.ErrorType.BAD_EVENT_FORMAT, MXCryptoError.BAD_EVENT_FORMAT_TEXT_REASON) MXCryptoError.Base(MXCryptoError.ErrorType.BAD_EVENT_FORMAT, MXCryptoError.BAD_EVENT_FORMAT_TEXT_REASON)