20
20
from cryptography .x509 import (
21
21
NameOID ,
22
22
SignatureAlgorithmOID ,
23
- load_pem_x509_certificate , Certificate ,
23
+ Certificate ,
24
24
)
25
25
from django .conf import settings
26
26
from django .db import transaction
32
32
ServerScanStatusEnum ,
33
33
ScanCommand ,
34
34
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 ,
36
42
)
37
- from sslyze .plugins .certificate_info ._certificate_utils import parse_subject_alternative_name_extension , \
38
- get_common_names
39
43
40
44
from checks import categories , scoring
41
45
from checks .http_client import http_get_ip
69
73
results_per_domain ,
70
74
)
71
75
from interface import batch , batch_shared_task , redis_id
76
+
72
77
# Workaround for https://github.com/eventlet/eventlet/issues/413 for eventlet
73
78
# while monkey patching. That way we can still catch subprocess.TimeoutExpired
74
79
# instead of just Exception which may intervene with Celery's own exceptions.
@@ -960,7 +965,17 @@ def build_summary_report(testtls, category):
960
965
testtls .report = report
961
966
962
967
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
+ ):
964
979
"""
965
980
Check if there are TLSA records, if they are valid and if a DANE rollover
966
981
scheme is currently in place.
@@ -1116,6 +1131,7 @@ def get_common_name(cert):
1116
1131
pass
1117
1132
return value
1118
1133
1134
+
1119
1135
def do_web_cert (af_ip_pairs , url , task , * args , ** kwargs ):
1120
1136
"""
1121
1137
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
1151
1167
port = 25
1152
1168
scan = ServerScanRequest (
1153
1169
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
+ ),
1156
1173
scan_commands = {ScanCommand .CERTIFICATE_INFO },
1157
1174
)
1158
1175
else :
@@ -1218,7 +1235,6 @@ def cert_checks(url, mode, task, af_ip_pair=None, dane_cb_data=None, *args, **kw
1218
1235
}
1219
1236
hostmatch_bad = certificate_names
1220
1237
1221
-
1222
1238
pubkey_score , pubkey_bad , pubkey_phase_out = check_pubkey (cert_deployment .received_certificate_chain )
1223
1239
1224
1240
# NCSC guideline B3-2
@@ -1230,13 +1246,13 @@ def cert_checks(url, mode, task, af_ip_pair=None, dane_cb_data=None, *args, **kw
1230
1246
sigalg = cert .signature_algorithm_oid
1231
1247
# Check oids
1232
1248
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 ,
1240
1256
):
1241
1257
sigalg_bad [get_common_name (cert )] = sigalg ._name
1242
1258
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
1245
1261
for cert in cert_deployment .received_certificate_chain :
1246
1262
chain_str .append (get_common_name (cert ))
1247
1263
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
+ )
1253
1275
1254
1276
results = dict (
1255
1277
tls_cert = True ,
@@ -1288,11 +1310,13 @@ def check_pubkey(certificates: List[Certificate]):
1288
1310
elif public_key_type is dsa .DSAPublicKey and bits < 2048 :
1289
1311
failed_key_type = public_key_type .__name__
1290
1312
# TODO: DH type?
1291
- #elif public_key_type is DHPublicKey and bits < 2048:
1313
+ # elif public_key_type is DHPublicKey and bits < 2048:
1292
1314
# failed_key_type = "DHPublicKey"
1293
1315
elif public_key_type in [x25519 .X25519PublicKey , x448 .X448PublicKey ] and bits < 224 :
1294
1316
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
+ ):
1296
1320
failed_key_type = public_key_type .__name__
1297
1321
if failed_key_type :
1298
1322
message = f"{ common_name } : { failed_key_type } -{ bits } bits"
@@ -1305,6 +1329,7 @@ def check_pubkey(certificates: List[Certificate]):
1305
1329
pubkey_score = scoring .WEB_TLS_PUBKEY_BAD
1306
1330
return pubkey_score , bad_pubkey , phase_out_pubkey
1307
1331
1332
+
1308
1333
def do_web_conn (af_ip_pairs , url , * args , ** kwargs ):
1309
1334
"""
1310
1335
Start all the TLS related checks for the web test.
@@ -1386,7 +1411,9 @@ def check_mail_tls(server, dane_cb_data, task):
1386
1411
scans = [
1387
1412
ServerScanRequest (
1388
1413
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
+ ),
1390
1417
scan_commands = {
1391
1418
# ScanCommand.CERTIFICATE_INFO,
1392
1419
ScanCommand .SSL_2_0_CIPHER_SUITES ,
@@ -1500,7 +1527,6 @@ def has_daneTA(tlsa_records):
1500
1527
return False
1501
1528
1502
1529
1503
-
1504
1530
def check_web_tls (url , af_ip_pair = None , * args , ** kwargs ):
1505
1531
"""
1506
1532
Check the webserver's TLS configuration.
0 commit comments