1
1
mirror of https://github.com/Yubico/yubioath-flutter.git synced 2025-01-03 07:34:10 +03:00

handle IO exceptions correctly

This commit is contained in:
Adam Velebil 2024-09-10 19:31:06 +02:00
parent a6038cad6e
commit 827c95f72b
No known key found for this signature in database
GPG Key ID: C9B1E4A3CBBD2E10
4 changed files with 36 additions and 9 deletions
android/app/src/main/kotlin/com/yubico/authenticator
lib/app/views

View File

@ -42,6 +42,14 @@ class FidoConnectionHelper(private val deviceManager: DeviceManager) {
return requestHandled
}
fun failPending(e: Exception) {
pendingAction?.let { action ->
logger.error("Failing pending action with {}", e.message)
action.invoke(Result.failure(e))
pendingAction = null
}
}
fun cancelPending() {
pendingAction?.let { action ->
action.invoke(Result.failure(CancellationException()))

View File

@ -210,8 +210,13 @@ class FidoManager(
// something went wrong, try to get DeviceInfo from any available connection type
logger.error("Failure when processing YubiKey: ", e)
// Clear any cached FIDO state
fidoViewModel.clearSessionState()
connectionHelper.failPending(e)
if (e !is IOException) {
// we don't clear the session on IOExceptions so that the session is ready for
// a possible re-run of a failed action.
fidoViewModel.clearSessionState()
}
throw e
}

View File

@ -266,7 +266,15 @@ class OathManager(
)
)
if (!session.isLocked) {
oathViewModel.updateCredentials(calculateOathCodes(session))
try {
oathViewModel.updateCredentials(calculateOathCodes(session))
} catch (e: IOException) {
// in this situation we clear the session because otherwise
// the credential list would be in loading state
// clearing the session will prompt the user to try again
oathViewModel.clearSession()
throw e
}
}
// Awaiting an action for a different or no device?
@ -315,14 +323,19 @@ class OathManager(
}
} catch (e: Exception) {
// OATH not enabled/supported, try to get DeviceInfo over other USB interfaces
logger.error("Failed to connect to CCID: ", e)
// Clear any cached OATH state
oathViewModel.clearSession()
logger.error("Exception during SmartCard connection/OATH session creation: ", e)
// Remove any pending action
pendingAction?.let { action ->
logger.error("Cancelling pending action")
logger.error("Failing pending action with {}", e.message)
action.invoke(Result.failure(e))
pendingAction = null
action.invoke(Result.failure(CancellationException()))
}
if (e !is IOException) {
// we don't clear the session on IOExceptions so that the session is ready for
// a possible re-run of a failed action.
oathViewModel.clearSession()
}
throw e

View File

@ -60,7 +60,8 @@ class MainPage extends ConsumerWidget {
ref.listen<AsyncValue<YubiKeyData>>(currentDeviceDataProvider,
(prev, next) {
final serial = next.value?.info.serial;
if (serial != null && serial == prev?.value?.info.serial) {
if ((serial != null && serial == prev?.value?.info.serial) ||
(next.hasValue && (prev != null && prev.isLoading))) {
return;
}