Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add smtp start_tls implementation
  • Loading branch information
jake-walker committed Jan 14, 2026
commit 9e39beb41dd0869b1108e14c0ccabbceacafbc13
18 changes: 18 additions & 0 deletions tls/datadog_checks/tls/tls_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,24 @@ def _switch_starttls(self, sock):
# Read Mysql welcome message
data = self._read_n_bytes_from_socket(sock, bytes_to_read)
sock.sendall(packet)
elif protocol == "smtp":
self.log.debug('Switching connection to encrypted for %s protocol', protocol)

# read & check server hello
initial_banner = sock.recv(4096)
if not initial_banner.startswith(b'220'):
raise Exception('SMTP server did not greet correctly')

# send client hello
sock.sendall(f'EHLO {self.agent_check._server_hostname}\r\n'.encode('ascii'))
# drain EHLO response
sock.recv(4096)

# upgrade connection
sock.sendall(b'STARTTLS\r\n')
data = sock.recv(1024)
if not data.startswith(b'220'):
raise Exception('SMTP endpoint does not support STARTTLS')
else:
raise Exception('Unsupported starttls protocol: ' + protocol)

Expand Down