Skip to content

Commit 2cea3b6

Browse files
authored
Merge pull request #348 from Yubico/dennisdyallo/fix-device-props
fix: certain YubiKeyDevice properties were not being updated in the YubiKeyDevice
2 parents 1a5e5be + cdb58df commit 2cea3b6

File tree

3 files changed

+297
-116
lines changed

3 files changed

+297
-116
lines changed

Yubico.YubiKey/src/Yubico/YubiKey/IYubiKeyDevice.cs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,10 @@ bool TryConnect(
400400
/// </para>
401401
///
402402
/// <para>
403-
/// Modifies the value of <see cref="IYubiKeyDeviceInfo.ChallengeResponseTimeout"/>. This
404-
/// requires the YubiKey's configuration to be unlocked (see
405-
/// <see cref="IYubiKeyDeviceInfo.ConfigurationLocked"/> and
403+
/// Modifies the value of <see cref="IYubiKeyDeviceInfo.ChallengeResponseTimeout"/>.
404+
/// After successful execution, the <see cref="IYubiKeyDeviceInfo.ChallengeResponseTimeout"/> property
405+
/// will immediately reflect the new value. This requires the YubiKey's configuration
406+
/// to be unlocked (see <see cref="IYubiKeyDeviceInfo.ConfigurationLocked"/> and
406407
/// <see cref="UnlockConfiguration(ReadOnlySpan{byte})"/>.
407408
/// </para>
408409
/// </remarks>
@@ -432,9 +433,10 @@ bool TryConnect(
432433
/// </para>
433434
///
434435
/// <para>
435-
/// Modifies the value of <see cref="IYubiKeyDeviceInfo.AutoEjectTimeout"/>. This
436-
/// requires the YubiKey's configuration to be unlocked (see
437-
/// <see cref="IYubiKeyDeviceInfo.ConfigurationLocked"/> and
436+
/// Modifies the value of <see cref="IYubiKeyDeviceInfo.AutoEjectTimeout"/>.
437+
/// After successful execution, the <see cref="IYubiKeyDeviceInfo.AutoEjectTimeout"/> property
438+
/// will immediately reflect the new value. This requires the YubiKey's configuration
439+
/// to be unlocked (see <see cref="IYubiKeyDeviceInfo.ConfigurationLocked"/> and
438440
/// <see cref="UnlockConfiguration(ReadOnlySpan{byte})"/>.
439441
/// </para>
440442
/// <para>
@@ -465,6 +467,11 @@ bool TryConnect(
465467
/// </summary>
466468
/// <remarks>
467469
/// <para>
470+
/// After successful execution, the <see cref="DeviceFlags"/> property
471+
/// will immediately reflect the new value.
472+
/// </para>
473+
///
474+
/// <para>
468475
/// YubiKeys prior to firmware version 5 can use
469476
/// <see cref="SetLegacyDeviceConfiguration(YubiKeyCapabilities, byte, bool, int)"/> to enable
470477
/// <see cref="DeviceFlags.TouchEject"/>.
@@ -499,7 +506,8 @@ bool TryConnect(
499506
/// </para>
500507
///
501508
/// <para>
502-
/// See <see cref="IYubiKeyDeviceInfo.ConfigurationLocked"/>.
509+
/// See <see cref="IYubiKeyDeviceInfo.ConfigurationLocked"/>. After successful execution,
510+
/// the <see cref="IYubiKeyDeviceInfo.ConfigurationLocked"/> property will immediately be set to <c>true</c>.
503511
/// </para>
504512
/// <para>
505513
/// Once the lock code is set, no changes can be made to the YubiKey's user-settable
@@ -537,7 +545,8 @@ bool TryConnect(
537545
///
538546
/// <remarks>
539547
/// <para>
540-
/// See <see cref="IYubiKeyDeviceInfo.ConfigurationLocked"/>.
548+
/// See <see cref="IYubiKeyDeviceInfo.ConfigurationLocked"/>. After successful execution,
549+
/// the <see cref="IYubiKeyDeviceInfo.ConfigurationLocked"/> property will immediately be set to <c>false</c>.
541550
/// </para>
542551
/// <para>
543552
/// By removing the lock code, changes can be made to the YubiKey's user-settable
@@ -648,12 +657,26 @@ void SetLegacyDeviceConfiguration(
648657
int autoEjectTimeout = 0);
649658

650659
/// <summary>
651-
/// Sets the <see cref="IYubiKeyDeviceInfo.IsNfcRestricted"/> on the <see cref="YubiKeyDeviceInfo"/>
660+
/// Sets the <see cref="IYubiKeyDeviceInfo.IsNfcRestricted"/> value.
652661
/// </summary>
653-
/// <param name="enabled">Set this value to true to enable, otherwise false</param>
662+
/// <remarks>
663+
/// <para>
664+
/// After successful execution, the <see cref="IYubiKeyDeviceInfo.IsNfcRestricted"/> property
665+
/// will immediately reflect the new value.
666+
/// </para>
667+
/// <para>
668+
/// This operation requires the YubiKey's configuration to be unlocked (see
669+
/// <see cref="IYubiKeyDeviceInfo.ConfigurationLocked"/> and
670+
/// <see cref="UnlockConfiguration(ReadOnlySpan{byte})"/>.
671+
/// </para>
672+
/// </remarks>
673+
/// <param name="enabled">Set this value to true to restrict NFC, false to allow NFC.</param>
654674
/// <exception cref="InvalidOperationException">
655675
/// The command failed to complete.
656676
/// </exception>
677+
/// <exception cref="NotSupportedException">
678+
/// This feature is not supported on this YubiKey version.
679+
/// </exception>
657680
void SetIsNfcRestricted(bool enabled);
658681

659682
/// <summary>

Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Instance.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ public void SetChallengeResponseTimeout(int seconds)
373373
{
374374
throw new InvalidOperationException(response.StatusMessage);
375375
}
376+
377+
// Update cached property to reflect the new configuration
378+
if (_yubiKeyDeviceInfo is YubiKeyDeviceInfo deviceInfo)
379+
{
380+
deviceInfo.ChallengeResponseTimeout = (byte)seconds;
381+
}
376382
}
377383

378384
/// <inheritdoc/>
@@ -394,6 +400,12 @@ public void SetAutoEjectTimeout(int seconds)
394400
{
395401
throw new InvalidOperationException(response.StatusMessage);
396402
}
403+
404+
// Update cached property to reflect the new configuration
405+
if (_yubiKeyDeviceInfo is YubiKeyDeviceInfo deviceInfo)
406+
{
407+
deviceInfo.AutoEjectTimeout = seconds;
408+
}
397409
}
398410

399411
/// <inheritdoc/>
@@ -411,6 +423,12 @@ public void SetIsNfcRestricted(bool enabled)
411423
{
412424
throw new InvalidOperationException(response.StatusMessage);
413425
}
426+
427+
// Update cached property to reflect the new configuration
428+
if (_yubiKeyDeviceInfo is YubiKeyDeviceInfo deviceInfo)
429+
{
430+
deviceInfo.IsNfcRestricted = enabled;
431+
}
414432
}
415433

416434
/// <inheritdoc/>
@@ -426,6 +444,12 @@ public void SetDeviceFlags(DeviceFlags deviceFlags)
426444
{
427445
throw new InvalidOperationException(response.StatusMessage);
428446
}
447+
448+
// Update cached property to reflect the new configuration
449+
if (_yubiKeyDeviceInfo is YubiKeyDeviceInfo deviceInfo)
450+
{
451+
deviceInfo.DeviceFlags = deviceFlags;
452+
}
429453
}
430454

431455
/// <inheritdoc/>
@@ -457,6 +481,12 @@ public void LockConfiguration(ReadOnlySpan<byte> lockCode)
457481
{
458482
throw new InvalidOperationException(response.StatusMessage);
459483
}
484+
485+
// Update cached property to reflect the new configuration
486+
if (_yubiKeyDeviceInfo is YubiKeyDeviceInfo deviceInfo)
487+
{
488+
deviceInfo.ConfigurationLocked = true;
489+
}
460490
}
461491

462492
/// <inheritdoc/>
@@ -483,6 +513,12 @@ public void UnlockConfiguration(ReadOnlySpan<byte> lockCode)
483513
{
484514
throw new InvalidOperationException(response.StatusMessage);
485515
}
516+
517+
// Update cached property to reflect the new configuration
518+
if (_yubiKeyDeviceInfo is YubiKeyDeviceInfo deviceInfo)
519+
{
520+
deviceInfo.ConfigurationLocked = false;
521+
}
486522
}
487523

488524
/// <inheritdoc/>

0 commit comments

Comments
 (0)