Skip to content

Commit

Permalink
Replace flake8 and black with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
nabla-c0d3 committed Feb 26, 2024
1 parent 38f4464 commit b947aab
Show file tree
Hide file tree
Showing 31 changed files with 34 additions and 84 deletions.
3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[tool.ruff]
line-length = 120

[tool.mypy]
python_version = "3.8"
ignore_missing_imports = true
strict_optional = true
disallow_untyped_defs = true

[[tool.mypy.overrides]]
module = "tests.*"
disallow_untyped_defs = false
12 changes: 4 additions & 8 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
mypy==1.4.1
flake8>=5,<7
mypy==1.8
ruff==0.2.2
invoke>=2,<3
pytest>=7.4,<8
sphinx
sphinx-rtd-theme
twine>=4,<5
sphinx-autodoc-typehints
black==22.10.0
pytest-cov
faker

# For mypy
types-pyOpenSSL

# For building the Windows executable
cx-freeze==6.15.8; sys.platform == 'win32'
# For building the Windows executable; cx-freeze is not compatible with Python 3.12 yet
cx-freeze==6.15.15; sys.platform == 'win32' and python_version < '3.12'
16 changes: 0 additions & 16 deletions setup.cfg

This file was deleted.

1 change: 0 additions & 1 deletion sslyze/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def main() -> None:
if not parsed_command_line.check_against_mozilla_config:
print(" Disabled; use --mozilla_config={old, intermediate, modern}.\n")
else:

print(
f' Checking results against Mozilla\'s "{parsed_command_line.check_against_mozilla_config}"'
f" configuration. See https://ssl-config.mozilla.org/ for more details.\n"
Expand Down
1 change: 0 additions & 1 deletion sslyze/cli/command_line_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@


class CommandLineParsingError(Exception):

PARSING_ERROR_FORMAT = " Command line error: {0}\n Use -h for help."

def get_error_msg(self) -> str:
Expand Down
1 change: 0 additions & 1 deletion sslyze/connection_helpers/http_request_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class HttpRequestGenerator:

HTTP_GET_FORMAT = (
"GET {path} HTTP/1.1\r\n"
"Host: {host}\r\n"
Expand Down
4 changes: 0 additions & 4 deletions sslyze/connection_helpers/opportunistic_tls_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,31 +177,27 @@ def prepare_socket_for_tls_handshake(self, sock: socket.socket) -> None:


class _ImapHelper(_GenericOpportunisticTlsHelper):

ERR_NO_STARTTLS = "IMAP START TLS was rejected"

START_TLS_CMD = b". STARTTLS\r\n"
START_TLS_OK = b". OK"


class _Pop3Helper(_GenericOpportunisticTlsHelper):

ERR_NO_STARTTLS = "POP START TLS was rejected"

START_TLS_CMD = b"STLS\r\n"
START_TLS_OK = b"+OK"


class _FtpHelper(_GenericOpportunisticTlsHelper):

ERR_NO_STARTTLS = "FTP AUTH TLS was rejected"

START_TLS_CMD = b"AUTH TLS\r\n"
START_TLS_OK = b"234"


class _PostgresHelper(_GenericOpportunisticTlsHelper):

ERR_NO_STARTTLS = "Postgres AUTH TLS was rejected"

START_TLS_CMD = b"\x00\x00\x00\x08\x04\xD2\x16\x2F"
Expand Down
2 changes: 1 addition & 1 deletion sslyze/json/pydantic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BaseModelWithOrmModeAndForbid(BaseModel):


def _handle_enum_name(enum_value: Any) -> str:
if type(enum_value) is str:
if isinstance(enum_value, str):
return enum_value
else:
return enum_value.name
Expand Down
3 changes: 2 additions & 1 deletion sslyze/json/scan_attempt_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
# Must be subclassed in order to add the result field
class ScanCommandAttemptAsJson(BaseModel, ABC):
model_config = ConfigDict(
extra="forbid", from_attributes=True # Fields must match between the JSON representation and the actual objects
extra="forbid",
from_attributes=True, # Fields must match between the JSON representation and the actual objects
)

status: ScanCommandAttemptStatusEnum
Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/certificate_info/_cli_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
class _CertificateInfoCliConnector(
ScanCommandCliConnector["CertificateInfoScanResult", "CertificateInfoExtraArgument"]
):

_cli_option = "certinfo"
_cli_description = "Retrieve and analyze a server's certificate(s) to verify its validity."

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/certificate_info/json_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def _handle_object(cls, data: Any) -> Any:


class _SubjAltNameAsJson(BaseModel):

dns_names: List[str]
ip_addresses: List[str] = []

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/compression_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class CompressionScanAttemptAsJson(ScanCommandAttemptAsJson):


class _CompressionCliConnector(ScanCommandCliConnector[CompressionScanResult, None]):

_cli_option = "compression"
_cli_description = "Test a server for TLS compression support, which can be leveraged to perform a CRIME attack."

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/early_data_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class EarlyDataScanAttemptAsJson(ScanCommandAttemptAsJson):


class _EarlyDataCliConnector(ScanCommandCliConnector[EarlyDataScanResult, None]):

_cli_option = "early_data"
_cli_description = "Test a server for TLS 1.3 early data support."

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/elliptic_curves_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class SupportedEllipticCurvesScanAttemptAsJson(ScanCommandAttemptAsJson):


class _SupportedEllipticCurvesCliConnector(ScanCommandCliConnector[SupportedEllipticCurvesScanResult, None]):

_cli_option = "elliptic_curves"
_cli_description = "Test a server for supported elliptic curves."

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/fallback_scsv_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class FallbackScsvScanAttemptAsJson(ScanCommandAttemptAsJson):


class _FallbackScsvCliConnector(ScanCommandCliConnector[FallbackScsvScanResult, None]):

_cli_option = "fallback"
_cli_description = "Test a server for the TLS_FALLBACK_SCSV mechanism to prevent downgrade attacks."

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/heartbleed_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class HeartbleedScanAttemptAsJson(ScanCommandAttemptAsJson):


class _HeartbleedCliConnector(ScanCommandCliConnector[HeartbleedScanResult, None]):

_cli_option = "heartbleed"
_cli_description = "Test a server for the OpenSSL Heartbleed vulnerability."

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/http_headers_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class HttpHeadersScanAttemptAsJson(ScanCommandAttemptAsJson):


class _HttpHeadersCliConnector(ScanCommandCliConnector[HttpHeadersScanResult, None]):

_cli_option = "http_headers"
_cli_description = "Test a server for the presence of security-related HTTP headers."

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/openssl_ccs_injection_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class OpenSslCcsInjectionScanAttemptAsJson(ScanCommandAttemptAsJson):


class _OpenSslCcsInjectionCliConnector(ScanCommandCliConnector[OpenSslCcsInjectionScanResult, None]):

_cli_option = "openssl_ccs"
_cli_description = "Test a server for the OpenSSL CCS Injection vulnerability (CVE-2014-0224)."

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/openssl_cipher_suites/_cli_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class _CipherSuitesCliConnector(ScanCommandCliConnector["CipherSuitesScanResult", None]):

_title_in_output: ClassVar[str]

@classmethod
Expand Down
7 changes: 0 additions & 7 deletions sslyze/plugins/openssl_cipher_suites/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,42 @@ def is_tls_version_supported(self) -> bool:


class _Sslv20CliConnector(_CipherSuitesCliConnector):

_cli_option = "sslv2"
_cli_description = "Test a server for SSL 2.0 support."
_title_in_output = "SSL 2.0 Cipher Suites"


class _Sslv30CliConnector(_CipherSuitesCliConnector):

_cli_option = "sslv3"
_cli_description = "Test a server for SSL 3.0 support."
_title_in_output = "SSL 3.0 Cipher Suites"


class _Tlsv10CliConnector(_CipherSuitesCliConnector):

_cli_option = "tlsv1"
_cli_description = "Test a server for TLS 1.0 support."
_title_in_output = "TLS 1.0 Cipher Suites"


class _Tlsv11CliConnector(_CipherSuitesCliConnector):

_cli_option = "tlsv1_1"
_cli_description = "Test a server for TLS 1.1 support."
_title_in_output = "TLS 1.1 Cipher Suites"


class _Tlsv12CliConnector(_CipherSuitesCliConnector):

_cli_option = "tlsv1_2"
_cli_description = "Test a server for TLS 1.2 support."
_title_in_output = "TLS 1.2 Cipher Suites"


class _Tlsv13CliConnector(_CipherSuitesCliConnector):

_cli_option = "tlsv1_3"
_cli_description = "Test a server for TLS 1.3 support."
_title_in_output = "TLS 1.3 Cipher Suites"


class _CipherSuitesScanImplementation(ScanCommandImplementation[CipherSuitesScanResult, None]):

# The SSL version corresponding to the scan command
_tls_version: ClassVar[TlsVersionEnum]

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/robot/_robot_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class RobotPmsPaddingPayloadEnum(Enum):


class _RobotTlsRecordPayloads:

# From https://github.com/robotattackorg/robot-detect and testssl.sh
# The high level idea of an oracle attack is to send several payloads that are slightly wrong, in different ways,
# hoping that the server is going to give a different response (a TLS alert, a connection reset, no data, etc.) for
Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/robot/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class RobotScanAttemptAsJson(ScanCommandAttemptAsJson):


class _RobotCliConnector(ScanCommandCliConnector[RobotScanResult, None]):

_cli_option = "robot"
_cli_description = "Test a server for the ROBOT vulnerability."

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/session_renegotiation_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class _ScanJobResultEnum(Enum):


class _SessionRenegotiationCliConnector(ScanCommandCliConnector[SessionRenegotiationScanResult, None]):

_cli_option = "reneg"
_cli_description = "Test a server for for insecure TLS renegotiation and client-initiated renegotiation."

Expand Down
1 change: 0 additions & 1 deletion sslyze/plugins/session_resumption/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def _resumption_result_to_console_output(
class _SessionResumptionSupportCliConnector(
ScanCommandCliConnector[SessionResumptionSupportScanResult, SessionResumptionSupportExtraArgument]
):

_cli_option = "resum"
_cli_description = "Test a server for TLS 1.2 session resumption support using session IDs and TLS tickets."

Expand Down
1 change: 0 additions & 1 deletion sslyze/server_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ def _detect_support_for_tls_1_2_or_below(
network_config: ServerNetworkConfiguration,
tls_version: TlsVersionEnum,
) -> _TlsVersionDetectionResult:

if tls_version == TlsVersionEnum.SSL_2_0:
# DEFAULT excludes SSLv2 ciphers in OpenSSL 1.0.2
default_cipher_list = "SSLv2"
Expand Down
10 changes: 8 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ def test(ctx: Context) -> None:

@task
def lint(ctx: Context) -> None:
ctx.run("flake8 .")
ctx.run("ruff format . --check")
ctx.run("ruff check .")
ctx.run("mypy .")
ctx.run("black -l 120 sslyze tests api_sample.py tasks.py --check")


@task
def autoformat(ctx: Context) -> None:
ctx.run("ruff format .")
ctx.run("ruff check . --fix")


@task
Expand Down
28 changes: 7 additions & 21 deletions tests/plugins_tests/certificate_info/test_symantec.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def test_good(self):
R7vu2UObYzI35CU=
-----END CERTIFICATE-----
""".encode(
encoding="ascii"
),
""".encode(encoding="ascii"),
default_backend(),
),
# Google Internet Authority G3
Expand Down Expand Up @@ -67,9 +65,7 @@ def test_good(self):
7a8IVk6wuy6pm+T7HT4LY8ibS5FEZlfAFLSW8NwsVz9SBK2Vqn1N0PIMn5xA6NZV
c7o835DLAFshEWfC7TIe3g==
-----END CERTIFICATE-----
""".encode(
encoding="ascii"
),
""".encode(encoding="ascii"),
default_backend(),
),
# GlobalSign Root CA
Expand All @@ -96,9 +92,7 @@ def test_good(self):
AfvDbbnvRG15RjF+Cv6pgsH/76tuIMRQyV+dTZsXjAzlAcmgQWpzU/qlULRuJQ/7
TBj0/VLZjmmx6BEP3ojY+x1J96relc8geMJgEtslQIxq/H5COEBkEveegeGTLg==
-----END CERTIFICATE-----
""".encode(
encoding="ascii"
),
""".encode(encoding="ascii"),
default_backend(),
),
]
Expand Down Expand Up @@ -167,9 +161,7 @@ def test_march_2018(self):
QzQuVEXo8FVfMP9wqDEQe1IeOePcYMFEBt4/evEneUvEX2MNLc+wMt8qf44pxryp
8NIYplnoidK7+W1YRQcFUhx/3xbyoBB2fEHCsvyYGw==
-----END CERTIFICATE-----
""".encode(
encoding="ascii"
),
""".encode(encoding="ascii"),
default_backend(),
),
# GeoTrust DV SSL
Expand Down Expand Up @@ -199,9 +191,7 @@ def test_march_2018(self):
SGGFixD0wYi/f1+KwtfNK5RcHzRKCK/rromoSHVVlR27wJoBufQDIj7U5lIwDWe5
wJH9LUwwjr2MpQSRu6Srfw/Yb/BmAMmjXPWwj4PmnFrmtrnFvL7kAg==
-----END CERTIFICATE-----
""".encode(
encoding="ascii"
),
""".encode(encoding="ascii"),
default_backend(),
),
# GeoTrust Global CA
Expand Down Expand Up @@ -246,9 +236,7 @@ def test_september_2018(self):
Aw5rmaztWlYO64YS7z4am5d9h2rrF1rfgv9Mc3caxAUO3sJZDRyhYaj+7BUgv8HR
otJHkjr2ASPp31Yf
-----END CERTIFICATE-----
""".encode(
encoding="ascii"
),
""".encode(encoding="ascii"),
default_backend(),
),
# RapidSSL SHA 256
Expand Down Expand Up @@ -279,9 +267,7 @@ def test_september_2018(self):
Px8G8k/Ll6BKWcZ40egDuYVtLLrhX7atKz4lecWLVtXjCYDqwSfC2Q7sRwrp0Mr8
2A==
-----END CERTIFICATE-----
""".encode(
encoding="ascii"
),
""".encode(encoding="ascii"),
default_backend(),
),
# GeoTrust Global CA
Expand Down
Loading

0 comments on commit b947aab

Please sign in to comment.