Makes NuCypherKeyring disk write operations more lazy.

pull/1029/head
Kieran Prasch 2019-06-08 11:53:29 -07:00 committed by David Núñez
parent 3c949192f0
commit 8fcdf8e2f4
2 changed files with 29 additions and 17 deletions

View File

@ -50,14 +50,13 @@ class UrsulaConfiguration(NodeConfiguration):
base_filepaths.update(filepaths)
return base_filepaths
@property
def static_payload(self) -> dict:
payload = dict(
rest_host=self.rest_host,
rest_port=self.rest_port,
db_filepath=self.db_filepath,
)
return {**super().static_payload, **payload}
return {**super().static_payload(), **payload}
@property
def dynamic_payload(self) -> dict:
@ -194,14 +193,13 @@ class FelixConfiguration(NodeConfiguration):
DEFAULT_REST_PORT = 6151
DEFAULT_LEARNER_PORT = 9151
@property
def static_payload(self) -> dict:
payload = dict(
rest_host=self.rest_host,
rest_port=self.rest_port,
db_filepath=self.db_filepath,
)
return {**super().static_payload, **payload}
return {**super().static_payload(), **payload}
def write_keyring(self, password: str, **generation_kwargs) -> NucypherKeyring:

View File

@ -525,8 +525,9 @@ class NucypherKeyring:
rest: bool,
host: str = None,
curve: EllipticCurve = None,
federated: bool = False,
checksum_address: str = None,
keyring_root: str = None,
checksum_address: str = None
) -> 'NucypherKeyring':
"""
Generates new encrypting, signing, and wallet keys encrypted with the password,
@ -545,20 +546,10 @@ class NucypherKeyring:
if curve is None:
curve = cls.__DEFAULT_TLS_CURVE
if checksum_address and not is_checksum_address(checksum_address):
raise ValueError(f"{checksum_address} is not a valid ethereum checksum address")
_base_filepaths = cls._generate_base_filepaths(keyring_root=keyring_root)
_public_key_dir = _base_filepaths['public_key_dir']
_private_key_dir = _base_filepaths['private_key_dir']
# Write to disk
if not os.path.isdir(_public_key_dir):
os.mkdir(_public_key_dir, mode=0o744) # public dir
if not os.path.isdir(_private_key_dir):
os.mkdir(_private_key_dir, mode=0o700) # private dir
#
# Generate New Keypairs
#
@ -568,12 +559,23 @@ class NucypherKeyring:
if encrypting is True:
signing_private_key, signing_public_key = _generate_signing_keys()
if checksum_address is None:
if federated and not checksum_address:
uncompressed_bytes = signing_public_key.to_bytes(is_compressed=False)
without_prefix = uncompressed_bytes[1:]
verifying_key_as_eth_key = EthKeyAPI.PublicKey(without_prefix)
checksum_address = verifying_key_as_eth_key.to_checksum_address()
else:
# TODO: Consider a "Repair" mode here
# signing_private_key, signing_public_key = ...
pass
if not checksum_address:
raise ValueError("Checksum address must bas provided for non-federated keyring generation")
# Addresses read from some node keyrings (clients) are *not* returned in checksum format.
checksum_address = to_checksum_address(checksum_address)
__key_filepaths = cls._generate_key_filepaths(account=checksum_address,
private_key_dir=_private_key_dir,
public_key_dir=_public_key_dir)
@ -606,7 +608,19 @@ class NucypherKeyring:
master_salt=password_salt,
wrap_salt=delegating_salt)
# Write Private Keys
#
# Write Keys
#
if not os.path.isdir(keyring_root):
os.mkdir(keyring_root, mode=0o700) # TODO: Keyring backend entry point - COS
if not os.path.isdir(_public_key_dir):
os.mkdir(_public_key_dir, mode=0o744) # public dir
if not os.path.isdir(_private_key_dir):
os.mkdir(_private_key_dir, mode=0o700) # private dir
rootkey_path = _write_private_keyfile(keypath=__key_filepaths['root'],
key_data=encrypting_key_metadata,
serializer=cls._private_key_serializer)