@@ -242,7 +242,6 @@ class OathManager(
242
242
try {
243
243
device.withConnection<SmartCardConnection , Unit > { connection ->
244
244
val session = YubiKitOathSession (connection)
245
- tryToUnlockOathSession(session)
246
245
247
246
val previousId = oathViewModel.sessionState.value?.deviceId
248
247
if (session.deviceId == previousId && device is NfcYubiKeyDevice ) {
@@ -434,7 +433,7 @@ class OathManager(
434
433
}
435
434
436
435
private suspend fun unsetPassword (currentPassword : String ): String =
437
- useOathSession(" Unset password" ) { session ->
436
+ useOathSession(" Unset password" , unlock = false ) { session ->
438
437
if (session.isAccessKeySet) {
439
438
// test current password sent by the user
440
439
if (session.unlock(currentPassword.toCharArray())) {
@@ -624,31 +623,40 @@ class OathManager(
624
623
625
624
private suspend fun <T > useOathSession (
626
625
title : String ,
626
+ unlock : Boolean = true,
627
627
action : (YubiKitOathSession ) -> T
628
628
): T {
629
629
return appViewModel.connectedYubiKey.value?.let {
630
- useOathSessionUsb(it, action)
631
- } ? : useOathSessionNfc(title, action)
630
+ useOathSessionUsb(it, unlock, action)
631
+ } ? : useOathSessionNfc(title, unlock, action)
632
632
}
633
633
634
634
private suspend fun <T > useOathSessionUsb (
635
635
device : UsbYubiKeyDevice ,
636
+ unlock : Boolean = true,
636
637
block : (YubiKitOathSession ) -> T
637
638
): T = device.withConnection<SmartCardConnection , T > {
638
639
val session = YubiKitOathSession (it)
639
- tryToUnlockOathSession(session)
640
+ if (unlock) {
641
+ tryToUnlockOathSession(session)
642
+ }
640
643
block(session)
641
644
}
642
645
643
646
private suspend fun <T > useOathSessionNfc (
644
647
title : String ,
648
+ unlock : Boolean = true,
645
649
block : (YubiKitOathSession ) -> T
646
650
): T {
647
651
try {
648
652
val result = suspendCoroutine { outer ->
649
653
pendingAction = {
650
654
outer.resumeWith(runCatching {
651
- block.invoke(it.value)
655
+ val session = it.value
656
+ if (unlock) {
657
+ tryToUnlockOathSession(session)
658
+ }
659
+ block.invoke(session)
652
660
})
653
661
}
654
662
dialogManager.showDialog(Icon .NFC , " Tap your key" , title) {
0 commit comments