mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 18:05:36 +03:00
Add MXCryptoConfig flag for key history sharing
Add shared_history flag to sessionBackupData
This commit is contained in:
parent
fb352ffa38
commit
a9a7400fef
5 changed files with 29 additions and 5 deletions
|
@ -38,4 +38,10 @@ data class MXCryptoConfig constructor(
|
|||
* You can limit request only to your sessions by turning this setting to `true`
|
||||
*/
|
||||
val limitRoomKeyRequestsToMyDevices: Boolean = false,
|
||||
|
||||
/**
|
||||
* Flag that indicates whether or not key history will be shared to invited
|
||||
* users with respect to room visibility
|
||||
*/
|
||||
val shouldShareKeyHistory: Boolean = true,
|
||||
)
|
||||
|
|
|
@ -1429,7 +1429,8 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||
"sender_key" to sessionData.senderKey,
|
||||
"sender_claimed_keys" to sessionData.senderClaimedKeys,
|
||||
"forwarding_curve25519_key_chain" to (sessionData.forwardingCurve25519KeyChain.orEmpty()),
|
||||
"session_key" to sessionData.sessionKey
|
||||
"session_key" to sessionData.sessionKey,
|
||||
"org.matrix.msc3061.shared_history" to sessionData.sharedHistory
|
||||
)
|
||||
|
||||
val json = MoshiProvider.providesMoshi()
|
||||
|
@ -1456,7 +1457,7 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||
},
|
||||
forwardedCount = olmInboundGroupSessionWrapper.sessionData.forwardingCurve25519KeyChain.orEmpty().size,
|
||||
isVerified = device?.isVerified == true,
|
||||
|
||||
sharedHistory = olmInboundGroupSessionWrapper.sessionData.sharedHistory,
|
||||
sessionData = mapOf(
|
||||
"ciphertext" to encryptedSessionBackupData.mCipherText,
|
||||
"mac" to encryptedSessionBackupData.mMac,
|
||||
|
|
|
@ -50,5 +50,12 @@ internal data class KeyBackupData(
|
|||
* Algorithm-dependent data.
|
||||
*/
|
||||
@Json(name = "session_data")
|
||||
val sessionData: JsonDict
|
||||
val sessionData: JsonDict,
|
||||
|
||||
/**
|
||||
* Flag that indicates whether or not the current inboundSession will be shared to
|
||||
* invited users to decrypt past messages
|
||||
*/
|
||||
@Json(name = "org.matrix.msc3061.shared_history")
|
||||
val sharedHistory: Boolean = false
|
||||
)
|
||||
|
|
|
@ -26,6 +26,7 @@ import io.realm.RealmConfiguration
|
|||
import io.realm.Sort
|
||||
import io.realm.kotlin.createObject
|
||||
import io.realm.kotlin.where
|
||||
import org.matrix.android.sdk.api.MatrixConfiguration
|
||||
import org.matrix.android.sdk.api.crypto.MXCRYPTO_ALGORITHM_MEGOLM
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.logger.LoggerTag
|
||||
|
@ -111,6 +112,7 @@ internal class RealmCryptoStore @Inject constructor(
|
|||
private val crossSigningKeysMapper: CrossSigningKeysMapper,
|
||||
@UserId private val userId: String,
|
||||
@DeviceId private val deviceId: String?,
|
||||
private val matrixConfiguration: MatrixConfiguration,
|
||||
private val clock: Clock,
|
||||
) : IMXCryptoStore {
|
||||
|
||||
|
@ -658,6 +660,7 @@ internal class RealmCryptoStore @Inject constructor(
|
|||
}
|
||||
|
||||
override fun shouldShareHistory(roomId: String): Boolean {
|
||||
if (!matrixConfiguration.cryptoConfig.shouldShareKeyHistory) return false
|
||||
return doWithRealm(realmConfiguration) {
|
||||
CryptoRoomEntity.getById(it, roomId)?.shouldShareHistory
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import dagger.assisted.AssistedFactory
|
|||
import dagger.assisted.AssistedInject
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import org.matrix.android.sdk.api.MatrixConfiguration
|
||||
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
||||
import org.matrix.android.sdk.api.session.room.members.MembershipService
|
||||
|
@ -57,6 +58,7 @@ internal class DefaultMembershipService @AssistedInject constructor(
|
|||
private val cryptoService: CryptoService,
|
||||
@UserId
|
||||
private val userId: String,
|
||||
private val matrixConfiguration: MatrixConfiguration,
|
||||
private val queryStringValueProcessor: QueryStringValueProcessor
|
||||
) : MembershipService {
|
||||
|
||||
|
@ -144,13 +146,18 @@ internal class DefaultMembershipService @AssistedInject constructor(
|
|||
}
|
||||
|
||||
override suspend fun invite(userId: String, reason: String?) {
|
||||
sendShareHistoryKeysIfNeeded(userId)
|
||||
val params = InviteTask.Params(roomId, userId, reason)
|
||||
inviteTask.execute(params)
|
||||
}
|
||||
|
||||
private suspend fun sendShareHistoryKeysIfNeeded(userId: String) {
|
||||
if (!matrixConfiguration.cryptoConfig.shouldShareKeyHistory) return
|
||||
// TODO not sure it's the right way to get the latest messages in a room
|
||||
val sessionInfo = Realm.getInstance(monarchy.realmConfiguration).use {
|
||||
ChunkEntity.findLatestSessionInfo(it, roomId)
|
||||
}
|
||||
cryptoService.sendSharedHistoryKeys(roomId, userId, sessionInfo)
|
||||
val params = InviteTask.Params(roomId, userId, reason)
|
||||
inviteTask.execute(params)
|
||||
}
|
||||
|
||||
override suspend fun invite3pid(threePid: ThreePid) {
|
||||
|
|
Loading…
Reference in a new issue