Last active
April 28, 2016 22:41
-
-
Save jomat/17d57f2cff748ec8ea6e53e22636a20a to your computer and use it in GitHub Desktop.
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/zsh | |
function retr_cert_base64() { | |
fields=(${(s: :)1}) | |
host=$fields[1] | |
port=$fields[2] | |
sni=$fields[3] | |
proto=$fields[4] | |
[ -z "$sni" ] && servername=$host || servername=$sni | |
[ -n "$proto" ] && starttls="-starttls $proto" | |
openssl s_client -servername $servername -host $host -port $port $starttls </dev/null 2>/dev/null|awk '/^-----BEGIN CERTIFICATE-----$/{p=1;next} p&&/^-----END CERTIFICATE-----$/{p=0};p' | |
} | |
function x509text() { | |
echo -e "-----BEGIN CERTIFICATE-----\n$1\n-----END CERTIFICATE-----"|openssl x509 -text -noout -fingerprint -sha512 2>/dev/null | |
} | |
function end_date() { | |
date '+%s' --date "$(echo $1|sed -n 's/ *Not After : *//p')" | |
} | |
function sha512() { | |
echo $text|sed -n 's/SHA512 Fingerprint=*//p'|tr -d : | |
} | |
function issuer() { | |
echo $text|sed -n 's/ *Issuer: *//p' | |
} | |
function days_left() { | |
echo $((($(end_date $1) - $(date '+%s'))/24/3600)) | |
} | |
cat ~/sslarm/domains.txt|grep -v '^$'|grep -v '^#'|while read line | |
do | |
fields=(${(s: :)line}) | |
host=$fields[1] | |
port=$fields[2] | |
sni=$fields[3] | |
[ -z "$sni" ] && servername=$host || servername=$sni | |
#echo -n $servername:$port\ | |
cert=$(retr_cert_base64 $line) | |
text=$(x509text $cert) | |
#echo $(end_date $text) $(issuer $text) $(sha512 $text) | |
days_left=$(days_left $text) | |
[ $days_left -lt 28 ] && echo $days_left $servername:$port >/dev/stderr || echo $days_left $servername:$port | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment