-
Notifications
You must be signed in to change notification settings - Fork 8
/
s_dump_smtp
executable file
·55 lines (49 loc) · 1.5 KB
/
s_dump_smtp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /bin/sh
# s_dump_smtp (Bourne shell script) -- Connects to an SMTP server, invokes STARTTLS and shows info about the X.509 certificate
#
# Version: 1.2
# Copyright: (c) 2019 Alastair Irvine <alastair@plug.org.au>
# Keywords: openssl, SSL, TLS, secure certificate
# Licence: This file is released under the GNU General Public License v2
#
# Uses "Server Name Indication" (SNI) with TLS and EHLO
# Similar to "-nameopt RFC2253" but with semicolons and without dn_rev
OPTS="-nameopt esc_2253,esc_ctrl,esc_msb,utf8,dump_nostr,dump_unknown,dump_der,sep_semi_plus_space,sname"
SELF=$(basename "$0")
if [ "$1" = -P ] ; then
PORT=$2
shift
shift
fi
if [ "$1" = -E ] ; then
EHLO=$2
shift
shift
else
# Reverse-resolve the external IPv4 address to get the EHLO hostname
# ...if the `dig` command exists
if type dig >/dev/null
then
ip=$(dig -4 +short myip.opendns.com a @resolver1.opendns.com)
if reverse_record=$(dig +short -x $ip)
then
# Removed the trailing "." from `dig` output
EHLO=${reverse_record%.}
fi
fi
fi
if [ $# -lt 1 -o $# -gt 3 ] ; then
echo "Usage: $SELF [ -P <port> ] <servername> [ <sitename> ] [ <opts> ]" >&2
exit 1
fi
if [ -z "$SSL_PATH" ] ; then
if [ -d /etc/pki/tls ] ; then
SSL_PATH=/etc/pki/tls
else
SSL_PATH=/etc/ssl
fi
fi
openssl s_client -connect $1:${PORT-587} ${3:--no_ssl3} -CApath $SSL_PATH/certs/ \
-starttls smtp -servername ${2:-$1} ${EHLO:+-name $EHLO} < /dev/null |
openssl x509 -text $OPTS -noout |
${PAGER:-less}