Created
April 3, 2013 00:43
-
-
Save richo/5297537 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
| function getcertnames() { | |
| if [ -z "${1}" ]; then | |
| echo "ERROR: No domain specified." | |
| return 1 | |
| fi | |
| local domain="${1}" | |
| echo "Testing ${domain}…" | |
| echo # newline | |
| tmp=$(echo -e "GET / HTTP/1.0\nEOT" \ | |
| | openssl s_client -connect "${domain}:443" 2>&1); | |
| if [[ "${tmp}" = *"-----BEGIN CERTIFICATE-----"* ]]; then | |
| certText=$(echo "${tmp}" \ | |
| | openssl x509 -text -certopt "no_header, no_serial, no_version, \ | |
| no_signame, no_validity, no_issuer, no_pubkey, no_sigdump, no_aux"); | |
| echo "Common Name:" | |
| echo # newline | |
| echo "${certText}" | grep "Subject:" | sed -e "s/^.*CN=//"; | |
| echo # newline | |
| echo "Subject Alternative Name(s):" | |
| echo # newline | |
| echo "${certText}" | grep -A 1 "Subject Alternative Name:" \ | |
| | sed -e "2s/DNS://g" -e "s/ //g" | tr "," "\n" | tail -n +2 | |
| return 0 | |
| else | |
| echo "ERROR: Certificate not found."; | |
| return 1 | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment