Example #1
0
def alice(ursulas, mock_policy_agent, nucypher_test_config):
    ALICE = Alice(network_middleware=MockNetworkyStuff(ursulas), policy_agent=mock_policy_agent, config=nucypher_test_config)
    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
Example #2
0
def alice(ursulas):
    alice = Alice(network_middleware=MockRestMiddleware(),
                  known_nodes=ursulas,
                  federated_only=True,
                  abort_on_learning_error=True)
    alice.recruit = lambda *args, **kwargs: [u._ether_address for u in ursulas]

    return alice
Example #3
0
    def create_policy(self, label: bytes, alice_privkey: UmbralPrivateKey,
                      bob_pubkey: UmbralPublicKey, policy_expiration, m: int,
                      n: int):
        """
        Create a Policy with Alice granting Bob access to `label` DataSource

        :param label: A label to represent the policies data
        :param alice_privkey: Alice's private key
        :param bob_pubkey: Bob's public key
        :param policy_expiration: Datetime of policy expiration duration
        :param m: Minimum number of KFrags needed to rebuild ciphertext
        :param n: Total number of rekey shares to generate

        :return: The policy granted to Bob
        """
        # This is not how this should be implemented, but I am still figuring out
        # the keying material and why it is randomly generated when a character is
        # initialized, instead of being derived from the keys like the other powers
        # or explained how it should be stored.
        d = DelegatingPower()
        d.umbral_keying_material = UmbralKeyingMaterial.from_bytes(
            alice_privkey.to_bytes() + alice_privkey.get_pubkey().to_bytes())

        # Initialize Alice
        ALICE = Alice(
            crypto_power_ups=[
                SigningPower(keypair=SigningKeypair(alice_privkey)),
                EncryptingPower(keypair=EncryptingKeypair(alice_privkey)),
                # DelegatingPower
                d
            ],
            network_middleware=RestMiddleware(),
            known_nodes=(self.ursula, ),
            federated_only=True,
            always_be_learning=True)

        # Initialize Bob
        BOB = Bob(crypto_power_ups=[
            SigningPower(pubkey=bob_pubkey),
            EncryptingPower(pubkey=bob_pubkey)
        ],
                  known_nodes=(self.ursula, ),
                  federated_only=True,
                  always_be_learning=True)

        # Alice grants a policy for Bob
        policy = ALICE.grant(BOB,
                             label,
                             m=m,
                             n=n,
                             expiration=policy_expiration)

        return policy
Example #4
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, id, expiration_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, id=id, expiration=expiration)
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(federated_only=True, always_be_learning=False)

    # So, our story is fairly simple: an everyman meets Alice.
    somebody = Character(always_be_learning=False, federated_only=True)

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

    # Our everyman can verify it.
    cleartext = somebody.verify_from(alice, message, signature, decrypt=False)
    assert cleartext is constants.NO_DECRYPTION_PERFORMED
Example #6
0
def blockchain_alice(mining_ursulas, three_agents):
    token_agent, miner_agent, policy_agent = three_agents
    etherbase, alice_address, bob_address, *everyone_else = token_agent.blockchain.interface.w3.eth.accounts

    alice = Alice(network_middleware=MockRestMiddleware(),
                  policy_agent=policy_agent,
                  known_nodes=mining_ursulas,
                  abort_on_learning_error=True,
                  checksum_address=alice_address)
    # alice.recruit = lambda *args, **kwargs: [u._ether_address for u in ursulas]

    return alice
def test_anybody_can_verify(nucypher_test_config, mock_policy_agent):
    """
    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(config=nucypher_test_config, policy_agent=mock_policy_agent)

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

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

    # Our everyman can verify it.
    verification, cleartext = somebody.verify_from(alice,
                                                   message,
                                                   signature,
                                                   decrypt=False)
    assert verification is True
    assert cleartext is constants.NO_DECRYPTION_PERFORMED
Example #8
0
# This is already running in another process.


##############################################
# This is already running in another process.
##############################################

BLOCKCHAIN = Blockchain.connect()

URSULA = Ursula.from_config()

#########
# Alice #
#########

ALICE = Alice.from_config()

# Here are our Policy details.
policy_end_datetime = maya.now() + datetime.timedelta(days=201)
m = 2
n = 3
label = b"secret/files/and/stuff"

# Alice grants to Bob.
BOB = Bob.from_config()

ALICE.start_learning_loop(now=True)
policy = ALICE.grant(BOB, label, m=m, n=n,
                     expiration=policy_end_datetime)

# Alice puts her public key somewhere for Bob to find later...
Example #9
0
with open("examples-runtime-cruft/node-metadata-{}".format(teacher_rest_port),
          "r") as f:
    f.seek(0)
    teacher_bytes = binascii.unhexlify(f.read())
URSULA = Ursula.from_bytes(teacher_bytes, federated_only=True)
print("Will learn from {}".format(URSULA))

# network_middleware = SandboxRestMiddleware([URSULA])

#########
# Alice #
#########

ALICE = Alice(
    network_middleware=RestMiddleware(),
    known_nodes=(URSULA, ),  # in lieu of seed nodes
    federated_only=True,
    always_be_learning=True)  # TODO: 289

# Here are our Policy details.
policy_end_datetime = maya.now() + datetime.timedelta(days=5)
m = 2
n = 3
label = b"secret/files/and/stuff"

# Alice grants to Bob.
BOB = Bob(known_nodes=(URSULA, ), federated_only=True, always_be_learning=True)
ALICE.start_learning_loop(now=True)
policy = ALICE.grant(BOB, label, m=m, n=n, expiration=policy_end_datetime)

# Alice puts her public key somewhere for Bob to find later...
Example #10
0
def get_alice():
    return  Alice(network_middleware=RestMiddleware(),
          known_nodes=(get_seed(),),  # in lieu of seed nodes
          federated_only=True,
          always_be_learning=True)  # TODO: 289
Example #11
0
from examples.sandbox_resources import SandboxNetworkyStuff
from nucypher.characters import Alice, Bob, Ursula
from nucypher.data_sources import DataSource
from nucypher.network.node import NetworkyStuff
import maya

# This is already running in another process.
URSULA = Ursula.from_rest_url(NetworkyStuff(), address="localhost", port=3601)
network_middleware = SandboxNetworkyStuff([URSULA])

#########
# Alice #
#########

ALICE = Alice(network_middleware=network_middleware)

# Here are our Policy details.
policy_end_datetime = maya.now() + datetime.timedelta(days=5)
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()
policy = ALICE.grant(BOB, label, m=m, n=n, expiration=policy_end_datetime)