mitm status on announces

main
Bob Mottram 2022-10-03 11:39:23 +01:00
parent ff124762b5
commit a9e300037d
2 changed files with 32 additions and 23 deletions

View File

@ -456,6 +456,7 @@ class PubServer(BaseHTTPRequestHandler):
"""Detect if a request contains a MiTM """Detect if a request contains a MiTM
""" """
mitm_domains = ['cloudflare'] mitm_domains = ['cloudflare']
# look for domains within these headers
check_headers = ( check_headers = (
'Server', 'Report-To', 'Report-to', 'report-to', 'Server', 'Report-To', 'Report-to', 'report-to',
'Expect-CT', 'Expect-Ct', 'expect-ct' 'Expect-CT', 'Expect-Ct', 'expect-ct'
@ -465,7 +466,7 @@ class PubServer(BaseHTTPRequestHandler):
if self.headers.get(header_name): if self.headers.get(header_name):
if interloper in self.headers[header_name]: if interloper in self.headers[header_name]:
return True return True
# The presence if these headers on their own indicates a MiTM # The presence of these headers on their own indicates a MiTM
mitm_headers = ( mitm_headers = (
'CF-Connecting-IP', 'CF-RAY', 'CF-IPCountry', 'CF-Visitor', 'CF-Connecting-IP', 'CF-RAY', 'CF-IPCountry', 'CF-Visitor',
'CDN-Loop', 'CF-Worker', 'CF-Cache-Status' 'CDN-Loop', 'CF-Worker', 'CF-Cache-Status'

View File

@ -742,23 +742,23 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str,
print('DIGEST|' + time_diff_str + '|' + filename) print('DIGEST|' + time_diff_str + '|' + filename)
new_queue_item = { new_queue_item = {
'originalId': original_post_id, "originalId": original_post_id,
'id': post_id, "id": post_id,
'actor': actor, "actor": actor,
'nickname': nickname, "nickname": nickname,
'domain': domain, "domain": domain,
'postNickname': post_nickname, "postNickname": post_nickname,
'postDomain': post_domain, "postDomain": post_domain,
'sharedInbox': shared_inbox_item, "sharedInbox": shared_inbox_item,
'published': published, "published": published,
'httpHeaders': http_headers, "httpHeaders": http_headers,
'path': post_path, "path": post_path,
'post': post_json_object, "post": post_json_object,
'original': original_post_json_object, "original": original_post_json_object,
'digest': digest, "digest": digest,
'filename': filename, "filename": filename,
'destination': destination, "destination": destination,
'mitm': mitm "mitm": mitm
} }
if debug: if debug:
@ -2410,7 +2410,7 @@ def _receive_announce(recent_posts_cache: {},
peertube_instances: [], peertube_instances: [],
max_like_count: int, cw_lists: {}, max_like_count: int, cw_lists: {},
lists_enabled: str, bold_reading: bool, lists_enabled: str, bold_reading: bool,
dogwhistles: {}) -> bool: dogwhistles: {}, mitm: bool) -> bool:
"""Receives an announce activity within the POST section of HTTPServer """Receives an announce activity within the POST section of HTTPServer
""" """
if message_json['type'] != 'Announce': if message_json['type'] != 'Announce':
@ -2510,9 +2510,17 @@ def _receive_announce(recent_posts_cache: {},
if debug: if debug:
print('Generating html for announce ' + message_json['id']) print('Generating html for announce ' + message_json['id'])
timezone = get_account_timezone(base_dir, nickname, domain) timezone = get_account_timezone(base_dir, nickname, domain)
mitm = False
if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): if mitm:
mitm = True post_filename_mitm = \
post_filename.replace('.json', '') + '.mitm'
try:
with open(post_filename_mitm, 'w+',
encoding='utf-8') as mitm_file:
mitm_file.write('\n')
except OSError:
print('EX: unable to write mitm ' + post_filename_mitm)
announce_html = \ announce_html = \
individual_post_as_html(signing_priv_key_pem, True, individual_post_as_html(signing_priv_key_pem, True,
recent_posts_cache, max_recent_posts, recent_posts_cache, max_recent_posts,
@ -4152,7 +4160,7 @@ def _inbox_after_initial(server, inbox_start_time,
allow_deletion, allow_deletion,
peertube_instances, peertube_instances,
max_like_count, cw_lists, lists_enabled, max_like_count, cw_lists, lists_enabled,
bold_reading, dogwhistles): bold_reading, dogwhistles, mitm):
if debug: if debug:
print('DEBUG: Announce accepted from ' + actor) print('DEBUG: Announce accepted from ' + actor)
fitness_performance(inbox_start_time, server.fitness, fitness_performance(inbox_start_time, server.fitness,