From 0c7f916088687c69d822737d082a05aa683aad8d Mon Sep 17 00:00:00 2001 From: Dennis Dyall Date: Thu, 19 Dec 2024 11:51:11 +0100 Subject: [PATCH 1/2] fix: ConnectionFactory incorrectly using SmartCardConnection instead of FIDO2Connection --- .../src/Yubico/YubiKey/ConnectionFactory.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/ConnectionFactory.cs b/Yubico.YubiKey/src/Yubico/YubiKey/ConnectionFactory.cs index 9ba7e72b..cca65e5b 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/ConnectionFactory.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/ConnectionFactory.cs @@ -112,14 +112,6 @@ public IScpYubiKeyConnection CreateScpConnection(YubiKeyApplication application, /// public IYubiKeyConnection CreateConnection(YubiKeyApplication application) { - if (_smartCardDevice != null) - { - _log.LogDebug("Connecting via the SmartCard interface."); - - WaitForReclaimTimeout(Transport.SmartCard); - return new SmartCardConnection(_smartCardDevice, application); - } - if (_hidKeyboardDevice != null && application == YubiKeyApplication.Otp) { _log.LogDebug("Connecting via the Keyboard interface."); @@ -128,13 +120,22 @@ public IYubiKeyConnection CreateConnection(YubiKeyApplication application) return new KeyboardConnection(_hidKeyboardDevice); } - if (_hidFidoDevice != null && (application == YubiKeyApplication.Fido2 || application == YubiKeyApplication.FidoU2f)) + bool isFidoApplication = application == YubiKeyApplication.Fido2 || application == YubiKeyApplication.FidoU2f; + if (_hidFidoDevice != null && isFidoApplication) { _log.LogDebug("Connecting via the FIDO interface."); WaitForReclaimTimeout(Transport.HidFido); return new FidoConnection(_hidFidoDevice); } + + if (_smartCardDevice != null) + { + _log.LogDebug("Connecting via the SmartCard interface."); + + WaitForReclaimTimeout(Transport.SmartCard); + return new SmartCardConnection(_smartCardDevice, application); + } throw new InvalidOperationException("No suitable interface present. Unable to establish connection to YubiKey."); } From 1160d51b5a662088dccb55d3b943f799bdd5cc0d Mon Sep 17 00:00:00 2001 From: Dennis Dyall Date: Thu, 19 Dec 2024 14:08:41 +0100 Subject: [PATCH 2/2] fix: OathSession not clearing KeyCollector on disposal --- Yubico.YubiKey/src/Yubico/YubiKey/Oath/OathSession.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Oath/OathSession.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Oath/OathSession.cs index 82407e73..e240eaf7 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/Oath/OathSession.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/Oath/OathSession.cs @@ -127,11 +127,9 @@ protected override void Dispose(bool disposing) { if (disposing) { - return; + KeyCollector = null; + base.Dispose(disposing); } - - KeyCollector = null; - base.Dispose(disposing); } } }