Handle SVR exceptions in Registration V2.
This commit is contained in:
parent
303100bb6b
commit
b99c2165fa
6 changed files with 45 additions and 34 deletions
|
@ -38,6 +38,7 @@ import org.thoughtcrime.securesms.keyvalue.PhoneNumberPrivacyValues
|
|||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.notifications.NotificationIds
|
||||
import org.thoughtcrime.securesms.pin.SvrRepository
|
||||
import org.thoughtcrime.securesms.pin.SvrWrongPinException
|
||||
import org.thoughtcrime.securesms.push.AccountManagerFactory
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
|
@ -55,6 +56,7 @@ import org.thoughtcrime.securesms.service.DirectoryRefreshListener
|
|||
import org.thoughtcrime.securesms.service.RotateSignedPreKeyListener
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
import org.whispersystems.signalservice.api.SvrNoDataException
|
||||
import org.whispersystems.signalservice.api.account.AccountAttributes
|
||||
import org.whispersystems.signalservice.api.account.PreKeyCollection
|
||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess
|
||||
|
@ -383,7 +385,17 @@ object RegistrationRepository {
|
|||
val universalUnidentifiedAccess: Boolean = TextSecurePreferences.isUniversalUnidentifiedAccess(context)
|
||||
val unidentifiedAccessKey: ByteArray = UnidentifiedAccess.deriveAccessKeyFrom(registrationData.profileKey)
|
||||
|
||||
val masterKey: MasterKey? = masterKeyProducer?.produceMasterKey()
|
||||
val masterKey: MasterKey?
|
||||
try {
|
||||
masterKey = masterKeyProducer?.produceMasterKey()
|
||||
} catch (e: SvrNoDataException) {
|
||||
return@withContext RegisterAccountResult.SvrNoData(e)
|
||||
} catch (e: SvrWrongPinException) {
|
||||
return@withContext RegisterAccountResult.SvrWrongPin(e)
|
||||
} catch (e: IOException) {
|
||||
return@withContext RegisterAccountResult.UnknownError(e)
|
||||
}
|
||||
|
||||
val registrationLock: String? = masterKey?.deriveRegistrationLock()
|
||||
|
||||
val accountAttributes = AccountAttributes(
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
|
||||
package org.thoughtcrime.securesms.registration.v2.data.network
|
||||
|
||||
import org.thoughtcrime.securesms.pin.SvrWrongPinException
|
||||
import org.thoughtcrime.securesms.registration.v2.data.RegistrationRepository
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
import org.whispersystems.signalservice.api.SvrNoDataException
|
||||
import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException
|
||||
import org.whispersystems.signalservice.api.push.exceptions.IncorrectRegistrationRecoveryPasswordException
|
||||
import org.whispersystems.signalservice.api.push.exceptions.MalformedRequestException
|
||||
|
@ -61,4 +63,9 @@ sealed class RegisterAccountResult(cause: Throwable?) : RegistrationResult(cause
|
|||
class AttemptsExhausted(cause: Throwable) : RegisterAccountResult(cause)
|
||||
class RegistrationLocked(cause: Throwable, val timeRemaining: Long, val svr2Credentials: AuthCredentials?) : RegisterAccountResult(cause)
|
||||
class UnknownError(cause: Throwable) : RegisterAccountResult(cause)
|
||||
|
||||
class SvrNoData(cause: SvrNoDataException) : RegisterAccountResult(cause)
|
||||
class SvrWrongPin(cause: SvrWrongPinException) : RegisterAccountResult(cause) {
|
||||
val triesRemaining = cause.triesRemaining
|
||||
}
|
||||
}
|
||||
|
|
|
@ -507,7 +507,12 @@ class RegistrationV2ViewModel : ViewModel() {
|
|||
is RegisterAccountResult.RegistrationLocked -> {
|
||||
Log.i(TAG, "Account is registration locked!", registrationResult.getCause())
|
||||
}
|
||||
is RegisterAccountResult.SvrWrongPin -> {
|
||||
Log.i(TAG, "Received wrong SVR PIN response! ${registrationResult.triesRemaining} tries remaining.")
|
||||
updateSvrTriesRemaining(registrationResult.triesRemaining)
|
||||
}
|
||||
|
||||
is RegisterAccountResult.SvrNoData,
|
||||
is RegisterAccountResult.AttemptsExhausted,
|
||||
is RegisterAccountResult.RateLimited,
|
||||
is RegisterAccountResult.AuthorizationFailed,
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.thoughtcrime.securesms.jobs.StorageSyncJob
|
|||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.lock.v2.PinKeyboardType
|
||||
import org.thoughtcrime.securesms.lock.v2.SvrConstants
|
||||
import org.thoughtcrime.securesms.pin.SvrWrongPinException
|
||||
import org.thoughtcrime.securesms.registration.fragments.RegistrationViewDelegate.setDebugLogSubmitMultiTapView
|
||||
import org.thoughtcrime.securesms.registration.v2.data.network.RegisterAccountResult
|
||||
import org.thoughtcrime.securesms.registration.v2.data.network.RegistrationResult
|
||||
|
@ -41,7 +40,6 @@ import org.thoughtcrime.securesms.util.FeatureFlags
|
|||
import org.thoughtcrime.securesms.util.SupportEmailUtil
|
||||
import org.thoughtcrime.securesms.util.ViewUtil
|
||||
import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
||||
import org.whispersystems.signalservice.api.SvrNoDataException
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
@ -154,21 +152,9 @@ class RegistrationLockV2Fragment : LoggingFragment(R.layout.fragment_registratio
|
|||
Toast.makeText(requireContext(), "Reg lock!", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
else -> when (val cause = requestResult.getCause()) {
|
||||
is SvrWrongPinException -> {
|
||||
Log.w(TAG, "TODO figure out which Result class this results in and create a concrete class.")
|
||||
onIncorrectKbsRegistrationLockPin(cause.triesRemaining)
|
||||
}
|
||||
|
||||
is SvrNoDataException -> {
|
||||
Log.w(TAG, "TODO figure out which Result class this results in and create a concrete class.")
|
||||
navigateToAccountLocked()
|
||||
}
|
||||
|
||||
else -> {
|
||||
Log.w(TAG, "Unable to verify code with registration lock", cause)
|
||||
onError()
|
||||
}
|
||||
else -> {
|
||||
Log.w(TAG, "Unable to verify code with registration lock", requestResult.getCause())
|
||||
onError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -185,21 +171,12 @@ class RegistrationLockV2Fragment : LoggingFragment(R.layout.fragment_registratio
|
|||
Toast.makeText(requireContext(), "Reg lock!", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
else -> when (val cause = result.getCause()) {
|
||||
is SvrWrongPinException -> {
|
||||
Log.w(TAG, "TODO figure out which Result class this results in and create a concrete class.")
|
||||
onIncorrectKbsRegistrationLockPin(cause.triesRemaining)
|
||||
}
|
||||
is RegisterAccountResult.SvrWrongPin -> onIncorrectKbsRegistrationLockPin(result.triesRemaining)
|
||||
is RegisterAccountResult.SvrNoData -> navigateToAccountLocked()
|
||||
|
||||
is SvrNoDataException -> {
|
||||
Log.w(TAG, "TODO figure out which Result class this results in and create a concrete class.")
|
||||
navigateToAccountLocked()
|
||||
}
|
||||
|
||||
else -> {
|
||||
Log.w(TAG, "Unable to register account with registration lock", cause)
|
||||
onError()
|
||||
}
|
||||
else -> {
|
||||
Log.w(TAG, "Unable to register account with registration lock", result.getCause())
|
||||
onError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -268,6 +268,12 @@ class ReRegisterWithPinV2Fragment : LoggingFragment(R.layout.fragment_registrati
|
|||
|
||||
is RegisterAccountResult.AttemptsExhausted,
|
||||
is RegisterAccountResult.RateLimited -> presentRateLimitedDialog()
|
||||
|
||||
is RegisterAccountResult.SvrNoData -> onAccountLocked()
|
||||
is RegisterAccountResult.SvrWrongPin -> {
|
||||
reRegisterViewModel.markIncorrectGuess()
|
||||
reRegisterViewModel.markAsRemoteVerification()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package org.thoughtcrime.securesms.registration.v2.ui.reregisterwithpin
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.asLiveData
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import org.signal.core.util.logging.Log
|
||||
|
@ -17,13 +16,18 @@ class ReRegisterWithPinV2ViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
private val store = MutableStateFlow(ReRegisterWithPinV2State())
|
||||
val uiState = store.asLiveData()
|
||||
|
||||
val isLocalVerification: Boolean
|
||||
get() = store.value.isLocalVerification
|
||||
val hasIncorrectGuess: Boolean
|
||||
get() = store.value.hasIncorrectGuess
|
||||
|
||||
fun markAsRemoteVerification() {
|
||||
store.update {
|
||||
it.copy(isLocalVerification = false)
|
||||
}
|
||||
}
|
||||
|
||||
fun markIncorrectGuess() {
|
||||
store.update {
|
||||
it.copy(hasIncorrectGuess = true)
|
||||
|
|
Loading…
Add table
Reference in a new issue