Skip to content

Commit c9d4377

Browse files
committed
Merge PR #1036.
2 parents 0785308 + 55785cc commit c9d4377

File tree

1 file changed

+14
-6
lines changed
  • android/app/src/main/kotlin/com/yubico/authenticator/oath

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ class OathManager(
242242
try {
243243
device.withConnection<SmartCardConnection, Unit> { connection ->
244244
val session = YubiKitOathSession(connection)
245-
tryToUnlockOathSession(session)
246245

247246
val previousId = oathViewModel.sessionState.value?.deviceId
248247
if (session.deviceId == previousId && device is NfcYubiKeyDevice) {
@@ -434,7 +433,7 @@ class OathManager(
434433
}
435434

436435
private suspend fun unsetPassword(currentPassword: String): String =
437-
useOathSession("Unset password") { session ->
436+
useOathSession("Unset password", unlock = false) { session ->
438437
if (session.isAccessKeySet) {
439438
// test current password sent by the user
440439
if (session.unlock(currentPassword.toCharArray())) {
@@ -624,31 +623,40 @@ class OathManager(
624623

625624
private suspend fun <T> useOathSession(
626625
title: String,
626+
unlock: Boolean = true,
627627
action: (YubiKitOathSession) -> T
628628
): T {
629629
return appViewModel.connectedYubiKey.value?.let {
630-
useOathSessionUsb(it, action)
631-
} ?: useOathSessionNfc(title, action)
630+
useOathSessionUsb(it, unlock, action)
631+
} ?: useOathSessionNfc(title, unlock, action)
632632
}
633633

634634
private suspend fun <T> useOathSessionUsb(
635635
device: UsbYubiKeyDevice,
636+
unlock: Boolean = true,
636637
block: (YubiKitOathSession) -> T
637638
): T = device.withConnection<SmartCardConnection, T> {
638639
val session = YubiKitOathSession(it)
639-
tryToUnlockOathSession(session)
640+
if (unlock) {
641+
tryToUnlockOathSession(session)
642+
}
640643
block(session)
641644
}
642645

643646
private suspend fun <T> useOathSessionNfc(
644647
title: String,
648+
unlock: Boolean = true,
645649
block: (YubiKitOathSession) -> T
646650
): T {
647651
try {
648652
val result = suspendCoroutine { outer ->
649653
pendingAction = {
650654
outer.resumeWith(runCatching {
651-
block.invoke(it.value)
655+
val session = it.value
656+
if (unlock) {
657+
tryToUnlockOathSession(session)
658+
}
659+
block.invoke(session)
652660
})
653661
}
654662
dialogManager.showDialog(Icon.NFC, "Tap your key", title) {

0 commit comments

Comments
 (0)