Skip to content

Commit c6fd1c8

Browse files
committed
Formating
Basic Pester Update documentation
1 parent a599fdb commit c6fd1c8

4 files changed

Lines changed: 64 additions & 14 deletions

File tree

Docs/Commands/Set-YubikeyOTP.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ online version:
55
schema: 2.0.0
66
---
77

8-
# Set-YubikeyOTP
8+
# Set-YubiKeyOTP
99

1010
## SYNOPSIS
1111
Configure OTP slots
@@ -14,28 +14,34 @@ Configure OTP slots
1414

1515
### Yubico OTP
1616
```
17-
Set-YubikeyOTP -Slot <Slot> [-YubicoOTP] [-PublicID <Byte[]>] [-PrivateID <Byte[]>] [-SecretKey <Byte[]>]
17+
Set-YubiKeyOTP -Slot <Slot> [-YubicoOTP] [-PublicID <Byte[]>] [-PrivateID <Byte[]>] [-SecretKey <Byte[]>]
1818
[-Upload] [-WhatIf] [-Confirm] [<CommonParameters>]
1919
```
2020

2121
### Static Password
2222
```
23-
Set-YubikeyOTP -Slot <Slot> [-StaticPassword] -Password <SecureString> [-KeyboardLayout <KeyboardLayout>]
23+
Set-YubiKeyOTP -Slot <Slot> [-StaticPassword] -Password <SecureString> [-KeyboardLayout <KeyboardLayout>]
2424
[-AppendCarriageReturn] [-WhatIf] [-Confirm] [<CommonParameters>]
2525
```
2626

2727
### Static Generated Password
2828
```
29-
Set-YubikeyOTP -Slot <Slot> [-StaticGeneratedPassword] -PasswordLength <Int32>
29+
Set-YubiKeyOTP -Slot <Slot> [-StaticGeneratedPassword] -PasswordLength <Int32>
3030
[-KeyboardLayout <KeyboardLayout>] [-AppendCarriageReturn] [-WhatIf] [-Confirm] [<CommonParameters>]
3131
```
3232

3333
### ChallengeResponse
3434
```
35-
Set-YubikeyOTP -Slot <Slot> [-ChallengeResponse] [-SecretKey <Byte[]>]
35+
Set-YubiKeyOTP -Slot <Slot> [-ChallengeResponse] [-SecretKey <Byte[]>]
3636
[-Algorithm <ChallengeResponseAlgorithm>] [-RequireTouch] [-WhatIf] [-Confirm] [<CommonParameters>]
3737
```
3838

39+
### HOTP
40+
```
41+
Set-YubiKeyOTP -Slot <Slot> [-SecretKey <Byte[]>] [-AppendCarriageReturn] [-HOTP] [-Base32Secret <String>]
42+
[-WhatIf] [-Confirm] [<CommonParameters>]
43+
```
44+
3945
## DESCRIPTION
4046
Allows the configuration of the YubiKey OTP slots (2). The YubiKey OTP slots can be configured with:
4147

@@ -105,7 +111,22 @@ field and "pressing Enter" on behalf of the user.
105111
106112
```yaml
107113
Type: SwitchParameter
108-
Parameter Sets: Static Password, Static Generated Password
114+
Parameter Sets: Static Password, Static Generated Password, HOTP
115+
Aliases:
116+
117+
Required: False
118+
Position: Named
119+
Default value: None
120+
Accept pipeline input: False
121+
Accept wildcard characters: False
122+
```
123+
124+
### -Base32Secret
125+
Base32 encoded secret key for HOTP
126+
127+
```yaml
128+
Type: String
129+
Parameter Sets: HOTP
109130
Aliases:
110131

111132
Required: False
@@ -130,6 +151,21 @@ Accept pipeline input: False
130151
Accept wildcard characters: False
131152
```
132153
154+
### -HOTP
155+
Allows configuration of HOTP mode
156+
157+
```yaml
158+
Type: SwitchParameter
159+
Parameter Sets: HOTP
160+
Aliases:
161+
162+
Required: False
163+
Position: Named
164+
Default value: None
165+
Accept pipeline input: False
166+
Accept wildcard characters: False
167+
```
168+
133169
### -KeyboardLayout
134170
Keyboard layout to be used.
135171
@@ -226,7 +262,7 @@ Sets the Secret Key, defaults to random 16 bytes.
226262
227263
```yaml
228264
Type: Byte[]
229-
Parameter Sets: Yubico OTP, ChallengeResponse
265+
Parameter Sets: Yubico OTP, ChallengeResponse, HOTP
230266
Aliases:
231267

232268
Required: False

Module/Cmdlets/OTP/SetYubikeyOTP.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ protected override void BeginProcessing()
168168

169169

170170
/// Main processing method that configures the YubiKey OTP settings based on the selected mode
171-
protected override void ProcessRecord()
171+
protected override void ProcessRecord()
172172
{
173173
using (var otpSession = new OtpSession((YubiKeyDevice)YubiKeyModule._yubikey!))
174174
{
175175
WriteDebug($"Working with {ParameterSetName}");
176-
if ((Slot == Yubico.YubiKey.Otp.Slot.ShortPress && !otpSession.IsShortPressConfigured) ||
177-
(Slot == Yubico.YubiKey.Otp.Slot.LongPress && !otpSession.IsLongPressConfigured) ||
176+
if ((Slot == Yubico.YubiKey.Otp.Slot.ShortPress && !otpSession.IsShortPressConfigured) ||
177+
(Slot == Yubico.YubiKey.Otp.Slot.LongPress && !otpSession.IsLongPressConfigured) ||
178178
ShouldProcess($"Yubikey OTP {Slot}", "Set"))
179179
{
180180
switch (ParameterSetName)
@@ -268,7 +268,7 @@ protected override void ProcessRecord()
268268
// Configure challenge-response mode
269269
Memory<byte> _CRsecretKey = new Memory<byte>(new byte[20]);
270270
ConfigureChallengeResponse configureCR = otpSession.ConfigureChallengeResponse(Slot);
271-
271+
272272
// Handle Secret Key configuration
273273
if (SecretKey is null)
274274
{
@@ -310,7 +310,7 @@ protected override void ProcessRecord()
310310
// Configure HOTP mode
311311
Memory<byte> _HOTPsecretKey = new Memory<byte>(new byte[20]);
312312
ConfigureHotp configureHOTP = otpSession.ConfigureHotp(Slot);
313-
313+
314314
// Handle Secret Key configuration
315315
if (Base32Secret != null)
316316
{
@@ -336,7 +336,8 @@ protected override void ProcessRecord()
336336
configureHOTP.Execute();
337337

338338
// Return both raw and Base32 representations of the key
339-
WriteObject(new {
339+
WriteObject(new
340+
{
340341
SecretKey = _HOTPsecretKey.ToArray(),
341342
Base32Secret = powershellYK.support.Base32.Encode(_HOTPsecretKey.ToArray())
342343
});

Module/support/Base32.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ public static byte[] Decode(string base32String)
9090
return result;
9191
}
9292
}
93-
}
93+
}

Pester/420-OTP-HOTP.tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Describe "OTP HOTP Tests" -Tag "OTP",'OTP-HOTP' {
2+
It -Name "Setting should not throw" -Test {
3+
{$return = Set-YubiKeyOTP -Slot ShortPress -HOTP -SecretKey ([byte[]]@(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)) -Confirm:$false} | Should -Not -Throw
4+
}
5+
It -Name "Verify that it sets it correctly" -Test {
6+
$return = Set-YubiKeyOTP -Slot ShortPress -HOTP -SecretKey ([byte[]]@(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)) -Confirm:$false
7+
$return.Base32Secret | Should -Be "AEBAGBAFAYDQQCIKBMGA2DQPCAIREEYU"
8+
}
9+
It -Name "Verify that it sets it correctly from Base32" -Test {
10+
$return = Set-YubiKeyOTP -Slot ShortPress -HOTP -Base32Secret 'QRFJ7DTIVASL3PNYXWFIQAQN5RKUJD4U' -Confirm:$false
11+
$return.SecretKey | Should -Be @(0x84, 0x4a, 0x9f, 0x8e, 0x68, 0xa8, 0x24, 0xbd, 0xbd, 0xb8, 0xbd, 0x8a, 0x88, 0x02, 0x0d, 0xec, 0x55, 0x44, 0x8f, 0x94)
12+
}
13+
}

0 commit comments

Comments
 (0)