5 echo "Usage: $0 [-v] server [port]" >&2
16 for color
in black red green yellow blue magenta cyan white
19 eval "ANSI_$color=\$'\033[0;3${n}m'"
20 eval "ANSI_BOLD_$color=\$'\033[1;3${n}m'"
21 eval "ANSI_BG_$color=\$'\033[4${n}m'"
31 -v|
--verbose) verbose
=1;;
46 [ -n "$2" ] && port
=$2 || port
=https
52 issuer_file
=`tempfile`
54 trap "rm '$cert' '$issuer_file' '$tmp'" EXIT
56 echo "${ANSI_BOLD_YELLOW}${ANSI_BG_BLUE}Certificate${ANSI_NONE}"
57 openssl s_client
-CApath "$capath" -connect "$address" -servername "$server" -showcerts </dev
/null \
59 if(($a,$b,$c,$d) = /^(verify )(return:(\d+)|error:)(.*)$/s)
63 print "'"${ANSI_BOLD_RED}"'$a$b'"${ANSI_RED}"'";
67 print "'"${ANSI_BOLD_GREEN}"'$a$b";
71 print "'"${ANSI_BOLD_YELLOW}"'$a$b";
73 print "$d'"${ANSI_NONE}"'";
80 1> >(sed -n '/-----BEGIN/,/-----END/p' >"$cert")
83 openssl x509
-noout -serial -issuer -fingerprint -sha1 -text -in "$cert"
86 ocsp_url
=`openssl x509 -noout -ocsp_uri -in "$cert"`
87 startdate
=`openssl x509 -noout -startdate -in "$cert"`
88 enddate
=`openssl x509 -noout -enddate -in "$cert"`
89 fingerprint
=`openssl x509 -noout -fingerprint -in "$cert"`
90 san
=`openssl x509 -noout -text -in "$cert" | grep "X509v3 Subject Alternative Name" -A1 | tail -n 1 | sed -e 's/\bDNS://g'`
92 echo "${ANSI_BOLD_BLUE}${startdate%%=*}: ${ANSI_BOLD_CYAN}${startdate#*=}${ANSI_NONE}"
93 echo "${ANSI_BOLD_BLUE}${enddate%%=*}: ${ANSI_BOLD_CYAN}${enddate#*=}${ANSI_NONE}"
94 echo "${ANSI_BOLD_BLUE}${fingerprint%%=*}: ${ANSI_BOLD_CYAN}${fingerprint#*=}${ANSI_NONE}"
95 echo "${ANSI_BOLD_BLUE}SAN:${ANSI_BOLD_CYAN}" $san "${ANSI_NONE}"
100 echo "${ANSI_BOLD_BLUE}OCSP URL: ${ANSI_BOLD_CYAN}$ocsp_url${ANSI_NONE}"
102 info
=`openssl x509 -noout -text -in "$cert"`
103 issuer_cert_url
=`echo "$info" | grep -m1 "CA Issuers - URI" | cut -d: -f2-`
104 if [ -n "$issuer_cert_url" ]
106 wget
-q "$issuer_cert_url" -O "$issuer_file"
107 if [ "$(file -b "$issuer_file")" != "PEM certificate" ]
109 cat "$issuer_file" > "$tmp"
110 openssl x509
-inform der
-in "$tmp" -out "$issuer_file"
114 issuer_keyid
=`echo "$info" | grep -m1 -A1 "X509v3 Authority Key Identifier:" | grep "keyid:" | cut -d: -f2-`
120 if [ -z "$issuer_keyid" ]
122 echo "${ANSI_BOLD_YELLOW}Authority Key Identifier not found.${ANSI_NONE}" >&2
126 for file in "$capath"/*
128 keyid
=`openssl x509 -noout -text -in "$file" | grep -A1 "X509v3 Subject Key Identifier:" | tail -n1 | tr -d " "`
129 if [ "$keyid" = "$issuer_keyid" ]
131 file=`readlink -m -n "$file"`
132 echo "${ANSI_BOLD_BLUE}Issuer file: ${ANSI_BOLD_CYAN}$file${ANSI_NONE}"
141 echo "${ANSI_BOLD_YELLOW}Authority certificate ${ANSI_YELLOW}($issuer_keyid)${ANSI_BOLD_YELLOW} not found.${ANSI_NONE}" >&2
146 lnbuf
=/usr
/lib
/yazzy-preload
/lnbuf.so
147 [ -e "$lnbuf" ] || lnbuf
=
148 LD_PRELOAD
=$lnbuf openssl ocsp
-issuer "$issuer" -cert "$cert" -url "$ocsp_url" ${verbose:+-text} 2>&1 |\
151 if(($a,$b) = /^(\Q$ENV{cert}\E:|Response verify) (.*)$/is)
153 if($b =~ /^(good|OK)/)
155 print "'"${ANSI_BOLD_GREEN}"'";
159 print "'"${ANSI_BOLD_RED}"'";
161 print "$_'"${ANSI_NONE}"'";
165 print "'"${ANSI_RED}"'$_'"${ANSI_NONE}"'";
173 echo "${ANSI_BOLD_YELLOW}No OCSP URL found in certificate.${ANSI_NONE}" >&2