Skip to content

Commit 68f3f8b

Browse files
committed
Update for new resolver
1 parent 8360941 commit 68f3f8b

File tree

12 files changed

+35078
-3408
lines changed

12 files changed

+35078
-3408
lines changed

checks/http_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
from forcediphttpsadapter.adapters import ForcedIPHTTPSAdapter
1111

1212
from checks.resolver import dns_resolve_aaaa, dns_resolve_a
13-
from checks.tasks.tls_connection import DEFAULT_TIMEOUT
14-
from checks.tasks.tls_connection_exceptions import NoIpError
1513
from django.conf import settings
1614
from internetnl import log
1715

checks/tasks/tls.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,6 @@ def save_results(model, results, addr, domain, category):
656656
model.cert_hostmatch_score = result.get("hostmatch_score")
657657
model.cert_hostmatch_bad = result.get("hostmatch_bad")
658658
model.caa_enabled = result.get("caa_result").caa_found
659-
model.caa_records = result.get("caa_result").caa_records_str
660659
model.caa_error = [ttti.to_dict() for ttti in result.get("caa_result").errors]
661660
model.caa_recommendations = [ttti.to_dict() for ttti in result.get("caa_result").recommendations]
662661
model.caa_score = result.get("caa_result").score
@@ -730,7 +729,6 @@ def save_results(model, results, addr, domain, category):
730729
model.cert_hostmatch_score = result.get("hostmatch_score")
731730
model.cert_hostmatch_bad = result.get("hostmatch_bad")
732731
model.caa_enabled = result.get("caa_result").caa_found
733-
model.caa_records = result.get("caa_result").caa_records_str
734732
model.caa_error = [ttti.to_dict() for ttti in result.get("caa_result").errors]
735733
model.caa_recommendations = [ttti.to_dict() for ttti in result.get("caa_result").recommendations]
736734
model.caa_score = result.get("caa_result").score
@@ -903,15 +901,10 @@ def annotate_and_combine_all(good_items, sufficient_items, bad_items, phaseout_i
903901
caa_tech_table = caa_host_message + dttls.caa_errors + dttls.caa_recommendations
904902
for record in dttls.caa_records:
905903
caa_tech_table.append(
906-
TranslatableTechTableItem(msgid="caa-record", context={"record": record}).to_dict()
904+
TranslatableTechTableItem(msgid="caa_record", context={"record": record}).to_dict()
907905
)
908906
if not dttls.caa_enabled:
909907
category.subtests["web_caa"].result_bad(caa_tech_table)
910-
elif dttls.caa_errors:
911-
if all([ttti.msgid != CAA_MSGID_INSUFFICIENT_POLICY for ttti in dttls.caa_errors]):
912-
category.subtests["web_caa"].result_syntax_error(caa_tech_table)
913-
else:
914-
category.subtests["web_caa"].result_insufficient(caa_tech_table)
915908
elif dttls.caa_recommendations:
916909
category.subtests["web_caa"].result_recommendations(caa_tech_table)
917910
else:
@@ -1082,15 +1075,10 @@ def annotate_and_combine_all(good_items, sufficient_items, bad_items, phaseout_i
10821075
caa_tech_table = caa_host_message + dttls.caa_errors + dttls.caa_recommendations
10831076
for record in dttls.caa_records:
10841077
caa_tech_table.append(
1085-
TranslatableTechTableItem(msgid="caa-record", context={"record": record}).to_dict()
1078+
TranslatableTechTableItem(msgid="caa_record", context={"record": record}).to_dict()
10861079
)
10871080
if not dttls.caa_enabled:
10881081
category.subtests["mail_caa"].result_bad(caa_tech_table)
1089-
elif dttls.caa_errors:
1090-
if all([error["msgid"] != CAA_MSGID_INSUFFICIENT_POLICY for error in dttls.caa_errors]):
1091-
category.subtests["mail_caa"].result_syntax_error(caa_tech_table)
1092-
else:
1093-
category.subtests["mail_caa"].result_insufficient(caa_tech_table)
10941082
elif dttls.caa_recommendations:
10951083
category.subtests["mail_caa"].result_recommendations(caa_tech_table)
10961084
else:

checks/tasks/tls/http.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
)
1313

1414

15-
def http_checks(af_ip_pair, url, task):
15+
def http_checks(af_ip_pair, url):
1616
"""
1717
Perform the HTTP header and HTTPS redirection checks for this webserver.
1818
"""
19-
forced_https_score, forced_https = forced_http_check(af_ip_pair, url, task)
19+
forced_https_score, forced_https = forced_http_check(af_ip_pair, url)
2020
header_checkers = [
2121
HeaderCheckerContentEncoding(),
2222
HeaderCheckerStrictTransportSecurity(),
2323
]
24-
header_results = http_headers_check(af_ip_pair, url, header_checkers, task)
24+
header_results = http_headers_check(af_ip_pair, url, header_checkers)
2525
results = {
2626
"forced_https": forced_https,
2727
"forced_https_score": forced_https_score,
@@ -30,7 +30,7 @@ def http_checks(af_ip_pair, url, task):
3030
return results
3131

3232

33-
def forced_http_check(af_ip_pair, url, task):
33+
def forced_http_check(af_ip_pair, url):
3434
"""
3535
Check if the webserver is properly configured with HTTPS redirection.
3636
"""

checks/tasks/tls/scans.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from sslyze.server_connectivity import ServerConnectivityInfo
5050

5151
from checks import scoring
52+
from checks.caa.retrieval import retrieve_parse_caa
5253
from checks.models import (
5354
DaneStatus,
5455
ZeroRttStatus,
@@ -119,8 +120,6 @@ def dane(
119120
url: str,
120121
port: int,
121122
chain: List[Certificate],
122-
task,
123-
dane_cb_data,
124123
score_none: scoring.Score,
125124
score_none_bogus: scoring.Score,
126125
score_failed: scoring.Score,
@@ -139,7 +138,7 @@ def dane(
139138

140139
continue_testing = False
141140

142-
cb_data = dane_cb_data or resolve_dane(task, port, url)
141+
cb_data = resolve_dane(port, url)
143142

144143
# Check if there is a TLSA record, if TLSA records are bogus or NXDOMAIN is
145144
# returned for the TLSA domain (faulty signer).
@@ -149,7 +148,7 @@ def dane(
149148
elif cb_data.get("data") and cb_data.get("secure"):
150149
# If there is a secure TLSA record check for the existence of
151150
# possible bogus (unsigned) NXDOMAIN in A.
152-
tmp_data = resolve_dane(task, port, url, check_nxdomain=True)
151+
tmp_data = resolve_dane(port, url, check_nxdomain=True)
153152
if tmp_data.get("nxdomain") and tmp_data.get("bogus"):
154153
status = DaneStatus.none_bogus
155154
score = score_none_bogus
@@ -280,7 +279,7 @@ def get_common_name(cert: Certificate) -> str:
280279
return value
281280

282281

283-
def cert_checks(hostname: str, mode: ChecksMode, task, af_ip_pair=None, dane_cb_data=None, *args, **kwargs):
282+
def cert_checks(hostname: str, mode: ChecksMode, af_ip_pair=None, *args, **kwargs):
284283
"""
285284
Perform certificate checks, such as trust, name match. Also scans the server.
286285
"""
@@ -384,14 +383,14 @@ def cert_checks(hostname: str, mode: ChecksMode, task, af_ip_pair=None, dane_cb_
384383
hostname,
385384
port,
386385
cert_deployment.received_certificate_chain,
387-
task,
388-
dane_cb_data,
389386
scoring.WEB_TLS_DANE_NONE,
390387
scoring.WEB_TLS_DANE_NONE_BOGUS,
391388
scoring.WEB_TLS_DANE_FAILED,
392389
scoring.WEB_TLS_DANE_VALIDATED,
393390
)
394391

392+
caa_result = retrieve_parse_caa(hostname)
393+
395394
results = dict(
396395
tls_cert=True,
397396
chain=chain_str,
@@ -407,6 +406,7 @@ def cert_checks(hostname: str, mode: ChecksMode, task, af_ip_pair=None, dane_cb_
407406
sigalg_score=sigalg_score,
408407
hostmatch_bad=hostmatch_bad,
409408
hostmatch_score=hostmatch_score,
409+
caa_result=caa_result,
410410
)
411411
results.update(dane_results)
412412

@@ -484,7 +484,7 @@ def check_pubkey(certificates: List[Certificate], mode: ChecksMode):
484484
return pubkey_score, bad_pubkey, phase_out_pubkey
485485

486486

487-
def check_mail_tls_multiple(server_tuples, task) -> Dict[str, Dict[str, Any]]:
487+
def check_mail_tls_multiple(server_tuples) -> Dict[str, Dict[str, Any]]:
488488
"""
489489
Perform sslyze probing on all mail servers, in parallel.
490490
"""
@@ -518,7 +518,7 @@ def check_mail_tls_multiple(server_tuples, task) -> Dict[str, Dict[str, Any]]:
518518
continue
519519
log.debug(f"sslyze mail scan complete for {result.server_location.hostname}, other scans may be pending")
520520
dane_cb_data = dane_cb_per_server[result.server_location.hostname]
521-
results[result.server_location.hostname] = check_mail_tls(result, all_suites, dane_cb_data, task)
521+
results[result.server_location.hostname] = check_mail_tls(result, all_suites, dane_cb_data)
522522
log.debug(f"check_mail_tls complete for {result.server_location.hostname}")
523523
return results
524524

@@ -576,7 +576,7 @@ def _generate_mail_server_scan_request(mx_hostname: str) -> Optional[ServerScanR
576576
)
577577

578578

579-
def check_mail_tls(result: ServerScanResult, all_suites: List[CipherSuitesScanAttempt], dane_cb_data, task):
579+
def check_mail_tls(result: ServerScanResult, all_suites: List[CipherSuitesScanAttempt], dane_cb_data):
580580
"""
581581
Perform evaluation and additional probes for a single mail server.
582582
This happens after sslyze has already been run on it.
@@ -597,7 +597,7 @@ def check_mail_tls(result: ServerScanResult, all_suites: List[CipherSuitesScanAt
597597
prots_accepted,
598598
cipher_evaluation,
599599
)
600-
cert_results = cert_checks(result.server_location.hostname, ChecksMode.MAIL, task, dane_cb_data)
600+
cert_results = cert_checks(result.server_location.hostname, ChecksMode.MAIL, dane_cb_data)
601601

602602
# HACK for DANE-TA(2) and hostname mismatch!
603603
# Give a good hosmatch score if DANE-TA *is not* present.

checks/tasks/tls/tasks_reports.py

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
ZeroRttStatus,
2323
WebTestTls,
2424
)
25-
from checks.tasks import SetupUnboundContext
2625
from checks.tasks.dispatcher import check_registry, post_callback_hook
2726
from checks.tasks.shared import (
2827
aggregate_subreports,
@@ -32,6 +31,7 @@
3231
mail_get_servers,
3332
resolve_a_aaaa,
3433
results_per_domain,
34+
TranslatableTechTableItem,
3535
)
3636
from checks.tasks.tls.http import http_checks
3737
from interface import batch, batch_shared_task, redis_id
@@ -158,7 +158,6 @@ def callback_null_mx(results, domain, test_type):
158158
bind=True,
159159
soft_time_limit=settings.SHARED_TASK_SOFT_TIME_LIMIT_HIGH,
160160
time_limit=settings.SHARED_TASK_TIME_LIMIT_HIGH,
161-
base=SetupUnboundContext,
162161
)
163162
def web_cert(self, af_ip_pairs, url, *args, **kwargs):
164163
return do_web_cert(af_ip_pairs, url, self, *args, **kwargs)
@@ -169,7 +168,6 @@ def web_cert(self, af_ip_pairs, url, *args, **kwargs):
169168
bind=True,
170169
soft_time_limit=settings.BATCH_SHARED_TASK_SOFT_TIME_LIMIT_HIGH,
171170
time_limit=settings.BATCH_SHARED_TASK_TIME_LIMIT_HIGH,
172-
base=SetupUnboundContext,
173171
)
174172
def batch_web_cert(self, af_ip_pairs, url, *args, **kwargs):
175173
return do_web_cert(af_ip_pairs, url, self, *args, **kwargs)
@@ -180,7 +178,6 @@ def batch_web_cert(self, af_ip_pairs, url, *args, **kwargs):
180178
bind=True,
181179
soft_time_limit=settings.SHARED_TASK_SOFT_TIME_LIMIT_HIGH,
182180
time_limit=settings.SHARED_TASK_TIME_LIMIT_HIGH,
183-
base=SetupUnboundContext,
184181
)
185182
def web_conn(self, af_ip_pairs, url, *args, **kwargs):
186183
return do_web_conn(af_ip_pairs, url, *args, **kwargs)
@@ -191,7 +188,6 @@ def web_conn(self, af_ip_pairs, url, *args, **kwargs):
191188
bind=True,
192189
soft_time_limit=settings.BATCH_SHARED_TASK_SOFT_TIME_LIMIT_HIGH,
193190
time_limit=settings.BATCH_SHARED_TASK_TIME_LIMIT_HIGH,
194-
base=SetupUnboundContext,
195191
)
196192
def batch_web_conn(self, af_ip_pairs, url, *args, **kwargs):
197193
return do_web_conn(af_ip_pairs, url, *args, **kwargs)
@@ -202,7 +198,6 @@ def batch_web_conn(self, af_ip_pairs, url, *args, **kwargs):
202198
bind=True,
203199
soft_time_limit=settings.SHARED_TASK_SOFT_TIME_LIMIT_HIGH,
204200
time_limit=settings.SHARED_TASK_TIME_LIMIT_HIGH,
205-
base=SetupUnboundContext,
206201
)
207202
def mail_smtp_starttls(self, mailservers, url, *args, **kwargs):
208203
return do_mail_smtp_starttls(mailservers, url, self, *args, **kwargs)
@@ -213,7 +208,6 @@ def mail_smtp_starttls(self, mailservers, url, *args, **kwargs):
213208
bind=True,
214209
soft_time_limit=settings.BATCH_SHARED_TASK_SOFT_TIME_LIMIT_HIGH,
215210
time_limit=settings.BATCH_SHARED_TASK_TIME_LIMIT_HIGH,
216-
base=SetupUnboundContext,
217211
)
218212
def batch_mail_smtp_starttls(self, mailservers, url, *args, **kwargs):
219213
return do_mail_smtp_starttls(mailservers, url, self, *args, **kwargs)
@@ -224,7 +218,6 @@ def batch_mail_smtp_starttls(self, mailservers, url, *args, **kwargs):
224218
bind=True,
225219
soft_time_limit=settings.SHARED_TASK_SOFT_TIME_LIMIT_HIGH,
226220
time_limit=settings.SHARED_TASK_TIME_LIMIT_HIGH,
227-
base=SetupUnboundContext,
228221
)
229222
def web_http(self, af_ip_pairs, url, *args, **kwargs):
230223
return do_web_http(af_ip_pairs, url, self, *args, **kwargs)
@@ -235,7 +228,6 @@ def web_http(self, af_ip_pairs, url, *args, **kwargs):
235228
bind=True,
236229
soft_time_limit=settings.BATCH_SHARED_TASK_SOFT_TIME_LIMIT_HIGH,
237230
time_limit=settings.BATCH_SHARED_TASK_TIME_LIMIT_HIGH,
238-
base=SetupUnboundContext,
239231
)
240232
def batch_web_http(self, af_ip_pairs, url, *args, **kwargs):
241233
return do_web_http(af_ip_pairs, url, self, args, **kwargs)
@@ -293,6 +285,11 @@ def save_results(model, results, addr, domain, category):
293285
model.cert_signature_score = result.get("sigalg_score")
294286
model.cert_hostmatch_score = result.get("hostmatch_score")
295287
model.cert_hostmatch_bad = result.get("hostmatch_bad")
288+
model.caa_enabled = result.get("caa_result").caa_found
289+
model.caa_error = [ttti.to_dict() for ttti in result.get("caa_result").errors]
290+
model.caa_recommendations = [ttti.to_dict() for ttti in result.get("caa_result").recommendations]
291+
model.caa_score = result.get("caa_result").score
292+
model.caa_found_on_domain = result.get("caa_result").canonical_name
296293
model.dane_log = result.get("dane_log")
297294
model.dane_score = result.get("dane_score")
298295
model.dane_status = result.get("dane_status")
@@ -361,6 +358,11 @@ def save_results(model, results, addr, domain, category):
361358
model.cert_signature_score = result.get("sigalg_score")
362359
model.cert_hostmatch_score = result.get("hostmatch_score")
363360
model.cert_hostmatch_bad = result.get("hostmatch_bad")
361+
model.caa_enabled = result.get("caa_result").caa_found
362+
model.caa_error = [ttti.to_dict() for ttti in result.get("caa_result").errors]
363+
model.caa_recommendations = [ttti.to_dict() for ttti in result.get("caa_result").recommendations]
364+
model.caa_score = result.get("caa_result").score
365+
model.caa_found_on_domain = result.get("caa_result").canonical_name
364366
model.dane_log = result.get("dane_log")
365367
model.dane_score = result.get("dane_score")
366368
model.dane_status = result.get("dane_status")
@@ -500,6 +502,22 @@ def annotate_and_combine_all(good_items, sufficient_items, bad_items, phaseout_i
500502
else:
501503
category.subtests["cert_hostmatch"].result_good()
502504

505+
if dttls.caa_enabled:
506+
caa_host_message = [
507+
TranslatableTechTableItem(
508+
msgid="found_host", context={"host": dttls.caa_found_on_domain}
509+
).to_dict()
510+
]
511+
else:
512+
caa_host_message = [TranslatableTechTableItem(msgid="not_found").to_dict()]
513+
caa_tech_table = caa_host_message + dttls.caa_errors + dttls.caa_recommendations
514+
if not dttls.caa_enabled or dttls.caa_errors:
515+
category.subtests["web_caa"].result_bad(caa_tech_table)
516+
elif dttls.caa_recommendations:
517+
category.subtests["web_caa"].result_recommendations(caa_tech_table)
518+
else:
519+
category.subtests["web_caa"].result_good(caa_tech_table)
520+
503521
if dttls.dane_status == DaneStatus.none:
504522
category.subtests["dane_exists"].result_bad()
505523
elif dttls.dane_status == DaneStatus.none_bogus:
@@ -637,6 +655,20 @@ def annotate_and_combine_all(good_items, sufficient_items, bad_items, phaseout_i
637655
else:
638656
category.subtests["cert_hostmatch"].result_good()
639657

658+
if dttls.caa_enabled:
659+
caa_host_message = [
660+
TranslatableTechTableItem(msgid="found_host", context={"host": dttls.caa_found_on_domain}).to_dict()
661+
]
662+
else:
663+
caa_host_message = [TranslatableTechTableItem(msgid="not_found").to_dict()]
664+
caa_tech_table = caa_host_message + dttls.caa_errors + dttls.caa_recommendations
665+
if not dttls.caa_enabled or dttls.caa_errors:
666+
category.subtests["mail_caa"].result_bad(caa_tech_table)
667+
elif dttls.caa_recommendations:
668+
category.subtests["mail_caa"].result_recommendations(caa_tech_table)
669+
else:
670+
category.subtests["mail_caa"].result_good(caa_tech_table)
671+
640672
if dttls.dane_status == DaneStatus.none:
641673
category.subtests["dane_exists"].result_bad()
642674
elif dttls.dane_status == DaneStatus.none_bogus:
@@ -711,15 +743,15 @@ def build_summary_report(testtls, category):
711743
testtls.report = report
712744

713745

714-
def do_web_cert(af_ip_pairs, url, task, *args, **kwargs):
746+
def do_web_cert(af_ip_pairs, url, *args, **kwargs):
715747
"""
716748
Check the web server's certificate.
717749
718750
"""
719751
try:
720752
results = {}
721753
for af_ip_pair in af_ip_pairs:
722-
results[af_ip_pair[1]] = cert_checks(url, ChecksMode.WEB, task, af_ip_pair, *args, **kwargs)
754+
results[af_ip_pair[1]] = cert_checks(url, ChecksMode.WEB, af_ip_pair, *args, **kwargs)
723755
except SoftTimeLimitExceeded:
724756
log.debug("Soft time limit exceeded. Url: %s", url)
725757
for af_ip_pair in af_ip_pairs:
@@ -747,7 +779,7 @@ def do_web_conn(af_ip_pairs, url, *args, **kwargs):
747779
return ("tls_conn", results)
748780

749781

750-
def do_mail_smtp_starttls(mailservers, url, task, *args, **kwargs):
782+
def do_mail_smtp_starttls(mailservers, url, *args, **kwargs):
751783
"""
752784
Start all the TLS related checks for the mail test.
753785
@@ -782,7 +814,7 @@ def do_mail_smtp_starttls(mailservers, url, task, *args, **kwargs):
782814
(server, dane_cb_data) for server, dane_cb_data, _ in mailservers if not results[server]
783815
]
784816
log.debug(f"=========== checking remaining {servers_to_check=}")
785-
results.update(check_mail_tls_multiple(servers_to_check, task))
817+
results.update(check_mail_tls_multiple(servers_to_check))
786818
time.sleep(1)
787819
for server, server_result in results.items():
788820
cache_id = redis_id.mail_starttls.id.format(server)
@@ -798,15 +830,15 @@ def do_mail_smtp_starttls(mailservers, url, task, *args, **kwargs):
798830
return "smtp_starttls", results
799831

800832

801-
def do_web_http(af_ip_pairs, url, task, *args, **kwargs):
833+
def do_web_http(af_ip_pairs, url, *args, **kwargs):
802834
"""
803835
Start all the HTTP related checks for the web test.
804836
805837
"""
806838
try:
807839
results = {}
808840
for af_ip_pair in af_ip_pairs:
809-
results[af_ip_pair[1]] = http_checks(af_ip_pair, url, task)
841+
results[af_ip_pair[1]] = http_checks(af_ip_pair, url)
810842

811843
except SoftTimeLimitExceeded:
812844
log.debug("Soft time limit exceeded.")

checks/tasks/tls_connection.py

Whitespace-only changes.

0 commit comments

Comments
 (0)