Last active
January 31, 2025 09:58
-
-
Save zeehio/8a11138d4d19ac705a80a2f35de9db74 to your computer and use it in GitHub Desktop.
Extract certificate chain from a URL you visit
This file contains hidden or 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
#!/bin/bash | |
# Derived from https://unix.stackexchange.com/a/487546/378468 | |
URL=www.google.com | |
openssl s_client -showcerts -verify 5 -servername "$URL" -connect "$URL":443 < /dev/null | \ | |
awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/{ if(/BEGIN CERTIFICATE/){a++}; out="cert"a".pem"; print >out}' | |
for cert in *.pem; do | |
newname=$(openssl x509 -noout -subject -in $cert | sed -nE 's/.*CN ?= ?([^,]*).*/\1/; s/[ ,.*]/_/g; s/__/_/g; s/_-_/-/; s/^_//g;p' | tr '[:upper:]' '[:lower:]').pem | |
echo "${newname}"; | |
mv "${cert}" "${newname}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment