SetEnabledUsbCapabilities Method
SetEnabledUsbCapabilities(YubiKeyCapabilities)
Sets which USB features are enabled (and disabled).
void SetEnabledUsbCapabilities(YubiKeyCapabilities yubiKeyCapabilities)
Parameters
Type | Name | Description |
---|---|---|
YubiKeyCapabilities | yubiKeyCapabilities | The desired set of USB features to enable on the YubiKey. A set flag means that the related capability is enabled. Otherwise, the capability is disabled. At least one available USB capability must be enabled. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Either the command failed to complete. |
System.NotSupportedException | An error occurred when attempting to connect to the device. |
Remarks
YubiKeys prior to firmware version 5 must use SetLegacyDeviceConfiguration(YubiKeyCapabilities, Byte, Boolean, Int32).
Modifies the value of EnabledUsbCapabilities. This requires the YubiKey's configuration to be unlocked (see ConfigurationLocked and UnlockConfiguration(ReadOnlySpan<Byte>).
The YubiKey will reboot as part of this change. This will cause
this IYubiKeyDevice
object to become stale, and future connection
attempts using this object are likely to fail. To get fresh
IYubiKeys
, use the YubiKey enumeration functions such as
FindAll() and FindByTransport(Transport).
To see which USB features are available on the YubiKey, see AvailableUsbCapabilities. At least one of these capabilities must be enabled.
Piv
is available. All other
capabilities will be disabled. The new set of enabled USB capabilities will be
printed to the console, showing that only Piv
is enabled over USB.
IEnumerable<IYubiKeyDevice> yubiKeys =
YubiKey.FindAll()
.Where(d => d.AvailableUsbCapabilities.HasFlag(YubiKeyCapabilities.Piv));
foreach (IYubiKeyDevice yubiKey in yubiKeys)
{
device.SetEnabledUsbCapabilities(YubiKeyCapabilities.Piv);
}
// The devices may need a little time to finish rebooting
sleep(100);
// Get fresh IYubiKeys
IEnumerable<IYubiKeyDevice> freshYubiKeys =
YubiKey.FindAll()
.Where(d => d.AvailableUsbCapabilities.HasFlag(YubiKeyCapabilities.Piv));
int i = 1;
foreach (IYubiKeyDevice yubiKey in freshYubiKeys)
{
Console.PrintLine($"{i:} {yubiKey.SerialNumber} - {yubiKey.EnabledUsbCapabilities}");
}
YubiKeyCapabilities desiredUsbCapabilities = yubiKey.EnabledUsbCapabilities; // Selectively enable Piv
desiredUsbCapabilities |= YubiKeyCapabilities.Piv; // Selectively disable Otp
desiredUsbCapabilities &= ~YubiKeyCapabilities.Otp; yubiKey.SetEnabledUsbCapabilities(desiredUsbCapabilities);IYubiKeyDevice yubiKey = YubiKey.FindAll().First();