From 86ce7f2cf9dcf82d8d290c47d81f4703cec3cfd1 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 14 Jul 2022 07:56:42 -0400 Subject: [PATCH] Island: Remove disused dict_encryptor --- .../cc/server_utils/encryption/__init__.py | 6 --- .../server_utils/encryption/dict_encryptor.py | 48 ------------------- 2 files changed, 54 deletions(-) delete mode 100644 monkey/monkey_island/cc/server_utils/encryption/dict_encryptor.py diff --git a/monkey/monkey_island/cc/server_utils/encryption/__init__.py b/monkey/monkey_island/cc/server_utils/encryption/__init__.py index d790a71f6..f39c9c603 100644 --- a/monkey/monkey_island/cc/server_utils/encryption/__init__.py +++ b/monkey/monkey_island/cc/server_utils/encryption/__init__.py @@ -14,11 +14,5 @@ from .data_store_encryptor import ( unlock_datastore_encryptor, reset_datastore_encryptor, ) -from .dict_encryptor import ( - SensitiveField, - encrypt_dict, - decrypt_dict, - FieldNotFoundError, -) from .field_encryptors.i_field_encryptor import IFieldEncryptor from .field_encryptors.string_encryptor import StringEncryptor diff --git a/monkey/monkey_island/cc/server_utils/encryption/dict_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/dict_encryptor.py deleted file mode 100644 index 4dc4662d6..000000000 --- a/monkey/monkey_island/cc/server_utils/encryption/dict_encryptor.py +++ /dev/null @@ -1,48 +0,0 @@ -from dataclasses import dataclass -from typing import Callable, List, Type - -import dpath.util - -from .field_encryptors import IFieldEncryptor - - -class FieldNotFoundError(Exception): - pass - - -@dataclass -class SensitiveField: - path: str - path_separator = "." - field_encryptor: Type[IFieldEncryptor] - - -def encrypt_dict(sensitive_fields: List[SensitiveField], document_dict: dict) -> dict: - for sensitive_field in sensitive_fields: - _apply_operation_to_document_field( - document_dict, sensitive_field, sensitive_field.field_encryptor.encrypt - ) - - return document_dict - - -def decrypt_dict(sensitive_fields: List[SensitiveField], document_dict: dict) -> dict: - for sensitive_field in sensitive_fields: - _apply_operation_to_document_field( - document_dict, sensitive_field, sensitive_field.field_encryptor.decrypt - ) - return document_dict - - -def _apply_operation_to_document_field( - report: dict, sensitive_field: SensitiveField, operation: Callable -): - field_value = dpath.util.get(report, sensitive_field.path, sensitive_field.path_separator, None) - if field_value is None: - raise FieldNotFoundError( - f"Can't encrypt object because the path {sensitive_field.path} doesn't exist." - ) - - modified_value = operation(field_value) - - dpath.util.set(report, sensitive_field.path, modified_value, sensitive_field.path_separator)