Last active
November 10, 2020 01:03
-
-
Save fada21/405d022be078d37339505b0eac4d7cd4 to your computer and use it in GitHub Desktop.
Given a domain name, the code below prints out the public keys in the chain as a SHA-256 hash using base 64 encoding.
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
# use like ./certs.sh www.google.com | |
#!/bin/bash | |
certs=`openssl s_client -servername $1 -host $1 -port 443 -showcerts </dev/null 2>/dev/null | sed -n '/Certificate chain/,/Server certificate/p'` | |
rest=$certs | |
while [[ "$rest" =~ '-----BEGIN CERTIFICATE-----' ]] | |
do | |
cert="${rest%%-----END CERTIFICATE-----*}-----END CERTIFICATE-----" | |
rest=${rest#*-----END CERTIFICATE-----} | |
echo `echo "$cert" | grep 's:' | sed 's/.*s:\(.*\)/\1/'` | |
echo "$cert" | openssl x509 -pubkey -noout | | |
openssl rsa -pubin -outform der 2>/dev/null | | |
openssl dgst -sha256 -binary | openssl enc -base64 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tnq man