From e349a78334b42eaf42e9dd36f00e018da6fc7122 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 13 Jul 2022 14:59:27 -0400 Subject: [PATCH] Island: Fix string/bytes bug in StringListEncryptor For some reason, bytes objects do not come out of mongo the same way they go in. This class will be removed when reporting is reworked, so rather than spend the time on figuring out exactly what's going on, just use strings. --- monkey/monkey_island/cc/models/report/report_dal.py | 3 ++- .../encryption/field_encryptors/string_list_encryptor.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/monkey/monkey_island/cc/models/report/report_dal.py b/monkey/monkey_island/cc/models/report/report_dal.py index 3b7ca65e9..76c43bae6 100644 --- a/monkey/monkey_island/cc/models/report/report_dal.py +++ b/monkey/monkey_island/cc/models/report/report_dal.py @@ -29,7 +29,8 @@ def save_report(report_dict: dict): def get_report() -> dict: report_dict = Report.objects.first().to_mongo() - return _decode_dot_char_before_mongo_insert(decrypt_dict(sensitive_fields, report_dict)) + decrypted = decrypt_dict(sensitive_fields, report_dict) + return _decode_dot_char_before_mongo_insert(decrypted) # TODO remove this unnecessary encoding. I think these are legacy methods from back in the day diff --git a/monkey/monkey_island/cc/server_utils/encryption/field_encryptors/string_list_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/field_encryptors/string_list_encryptor.py index 9adf733a4..bf2555016 100644 --- a/monkey/monkey_island/cc/server_utils/encryption/field_encryptors/string_list_encryptor.py +++ b/monkey/monkey_island/cc/server_utils/encryption/field_encryptors/string_list_encryptor.py @@ -6,9 +6,9 @@ from . import IFieldEncryptor class StringListEncryptor(IFieldEncryptor): @staticmethod - def encrypt(value: List[str]): - return [get_datastore_encryptor().encrypt(string.encode()) for string in value] + def encrypt(value: List[str]) -> List[str]: + return [get_datastore_encryptor().encrypt(string.encode()).decode() for string in value] @staticmethod - def decrypt(value: List[bytes]): - return [get_datastore_encryptor().decrypt(bytes_).decode() for bytes_ in value] + def decrypt(value: List[str]) -> List[str]: + return [get_datastore_encryptor().decrypt(string.encode()).decode() for string in value]