|
46 | 46 | /// Set-YubiKeyOTP -Slot ShortPress -HOTP -Base32Secret "QRFJ7DTIVASL3PNYXWFIQAQN5RKUJD4U" -AppendCarriageReturn |
47 | 47 | /// |
48 | 48 | /// .EXAMPLE |
| 49 | +/// # Configure HOTP with hex encoded secret and carriage return |
| 50 | +/// Set-YubiKeyOTP -Slot ShortPress -HOTP -HexSecret "0102030405060708090a0b0c0d0e0f1011121314" -AppendCarriageReturn |
| 51 | +/// |
| 52 | +/// .EXAMPLE |
49 | 53 | /// # Configure HOTP with TAB before OTP code for easier form navigation |
50 | 54 | /// Set-YubiKeyOTP -Slot ShortPress -HOTP -Base32Secret "QRFJ7DTIVASL3PNYXWFIQAQN5RKUJD4U" -SendTabFirst |
51 | 55 | /// |
@@ -158,6 +162,10 @@ public class SetYubikeyOTPCommand : PSCmdlet |
158 | 162 | [Parameter(Mandatory = false, ValueFromPipeline = false, HelpMessage = "Base32 encoded secret key for HOTP", ParameterSetName = "HOTP")] |
159 | 163 | public string? Base32Secret { get; set; } |
160 | 164 |
|
| 165 | + // Hex encoded secret key for HOTP mode |
| 166 | + [Parameter(Mandatory = false, ValueFromPipeline = false, HelpMessage = "Hex encoded secret key for HOTP", ParameterSetName = "HOTP")] |
| 167 | + public string? HexSecret { get; set; } |
| 168 | + |
161 | 169 | // Use 8 digits instead of 6 for HOTP mode |
162 | 170 | [Parameter(Mandatory = false, ValueFromPipeline = false, HelpMessage = "Use 8 digits instead of 6 for HOTP", ParameterSetName = "HOTP")] |
163 | 171 | public SwitchParameter Use8Digits { get; set; } |
@@ -326,12 +334,18 @@ protected override void ProcessRecord() |
326 | 334 | Memory<byte> _HOTPsecretKey = new Memory<byte>(new byte[20]); |
327 | 335 | ConfigureHotp configureHOTP = otpSession.ConfigureHotp(Slot); |
328 | 336 |
|
329 | | - // Handle Secret Key configuration |
| 337 | + // Handle Secret Key configuration using Base32 |
330 | 338 | if (Base32Secret != null) |
331 | 339 | { |
332 | 340 | _HOTPsecretKey = powershellYK.support.Base32.Decode(Base32Secret); |
333 | 341 | configureHOTP = configureHOTP.UseKey(_HOTPsecretKey); |
334 | 342 | } |
| 343 | + // Handle Secret Key configuration using Hex |
| 344 | + else if (HexSecret != null) |
| 345 | + { |
| 346 | + _HOTPsecretKey = powershellYK.support.Hex.Decode(HexSecret); |
| 347 | + configureHOTP = configureHOTP.UseKey(_HOTPsecretKey); |
| 348 | + } |
335 | 349 | else if (SecretKey is null) |
336 | 350 | { |
337 | 351 | configureHOTP = configureHOTP.GenerateKey(_HOTPsecretKey); |
@@ -362,10 +376,10 @@ protected override void ProcessRecord() |
362 | 376 |
|
363 | 377 | configureHOTP.Execute(); |
364 | 378 |
|
365 | | - // Return both raw and Base32 representations of the key |
| 379 | + // Return both Hex and Base32 representations of the key |
366 | 380 | WriteObject(new |
367 | 381 | { |
368 | | - SecretKey = _HOTPsecretKey.ToArray(), |
| 382 | + HexSecret = powershellYK.support.Hex.Encode(_HOTPsecretKey.ToArray()), |
369 | 383 | Base32Secret = powershellYK.support.Base32.Encode(_HOTPsecretKey.ToArray()) |
370 | 384 | }); |
371 | 385 | break; |
|
0 commit comments