Skip to content

Commit 3e335db

Browse files
committed
select OTP applet before reading device info
1 parent e2482c5 commit 3e335db

File tree

1 file changed

+16
-28
lines changed
  • android/app/src/main/kotlin/com/yubico/authenticator/oath

1 file changed

+16
-28
lines changed

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

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ import com.yubico.authenticator.yubikit.withConnection
3232
import com.yubico.yubikit.android.transport.usb.UsbYubiKeyDevice
3333
import com.yubico.yubikit.core.Transport
3434
import com.yubico.yubikit.core.YubiKeyDevice
35-
import com.yubico.yubikit.core.YubiKeyType
3635
import com.yubico.yubikit.core.application.ApplicationNotAvailableException
3736
import com.yubico.yubikit.core.smartcard.ApduException
3837
import com.yubico.yubikit.core.smartcard.SW
3938
import com.yubico.yubikit.core.smartcard.SmartCardConnection
39+
import com.yubico.yubikit.core.smartcard.SmartCardProtocol
4040
import com.yubico.yubikit.core.util.Result
4141
import com.yubico.yubikit.oath.*
4242
import com.yubico.yubikit.support.DeviceUtil
@@ -61,6 +61,7 @@ class OathManager(
6161
companion object {
6262
const val TAG = "OathManager"
6363
const val NFC_DATA_CLEANUP_DELAY = 30L * 1000 // 30s
64+
val OTP_AID = byteArrayOf(0xa0.toByte(), 0x00, 0x00, 0x05, 0x27, 0x20, 0x01, 0x01)
6465
}
6566

6667
private val dispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
@@ -253,35 +254,22 @@ class OathManager(
253254
}
254255
}
255256

256-
// Update deviceInfo since the deviceId has changed
257257
if (oath.version.isLessThan(4, 0, 0) && connection.transport == Transport.NFC) {
258-
// NEO over NFC, need a new connection to select another applet
259-
device.requestConnection(SmartCardConnection::class.java) {
260-
try {
261-
val deviceInfo = DeviceUtil.readInfo(it.value, null)
262-
appViewModel.setDeviceInfo(
263-
deviceInfo.model(
264-
DeviceUtil.getName(deviceInfo, YubiKeyType.NEO),
265-
true,
266-
null
267-
)
268-
)
269-
} catch (e: Exception) {
270-
Log.e(TAG, "Failed to read device info", e.toString())
271-
}
272-
}
273-
} else {
274-
// Not a NEO over NFC, reuse existing connection
275-
val pid = (device as? UsbYubiKeyDevice)?.pid
276-
val deviceInfo = DeviceUtil.readInfo(connection, pid)
277-
appViewModel.setDeviceInfo(
278-
deviceInfo.model(
279-
DeviceUtil.getName(deviceInfo, pid?.type),
280-
device.transport == Transport.NFC,
281-
pid?.value
282-
)
283-
)
258+
// NEO over NFC, select OTP applet before reading info
259+
SmartCardProtocol(connection).select(OTP_AID)
284260
}
261+
262+
// Update deviceInfo since the deviceId has changed
263+
val pid = (device as? UsbYubiKeyDevice)?.pid
264+
val deviceInfo = DeviceUtil.readInfo(connection, pid)
265+
appViewModel.setDeviceInfo(
266+
deviceInfo.model(
267+
DeviceUtil.getName(deviceInfo, pid?.type),
268+
device.transport == Transport.NFC,
269+
pid?.value
270+
)
271+
)
272+
285273
}
286274
}
287275
Log.d(

0 commit comments

Comments
 (0)