Fix handling non-existent SVR enclaves.

This commit is contained in:
Greyson Parrelli
2025-11-04 13:59:19 -05:00
parent 2b2e3e1d02
commit 680d436038
6 changed files with 39 additions and 11 deletions

View File

@@ -103,6 +103,9 @@ interface SecureValueRecovery {
/** The PIN was incorrect. Includes the number of attempts the user has remaining. */
data class PinMismatch(val triesRemaining: Int) : RestoreResponse()
/** The enclave no longer exists */
data object EnclaveNotFound : RestoreResponse()
/** There as a network error. Not a bad response, but rather interference or some other inability to make a network request. */
data class NetworkError(val exception: IOException) : RestoreResponse()

View File

@@ -83,7 +83,11 @@ class SecureValueRecoveryV2(
DeleteResponse.Success
} catch (e: NonSuccessfulResponseCodeException) {
Log.w(TAG, "[Delete] Failed with a non-successful response code exception!", e)
DeleteResponse.ApplicationError(e)
if (e.code == 404) {
DeleteResponse.EnclaveNotFound
} else {
DeleteResponse.ApplicationError(e)
}
} catch (e: IOException) {
Log.w(TAG, "[Delete] Failed with a network exception!", e)
DeleteResponse.NetworkError(e)
@@ -149,7 +153,11 @@ class SecureValueRecoveryV2(
}
} catch (e: NonSuccessfulResponseCodeException) {
Log.w(TAG, "[Restore] Failed with a non-successful response code exception!", e)
RestoreResponse.ApplicationError(e)
if (e.code == 404) {
RestoreResponse.EnclaveNotFound
} else {
RestoreResponse.ApplicationError(e)
}
} catch (e: IOException) {
Log.w(TAG, "[Restore] Failed with a network exception!", e)
RestoreResponse.NetworkError(e)
@@ -212,7 +220,11 @@ class SecureValueRecoveryV2(
}
} catch (e: NonSuccessfulResponseCodeException) {
Log.w(TAG, "[Set] Failed with a non-successful response code exception!", e)
BackupResponse.ApplicationError(e)
if (e.code == 404) {
BackupResponse.EnclaveNotFound
} else {
BackupResponse.ApplicationError(e)
}
} catch (e: IOException) {
Log.w(TAG, "[Set] Failed with a network exception!", e)
BackupResponse.NetworkError(e)

View File

@@ -149,7 +149,13 @@ internal class Svr2Socket(
}
override fun onFailure(webSocket: WebSocket, t: Throwable, response: OkHttpResponse?) {
if (emitError(IOException(t))) {
val exception = if (t.message?.contains("404") == true) {
NonSuccessfulResponseCodeException(404)
} else {
IOException(t)
}
if (emitError(exception)) {
Log.w(TAG, "[onFailure] response? " + (response != null), t)
stage.set(Stage.FAILED)
webSocket.close(1000, "OK")