Created
March 1, 2022 10:17
-
-
Save pkutaj/79ecd4da773d3878dc45330748be3ee0 to your computer and use it in GitHub Desktop.
PowerShell Wrapper for OpenSSL to Test Certificates Fast with Extended Functionality
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([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