-
Notifications
You must be signed in to change notification settings - Fork 859
Support misconfigured room encryption #4726
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
Changes from all commits
6b05e7a
38fbfad
1fdb851
fca32da
74dfdde
b10bc70
57b78a6
1a92d75
aa7d284
6798492
60ae416
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Better handling of misconfigured room encryption |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright 2021 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.room.model | ||
|
|
||
| import org.matrix.android.sdk.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM | ||
|
|
||
| sealed class RoomEncryptionAlgorithm { | ||
|
|
||
| abstract class SupportedAlgorithm(val alg: String) : RoomEncryptionAlgorithm() | ||
bmarty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| object Megolm : SupportedAlgorithm(MXCRYPTO_ALGORITHM_MEGOLM) | ||
|
|
||
| data class UnsupportedAlgorithm(val name: String?) : RoomEncryptionAlgorithm() | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent | |
| import org.matrix.android.sdk.api.session.room.model.VersioningState | ||
| import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent | ||
| import org.matrix.android.sdk.api.session.room.model.tag.RoomTag | ||
| import org.matrix.android.sdk.internal.crypto.model.event.EncryptionEventContent | ||
| import org.matrix.android.sdk.internal.database.model.ChunkEntityFields | ||
| import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntityFields | ||
| import org.matrix.android.sdk.internal.database.model.EditAggregatedSummaryEntityFields | ||
|
|
@@ -55,7 +56,7 @@ internal class RealmSessionStoreMigration @Inject constructor( | |
| ) : RealmMigration { | ||
|
|
||
| companion object { | ||
| const val SESSION_STORE_SCHEMA_VERSION = 20L | ||
| const val SESSION_STORE_SCHEMA_VERSION = 21L | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -88,6 +89,7 @@ internal class RealmSessionStoreMigration @Inject constructor( | |
| if (oldVersion <= 17) migrateTo18(realm) | ||
| if (oldVersion <= 18) migrateTo19(realm) | ||
| if (oldVersion <= 19) migrateTo20(realm) | ||
| if (oldVersion <= 20) migrateTo21(realm) | ||
| } | ||
|
|
||
| private fun migrateTo1(realm: DynamicRealm) { | ||
|
|
@@ -395,6 +397,7 @@ internal class RealmSessionStoreMigration @Inject constructor( | |
|
|
||
| private fun migrateTo20(realm: DynamicRealm) { | ||
| Timber.d("Step 19 -> 20") | ||
|
|
||
| realm.schema.get("ChunkEntity")?.apply { | ||
| if (hasField("numberOfTimelineEvents")) { | ||
| removeField("numberOfTimelineEvents") | ||
|
|
@@ -414,4 +417,32 @@ internal class RealmSessionStoreMigration @Inject constructor( | |
| } | ||
| } | ||
| } | ||
|
|
||
| private fun migrateTo21(realm: DynamicRealm) { | ||
| Timber.d("Step 20 -> 21") | ||
|
|
||
| realm.schema.get("RoomSummaryEntity") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done + rebase
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks |
||
| ?.addField(RoomSummaryEntityFields.E2E_ALGORITHM, String::class.java) | ||
| ?.transform { obj -> | ||
|
|
||
| val encryptionContentAdapter = MoshiProvider.providesMoshi().adapter(EncryptionEventContent::class.java) | ||
|
|
||
| val encryptionEvent = realm.where("CurrentStateEventEntity") | ||
| .equalTo(CurrentStateEventEntityFields.ROOM_ID, obj.getString(RoomSummaryEntityFields.ROOM_ID)) | ||
| .equalTo(CurrentStateEventEntityFields.TYPE, EventType.STATE_ROOM_ENCRYPTION) | ||
| .findFirst() | ||
|
|
||
| val encryptionEventRoot = encryptionEvent?.getObject(CurrentStateEventEntityFields.ROOT.`$`) | ||
| val algorithm = encryptionEventRoot | ||
| ?.getString(EventEntityFields.CONTENT)?.let { | ||
| encryptionContentAdapter.fromJson(it)?.algorithm | ||
| } | ||
|
|
||
| obj.setString(RoomSummaryEntityFields.E2E_ALGORITHM, algorithm) | ||
| obj.setBoolean(RoomSummaryEntityFields.IS_ENCRYPTED, encryptionEvent != null) | ||
| encryptionEventRoot?.getLong(EventEntityFields.ORIGIN_SERVER_TS)?.let { | ||
| obj.setLong(RoomSummaryEntityFields.ENCRYPTION_EVENT_TS, it) | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.