Public/Test-PWSHYBKPIVBio.ps1
|
function Test-PWSHYBKPIVBio { <# .SYNOPSIS Tests a fingerprint match against a locally attached bio-capable YubiKey's PIV application. .DESCRIPTION Wraps "yubico-piv-tool.exe --action verify-bio". Follows Test- verb convention: returns $true/$false rather than throwing on a failed match. A failed match still consumes one of the YubiKey's limited biometric match retries, a real side effect on the device, so this cmdlet supports -WhatIf/-Confirm like Test-PWSHYBKPIVPin. Accepts the "verify-bio" action's config-declared options (-Reader) as dynamic parameters built from Config\Posh-YBKPIV.json. .PARAMETER Reader Name of the smart card reader to target, when more than one is attached. If omitted, yubico-piv-tool.exe uses its own default reader selection. .INPUTS None. This cmdlet does not accept pipeline input. .OUTPUTS Boolean. $true if the fingerprint matched, $false otherwise. .NOTES -Reader is declared dynamically from Config\Posh-YBKPIV.json and therefore does not appear in Get-Help's PARAMETERS/SYNTAX sections. Run `Get-Command Test-PWSHYBKPIVBio -Syntax` for the authoritative, current parameter list. .EXAMPLE Test-PWSHYBKPIVBio Prompts for a fingerprint on the device and returns whether it matched. .LINK https://developers.yubico.com/yubico-piv-tool/Actions/ .LINK Test-PWSHYBKPIVPin #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')] [OutputType([bool])] param() DynamicParam { $dynamicConfig = Read-PWSHYBKPIVConfigFile Get-PWSHYBKPIVActionParameter -Action 'verify-bio' -CmdletWrapping $dynamicConfig.cmdletWrapping } begin { $config = Read-PWSHYBKPIVConfigFile Write-PWSHYBKPIVLog -Config $config -Level Debug -CmdletName $MyInvocation.MyCommand.Name ` -Message 'Cmdlet invoked' -BoundParameters $PSBoundParameters $architecture = Resolve-PWSHYBKPIVArchitecture -Architecture $config.installation.architecture $exePath = Get-PWSHYBKPIVInstallPath -Installation $config.installation -Architecture $architecture if (-not (Test-Path -Path $exePath -PathType Leaf)) { throw "yubico-piv-tool.exe was not found at '$exePath'. Run Install-PWSHYBKPIVTool first." } } end { if (-not $PSCmdlet.ShouldProcess('YubiKey PIV application', 'Verify fingerprint')) { return } try { $null = Invoke-PWSHYBKPIVTool -ExePath $exePath -Action 'verify-bio' ` -CmdletWrapping $config.cmdletWrapping -BoundParameters $PSBoundParameters Write-PWSHYBKPIVLog -Config $config -Level Information -CmdletName $MyInvocation.MyCommand.Name ` -Message 'Fingerprint verified successfully' $true } catch { Write-PWSHYBKPIVLog -Config $config -Level Warning -CmdletName $MyInvocation.MyCommand.Name ` -Message "Fingerprint verification failed: $_" $false } } } |