29 lines
1.7 KiB
PowerShell
29 lines
1.7 KiB
PowerShell
function Get-SamsaraCertificates {
|
|
param($Result)
|
|
$collection = @{ stores = @() }
|
|
Invoke-SamsaraRead $Result 'Local machine certificate store list' {
|
|
$collection.stores = @(Get-ChildItem -LiteralPath 'Cert:\LocalMachine' -ErrorAction Stop)
|
|
}
|
|
# Listing store names is not evidence that any listed store was readable.
|
|
if ($collection.stores.Count -gt 0) { $Result.successful_subchecks-- }
|
|
foreach ($store in $collection.stores) {
|
|
# Certificate provider PSPath may omit LocalMachine (including on 5.1).
|
|
# Construct an explicit provider path from the enumerated store name.
|
|
$storeName = [string]$store.PSChildName
|
|
Invoke-SamsaraRead $Result 'Certificate store query' {
|
|
if ($storeName -notmatch '^[A-Za-z0-9_. -]+$') { throw 'Invalid store name' }
|
|
$certificates = @(Get-ChildItem -LiteralPath ('Cert:\LocalMachine\' + $storeName) -ErrorAction Stop)
|
|
foreach ($certificate in $certificates) {
|
|
Invoke-SamsaraRead $Result 'Certificate metadata projection' {
|
|
$row = [pscustomobject]@{ subject = [string]$certificate.Subject; issuer = [string]$certificate.Issuer
|
|
expires = $certificate.NotAfter.ToUniversalTime().ToString('o'); thumbprint = [string]$certificate.Thumbprint
|
|
store = $storeName }
|
|
$null = ConvertTo-Json -InputObject $row -Depth 4 -ErrorAction Stop
|
|
$Result.data += $row
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$Result.limitations += 'Public LocalMachine certificate metadata only. Private keys, password-protected files, CurrentUser stores, application bindings and off-store certificates are not read.'
|
|
}
|