@@ -61,12 +61,15 @@ def prepare_socket_for_tls_handshake(self, sock: socket.socket) -> None:
61
61
class _SmtpHelper (_OpportunisticTlsHelper ):
62
62
"""Perform an SMTP StartTLS negotiation."""
63
63
64
+ def __init__ (self , smtp_ehlo_hostname : str ):
65
+ self ._smtp_ehlo_hostname = smtp_ehlo_hostname
66
+
64
67
def prepare_socket_for_tls_handshake (self , sock : socket .socket ) -> None :
65
68
# Get the SMTP banner
66
69
sock .recv (2048 )
67
70
68
71
# 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" ) )
70
73
data = sock .recv (2048 )
71
74
if b"250 " not in data :
72
75
raise OpportunisticTlsError (f"SMTP EHLO was rejected: { repr (data )} " )
@@ -220,14 +223,16 @@ class _PostgresHelper(_GenericOpportunisticTlsHelper):
220
223
221
224
222
225
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
224
227
) -> _OpportunisticTlsHelper :
225
228
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 ]:
229
230
if xmpp_to_hostname is None :
230
231
raise ValueError ("Received None for xmpp_to_hostname" )
231
232
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 ()
232
237
233
238
return opportunistic_tls_helper
0 commit comments