Skip to content

Set temporary touch sensitivity #95

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 4 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
1 change: 1 addition & 0 deletions Yubico.YubiKey/src/Yubico/YubiKey/FirmwareVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class FirmwareVersion : IComparable<FirmwareVersion>, IComparable, IEquat
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_3_0 = new FirmwareVersion(5, 3, 0);
internal static readonly FirmwareVersion V5_3_1 = new FirmwareVersion(5, 3, 1);
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);
Expand Down
23 changes: 22 additions & 1 deletion Yubico.YubiKey/src/Yubico/YubiKey/IYubiKeyDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -665,12 +665,33 @@ void SetLegacyDeviceConfiguration(


/// <summary>
/// Sets the <see cref="IYubiKeyDeviceInfo.IsNfcRestricted"/> on the <see cref="YubiKeyDeviceInfo"/>
/// Sets the <see cref="IYubiKeyDeviceInfo.IsNfcRestricted"/> on the <see cref="YubiKeyDeviceInfo"/>
/// </summary>
/// <param name="enabled">Set this value to true to enable, otherwise false</param>
/// <exception cref="InvalidOperationException">
/// The command failed to complete.
/// </exception>
void SetIsNfcRestricted(bool enabled);

/// <summary>
/// Temporarily set the threshold at which a capacitive touch should be considered active.
/// </summary>
/// <remarks>
/// <para>
/// The field is using arbitrary units and has a default value of `6`. A higher value increases the sensor
/// threshold which has the effect of decreasing the sensitivity of the sensor. Lower values increase the
/// sensitivity, but callers cannot reduce the threshold below the default value of `6` which is locked in at
/// manufacturing time. The value should not be any higher than `255`.
/// </para>
/// <para>
/// The value set here is only valid until the next time the YubiKey is power cycled. It does not persist.
/// </para>
/// <para>
/// You should typically not ever need to adjust this value. This is primarily used in the context of automatic
/// provisioning and testing where the YubiKey is being "touched" by electrically grounding the sensor.
/// </para>
/// </remarks>
/// <param name="value">The touch threshold to apply to the YubiKey. Must be a value greater than `6`.</param>
void SetTemporaryTouchThreshold(int value);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File SetDeviceInfoBaseCommsnd.cs line 36, Where do all these tag number coming from? and 0x85 is very different then the other tags

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! They typically come from the internal documentation of the management application which would be provided by the firmware team.

Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ public class SetDeviceInfoBaseCommand
private const byte ResetAfterConfigTag = 0x0c;
private const byte NfcEnabledCapabilitiesTag = 0x0e;
private const byte NfcRestrictedTag = 0x17;
private const byte TempTouchThresholdTag = 0x85;

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

/// <summary>
/// The length that a configuration lock code must be.
Expand All @@ -60,8 +62,6 @@ public class SetDeviceInfoBaseCommand
/// </summary>
public byte? ChallengeResponseTimeout { get; set; }

private ushort? _autoEjectTimeout;

/// <summary>
/// The CCID auto-eject timeout (in seconds). This field is only meaningful if the
/// TouchEject flag in DeviceFlags is set. <see langword="null"/> to leave unchanged.
Expand Down Expand Up @@ -106,6 +106,26 @@ public int? AutoEjectTimeout
/// </summary>
public bool RestrictNfc { get; set; }

/// <summary>
/// Temporarily set the threshold at which a capacitive touch should be considered active.
/// </summary>
/// <remarks>
/// <para>
/// The field is using arbitrary units and has a default value of `6`. A higher value increases the sensor
/// threshold which has the effect of decreasing the sensitivity of the sensor. Lower values increase the
/// sensitivity, but callers cannot reduce the threshold below the default value of `6` which is locked in at
/// manufacturing time.
/// </para>
/// <para>
/// The value set here is only valid until the next time the YubiKey is power cycled. It does not persist.
/// </para>
/// <para>
/// You should typically not ever need to adjust this value. This is primarily used in the context of automatic
/// provisioning and testing where the YubiKey is being "touched" by electrically grounding the sensor.
/// </para>
/// </remarks>
public int? TemporaryTouchThreshold { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="SetDeviceInfoBaseCommand"/> class.
/// </summary>
Expand Down Expand Up @@ -257,6 +277,11 @@ private byte[] GetTlvData()
buffer.WriteByte(NfcRestrictedTag, 1);
}

if (TemporaryTouchThreshold.HasValue)
{
buffer.WriteByte(TempTouchThresholdTag, (byte)TemporaryTouchThreshold.Value);
}

return buffer.Encode();
}
}
Expand Down
37 changes: 37 additions & 0 deletions Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,43 @@ public void SetLegacyDeviceConfiguration(
}
}

/// <inheritdoc />
/// <exception cref="NotSupportedException">
/// The YubiKey does not support this feature.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// The value is less than `6` or greater than `255`.
/// </exception>
/// <exception cref="InvalidOperationException">
/// The YubiKey encountered an error and could not set the setting.
/// </exception>
public void SetTemporaryTouchThreshold(int value)
{
if (!this.HasFeature(YubiKeyFeature.TemporaryTouchThreshold))
{
throw new NotSupportedException(
string.Format(
CultureInfo.CurrentCulture,
ExceptionMessages.NotSupportedByYubiKeyVersion));
}

if (value < 6 || value > 255)
{
throw new ArgumentOutOfRangeException(nameof(value));
}

var command = new MgmtCmd.SetDeviceInfoCommand
{
TemporaryTouchThreshold = value
};

IYubiKeyResponse response = SendConfiguration(command);
if (response.Status != ResponseStatus.Success)
{
throw new InvalidOperationException(response.StatusMessage);
}
}

private IYubiKeyResponse SendConfiguration(MgmtCmd.SetDeviceInfoBaseCommand baseCommand)
{
IYubiKeyConnection? connection = null;
Expand Down
5 changes: 5 additions & 0 deletions Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public enum YubiKeyFeature
/// </summary>
FastUsbReclaim,

/// <summary>
/// The YubiKey allows temporarily adjusting the sensitivity of the capacitive touch sensor.
/// </summary>
TemporaryTouchThreshold,

// OTP application features

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyFeatureExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public static bool HasFeature(this IYubiKeyDevice yubiKeyDevice, YubiKeyFeature
YubiKeyFeature.FastUsbReclaim =>
yubiKeyDevice.FirmwareVersion >= FirmwareVersion.V5_6_0,

YubiKeyFeature.TemporaryTouchThreshold =>
yubiKeyDevice.FirmwareVersion >= FirmwareVersion.V5_3_1,

YubiKeyFeature.YubiHsmAuthApplication =>
yubiKeyDevice.FirmwareVersion >= FirmwareVersion.V5_4_3
&& HasApplication(yubiKeyDevice, YubiKeyCapabilities.YubiHsmAuth),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,10 @@ public void SetIsNfcRestricted(bool enabled)
{
throw new NotImplementedException();
}

public void SetTemporaryTouchThreshold(int value)
{
throw new NotImplementedException();
}
}
}