-
-
Save Synchro/a83dbb7464c0885056ca5de0f38b3b9b to your computer and use it in GitHub Desktop.
Generate HPKP or TLSA fingerprint
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 | |
# Uses pkey instead of rsa so it also works with ecc certs | |
case "$1" in | |
hpkp) | |
case "$2" in | |
key) | |
openssl pkey -in "$3" -outform der -pubout 2>/dev/null | openssl dgst -sha256 -binary | openssl enc -base64 | |
;; | |
csr) | |
openssl req -in "$3" -pubkey -noout | openssl pkey -pubin -outform der 2>/dev/null | openssl dgst -sha256 -binary | openssl enc -base64 | |
;; | |
crt) | |
openssl x509 -in "$3" -pubkey -noout | openssl pkey -pubin -outform der 2>/dev/null | openssl dgst -sha256 -binary | openssl enc -base64 | |
;; | |
esac | |
;; | |
tlsa) | |
case "$2" in | |
key) | |
openssl pkey -in "$3" -outform der -pubout 2>/dev/null | openssl dgst -sha512 -hex | |
;; | |
csr) | |
openssl req -in "$3" -pubkey -noout | openssl pkey -pubin -outform der 2>/dev/null | openssl dgst -sha512 -hex | |
;; | |
crt) | |
openssl x509 -in "$3" -pubkey -noout | openssl pkey -pubin -outform der 2>/dev/null | openssl dgst -sha512 -hex | |
;; | |
esac | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment