Implement hashing fields

This commit is contained in:
2022-08-18 07:20:30 +01:00
parent 3d8519154b
commit c984e70689
14 changed files with 261 additions and 38 deletions

View File

@@ -1,9 +1,11 @@
from copy import deepcopy
from django.conf import settings
from opensearchpy import OpenSearch
from opensearchpy.exceptions import NotFoundError, RequestError
from core.lib.threshold import annotate_num_chans, annotate_num_users, annotate_online
from core.views.helpers import dedup_list
from core.views.helpers import dedup_list, encrypt_list, hash_list, hash_lookup
def initialise_opensearch():
@@ -258,6 +260,7 @@ def query_results(
reverse=False,
dedup=False,
dedup_fields=None,
lookup_hashes=True,
):
"""
API helper to alter the OpenSearch return format into something
@@ -273,6 +276,13 @@ def query_results(
add_top = []
add_top_negative = []
sort = None
# Lookup the hash values but don't disclose them to the user
if lookup_hashes:
if settings.HASHING:
query_params = deepcopy(query_params)
hash_lookup(query_params)
if request.user.is_anonymous:
sizes = settings.OPENSEARCH_MAIN_SIZES_ANON
else:
@@ -397,6 +407,7 @@ def query_results(
return {"message": message, "class": message_class}
else:
index = settings.OPENSEARCH_INDEX_MAIN
results = run_main_query(
client,
request.user, # passed through run_main_query to filter_blacklisted
@@ -436,6 +447,15 @@ def query_results(
dedup_fields = ["msg", "nick", "ident", "host", "net", "channel"]
results_parsed = dedup_list(results_parsed, dedup_fields)
if settings.ENCRYPTION:
encrypt_list(results_parsed, settings.ENCRYPTION_KEY)
if settings.HASHING:
hash_list(results_parsed)
# process_list(reqults)
# IMPORTANT! - DO NOT PASS query_params to the user!
context = {
"object_list": results_parsed,
"card": results["hits"]["total"]["value"],