Skip to content

Instantly share code, notes, and snippets.

@KingOfSpades
Last active January 30, 2023 12:32
Show Gist options
  • Save KingOfSpades/351479a47ea5a07381b77a3067bc52de to your computer and use it in GitHub Desktop.
Save KingOfSpades/351479a47ea5a07381b77a3067bc52de to your computer and use it in GitHub Desktop.
SSL Tools
# Request certificate from https endpoint and show info for macOS
function certinfo() {
if [[ "$1" == *":"* ]]; then
_port=$( echo $1 | cut -f2 -d':')
else
_port=443
fi
echo "\n"
echo -e "\033[0;97m\033[41m Using $1:$_port \033[0m"
openssl s_client -connect $1:$_port -servername $1 \
< /dev/null 2>/dev/null \
| openssl x509 \
-fingerprint \
-issuer \
-subject \
-dates \
-noout \
-in /dev/stdin
echo "\n"
echo -e '\033[0;97m\033[41m Chain Info \033[0m'
echo "--------------------------"
openssl s_client -connect $1:$_port < /dev/null 2>/dev/null | grep -e '[si]:'
echo "--------------------------"
}
# Request certificate from https endpoint and show info for macOS
# but uses the openssl client from brew instead of the mac version
function certinfobrew() {
if [[ "$1" == *":"* ]]; then
_port=$( echo $1 | cut -f2 -d':')
else
_port=443
fi
echo "\n"
echo -e "\033[0;97m\033[41m Using $1:$_port \033[0m"
/usr/local/opt/openssl@3/bin/openssl s_client -connect $1:$_port -servername $1 \
< /dev/null 2>/dev/null \
| /usr/local/opt/openssl@3/bin/openssl x509 \
-fingerprint \
-issuer \
-subject \
-dates \
-noout \
-in /dev/stdin
echo "\n"
echo -e '\033[0;97m\033[41m Chain Info \033[0m'
echo "--------------------------"
openssl s_client -connect $1:$_port < /dev/null 2>/dev/null | grep -e '[si]:'
echo "--------------------------"
}
# Parses selected cert
function certparse() {
echo -e "\033[0;97m\033[41m Parsing \033[0m"
openssl x509 -noout -subject -dates -issuer -in $1
}
# Parses cert from clipboard
function certparseclipboard() {
headClip=$(pbpaste | head -n 10)
echo -e "\033[0;97m\033[41m Parsing from cliboard \033[0m"
echo -e "\n \033[0;32\033[47m Head of file \n $headClip \n ... \033[0m \n"
echo -e "Certificate Information"
echo -e "--------------------------"
pbpaste | openssl x509 -noout -subject -dates -issuer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment