Created
November 13, 2016 20:42
-
-
Save dmitriysafronov/858e32380f02b4d24bc8bdd7d5df418a to your computer and use it in GitHub Desktop.
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/bash | |
if [[ -z "$1" ]]; then | |
echo "Unified cert?" | |
exit 1 | |
fi | |
if [[ -z "$2" ]]; then | |
echo "Which cert?" | |
exit 1 | |
fi | |
CRT_END="$(grep 'END CERTIFICATE' $1 -no | cut -s -d ':' -f 1 | head -n $2 | tail -n 1)" | |
CRT_BEGIN="$(grep 'BEGIN CERTIFICATE' $1 -no | cut -s -d ':' -f 1 | head -n $2 | tail -n 1)" | |
CRT_LENGTH="$(expr ${CRT_END} - ${CRT_BEGIN} + 1)" | |
cat $1 | head -n ${CRT_END} | tail -n ${CRT_LENGTH} > /tmp/cert.pem | |
openssl x509 -noout -in /tmp/cert.pem -pubkey | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | base64 | |
rm -f /tmp/cert.pem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment