mirror of https://github.com/nucypher/nucypher.git
Federated demo up to date with the new stuff.
parent
cb80379ff1
commit
a9752fa755
|
@ -6,27 +6,29 @@
|
|||
import datetime
|
||||
import sys
|
||||
|
||||
import maya
|
||||
from sandbox_resources import SandboxRestMiddleware
|
||||
|
||||
from nucypher.characters import Alice, Bob, Ursula
|
||||
from nucypher.data_sources import DataSource
|
||||
import maya
|
||||
|
||||
# This is already running in another process.
|
||||
from nucypher.network.middleware import RestMiddleware
|
||||
from umbral.keys import UmbralPublicKey
|
||||
|
||||
URSULA = Ursula.from_rest_url(network_middleware=RestMiddleware(),
|
||||
host="localhost",
|
||||
port=3601)
|
||||
port=3601,
|
||||
federated_only=True)
|
||||
|
||||
network_middleware = SandboxRestMiddleware([URSULA])
|
||||
|
||||
|
||||
#########
|
||||
# Alice #
|
||||
#########
|
||||
|
||||
ALICE = Alice(network_middleware=network_middleware, federated_only=True) # TODO: 289
|
||||
ALICE = Alice(network_middleware=network_middleware,
|
||||
known_nodes=(URSULA,), # in lieu of seed nodes
|
||||
federated_only=True) # TODO: 289
|
||||
|
||||
# Here are our Policy details.
|
||||
policy_end_datetime = maya.now() + datetime.timedelta(days=5)
|
||||
|
@ -34,13 +36,8 @@ m = 1
|
|||
n = 1
|
||||
label = b"secret/files/and/stuff"
|
||||
|
||||
|
||||
# Alice gets on the network and, knowing about at least one Ursula,
|
||||
# Is able to discover all Ursulas.
|
||||
ALICE.network_bootstrap([("localhost", 3601)])
|
||||
|
||||
# Alice grants to Bob.
|
||||
BOB = Bob()
|
||||
BOB = Bob(known_nodes=(URSULA,), federated_only=True)
|
||||
policy = ALICE.grant(BOB, label, m=m, n=n,
|
||||
expiration=policy_end_datetime)
|
||||
|
||||
|
@ -90,10 +87,9 @@ for counter, plaintext in enumerate(finnegans_wake):
|
|||
print("PREs per second: {}".format(counter / seconds))
|
||||
print("********************************")
|
||||
|
||||
|
||||
################################################################################
|
||||
# ...here. OK, pay attention again.
|
||||
# Now it's time for...
|
||||
################################################################################
|
||||
# ...here. OK, pay attention again.
|
||||
# Now it's time for...
|
||||
|
||||
#####################
|
||||
# Using DataSources #
|
||||
|
@ -139,10 +135,10 @@ for counter, plaintext in enumerate(finnegans_wake):
|
|||
# Now Bob can retrieve the original message. He just needs the MessageKit
|
||||
# and the DataSource which produced it.
|
||||
alice_pubkey_restored_from_ancient_scroll = UmbralPublicKey.from_bytes(alices_pubkey_bytes_saved_for_posterity)
|
||||
delivered_cleartext = BOB.retrieve(message_kit=message_kit,
|
||||
delivered_cleartexts = BOB.retrieve(message_kit=message_kit,
|
||||
data_source=datasource_as_understood_by_bob,
|
||||
alice_pubkey_sig=alice_pubkey_restored_from_ancient_scroll)
|
||||
alice_verifying_key=alice_pubkey_restored_from_ancient_scroll)
|
||||
|
||||
# We show that indeed this is the passage originally encrypted by the DataSource.
|
||||
assert plaintext == delivered_cleartext
|
||||
print("Retrieved: {}".format(delivered_cleartext))
|
||||
assert plaintext == delivered_cleartexts[0]
|
||||
print("Retrieved: {}".format(delivered_cleartexts[0]))
|
||||
|
|
|
@ -19,14 +19,19 @@ from nucypher.crypto.api import generate_self_signed_certificate
|
|||
|
||||
DB_NAME = "non-mining-proxy-node"
|
||||
|
||||
_URSULA = Ursula(dht_port=3501, rest_port=3601, ip_address="localhost", db_name=DB_NAME, federated_only=True)
|
||||
_URSULA = Ursula(dht_port=3501,
|
||||
rest_port=3601,
|
||||
rest_host="localhost",
|
||||
dht_host="localhost",
|
||||
db_name=DB_NAME,
|
||||
federated_only=True)
|
||||
_URSULA.dht_listen()
|
||||
|
||||
CURVE = ec.SECP256R1
|
||||
cert, private_key = generate_self_signed_certificate(_URSULA.stamp.fingerprint().decode(), CURVE)
|
||||
|
||||
deployer = HendrixDeployTLS("start",
|
||||
{"wsgi":_URSULA.rest_app, "https_port": _URSULA.rest_port},
|
||||
{"wsgi":_URSULA.rest_app, "https_port": _URSULA.rest_interface.port},
|
||||
key=private_key,
|
||||
cert=X509.from_cryptography(cert),
|
||||
context_factory=ExistingKeyTLSContextFactory,
|
||||
|
|
|
@ -18,27 +18,27 @@ class RestMiddleware:
|
|||
return NotImplemented
|
||||
|
||||
def get_treasure_map_from_node(self, node, map_id):
|
||||
port = node.rest_port
|
||||
address = node.ip_address
|
||||
endpoint = "https://{}:{}/treasure_map/{}".format(address, port, map_id.hex())
|
||||
port = node.rest_interface.port
|
||||
address = node.rest_interface.host
|
||||
endpoint = "https://{}:{}/treasure_map/{}".format(address, port, map_id)
|
||||
response = requests.get(endpoint, verify=False)
|
||||
return response
|
||||
|
||||
def put_treasure_map_on_node(self, node, map_id, map_payload):
|
||||
port = node.rest_port
|
||||
address = node.ip_address
|
||||
endpoint = "https://{}:{}/treasure_map/{}".format(address, port, map_id.hex())
|
||||
port = node.rest_interface.port
|
||||
address = node.rest_interface.host
|
||||
endpoint = "https://{}:{}/treasure_map/{}".format(address, port, map_id)
|
||||
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('https://{}/kFrag/{}/reencrypt'.format(work_order.ursula.rest_url(), hrac_as_hex),
|
||||
id_as_hex = work_order.arrangement_id.hex()
|
||||
return requests.post('https://{}/kFrag/{}/reencrypt'.format(work_order.ursula.rest_url(), id_as_hex),
|
||||
payload, verify=False)
|
||||
|
||||
def ursula_from_rest_interface(self, address, port):
|
||||
return requests.get("https://{}:{}/public_keys".format(address, port), verify=False) # TODO: TLS-only.
|
||||
def node_information(self, host, port):
|
||||
return requests.get("https://{}:{}/public_information".format(host, port), verify=False) # TODO: TLS-only.
|
||||
|
||||
def get_nodes_via_rest(self, address, port, node_ids=None):
|
||||
if node_ids:
|
||||
|
|
Loading…
Reference in New Issue