Island, UT: Add String field encryptor

This encryptor is going to be used by dict_encryptor
to encrypt/decrypt the ssh_keypairs dictionaries
This commit is contained in:
Ilija Lazoroski 2022-04-06 16:56:42 +02:00
parent 8248004bce
commit 12937f9880
4 changed files with 31 additions and 0 deletions

View File

@ -24,3 +24,4 @@ from .dict_encryptor import (
)
from .field_encryptors.i_field_encryptor import IFieldEncryptor
from .field_encryptors.string_list_encryptor import StringListEncryptor
from .field_encryptors.string_encryptor import StringEncryptor

View File

@ -1,2 +1,3 @@
from .i_field_encryptor import IFieldEncryptor
from .string_list_encryptor import StringListEncryptor
from .string_encryptor import StringEncryptor

View File

@ -0,0 +1,12 @@
from ..data_store_encryptor import get_datastore_encryptor
from . import IFieldEncryptor
class StringEncryptor(IFieldEncryptor):
@staticmethod
def encrypt(value: str):
return get_datastore_encryptor().encrypt(value)
@staticmethod
def decrypt(value: str):
return get_datastore_encryptor().decrypt(value)

View File

@ -0,0 +1,17 @@
from monkey_island.cc.server_utils.encryption import StringEncryptor
MOCK_STRING = "m0nk3y"
EMPTY_STRING = ""
def test_encryptor(uses_encryptor):
encrypted_string = StringEncryptor.encrypt(MOCK_STRING)
assert not encrypted_string == MOCK_STRING
decrypted_string = StringEncryptor.decrypt(encrypted_string)
assert decrypted_string == MOCK_STRING
def test_empty_string(uses_encryptor):
# Tests that no erros are raised
encrypted_string = StringEncryptor.encrypt(EMPTY_STRING)
StringEncryptor.decrypt(encrypted_string)