Skip to content

Instantly share code, notes, and snippets.

@MLukman
Created February 2, 2021 13:43
Show Gist options
  • Save MLukman/9a5b97b6f90bb7c913ce8738dee2b5ce to your computer and use it in GitHub Desktop.
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)
#!/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