Created
February 2, 2021 13:43
-
-
Save MLukman/9a5b97b6f90bb7c913ce8738dee2b5ce to your computer and use it in GitHub Desktop.
A simple Linux shell script to get the SHA256 hash of the public key of SSL certificate of an online server (most commonly to implement SSL pinning)
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
#!/bin/sh | |
if [ -z $(which openssl) ]; then | |
echo "Error: OpenSSL is not installed" >&2 | |
exit 1 | |
fi | |
if [ "$#" -lt 1 ] || [ -n "${1##*:*}" ]; then | |
echo "Usage: $0 URL:PORT" >&2 | |
exit 1 | |
fi | |
HOSTPORT=$1 | |
echo | openssl s_client -connect $HOSTPORT 2> /dev/null | openssl x509 -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment