mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-23 02:01:36 +03:00
Merge PR #1203.
This commit is contained in:
commit
5f78b0952f
@ -62,6 +62,7 @@ import io.flutter.plugin.common.MethodChannel
|
|||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.io.IOException
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
@ -554,29 +555,47 @@ class OathManager(
|
|||||||
NULL
|
NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun requestRefresh() =
|
private suspend fun requestRefresh() {
|
||||||
|
|
||||||
|
val clearCodes = {
|
||||||
|
val currentCredentials = oathViewModel.credentials.value
|
||||||
|
oathViewModel.updateCredentials(currentCredentials?.associate {
|
||||||
|
it.credential to null
|
||||||
|
} ?: emptyMap())
|
||||||
|
}
|
||||||
|
|
||||||
appViewModel.connectedYubiKey.value?.let { usbYubiKeyDevice ->
|
appViewModel.connectedYubiKey.value?.let { usbYubiKeyDevice ->
|
||||||
useOathSessionUsb(usbYubiKeyDevice) { session ->
|
try {
|
||||||
try {
|
useOathSessionUsb(usbYubiKeyDevice) { session ->
|
||||||
oathViewModel.updateCredentials(calculateOathCodes(session))
|
try {
|
||||||
} catch (apduException: ApduException) {
|
oathViewModel.updateCredentials(calculateOathCodes(session))
|
||||||
if (apduException.sw == SW.SECURITY_CONDITION_NOT_SATISFIED) {
|
} catch (apduException: ApduException) {
|
||||||
logger.debug("Handled oath credential refresh on locked session.")
|
if (apduException.sw == SW.SECURITY_CONDITION_NOT_SATISFIED) {
|
||||||
oathViewModel.setSessionState(
|
logger.debug("Handled oath credential refresh on locked session.")
|
||||||
Session(
|
oathViewModel.setSessionState(
|
||||||
session,
|
Session(
|
||||||
keyManager.isRemembered(session.deviceId)
|
session,
|
||||||
|
keyManager.isRemembered(session.deviceId)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
} else {
|
||||||
} else {
|
logger.error(
|
||||||
logger.error(
|
"Unexpected sw when refreshing oath credentials",
|
||||||
"Unexpected sw when refreshing oath credentials",
|
apduException
|
||||||
apduException
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (ioException: IOException) {
|
||||||
|
logger.error("IOException when accessing USB device: ", ioException)
|
||||||
|
clearCodes()
|
||||||
|
} catch (illegalStateException: IllegalStateException) {
|
||||||
|
logger.error("IllegalStateException when accessing USB device: ", illegalStateException)
|
||||||
|
clearCodes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private suspend fun calculate(credentialId: String): String =
|
private suspend fun calculate(credentialId: String): String =
|
||||||
useOathSession(OathActionDescription.CalculateCode) { session ->
|
useOathSession(OathActionDescription.CalculateCode) { session ->
|
||||||
|
Loading…
Reference in New Issue
Block a user