#!/bin/sh #@kapad`22.277 app=$(basename $0) port= proto= tls= service=$1 [ -z "$1" ] && echo "Usage: $app [--short|--bin] [port] [proto|c2s|s2s|smtps|imaps] ...">&2 && exit 0 #NOTES: # >>> set 1st proto, then port if not a default port # xmpp c2s (-xmpphost ??) # other: ftp|irc|postgres|mysql|lmtp|nntp|sieve|ldap) :; ;; while [ -n "$1" ];do case $1 in --bin) BIN=1; ;; --short) SHORT=1; ;; -*) break; ;; #pops) port=995; ;; # pop) port=995; tls="-starttls $1"; ;; smtps) port=465; ;; smtp) port=587; tls="-starttls $1"; ;; imaps) port=993; ;; imap) port=143; tls="-starttls $1"; ;; c2s|xmpp) port=5222; tls="-starttls xmpp"; ;; s2s|xmpp-server) port=5269; tls="-starttls xmpp-server"; ;; *) echo $1|grep -q '^[0-9]*$' && port=$1 || service="$1"; ;; esac shift 2>/dev/null || true done port=${port:-443} if [ -f "$service" ]; then CERTCMD="cat $service" else CERTCMD="openssl s_client -showcerts -connect $service:$port $tls" fi { echo "service: "$service echo " proto: "$proto echo " port: "$port echo " * : "$CERTCMD $* }|egrep --color "^[^:]*" >&2 echo && read -p "- Continue ? " -r a && echo echo | $CERTCMD "$@" 2>/dev/null \ |{ [ -n "$BIN" ] && { openssl x509 -inform pem|egrep --color '^|^\-.*' ; } \ || { openssl x509 -inform pem -noout -text \ |{ [ -n "$SHORT" ] \ && { egrep -w "CN|Not|DNS|Algorithm:"|tr -s ' '|egrep --color "^[^:]*" ; } \ || cat - }\ |egrep --color "^|^[[:space:]]*[A-Z][^:]*" } } exit $?