Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Module/Cmdlets/PIV/SetYubikeyPIV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ protected override void ProcessRecord()
}
break;

case "ResetPIN":
case "UnblockPIN":
try
{
WriteDebug("Resetting PIN...");
if (pivSession.TryResetPin(System.Text.Encoding.UTF8.GetBytes(Marshal.PtrToStringUni(Marshal.SecureStringToGlobalAllocUnicode(PUK))!)
, System.Text.Encoding.UTF8.GetBytes(Marshal.PtrToStringUni(Marshal.SecureStringToGlobalAllocUnicode(NewPIN))!)
, out retriesLeft) == false)
Expand Down
15 changes: 9 additions & 6 deletions Pester/210-YubikeyPIV-Codes.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
Describe "Test YubikeyPIV PIV/PUK management" -Tag "Destructive" {
BeforeEach {
Reset-YubikeyPIV -Confirm:$false
}
It "outputs 'Verify that connect works'" {
{Reset-YubikeyPIV -Confirm:$false} | Should -Not -Throw
Get-YubikeyPIV|Select -ExpandProperty PinRetries | Should -Be 3
}
It "outputs 'Test Set-YubikeyPIV -PINRetries 8 -PUKRetries 6'" {
{Reset-YubikeyPIV -Confirm:$false} | Should -Not -Throw
{Connect-YubikeyPIV -PIN (ConvertTo-SecureString -String "123456" -AsPlainText -Force)} | Should -Not -Throw
{Set-YubikeyPIV -PinRetries 8 -PukRetries 6} | Should -Not -Throw
Get-YubikeyPIV|Select -ExpandProperty PinRetries | Should -Be 8
Expand All @@ -16,21 +15,26 @@ Describe "Test YubikeyPIV PIV/PUK management" -Tag "Destructive" {
{Block-YubikeyPIV} | Should -Throw
}
It "outputs 'Test Block-YubikeyPIV -PIN'" {
{Reset-YubikeyPIV -Confirm:$false} | Should -Not -Throw
{Connect-YubikeyPIV -PIN (ConvertTo-SecureString -String "123456" -AsPlainText -Force)} | Should -Not -Throw
{Block-YubikeyPIV -PIN } | Should -Not -Throw
Get-YubikeyPIV|Select -ExpandProperty PinRetries | Should -Be 3
Get-YubikeyPIV|Select -ExpandProperty PinRetriesLeft | Should -Be 0
}
It "outputs 'Test Set-YubiKeyPIV UnblockPIN'" {
Connect-YubikeyPIV -PIN (ConvertTo-SecureString -String "123456" -AsPlainText -Force)
Block-YubikeyPIV -PIN
Get-YubikeyPIV|Select -ExpandProperty PinRetries | Should -Be 3
Get-YubikeyPIV|Select -ExpandProperty PinRetriesLeft | Should -Be 0
Set-YubiKeyPIV -UnblockPIN -NewPIN (ConvertTo-SecureString -String "123456" -AsPlainText -Force) -PUK (ConvertTo-SecureString -String "12345678" -AsPlainText -Force)
Get-YubikeyPIV|Select -ExpandProperty PinRetriesLeft | Should -Be 3
}
It "outputs 'Test Block-YubikeyPIV -PUK'" {
{Reset-YubikeyPIV -Confirm:$false} | Should -Not -Throw
{Connect-YubikeyPIV -PIN (ConvertTo-SecureString -String "123456" -AsPlainText -Force)} | Should -Not -Throw
{Block-YubikeyPIV -PUK } | Should -Not -Throw
Get-YubikeyPIV|Select -ExpandProperty PUKRetries | Should -Be 3
Get-YubikeyPIV|Select -ExpandProperty PUKRetriesLeft | Should -Be 0
}
It "outputs 'Test Block-YubikeyPIV -PIN -PUK'" {
{Reset-YubikeyPIV -Confirm:$false} | Should -Not -Throw
{Connect-YubikeyPIV -PIN (ConvertTo-SecureString -String "123456" -AsPlainText -Force)} | Should -Not -Throw
{Set-YubikeyPIV -PinRetries 4 -PukRetries 5} | Should -Not -Throw
{Block-YubikeyPIV -PIN -PUK } | Should -Not -Throw
Expand All @@ -40,7 +44,6 @@ Describe "Test YubikeyPIV PIV/PUK management" -Tag "Destructive" {
Get-YubikeyPIV|Select -ExpandProperty PUKRetriesLeft | Should -Be 0
}
It "outputs 'Change PIN and Verify'" {
{Reset-YubikeyPIV -Confirm:$false} | Should -Not -Throw
{Set-YubikeyPIV -PIN (ConvertTo-SecureString -String "123456" -AsPlainText -Force) -NewPIN (ConvertTo-SecureString -String "654321" -AsPlainText -Force)} | Should -Not -Throw
{Connect-YubikeyPIV -PIN (ConvertTo-SecureString -String "123456" -AsPlainText -Force)} | Should -Throw
{Connect-YubikeyPIV -PIN (ConvertTo-SecureString -String "654321" -AsPlainText -Force)} | Should -Not -Throw
Expand Down
Loading