mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-26 22:03:55 +03:00
Fix readig DeviceInfo from NEO over NFC.
This commit is contained in:
parent
33b5214526
commit
10f86dde8b
@ -13,6 +13,7 @@ import com.yubico.authenticator.yubikit.withConnection
|
|||||||
import com.yubico.yubikit.android.transport.usb.UsbYubiKeyDevice
|
import com.yubico.yubikit.android.transport.usb.UsbYubiKeyDevice
|
||||||
import com.yubico.yubikit.core.Transport
|
import com.yubico.yubikit.core.Transport
|
||||||
import com.yubico.yubikit.core.YubiKeyDevice
|
import com.yubico.yubikit.core.YubiKeyDevice
|
||||||
|
import com.yubico.yubikit.core.YubiKeyType
|
||||||
import com.yubico.yubikit.core.application.ApplicationNotAvailableException
|
import com.yubico.yubikit.core.application.ApplicationNotAvailableException
|
||||||
import com.yubico.yubikit.core.smartcard.SmartCardConnection
|
import com.yubico.yubikit.core.smartcard.SmartCardConnection
|
||||||
import com.yubico.yubikit.core.util.Result
|
import com.yubico.yubikit.core.util.Result
|
||||||
@ -166,8 +167,8 @@ class OathManager(
|
|||||||
|
|
||||||
override suspend fun processYubiKey(device: YubiKeyDevice) {
|
override suspend fun processYubiKey(device: YubiKeyDevice) {
|
||||||
try {
|
try {
|
||||||
device.withConnection<SmartCardConnection, Unit> {
|
device.withConnection<SmartCardConnection, Unit> { connection ->
|
||||||
val oath = OathSession(it)
|
val oath = OathSession(connection)
|
||||||
tryToUnlockOathSession(oath)
|
tryToUnlockOathSession(oath)
|
||||||
|
|
||||||
val previousId = oathViewModel.sessionState.value?.deviceId
|
val previousId = oathViewModel.sessionState.value?.deviceId
|
||||||
@ -197,7 +198,7 @@ class OathManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear in-memory password for any previous device
|
// Clear in-memory password for any previous device
|
||||||
if (it.transport == Transport.NFC && previousId != null) {
|
if (connection.transport == Transport.NFC && previousId != null) {
|
||||||
memoryKeyProvider.removeKey(previousId)
|
memoryKeyProvider.removeKey(previousId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,15 +211,34 @@ class OathManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update deviceInfo since the deviceId has changed
|
// Update deviceInfo since the deviceId has changed
|
||||||
val pid = (device as? UsbYubiKeyDevice)?.pid
|
if (oath.version.isLessThan(4, 0, 0) && connection.transport == Transport.NFC) {
|
||||||
val deviceInfo = DeviceUtil.readInfo(it, pid)
|
// NEO over NFC, need a new connection to select another applet
|
||||||
appViewModel.setDeviceInfo(
|
device.requestConnection(SmartCardConnection::class.java) {
|
||||||
deviceInfo.model(
|
try {
|
||||||
DeviceUtil.getName(deviceInfo, pid?.type),
|
val deviceInfo = DeviceUtil.readInfo(it.value, null)
|
||||||
device.transport == Transport.NFC,
|
appViewModel.setDeviceInfo(
|
||||||
pid?.value
|
deviceInfo.model(
|
||||||
|
DeviceUtil.getName(deviceInfo, YubiKeyType.NEO),
|
||||||
|
true,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Failed to read device info", e.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not a NEO over NFC, reuse existing connection
|
||||||
|
val pid = (device as? UsbYubiKeyDevice)?.pid
|
||||||
|
val deviceInfo = DeviceUtil.readInfo(connection, pid)
|
||||||
|
appViewModel.setDeviceInfo(
|
||||||
|
deviceInfo.model(
|
||||||
|
DeviceUtil.getName(deviceInfo, pid?.type),
|
||||||
|
device.transport == Transport.NFC,
|
||||||
|
pid?.value
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(
|
Log.d(
|
||||||
|
Loading…
Reference in New Issue
Block a user