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, start_learning_now=False) # So, our story is fairly simple: an everyman meets Alice. somebody = Character(start_learning_now=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. somebody.verify_from(alice, message, signature) # Of course, verification fails with any fake message with pytest.raises(InvalidSignature): fake = b"McLovin 892 Momona St. Honolulu, HI 96820" somebody.verify_from(alice, fake, signature) # Signature verification also works when Alice is not living with our # everyman in the same process, and he only knows her by her public key alice_pubkey_bytes = bytes(alice.stamp) hearsay_alice = Character.from_public_keys({SigningPower: alice_pubkey_bytes}) somebody.verify_from(hearsay_alice, message, signature) hearsay_alice = Character.from_public_keys(verifying_key=alice_pubkey_bytes) somebody.verify_from(hearsay_alice, message, signature) alice.disenchant()
def test_characters_use_keystore(temp_dir_path): keystore = Keystore.generate(password=INSECURE_DEVELOPMENT_PASSWORD, keystore_dir=temp_dir_path) keystore.unlock(password=INSECURE_DEVELOPMENT_PASSWORD) alice = Alice(federated_only=True, start_learning_now=False, keystore=keystore) Bob(federated_only=True, start_learning_now=False, keystore=keystore) Ursula(federated_only=True, start_learning_now=False, keystore=keystore, rest_host=LOOPBACK_ADDRESS, rest_port=12345, db_filepath=tempfile.mkdtemp(), domain=TEMPORARY_DOMAIN) alice.disenchant( ) # To stop Alice's publication threadpool. TODO: Maybe only start it at first enactment?
def test_characters_use_keyring(tmpdir): keyring = NucypherKeyring.generate(checksum_address=FEDERATED_ADDRESS, password=INSECURE_DEVELOPMENT_PASSWORD, encrypting=True, rest=False, keyring_root=tmpdir) keyring.unlock(password=INSECURE_DEVELOPMENT_PASSWORD) a = Alice(federated_only=True, start_learning_now=False, keyring=keyring) Bob(federated_only=True, start_learning_now=False, keyring=keyring) Ursula(federated_only=True, start_learning_now=False, keyring=keyring, rest_host='127.0.0.1', rest_port=12345, db_filepath=tempfile.mkdtemp()) a.disenchant( ) # To stop Alice's publication threadpool. TODO: Maybe only start it at first enactment?
# Alice grants access to Bob... policy = alice.grant( remote_bob, label, threshold=threshold, shares=shares, value=price, expiration=expiration, ) # ...and then disappears from the internet. # # Note that local characters (alice and bob), as opposed to objects representing # remote characters constructed from public data (remote_alice and remote_bob) # run node discovery in a background thread and must be stopped explicitly. alice.disenchant() del alice ######################### # Enrico, the Encryptor # ######################### # Now that Bob has access to the policy, let's show how Enrico the Encryptor # can share data with the members of this Policy and then how Bob retrieves it. with open(BOOK_PATH, 'rb') as file: finnegans_wake = file.readlines() print("\n************** Encrypt and Retrieve **************\n") for counter, plaintext in enumerate(finnegans_wake):
ALICE.start_learning_loop(now=True) ALICE.block_until_number_of_known_nodes_is( 8, timeout=30, learn_on_this_thread=True ) # In case the fleet isn't fully spun up yet, as sometimes happens on CI. policy = ALICE.grant(BOB, label, m=m, n=n, expiration=policy_end_datetime) assert policy.public_key == policy_pubkey policy.publishing_mutex.block_until_complete() # Alice puts her public key somewhere for Bob to find later... alices_pubkey_bytes_saved_for_posterity = bytes(ALICE.stamp) # ...and then disappears from the internet. ALICE.disenchant() del ALICE ##################### # some time passes. # # ... # # # # ... # # And now for Bob. # ##################### ##################### # Bob the BUIDLer ## ##################### BOB.join_policy(label, alices_pubkey_bytes_saved_for_posterity)