mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-23 19:26:17 +00:00
Removal final usage of VerifyResponseProcessor.
This commit is contained in:
committed by
Cody Henthorne
parent
bf46e5bc24
commit
f29d4f980a
@@ -6,7 +6,6 @@ import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import okio.ByteString.Companion.toByteString
|
||||
import org.signal.core.util.concurrent.safeBlockingGet
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.orNull
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair
|
||||
import org.signal.libsignal.protocol.SignalProtocolAddress
|
||||
import org.signal.libsignal.protocol.state.KyberPreKeyRecord
|
||||
@@ -20,13 +19,11 @@ import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.jobmanager.Job
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.registration.VerifyResponse
|
||||
import org.thoughtcrime.securesms.registration.VerifyResponseWithoutKbs
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
import org.whispersystems.signalservice.api.account.PniKeyDistributionRequest
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
||||
import org.whispersystems.signalservice.api.push.SignedPreKeyEntity
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse
|
||||
import org.whispersystems.signalservice.internal.push.KyberPreKeyEntity
|
||||
import org.whispersystems.signalservice.internal.push.OutgoingPushMessage
|
||||
import org.whispersystems.signalservice.internal.push.SyncMessage
|
||||
@@ -98,11 +95,10 @@ class PnpInitializeDevicesJob private constructor(parameters: Parameters) : Base
|
||||
|
||||
try {
|
||||
Log.i(TAG, "Initializing PNI for linked devices")
|
||||
val result: VerifyResponseWithoutKbs = initializeDevices(e164)
|
||||
.map(::VerifyResponseWithoutKbs)
|
||||
val result: NetworkResult<VerifyAccountResponse> = initializeDevices(e164)
|
||||
.safeBlockingGet()
|
||||
|
||||
result.error?.let { throw it }
|
||||
result.getCause()?.let { throw it }
|
||||
} catch (e: InterruptedException) {
|
||||
throw IOException("Retry", e)
|
||||
} catch (t: Throwable) {
|
||||
@@ -116,40 +112,34 @@ class PnpInitializeDevicesJob private constructor(parameters: Parameters) : Base
|
||||
}
|
||||
}
|
||||
|
||||
private fun initializeDevices(newE164: String): Single<ServiceResponse<VerifyResponse>> {
|
||||
private fun initializeDevices(newE164: String): Single<NetworkResult<VerifyAccountResponse>> {
|
||||
val accountManager = AppDependencies.signalServiceAccountManager
|
||||
val messageSender = AppDependencies.signalServiceMessageSender
|
||||
|
||||
return Single.fromCallable {
|
||||
var completed = false
|
||||
var attempts = 0
|
||||
lateinit var distributionResponse: ServiceResponse<VerifyAccountResponse>
|
||||
lateinit var distributionResponse: NetworkResult<VerifyAccountResponse>
|
||||
|
||||
while (!completed && attempts < 5) {
|
||||
val request = createInitializeDevicesRequest(
|
||||
newE164 = newE164
|
||||
)
|
||||
|
||||
distributionResponse = accountManager.distributePniKeys(request)
|
||||
distributionResponse = accountManager.registrationApi.distributePniKeys(request)
|
||||
|
||||
val possibleError: Throwable? = distributionResponse.applicationError.orNull()
|
||||
if (possibleError is MismatchedDevicesException) {
|
||||
messageSender.handleChangeNumberMismatchDevices(possibleError.mismatchedDevices)
|
||||
if (distributionResponse is NetworkResult.StatusCodeError &&
|
||||
distributionResponse.exception is MismatchedDevicesException
|
||||
) {
|
||||
messageSender.handleChangeNumberMismatchDevices((distributionResponse.exception as MismatchedDevicesException).mismatchedDevices)
|
||||
attempts++
|
||||
} else {
|
||||
completed = true
|
||||
}
|
||||
}
|
||||
|
||||
VerifyResponse.from(
|
||||
response = distributionResponse,
|
||||
masterKey = null,
|
||||
pin = null,
|
||||
aciPreKeyCollection = null,
|
||||
pniPreKeyCollection = null
|
||||
)
|
||||
distributionResponse
|
||||
}.subscribeOn(Schedulers.single())
|
||||
.onErrorReturn { t -> ServiceResponse.forExecutionError(t) }
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package org.thoughtcrime.securesms.registration
|
||||
|
||||
import org.whispersystems.signalservice.api.account.PreKeyCollection
|
||||
import org.whispersystems.signalservice.api.kbs.MasterKey
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse
|
||||
import org.whispersystems.signalservice.internal.push.VerifyAccountResponse
|
||||
|
||||
data class VerifyResponse(
|
||||
val verifyAccountResponse: VerifyAccountResponse,
|
||||
val masterKey: MasterKey?,
|
||||
val pin: String?,
|
||||
val aciPreKeyCollection: PreKeyCollection?,
|
||||
val pniPreKeyCollection: PreKeyCollection?
|
||||
) {
|
||||
companion object {
|
||||
fun from(
|
||||
response: ServiceResponse<VerifyAccountResponse>,
|
||||
masterKey: MasterKey?,
|
||||
pin: String?,
|
||||
aciPreKeyCollection: PreKeyCollection?,
|
||||
pniPreKeyCollection: PreKeyCollection?
|
||||
): ServiceResponse<VerifyResponse> {
|
||||
return if (response.result.isPresent) {
|
||||
ServiceResponse.forResult(VerifyResponse(response.result.get(), masterKey, pin, aciPreKeyCollection, pniPreKeyCollection), 200, null)
|
||||
} else {
|
||||
ServiceResponse.coerceError(response)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package org.thoughtcrime.securesms.registration
|
||||
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse
|
||||
import org.whispersystems.signalservice.internal.ServiceResponseProcessor
|
||||
import org.whispersystems.signalservice.internal.push.LockedException
|
||||
|
||||
/**
|
||||
* Process responses from attempting to verify an account for use in account registration.
|
||||
*/
|
||||
sealed class VerifyResponseProcessor(response: ServiceResponse<VerifyResponse>) : ServiceResponseProcessor<VerifyResponse>(response) {
|
||||
|
||||
public override fun authorizationFailed(): Boolean {
|
||||
return super.authorizationFailed()
|
||||
}
|
||||
|
||||
public override fun registrationLock(): Boolean {
|
||||
return super.registrationLock()
|
||||
}
|
||||
|
||||
public override fun rateLimit(): Boolean {
|
||||
return super.rateLimit()
|
||||
}
|
||||
|
||||
public override fun getError(): Throwable? {
|
||||
return super.getError()
|
||||
}
|
||||
|
||||
fun getLockedException(): LockedException {
|
||||
return error as LockedException
|
||||
}
|
||||
|
||||
/** True if the account has reglock enabled but all guesses have been exhausted, otherwise false. */
|
||||
abstract fun isRegistrationLockPresentAndSvrExhausted(): Boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify processor specific to verifying without needing to handle registration lock.
|
||||
*/
|
||||
class VerifyResponseWithoutKbs(response: ServiceResponse<VerifyResponse>) : VerifyResponseProcessor(response) {
|
||||
override fun isRegistrationLockPresentAndSvrExhausted(): Boolean {
|
||||
return registrationLock() && getLockedException().svr2Credentials == null
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ package org.whispersystems.signalservice.api.registration
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
import org.whispersystems.signalservice.api.account.AccountAttributes
|
||||
import org.whispersystems.signalservice.api.account.ChangePhoneNumberRequest
|
||||
import org.whispersystems.signalservice.api.account.PniKeyDistributionRequest
|
||||
import org.whispersystems.signalservice.api.account.PreKeyCollection
|
||||
import org.whispersystems.signalservice.internal.push.BackupV2AuthCheckResponse
|
||||
import org.whispersystems.signalservice.internal.push.BackupV3AuthCheckResponse
|
||||
@@ -135,4 +136,10 @@ class RegistrationApi(
|
||||
pushServiceSocket.changeNumber(requestBody)
|
||||
}
|
||||
}
|
||||
|
||||
fun distributePniKeys(requestBody: PniKeyDistributionRequest): NetworkResult<VerifyAccountResponse> {
|
||||
return NetworkResult.fromFetch {
|
||||
pushServiceSocket.distributePniKeys(requestBody)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user