mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-25 05:27:42 +00:00
Support multiple sequential captcha challenges.
This commit is contained in:
@@ -8,6 +8,7 @@ import org.whispersystems.signalservice.api.push.exceptions.MustRequestNewCodeEx
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NoSuchSessionException
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NonNormalizedPhoneNumberException
|
||||
import org.whispersystems.signalservice.api.push.exceptions.RateLimitException
|
||||
import org.whispersystems.signalservice.api.push.exceptions.TokenNotAcceptedException
|
||||
import org.whispersystems.signalservice.api.util.Preconditions
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse
|
||||
import org.whispersystems.signalservice.internal.ServiceResponseProcessor
|
||||
@@ -41,6 +42,10 @@ sealed class RegistrationSessionProcessor(response: ServiceResponse<Registration
|
||||
return PUSH_CHALLENGE_KEY == getChallenge()
|
||||
}
|
||||
|
||||
fun isTokenRejected(): Boolean {
|
||||
return error is TokenNotAcceptedException
|
||||
}
|
||||
|
||||
fun isImpossibleNumber(): Boolean {
|
||||
return error is ImpossiblePhoneNumberException
|
||||
}
|
||||
|
||||
@@ -299,6 +299,9 @@ public final class EnterPhoneNumberFragment extends LoggingFragment implements R
|
||||
String.format(getString(R.string.RegistrationActivity_the_number_you_specified_s_is_invalid), viewModel.getNumber().getFullFormattedNumber()));
|
||||
} else if (processor.isNonNormalizedNumber()) {
|
||||
handleNonNormalizedNumberError(processor.getOriginalNumber(), processor.getNormalizedNumber(), mode);
|
||||
} else if (processor.isTokenRejected()) {
|
||||
Log.i(TAG, "The server did not accept the information.", processor.getError());
|
||||
showErrorDialog(register.getContext(), getString(R.string.RegistrationActivity_we_need_to_verify_that_youre_human));
|
||||
} else {
|
||||
Log.i(TAG, "Unknown error during verification code request", processor.getError());
|
||||
showErrorDialog(register.getContext(), getString(R.string.RegistrationActivity_unable_to_connect_to_service));
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.google.i18n.phonenumbers.NumberParseException;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.Phonenumber;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.pin.KbsRepository;
|
||||
import org.thoughtcrime.securesms.pin.TokenData;
|
||||
@@ -36,6 +37,8 @@ import io.reactivex.rxjava3.core.Single;
|
||||
*/
|
||||
public abstract class BaseRegistrationViewModel extends ViewModel {
|
||||
|
||||
private static final String TAG = Log.tag(BaseRegistrationViewModel.class);
|
||||
|
||||
private static final String STATE_NUMBER = "NUMBER";
|
||||
private static final String STATE_REGISTRATION_SECRET = "REGISTRATION_SECRET";
|
||||
private static final String STATE_VERIFICATION_CODE = "TEXT_CODE_ENTERED";
|
||||
@@ -280,10 +283,14 @@ public abstract class BaseRegistrationViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
if (hasCaptchaToken() && processor.captchaRequired()) {
|
||||
return verifyAccountRepository.verifyCaptcha(sessionId, Objects.requireNonNull(getCaptchaToken()), e164, getRegistrationSecret())
|
||||
Log.d(TAG, "Submitting completed captcha challenge");
|
||||
final String captcha = Objects.requireNonNull(getCaptchaToken());
|
||||
clearCaptchaResponse();
|
||||
return verifyAccountRepository.verifyCaptcha(sessionId, captcha, e164, getRegistrationSecret())
|
||||
.map(RegistrationSessionProcessor.RegistrationSessionProcessorForSession::new);
|
||||
} else {
|
||||
String challenge = processor.getChallenge();
|
||||
Log.d(TAG, "Handling challenge of type " + challenge);
|
||||
if (challenge != null) {
|
||||
switch (challenge) {
|
||||
case RegistrationSessionProcessor.PUSH_CHALLENGE_KEY:
|
||||
|
||||
Reference in New Issue
Block a user