Created
March 12, 2021 04:17
-
-
Save pkutaj/9fe57c5a1208256f63d256c19da2e3ce to your computer and use it in GitHub Desktop.
PowerShell's script to validate / download OpenSSL certificate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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