Skip to content

Commit 6a8265d

Browse files
committed
fix some linting things
1 parent ed54a6b commit 6a8265d

File tree

2 files changed

+51
-24
lines changed

2 files changed

+51
-24
lines changed

checks/http_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
DEFAULT_TIMEOUT = 10
2222

23+
2324
def _do_request(args, headers, kwargs, session, url):
2425
"""
2526
This small wrapper helps with handling of redirects.

checks/tasks/tls.py

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from cryptography.x509 import (
2121
NameOID,
2222
SignatureAlgorithmOID,
23-
load_pem_x509_certificate, Certificate,
23+
Certificate,
2424
)
2525
from django.conf import settings
2626
from django.db import transaction
@@ -32,10 +32,14 @@
3232
ServerScanStatusEnum,
3333
ScanCommand,
3434
TlsVersionEnum,
35-
CipherSuiteAcceptedByServer, ServerNetworkConfiguration, ProtocolWithOpportunisticTlsEnum,
35+
CipherSuiteAcceptedByServer,
36+
ServerNetworkConfiguration,
37+
ProtocolWithOpportunisticTlsEnum,
38+
)
39+
from sslyze.plugins.certificate_info._certificate_utils import (
40+
parse_subject_alternative_name_extension,
41+
get_common_names,
3642
)
37-
from sslyze.plugins.certificate_info._certificate_utils import parse_subject_alternative_name_extension, \
38-
get_common_names
3943

4044
from checks import categories, scoring
4145
from checks.http_client import http_get_ip
@@ -69,6 +73,7 @@
6973
results_per_domain,
7074
)
7175
from interface import batch, batch_shared_task, redis_id
76+
7277
# Workaround for https://github.com/eventlet/eventlet/issues/413 for eventlet
7378
# while monkey patching. That way we can still catch subprocess.TimeoutExpired
7479
# instead of just Exception which may intervene with Celery's own exceptions.
@@ -960,7 +965,17 @@ def build_summary_report(testtls, category):
960965
testtls.report = report
961966

962967

963-
def dane(url: str, port: int, chain: List[Certificate], task, dane_cb_data, score_none, score_none_bogus, score_failed, score_validated):
968+
def dane(
969+
url: str,
970+
port: int,
971+
chain: List[Certificate],
972+
task,
973+
dane_cb_data,
974+
score_none,
975+
score_none_bogus,
976+
score_failed,
977+
score_validated,
978+
):
964979
"""
965980
Check if there are TLSA records, if they are valid and if a DANE rollover
966981
scheme is currently in place.
@@ -1116,6 +1131,7 @@ def get_common_name(cert):
11161131
pass
11171132
return value
11181133

1134+
11191135
def do_web_cert(af_ip_pairs, url, task, *args, **kwargs):
11201136
"""
11211137
Check the web server's certificate.
@@ -1151,8 +1167,9 @@ def cert_checks(url, mode, task, af_ip_pair=None, dane_cb_data=None, *args, **kw
11511167
port = 25
11521168
scan = ServerScanRequest(
11531169
server_location=ServerNetworkLocation(hostname=url, port=port),
1154-
network_configuration=ServerNetworkConfiguration(tls_server_name_indication=url,
1155-
tls_opportunistic_encryption=ProtocolWithOpportunisticTlsEnum.SMTP),
1170+
network_configuration=ServerNetworkConfiguration(
1171+
tls_server_name_indication=url, tls_opportunistic_encryption=ProtocolWithOpportunisticTlsEnum.SMTP
1172+
),
11561173
scan_commands={ScanCommand.CERTIFICATE_INFO},
11571174
)
11581175
else:
@@ -1218,7 +1235,6 @@ def cert_checks(url, mode, task, af_ip_pair=None, dane_cb_data=None, *args, **kw
12181235
}
12191236
hostmatch_bad = certificate_names
12201237

1221-
12221238
pubkey_score, pubkey_bad, pubkey_phase_out = check_pubkey(cert_deployment.received_certificate_chain)
12231239

12241240
# NCSC guideline B3-2
@@ -1230,13 +1246,13 @@ def cert_checks(url, mode, task, af_ip_pair=None, dane_cb_data=None, *args, **kw
12301246
sigalg = cert.signature_algorithm_oid
12311247
# Check oids
12321248
if sigalg not in (
1233-
SignatureAlgorithmOID.RSA_WITH_SHA256,
1234-
SignatureAlgorithmOID.RSA_WITH_SHA384,
1235-
SignatureAlgorithmOID.RSA_WITH_SHA512,
1236-
SignatureAlgorithmOID.ECDSA_WITH_SHA256,
1237-
SignatureAlgorithmOID.ECDSA_WITH_SHA384,
1238-
SignatureAlgorithmOID.ECDSA_WITH_SHA512,
1239-
SignatureAlgorithmOID.DSA_WITH_SHA256,
1249+
SignatureAlgorithmOID.RSA_WITH_SHA256,
1250+
SignatureAlgorithmOID.RSA_WITH_SHA384,
1251+
SignatureAlgorithmOID.RSA_WITH_SHA512,
1252+
SignatureAlgorithmOID.ECDSA_WITH_SHA256,
1253+
SignatureAlgorithmOID.ECDSA_WITH_SHA384,
1254+
SignatureAlgorithmOID.ECDSA_WITH_SHA512,
1255+
SignatureAlgorithmOID.DSA_WITH_SHA256,
12401256
):
12411257
sigalg_bad[get_common_name(cert)] = sigalg._name
12421258
sigalg_score = scoring.WEB_TLS_SIGNATURE_BAD
@@ -1245,11 +1261,17 @@ def cert_checks(url, mode, task, af_ip_pair=None, dane_cb_data=None, *args, **kw
12451261
for cert in cert_deployment.received_certificate_chain:
12461262
chain_str.append(get_common_name(cert))
12471263

1248-
dane_results = dane(url, port, cert_deployment.received_certificate_chain, task,
1249-
dane_cb_data, scoring.WEB_TLS_DANE_NONE,
1250-
scoring.WEB_TLS_DANE_NONE_BOGUS,
1251-
scoring.WEB_TLS_DANE_FAILED,
1252-
scoring.WEB_TLS_DANE_VALIDATED)
1264+
dane_results = dane(
1265+
url,
1266+
port,
1267+
cert_deployment.received_certificate_chain,
1268+
task,
1269+
dane_cb_data,
1270+
scoring.WEB_TLS_DANE_NONE,
1271+
scoring.WEB_TLS_DANE_NONE_BOGUS,
1272+
scoring.WEB_TLS_DANE_FAILED,
1273+
scoring.WEB_TLS_DANE_VALIDATED,
1274+
)
12531275

12541276
results = dict(
12551277
tls_cert=True,
@@ -1288,11 +1310,13 @@ def check_pubkey(certificates: List[Certificate]):
12881310
elif public_key_type is dsa.DSAPublicKey and bits < 2048:
12891311
failed_key_type = public_key_type.__name__
12901312
# TODO: DH type?
1291-
#elif public_key_type is DHPublicKey and bits < 2048:
1313+
# elif public_key_type is DHPublicKey and bits < 2048:
12921314
# failed_key_type = "DHPublicKey"
12931315
elif public_key_type in [x25519.X25519PublicKey, x448.X448PublicKey] and bits < 224:
12941316
failed_key_type = public_key_type.__name__
1295-
elif public_key_type is EllipticCurvePublicKey and (bits < 224 or public_key.curve not in [ec.SECP384R1, ec.SECP256R1]):
1317+
elif public_key_type is EllipticCurvePublicKey and (
1318+
bits < 224 or public_key.curve not in [ec.SECP384R1, ec.SECP256R1]
1319+
):
12961320
failed_key_type = public_key_type.__name__
12971321
if failed_key_type:
12981322
message = f"{common_name}: {failed_key_type}-{bits} bits"
@@ -1305,6 +1329,7 @@ def check_pubkey(certificates: List[Certificate]):
13051329
pubkey_score = scoring.WEB_TLS_PUBKEY_BAD
13061330
return pubkey_score, bad_pubkey, phase_out_pubkey
13071331

1332+
13081333
def do_web_conn(af_ip_pairs, url, *args, **kwargs):
13091334
"""
13101335
Start all the TLS related checks for the web test.
@@ -1386,7 +1411,9 @@ def check_mail_tls(server, dane_cb_data, task):
13861411
scans = [
13871412
ServerScanRequest(
13881413
server_location=ServerNetworkLocation(hostname=server, port=25),
1389-
network_configuration=ServerNetworkConfiguration(tls_server_name_indication=server, tls_opportunistic_encryption=ProtocolWithOpportunisticTlsEnum.SMTP),
1414+
network_configuration=ServerNetworkConfiguration(
1415+
tls_server_name_indication=server, tls_opportunistic_encryption=ProtocolWithOpportunisticTlsEnum.SMTP
1416+
),
13901417
scan_commands={
13911418
# ScanCommand.CERTIFICATE_INFO,
13921419
ScanCommand.SSL_2_0_CIPHER_SUITES,
@@ -1500,7 +1527,6 @@ def has_daneTA(tlsa_records):
15001527
return False
15011528

15021529

1503-
15041530
def check_web_tls(url, af_ip_pair=None, *args, **kwargs):
15051531
"""
15061532
Check the webserver's TLS configuration.

0 commit comments

Comments
 (0)