SetEnabledNfcCapabilities Method
SetEnabledNfcCapabilities(YubiKeyCapabilities)
Sets which NFC features are enabled (and disabled).
void SetEnabledNfcCapabilities(YubiKeyCapabilities yubiKeyCapabilities)
Parameters
Type | Name | Description |
---|---|---|
YubiKeyCapabilities | yubiKeyCapabilities | The desired set of NFC features to enable on the YubiKey. A set flag means that the related capability is enabled. Otherwise, the capability is disabled. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The command failed to complete. |
System.NotSupportedException | An error occurred when attempting to connect to the device. |
Remarks
Requires firmware version >= 5.0.0.
Modifies the value of EnabledNfcCapabilities. 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 NFC features are available on the YubiKey, see AvailableNfcCapabilities.
Piv
is available. All other
capabilities will be disabled. The new set of enabled NFC capabilities will be
printed to the console, showing that only Piv
is enabled over NFC.
IEnumerable<IYubiKeyDevice> yubiKeys =
YubiKey.FindAll()
.Where(d => d.AvailableNfcCapabilities.HasFlag(YubiKeyCapabilities.Piv));
foreach (IYubiKeyDevice yubiKey in yubiKeys)
{
device.SetEnabledNfcCapabilities(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.AvailableNfcCapabilities.HasFlag(YubiKeyCapabilities.Piv));
int i = 1;
foreach (IYubiKeyDevice yubiKey in freshYubiKeys)
{
Console.PrintLine($"{i:} {yubiKey.SerialNumber} - {yubiKey.EnabledNfcCapabilities}");
}
YubiKeyCapabilities desiredNfcCapabilities = yubiKey.EnabledNfcCapabilities; // Selectively enable Piv
desiredNfcCapabilities |= YubiKeyCapabilities.Piv; // Selectively disable Otp
desiredNfcCapabilities &= ~YubiKeyCapabilities.Otp; yubiKey.SetEnabledNfcCapabilities(desiredNfcCapabilities);IYubiKeyDevice yubiKey = YubiKey.FindAll().First();