Created
March 21, 2017 07:13
-
-
Save drscream/82a5392b62c0fbd8d7024ef2ee3d9c41 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Thomas Merkel <[email protected]> | |
# Allow you to show ssl certificate details or show only the PEM | |
# format. | |
export PATH=/opt/pkg/bin:${PATH} | |
show_help() { | |
echo "${0} [-d|-s] host port starttls" | |
echo | |
echo " -d: show details" | |
echo " -s: show only pem format" | |
exit 1 | |
} | |
if (( ${#} < 1 )); then | |
show_help | |
fi | |
OPTION=${1}; shift | |
REMHOST=${1}; shift | |
REMPORT=${1:-443}; shift | |
STARTTLS=${@} | |
if [[ -n ${STARTTLS} ]]; then | |
STARTTLS='-starttls '${STARTTLS} | |
fi | |
save_cert() { | |
echo |\ | |
openssl s_client -connect ${REMHOST}:${REMPORT} -servername ${REMHOST} ${STARTTLS} 2>&1 |\ | |
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | |
} | |
detail_cert() { | |
echo |\ | |
openssl s_client -connect ${REMHOST}:${REMPORT} -servername ${REMHOST} ${STARTTLS} 2>&1 |\ | |
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' |\ | |
openssl x509 -text | |
} | |
case ${OPTION} in | |
-d|-detail) | |
detail_cert | |
;; | |
-s|-save) | |
save_cert | |
;; | |
*) | |
echo -e "/!\\ WARNING: legacy support\n" | |
STARTTLS=${@} | |
REMPORT=${REMHOST:-443} | |
REMHOST=${OPTION} | |
detail_cert | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment