-
Notifications
You must be signed in to change notification settings - Fork 768
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
Defensive coding to ensure encryption when room was once e2e #5136
Changes from all commits
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 @@ | ||
Defensive coding to ensure encryption when room was once e2e |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.internal.crypto.store.db.migration | ||
|
||
import io.realm.DynamicRealm | ||
import org.matrix.android.sdk.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM | ||
import org.matrix.android.sdk.internal.crypto.store.db.model.CryptoRoomEntityFields | ||
import org.matrix.android.sdk.internal.util.database.RealmMigrator | ||
|
||
// Version 14L Update the way we remember key sharing | ||
class MigrateCryptoTo015(realm: DynamicRealm) : RealmMigrator(realm, 15) { | ||
|
||
override fun doMigrate(realm: DynamicRealm) { | ||
realm.schema.get("CryptoRoomEntity") | ||
?.addField(CryptoRoomEntityFields.WAS_ENCRYPTED_ONCE, Boolean::class.java) | ||
?.setNullable(CryptoRoomEntityFields.WAS_ENCRYPTED_ONCE, true) | ||
?.transform { | ||
val currentAlgorithm = it.getString(CryptoRoomEntityFields.ALGORITHM) | ||
it.set(CryptoRoomEntityFields.WAS_ENCRYPTED_ONCE, currentAlgorithm == MXCRYPTO_ALGORITHM_MEGOLM) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ import org.matrix.android.sdk.api.util.Cancelable | |
import org.matrix.android.sdk.api.util.CancelableBag | ||
import org.matrix.android.sdk.api.util.JsonDict | ||
import org.matrix.android.sdk.api.util.NoOpCancellable | ||
import org.matrix.android.sdk.internal.crypto.CryptoSessionInfoProvider | ||
import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore | ||
import org.matrix.android.sdk.internal.di.SessionId | ||
import org.matrix.android.sdk.internal.di.WorkManagerProvider | ||
import org.matrix.android.sdk.internal.session.content.UploadContentWorker | ||
|
@@ -66,7 +66,7 @@ internal class DefaultSendService @AssistedInject constructor( | |
private val workManagerProvider: WorkManagerProvider, | ||
@SessionId private val sessionId: String, | ||
private val localEchoEventFactory: LocalEchoEventFactory, | ||
private val cryptoSessionInfoProvider: CryptoSessionInfoProvider, | ||
private val cryptoStore: IMXCryptoStore, | ||
private val taskExecutor: TaskExecutor, | ||
private val localEchoRepository: LocalEchoRepository, | ||
private val eventSenderProcessor: EventSenderProcessor, | ||
|
@@ -303,7 +303,7 @@ internal class DefaultSendService @AssistedInject constructor( | |
private fun internalSendMedia(allLocalEchoes: List<Event>, attachment: ContentAttachmentData, compressBeforeSending: Boolean): Cancelable { | ||
val cancelableBag = CancelableBag() | ||
|
||
allLocalEchoes.groupBy { cryptoSessionInfoProvider.isRoomEncrypted(it.roomId!!) } | ||
allLocalEchoes.groupBy { cryptoStore.roomWasOnceEncrypted(it.roomId!!) } | ||
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. We still have 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. Yes it's a private function, so acceptable :/ |
||
.apply { | ||
keys.forEach { isRoomEncrypted -> | ||
// Should never be empty | ||
|
@@ -334,7 +334,7 @@ internal class DefaultSendService @AssistedInject constructor( | |
} | ||
|
||
private fun sendEvent(event: Event): Cancelable { | ||
return eventSenderProcessor.postEvent(event, cryptoSessionInfoProvider.isRoomEncrypted(event.roomId!!)) | ||
return eventSenderProcessor.postEvent(event) | ||
} | ||
|
||
private fun createLocalEcho(event: Event) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment need to be updated (or removed). I can delete it on develop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(95c00a1)