From 36846301de0fbb2c5e645334a7beb1be5887147f Mon Sep 17 00:00:00 2001 From: Nicholas Tinsley Date: Fri, 26 Jul 2024 18:45:14 +0200 Subject: [PATCH] Add missing handling for sessions that are already verified. --- .../registration/data/RegistrationRepository.kt | 1 + .../registration/ui/RegistrationViewModel.kt | 7 +++++++ .../internal/push/PushServiceSocket.java | 16 +++++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/data/RegistrationRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/registration/data/RegistrationRepository.kt index bb2cd5bcaa..14a9cedbc9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/data/RegistrationRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/data/RegistrationRepository.kt @@ -384,6 +384,7 @@ object RegistrationRepository { */ suspend fun registerAccount(context: Context, sessionId: String?, registrationData: RegistrationData, pin: String? = null, masterKeyProducer: VerifyAccountRepository.MasterKeyProducer? = null): RegisterAccountResult = withContext(Dispatchers.IO) { + Log.v(TAG, "registerAccount()") val api: RegistrationApi = AccountManagerFactory.getInstance().createUnauthenticated(context, registrationData.e164, SignalServiceAddress.DEFAULT_DEVICE_ID, registrationData.password).registrationApi val universalUnidentifiedAccess: Boolean = TextSecurePreferences.isUniversalUnidentifiedAccess(context) diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/ui/RegistrationViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/registration/ui/RegistrationViewModel.kt index 50ae77b505..fb93f80d53 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/ui/RegistrationViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/ui/RegistrationViewModel.kt @@ -357,6 +357,12 @@ class RegistrationViewModel : ViewModel() { ) Log.d(TAG, "SMS code request network call completed.") + if (codeRequestResponse is AlreadyVerified) { + Log.d(TAG, "Got session was already verified when requesting SMS code.") + registerVerifiedSession(context, sessionId) + return + } + handleSessionStateResult(context, codeRequestResponse) if (codeRequestResponse is Success) { @@ -792,6 +798,7 @@ class RegistrationViewModel : ViewModel() { } private suspend fun registerVerifiedSession(context: Context, sessionId: String) { + Log.v(TAG, "registerVerifiedSession()") val registrationData = getRegistrationData() val registrationResponse: RegisterAccountResult = RegistrationRepository.registerAccount(context, sessionId, registrationData) handleRegistrationResult(context, registrationData, registrationResponse, false) diff --git a/libsignal-service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java b/libsignal-service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java index 13ca5d7b0f..731206568d 100644 --- a/libsignal-service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java +++ b/libsignal-service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java @@ -3005,11 +3005,14 @@ public class PushServiceSocket { Log.e(TAG, "Unable to read response body.", e); throw new NonSuccessfulResponseCodeException(409); } - if (response.pushChallengedRequired()) { + if (response.getVerified()) { + throw new AlreadyVerifiedException(); + } else if (response.pushChallengedRequired()) { throw new PushChallengeRequiredException(); } else if (response.captchaRequired()) { throw new CaptchaRequiredException(); } else { + Log.i(TAG, "Received 409 in reg session handler that is not verified, with required information: " + String.join(", ", response.getRequestedInformation())); throw new HttpConflictException(); } } else if (responseCode == 502) { @@ -3045,11 +3048,14 @@ public class PushServiceSocket { Log.e(TAG, "Unable to read response body.", e); throw new NonSuccessfulResponseCodeException(409); } - if (response.pushChallengedRequired()) { + if (response.getVerified()) { + throw new AlreadyVerifiedException(); + } else if (response.pushChallengedRequired()) { throw new PushChallengeRequiredException(); } else if (response.captchaRequired()) { throw new CaptchaRequiredException(); } else { + Log.i(TAG, "Received 409 in for reg code request that is not verified, with required information: " + String.join(", ", response.getRequestedInformation())); throw new HttpConflictException(); } } else if (responseCode == 418) { @@ -3087,11 +3093,14 @@ public class PushServiceSocket { Log.e(TAG, "Unable to read response body.", e); throw new NonSuccessfulResponseCodeException(409); } - if (response.pushChallengedRequired()) { + if (response.getVerified()) { + throw new AlreadyVerifiedException(); + } else if (response.pushChallengedRequired()) { throw new PushChallengeRequiredException(); } else if (response.captchaRequired()) { throw new CaptchaRequiredException(); } else { + Log.i(TAG, "Received 409 for patching reg session that is not verified, with required information: " + String.join(", ", response.getRequestedInformation())); throw new HttpConflictException(); } } @@ -3121,6 +3130,7 @@ public class PushServiceSocket { // Note: this explicitly requires Verified to be false throw new MustRequestNewCodeException(); } else { + Log.i(TAG, "Received 409 for reg code submission that is not verified, with required information: " + String.join(", ", sessionMetadata.getRequestedInformation())); throw new HttpConflictException(); } case 440: