Skip to content

Commit 5f78b09

Browse files
committed
Merge PR #1203.
2 parents a90d118 + 452491a commit 5f78b09

File tree

1 file changed

+36
-17
lines changed
  • android/app/src/main/kotlin/com/yubico/authenticator/oath

1 file changed

+36
-17
lines changed

android/app/src/main/kotlin/com/yubico/authenticator/oath/OathManager.kt

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import io.flutter.plugin.common.MethodChannel
6262
import kotlinx.coroutines.*
6363
import kotlinx.serialization.encodeToString
6464
import org.slf4j.LoggerFactory
65+
import java.io.IOException
6566
import java.net.URI
6667
import java.util.concurrent.Executors
6768
import java.util.concurrent.atomic.AtomicBoolean
@@ -554,29 +555,47 @@ class OathManager(
554555
NULL
555556
}
556557

557-
private suspend fun requestRefresh() =
558+
private suspend fun requestRefresh() {
559+
560+
val clearCodes = {
561+
val currentCredentials = oathViewModel.credentials.value
562+
oathViewModel.updateCredentials(currentCredentials?.associate {
563+
it.credential to null
564+
} ?: emptyMap())
565+
}
566+
558567
appViewModel.connectedYubiKey.value?.let { usbYubiKeyDevice ->
559-
useOathSessionUsb(usbYubiKeyDevice) { session ->
560-
try {
561-
oathViewModel.updateCredentials(calculateOathCodes(session))
562-
} catch (apduException: ApduException) {
563-
if (apduException.sw == SW.SECURITY_CONDITION_NOT_SATISFIED) {
564-
logger.debug("Handled oath credential refresh on locked session.")
565-
oathViewModel.setSessionState(
566-
Session(
567-
session,
568-
keyManager.isRemembered(session.deviceId)
568+
try {
569+
useOathSessionUsb(usbYubiKeyDevice) { session ->
570+
try {
571+
oathViewModel.updateCredentials(calculateOathCodes(session))
572+
} catch (apduException: ApduException) {
573+
if (apduException.sw == SW.SECURITY_CONDITION_NOT_SATISFIED) {
574+
logger.debug("Handled oath credential refresh on locked session.")
575+
oathViewModel.setSessionState(
576+
Session(
577+
session,
578+
keyManager.isRemembered(session.deviceId)
579+
)
569580
)
570-
)
571-
} else {
572-
logger.error(
573-
"Unexpected sw when refreshing oath credentials",
574-
apduException
575-
)
581+
} else {
582+
logger.error(
583+
"Unexpected sw when refreshing oath credentials",
584+
apduException
585+
)
586+
}
576587
}
577588
}
589+
} catch (ioException: IOException) {
590+
logger.error("IOException when accessing USB device: ", ioException)
591+
clearCodes()
592+
} catch (illegalStateException: IllegalStateException) {
593+
logger.error("IllegalStateException when accessing USB device: ", illegalStateException)
594+
clearCodes()
578595
}
579596
}
597+
}
598+
580599

581600
private suspend fun calculate(credentialId: String): String =
582601
useOathSession(OathActionDescription.CalculateCode) { session ->

0 commit comments

Comments
 (0)