Skip to content

Adding additional device info fields to IYubikeyDeviceInfo #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;
using Yubico.PlatformInterop;
Expand Down
2 changes: 2 additions & 0 deletions Yubico.YubiKey/src/Yubico/YubiKey/FirmwareVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public class FirmwareVersion : IComparable<FirmwareVersion>, IComparable, IEquat
internal static readonly FirmwareVersion V4_3_4 = new FirmwareVersion(4, 3, 4);
internal static readonly FirmwareVersion V4_4_0 = new FirmwareVersion(4, 4, 0);
internal static readonly FirmwareVersion V4_5_0 = new FirmwareVersion(4, 5, 0);
internal static readonly FirmwareVersion V5_0_0 = new FirmwareVersion(5, 0, 0);
internal static readonly FirmwareVersion V5_3_0 = new FirmwareVersion(5, 3, 0);
internal static readonly FirmwareVersion V5_4_2 = new FirmwareVersion(5, 4, 2);
internal static readonly FirmwareVersion V5_4_3 = new FirmwareVersion(5, 4, 3);
internal static readonly FirmwareVersion V5_6_0 = new FirmwareVersion(5, 6, 0);
internal static readonly FirmwareVersion V5_7_0 = new FirmwareVersion(5, 7, 0);
#endregion

public byte Major { get; set; }
Expand Down
1 change: 0 additions & 1 deletion Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ where TCommand
var combinedPages = new Dictionary<int, ReadOnlyMemory<byte>>();

bool hasMoreData = true;

while (hasMoreData)
{
IYubiKeyResponseWithData<Dictionary<int, ReadOnlyMemory<byte>>> response =
Expand Down
31 changes: 30 additions & 1 deletion Yubico.YubiKey/src/Yubico/YubiKey/IYubiKeyDeviceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ public interface IYubiKeyDeviceInfo
/// </summary>
public YubiKeyCapabilities EnabledNfcCapabilities { get; }

/// <summary>
/// The set of YubiKey applications that are currently configured to meet FIPS requirements.
/// </summary>
public YubiKeyCapabilities FipsApproved { get; }

/// <summary>
/// The set of YubiKey applications that are capable of being put into FIPS mode.
/// </summary>
public YubiKeyCapabilities FipsCapable { get; }

/// <summary>
/// The set of YubiKey applications that are blocked from being reset.
/// </summary>
public YubiKeyCapabilities ResetBlocked { get; }

/// <summary>
/// The serial number of the YubiKey, if one is present.
/// </summary>
Expand Down Expand Up @@ -79,12 +94,14 @@ public interface IYubiKeyDeviceInfo
/// The version of the chip/firmware storing the fingerprints (the second
/// secure element). If there is no template storage chip, this will be
/// null.
/// <remarks>This field is also known as the "FPS Version".</remarks>
/// </summary>
public TemplateStorageVersion? TemplateStorageVersion { get; }

/// <summary>
/// The version of the chip/firmware performing the image processing. If
/// there is no image processing chip, this will be null.
/// <remarks>This field is also known as the "STM Version".</remarks>
/// </summary>
public ImageProcessorVersion? ImageProcessorVersion { get; }

Expand Down Expand Up @@ -123,8 +140,20 @@ public interface IYubiKeyDeviceInfo
public bool ConfigurationLocked { get; }

/// <summary>
/// Indicates if this device has temporarily disabled NFC.
/// Indicates if the NFC connectivity on the device is temporarily disabled
/// </summary>
public bool IsNfcRestricted { get; }

/// <summary>
/// The part number for the Secure Element processor, if available, otherwise `null`
/// </summary>
string? PartNumber { get; }

/// <summary>
/// Whether or not pin complexity is enabled on the Yubikey.
/// For more information see
/// <a href="https://docs.yubico.com/hardware/yubikey/yk-tech-manual/5.7-firmware-specifics.html#pin-complexity">this documentation on pin complexity</a>
/// </summary>
bool IsPinComplexityEnabled { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ namespace Yubico.YubiKey.Management.Commands
/// </summary>
public class SetDeviceInfoBaseCommand
{
private const byte UsbEnabledCapabilitiesTag = 0x03;
private const byte AutoEjectTimeoutTag = 0x06;
private const byte ChallengeResponseTimeoutTag = 0x07;
private const byte DeviceFlagsTag = 0x08;
private const byte ConfigurationLockPresentTag = 0x0a;
private const byte ConfigurationUnlockPresentTag = 0x0b;
private const byte ResetAfterConfigTag = 0x0c;
private const byte NfcEnabledCapabilitiesTag = 0x0e;
private const byte NfcRestrictedTag = 0x17;

private byte[]? _lockCode;
private byte[]? _unlockCode;

Expand Down Expand Up @@ -214,47 +204,47 @@ private byte[] GetTlvData()

if (EnabledUsbCapabilities is YubiKeyCapabilities usbCapabilities)
{
buffer.WriteInt16(UsbEnabledCapabilitiesTag, (short)usbCapabilities);
buffer.WriteInt16(YubikeyDeviceManagementTags.UsbEnabledCapabilitiesTag, (short)usbCapabilities);
}

if (EnabledNfcCapabilities is YubiKeyCapabilities nfcCapabilities)
{
buffer.WriteInt16(NfcEnabledCapabilitiesTag, (short)nfcCapabilities);
buffer.WriteInt16(YubikeyDeviceManagementTags.NfcEnabledCapabilitiesTag, (short)nfcCapabilities);
}

if (ChallengeResponseTimeout is byte crTimeout)
{
buffer.WriteByte(ChallengeResponseTimeoutTag, crTimeout);
buffer.WriteByte(YubikeyDeviceManagementTags.ChallengeResponseTimeoutTag, crTimeout);
}

if (_autoEjectTimeout is ushort aeTimeout)
{
buffer.WriteUInt16(AutoEjectTimeoutTag, aeTimeout);
buffer.WriteUInt16(YubikeyDeviceManagementTags.AutoEjectTimeoutTag, aeTimeout);
}

if (DeviceFlags is DeviceFlags deviceFlags)
{
buffer.WriteByte(DeviceFlagsTag, (byte)deviceFlags);
buffer.WriteByte(YubikeyDeviceManagementTags.DeviceFlagsTag, (byte)deviceFlags);
}

if (ResetAfterConfig)
{
buffer.WriteValue(ResetAfterConfigTag, ReadOnlySpan<byte>.Empty);
buffer.WriteValue(YubikeyDeviceManagementTags.ResetAfterConfigTag, ReadOnlySpan<byte>.Empty);
}

if (_lockCode is byte[] lockCode)
{
buffer.WriteValue(ConfigurationLockPresentTag, lockCode);
buffer.WriteValue(YubikeyDeviceManagementTags.ConfigurationLockPresentTag, lockCode);
}

if (_unlockCode is byte[] unlockCode)
{
buffer.WriteValue(ConfigurationUnlockPresentTag, unlockCode);
buffer.WriteValue(YubikeyDeviceManagementTags.ConfigurationUnlockPresentTag, unlockCode);
}

if (RestrictNfc)
{
buffer.WriteByte(NfcRestrictedTag, 1);
buffer.WriteByte(YubikeyDeviceManagementTags.NfcRestrictedTag, 1);
}

return buffer.Encode();
Expand Down
16 changes: 15 additions & 1 deletion Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,24 @@ public partial class YubiKeyDevice : IYubiKeyDevice
/// <inheritdoc />
public YubiKeyCapabilities EnabledNfcCapabilities => _yubiKeyInfo.EnabledNfcCapabilities;

/// <inheritdoc />
public YubiKeyCapabilities FipsApproved => _yubiKeyInfo.FipsApproved;

/// <inheritdoc />
public YubiKeyCapabilities FipsCapable => _yubiKeyInfo.FipsCapable;

/// <inheritdoc />
public YubiKeyCapabilities ResetBlocked => _yubiKeyInfo.ResetBlocked;

/// <inheritdoc />
public bool IsNfcRestricted => _yubiKeyInfo.IsNfcRestricted;

/// <inheritdoc />
public string? PartNumber => _yubiKeyInfo.PartNumber;

/// <inheritdoc />
public bool IsPinComplexityEnabled => _yubiKeyInfo.IsPinComplexityEnabled;

/// <inheritdoc />
public int? SerialNumber => _yubiKeyInfo.SerialNumber;

Expand Down Expand Up @@ -955,7 +970,6 @@ public override string ToString()
+ "- Available NFC Capabilities: " + AvailableNfcCapabilities + EOL
+ "- Enabled USB Capabilities: " + EnabledUsbCapabilities + EOL
+ "- Enabled NFC Capabilities: " + EnabledNfcCapabilities + EOL;

return res;
}
#endregion
Expand Down
15 changes: 6 additions & 9 deletions Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Static.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,14 @@ public override bool Equals(object? obj)
{
return false;
}
else
{
int? thisSerialNumber = Info.SerialNumber;

var objDeviceWithInfo = (YubicoDeviceWithInfo)obj;
int? objSerialNumber = objDeviceWithInfo.Info.SerialNumber;
var objDeviceWithInfo = (YubicoDeviceWithInfo)obj;
int? objSerialNumber = objDeviceWithInfo.Info.SerialNumber;

return thisSerialNumber.HasValue
&& objSerialNumber.HasValue
&& thisSerialNumber.Value == objSerialNumber.Value;
}
int? thisSerialNumber = Info.SerialNumber;
return thisSerialNumber.HasValue
&& objSerialNumber.HasValue
&& thisSerialNumber.Value == objSerialNumber.Value;
}

public override int GetHashCode() => Info.SerialNumber.GetHashCode();
Expand Down
Loading