Step 1: Testing Connectivity to a Server¶
Basic Example¶
Before a server can be scanned, SSLyze must ensure that it is able to reach the server. This is achieved using the ServerConnectivityTester class:
def demo_server_connectivity_tester():
try:
server_tester = ServerConnectivityTester(
hostname='smtp.gmail.com',
port=587,
tls_wrapped_protocol=TlsWrappedProtocolEnum.STARTTLS_SMTP
)
print(f'\nTesting connectivity with {server_tester.hostname}:{server_tester.port}...')
server_info = server_tester.perform()
except ServerConnectivityError as e:
# Could not establish an SSL connection to the server
raise RuntimeError(f'Could not connect to {e.server_info.hostname}: {e.error_message}')
return server_info
If the call to ServerConnectivityTester.perform() is successful, it returns a ServerConnectivityInfo object that can then be used for scanning the server. This is described in Step 2: Running Scan Commands Against a Server.
Advanced Usage¶
The ServerConnectivityTester classs provides fine-grained controls regarding how SSLyze should connect to a server. If only a hostname is supplied (like in the example above), default values will be used and SSLyze will assume that the server is an HTTPS server listening on port 443.
Several additional settings can be supplied in order to be more specific about the protocol the SSL/TLS server uses (such as StartTLS) and how to connect to it (for example by supplying an IP address or a client certificate).