Perform comprehensive PKI infrastructure analysis and remediation for complex cryptographic failures affecting multiple systems or services.
- Analyze Certificate Revocation List (CRL) and Online Certificate Status Protocol (OCSP) connectivity:
# Test CRL and OCSP endpoints
$certs = Get-ChildItem Cert:\LocalMachine\My
foreach ($cert in $certs) {
$extensions = $cert.Extensions | Where-Object {$_.Oid.FriendlyName -eq "CRL Distribution Points"}
if ($extensions) {
Write-Host "Certificate: $($cert.Subject)"
Write-Host "CRL URLs: $($extensions.Format($false))"
# Test CRL accessibility
$crlUrls = $extensions.Format($false) -split "`n" | Where-Object {$_ -match "http"}
foreach ($url in $crlUrls) {
try {
$response = Invoke-WebRequest -Uri $url.Trim() -TimeoutSec 10
Write-Host " CRL accessible: $($url.Trim()) - Status: $($response.StatusCode)"
} catch {
Write-Host " CRL inaccessible: $($url.Trim()) - Error: $($_.Exception.Message)"
}
}
}
}
Check domain controller certificate health in Active Directory environments:# Check domain controller certificates
Get-ADDomainController -Filter * | ForEach-Object {
$dcName = $_.Name
Write-Host "Checking DC: $dcName"
try {
$cert = Invoke-Command -ComputerName $dcName -ScriptBlock {
Get-ChildItem Cert:\LocalMachine\My | Where-Object {
$_.Subject -like "*$env:COMPUTERNAME*" -and $_.HasPrivateKey
}
}
if ($cert.NotAfter -lt (Get-Date).AddDays(30)) {
Write-Host " WARNING: Certificate expires soon on $dcName"
}
} catch {
Write-Host " ERROR: Cannot check certificate on $dcName"
}
}
Validate time synchronization across the infrastructure:# Check time synchronization (critical for certificate validation)
w32tm /query /status
w32tm /query /peers
# Compare local time with domain controller
$dcTime = Invoke-Command -ComputerName (Get-ADDomainController).Name -ScriptBlock {Get-Date}
$localTime = Get-Date
$timeDiff = ($localTime - $dcTime).TotalSeconds
if ([Math]::Abs($timeDiff) -gt 300) {
Write-Host "WARNING: Time difference with DC is $timeDiff seconds (threshold: 300s)"
Write-Host "Run: w32tm /resync /force"
}
Rebuild certificate chain and trust relationships:# Clear certificate cache and rebuild chains
CertLM.msc
# Or via command line:
certutil -pulse
certutil -generateSSTFromWU roots.sst
certutil -addstore -f root roots.sst
Check Group Policy settings affecting cryptographic operations:# Check relevant Group Policy settings
Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Cryptography\Configuration\SSL\00010002" -ErrorAction SilentlyContinue
Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Cryptography\Configuration\Local\SSL\00010002" -ErrorAction SilentlyContinue
Generate comprehensive cryptographic health report:# Create detailed cryptographic infrastructure report
$report = @{}
$report.Timestamp = Get-Date
$report.ComputerName = $env:COMPUTERNAME
$report.Certificates = Get-ChildItem Cert:\LocalMachine\My | Select-Object Subject, NotAfter, HasPrivateKey, Thumbprint
$report.ExpiredCerts = Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.NotAfter -lt (Get-Date)}
$report.CryptoServices = Get-Service -Name "CryptSvc","BITS","EventLog" | Select-Object Name, Status
$report.RecentCryptoEvents = Get-WinEvent -FilterHashtable @{LogName='Security'; Id=5061; StartTime=(Get-Date).AddDays(-7)} -ErrorAction SilentlyContinue
$report | ConvertTo-Json -Depth 3 | Out-File "C:\temp\CryptoHealthReport_$(Get-Date -Format 'yyyyMMdd_HHmmss').json"
Pro tip: In enterprise environments, consider implementing automated certificate lifecycle management and monitoring to prevent Event ID 5061 occurrences.