Skip to content

Instantly share code, notes, and snippets.

@DastanIqbal
Created August 9, 2021 14:08
Show Gist options
  • Save DastanIqbal/bb859b8fb1ccec4b65706b26e2c3fcb3 to your computer and use it in GitHub Desktop.
Save DastanIqbal/bb859b8fb1ccec4b65706b26e2c3fcb3 to your computer and use it in GitHub Desktop.
Find website certificate RSA 2048 SHA256
#!/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