From 0eafc6613a14908bab3c0952d3f6ad30d571dabb Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 5 Oct 2021 12:37:05 -0400 Subject: [PATCH] Island: Flatten directory structure for "encryption" package --- .../cc/server_utils/encryption/__init__.py | 15 ++++++++------- .../encryption/data_store_encryptor.py | 4 +++- .../encryption/dict_encryption/__init__.py | 0 .../{dict_encryption => }/dict_encryptor.py | 0 .../encryption/encryptors/__init__.py | 4 ---- .../field_encryptors/__init__.py | 0 .../field_encryptors/i_field_encryptor.py | 0 .../mimikatz_results_encryptor.py | 2 +- .../field_encryptors/string_list_encryptor.py | 2 +- .../encryption/{encryptors => }/i_encryptor.py | 0 .../{encryptors => }/key_based_encryptor.py | 0 .../password_based_bytes_encryptor.py | 0 .../password_based_string_encryptor.py | 0 .../monkey_island/cc/models/test_report_dal.py | 5 +---- .../encryption}/test_string_list_encryptor.py | 4 +--- 15 files changed, 15 insertions(+), 21 deletions(-) delete mode 100644 monkey/monkey_island/cc/server_utils/encryption/dict_encryption/__init__.py rename monkey/monkey_island/cc/server_utils/encryption/{dict_encryption => }/dict_encryptor.py (100%) delete mode 100644 monkey/monkey_island/cc/server_utils/encryption/encryptors/__init__.py rename monkey/monkey_island/cc/server_utils/encryption/{dict_encryption => }/field_encryptors/__init__.py (100%) rename monkey/monkey_island/cc/server_utils/encryption/{dict_encryption => }/field_encryptors/i_field_encryptor.py (100%) rename monkey/monkey_island/cc/server_utils/encryption/{dict_encryption => }/field_encryptors/mimikatz_results_encryptor.py (93%) rename monkey/monkey_island/cc/server_utils/encryption/{dict_encryption => }/field_encryptors/string_list_encryptor.py (86%) rename monkey/monkey_island/cc/server_utils/encryption/{encryptors => }/i_encryptor.py (100%) rename monkey/monkey_island/cc/server_utils/encryption/{encryptors => }/key_based_encryptor.py (100%) rename monkey/monkey_island/cc/server_utils/encryption/{encryptors => }/password_based_bytes_encryptor.py (100%) rename monkey/monkey_island/cc/server_utils/encryption/{encryptors => }/password_based_string_encryptor.py (100%) rename monkey/tests/unit_tests/monkey_island/cc/{models/utils/field_encryptors => server_utils/encryption}/test_string_list_encryptor.py (83%) diff --git a/monkey/monkey_island/cc/server_utils/encryption/__init__.py b/monkey/monkey_island/cc/server_utils/encryption/__init__.py index 907ffbde6..1b302a6fc 100644 --- a/monkey/monkey_island/cc/server_utils/encryption/__init__.py +++ b/monkey/monkey_island/cc/server_utils/encryption/__init__.py @@ -1,12 +1,12 @@ -from monkey_island.cc.server_utils.encryption.encryptors.i_encryptor import IEncryptor -from monkey_island.cc.server_utils.encryption.encryptors.key_based_encryptor import ( +from .i_encryptor import IEncryptor +from .key_based_encryptor import ( KeyBasedEncryptor, ) -from monkey_island.cc.server_utils.encryption.encryptors.password_based_string_encryptor import ( +from .password_based_string_encryptor import ( PasswordBasedStringEncryptor, is_encrypted, ) -from monkey_island.cc.server_utils.encryption.encryptors.password_based_bytes_encryptor import ( +from .password_based_bytes_encryptor import ( PasswordBasedBytesEncryptor, InvalidCredentialsError, InvalidCiphertextError, @@ -16,11 +16,12 @@ from .data_store_encryptor import ( get_datastore_encryptor, remove_old_datastore_key, ) -from .dict_encryption.dict_encryptor import ( +from .dict_encryptor import ( SensitiveField, encrypt_dict, decrypt_dict, FieldNotFoundError, ) -from .dict_encryption.field_encryptors.mimikatz_results_encryptor import MimikatzResultsEncryptor -from .dict_encryption.field_encryptors.string_list_encryptor import StringListEncryptor +from .field_encryptors.i_field_encryptor import IFieldEncryptor +from .field_encryptors.mimikatz_results_encryptor import MimikatzResultsEncryptor +from .field_encryptors.string_list_encryptor import StringListEncryptor diff --git a/monkey/monkey_island/cc/server_utils/encryption/data_store_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/data_store_encryptor.py index 3e8028944..424a511f7 100644 --- a/monkey/monkey_island/cc/server_utils/encryption/data_store_encryptor.py +++ b/monkey/monkey_island/cc/server_utils/encryption/data_store_encryptor.py @@ -5,7 +5,9 @@ from Crypto import Random # noqa: DUO133 # nosec: B413 from monkey_island.cc.server_utils.file_utils import open_new_securely_permissioned_file -from .encryptors import IEncryptor, KeyBasedEncryptor, PasswordBasedBytesEncryptor +from .i_encryptor import IEncryptor +from .key_based_encryptor import KeyBasedEncryptor +from .password_based_bytes_encryptor import PasswordBasedBytesEncryptor _KEY_FILENAME = "mongo_key.bin" _BLOCK_SIZE = 32 diff --git a/monkey/monkey_island/cc/server_utils/encryption/dict_encryption/__init__.py b/monkey/monkey_island/cc/server_utils/encryption/dict_encryption/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/monkey/monkey_island/cc/server_utils/encryption/dict_encryption/dict_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/dict_encryptor.py similarity index 100% rename from monkey/monkey_island/cc/server_utils/encryption/dict_encryption/dict_encryptor.py rename to monkey/monkey_island/cc/server_utils/encryption/dict_encryptor.py diff --git a/monkey/monkey_island/cc/server_utils/encryption/encryptors/__init__.py b/monkey/monkey_island/cc/server_utils/encryption/encryptors/__init__.py deleted file mode 100644 index 11386f798..000000000 --- a/monkey/monkey_island/cc/server_utils/encryption/encryptors/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .i_encryptor import IEncryptor -from .key_based_encryptor import KeyBasedEncryptor -from .password_based_string_encryptor import PasswordBasedStringEncryptor -from .password_based_bytes_encryptor import PasswordBasedBytesEncryptor diff --git a/monkey/monkey_island/cc/server_utils/encryption/dict_encryption/field_encryptors/__init__.py b/monkey/monkey_island/cc/server_utils/encryption/field_encryptors/__init__.py similarity index 100% rename from monkey/monkey_island/cc/server_utils/encryption/dict_encryption/field_encryptors/__init__.py rename to monkey/monkey_island/cc/server_utils/encryption/field_encryptors/__init__.py diff --git a/monkey/monkey_island/cc/server_utils/encryption/dict_encryption/field_encryptors/i_field_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/field_encryptors/i_field_encryptor.py similarity index 100% rename from monkey/monkey_island/cc/server_utils/encryption/dict_encryption/field_encryptors/i_field_encryptor.py rename to monkey/monkey_island/cc/server_utils/encryption/field_encryptors/i_field_encryptor.py diff --git a/monkey/monkey_island/cc/server_utils/encryption/dict_encryption/field_encryptors/mimikatz_results_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/field_encryptors/mimikatz_results_encryptor.py similarity index 93% rename from monkey/monkey_island/cc/server_utils/encryption/dict_encryption/field_encryptors/mimikatz_results_encryptor.py rename to monkey/monkey_island/cc/server_utils/encryption/field_encryptors/mimikatz_results_encryptor.py index 696a9187b..31f597e60 100644 --- a/monkey/monkey_island/cc/server_utils/encryption/dict_encryption/field_encryptors/mimikatz_results_encryptor.py +++ b/monkey/monkey_island/cc/server_utils/encryption/field_encryptors/mimikatz_results_encryptor.py @@ -1,6 +1,6 @@ import logging -from ... import get_datastore_encryptor +from ..data_store_encryptor import get_datastore_encryptor from . import IFieldEncryptor logger = logging.getLogger(__name__) diff --git a/monkey/monkey_island/cc/server_utils/encryption/dict_encryption/field_encryptors/string_list_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/field_encryptors/string_list_encryptor.py similarity index 86% rename from monkey/monkey_island/cc/server_utils/encryption/dict_encryption/field_encryptors/string_list_encryptor.py rename to monkey/monkey_island/cc/server_utils/encryption/field_encryptors/string_list_encryptor.py index 6a0dd58d2..ce0ceb8dd 100644 --- a/monkey/monkey_island/cc/server_utils/encryption/dict_encryption/field_encryptors/string_list_encryptor.py +++ b/monkey/monkey_island/cc/server_utils/encryption/field_encryptors/string_list_encryptor.py @@ -1,6 +1,6 @@ from typing import List -from ... import get_datastore_encryptor +from ..data_store_encryptor import get_datastore_encryptor from . import IFieldEncryptor diff --git a/monkey/monkey_island/cc/server_utils/encryption/encryptors/i_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/i_encryptor.py similarity index 100% rename from monkey/monkey_island/cc/server_utils/encryption/encryptors/i_encryptor.py rename to monkey/monkey_island/cc/server_utils/encryption/i_encryptor.py diff --git a/monkey/monkey_island/cc/server_utils/encryption/encryptors/key_based_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/key_based_encryptor.py similarity index 100% rename from monkey/monkey_island/cc/server_utils/encryption/encryptors/key_based_encryptor.py rename to monkey/monkey_island/cc/server_utils/encryption/key_based_encryptor.py diff --git a/monkey/monkey_island/cc/server_utils/encryption/encryptors/password_based_bytes_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/password_based_bytes_encryptor.py similarity index 100% rename from monkey/monkey_island/cc/server_utils/encryption/encryptors/password_based_bytes_encryptor.py rename to monkey/monkey_island/cc/server_utils/encryption/password_based_bytes_encryptor.py diff --git a/monkey/monkey_island/cc/server_utils/encryption/encryptors/password_based_string_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/password_based_string_encryptor.py similarity index 100% rename from monkey/monkey_island/cc/server_utils/encryption/encryptors/password_based_string_encryptor.py rename to monkey/monkey_island/cc/server_utils/encryption/password_based_string_encryptor.py diff --git a/monkey/tests/unit_tests/monkey_island/cc/models/test_report_dal.py b/monkey/tests/unit_tests/monkey_island/cc/models/test_report_dal.py index 5d3d5a49a..67ac8355e 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/models/test_report_dal.py +++ b/monkey/tests/unit_tests/monkey_island/cc/models/test_report_dal.py @@ -5,10 +5,7 @@ import pytest from monkey_island.cc.models import Report from monkey_island.cc.models.report import get_report, save_report -from monkey_island.cc.server_utils.encryption import SensitiveField -from monkey_island.cc.server_utils.encryption.dict_encryption.field_encryptors import ( - IFieldEncryptor, -) +from monkey_island.cc.server_utils.encryption import IFieldEncryptor, SensitiveField MOCK_SENSITIVE_FIELD_CONTENTS = ["the_string", "the_string2"] MOCK_REPORT_DICT = { diff --git a/monkey/tests/unit_tests/monkey_island/cc/models/utils/field_encryptors/test_string_list_encryptor.py b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_string_list_encryptor.py similarity index 83% rename from monkey/tests/unit_tests/monkey_island/cc/models/utils/field_encryptors/test_string_list_encryptor.py rename to monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_string_list_encryptor.py index e39dffd94..b78cd6ec0 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/models/utils/field_encryptors/test_string_list_encryptor.py +++ b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_string_list_encryptor.py @@ -1,8 +1,6 @@ import pytest -from monkey_island.cc.server_utils.encryption.dict_encryption.field_encryptors import ( - StringListEncryptor, -) +from monkey_island.cc.server_utils.encryption import StringListEncryptor MOCK_STRING_LIST = ["test_1", "test_2"] EMPTY_LIST = []