From 7a3f2bb2407e180afdfefa7bfb4034440a8c398f Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 12 Jul 2022 09:30:43 +0200 Subject: [PATCH 1/3] stable name for withheld --- changelog.d/5115.bugfix | 1 + .../matrix/android/sdk/api/session/events/model/EventType.kt | 2 +- .../android/sdk/internal/crypto/DefaultCryptoService.kt | 4 ++-- .../android/sdk/internal/crypto/IncomingKeyRequestManager.kt | 2 +- .../internal/crypto/algorithms/megolm/MXMegolmEncryption.kt | 2 +- .../crypto/store/db/model/OutgoingKeyRequestEntity.kt | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 changelog.d/5115.bugfix diff --git a/changelog.d/5115.bugfix b/changelog.d/5115.bugfix new file mode 100644 index 0000000000..6b3ca4a7b4 --- /dev/null +++ b/changelog.d/5115.bugfix @@ -0,0 +1 @@ +Stop using unstable names for withheld codes diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt index fa3a9f6acd..656a20a62e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt @@ -87,7 +87,7 @@ object EventType { // Key share events const val ROOM_KEY_REQUEST = "m.room_key_request" const val FORWARDED_ROOM_KEY = "m.forwarded_room_key" - const val ROOM_KEY_WITHHELD = "org.matrix.room_key.withheld" + val ROOM_KEY_WITHHELD = listOf("m.room_key.withheld", "org.matrix.room_key.withheld") const val REQUEST_SECRET = "m.secret.request" const val SEND_SECRET = "m.secret.send" diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt index 850a4379ca..42783eb8a2 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt @@ -820,7 +820,7 @@ internal class DefaultCryptoService @Inject constructor( EventType.SEND_SECRET -> { onSecretSendReceived(event) } - EventType.ROOM_KEY_WITHHELD -> { + in EventType.ROOM_KEY_WITHHELD -> { onKeyWithHeldReceived(event) } else -> { @@ -869,7 +869,7 @@ internal class DefaultCryptoService @Inject constructor( senderKey = withHeldContent.senderKey, fromDevice = withHeldContent.fromDevice, event = Event( - type = EventType.ROOM_KEY_WITHHELD, + type = EventType.ROOM_KEY_WITHHELD.first(), senderId = senderId, content = event.getClearContent() ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt index 7f36224dae..5eec293ac6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt @@ -315,7 +315,7 @@ internal class IncomingKeyRequestManager @Inject constructor( ) val params = SendToDeviceTask.Params( - EventType.ROOM_KEY_WITHHELD, + EventType.ROOM_KEY_WITHHELD.first(), MXUsersDevicesMap().apply { setObject(request.requestingUserId, request.requestingDeviceId, withHeldContent) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt index ceaee582c7..d524acbe81 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt @@ -365,7 +365,7 @@ internal class MXMegolmEncryption( fromDevice = myDeviceId ) val params = SendToDeviceTask.Params( - EventType.ROOM_KEY_WITHHELD, + EventType.ROOM_KEY_WITHHELD.first(), MXUsersDevicesMap().apply { targets.forEach { setObject(it.userId, it.deviceId, withHeldContent) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingKeyRequestEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingKeyRequestEntity.kt index 854d148b76..42cc5978cd 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingKeyRequestEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingKeyRequestEntity.kt @@ -117,7 +117,7 @@ internal open class OutgoingKeyRequestEntity( private fun eventToResult(event: Event): RequestResult? { return when (event.getClearType()) { - EventType.ROOM_KEY_WITHHELD -> { + in EventType.ROOM_KEY_WITHHELD -> { event.content.toModel()?.code?.let { RequestResult.Failure(it) } From d51a1fdb0e2101abdcd18625b4a3ac41a1ffdb09 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 12 Jul 2022 09:35:50 +0200 Subject: [PATCH 2/3] add back withheld tests --- .../android/sdk/internal/crypto/gossiping/WithHeldTests.kt | 1 - 1 file changed, 1 deletion(-) 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 ae420a09b3..94fdddc1d9 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 @@ -47,7 +47,6 @@ import org.matrix.android.sdk.mustFail @RunWith(AndroidJUnit4::class) @FixMethodOrder(MethodSorters.JVM) @LargeTest -@Ignore class WithHeldTests : InstrumentedTest { @get:Rule val rule = RetryTestRule(3) From 687c2794fd03960ee0f670d9c092801ca11be02d Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 21 Jul 2022 10:13:15 +0200 Subject: [PATCH 3/3] use specific unstable/stable class --- .../crypto/gossiping/WithHeldTests.kt | 1 - .../sdk/api/session/events/model/EventType.kt | 5 +++- .../session/events/model/StableUnstableId.kt | 24 +++++++++++++++++++ .../internal/crypto/DefaultCryptoService.kt | 4 ++-- .../crypto/IncomingKeyRequestManager.kt | 2 +- .../algorithms/megolm/MXMegolmEncryption.kt | 2 +- .../db/model/OutgoingKeyRequestEntity.kt | 2 +- 7 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/StableUnstableId.kt 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 94fdddc1d9..0aac4297e4 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 @@ -21,7 +21,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import org.junit.Assert import org.junit.FixMethodOrder -import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt index 656a20a62e..8fdbba21c5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt @@ -87,7 +87,10 @@ object EventType { // Key share events const val ROOM_KEY_REQUEST = "m.room_key_request" const val FORWARDED_ROOM_KEY = "m.forwarded_room_key" - val ROOM_KEY_WITHHELD = listOf("m.room_key.withheld", "org.matrix.room_key.withheld") + val ROOM_KEY_WITHHELD = StableUnstableId( + stable = "m.room_key.withheld", + unstable = "org.matrix.room_key.withheld" + ) const val REQUEST_SECRET = "m.secret.request" const val SEND_SECRET = "m.secret.send" diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/StableUnstableId.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/StableUnstableId.kt new file mode 100644 index 0000000000..c68a9e47f9 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/StableUnstableId.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.api.session.events.model + +data class StableUnstableId( + val stable: String, + val unstable: String, +) { + val values = listOf(stable, unstable) +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt index 42783eb8a2..35c066dea8 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt @@ -820,7 +820,7 @@ internal class DefaultCryptoService @Inject constructor( EventType.SEND_SECRET -> { onSecretSendReceived(event) } - in EventType.ROOM_KEY_WITHHELD -> { + in EventType.ROOM_KEY_WITHHELD.values -> { onKeyWithHeldReceived(event) } else -> { @@ -869,7 +869,7 @@ internal class DefaultCryptoService @Inject constructor( senderKey = withHeldContent.senderKey, fromDevice = withHeldContent.fromDevice, event = Event( - type = EventType.ROOM_KEY_WITHHELD.first(), + type = EventType.ROOM_KEY_WITHHELD.stable, senderId = senderId, content = event.getClearContent() ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt index 5eec293ac6..729b4481e4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt @@ -315,7 +315,7 @@ internal class IncomingKeyRequestManager @Inject constructor( ) val params = SendToDeviceTask.Params( - EventType.ROOM_KEY_WITHHELD.first(), + EventType.ROOM_KEY_WITHHELD.stable, MXUsersDevicesMap().apply { setObject(request.requestingUserId, request.requestingDeviceId, withHeldContent) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt index d524acbe81..96d97a41d7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt @@ -365,7 +365,7 @@ internal class MXMegolmEncryption( fromDevice = myDeviceId ) val params = SendToDeviceTask.Params( - EventType.ROOM_KEY_WITHHELD.first(), + EventType.ROOM_KEY_WITHHELD.stable, MXUsersDevicesMap().apply { targets.forEach { setObject(it.userId, it.deviceId, withHeldContent) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingKeyRequestEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingKeyRequestEntity.kt index 42cc5978cd..b10e7501d6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingKeyRequestEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingKeyRequestEntity.kt @@ -117,7 +117,7 @@ internal open class OutgoingKeyRequestEntity( private fun eventToResult(event: Event): RequestResult? { return when (event.getClearType()) { - in EventType.ROOM_KEY_WITHHELD -> { + in EventType.ROOM_KEY_WITHHELD.values -> { event.content.toModel()?.code?.let { RequestResult.Failure(it) }