Some cleanup and refactor.

pull/501/head
jMyles 2018-10-23 18:45:43 +02:00
parent 6144bca92f
commit 7ef561ff2e
7 changed files with 41 additions and 41 deletions

View File

@ -584,9 +584,10 @@ class Ursula(Character, VerifiableNode, Miner):
network_middleware: RestMiddleware,
host: str,
port: int,
certificate_filepath,
federated_only: bool = False) -> 'Ursula':
response = network_middleware.node_information(host, port) # TODO: pre-load certificates here?
response = network_middleware.node_information(host, port, certificate_filepath=certificate_filepath)
if not response.status_code == 200:
raise RuntimeError("Got a bad response: {}".format(response))

View File

@ -12,10 +12,10 @@ APP_DIR = AppDirs("nucypher", "NuCypher")
DEFAULT_CONFIG_ROOT = APP_DIR.user_data_dir
#
# Bootnodes
# seednodes
#
Bootnode = namedtuple('Bootnode', ['checksum_address', 'rest_url'])
BOOTNODES = (
Bootnode('0xDbf2Bc4b81eB46CdDfa52348Ecf3c142841267E0', 'https://18.223.117.103:9151'),
SeednodeMetadata = namedtuple('seednode', ['checksum_address', 'rest_host', 'rest_port'])
SEEDNODES = (
SeednodeMetadata('0xDbf2Bc4b81eB46CdDfa52348Ecf3c142841267E0', 'https://18.223.117.103', '9151'),
)

View File

@ -1,31 +1,21 @@
import binascii
import json
import os
import socket
import ssl
import time
from json import JSONDecodeError
from logging import getLogger
from tempfile import TemporaryDirectory
from typing import List
from urllib.parse import urlparse
from constant_sorrow import constants
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.serialization import Encoding
from nucypher.characters.lawful import Ursula
from nucypher.config.constants import DEFAULT_CONFIG_ROOT, BASE_DIR, BOOTNODES
from nucypher.config.keyring import NucypherKeyring, _write_tls_certificate
from nucypher.config.constants import DEFAULT_CONFIG_ROOT, BASE_DIR
from nucypher.config.keyring import NucypherKeyring
from nucypher.config.storages import NodeStorage, InMemoryNodeStorage, LocalFileBasedNodeStorage
from nucypher.crypto.powers import CryptoPowerUp
from nucypher.crypto.signing import signature_splitter
from nucypher.network.middleware import RestMiddleware
class NodeConfiguration:
_name = 'node'
_Character = NotImplemented
@ -236,19 +226,19 @@ class NodeConfiguration:
def static_payload(self) -> dict:
"""Exported static configuration values for initializing Ursula"""
payload = dict(
# Identity
is_me=self.is_me,
federated_only=self.federated_only, # TODO: 466
checksum_address=self.checksum_address,
keyring_dir=self.keyring_dir,
known_certificates_dir=self.known_certificates_dir,
# Identity
is_me=self.is_me,
federated_only=self.federated_only, # TODO: 466
checksum_address=self.checksum_address,
keyring_dir=self.keyring_dir,
known_certificates_dir=self.known_certificates_dir,
# Behavior
learn_on_same_thread=self.learn_on_same_thread,
abort_on_learning_error=self.abort_on_learning_error,
start_learning_now=self.start_learning_now,
save_metadata=self.save_metadata
)
# Behavior
learn_on_same_thread=self.learn_on_same_thread,
abort_on_learning_error=self.abort_on_learning_error,
start_learning_now=self.start_learning_now,
save_metadata=self.save_metadata
)
return payload
@property
@ -334,9 +324,9 @@ class NodeConfiguration:
try:
# Directories
os.mkdir(self.keyring_dir, mode=0o700) # keyring
os.mkdir(self.known_nodes_dir, mode=0o755) # known_nodes
os.mkdir(self.known_certificates_dir, mode=0o755) # known_certs
os.mkdir(self.keyring_dir, mode=0o700) # keyring
os.mkdir(self.known_nodes_dir, mode=0o755) # known_nodes
os.mkdir(self.known_certificates_dir, mode=0o755) # known_certs
self.node_storage.initialize() # TODO: default know dir
if not self.temp and not no_keys:
@ -356,7 +346,8 @@ class NodeConfiguration:
except FileExistsError:
existing_paths = [os.path.join(self.config_root, f) for f in os.listdir(self.config_root)]
message = "There are pre-existing nucypher installation files at {}: {}".format(self.config_root, existing_paths)
message = "There are pre-existing nucypher installation files at {}: {}".format(self.config_root,
existing_paths)
self.log.critical(message)
raise NodeConfiguration.ConfigurationError(message)
@ -374,7 +365,7 @@ class NodeConfiguration:
raise self.ConfigurationError("No account specified to unlock keyring")
self.keyring = NucypherKeyring(keyring_root=self.keyring_dir,
account=self.checksum_address,
*args, ** kwargs)
*args, **kwargs)
def write_keyring(self,
passphrase: str,
@ -410,7 +401,8 @@ class NodeConfiguration:
blank=False) -> str:
if force and os.path.isfile(output_filepath):
raise self.ConfigurationError('There is an existing file at the registry output_filepath {}'.format(output_filepath))
raise self.ConfigurationError(
'There is an existing file at the registry output_filepath {}'.format(output_filepath))
output_filepath = output_filepath or self.registry_filepath
source = source or self.REGISTRY_SOURCE

View File

@ -3,9 +3,11 @@ import requests
from bytestring_splitter import BytestringSplitter, VariableLengthBytestring
from umbral.fragments import CapsuleFrag
from twisted.logger import Logger
class RestMiddleware:
log = Logger()
def consider_arrangement(self, arrangement):
node = arrangement.ursula

View File

@ -8,6 +8,7 @@ from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.x509 import Certificate
from eth_keys.datatypes import Signature as EthSignature
from nucypher.config.constants import SeednodeMetadata
from nucypher.config.keyring import _write_tls_certificate
from nucypher.crypto.powers import BlockchainPower, SigningPower, EncryptingPower, NoSigningPower
from nucypher.network.protocols import SuspiciousActivity
@ -15,7 +16,6 @@ from nucypher.network.server import TLSHostingPower
class VerifiableNode:
_evidence_of_decentralized_identity = constants.NOT_SIGNED
verified_stamp = False
verified_interface = False
@ -72,7 +72,7 @@ class VerifiableNode:
return True
elif self.federated_only and signature is constants.NOT_SIGNED:
message = "This node can't be verified in this manner, " \
"but is OK to use in federated mode if you" \
"but is OK to use in federated mode if you" \
" have reason to believe it is trustworthy."
raise self.WrongMode(message)
else:
@ -131,9 +131,9 @@ class VerifiableNode:
certificate_filepath=certificate_filepath)
if not response.status_code == 200:
raise RuntimeError("Or something.") # TODO: Raise an error here? Or return False? Or something?
timestamp, signature, identity_evidence, \
verifying_key, encrypting_key, \
public_address, certificate_vbytes, rest_info = self._internal_splitter(response.content)
timestamp, signature, identity_evidence, \
verifying_key, encrypting_key, \
public_address, certificate_vbytes, rest_info = self._internal_splitter(response.content)
verifying_keys_match = verifying_key == self.public_keys(SigningPower)
encrypting_keys_match = encrypting_key == self.public_keys(EncryptingPower)

View File

@ -1,4 +1,9 @@
from urllib.parse import urlparse
from apistar import TestClient
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.serialization import Encoding
from nucypher.characters.lawful import Ursula
from nucypher.network.middleware import RestMiddleware
@ -88,6 +93,7 @@ class EvilMiddleWare(MockRestMiddleware):
"""
Middleware for assholes.
"""
def propagate_shitty_interface_id(self, ursula, shitty_interface_id):
"""
Try to get Ursula to propagate a malicious (or otherwise shitty) interface ID.

View File

@ -15,7 +15,6 @@ from typing import Set, Union
from nucypher.blockchain.eth import constants
from nucypher.characters.lawful import Ursula
from nucypher.config.characters import UrsulaConfiguration
from nucypher.config.constants import BOOTNODES
from nucypher.crypto.api import secure_random
from nucypher.utilities.sandbox.constants import (DEFAULT_NUMBER_OF_URSULAS_IN_DEVELOPMENT_NETWORK,
TEST_URSULA_STARTING_PORT,