Skip to content

Commit dc9fc52

Browse files
authored
Merge pull request #268 from Yubico/docs-slot-access-codes
docs: Improvements to slot access codes how-to
2 parents 1beaf11 + 18b935d commit dc9fc52

File tree

2 files changed

+54
-48
lines changed

2 files changed

+54
-48
lines changed

docs/users-manual/application-otp/how-to-slot-access-codes.md

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,30 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1616
See the License for the specific language governing permissions and
1717
limitations under the License. -->
1818

19-
# How to set, reset, remove, and use slot access codes
19+
# How to set, modify, remove, and use slot access codes
2020

2121
The YubiKey's OTP application [slots](xref:OtpSlots) can be protected by a six-byte access code. Once a slot is
22-
configured with an access code, that slot cannot be reconfigured in any way unless the correct access code in provided
22+
configured with an access code, that slot cannot be reconfigured in any way unless the correct access code is provided
2323
during the reconfiguration operation.
2424

25-
> [!NOTE]
26-
> Attempting to perform an OTP application configuration operation without providing the correct access code will result
27-
> in the following exception:
28-
>
29-
> ```System.InvalidOperationException has been thrown.```
30-
> ```YubiKey Operation Failed. [Warning, state of non-volatile memory is unchanged.]```
25+
Attempting to perform a slot configuration operation without providing the correct access code will result
26+
in the following exception:
27+
28+
```System.InvalidOperationException has been thrown.```
29+
```YubiKey Operation Failed. [Warning, state of non-volatile memory is unchanged.]```
3130

32-
So for example, let's say that the short press slot of a key was configured with a Yubico OTP credential and a slot
33-
access code. If you want to reconfigure the slot with an OATH HOTP credential, you will have to provide the slot's
34-
access code when calling ``ConfigureHotp()``.
31+
## Slot access code properties
3532

36-
Access codes can only be set, reset, or removed during another slot configuration operation:
33+
Access codes can only be set, modified, or removed during one of the following slot configuration operations:
3734

3835
- [ConfigureYubicoOtp()](xref:Yubico.YubiKey.Otp.OtpSession.ConfigureYubicoOtp%28Yubico.YubiKey.Otp.Slot%29)
3936
- [ConfigureHotp()](xref:Yubico.YubiKey.Otp.OtpSession.ConfigureHotp%28Yubico.YubiKey.Otp.Slot%29)
4037
- [ConfigureChallengeResponse()](xref:Yubico.YubiKey.Otp.OtpSession.ConfigureChallengeResponse%28Yubico.YubiKey.Otp.Slot%29)
4138
- [ConfigureStaticPassword()](xref:Yubico.YubiKey.Otp.OtpSession.ConfigureStaticPassword%28Yubico.YubiKey.Otp.Slot%29)
4239
- [UpdateSlot()](xref:Yubico.YubiKey.Otp.OtpSession.UpdateSlot%28Yubico.YubiKey.Otp.Slot%29)
4340

41+
Of these options, the **only** method that allows you to configure a slot access code without changing the slot's current cryptographic credential is ``UpdateSlot()``. However, calling ``UpdateSlot()`` will revert a number of other slot settings (such as ``SetAppendCarriageReturn()``) to their default states unless otherwise specified during the operation. See [How to update slot settings](xref:OtpUpdateSlot) for more information.
42+
4443
> [!NOTE]
4544
> If a slot is configured with an access code,
4645
> calling [ConfigureNdef()](xref:Yubico.YubiKey.Otp.OtpSession.ConfigureNdef%28Yubico.YubiKey.Otp.Slot%29) will fail,
@@ -49,17 +48,17 @@ Access codes can only be set, reset, or removed during another slot configuratio
4948
> code,
5049
> you cannot set one when calling ``ConfigureNdef()``.
5150
52-
## Slot access code properties
53-
5451
Access codes must be exactly six
5552
bytes ([MaxAccessCodeLength](xref:Yubico.YubiKey.Otp.SlotAccessCode.MaxAccessCodeLength)).
5653
The [SlotAccessCode](xref:Yubico.YubiKey.Otp.SlotAccessCode) container class pads the code with zeros (0x00) if less
5754
than six bytes are provided and throws an exception if more than six bytes are provided.
5855

5956
If a slot is configured with an access code, that code must be specified during any reconfiguration operation. In
60-
addition, if you don’t also resupply the same (or any) code as a "new" access code, an access code will not be carried
57+
addition, if you don’t resupply the same (or any) code as a "new" access code, an access code will not be carried
6158
over to the new slot configuration, and the slot will no longer be protected after reconfiguration.
6259

60+
If a slot is protected by an access code, deleting the slot's configuration requires the use of the compatible [DeleteSlotConfiguration](xref:Yubico.YubiKey.Otp.OtpSession.DeleteSlotConfiguration%28Yubico.YubiKey.Otp.Slot%29) method.
61+
6362
## Example code
6463

6564
Before running any of the code provided below, make sure you have already connected to a particular YubiKey on your host
@@ -73,19 +72,23 @@ IEnumerable<IYubiKeyDevice> yubiKeyList = YubiKeyDevice.FindAll();
7372
var yubiKey = yubiKeyList.First();
7473
```
7574

76-
## Exampe: set a slot access code
75+
### Example: set a slot access code
7776

7877
To set a slot's access code when no access code is present,
7978
call [SetNewAccessCode()](xref:Yubico.YubiKey.Otp.Operations.OperationBase%601.SetNewAccessCode%28Yubico.YubiKey.Otp.SlotAccessCode%29)
8079
during a slot configuration operation, and provide the access code as a ``SlotAccessCode`` object. Prior to the
8180
configuration operation, initialize the ``SlotAccessCode`` object by passing it the access code
8281
in ``ReadOnlyMemory<byte>`` form.
8382

83+
In this example, we are setting a new access code while configuring the long press slot with a new HOTP credential.
84+
8485
```C#
8586
using (OtpSession otp = new OtpSession(yubiKey))
8687
{
88+
// example HOTP key
8789
ReadOnlyMemory<byte> hmacKey = new byte[ConfigureHotp.HmacKeySize] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
8890

91+
// example slot access code
8992
ReadOnlyMemory<byte> accessCodeBytes = new byte[SlotAccessCode.MaxAccessCodeLength] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, };
9093
SlotAccessCode accessCode = new SlotAccessCode(accessCodeBytes);
9194

@@ -96,79 +99,81 @@ using (OtpSession otp = new OtpSession(yubiKey))
9699
}
97100
```
98101

99-
## Example: reset a slot access code
102+
### Example: modify a slot access code
100103

101-
To reset a slot's access code, you must provide the current access code
104+
To modify a slot's access code, you must provide the current access code
102105
with [UseCurrentAccessCode()](xref:Yubico.YubiKey.Otp.Operations.OperationBase%601.UseCurrentAccessCode%28Yubico.YubiKey.Otp.SlotAccessCode%29)
103-
followed by the new access code with ``SetNewAccessCode()``:
106+
followed by the new access code with ``SetNewAccessCode()`` during a slot configuration operation.
107+
108+
In this example, we are reconfiguring the long press slot with a new access code via the ``UpdateSlot()`` method. ``UpdateSlot()`` will not modify the slot's cryptographic configuration. However, it will revert a number of other slot settings (such as ``SetAppendCarriageReturn()``) to their default states unless otherwise specified during the operation.
104109

105110
```C#
106111
using (OtpSession otp = new OtpSession(yubiKey))
107112
{
108-
ReadOnlyMemory<byte> hmacKey = new byte[ConfigureHotp.HmacKeySize] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
109-
113+
// Example current slot access code.
110114
ReadOnlyMemory<byte> currentAccessCodeBytes = new byte[SlotAccessCode.MaxAccessCodeLength] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, };
111115
SlotAccessCode currentAccessCode = new SlotAccessCode(currentAccessCodeBytes);
112116

117+
// Example new slot access code.
113118
ReadOnlyMemory<byte> newAccessCodeBytes = new byte[SlotAccessCode.MaxAccessCodeLength] { 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, };
114119
SlotAccessCode newAccessCode = new SlotAccessCode(newAccessCodeBytes);
115120

116-
otp.ConfigureHotp(Slot.LongPress)
117-
.UseKey(hmacKey)
121+
otp.UpdateSlot(Slot.LongPress)
118122
.UseCurrentAccessCode(currentAccessCode)
119123
.SetNewAccessCode(newAccessCode)
120124
.Execute();
121125
}
122126
```
123127

124-
## Example: remove a slot access code
128+
### Example: remove a slot access code
125129

126-
If you want to remove a slot's access code, you must either:
130+
If you want to remove a slot's access code during a configuration operation, you can either:
127131

128-
- provide a new access code of all zeros, or
129-
- only call ``UseCurrentAccessCode()`` during the reconfiguration operation. The slot's access code will be removed if a
130-
code is not provided via ``SetNewAccessCode()`` after calling ``UseCurrentAccessCode()``.
132+
- provide a new access code of all zeros with ``SetNewAccessCode()``, or
133+
- skip the ``SetNewAccessCode()`` call entirely
131134

132135
> [!NOTE]
133-
> A 6-byte access code of zeros (0x00) is considered no access code. The factory default state of the access code for
134-
> each OTP slot is all zeros.
136+
> A 6-byte access code of zeros (0x00) is the factory default state for each OTP slot.
135137
136138
Once the access code is removed, you do not need to call ``UseCurrentAccessCode()`` with subsequent configuration
137139
operations.
138140

139-
> [!NOTE]
140-
> Technically, if a slot does not have an access code, you could provide any 6-byte code
141-
> with ``UseCurrentAccessCode()``, and the operation would succeed.
141+
In this example, we are effectively removing the access code from the long press slot by providing a new code of all zeros during the ``UpdateSlot()`` operation. ``UpdateSlot()`` will not modify the slot's cryptographic configuration. However, it will revert a number of other slot settings (such as ``SetAppendCarriageReturn()``) to their default states unless otherwise specified during the operation.
142142

143143
```C#
144144
using (OtpSession otp = new OtpSession(yubiKey))
145145
{
146-
ReadOnlyMemory<byte> hmacKey = new byte[ConfigureHotp.HmacKeySize] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
147-
146+
// Example current access code.
148147
ReadOnlyMemory<byte> currentAccessCodeBytes = new byte[SlotAccessCode.MaxAccessCodeLength] { 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, };
149148
SlotAccessCode currentAccessCode = new SlotAccessCode(currentAccessCodeBytes);
150149

151150
// New access code of all zeros.
152151
ReadOnlyMemory<byte> newAccessCodeBytes = new byte[SlotAccessCode.MaxAccessCodeLength] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
153152
SlotAccessCode newAccessCode = new SlotAccessCode(newAccessCodeBytes);
154153

155-
otp.ConfigureHotp(Slot.LongPress)
156-
.UseKey(hmacKey)
154+
otp.UpdateSlot(Slot.LongPress)
157155
.UseCurrentAccessCode(currentAccessCode)
158156
.SetNewAccessCode(newAccessCode)
159157
.Execute();
160158
}
161159
```
162160

163-
## Example: provide a slot access code during a configuration operation
161+
### Example: provide a slot access code during a configuration operation
164162

165163
Once a slot has been configured with an access code, you must provide that access code with ``UseCurrentAccessCode()``
166164
when performing a configuration operation on that slot. To retain the access code, you must also
167-
call ``SetNewAccessCode()``. If you do not call ``SetNewAccessCode()``, the access code will be removed.
165+
call ``SetNewAccessCode()`` and provide the same access code. If you do not call ``SetNewAccessCode()``, the access code will be removed.
166+
167+
> [!NOTE]
168+
> If a slot does not have an access code, providing any 6-byte code
169+
> with ``UseCurrentAccessCode()`` during a configuration operation will succeed.
170+
171+
In this example, we are reconfiguring an access code-protected long press slot with a new Yubico OTP credential. The access code is carried over to the new slot configuration by the ``SetNewAccessCode(currentAccessCode)`` call.
168172

169173
```C#
170174
using (OtpSession otp = new OtpSession(yubiKey))
171175
{
176+
// Example current access code.
172177
ReadOnlyMemory<byte> currentAccessCodeBytes = new byte[SlotAccessCode.MaxAccessCodeLength] { 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, };
173178
SlotAccessCode currentAccessCode = new SlotAccessCode(currentAccessCodeBytes);
174179

@@ -185,19 +190,19 @@ using (OtpSession otp = new OtpSession(yubiKey))
185190
}
186191
```
187192

188-
In this example, the slot is now configured with a Yubico OTP credential and is still protected by the same access
189-
code (``currentAccessCode``).
190-
191-
## Deleting a slot configuration when an access code is present
193+
### Example: deleting a slot configuration when an access code is present
192194

193195
To delete a slot configuration that is protected with an access code, you must
194196
call [DeleteSlotConfiguration](xref:Yubico.YubiKey.Otp.OtpSession.DeleteSlotConfiguration%28Yubico.YubiKey.Otp.Slot%29)
195-
and provide the current access code with ``UseCurrentAccessCode()``. You cannot set a new access code during this
196-
operation--calling ``SetNewAccessCode()`` will succeed, but the operation will not be applied.
197+
and provide the current access code with ``UseCurrentAccessCode()``.
198+
199+
You cannot set a new access code during this
200+
operation. The ``DeleteSlotConfiguration`` operation will still succeed if you call ``SetNewAccessCode()``, but the new access code will not be applied.
197201

198202
```C#
199203
using (OtpSession otp = new OtpSession(yubiKey))
200204
{
205+
// Example current access code.
201206
ReadOnlyMemory<byte> currentAccessCodeBytes = new byte[SlotAccessCode.MaxAccessCodeLength] { 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, };
202207
SlotAccessCode currentAccessCode = new SlotAccessCode(currentAccessCodeBytes);
203208

@@ -207,5 +212,6 @@ using (OtpSession otp = new OtpSession(yubiKey))
207212
}
208213
```
209214

210-
To delete a slot configuration that is not protected with an access code,
211-
use [DeleteSlot()](xref:Yubico.YubiKey.Otp.OtpSession.DeleteSlot%28Yubico.YubiKey.Otp.Slot%29).
215+
> [!NOTE]
216+
> To delete a slot configuration that is not protected with an access code,
217+
use [DeleteSlot()](xref:Yubico.YubiKey.Otp.OtpSession.DeleteSlot%28Yubico.YubiKey.Otp.Slot%29).

docs/users-manual/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
href: application-otp/how-to-delete-a-slot-configuration.md
116116
- name: How to swap slot configurations
117117
href: application-otp/how-to-swap-slot-configs.md
118-
- name: How to set, reset, remove, and use slot access codes
118+
- name: How to set, modify, remove, and use slot access codes
119119
href: application-otp/how-to-slot-access-codes.md
120120
- name: OTP commands and APDUs
121121
href: application-otp/otp-commands.md

0 commit comments

Comments
 (0)