diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs b/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs index 5410450f..6864227c 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs @@ -75,7 +75,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); + yubiKeyDeviceInfo = GetDeviceInfoHelper.GetDeviceInfo(connection); if (yubiKeyDeviceInfo is { }) { log.LogInformation("Successfully read device info via FIDO interface management command."); diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/DeviceInfoHelper.cs b/Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoHelper.cs similarity index 93% rename from Yubico.YubiKey/src/Yubico/YubiKey/DeviceInfoHelper.cs rename to Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoHelper.cs index fd03dcf1..b61deb0e 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/DeviceInfoHelper.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoHelper.cs @@ -19,7 +19,7 @@ namespace Yubico.YubiKey { - internal static class DeviceInfoHelper + internal static class GetDeviceInfoHelper { private static readonly Logger Logger = Log.GetLogger(); @@ -82,6 +82,9 @@ internal static class DeviceInfoHelper return null; } + // Certain transports (such as OTP keyboard) may return a buffer that is larger than the + // overall TLV size. We want to make sure we're only parsing over real TLV data here, so + // check the first byte to get the overall TLV length and slice accordingly. int tlvDataLength = tlvData.Span[0]; if (tlvDataLength == 0 || 1 + tlvDataLength > tlvData.Length) { diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs b/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs index e27006c7..62ee6f68 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs @@ -76,7 +76,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); + yubiKeyDeviceInfo = GetDeviceInfoHelper.GetDeviceInfo(connection); if (yubiKeyDeviceInfo is { }) { log.LogInformation("Successfully read device info via the keyboard management command."); diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Management/Commands/GetPagedDeviceInfoResponse.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Management/Commands/GetPagedDeviceInfoResponse.cs index fba854b2..844d492d 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/Management/Commands/GetPagedDeviceInfoResponse.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/Management/Commands/GetPagedDeviceInfoResponse.cs @@ -59,7 +59,7 @@ public Dictionary> GetData() }; } - Dictionary>? result = DeviceInfoHelper.CreateApduDictionaryFromResponseData(ResponseApdu.Data); + Dictionary>? result = GetDeviceInfoHelper.CreateApduDictionaryFromResponseData(ResponseApdu.Data); return result ?? throw new MalformedYubiKeyResponseException { diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Otp/Commands/GetPagedDeviceInfoResponse.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Otp/Commands/GetPagedDeviceInfoResponse.cs index 3ca0ef07..288456a3 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/Otp/Commands/GetPagedDeviceInfoResponse.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/Otp/Commands/GetPagedDeviceInfoResponse.cs @@ -58,7 +58,7 @@ public Dictionary> GetData() }; } - Dictionary>? result = DeviceInfoHelper.CreateApduDictionaryFromResponseData(ResponseApdu.Data); + Dictionary>? result = GetDeviceInfoHelper.CreateApduDictionaryFromResponseData(ResponseApdu.Data); return result ?? throw new MalformedYubiKeyResponseException { diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs b/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs index f57f4149..ef21b75d 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs @@ -89,7 +89,7 @@ private static bool TryGetDeviceInfoFromManagement( log.LogInformation("Attempting to read device info via the management application."); using var connection = new SmartcardConnection(device, YubiKeyApplication.Management); - yubiKeyDeviceInfo = DeviceInfoHelper.GetDeviceInfo(connection); + yubiKeyDeviceInfo = GetDeviceInfoHelper.GetDeviceInfo(connection); if (yubiKeyDeviceInfo is { }) { log.LogInformation("Successfully read device info via management application."); diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/Commands/GetPagedDeviceInfoResponse.cs b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/Commands/GetPagedDeviceInfoResponse.cs index 1d9016b9..357d780e 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/Commands/GetPagedDeviceInfoResponse.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/Commands/GetPagedDeviceInfoResponse.cs @@ -58,7 +58,7 @@ public Dictionary> GetData() }; } - Dictionary>? result = DeviceInfoHelper.CreateApduDictionaryFromResponseData(ResponseApdu.Data); + Dictionary>? result = GetDeviceInfoHelper.CreateApduDictionaryFromResponseData(ResponseApdu.Data); return result ?? throw new MalformedYubiKeyResponseException { diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDeviceInfo.cs b/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDeviceInfo.cs index 5e1af3c0..6753499c 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDeviceInfo.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDeviceInfo.cs @@ -135,6 +135,7 @@ public YubiKeyDeviceInfo() /// True if the parsing and construction was successful, and false if /// did not meet formatting requirements. /// + [Obsolete("This has been replaced by CreateFromResponseData")] internal static bool TryCreateFromResponseData( ReadOnlyMemory responseApduData, [MaybeNullWhen(returnValue: false)] out YubiKeyDeviceInfo deviceInfo)