Skip to content

Commit

Permalink
[#575] Ensure default scans cmds are run when none are specified
Browse files Browse the repository at this point in the history
  • Loading branch information
nabla-c0d3 committed Oct 15, 2022
1 parent 820765d commit 33a0a45
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions sslyze/cli/command_line_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ class ParsedCommandLine:
class CommandLineParser:
def __init__(self, sslyze_version: str) -> None:
"""Generate SSLyze's command line parser."""
self.aparser = ArgumentParser(prog="sslyze", description=f"SSLyze version {sslyze_version}")
self._parser = ArgumentParser(prog="sslyze", description=f"SSLyze version {sslyze_version}")

# Add generic command line options to the parser
self._add_default_options()

# Add plugin .ie scan command options to the parser
scan_commands_group = self.aparser.add_argument_group("Scan commands")
scan_commands_group = self._parser.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,
)

self.aparser.add_argument(
self._parser.add_argument(
"--mozilla_config",
action="store",
dest="mozilla_config",
Expand All @@ -109,11 +109,11 @@ def __init__(self, sslyze_version: str) -> None:
" this check.",
)

self.aparser.add_argument(dest="target", default=[], nargs="*", help="The list of servers to scan.")
self._parser.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."""
args_command_list = self.aparser.parse_args()
args_command_list = self._parser.parse_args()
args_target_list = []

if args_command_list.update_trust_stores:
Expand All @@ -140,11 +140,14 @@ def parse_command_line(self) -> ParsedCommandLine:

# Handle the case when no scan commands have been specified: run --mozilla-config=intermediate by default
if not args_command_list.mozilla_config:
did_user_enable_some_scan_commands = [
getattr(args_command_list, option.option)
for option in self._get_plugin_scan_commands()
if getattr(args_command_list, option.option)
]
did_user_enable_some_scan_commands = False
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, _ = cli_connector_cls.find_cli_options_in_command_line(args_command_list.__dict__)
if is_scan_cmd_enabled:
did_user_enable_some_scan_commands = True
break

if not did_user_enable_some_scan_commands:
setattr(args_command_list, "mozilla_config", MozillaTlsConfigurationEnum.INTERMEDIATE.value)

Expand Down Expand Up @@ -322,7 +325,7 @@ def parse_command_line(self) -> ParsedCommandLine:
def _add_default_options(self) -> None:
"""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 = self._parser.add_argument_group("Trust stores options")
trust_stores_group.add_argument(
"--update_trust_stores",
help="Update the default trust stores used by SSLyze. The latest stores will be "
Expand All @@ -334,7 +337,7 @@ def _add_default_options(self) -> None:
)

# Client certificate options
client_certificate_group = self.aparser.add_argument_group("Client certificate options")
client_certificate_group = self._parser.add_argument_group("Client certificate options")
client_certificate_group.add_argument(
"--cert",
metavar="CERTIFICATE_FILE",
Expand Down Expand Up @@ -363,7 +366,7 @@ def _add_default_options(self) -> None:
)

# Input / output
input_and_output_group = self.aparser.add_argument_group("Input and output options")
input_and_output_group = self._parser.add_argument_group("Input and output options")
# JSON output
input_and_output_group.add_argument(
"--json_out",
Expand Down Expand Up @@ -395,7 +398,7 @@ def _add_default_options(self) -> None:
)

# Connectivity option group
connectivity_group = self.aparser.add_argument_group("Contectivity options")
connectivity_group = self._parser.add_argument_group("Contectivity options")
# Connection speed
connectivity_group.add_argument(
"--slow_connection",
Expand Down

0 comments on commit 33a0a45

Please sign in to comment.