diff --git a/bin/executable_show-cert.sh b/bin/executable_show-cert.sh new file mode 100644 index 0000000..0477644 --- /dev/null +++ b/bin/executable_show-cert.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# +# Show SSL Certificate info with openssl. +# Inspired by https://cheat.sh/openssl +# + +function show-cert() { + local host=$1 + local port=${2:-443} + local type=${3:short} + + echo "Certificate info for $host:$port" + echo + if [ "$type" == "pem" ]; then + echo | openssl s_client -connect "$host:$port" 2> /dev/null | \ + awk '/-----BEGIN/,/END CERTIFICATE-----/' + else + echo | openssl s_client -connect "$host:$port" 2> /dev/null | \ + awk '/-----BEGIN/,/END CERTIFICATE-----/' | \ + openssl x509 -noout -subject -dates + fi +} + +if [ $# -lt 1 ]; then + echo "Usage: $0