]>
git.siccegge.de Git - dane-monitoring-plugins.git/blob - check_dane/smtp.py
5 from __future__
import print_function
10 from ssl
import SSLContext
, PROTOCOL_TLSv1_2
, CERT_REQUIRED
11 from socket
import socket
13 from check_dane
.cert
import add_certificate_options
14 from check_dane
.abstract
import DaneChecker
17 class SmtpDaneChecker(DaneChecker
):
18 def _init_connection(self
, family
, host
, port
):
21 connection
= self
._sslcontext
.wrap_socket(socket(family
),
23 connection
.connect((host
, port
))
24 answer
= connection
.recv(512)
27 connection
.send(b
"EHLO localhost\r\n")
28 answer
= connection
.recv(512)
32 connection
= socket(family
=family
)
33 connection
.connect((host
, port
))
34 answer
= connection
.recv(512)
37 connection
.send(b
"EHLO localhost\r\n")
38 answer
= connection
.recv(512)
41 connection
.send(b
"STARTTLS\r\n")
42 answer
= connection
.recv(512)
45 connection
= self
._sslcontext
.wrap_socket(connection
, server_hostname
=host
)
46 connection
.do_handshake()
48 connection
.send(b
"EHLO localhost\r\n")
49 answer
= connection
.recv(512)
65 def _close_connection(self
, connection
):
66 connection
.send(b
"QUIT\r\n")
67 answer
= connection
.recv(512)
75 DaneChecker
.__init
__(self
)
78 def set_args(self
, args
):
79 DaneChecker
.set_args(self
, args
)
83 self
._port
= 465 if args
.ssl
else 25
85 self
._port
= args
.port
87 sslcontext
= SSLContext(PROTOCOL_TLSv1_2
)
88 sslcontext
.verify_mode
= CERT_REQUIRED
89 sslcontext
.load_verify_locations(args
.castore
)
91 self
._sslcontext
= sslcontext
94 def generate_menu(self
, argparser
):
95 DaneChecker
.generate_menu(self
, argparser
)
96 argparser
.add_argument("-p", "--port",
97 action
="store", type=int, default
=0,
99 argparser
.add_argument("--ssl",
101 help="Use direct TLS connection instead of starttls (default: disabled)")
108 logging
.basicConfig(format
='%(levelname)5s %(message)s')
109 checker
= SmtpDaneChecker()
110 parser
= argparse
.ArgumentParser()
112 parser
.add_argument("--verbose", action
="store_true")
113 parser
.add_argument("--quiet", action
="store_true")
115 checker
.generate_menu(parser
)
116 add_certificate_options(parser
)
118 args
= parser
.parse_args()
119 checker
.set_args(args
)
122 logging
.getLogger().setLevel(logging
.DEBUG
)
124 logging
.getLogger().setLevel(logging
.WARNING
)
126 logging
.getLogger().setLevel(logging
.INFO
)
128 return checker
.check()
131 if __name__
== '__main__':