Rotate our session when there is a room history visibility change since the last outboundSession
This commit is contained in:
parent
d6358dcb16
commit
497f7cf044
@ -172,6 +172,8 @@ internal class MXMegolmEncryption(
|
|||||||
if (session == null ||
|
if (session == null ||
|
||||||
// Need to make a brand new session?
|
// Need to make a brand new session?
|
||||||
session.needsRotation(sessionRotationPeriodMsgs, sessionRotationPeriodMs) ||
|
session.needsRotation(sessionRotationPeriodMsgs, sessionRotationPeriodMs) ||
|
||||||
|
// Is there a room history visibility change since the last outboundSession
|
||||||
|
cryptoStore.needsRotationDueToVisibilityChange(roomId) ||
|
||||||
// Determine if we have shared with anyone we shouldn't have
|
// Determine if we have shared with anyone we shouldn't have
|
||||||
session.sharedWithTooManyDevices(devicesInRoom)) {
|
session.sharedWithTooManyDevices(devicesInRoom)) {
|
||||||
Timber.tag(loggerTag.value).d("roomId:$roomId Starting new megolm session because we need to rotate.")
|
Timber.tag(loggerTag.value).d("roomId:$roomId Starting new megolm session because we need to rotate.")
|
||||||
|
@ -341,7 +341,14 @@ internal interface IMXCryptoStore {
|
|||||||
fun storeCurrentOutboundGroupSessionForRoom(roomId: String, outboundGroupSession: OlmOutboundGroupSession?)
|
fun storeCurrentOutboundGroupSessionForRoom(roomId: String, outboundGroupSession: OlmOutboundGroupSession?)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an inbound group session.
|
* Returns true if there is a room history visibility change since the latest outbound
|
||||||
|
* session. Specifically when the room's history visibility setting changes to
|
||||||
|
* world_readable or shared from invited or joined, or changes to invited or joined from world_readable or shared
|
||||||
|
*/
|
||||||
|
fun needsRotationDueToVisibilityChange(roomId: String): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an inbound group session
|
||||||
*
|
*
|
||||||
* @param sessionId the session identifier.
|
* @param sessionId the session identifier.
|
||||||
* @param senderKey the base64-encoded curve25519 key of the sender.
|
* @param senderKey the base64-encoded curve25519 key of the sender.
|
||||||
|
@ -826,6 +826,8 @@ internal class RealmCryptoStore @Inject constructor(
|
|||||||
if (outboundGroupSession != null) {
|
if (outboundGroupSession != null) {
|
||||||
val info = realm.createObject(OutboundGroupSessionInfoEntity::class.java).apply {
|
val info = realm.createObject(OutboundGroupSessionInfoEntity::class.java).apply {
|
||||||
creationTime = clock.epochMillis()
|
creationTime = clock.epochMillis()
|
||||||
|
// Store the room history visibility on the outbound session creation
|
||||||
|
shouldShareHistory = entity.shouldShareHistory
|
||||||
putOutboundGroupSession(outboundGroupSession)
|
putOutboundGroupSession(outboundGroupSession)
|
||||||
}
|
}
|
||||||
entity.outboundSessionInfo = info
|
entity.outboundSessionInfo = info
|
||||||
@ -834,6 +836,14 @@ internal class RealmCryptoStore @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun needsRotationDueToVisibilityChange(roomId: String): Boolean {
|
||||||
|
return doWithRealm(realmConfiguration) { realm ->
|
||||||
|
CryptoRoomEntity.getById(realm, roomId)?.let { entity ->
|
||||||
|
entity.shouldShareHistory != entity.outboundSessionInfo?.shouldShareHistory
|
||||||
|
}
|
||||||
|
} ?: false
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: the result will be only use to export all the keys and not to use the OlmInboundGroupSessionWrapper2,
|
* Note: the result will be only use to export all the keys and not to use the OlmInboundGroupSessionWrapper2,
|
||||||
* so there is no need to use or update `inboundGroupSessionToRelease` for native memory management.
|
* so there is no need to use or update `inboundGroupSessionToRelease` for native memory management.
|
||||||
|
@ -24,7 +24,8 @@ import timber.log.Timber
|
|||||||
|
|
||||||
internal open class OutboundGroupSessionInfoEntity(
|
internal open class OutboundGroupSessionInfoEntity(
|
||||||
var serializedOutboundSessionData: String? = null,
|
var serializedOutboundSessionData: String? = null,
|
||||||
var creationTime: Long? = null
|
var creationTime: Long? = null,
|
||||||
|
var shouldShareHistory: Boolean = false
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
|
|
||||||
fun getOutboundGroupSession(): OlmOutboundGroupSession? {
|
fun getOutboundGroupSession(): OlmOutboundGroupSession? {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user