Skip to content

Instantly share code, notes, and snippets.

@pkutaj
Created March 12, 2021 04:17
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/9fe57c5a1208256f63d256c19da2e3ce to your computer and use it in GitHub Desktop.
Save pkutaj/9fe57c5a1208256f63d256c19da2e3ce to your computer and use it in GitHub Desktop.
PowerShell's script to validate / download OpenSSL certificate
function test-certificate($domain, $contextLength = 10, [switch]$download) {
$cacertPath = "c:\cacert.pem"
$connectDomain = $domain + ":443"
#<feature> download certificate into a download folder
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 | sls "notAfter.*"
echo "q" | openssl s_client -connect $connectDomain -CAfile $cacertPath | sls "certificate chain" -Context $contextLength
Write-Host "~~~" -ForegroundColor darkcyan
Write-Host "→ If needed, pass a desired output length after domainname" -ForegroundColor darkcyan
Write-Host "→ To update the list of trusted Certificates, run:" -ForegroundColor darkcyan
Write-Host "→ Invoke-WebRequest https://curl.se/ca/cacert.pem -OutFile 'c:\cacert.pem'" -ForegroundColor darkcyan
Write-Host "~~~" -ForegroundColor darkcyan
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment