Skip to content

Commit 7c38a4e

Browse files
committed
Add support for custom SMTP EHLO hostname
1 parent dd7e3b8 commit 7c38a4e

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

sslyze/connection_helpers/opportunistic_tls_helpers.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ def prepare_socket_for_tls_handshake(self, sock: socket.socket) -> None:
6161
class _SmtpHelper(_OpportunisticTlsHelper):
6262
"""Perform an SMTP StartTLS negotiation."""
6363

64+
def __init__(self, smtp_ehlo_hostname: str):
65+
self._smtp_ehlo_hostname = smtp_ehlo_hostname
66+
6467
def prepare_socket_for_tls_handshake(self, sock: socket.socket) -> None:
6568
# Get the SMTP banner
6669
sock.recv(2048)
6770

6871
# Send a EHLO and wait for the 250 status
69-
sock.send(b"EHLO sslyze.scan\r\n")
72+
sock.send(f"EHLO {self._smtp_ehlo_hostname}\r\n".encode("ascii"))
7073
data = sock.recv(2048)
7174
if b"250 " not in data:
7275
raise OpportunisticTlsError(f"SMTP EHLO was rejected: {repr(data)}")
@@ -220,14 +223,16 @@ class _PostgresHelper(_GenericOpportunisticTlsHelper):
220223

221224

222225
def get_opportunistic_tls_helper(
223-
protocol: ProtocolWithOpportunisticTlsEnum, xmpp_to_hostname: Optional[str]
226+
protocol: ProtocolWithOpportunisticTlsEnum, xmpp_to_hostname: Optional[str], smtp_ehlo_hostname: str
224227
) -> _OpportunisticTlsHelper:
225228
helper_cls = _START_TLS_HELPER_CLASSES[protocol]
226-
if protocol not in [ProtocolWithOpportunisticTlsEnum.XMPP, ProtocolWithOpportunisticTlsEnum.XMPP_SERVER]:
227-
opportunistic_tls_helper = helper_cls()
228-
else:
229+
if protocol in [ProtocolWithOpportunisticTlsEnum.XMPP, ProtocolWithOpportunisticTlsEnum.XMPP_SERVER]:
229230
if xmpp_to_hostname is None:
230231
raise ValueError("Received None for xmpp_to_hostname")
231232
opportunistic_tls_helper = helper_cls(xmpp_to=xmpp_to_hostname)
233+
elif protocol == ProtocolWithOpportunisticTlsEnum.SMTP:
234+
opportunistic_tls_helper = helper_cls(smtp_ehlo_hostname)
235+
else:
236+
opportunistic_tls_helper = helper_cls()
232237

233238
return opportunistic_tls_helper

sslyze/connection_helpers/tls_connection.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ def _do_pre_handshake(self) -> None:
233233
# Do the Opportunistic/StartTLS negotiation if needed
234234
if self._network_configuration.tls_opportunistic_encryption:
235235
opportunistic_tls_helper = get_opportunistic_tls_helper(
236-
self._network_configuration.tls_opportunistic_encryption, self._network_configuration.xmpp_to_hostname
236+
self._network_configuration.tls_opportunistic_encryption,
237+
self._network_configuration.xmpp_to_hostname,
238+
self._network_configuration.smtp_ehlo_hostname,
237239
)
238240
try:
239241
opportunistic_tls_helper.prepare_socket_for_tls_handshake(sock)

sslyze/server_setting.py

+3
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class ServerNetworkConfiguration:
173173
xmpp_to_hostname: The hostname to set within the `to` attribute of the XMPP stream. If not supplied, the
174174
server's hostname will be used. Should only be set if the supplied `tls_opportunistic_encryption` is an
175175
XMPP protocol.
176+
smtp_ehlo_hostname: The hostname to set in the SMTP EHLO. If not supplied, the default of "sslyze.scan"
177+
will be used. Should only be set if the supplied `tls_opportunistic_encryption` is SMTP.
176178
network_timeout: The timeout (in seconds) to be used when attempting to establish a connection to the
177179
server.
178180
network_max_retries: The number of retries SSLyze will perform when attempting to establish a connection
@@ -184,6 +186,7 @@ class ServerNetworkConfiguration:
184186
tls_client_auth_credentials: Optional[ClientAuthenticationCredentials] = None
185187

186188
xmpp_to_hostname: Optional[str] = None
189+
smtp_ehlo_hostname: str = "sslyze.scan"
187190

188191
network_timeout: int = 5
189192
network_max_retries: int = 3

0 commit comments

Comments
 (0)