Created
March 1, 2015 01:28
-
-
Save Kirill888/ca21dc1a2e57ba9f00ad to your computer and use it in GitHub Desktop.
prints server certificate
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/sh | |
exit_with_error () { | |
rr=$1; shift | |
>&2 echo "$@" | |
exit $rr | |
} | |
is_installed () { | |
cmd="$1" | |
hash "${cmd}" 2> /dev/null || exit_with_error 1 "Missing ${cmd}" | |
} | |
parse_cert () { | |
awk 'BEGIN { f = 0; } | |
/^-----BEGIN CERTIFICATE-----/ || f == 1 { f = 1; print; } | |
/^-----END CERTIFICATE-----/ { exit;}' | |
} | |
get_cert () { | |
server="$1" | |
if ct_data=$(openssl s_client -connect "${server}" </dev/null 2> /dev/null) | |
then | |
echo "${ct_data}" | parse_cert | |
else | |
exit_with_error $? "Failed to connect to ${server}" | |
fi | |
} | |
has_right_tools () { | |
is_installed awk && is_installed openssl | |
} | |
has_right_tools && get_cert $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment