Merge pull request #38 from ethereum/hwwhww/uuid

Create uuid during calling `encrypt` instead of using class attribute
This commit is contained in:
Carl Beekhuizen 2020-05-26 15:32:17 +02:00 committed by GitHub
commit 9f7069575b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -65,7 +65,7 @@ class Keystore(BytesDataclass):
crypto: KeystoreCrypto = KeystoreCrypto() crypto: KeystoreCrypto = KeystoreCrypto()
pubkey: str = '' pubkey: str = ''
path: str = '' path: str = ''
uuid: str = str(uuid4()) # Generate a new uuid uuid: str = ''
version: int = 4 version: int = 4
def kdf(self, **kwargs: Any) -> bytes: def kdf(self, **kwargs: Any) -> bytes:
@ -96,6 +96,7 @@ class Keystore(BytesDataclass):
kdf_salt: bytes=randbits(256).to_bytes(32, 'big'), kdf_salt: bytes=randbits(256).to_bytes(32, 'big'),
aes_iv: bytes=randbits(128).to_bytes(16, 'big')) -> 'Keystore': aes_iv: bytes=randbits(128).to_bytes(16, 'big')) -> 'Keystore':
keystore = cls() keystore = cls()
keystore.uuid = str(uuid4())
keystore.crypto.kdf.params['salt'] = kdf_salt keystore.crypto.kdf.params['salt'] = kdf_salt
decryption_key = keystore.kdf(password=password, **keystore.crypto.kdf.params) decryption_key = keystore.kdf(password=password, **keystore.crypto.kdf.params)
keystore.crypto.cipher.params['iv'] = aes_iv keystore.crypto.cipher.params['iv'] = aes_iv

View File

@ -8,6 +8,7 @@ from click.testing import CliRunner
from eth2deposit import deposit from eth2deposit import deposit
from eth2deposit.deposit import main from eth2deposit.deposit import main
from eth2deposit.utils.constants import DEFAULT_VALIDATOR_KEYS_FOLDER_NAME from eth2deposit.utils.constants import DEFAULT_VALIDATOR_KEYS_FOLDER_NAME
from eth2deposit.key_handling.keystore import Keystore
def clean_key_folder(my_folder_path): def clean_key_folder(my_folder_path):
@ -36,7 +37,7 @@ def test_deposit(monkeypatch):
os.mkdir(my_folder_path) os.mkdir(my_folder_path)
runner = CliRunner() runner = CliRunner()
inputs = ['1', 'english', 'MyPassword', 'MyPassword', 'fakephrase'] inputs = ['5', 'english', 'MyPassword', 'MyPassword', 'fakephrase']
data = '\n'.join(inputs) data = '\n'.join(inputs)
result = runner.invoke(main, ['--folder', my_folder_path], input=data) result = runner.invoke(main, ['--folder', my_folder_path], input=data)
@ -45,7 +46,17 @@ def test_deposit(monkeypatch):
# Check files # Check files
validator_keys_folder_path = os.path.join(my_folder_path, DEFAULT_VALIDATOR_KEYS_FOLDER_NAME) validator_keys_folder_path = os.path.join(my_folder_path, DEFAULT_VALIDATOR_KEYS_FOLDER_NAME)
_, _, key_files = next(os.walk(validator_keys_folder_path)) _, _, key_files = next(os.walk(validator_keys_folder_path))
assert len(key_files) == 2
def get_uuid(key_file):
keystore = Keystore.from_json(key_file)
return keystore.uuid
all_uuid = [
get_uuid(validator_keys_folder_path + '/' + key_file)
for key_file in key_files
if key_file.startswith('keystore')
]
assert len(set(all_uuid)) == 5
# Clean up # Clean up
clean_key_folder(my_folder_path) clean_key_folder(my_folder_path)