Enhance key sharing to respect matrix configuration
This commit is contained in:
parent
a9a7400fef
commit
d3a516b05d
|
@ -17,6 +17,7 @@
|
|||
package org.matrix.android.sdk.internal.crypto.algorithms.megolm
|
||||
|
||||
import dagger.Lazy
|
||||
import org.matrix.android.sdk.api.MatrixConfiguration
|
||||
import org.matrix.android.sdk.api.logger.LoggerTag
|
||||
import org.matrix.android.sdk.api.session.crypto.MXCryptoError
|
||||
import org.matrix.android.sdk.api.session.crypto.NewSessionListener
|
||||
|
@ -41,6 +42,7 @@ internal class MXMegolmDecryption(
|
|||
private val olmDevice: MXOlmDevice,
|
||||
private val outgoingKeyRequestManager: OutgoingKeyRequestManager,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val matrixConfiguration: MatrixConfiguration,
|
||||
private val liveEventManager: Lazy<StreamEventsManager>
|
||||
) : IMXDecrypting {
|
||||
|
||||
|
@ -247,7 +249,7 @@ internal class MXMegolmDecryption(
|
|||
forwardingCurve25519KeyChain = forwardingCurve25519KeyChain,
|
||||
keysClaimed = keysClaimed,
|
||||
exportFormat = exportFormat,
|
||||
sharedHistory = roomKeyContent.sharedHistory ?: false
|
||||
sharedHistory = roomKeyContent.getSharedKey()
|
||||
)
|
||||
|
||||
when (addSessionResult) {
|
||||
|
@ -298,7 +300,15 @@ internal class MXMegolmDecryption(
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if the some messages can be decrypted with a new session.
|
||||
* Returns boolean shared key flag, if enabled with respect to matrix configuration
|
||||
*/
|
||||
private fun RoomKeyContent.getSharedKey(): Boolean {
|
||||
if (!matrixConfiguration.cryptoConfig.shouldShareKeyHistory) return false
|
||||
return sharedHistory ?: false
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the some messages can be decrypted with a new session
|
||||
*
|
||||
* @param roomId the room id where the new Megolm session has been created for, may be null when importing from external sessions
|
||||
* @param senderKey the session sender key
|
||||
|
|
|
@ -27,6 +27,7 @@ import kotlinx.coroutines.launch
|
|||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.MatrixConfiguration
|
||||
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
|
||||
import org.matrix.android.sdk.api.auth.data.Credentials
|
||||
import org.matrix.android.sdk.api.crypto.MXCRYPTO_ALGORITHM_MEGOLM_BACKUP
|
||||
|
@ -120,6 +121,7 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||
private val updateKeysBackupVersionTask: UpdateKeysBackupVersionTask,
|
||||
// Task executor
|
||||
private val taskExecutor: TaskExecutor,
|
||||
private val matrixConfiguration: MatrixConfiguration,
|
||||
private val inboundGroupSessionStore: InboundGroupSessionStore,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val cryptoCoroutineScope: CoroutineScope
|
||||
|
@ -1457,7 +1459,7 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||
},
|
||||
forwardedCount = olmInboundGroupSessionWrapper.sessionData.forwardingCurve25519KeyChain.orEmpty().size,
|
||||
isVerified = device?.isVerified == true,
|
||||
sharedHistory = olmInboundGroupSessionWrapper.sessionData.sharedHistory,
|
||||
sharedHistory = olmInboundGroupSessionWrapper.getSharedKey(),
|
||||
sessionData = mapOf(
|
||||
"ciphertext" to encryptedSessionBackupData.mCipherText,
|
||||
"mac" to encryptedSessionBackupData.mMac,
|
||||
|
@ -1466,6 +1468,14 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns boolean shared key flag, if enabled with respect to matrix configuration
|
||||
*/
|
||||
private fun MXInboundMegolmSessionWrapper.getSharedKey(): Boolean {
|
||||
if (!matrixConfiguration.cryptoConfig.shouldShareKeyHistory) return false
|
||||
return sessionData.sharedHistory
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@WorkerThread
|
||||
fun decryptKeyBackupData(keyBackupData: KeyBackupData, sessionId: String, roomId: String, decryption: OlmPkDecryption): MegolmSessionData? {
|
||||
|
|
Loading…
Reference in New Issue