Skip to content

Commit

Permalink
.functions: Improve getcertnames
Browse files Browse the repository at this point in the history
Follow-up to 12bb9da.

Many thanks to @dserodio!
  • Loading branch information
mathiasbynens committed Mar 9, 2013
1 parent 12bb9da commit e216473
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .functions
Expand Up @@ -82,7 +82,7 @@ function gz() {
# Test if HTTP compression (RFC 2616 + SDCH) is enabled for a given URL.
# Send a fake UA string for sites that sniff it instead of using the Accept-Encoding header. (Looking at you, ajax.googleapis.com!)
function httpcompression() {
encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding"
local encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding"
}

# Syntax-highlight JSON strings or files
Expand Down Expand Up @@ -126,15 +126,15 @@ function getcertnames() {
return 1
fi

domain="${1}"
local domain="${1}"
echo "Testing ${domain}…"
echo # newline

tmp=$(echo -e "GET / HTTP/1.0\nEOT" \
local tmp=$(echo -e "GET / HTTP/1.0\nEOT" \
| openssl s_client -connect "${domain}:443" 2>&1);

if [[ "${tmp}" = *"-----BEGIN CERTIFICATE-----"* ]]; then
certText=$(echo "${tmp}" \
local 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:"
Expand All @@ -144,7 +144,7 @@ function getcertnames() {
echo "Subject Alternative Name(s):"
echo # newline
echo "${certText}" | grep -A 1 "Subject Alternative Name:" \
| head -2 | tail -1 | sed "s/DNS://g" | sed "s/ //g" | tr "," "\n"
| sed -e "2s/DNS://g" -e "s/ //g" | tr "," "\n" | tail -n +2
return 0
else
echo "ERROR: Certificate not found.";
Expand Down

0 comments on commit e216473

Please sign in to comment.