diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/DeviceInfoHelper.cs b/Yubico.YubiKey/src/Yubico/YubiKey/DeviceInfoHelper.cs index 342124db..5591b69f 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/DeviceInfoHelper.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/DeviceInfoHelper.cs @@ -27,15 +27,12 @@ internal static class DeviceInfoHelper /// paging through the data as needed until all configuration data is retrieved. /// This method processes the responses, accumulating TLV-encoded data into a single dictionary. /// - /// The type of the YubiKey response which must include data. + /// The specific type of IGetPagedDeviceInfoCommand, e.g. GetPagedDeviceInfoCommand, which will then allow for returning the appropriate response. /// The connection interface to communicate with a YubiKey. - /// The command to be sent to the YubiKey. This command should be capable of handling pagination. /// A YubiKeyDeviceInfo object containing all relevant device information. /// Thrown when the command fails to retrieve successful response statuses from the YubiKey. - public static YubiKeyDeviceInfo GetDeviceInfo( - IYubiKeyConnection connection, - IPagedGetDeviceInfoCommand command) - where T : IYubiKeyResponseWithData>> + public static YubiKeyDeviceInfo GetDeviceInfo(IYubiKeyConnection connection) + where TCommand : IGetPagedDeviceInfoCommand>>>, new() { Logger log = Log.GetLogger(); @@ -45,8 +42,7 @@ public static YubiKeyDeviceInfo GetDeviceInfo( bool hasMoreData = true; while (hasMoreData) { - command.Page = (byte)page++; - T response = connection.SendCommand(command); + IYubiKeyResponseWithData>> response = connection.SendCommand(new TCommand {Page = (byte)page++}); if (response.Status == ResponseStatus.Success) { Dictionary> tlvData = response.GetData(); diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs b/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs index 3cc274ac..a513e6db 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs @@ -17,7 +17,7 @@ using Yubico.Core.Devices.Hid; using Yubico.Core.Logging; using Yubico.YubiKey.DeviceExtensions; -using Yubico.YubiKey.Management.Commands; +using Yubico.YubiKey.U2f.Commands; namespace Yubico.YubiKey { @@ -74,7 +74,7 @@ private static bool TryGetDeviceInfoFromFido(IHidDevice device, { log.LogInformation("Attempting to read device info via the FIDO interface management command."); using var connection = new FidoConnection(device); - yubiKeyDeviceInfo = DeviceInfoHelper.GetDeviceInfo(connection, new GetPagedDeviceInfoCommand()); + yubiKeyDeviceInfo = DeviceInfoHelper.GetDeviceInfo(connection); log.LogInformation("Successfully read device info via FIDO interface management command."); return true; diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/IGetPagedDeviceInfoCommand.cs b/Yubico.YubiKey/src/Yubico/YubiKey/IGetPagedDeviceInfoCommand.cs new file mode 100644 index 00000000..22a651db --- /dev/null +++ b/Yubico.YubiKey/src/Yubico/YubiKey/IGetPagedDeviceInfoCommand.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace Yubico.YubiKey +{ + public interface IGetPagedDeviceInfoCommand : IYubiKeyCommand + where T : IYubiKeyResponseWithData>> + { + public byte Page { get; set; } + + } +} + diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs b/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs index b8d0fd40..dc20952b 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs @@ -17,6 +17,7 @@ using Yubico.Core.Devices.Hid; using Yubico.Core.Logging; using Yubico.YubiKey.DeviceExtensions; +using Yubico.YubiKey.Otp.Commands; namespace Yubico.YubiKey { @@ -74,7 +75,7 @@ private static bool TryGetDeviceInfoFromKeyboard(IHidDevice device, [MaybeNullWh { log.LogInformation("Attempting to read device info via the management command over the keyboard interface."); using var connection = new KeyboardConnection(device); - yubiKeyDeviceInfo = DeviceInfoHelper.GetDeviceInfo(connection, new Management.Commands.GetPagedDeviceInfoCommand()); + yubiKeyDeviceInfo = DeviceInfoHelper.GetDeviceInfo(connection); //TODO Handle exceptions? return true; diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Management/Commands/GetPagedDeviceInfoCommand.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Management/Commands/GetPagedDeviceInfoCommand.cs index b23ce951..82e307bc 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/Management/Commands/GetPagedDeviceInfoCommand.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/Management/Commands/GetPagedDeviceInfoCommand.cs @@ -24,7 +24,7 @@ namespace Yubico.YubiKey.Management.Commands /// /// This class has a corresponding partner class /// - public sealed class GetPagedDeviceInfoCommand : IPagedGetDeviceInfoCommand + public sealed class GetPagedDeviceInfoCommand : IGetPagedDeviceInfoCommand { private const byte GetDeviceInfoInstruction = 0x1D; public byte Page { get; set; } @@ -56,20 +56,5 @@ public GetPagedDeviceInfoCommand() public GetPagedDeviceInfoResponse CreateResponseForApdu(ResponseApdu responseApdu) => new GetPagedDeviceInfoResponse(responseApdu); } - - /// - /// TODO - /// - /// - public interface IPagedGetDeviceInfoCommand : IYubiKeyCommand - where T : IYubiKeyResponseWithData>> - { - public byte Page { get; set; } - } - - // public interface IPagedGetDeviceInfoCommand : IYubiKeyCommand>>> - // { - // public byte Page { get; set; } - // } } diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Otp/Commands/GetPagedDeviceInfoCommand.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Otp/Commands/GetPagedDeviceInfoCommand.cs index 3db99b27..c10073ed 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/Otp/Commands/GetPagedDeviceInfoCommand.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/Otp/Commands/GetPagedDeviceInfoCommand.cs @@ -13,7 +13,7 @@ // limitations under the License. using Yubico.Core.Iso7816; -using Yubico.YubiKey.Management.Commands; + namespace Yubico.YubiKey.Otp.Commands { @@ -21,9 +21,9 @@ namespace Yubico.YubiKey.Otp.Commands /// Gets detailed information about the YubiKey and its current configuration. /// /// - /// This class has a corresponding partner class + /// This class has a corresponding partner class /// - public class PagedGetPagedDeviceInfoCommand : IPagedGetDeviceInfoCommand + public class GetPagedDeviceInfoCommand : IGetPagedDeviceInfoCommand { /// /// Gets the YubiKeyApplication to which this command belongs. @@ -36,9 +36,9 @@ public class PagedGetPagedDeviceInfoCommand : IPagedGetDeviceInfoCommand - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public PagedGetPagedDeviceInfoCommand() + public GetPagedDeviceInfoCommand() { } diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs b/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs index 0d13ccaa..dd6f9952 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs @@ -17,6 +17,7 @@ using Yubico.Core.Devices.SmartCard; using Yubico.Core.Logging; using Yubico.YubiKey.DeviceExtensions; +using Yubico.YubiKey.Management.Commands; namespace Yubico.YubiKey { @@ -77,9 +78,9 @@ public static YubiKeyDeviceInfo GetDeviceInfo(ISmartCardDevice device) return ykDeviceInfo; } - private static bool TryGetDeviceInfoFromManagement(ISmartCardDevice device, - [MaybeNullWhen(returnValue: false)] - out YubiKeyDeviceInfo yubiKeyDeviceInfo) + private static bool TryGetDeviceInfoFromManagement( + ISmartCardDevice device, + [MaybeNullWhen(returnValue: false)] out YubiKeyDeviceInfo yubiKeyDeviceInfo) { Logger log = Log.GetLogger(); @@ -87,7 +88,7 @@ private static bool TryGetDeviceInfoFromManagement(ISmartCardDevice device, { log.LogInformation("Attempting to read device info via the management application."); using var connection = new SmartcardConnection(device, YubiKeyApplication.Management); - yubiKeyDeviceInfo = DeviceInfoHelper.GetDeviceInfo(connection, new Management.Commands.GetPagedDeviceInfoCommand()); + yubiKeyDeviceInfo = DeviceInfoHelper.GetDeviceInfo(connection); log.LogInformation("Successfully read device info via management application."); return true; diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/Commands/GetPagedDeviceInfoCommand.cs b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/Commands/GetPagedDeviceInfoCommand.cs index a5ad2843..7169eeb7 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/Commands/GetPagedDeviceInfoCommand.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/Commands/GetPagedDeviceInfoCommand.cs @@ -13,14 +13,13 @@ // limitations under the License. using Yubico.Core.Iso7816; -using Yubico.YubiKey.Management.Commands; namespace Yubico.YubiKey.U2f.Commands { /// /// Gets detailed information about the YubiKey and its current configuration. /// - public sealed class PagedGetPagedDeviceInfoCommand : IPagedGetDeviceInfoCommand + public sealed class GetPagedDeviceInfoCommand : IGetPagedDeviceInfoCommand { private const byte GetDeviceInfoInstruction = 0xC2; public byte Page { get; set; } @@ -34,9 +33,9 @@ public sealed class PagedGetPagedDeviceInfoCommand : IPagedGetDeviceInfoCommand< public YubiKeyApplication Application => YubiKeyApplication.FidoU2f; /// - /// Constructs an instance of the class. + /// Constructs an instance of the class. /// - public PagedGetPagedDeviceInfoCommand() + public GetPagedDeviceInfoCommand() { }