Rotate MRBK when rotating AEP.

This commit is contained in:
Greyson Parrelli
2025-07-30 09:59:16 -04:00
committed by GitHub
parent faecbf5ea9
commit 90c381f0ba
5 changed files with 37 additions and 16 deletions

View File

@@ -15,6 +15,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.signal.core.util.concurrent.SignalDispatchers
import org.thoughtcrime.securesms.backup.v2.BackupRepository
import org.thoughtcrime.securesms.backup.v2.StagedBackupKeyRotations
import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.jobs.RestoreOptimizedMediaJob
import org.thoughtcrime.securesms.keyvalue.SignalStore
@@ -32,13 +33,14 @@ class BackupKeyDisplayViewModel : ViewModel(), BackupKeyCredentialManagerHandler
viewModelScope.launch {
_uiState.update { it.copy(rotationState = BackupKeyRotationState.GENERATING_KEY) }
val stagedAEP = withContext(SignalDispatchers.IO) {
BackupRepository.stageAEPKeyRotation()
val stagedKeyRotations = withContext(SignalDispatchers.IO) {
BackupRepository.stageBackupKeyRotations()
}
_uiState.update {
it.copy(
accountEntropyPool = stagedAEP,
accountEntropyPool = stagedKeyRotations.aep,
stagedKeyRotations = stagedKeyRotations,
rotationState = BackupKeyRotationState.USER_VERIFICATION
)
}
@@ -49,8 +51,10 @@ class BackupKeyDisplayViewModel : ViewModel(), BackupKeyCredentialManagerHandler
viewModelScope.launch {
_uiState.update { it.copy(rotationState = BackupKeyRotationState.COMMITTING_KEY) }
val keyRotations = _uiState.value.stagedKeyRotations ?: error("No key rotations to commit!")
withContext(SignalDispatchers.IO) {
BackupRepository.commitAEPKeyRotation(_uiState.value.accountEntropyPool)
BackupRepository.commitAEPKeyRotation(keyRotations)
}
_uiState.update { it.copy(rotationState = BackupKeyRotationState.FINISHED) }
@@ -68,7 +72,8 @@ data class BackupKeyDisplayUiState(
val accountEntropyPool: AccountEntropyPool = SignalStore.account.accountEntropyPool,
val keySaveState: BackupKeySaveState? = null,
val isOptimizedStorageEnabled: Boolean = SignalStore.backup.optimizeStorage,
val rotationState: BackupKeyRotationState = BackupKeyRotationState.NOT_STARTED
val rotationState: BackupKeyRotationState = BackupKeyRotationState.NOT_STARTED,
val stagedKeyRotations: StagedBackupKeyRotations? = null
)
enum class BackupKeyRotationState {