Skip to content

Commit

Permalink
Update black to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
nabla-c0d3 committed Apr 30, 2022
1 parent cbb5d4e commit d43478a
Show file tree
Hide file tree
Showing 46 changed files with 235 additions and 239 deletions.
3 changes: 1 addition & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ sphinx
sphinx-rtd-theme
twine
sphinx-autodoc-typehints
black==19.10b0
click==8.0.4 # TODO(AD): Fix for black; to remove after updating black
black==22.3.0
pytest-cov
faker

Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "sslyze.tex", u"SSLyze Documentation", author, "manual"),
(master_doc, "sslyze.tex", "SSLyze Documentation", author, "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "sslyze", u"SSLyze Documentation", [author], 1)]
man_pages = [(master_doc, "sslyze", "SSLyze Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -147,7 +147,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, "sslyze", u"SSLyze Documentation", author, author, __version__.__description__, "Security"),
(master_doc, "sslyze", "SSLyze Documentation", author, author, __version__.__description__, "Security"),
]

autodoc_member_order = "bysource"
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def get_project_info() -> Dict[str, str]:


def get_include_files() -> List[Tuple[str, str]]:
""""Get the list of non-Python files to package when doing a cx_freeze build.
"""
""" "Get the list of non-Python files to package when doing a cx_freeze build."""
non_python_files = []

# The trust stores
Expand Down
53 changes: 34 additions & 19 deletions sslyze/cli/command_line_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ def get_error_msg(self) -> str:

@dataclass(frozen=True)
class ParsedCommandLine:
"""The result of parsing a command line used to launch sslyze.
"""
"""The result of parsing a command line used to launch sslyze."""

invalid_servers: List[InvalidServerStringError]

Expand Down Expand Up @@ -85,8 +84,7 @@ class ParsedCommandLine:

class CommandLineParser:
def __init__(self, sslyze_version: str) -> None:
"""Generate SSLyze's command line parser.
"""
"""Generate SSLyze's command line parser."""
self.aparser = ArgumentParser(prog="sslyze", description=f"SSLyze version {sslyze_version}")

# Add generic command line options to the parser
Expand All @@ -96,7 +94,9 @@ def __init__(self, sslyze_version: str) -> None:
scan_commands_group = self.aparser.add_argument_group("Scan commands")
for scan_option in self._get_plugin_scan_commands():
scan_commands_group.add_argument(
f"--{scan_option.option}", help=scan_option.help, action=scan_option.action,
f"--{scan_option.option}",
help=scan_option.help,
action=scan_option.action,
)

self.aparser.add_argument(
Expand All @@ -112,8 +112,7 @@ def __init__(self, sslyze_version: str) -> None:
self.aparser.add_argument(dest="target", default=[], nargs="*", help="The list of servers to scan.")

def parse_command_line(self) -> ParsedCommandLine:
"""Parses the command line used to launch SSLyze.
"""
"""Parses the command line used to launch SSLyze."""
args_command_list = self.aparser.parse_args()
args_target_list = []

Expand Down Expand Up @@ -209,7 +208,11 @@ def parse_command_line(self) -> ParsedCommandLine:
for server_string in args_target_list:
try:
# Parse the string supplied via the CLI for this server
(hostname, ip_address, port,) = CommandLineServerStringParser.parse_server_string(server_string)
(
hostname,
ip_address,
port,
) = CommandLineServerStringParser.parse_server_string(server_string)
except InvalidServerStringError as e:
# The server string is malformed
invalid_server_strings.append(e)
Expand All @@ -224,16 +227,25 @@ def parse_command_line(self) -> ParsedCommandLine:
# Connect to the server via an HTTP proxy
# A limitation when using the CLI is that only one http_proxy_settings can be specified for all servers
server_location = ServerNetworkLocation(
hostname=hostname, port=final_port, http_proxy_settings=http_proxy_settings,
hostname=hostname,
port=final_port,
http_proxy_settings=http_proxy_settings,
)
else:
# Connect to the server directly
if ip_address:
server_location = ServerNetworkLocation(hostname=hostname, port=final_port, ip_address=ip_address,)
server_location = ServerNetworkLocation(
hostname=hostname,
port=final_port,
ip_address=ip_address,
)
else:
# No IP address supplied - do a DNS lookup
try:
server_location = ServerNetworkLocation(hostname=hostname, port=final_port,)
server_location = ServerNetworkLocation(
hostname=hostname,
port=final_port,
)
except ServerHostnameCouldNotBeResolved:
invalid_server_strings.append(
InvalidServerStringError(
Expand Down Expand Up @@ -284,9 +296,10 @@ def parse_command_line(self) -> ParsedCommandLine:
scan_commands_extra_arguments_dict: Dict[ScanCommand, plugin_base.ScanCommandExtraArgument] = {}
for scan_command in ScanCommandsRepository.get_all_scan_commands():
cli_connector_cls = ScanCommandsRepository.get_implementation_cls(scan_command).cli_connector_cls
(is_scan_cmd_enabled, extra_args,) = cli_connector_cls.find_cli_options_in_command_line(
args_command_list.__dict__
)
(
is_scan_cmd_enabled,
extra_args,
) = cli_connector_cls.find_cli_options_in_command_line(args_command_list.__dict__)
if is_scan_cmd_enabled:
scan_commands.add(scan_command)
if extra_args:
Expand All @@ -307,8 +320,7 @@ def parse_command_line(self) -> ParsedCommandLine:
)

def _add_default_options(self) -> None:
"""Add default command line options to the parser.
"""
"""Add default command line options to the parser."""
# Updating the trust stores
trust_stores_group = self.aparser.add_argument_group("Trust stores options")
trust_stores_group.add_argument(
Expand Down Expand Up @@ -343,7 +355,11 @@ def _add_default_options(self) -> None:
default="PEM",
)
client_certificate_group.add_argument(
"--pass", metavar="PASSPHRASE", help="Client private key passphrase.", dest="keypass", default="",
"--pass",
metavar="PASSPHRASE",
help="Client private key passphrase.",
dest="keypass",
default="",
)

# Input / output
Expand Down Expand Up @@ -431,8 +447,7 @@ def _add_default_options(self) -> None:

@staticmethod
def _get_plugin_scan_commands() -> List[OptParseCliOption]:
"""Retrieve the list of command line options implemented by the plugins currently available.
"""
"""Retrieve the list of command line options implemented by the plugins currently available."""
scan_commands_options = []
for scan_command in ScanCommandsRepository.get_all_scan_commands():
cli_connector_cls = ScanCommandsRepository.get_implementation_cls(scan_command).cli_connector_cls
Expand Down
3 changes: 1 addition & 2 deletions sslyze/cli/server_string_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

@dataclass(frozen=True)
class InvalidServerStringError(Exception):
"""Exception raised when SSLyze was unable to parse a hostname:port string supplied via the command line.
"""
"""Exception raised when SSLyze was unable to parse a hostname:port string supplied via the command line."""

server_string: str
error_message: str
Expand Down
6 changes: 2 additions & 4 deletions sslyze/connection_helpers/http_response_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class NotAValidHttpResponseError(Exception):


class HttpResponseParser:
"""Utility to parse HTTP responses - http://pythonwise.blogspot.com/2010/02/parse-http-response.html.
"""
"""Utility to parse HTTP responses - http://pythonwise.blogspot.com/2010/02/parse-http-response.html."""

@classmethod
def parse_from_socket(cls, sock: socket) -> HTTPResponse:
Expand All @@ -28,8 +27,7 @@ def parse_from_ssl_connection(cls, ssl_conn: BaseSslClient) -> HTTPResponse:

@staticmethod
def _parse(read_method: Callable) -> HTTPResponse:
"""Trick to standardize the API between sockets and SSLConnection objects.
"""
"""Trick to standardize the API between sockets and SSLConnection objects."""
response = read_method(4096)
while b"HTTP/" not in response or b"\r\n\r\n" not in response:
# Parse until the end of the headers
Expand Down
18 changes: 6 additions & 12 deletions sslyze/connection_helpers/opportunistic_tls_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class ProtocolWithOpportunisticTlsEnum(str, Enum):

@classmethod
def from_default_port(cls, port: int) -> Optional["ProtocolWithOpportunisticTlsEnum"]:
"""Given a port number, return the protocol that uses this port number by default.
"""
"""Given a port number, return the protocol that uses this port number by default."""
try:
return _DEFAULT_PORTS[port]
except KeyError:
Expand Down Expand Up @@ -55,14 +54,12 @@ class OpportunisticTlsError(Exception):
class _OpportunisticTlsHelper(ABC):
@abstractmethod
def prepare_socket_for_tls_handshake(self, sock: socket.socket) -> None:
"""Send the right protocol-specific requests to prepare the server for the TLS handshake.
"""
"""Send the right protocol-specific requests to prepare the server for the TLS handshake."""
pass


class _SmtpHelper(_OpportunisticTlsHelper):
"""Perform an SMTP StartTLS negotiation.
"""
"""Perform an SMTP StartTLS negotiation."""

def prepare_socket_for_tls_handshake(self, sock: socket.socket) -> None:
# Get the SMTP banner
Expand All @@ -80,8 +77,7 @@ def prepare_socket_for_tls_handshake(self, sock: socket.socket) -> None:


class _XmppHelper(_OpportunisticTlsHelper):
"""Perform an XMPP StartTLS negotiation.
"""
"""Perform an XMPP StartTLS negotiation."""

XMPP_OPEN_STREAM = (
"<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' "
Expand Down Expand Up @@ -123,8 +119,7 @@ class _XmppServerHelper(_XmppHelper):


class _LdapHelper(_OpportunisticTlsHelper):
"""Performs an LDAP StartTLS negotiation.
"""
"""Performs an LDAP StartTLS negotiation."""

START_TLS_CMD = b"0\x1d\x02\x01\x01w\x18\x80\x161.3.6.1.4.1.1466.20037"
START_TLS_OK = b"\x30\x0c\x02\x01\x01\x78\x07\x0a\x01\x00\x04\x00\x04"
Expand All @@ -142,8 +137,7 @@ def prepare_socket_for_tls_handshake(self, sock: socket.socket) -> None:


class _RdpHelper(_OpportunisticTlsHelper):
"""Perform an RDP StartTLS negotiation.
"""
"""Perform an RDP StartTLS negotiation."""

ERR_NO_STARTTLS = "RDP AUTH TLS was rejected"

Expand Down
3 changes: 1 addition & 2 deletions sslyze/connection_helpers/tls_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ def _open_socket(server_location: ServerNetworkLocation, network_timeout: int) -


class NoCiphersAvailableBugInSSlyze(Exception):
"""Should never happen.
"""
"""Should never happen."""


class SslConnection:
Expand Down
9 changes: 3 additions & 6 deletions sslyze/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@


class InvalidServerNetworkConfigurationError(Exception):
"""Raised when trying to create a ServerNetworkConfiguration with invalid settings.
"""
"""Raised when trying to create a ServerNetworkConfiguration with invalid settings."""


class ServerHostnameCouldNotBeResolved(Exception):
"""Raised when trying to create a ServerNetworkLocationViaDirectConnection with a hostname whose DNS lookup failed.
"""
"""Raised when trying to create a ServerNetworkLocationViaDirectConnection but DNS lookup failed."""


@dataclass(frozen=True)
class ConnectionToServerFailed(Exception):
"""Parent class for all exceptions raised when a connecting to a server failed.
"""
"""Parent class for all exceptions raised when a connecting to a server failed."""

server_location: "ServerNetworkLocation"
network_configuration: "ServerNetworkConfiguration"
Expand Down
6 changes: 2 additions & 4 deletions sslyze/json/json_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ def from_orm(cls, server_scan_result: ServerScanResult) -> "ServerScanResultAsJs


class InvalidServerStringAsJson(_BaseModelWithOrmModeAndForbid):
"""A hostname:port string supplied via the command line that SSLyze was unable to parse or resolve.
"""
"""A hostname:port string supplied via the command line that SSLyze was unable to parse or resolve."""

server_string: str
error_message: str
Expand All @@ -230,8 +229,7 @@ def from_orm(cls, invalid_server_string_error: "InvalidServerStringError") -> "I


class SslyzeOutputAsJson(pydantic.BaseModel):
"""The "root" dictionary of the JSON output when using the --json command line option.
"""
"""The "root" dictionary of the JSON output when using the --json command line option."""

invalid_server_strings: List[InvalidServerStringAsJson] = [] # TODO(AD): Remove default value starting with v6.x.x
server_scan_results: List[ServerScanResultAsJson]
Expand Down
Loading

0 comments on commit d43478a

Please sign in to comment.