Ejemplo n.º 1
0
def alice(ursulas):
    ALICE = Alice()
    ALICE.attach_server()
    ALICE.server.listen(8471)
    ALICE.__resource_id = b"some_resource_id"
    EVENT_LOOP.run_until_complete(ALICE.server.bootstrap([("127.0.0.1", u.port) for u in ursulas]))
    return ALICE
Ejemplo n.º 2
0
def test_anybody_can_verify():
    """
    In the last example, we used the lower-level Crypto API to verify the signature.

    Here, we show that anybody can do it without needing to directly access Crypto.
    """

    # Alice can sign by default, by dint of her _default_crypto_powerups.
    alice = Alice()

    # So, our story is fairly simple: an everyman meets Alice.
    somebody = Character()
    somebody.learn_about_actor(alice)

    # Alice signs a message.
    message = b"A message for all my friends who can only verify and not sign."
    signature = alice.seal(message)

    # Our everyman can verify it.
    verification, cleartext = somebody.verify_from(alice,
                                                   message,
                                                   signature,
                                                   decrypt=False)
    assert verification is True
    assert cleartext is NO_DECRYPTION_PERFORMED
Ejemplo n.º 3
0
def alice(ursulas):
    ALICE = Alice(network_middleware=MockNetworkyStuff(ursulas))
    ALICE.server.listen(8471)
    ALICE.__resource_id = b"some_resource_id"
    EVENT_LOOP.run_until_complete(
        ALICE.server.bootstrap([("127.0.0.1", u.dht_port) for u in ursulas]))
    ALICE.network_bootstrap([("127.0.0.1", u.rest_port) for u in ursulas])
    return ALICE
Ejemplo n.º 4
0
 def from_bytes(cls, contract_as_bytes):
     contract_splitter = key_splitter + BytestringSplitter(
         (bytes, KECCAK_DIGEST_LENGTH), (bytes, 26))
     alice_pubkey_sig, hrac, expiration_bytes, deposit_bytes = contract_splitter(
         contract_as_bytes, return_remainder=True)
     expiration = maya.parse(expiration_bytes.decode())
     alice = Alice.from_public_keys((SigningPower, alice_pubkey_sig))
     return cls(alice=alice, hrac=hrac, expiration=expiration)
Ejemplo n.º 5
0
 def from_bytes(cls, arrangement_as_bytes):
     # Still unclear how to arrive at the correct number of bytes to represent a deposit.  See #148.
     alice_pubkey_sig, hrac, expiration_bytes, deposit_bytes = cls.splitter(
         arrangement_as_bytes)
     expiration = maya.parse(expiration_bytes.decode())
     alice = Alice.from_public_keys({SigningPower: alice_pubkey_sig})
     return cls(alice=alice,
                hrac=hrac,
                expiration=expiration,
                deposit=int(deposit_bytes))
Ejemplo n.º 6
0
 def from_bytes(cls, arrangement_as_bytes):
     arrangement_splitter = key_splitter + BytestringSplitter(
         (bytes, KECCAK_DIGEST_LENGTH), (bytes, 27))
     alice_pubkey_sig, hrac, expiration_bytes, deposit_bytes = arrangement_splitter(
         arrangement_as_bytes, return_remainder=True)
     expiration = maya.parse(expiration_bytes.decode())
     alice = Alice.from_public_keys({SigningPower: alice_pubkey_sig})
     return cls(alice=alice,
                hrac=hrac,
                expiration=expiration,
                deposit=int(deposit_bytes))
Ejemplo n.º 7
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
# 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 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)
            })
Ejemplo n.º 9
0
def test_cannot_offer_policy_without_finding_ursula():
    networky_stuff = MockNetworkyStuff()
    policy = Policy(Alice())
    with pytest.raises(Ursula.NotFound):
        policy_offer = policy.encrypt_payload_for_ursula()
Ejemplo n.º 10
0
        _URSULA = Ursula()
        _URSULA.attach_server()
        _URSULA.listen(URSULA_PORT + _u, "127.0.0.1")

        URSULAS.append(_URSULA)

    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