Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PowerShell Wrapper for OpenSSL to Test Certificates Fast with Extended Functionality
function test-certificate([string[]]$domains, $contextLength = 10, [switch]$download) {
$cacertPath = "${env:USERPROFILE}\cacert.pem"
if (-not(Test-Path $cacertPath)) {
Invoke-WebRequest "https://curl.se/ca/cacert.pem" -OutFile "${env:USERNAME}\cacert.pem"
}
foreach ($domain in $domains) {
$connectDomain = $domain + ":443"
if ($download) {
echo "q" |
openssl s_client -servername $domain -connect $connectDomain -CAfile $cacertPath |
openssl x509 -text |
Out-File "C:\Users\$env:USERNAME\downloads\$domain.txt" -Force
Write-Host "~~~" -ForegroundColor darkcyan
Write-Host "Cert Dumped to 'C:\Users\$env:USERNAME\downloads\$domain.txt'" -ForegroundColor darkcyan
Write-Host "~~~" -ForegroundColor darkcyan
Pause
}
echo "q" |
openssl s_client -connect $connectDomain -CAfile $cacertPath |
openssl x509 -noout -enddate -text -nameopt multiline |
sls "notAfter.*|DNS:.*"
echo "q" |
openssl s_client -connect $connectDomain -CAfile $cacertPath |
sls "certificate chain" -Context $contextLength
if ($domains.length -gt 1) { Pause }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment