mirror of https://github.com/nucypher/nucypher.git
Updating tests and splitters.
parent
d32f290d6b
commit
06c1c6b06b
|
@ -138,6 +138,9 @@ class KeyStore(object):
|
|||
|
||||
policy_arrangement = session.query(PolicyArrangement).filter_by(hrac=hrac_as_hex.encode()).first()
|
||||
|
||||
if policy_arrangement is None:
|
||||
raise NotFound("Can't attach a kfrag to non-existent Arrangement with hrac {}".format(hrac_as_hex))
|
||||
|
||||
if policy_arrangement.alice_pubkey_sig.key_data != alice.stamp:
|
||||
raise alice.SuspiciousActivity
|
||||
|
||||
|
|
|
@ -46,19 +46,28 @@ class NetworkyStuff(object):
|
|||
return NotImplemented
|
||||
|
||||
def get_treasure_map_from_node(self, node, map_id):
|
||||
response = requests.get("{}/treasure_map/{}".format(node.rest_url(), map_id.hex()), verify=False)
|
||||
port = node.rest_port
|
||||
address = node.ip_address
|
||||
endpoint = "https://{}:{}/treasure_map/{}".format(address, port, map_id.hex())
|
||||
response = requests.get(endpoint, verify=False)
|
||||
return response
|
||||
|
||||
def push_treasure_map_to_node(self, node, map_id, map_payload):
|
||||
response = requests.post("{}/treasure_map/{}".format(node.rest_url(), map_id.hex()),
|
||||
data=map_payload, verify=False)
|
||||
port = node.rest_port
|
||||
address = node.ip_address
|
||||
endpoint = "https://{}:{}/treasure_map/{}".format(address, port, map_id.hex())
|
||||
response = requests.post(endpoint, data=map_payload, verify=False)
|
||||
return response
|
||||
|
||||
def send_work_order_payload_to_ursula(self, work_order):
|
||||
payload = work_order.payload()
|
||||
hrac_as_hex = work_order.kfrag_hrac.hex()
|
||||
return requests.post('{}/kFrag/{}/reencrypt'.format(work_order.ursula.rest_url(), hrac_as_hex),
|
||||
return requests.post('https://{}/kFrag/{}/reencrypt'.format(work_order.ursula.rest_url(), hrac_as_hex),
|
||||
payload, verify=False)
|
||||
|
||||
def ursula_from_rest_interface(self, address, port):
|
||||
return requests.get("{}:{}/list_nodes".format(address, port), verify=False) # TODO: TLS-only.
|
||||
return requests.get("https://{}:{}/public_keys".format(address, port), verify=False) # TODO: TLS-only.
|
||||
|
||||
def get_nodes_via_rest(self, address, port):
|
||||
response = requests.get("https://{}:{}/list_nodes".format(address, port), verify=False) # TODO: TLS-only.
|
||||
return response
|
||||
|
|
|
@ -11,9 +11,8 @@ from nkms.network.node import NuCypherNode
|
|||
from nkms.network.routing import NuCypherRoutingTable
|
||||
from umbral.keys import UmbralPublicKey
|
||||
|
||||
dht_value_splitter = default_constant_splitter + BytestringSplitter(Signature,
|
||||
(UmbralPublicKey, PUBLIC_KEY_LENGTH),
|
||||
(bytes, KECCAK_DIGEST_LENGTH))
|
||||
dht_value_splitter = default_constant_splitter + BytestringSplitter(Signature, (UmbralPublicKey, PUBLIC_KEY_LENGTH))
|
||||
dht_with_hrac_splitter = dht_value_splitter + BytestringSplitter((bytes, KECCAK_DIGEST_LENGTH))
|
||||
|
||||
|
||||
class NuCypherHashProtocol(KademliaProtocol):
|
||||
|
@ -78,9 +77,16 @@ class NuCypherHashProtocol(KademliaProtocol):
|
|||
self.log.debug("got a store request from %s" % str(sender))
|
||||
|
||||
# TODO: Why is this logic here? This is madness. See #172.
|
||||
if value.startswith(bytes(constants.BYTESTRING_IS_URSULA_IFACE_INFO)) or value.startswith(
|
||||
bytes(constants.BYTESTRING_IS_TREASURE_MAP)):
|
||||
header, signature, sender_pubkey_sig, hrac, message = dht_value_splitter(
|
||||
if value.startswith(bytes(constants.BYTESTRING_IS_URSULA_IFACE_INFO)):
|
||||
header, signature, sender_pubkey_sig, message = dht_value_splitter(
|
||||
value, return_remainder=True)
|
||||
|
||||
# TODO: TTL?
|
||||
hrac = keccak_digest(message)
|
||||
do_store = self.determine_legality_of_dht_key(signature, sender_pubkey_sig, message,
|
||||
hrac, key, value)
|
||||
elif value.startswith(bytes(constants.BYTESTRING_IS_TREASURE_MAP)):
|
||||
header, signature, sender_pubkey_sig, hrac, message = dht_with_hrac_splitter(
|
||||
value, return_remainder=True)
|
||||
|
||||
# TODO: TTL?
|
||||
|
|
|
@ -17,7 +17,7 @@ from nkms.keystore.threading import ThreadedSession
|
|||
from nkms.network.capabilities import SeedOnly, ServerCapability
|
||||
from nkms.network.node import NuCypherNode
|
||||
from nkms.network.protocols import NuCypherSeedOnlyProtocol, NuCypherHashProtocol, \
|
||||
dht_value_splitter
|
||||
dht_value_splitter, dht_with_hrac_splitter
|
||||
from nkms.network.storage import SeedOnlyStorage
|
||||
|
||||
|
||||
|
@ -95,8 +95,7 @@ class NuCypherSeedOnlyDHTServer(NuCypherDHTServer):
|
|||
|
||||
class ProxyRESTServer(object):
|
||||
|
||||
def __init__(self, rest_address, rest_port, db_name):
|
||||
self.rest_address = rest_address
|
||||
def __init__(self, rest_port, db_name):
|
||||
self.rest_port = rest_port
|
||||
self.db_name = db_name
|
||||
self._rest_app = None
|
||||
|
@ -146,14 +145,12 @@ class ProxyRESTServer(object):
|
|||
self.db_engine = engine
|
||||
|
||||
def rest_url(self):
|
||||
return "{}:{}".format(self.rest_address, self.rest_port)
|
||||
return "{}:{}".format(self.ip_address, self.rest_port)
|
||||
|
||||
# """
|
||||
|
||||
#####################################
|
||||
# Actual REST Endpoints and utilities
|
||||
# """
|
||||
# def find_ursulas_by_ids(self, request: http.Request):
|
||||
#
|
||||
#
|
||||
#####################################
|
||||
|
||||
def get_signing_and_encrypting_public_keys(self):
|
||||
"""
|
||||
|
@ -170,6 +167,7 @@ class ProxyRESTServer(object):
|
|||
def list_all_active_nodes_about_which_we_know(self):
|
||||
headers = {'Content-Type': 'application/octet-stream'}
|
||||
ursulas_as_bytes = bytes().join(self.server.protocol.ursulas.values())
|
||||
ursulas_as_bytes += self.interface_info_with_metadata()
|
||||
signature = self.stamp(ursulas_as_bytes)
|
||||
return Response(bytes(signature) + ursulas_as_bytes, headers=headers)
|
||||
|
||||
|
@ -178,7 +176,7 @@ class ProxyRESTServer(object):
|
|||
arrangement = Arrangement.from_bytes(request.body)
|
||||
|
||||
with ThreadedSession(self.db_engine) as session:
|
||||
self.datastore.add_policy_arrangement(
|
||||
new_policyarrangement = self.datastore.add_policy_arrangement(
|
||||
arrangement.expiration.datetime(),
|
||||
bytes(arrangement.deposit),
|
||||
hrac=arrangement.hrac.hex().encode(),
|
||||
|
@ -189,6 +187,7 @@ class ProxyRESTServer(object):
|
|||
# to decide if this Arrangement is worth accepting.
|
||||
|
||||
headers = {'Content-Type': 'application/octet-stream'}
|
||||
# TODO: Make this a legit response #234.
|
||||
return Response(b"This will eventually be an actual acceptance of the arrangement.", headers=headers)
|
||||
|
||||
def set_policy(self, hrac_as_hex, request: http.Request):
|
||||
|
@ -254,25 +253,31 @@ class ProxyRESTServer(object):
|
|||
def provide_treasure_map(self, treasure_map_id_as_hex):
|
||||
# For now, grab the TreasureMap for the DHT storage. Soon, no do that. #TODO!
|
||||
treasure_map_id = binascii.unhexlify(treasure_map_id_as_hex)
|
||||
treasure_map_bytes = self.server.storage.get(digest(treasure_map_id))
|
||||
headers = {'Content-Type': 'application/octet-stream'}
|
||||
|
||||
return Response(content=treasure_map_bytes, headers=headers)
|
||||
try:
|
||||
treasure_map_bytes = self.server.storage[digest(treasure_map_id)]
|
||||
response = Response(content=treasure_map_bytes, headers=headers)
|
||||
except KeyError:
|
||||
response = Response("No Treasure Map with ID {}".format(treasure_map_id),
|
||||
status_code=404, headers=headers)
|
||||
|
||||
return response
|
||||
|
||||
def receive_treasure_map(self, treasure_map_id_as_hex, request: http.Request):
|
||||
# TODO: This function is the epitome of #172.
|
||||
treasure_map_id = binascii.unhexlify(treasure_map_id_as_hex)
|
||||
|
||||
header, signature_for_ursula, pubkey_sig_alice, hrac, tmap_message_kit = \
|
||||
dht_value_splitter(request.body, return_remainder=True)
|
||||
dht_with_hrac_splitter(request.body, return_remainder=True)
|
||||
# TODO: This next line is possibly the worst in the entire codebase at the moment. #172.
|
||||
# Also TODO: TTL?
|
||||
do_store = self.server.protocol.determine_legality_of_dht_key(
|
||||
signature_for_ursula, pubkey_sig_alice, tmap_message_kit,
|
||||
hrac, digest(treasure_map_id), request.body)
|
||||
if do_store:
|
||||
# TODO: Stop storing things in the protocol storage. Do this better.
|
||||
# TODO: Propagate to other nodes.
|
||||
# TODO: Stop storing things in the protocol storage. Do this better. #227
|
||||
# TODO: Propagate to other nodes. #235
|
||||
self.server.protocol.storage[digest(treasure_map_id)] = request.body
|
||||
return # TODO: Proper response here.
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue