BIT-2318: Master password leak (#1372)

This commit is contained in:
David Perez 2024-05-14 13:28:24 -05:00 committed by Álison Fernandes
parent ccf094ee9f
commit cbb2050f10

View file

@ -27,6 +27,7 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import javax.crypto.Cipher import javax.crypto.Cipher
import javax.inject.Inject import javax.inject.Inject
@ -39,12 +40,13 @@ private const val KEY_STATE = "state"
@Suppress("TooManyFunctions") @Suppress("TooManyFunctions")
@HiltViewModel @HiltViewModel
class VaultUnlockViewModel @Inject constructor( class VaultUnlockViewModel @Inject constructor(
private val savedStateHandle: SavedStateHandle,
private val authRepository: AuthRepository, private val authRepository: AuthRepository,
private val vaultRepo: VaultRepository, private val vaultRepo: VaultRepository,
private val biometricsEncryptionManager: BiometricsEncryptionManager, private val biometricsEncryptionManager: BiometricsEncryptionManager,
environmentRepo: EnvironmentRepository, environmentRepo: EnvironmentRepository,
savedStateHandle: SavedStateHandle,
) : BaseViewModel<VaultUnlockState, VaultUnlockEvent, VaultUnlockAction>( ) : BaseViewModel<VaultUnlockState, VaultUnlockEvent, VaultUnlockAction>(
// We load the state from the savedStateHandle for testing purposes.
initialState = savedStateHandle[KEY_STATE] ?: run { initialState = savedStateHandle[KEY_STATE] ?: run {
val userState = requireNotNull(authRepository.userStateFlow.value) val userState = requireNotNull(authRepository.userStateFlow.value)
val trustedDevice = userState.activeAccount.trustedDevice val trustedDevice = userState.activeAccount.trustedDevice
@ -81,9 +83,6 @@ class VaultUnlockViewModel @Inject constructor(
}, },
) { ) {
init { init {
stateFlow
.onEach { savedStateHandle[KEY_STATE] = it }
.launchIn(viewModelScope)
environmentRepo environmentRepo
.environmentStateFlow .environmentStateFlow
.onEach { environment -> .onEach { environment ->
@ -329,7 +328,8 @@ data class VaultUnlockState(
val email: String, val email: String,
val environmentUrl: String, val environmentUrl: String,
val dialog: VaultUnlockDialog?, val dialog: VaultUnlockDialog?,
val input: String, // We never want this saved since the input is sensitive data.
@IgnoredOnParcel val input: String = "",
val isBiometricsValid: Boolean, val isBiometricsValid: Boolean,
val isBiometricEnabled: Boolean, val isBiometricEnabled: Boolean,
val showAccountMenu: Boolean, val showAccountMenu: Boolean,