File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,24 @@ def _switch_starttls(self, sock):
155155 # Read Mysql welcome message
156156 data = self ._read_n_bytes_from_socket (sock , bytes_to_read )
157157 sock .sendall (packet )
158+ elif protocol == "smtp" :
159+ self .log .debug ('Switching connection to encrypted for %s protocol' , protocol )
160+
161+ # read & check server hello
162+ initial_banner = sock .recv (4096 )
163+ if not initial_banner .startswith (b'220' ):
164+ raise Exception ('SMTP server did not greet correctly' )
165+
166+ # send client hello
167+ sock .sendall (f'EHLO { self .agent_check ._server_hostname } \r \n ' .encode ('ascii' ))
168+ # drain EHLO response
169+ sock .recv (4096 )
170+
171+ # upgrade connection
172+ sock .sendall (b'STARTTLS\r \n ' )
173+ data = sock .recv (1024 )
174+ if not data .startswith (b'220' ):
175+ raise Exception ('SMTP endpoint does not support STARTTLS' )
158176 else :
159177 raise Exception ('Unsupported starttls protocol: ' + protocol )
160178
You can’t perform that action at this time.
0 commit comments