forked from p15670423/monkey
Island: Rename FieldType to FieldEncryptor
* Switch FieldTypeABC from abstract class to interface, since there's no intention of ever implementing FieldTypeABC's methods. * Rename FieldTypeABC to IFieldEncryptor and rename StringList to StringListEncryptor.
This commit is contained in:
parent
5077d84269
commit
13ba0b9091
|
@ -0,0 +1,24 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from typing import Any
|
||||
|
||||
|
||||
class IFieldEncryptor(ABC):
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def encrypt(value: Any) -> Any:
|
||||
"""Encrypts data and returns the ciphertext.
|
||||
|
||||
:param value: Data that will be encrypted
|
||||
:return: Ciphertext generated by encrypting value
|
||||
:rtype: Any
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def decrypt(value: Any):
|
||||
"""Decrypts data and returns the plaintext.
|
||||
|
||||
:param value: Ciphertext that will be decrypted
|
||||
:return: Plaintext generated by decrypting value
|
||||
:rtype: Any
|
||||
"""
|
|
@ -1,10 +1,10 @@
|
|||
from typing import List
|
||||
|
||||
from monkey_island.cc.models.utils.field_types.field_type_abc import FieldTypeABC
|
||||
from monkey_island.cc.models.utils.field_encryptors.i_field_encryptor import IFieldEncryptor
|
||||
from monkey_island.cc.server_utils.encryption import string_encryptor
|
||||
|
||||
|
||||
class StringList(FieldTypeABC):
|
||||
class StringListEncryptor(IFieldEncryptor):
|
||||
@staticmethod
|
||||
def encrypt(value: List[str]):
|
||||
return [string_encryptor.encrypt(string) for string in value]
|
|
@ -1,14 +0,0 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from typing import Any
|
||||
|
||||
|
||||
class FieldTypeABC(ABC):
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def encrypt(value: Any):
|
||||
raise NotImplementedError()
|
||||
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def decrypt(value: Any):
|
||||
raise NotImplementedError()
|
|
@ -3,18 +3,20 @@ from typing import Callable, Type
|
|||
|
||||
import dpath.util
|
||||
|
||||
from monkey_island.cc.models.utils.field_types.field_type_abc import FieldTypeABC
|
||||
from monkey_island.cc.models.utils.field_types.string_list import StringList
|
||||
from monkey_island.cc.models.utils.field_encryptors.i_field_encryptor import IFieldEncryptor
|
||||
from monkey_island.cc.models.utils.field_encryptors.string_list_encryptor import StringListEncryptor
|
||||
|
||||
|
||||
@dataclass
|
||||
class SensitiveField:
|
||||
path: str
|
||||
path_separator = "."
|
||||
field_type: Type[FieldTypeABC]
|
||||
field_type: Type[IFieldEncryptor]
|
||||
|
||||
|
||||
sensitive_fields = [SensitiveField(path="overview.config_passwords", field_type=StringList)]
|
||||
sensitive_fields = [
|
||||
SensitiveField(path="overview.config_passwords", field_type=StringListEncryptor)
|
||||
]
|
||||
|
||||
|
||||
def encrypt(report: dict) -> dict:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from monkey_island.cc.models import Report
|
||||
from monkey_island.cc.models.utils.field_types.string_list import StringList
|
||||
from monkey_island.cc.models.utils.field_encryptors.string_list_encryptor import StringListEncryptor
|
||||
from monkey_island.cc.models.utils.report_encryptor import SensitiveField
|
||||
from monkey_island.cc.server_utils.encryptor import initialize_encryptor
|
||||
|
||||
|
@ -13,7 +13,7 @@ MOCK_REPORT_DICT = {
|
|||
"meta_info": {"foo": "bar"},
|
||||
}
|
||||
|
||||
MOCK_SENSITIVE_FIELDS = [SensitiveField("overview.foo.the_key", StringList)]
|
||||
MOCK_SENSITIVE_FIELDS = [SensitiveField("overview.foo.the_key", StringListEncryptor)]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("uses_database")
|
||||
|
|
Loading…
Reference in New Issue