示例#1
0
def bob(alice, ursulas):
    BOB = Bob(alice=alice)
    BOB.attach_server()
    BOB.server.listen(8475)
    EVENT_LOOP.run_until_complete(BOB.server.bootstrap([("127.0.0.1", URSULA_PORT)]))
    congregate(alice, BOB, *ursulas)
    return BOB
示例#2
0
 def from_rest_payload(cls, kfrag_hrac, rest_payload):
     payload_splitter = BytestringSplitter(Signature, PublicKey)
     signature, bob_pubkey_sig, (receipt_bytes,
                                 packed_pfrags) = payload_splitter(
                                     rest_payload, msgpack_remainder=True)
     pfrags = [PFrag(p) for p in msgpack.loads(packed_pfrags)]
     verified = signature.verify(receipt_bytes, bob_pubkey_sig)
     if not verified:
         raise ValueError("This doesn't appear to be from Bob.")
     bob = Bob.from_pubkey_sig_bytes(bob_pubkey_sig)
     return cls(bob, kfrag_hrac, pfrags, receipt_bytes, signature)
示例#3
0
 def from_rest_payload(cls, kfrag_hrac, rest_payload):
     payload_splitter = BytestringSplitter(Signature) + key_splitter
     signature, bob_pubkey_sig, (receipt_bytes,
                                 packed_capsules) = payload_splitter(
                                     rest_payload, msgpack_remainder=True)
     capsules = [
         Capsule.from_bytes(p) for p in msgpack.loads(packed_capsules)
     ]
     verified = signature.verify(receipt_bytes, bob_pubkey_sig)
     if not verified:
         raise ValueError("This doesn't appear to be from Bob.")
     bob = Bob.from_public_keys({SigningPower: bob_pubkey_sig})
     return cls(bob, kfrag_hrac, capsules, receipt_bytes, signature)
示例#4
0
def bob(alice, ursulas):
    BOB = Bob()
    BOB.server.listen(8475)
    EVENT_LOOP.run_until_complete(BOB.server.bootstrap([("127.0.0.1", URSULA_PORT)]))
    return BOB
示例#5
0
# This is an example of Alice setting a Policy on the NuCypher network.
# In this example, Alice uses n=1, which is almost always a bad idea.  Don't do it.

# WIP w/ hendrix@8227c4abcb37ee6d27528a13ec22d55ee106107f

import datetime

import requests

from nkms.characters import Alice, Bob, Ursula
from nkms.network.node import NetworkyStuff

ALICE = Alice()
BOB = Bob()
URSULA = Ursula.from_rest_url("http://localhost:3500/public_keys")

ALICE.learn_about_actor(URSULA)


class SandboxNetworkyStuff(NetworkyStuff):
    def find_ursula(self, contract=None):
        ursula = Ursula.as_discovered_on_network(dhr_port=None,
                                                 dht_interface=None,
                                                 pubkey_sig_bytes=bytes(
                                                     URSULA.stamp),
                                                 rest_address="localhost",
                                                 rest_port=3500)
        response = requests.post("http://localhost:3500/consider_contract",
                                 bytes(contract))
        response.was_accepted = True
        return ursula, response
示例#6
0
def bob(ursulas):
    BOB = Bob(network_middleware=MockNetworkyStuff(ursulas))
    return BOB
# WIP w/ hendrix@8227c4abcb37ee6d27528a13ec22d55ee106107f

import datetime
import sys

import requests

from nkms.characters import Alice, Bob, Ursula
from nkms.crypto.kits import MessageKit
from nkms.crypto.powers import SigningPower, EncryptingPower
from nkms.network.node import NetworkyStuff
from umbral import pre

ALICE = Alice()
BOB = Bob()
URSULA = Ursula.from_rest_url(address="https://localhost", port="3550")


class SandboxNetworkyStuff(NetworkyStuff):
    def find_ursula(self, contract=None):
        ursula = Ursula.as_discovered_on_network(
            dht_port=None,
            dht_interface=None,
            rest_address="https://localhost",
            rest_port=3550,
            powers_and_keys={
                SigningPower: URSULA.stamp.as_umbral_pubkey(),
                EncryptingPower: URSULA.public_key(EncryptingPower)
            })
        response = requests.post("https://localhost:3550/consider_contract",
示例#8
0
    for _counter, ursula in enumerate(URSULAS):
        EVENT_LOOP.run_until_complete(ursula.server.bootstrap([("127.0.0.1", URSULA_PORT)]))
        EVENT_LOOP.run_until_complete(ursula.server.bootstrap([("127.0.0.1", URSULA_PORT + _counter)]))
        ursula.publish_interface_information()

    return URSULAS

URSULAS = make_fake_ursulas(6)

ALICE = Alice()
ALICE.attach_server()
ALICE.server.listen(8471)
EVENT_LOOP.run_until_complete(ALICE.server.bootstrap([("127.0.0.1", URSULA_PORT)]))

BOB = Bob(alice=ALICE)
BOB.attach_server()
BOB.server.listen(8475)
EVENT_LOOP.run_until_complete(BOB.server.bootstrap([("127.0.0.1", URSULA_PORT)]))


community_meeting(ALICE, BOB, URSULAS[0])


def test_alice_finds_ursula():
    ursula_index = 1
    all_ursulas = list_all_ursulas()
    getter = ALICE.server.get(all_ursulas[ursula_index])
    loop = asyncio.get_event_loop()
    interface_bytes = loop.run_until_complete(getter)
    port, interface = msgpack.loads(interface_bytes)