Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkutaj/79ecd4da773d3878dc45330748be3ee0 to your computer and use it in GitHub Desktop.
Save pkutaj/79ecd4da773d3878dc45330748be3ee0 to your computer and use it in GitHub Desktop.
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