Table of Contents

Class ConfigureChallengeResponse

Namespace
Yubico.YubiKey.Otp.Operations
Assembly
Yubico.YubiKey.dll

Configures a YubiKey's OTP slot to perform challenge-response using either the Yubico OTP or the HMAC-SHA1 algorithm.

public class ConfigureChallengeResponse : OperationBase<ConfigureChallengeResponse>
Inheritance
object
ConfigureChallengeResponse
Inherited Members

Remarks

This class is not to be instantiated by non-SDK code. Instead, you will get a reference to an instance of this class by calling ConfigureChallengeResponse(Slot).

Once you have a reference to an instance, the member methods of this class can be used to chain together configurations using a builder pattern.

Challenge-response mode needs to either have the UseHmacSha1ChallengeResponseMode(bool) or the UseYubicoOtpChallengeResponseMode(bool) setting selected.

Fields

HmacSha1KeySize

The key for an HMAC-SHA1 operation is 20 bytes.

public const int HmacSha1KeySize = 20

Field Value

int

YubiOtpKeySize

The key for a Yubico OTP operation is 16 bytes.

public const int YubiOtpKeySize = 16

Field Value

int

Methods

ExecuteOperation()

Execute the operation here.

protected override void ExecuteOperation()

Remarks

This method is called after pre-launch code has run. Everything that could be validated should have been before this method is called.

The only validation could that should be in this method are things that could not be checked in the PreLaunchOperation() method. For example, if an operation must be completed in multiple steps, and subsequent steps depend on the success of previous steps, then it must be in this method by necessity.

GenerateKey(Memory<byte>)

Generates a cryptographically random series of bytes as the key for the credential.

public ConfigureChallengeResponse GenerateKey(Memory<byte> key)

Parameters

key Memory<byte>

Returns

ConfigureChallengeResponse

The current ConfigureChallengeResponse instance.

Remarks

Generating a key is not compatible with setting an explicit byte collection as the key. Specifying both will result in an exception.

Exceptions

InvalidOperationException

This will be thrown if the caller called UseKey(ReadOnlyMemory<byte>) before calling this method.

PreLaunchOperation()

Validate all settings and choices here.

protected override void PreLaunchOperation()

Remarks

All possible validation should be done here. The point of this method is to simplify the ExecuteOperation() method that each operation must implement.

Conflicting choices that could not be checked by the OtpSettings<T> methods should be checked here.

Many of the operation classes use nullable fields (bool?) for choices. This allows the PreLaunchOperation() implementation to verify that a choice has been made. In the ExecuteOperation() method, the field has already been validated, and an exception thrown if it was not set, so null-forgiving operators are used when accessing those fields in ExecuteOperation().

SetAllowUpdate(bool)

Allows certain non-security related settings to be modified after the configuration has been written.

public ConfigureChallengeResponse SetAllowUpdate(bool setConfig = true)

Parameters

setConfig bool

Returns

ConfigureChallengeResponse

The current ConfigureChallengeResponse instance.

Remarks

The list below is of all settings that can be updated when this setting is set. However, some of the options are not compatible with all settings, so it's important to use care when choosing settings to apply later.

UseButton(bool)

Require user acceptance by touching the YubiKey button for challenge-response operations

public ConfigureChallengeResponse UseButton(bool setConfig = true)

Parameters

setConfig bool

Returns

ConfigureChallengeResponse

The current ConfigureChallengeResponse instance.

Remarks

UseHmacSha1()

Configures the challenge-response to use the HMAC-SHA1 algorithm.

public ConfigureChallengeResponse UseHmacSha1()

Returns

ConfigureChallengeResponse

The current ConfigureChallengeResponse instance.

Exceptions

InvalidOperationException

You must choose either Yubico OTP or HMAC-SHA1, but not both.

UseKey(ReadOnlyMemory<byte>)

Explicitly sets the key of the credential.

public ConfigureChallengeResponse UseKey(ReadOnlyMemory<byte> bytes)

Parameters

bytes ReadOnlyMemory<byte>

A collection of bytes to use for the key.

Returns

ConfigureChallengeResponse

The current ConfigureChallengeResponse instance.

Remarks

Setting an explicit key is not compatible with generating a key. Specifying both will result in an exception.

Exceptions

InvalidOperationException

This is thrown when GenerateKey(Memory<byte>) has been called before this.

UseSmallChallenge(bool)

Set when the HMAC challenge will be less than 64-bytes.

public ConfigureChallengeResponse UseSmallChallenge(bool setConfig = true)

Parameters

setConfig bool

Returns

ConfigureChallengeResponse

The current ConfigureChallengeResponse instance.

Remarks

The traditional HMAC challenge is exactly 64-bytes. The YubiKey has a setting that indicates a key of less than 64 bytes.

Warning: It's important to choose this setting correctly. If you set this setting and submit a full 64-byte challenge to the YubiKey, then the last byte will be truncated, resulting in a different response.

This setting is only valid if configuring for an HMAC challenge. If you set this for a Yubico OTP challenge, an System.InvalidOperationException will be thrown when you call Execute().

UseYubiOtp()

Configures the challenge-response to use the Yubico OTP algorithm.

public ConfigureChallengeResponse UseYubiOtp()

Returns

ConfigureChallengeResponse

The current ConfigureChallengeResponse instance.

Exceptions

InvalidOperationException

You must choose either Yubico OTP or HMAC-SHA1, but not both.