From d31f5938ca13818577ccf54a5f11899e88a8a080 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Wed, 7 Jul 2021 09:24:17 -0400 Subject: [PATCH] Fix imports and function calls after rebasing over latest changes (TMapConKFrags and umbral_adapter). Fix incompatible treasure map data used in tests. --- nucypher/characters/lawful.py | 3 +- nucypher/crypto/keypairs.py | 2 +- nucypher/crypto/keystore.py | 2 +- nucypher/network/treasuremap.py | 12 +- nucypher/policy/policies.py | 7 +- .../utilities/porter/control/interfaces.py | 6 +- .../specifications/fields/treasuremapid.py | 5 +- .../specifications/fields/workorder.py | 2 +- nucypher/utilities/porter/porter.py | 8 +- .../test_porter_rpc_control_blockchain.py | 12 +- .../test_porter_web_control_blockchain.py | 12 +- .../porter/test_decentralized_porter.py | 6 +- .../test_porter_rpc_control_federated.py | 69 +++++++--- .../test_porter_web_control_federated.py | 130 ++++++++++++++---- .../porter/test_federated_porter.py | 61 ++++++-- .../porter/test_porter_specifications.py | 22 +-- .../control/test_character_fields.py | 23 ++-- tests/unit/test_porter.py | 22 +-- 18 files changed, 275 insertions(+), 129 deletions(-) diff --git a/nucypher/characters/lawful.py b/nucypher/characters/lawful.py index ee6f917ae..9417801a9 100644 --- a/nucypher/characters/lawful.py +++ b/nucypher/characters/lawful.py @@ -75,8 +75,7 @@ from nucypher.config.constants import END_OF_POLICIES_PROBATIONARY_PERIOD from nucypher.config.storages import ForgetfulNodeStorage, NodeStorage from nucypher.control.controllers import WebController from nucypher.control.emitters import StdoutEmitter -from nucypher.crypto.api import encrypt_and_sign, keccak_digest -from nucypher.crypto.constants import HRAC_LENGTH, PUBLIC_KEY_LENGTH, WRIT_CHECKSUM_SIZE +from nucypher.crypto.constants import HRAC_LENGTH, WRIT_CHECKSUM_SIZE from nucypher.crypto.keypairs import HostingKeypair from nucypher.crypto.kits import UmbralMessageKit from nucypher.crypto.powers import ( diff --git a/nucypher/crypto/keypairs.py b/nucypher/crypto/keypairs.py index a8a14b7c5..c60373e40 100644 --- a/nucypher/crypto/keypairs.py +++ b/nucypher/crypto/keypairs.py @@ -25,7 +25,7 @@ from constant_sorrow import constants from cryptography.hazmat.primitives.asymmetric import ec from hendrix.deploy.tls import HendrixDeployTLS from hendrix.facilities.services import ExistingKeyTLSContextFactory -from umbral.signing import Signer +from nucypher.crypto.umbral_adapter import Signer from nucypher.config.constants import MAX_UPLOAD_CONTENT_LENGTH from nucypher.crypto.kits import MessageKit diff --git a/nucypher/crypto/keystore.py b/nucypher/crypto/keystore.py index 2dc49c138..ceae863de 100644 --- a/nucypher/crypto/keystore.py +++ b/nucypher/crypto/keystore.py @@ -31,8 +31,8 @@ import click from constant_sorrow.constants import KEYSTORE_LOCKED from mnemonic.mnemonic import Mnemonic -from nucypher.characters.control.emitters import StdoutEmitter from nucypher.config.constants import DEFAULT_CONFIG_ROOT +from nucypher.control.emitters import StdoutEmitter from nucypher.crypto.keypairs import HostingKeypair from nucypher.crypto.passwords import ( secret_box_decrypt, diff --git a/nucypher/network/treasuremap.py b/nucypher/network/treasuremap.py index 8489824fe..70a494fef 100644 --- a/nucypher/network/treasuremap.py +++ b/nucypher/network/treasuremap.py @@ -17,7 +17,7 @@ along with nucypher. If not, see . from random import shuffle import maya -from umbral.keys import UmbralPublicKey +from nucypher.crypto.umbral_adapter import PublicKey from nucypher.acumen.perception import FleetSensor from nucypher.crypto.signing import InvalidSignature @@ -27,16 +27,16 @@ from nucypher.network.nodes import Learner def get_treasure_map_from_known_ursulas(learner: Learner, map_identifier: str, - bob_encrypting_key: UmbralPublicKey, + bob_encrypting_key: PublicKey, timeout=3): """ Iterate through the nodes we know, asking for the TreasureMap. Return the first one who has it. """ if learner.federated_only: - from nucypher.policy.collections import TreasureMap as _MapClass + from nucypher.policy.maps import TreasureMap as _MapClass else: - from nucypher.policy.collections import SignedTreasureMap as _MapClass + from nucypher.policy.maps import SignedTreasureMap as _MapClass start = maya.now() @@ -79,7 +79,7 @@ def get_treasure_map_from_known_ursulas(learner: Learner, def find_matching_nodes(known_nodes: FleetSensor, - bob_encrypting_key: UmbralPublicKey, + bob_encrypting_key: PublicKey, no_less_than=7): # Somewhat arbitrary floor here. # Look for nodes whose checksum address has the second character of Bob's encrypting key in the first # few characters. @@ -95,7 +95,7 @@ def find_matching_nodes(known_nodes: FleetSensor, search_boundary = 2 target_nodes = [] - target_hex_match = bob_encrypting_key.hex()[1] + target_hex_match = bytes(bob_encrypting_key).hex()[1] while len(target_nodes) < no_less_than: search_boundary += 2 if search_boundary > 42: # We've searched the entire string and can't match any. TODO: Portable learning is a nice idea here. diff --git a/nucypher/policy/policies.py b/nucypher/policy/policies.py index 863877bb0..151b6ac5b 100644 --- a/nucypher/policy/policies.py +++ b/nucypher/policy/policies.py @@ -25,9 +25,8 @@ from bytestring_splitter import BytestringSplitter, VariableLengthBytestring from eth_typing.evm import ChecksumAddress from twisted.internet import reactor -from nucypher.blockchain.eth.agents import StakersReservoir, StakingEscrowAgent from nucypher.blockchain.eth.constants import POLICY_ID_LENGTH -from nucypher.crypto.constants import HRAC_LENGTH, PUBLIC_KEY_LENGTH +from nucypher.crypto.constants import HRAC_LENGTH from nucypher.crypto.kits import RevocationKit from nucypher.crypto.powers import TransactingPower from nucypher.crypto.splitters import key_splitter @@ -83,7 +82,7 @@ class TreasureMapPublisher: def __init__(self, treasure_map_bytes: bytes, - nodes: Sequence[Ursula], + nodes: Sequence['Ursula'], network_middleware: RestMiddleware, percent_to_complete_before_release: int = 5, threadpool_size: int = 120, @@ -92,7 +91,7 @@ class TreasureMapPublisher: self._total = len(nodes) self._block_until_this_many_are_complete = math.ceil(len(nodes) * percent_to_complete_before_release / 100) - def put_treasure_map_on_node(node: Ursula): + def put_treasure_map_on_node(node: 'Ursula'): try: response = network_middleware.put_treasure_map_on_node(node=node, map_payload=treasure_map_bytes) diff --git a/nucypher/utilities/porter/control/interfaces.py b/nucypher/utilities/porter/control/interfaces.py index 31be039bd..b1e1510e9 100644 --- a/nucypher/utilities/porter/control/interfaces.py +++ b/nucypher/utilities/porter/control/interfaces.py @@ -17,7 +17,7 @@ from typing import List, Optional from eth_typing import ChecksumAddress -from umbral.keys import UmbralPublicKey +from nucypher.crypto.umbral_adapter import PublicKey from nucypher.characters.control.specifications.fields import TreasureMap from nucypher.control.interfaces import ControlInterface, attach_schema @@ -53,7 +53,7 @@ class PorterInterface(ControlInterface): def publish_treasure_map(self, treasure_map: bytes, bob_encrypting_key: bytes) -> dict: - bob_enc_key = UmbralPublicKey.from_bytes(bob_encrypting_key) + bob_enc_key = PublicKey.from_bytes(bob_encrypting_key) self.implementer.publish_treasure_map(treasure_map_bytes=treasure_map, bob_encrypting_key=bob_enc_key) response_data = {'published': True} # always True - if publish failed, an exception is raised by implementer @@ -74,7 +74,7 @@ class PorterInterface(ControlInterface): def get_treasure_map(self, treasure_map_id: str, bob_encrypting_key: bytes) -> dict: - bob_enc_key = UmbralPublicKey.from_bytes(bob_encrypting_key) + bob_enc_key = PublicKey.from_bytes(bob_encrypting_key) treasure_map = self.implementer.get_treasure_map(map_identifier=treasure_map_id, bob_encrypting_key=bob_enc_key) response_data = {'treasure_map': treasure_map} diff --git a/nucypher/utilities/porter/control/specifications/fields/treasuremapid.py b/nucypher/utilities/porter/control/specifications/fields/treasuremapid.py index f98900fb9..39dea2204 100644 --- a/nucypher/utilities/porter/control/specifications/fields/treasuremapid.py +++ b/nucypher/utilities/porter/control/specifications/fields/treasuremapid.py @@ -19,8 +19,7 @@ from marshmallow import fields from nucypher.control.specifications.exceptions import InvalidInputData from nucypher.control.specifications.fields.base import BaseField -from nucypher.crypto.constants import HRAC_LENGTH -from nucypher.policy.collections import TreasureMap +from nucypher.crypto.constants import HRAC_LENGTH, KECCAK_DIGEST_LENGTH class TreasureMapID(BaseField, fields.String): @@ -28,5 +27,5 @@ class TreasureMapID(BaseField, fields.String): def _validate(self, value): treasure_map_id = bytes.fromhex(value) # FIXME federated has map id length 32 bytes but decentralized has length 16 bytes ... huh? - #2725 - if len(treasure_map_id) != TreasureMap.ID_LENGTH and len(treasure_map_id) != HRAC_LENGTH: + if len(treasure_map_id) != KECCAK_DIGEST_LENGTH and len(treasure_map_id) != HRAC_LENGTH: raise InvalidInputData(f"Could not convert input for {self.name} to a valid TreasureMap ID: invalid length") diff --git a/nucypher/utilities/porter/control/specifications/fields/workorder.py b/nucypher/utilities/porter/control/specifications/fields/workorder.py index d8fc4b82a..4e354da51 100644 --- a/nucypher/utilities/porter/control/specifications/fields/workorder.py +++ b/nucypher/utilities/porter/control/specifications/fields/workorder.py @@ -19,7 +19,7 @@ from base64 import b64encode, b64decode from marshmallow import fields from nucypher.control.specifications.fields import BaseField -from nucypher.policy.collections import WorkOrder as WorkOrderClass +from nucypher.policy.orders import WorkOrder as WorkOrderClass class WorkOrder(BaseField, fields.Field): diff --git a/nucypher/utilities/porter/porter.py b/nucypher/utilities/porter/porter.py index ce3ef8ee7..ff2143226 100644 --- a/nucypher/utilities/porter/porter.py +++ b/nucypher/utilities/porter/porter.py @@ -19,7 +19,7 @@ from typing import List, Optional, Sequence from constant_sorrow.constants import NO_CONTROL_PROTOCOL, NO_BLOCKCHAIN_CONNECTION from eth_typing import ChecksumAddress from flask import request, Response -from umbral.keys import UmbralPublicKey +from nucypher.crypto.umbral_adapter import PublicKey from nucypher.blockchain.eth.agents import ContractAgency, StakingEscrowAgent from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory @@ -72,7 +72,7 @@ the Pipe for nucypher network operations class UrsulaInfo: """Simple object that stores relevant Ursula information resulting from sampling.""" - def __init__(self, checksum_address: str, uri: str, encrypting_key: UmbralPublicKey): + def __init__(self, checksum_address: str, uri: str, encrypting_key: PublicKey): self.checksum_address = checksum_address self.uri = uri self.encrypting_key = encrypting_key @@ -112,13 +112,13 @@ the Pipe for nucypher network operations self.make_cli_controller() self.log.info(self.BANNER) - def get_treasure_map(self, map_identifier: str, bob_encrypting_key: UmbralPublicKey): + def get_treasure_map(self, map_identifier: str, bob_encrypting_key: PublicKey): return treasuremap.get_treasure_map_from_known_ursulas(learner=self, map_identifier=map_identifier, bob_encrypting_key=bob_encrypting_key, timeout=self.DEFAULT_EXECUTION_TIMEOUT) - def publish_treasure_map(self, treasure_map_bytes: bytes, bob_encrypting_key: UmbralPublicKey) -> None: + def publish_treasure_map(self, treasure_map_bytes: bytes, bob_encrypting_key: PublicKey) -> None: # TODO (#2516): remove hardcoding of 8 nodes self.block_until_number_of_known_nodes_is(8, timeout=self.DEFAULT_EXECUTION_TIMEOUT, learn_on_this_thread=True) target_nodes = treasuremap.find_matching_nodes(known_nodes=self.known_nodes, diff --git a/tests/acceptance/porter/control/test_porter_rpc_control_blockchain.py b/tests/acceptance/porter/control/test_porter_rpc_control_blockchain.py index 6a59d85a0..7223e1946 100644 --- a/tests/acceptance/porter/control/test_porter_rpc_control_blockchain.py +++ b/tests/acceptance/porter/control/test_porter_rpc_control_blockchain.py @@ -18,12 +18,12 @@ from base64 import b64encode import pytest -from umbral.keys import UmbralPublicKey +from nucypher.crypto.umbral_adapter import PublicKey from nucypher.crypto.constants import HRAC_LENGTH from nucypher.crypto.powers import DecryptingPower from nucypher.network.nodes import Learner -from nucypher.policy.collections import TreasureMap +from nucypher.policy.maps import TreasureMap from tests.utils.middleware import MockRestMiddleware @@ -84,13 +84,13 @@ def test_publish_and_get_treasure_map(blockchain_porter_rpc_controller, idle_blockchain_policy): # ensure that random treasure map cannot be obtained since not available with pytest.raises(TreasureMap.NowhereToBeFound): - random_bob_encrypting_key = UmbralPublicKey.from_bytes( + random_bob_encrypting_key = PublicKey.from_bytes( bytes.fromhex("026d1f4ce5b2474e0dae499d6737a8d987ed3c9ab1a55e00f57ad2d8e81fe9e9ac")) random_treasure_map_id = "93a9482bdf3b4f2e9df906a35144ca84" assert len(bytes.fromhex(random_treasure_map_id)) == HRAC_LENGTH # non-federated is 16 bytes get_treasure_map_params = { 'treasure_map_id': random_treasure_map_id, - 'bob_encrypting_key': random_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(random_bob_encrypting_key).hex() } request_data = {'method': 'get_treasure_map', 'params': get_treasure_map_params} blockchain_porter_rpc_controller.send(request_data) @@ -103,7 +103,7 @@ def test_publish_and_get_treasure_map(blockchain_porter_rpc_controller, treasure_map = enacted_policy.treasure_map publish_treasure_map_params = { 'treasure_map': b64encode(bytes(treasure_map)).decode(), - 'bob_encrypting_key': blockchain_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(blockchain_bob_encrypting_key).hex() } request_data = {'method': 'publish_treasure_map', 'params': publish_treasure_map_params} response = blockchain_porter_rpc_controller.send(request_data) @@ -114,7 +114,7 @@ def test_publish_and_get_treasure_map(blockchain_porter_rpc_controller, enacted_policy.label) get_treasure_map_params = { 'treasure_map_id': map_id, - 'bob_encrypting_key': blockchain_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(blockchain_bob_encrypting_key).hex() } request_data = {'method': 'get_treasure_map', 'params': get_treasure_map_params} response = blockchain_porter_rpc_controller.send(request_data) diff --git a/tests/acceptance/porter/control/test_porter_web_control_blockchain.py b/tests/acceptance/porter/control/test_porter_web_control_blockchain.py index 5153e1245..df23730cd 100644 --- a/tests/acceptance/porter/control/test_porter_web_control_blockchain.py +++ b/tests/acceptance/porter/control/test_porter_web_control_blockchain.py @@ -19,12 +19,12 @@ import json from base64 import b64encode import pytest -from umbral.keys import UmbralPublicKey +from nucypher.crypto.umbral_adapter import PublicKey from nucypher.crypto.constants import HRAC_LENGTH from nucypher.crypto.powers import DecryptingPower from nucypher.network.nodes import Learner -from nucypher.policy.collections import TreasureMap +from nucypher.policy.maps import TreasureMap from tests.utils.middleware import MockRestMiddleware @@ -83,13 +83,13 @@ def test_publish_and_get_treasure_map(blockchain_porter_web_controller, # ensure that random treasure map cannot be obtained since not available with pytest.raises(TreasureMap.NowhereToBeFound): - random_bob_encrypting_key = UmbralPublicKey.from_bytes( + random_bob_encrypting_key = PublicKey.from_bytes( bytes.fromhex("026d1f4ce5b2474e0dae499d6737a8d987ed3c9ab1a55e00f57ad2d8e81fe9e9ac")) random_treasure_map_id = "93a9482bdf3b4f2e9df906a35144ca84" assert len(bytes.fromhex(random_treasure_map_id)) == HRAC_LENGTH # non-federated is 16 bytes get_treasure_map_params = { 'treasure_map_id': random_treasure_map_id, - 'bob_encrypting_key': random_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(random_bob_encrypting_key).hex() } blockchain_porter_web_controller.get('/get_treasure_map', data=json.dumps(get_treasure_map_params)) @@ -102,7 +102,7 @@ def test_publish_and_get_treasure_map(blockchain_porter_web_controller, treasure_map = enacted_policy.treasure_map publish_treasure_map_params = { 'treasure_map': b64encode(bytes(treasure_map)).decode(), - 'bob_encrypting_key': blockchain_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(blockchain_bob_encrypting_key).hex() } response = blockchain_porter_web_controller.post('/publish_treasure_map', data=json.dumps(publish_treasure_map_params)) assert response.status_code == 200 @@ -114,7 +114,7 @@ def test_publish_and_get_treasure_map(blockchain_porter_web_controller, enacted_policy.label) get_treasure_map_params = { 'treasure_map_id': map_id, - 'bob_encrypting_key': blockchain_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(blockchain_bob_encrypting_key).hex() } response = blockchain_porter_web_controller.get('/get_treasure_map', data=json.dumps(get_treasure_map_params)) diff --git a/tests/acceptance/porter/test_decentralized_porter.py b/tests/acceptance/porter/test_decentralized_porter.py index 03733b2fd..ec232fa41 100644 --- a/tests/acceptance/porter/test_decentralized_porter.py +++ b/tests/acceptance/porter/test_decentralized_porter.py @@ -16,11 +16,11 @@ """ import pytest -from umbral.keys import UmbralPublicKey +from nucypher.crypto.umbral_adapter import PublicKey from nucypher.crypto.constants import HRAC_LENGTH from nucypher.crypto.powers import DecryptingPower -from nucypher.policy.collections import TreasureMap +from nucypher.policy.maps import TreasureMap from tests.utils.middleware import MockRestMiddleware @@ -78,7 +78,7 @@ def test_publish_and_get_treasure_map(blockchain_porter, idle_blockchain_policy): # ensure that random treasure map cannot be obtained since not available with pytest.raises(TreasureMap.NowhereToBeFound): - random_bob_encrypting_key = UmbralPublicKey.from_bytes( + random_bob_encrypting_key = PublicKey.from_bytes( bytes.fromhex("026d1f4ce5b2474e0dae499d6737a8d987ed3c9ab1a55e00f57ad2d8e81fe9e9ac")) random_treasure_map_id = "93a9482bdf3b4f2e9df906a35144ca84" assert len(bytes.fromhex(random_treasure_map_id)) == HRAC_LENGTH # non-federated is 16 bytes diff --git a/tests/integration/porter/control/test_porter_rpc_control_federated.py b/tests/integration/porter/control/test_porter_rpc_control_federated.py index 7a6b27c8f..97d48927e 100644 --- a/tests/integration/porter/control/test_porter_rpc_control_federated.py +++ b/tests/integration/porter/control/test_porter_rpc_control_federated.py @@ -18,11 +18,11 @@ from base64 import b64encode, b64decode import pytest -from umbral.keys import UmbralPublicKey +from nucypher.crypto.umbral_adapter import PublicKey from nucypher.crypto.powers import DecryptingPower from nucypher.network.nodes import Learner -from nucypher.policy.collections import TreasureMap +from nucypher.policy.maps import TreasureMap # should always be first test due to checks on response id @@ -80,24 +80,59 @@ def test_publish_and_get_treasure_map(federated_porter_rpc_controller, federated_alice, federated_bob, enacted_federated_policy): - random_bob_encrypting_key = UmbralPublicKey.from_bytes( + random_bob_encrypting_key = PublicKey.from_bytes( bytes.fromhex("026d1f4ce5b2474e0dae499d6737a8d987ed3c9ab1a55e00f57ad2d8e81fe9e9ac")) - random_treasure_map_id = "f6ec73c93084ce91d5542a4ba6070071f5565112fe19b26ae9c960f9d658903a" # federated is 32 bytes - random_treasure_map = b64decode("Qld7S8sbKFCv2B8KxfJo4oxiTOjZ4VPyqTK5K1xK6DND6TbLg2hvlGaMV69aiiC5QfadB82w/5q1" - "Sw+SNFHN2esWgAbs38QuUVUGCzDoWzQAAAGIAuhw12ZiPMNV8LaeWV8uUN+au2HGOjWilqtKsaP9f" - "mnLAzFiTUAu9/VCxOLOQE88BPoWk1H7OxRLDEhnBVYyflpifKbOYItwLLTtWYVFRY90LtNSAzS8d3v" - "NH4c3SHSZwYsCKY+5LvJ68GD0CqhydSxCcGckh0unttHrYGSOQsURUI4AAAEBsSMlukjA1WyYA+Fouq" - "kuRtk8bVHcYLqRUkK2n6dShEUGMuY1SzcAbBINvJYmQp+hhzK5m47AzCl463emXepYZQC/evytktG7y" - "Xxd3k8Ak+Qr7T4+G2VgJl4YrafTpIT6wowd+8u/SMSrrf/M41OhtLeBC4uDKjO3rYBQfVLTpEAgiX/9" - "jxB80RtNMeCwgcieviAR5tlw2IlxVTEhxXbFeopcOZmfEuhVWqgBUfIakqsNCXkkubV0XS2l5G1vtTM8" - "oNML0rP8PyKd4+0M5N6P/EQqFkHH93LCDD0IQBq9usm3MoJp0eT8N3m5gprI05drDh2xe/W6qnQfw3YXn" - "jdvf2A=") + random_treasure_map_id = "cc1c29dd2305483cc838cbcc5ecb5ef6edfd69ecadb0aa52b6b084b630989187" # federated is 32 bytes + random_treasure_map = b64decode("VE0AAZ3jsXPynMD9dm+Fjwi49bxkOzUjwsNI0Y0p8bGB9F60OXGmJqibK0Ki4FSWti2Y" + "vUDuxMBrx8BidK00ITuDVoz037tyvCyOL+5Wcy5/LRD8AAAIgQOfxCS16Gu9aw0iy/G9" + "9JUW/hfj6Mt3lM7+hIrLASpMZgJO1o5GbBumlzv0w90HAwXGNrJkhbTgUpRgO0vsGqtr" + "OtuWe0lUNvLqPwvLbq1r5FmBD6FmvlfsiKI3aoKUgChEAlXU5d/KqJjvMHIih/yQNpZv" + "5RFBK52YiOEAb8EO4FqyAAAH+tzB7Fk7m8iVP/UILgco37l8EF2edLJyZloxggpe9cN7" + "fs5hHwAxTgRBCI3fZCyKxkZxVyFlPnRuih1A6dZJLOqeQGtDCsPDA/3wi1ND1swM31ti" + "2PopqoLTmhqWJvu+dqTqeqOAMXehbx/e5gpYEeyIFbt5dQyp7MLGHlGzvvbhh7SLqDN7" + "vGY4l9lnwNDfyVMZ2t0Q43oKYvv9YTSDkxJqeooTT21vcpLB3DMcjs2Geq3Zapcn2bfp" + "QoRh0ZyAjKTR650PDOA2DgwkuWfkTWJk8E9a1EVnV5zeWNQB3n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tunRD6uCibBVTtqZY5oTN8IUyTYyGV+K7w5jpm1ceUm" + "0kSeqivSArWInnpk7S098lz8DtFsXxJwhsKUXyOjWXAyYOTzIuB8HxvQ92KyPKrD927iZL" + "5q8DYgC8q5fozFbWFJ6Do+6STVtqYtngNCizrIoBg2/OMx0pUUGkH+S9b7wfordn+czd6s" + "t8NoCij4F3nHx8dvA2ZKEoC5YlrEsJBjdKHZwRPtQ6H8bDj2C20K48t4jQ26GPqithBkYE" + "ogU/kE00AE+L0JJQAkgWotyF28V/+awu+rpeuJ4eKzUS0ig0YiLYSfSAsqCARahH25QljG" + "pYabC2hGmPwkD9pGEymtCcFnf47Zhi6v7LkrbatbLk8ebIMm21a6WLy") # ensure that random treasure map cannot be obtained since not available with pytest.raises(TreasureMap.NowhereToBeFound): get_treasure_map_params = { 'treasure_map_id': random_treasure_map_id, - 'bob_encrypting_key': random_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(random_bob_encrypting_key).hex() } request_data = {'method': 'get_treasure_map', 'params': get_treasure_map_params} federated_porter_rpc_controller.send(request_data) @@ -105,7 +140,7 @@ def test_publish_and_get_treasure_map(federated_porter_rpc_controller, # publish the random treasure map publish_treasure_map_params = { 'treasure_map': b64encode(bytes(random_treasure_map)).decode(), - 'bob_encrypting_key': random_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(random_bob_encrypting_key).hex() } request_data = {'method': 'publish_treasure_map', 'params': publish_treasure_map_params} response = federated_porter_rpc_controller.send(request_data) @@ -114,7 +149,7 @@ def test_publish_and_get_treasure_map(federated_porter_rpc_controller, # try getting the random treasure map now get_treasure_map_params = { 'treasure_map_id': random_treasure_map_id, - 'bob_encrypting_key': random_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(random_bob_encrypting_key).hex() } request_data = {'method': 'get_treasure_map', 'params': get_treasure_map_params} response = federated_porter_rpc_controller.send(request_data) @@ -126,7 +161,7 @@ def test_publish_and_get_treasure_map(federated_porter_rpc_controller, enacted_federated_policy.label) get_treasure_map_params = { 'treasure_map_id': map_id, - 'bob_encrypting_key': federated_bob.public_keys(DecryptingPower).hex() + 'bob_encrypting_key': bytes(federated_bob.public_keys(DecryptingPower)).hex() } request_data = {'method': 'get_treasure_map', 'params': get_treasure_map_params} response = federated_porter_rpc_controller.send(request_data) diff --git a/tests/integration/porter/control/test_porter_web_control_federated.py b/tests/integration/porter/control/test_porter_web_control_federated.py index 0873a31cc..43006b0ed 100644 --- a/tests/integration/porter/control/test_porter_web_control_federated.py +++ b/tests/integration/porter/control/test_porter_web_control_federated.py @@ -19,11 +19,11 @@ import json from base64 import b64decode, b64encode import pytest -from umbral.keys import UmbralPublicKey +from nucypher.crypto.umbral_adapter import PublicKey from nucypher.crypto.powers import DecryptingPower from nucypher.network.nodes import Learner -from nucypher.policy.collections import TreasureMap +from nucypher.policy.maps import TreasureMap def test_get_ursulas(federated_porter_web_controller, federated_ursulas): @@ -79,31 +79,66 @@ def test_publish_and_get_treasure_map(federated_porter_web_controller, response = federated_porter_web_controller.post('/publish_treasure_map', data=json.dumps({'bad': 'input'})) assert response.status_code == 400 - random_bob_encrypting_key = UmbralPublicKey.from_bytes( + random_bob_encrypting_key = PublicKey.from_bytes( bytes.fromhex("026d1f4ce5b2474e0dae499d6737a8d987ed3c9ab1a55e00f57ad2d8e81fe9e9ac")) - random_treasure_map_id = "f6ec73c93084ce91d5542a4ba6070071f5565112fe19b26ae9c960f9d658903a" # federated is 32 bytes - random_treasure_map = b64decode("Qld7S8sbKFCv2B8KxfJo4oxiTOjZ4VPyqTK5K1xK6DND6TbLg2hvlGaMV69aiiC5QfadB82w/5q1" - "Sw+SNFHN2esWgAbs38QuUVUGCzDoWzQAAAGIAuhw12ZiPMNV8LaeWV8uUN+au2HGOjWilqtKsaP9f" - "mnLAzFiTUAu9/VCxOLOQE88BPoWk1H7OxRLDEhnBVYyflpifKbOYItwLLTtWYVFRY90LtNSAzS8d3v" - "NH4c3SHSZwYsCKY+5LvJ68GD0CqhydSxCcGckh0unttHrYGSOQsURUI4AAAEBsSMlukjA1WyYA+Fouq" - "kuRtk8bVHcYLqRUkK2n6dShEUGMuY1SzcAbBINvJYmQp+hhzK5m47AzCl463emXepYZQC/evytktG7y" - "Xxd3k8Ak+Qr7T4+G2VgJl4YrafTpIT6wowd+8u/SMSrrf/M41OhtLeBC4uDKjO3rYBQfVLTpEAgiX/9" - "jxB80RtNMeCwgcieviAR5tlw2IlxVTEhxXbFeopcOZmfEuhVWqgBUfIakqsNCXkkubV0XS2l5G1vtTM8" - "oNML0rP8PyKd4+0M5N6P/EQqFkHH93LCDD0IQBq9usm3MoJp0eT8N3m5gprI05drDh2xe/W6qnQfw3YXn" - "jdvf2A=") + random_treasure_map_id = "cc1c29dd2305483cc838cbcc5ecb5ef6edfd69ecadb0aa52b6b084b630989187" # federated is 32 bytes + random_treasure_map = b64decode("VE0AAZ3jsXPynMD9dm+Fjwi49bxkOzUjwsNI0Y0p8bGB9F60OXGmJqibK0Ki4FSWti2Y" + "vUDuxMBrx8BidK00ITuDVoz037tyvCyOL+5Wcy5/LRD8AAAIgQOfxCS16Gu9aw0iy/G9" + "9JUW/hfj6Mt3lM7+hIrLASpMZgJO1o5GbBumlzv0w90HAwXGNrJkhbTgUpRgO0vsGqtr" + "OtuWe0lUNvLqPwvLbq1r5FmBD6FmvlfsiKI3aoKUgChEAlXU5d/KqJjvMHIih/yQNpZv" + "5RFBK52YiOEAb8EO4FqyAAAH+tzB7Fk7m8iVP/UILgco37l8EF2edLJyZloxggpe9cN7" + "fs5hHwAxTgRBCI3fZCyKxkZxVyFlPnRuih1A6dZJLOqeQGtDCsPDA/3wi1ND1swM31ti" + "2PopqoLTmhqWJvu+dqTqeqOAMXehbx/e5gpYEeyIFbt5dQyp7MLGHlGzvvbhh7SLqDN7" + "vGY4l9lnwNDfyVMZ2t0Q43oKYvv9YTSDkxJqeooTT21vcpLB3DMcjs2Geq3Zapcn2bfp" + "QoRh0ZyAjKTR650PDOA2DgwkuWfkTWJk8E9a1EVn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Vm+L+utlMFFtunRD6uCibBVTtqZY5oTN8IUyTYyGV+K7w5jpm1ceUm" + "0kSeqivSArWInnpk7S098lz8DtFsXxJwhsKUXyOjWXAyYOTzIuB8HxvQ92KyPKrD927iZL" + "5q8DYgC8q5fozFbWFJ6Do+6STVtqYtngNCizrIoBg2/OMx0pUUGkH+S9b7wfordn+czd6s" + "t8NoCij4F3nHx8dvA2ZKEoC5YlrEsJBjdKHZwRPtQ6H8bDj2C20K48t4jQ26GPqithBkYE" + "ogU/kE00AE+L0JJQAkgWotyF28V/+awu+rpeuJ4eKzUS0ig0YiLYSfSAsqCARahH25QljG" + "pYabC2hGmPwkD9pGEymtCcFnf47Zhi6v7LkrbatbLk8ebIMm21a6WLy") # ensure that random treasure map cannot be obtained since not available with pytest.raises(TreasureMap.NowhereToBeFound): get_treasure_map_params = { 'treasure_map_id': random_treasure_map_id, - 'bob_encrypting_key': random_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(random_bob_encrypting_key).hex() } federated_porter_web_controller.get('/get_treasure_map', data=json.dumps(get_treasure_map_params)) # publish the random treasure map publish_treasure_map_params = { 'treasure_map': b64encode(bytes(random_treasure_map)).decode(), - 'bob_encrypting_key': random_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(random_bob_encrypting_key).hex() } response = federated_porter_web_controller.post('/publish_treasure_map', data=json.dumps(publish_treasure_map_params)) @@ -114,7 +149,7 @@ def test_publish_and_get_treasure_map(federated_porter_web_controller, # try getting the random treasure map now get_treasure_map_params = { 'treasure_map_id': random_treasure_map_id, - 'bob_encrypting_key': random_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(random_bob_encrypting_key).hex() } response = federated_porter_web_controller.get('/get_treasure_map', data=json.dumps(get_treasure_map_params)) @@ -127,7 +162,7 @@ def test_publish_and_get_treasure_map(federated_porter_web_controller, enacted_federated_policy.label) get_treasure_map_params = { 'treasure_map_id': map_id, - 'bob_encrypting_key': federated_bob.public_keys(DecryptingPower).hex() + 'bob_encrypting_key': bytes(federated_bob.public_keys(DecryptingPower)).hex() } response = federated_porter_web_controller.get('/get_treasure_map', data=json.dumps(get_treasure_map_params)) @@ -147,23 +182,58 @@ def test_endpoints_basic_auth(federated_porter_basic_auth_web_controller): response = federated_porter_basic_auth_web_controller.get('/get_ursulas', data=json.dumps(get_ursulas_params)) assert response.status_code == 401 # user unauthorized - random_bob_encrypting_key = UmbralPublicKey.from_bytes( + random_bob_encrypting_key = PublicKey.from_bytes( bytes.fromhex("026d1f4ce5b2474e0dae499d6737a8d987ed3c9ab1a55e00f57ad2d8e81fe9e9ac")) - random_treasure_map_id = "f6ec73c93084ce91d5542a4ba6070071f5565112fe19b26ae9c960f9d658903a" # federated is 32 bytes - random_treasure_map = b64decode("Qld7S8sbKFCv2B8KxfJo4oxiTOjZ4VPyqTK5K1xK6DND6TbLg2hvlGaMV69aiiC5QfadB82w/5q1" - "Sw+SNFHN2esWgAbs38QuUVUGCzDoWzQAAAGIAuhw12ZiPMNV8LaeWV8uUN+au2HGOjWilqtKsaP9f" - "mnLAzFiTUAu9/VCxOLOQE88BPoWk1H7OxRLDEhnBVYyflpifKbOYItwLLTtWYVFRY90LtNSAzS8d3v" - "NH4c3SHSZwYsCKY+5LvJ68GD0CqhydSxCcGckh0unttHrYGSOQsURUI4AAAEBsSMlukjA1WyYA+Fouq" - "kuRtk8bVHcYLqRUkK2n6dShEUGMuY1SzcAbBINvJYmQp+hhzK5m47AzCl463emXepYZQC/evytktG7y" - "Xxd3k8Ak+Qr7T4+G2VgJl4YrafTpIT6wowd+8u/SMSrrf/M41OhtLeBC4uDKjO3rYBQfVLTpEAgiX/9" - "jxB80RtNMeCwgcieviAR5tlw2IlxVTEhxXbFeopcOZmfEuhVWqgBUfIakqsNCXkkubV0XS2l5G1vtTM8" - "oNML0rP8PyKd4+0M5N6P/EQqFkHH93LCDD0IQBq9usm3MoJp0eT8N3m5gprI05drDh2xe/W6qnQfw3YXn" - "jdvf2A=") + random_treasure_map_id = "cc1c29dd2305483cc838cbcc5ecb5ef6edfd69ecadb0aa52b6b084b630989187" # federated is 32 bytes + random_treasure_map = b64decode("VE0AAZ3jsXPynMD9dm+Fjwi49bxkOzUjwsNI0Y0p8bGB9F60OXGmJqibK0Ki4FSWti2Y" + "vUDuxMBrx8BidK00ITuDVoz037tyvCyOL+5Wcy5/LRD8AAAIgQOfxCS16Gu9aw0iy/G9" + "9JUW/hfj6Mt3lM7+hIrLASpMZgJO1o5GbBumlzv0w90HAwXGNrJkhbTgUpRgO0vsGqtr" + "OtuWe0lUNvLqPwvLbq1r5FmBD6FmvlfsiKI3aoKUgChEAlXU5d/KqJjvMHIih/yQNpZv" + "5RFBK52YiOEAb8EO4FqyAAAH+tzB7Fk7m8iVP/UILgco37l8EF2edLJyZloxggpe9cN7" + "fs5hHwAxTgRBCI3fZCyKxkZxVyFlPnRuih1A6dZJLOqeQGtDCsPDA/3wi1ND1swM31ti" + "2PopqoLTmhqWJvu+dqTqeqOAMXehbx/e5gpYEeyIFbt5dQyp7MLGHlGzvvbhh7SLqDN7" + "vGY4l9lnwNDfyVMZ2t0Q43oKYvv9YTSDkxJqeooTT21vcpLB3DMcjs2Geq3Zapcn2bfp" + "QoRh0ZyAjKTR650PDOA2DgwkuWfkTWJk8E9a1EVnV5zeWNQB3nH5jfP5Tq/tXVs/4I8A" + "nvALP74PjDYmzwTkPWsZ4sKMe/3vrvu1cZMblv/3c006nhWTqGlYKP52d8mGzgORWCqA" + "Pn+to2xEIZZETUl4uWgJfMRlih0/kq1T6aHoIyr16hQKv9uJKnIbsdBE/D4eQUEvAUk/" + "YVQhoETgznQK04vMgLHErhiT/JquA2DZNKg7/Nw8L4Z49anwoYPxqbP9djcOnxzy2Iupv" + "HZrMX5D3tZHBszSwxQ7NiZRa38Hn/ed1Jodgv7j2nhRQVc+HZSJmj522FISk3wKMgNaHq" + "RbtmNot/4bRCARaDB1spOvnxqemq+RfsmCUJcsTjyjEfwHm74UD+G4Hv/3h9DEmWPnJ23" + "5q0x2Lood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/get_treasure_map get_treasure_map_params = { 'treasure_map_id': random_treasure_map_id, - 'bob_encrypting_key': random_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(random_bob_encrypting_key).hex() } response = federated_porter_basic_auth_web_controller.get('/get_treasure_map', data=json.dumps(get_treasure_map_params)) assert response.status_code == 401 # user not authenticated @@ -171,7 +241,7 @@ def test_endpoints_basic_auth(federated_porter_basic_auth_web_controller): # /publish_treasure_map publish_treasure_map_params = { 'treasure_map': b64encode(bytes(random_treasure_map)).decode(), - 'bob_encrypting_key': random_bob_encrypting_key.hex() + 'bob_encrypting_key': bytes(random_bob_encrypting_key).hex() } response = federated_porter_basic_auth_web_controller.post('/publish_treasure_map', data=json.dumps(publish_treasure_map_params)) diff --git a/tests/integration/porter/test_federated_porter.py b/tests/integration/porter/test_federated_porter.py index 88aaaa1cd..7cb7074df 100644 --- a/tests/integration/porter/test_federated_porter.py +++ b/tests/integration/porter/test_federated_porter.py @@ -17,10 +17,10 @@ from base64 import b64decode import pytest -from umbral.keys import UmbralPublicKey +from nucypher.crypto.umbral_adapter import PublicKey from nucypher.crypto.powers import DecryptingPower -from nucypher.policy.collections import TreasureMap +from nucypher.policy.maps import TreasureMap def test_get_ursulas(federated_porter, federated_ursulas): @@ -68,18 +68,53 @@ def test_get_ursulas(federated_porter, federated_ursulas): def test_publish_and_get_treasure_map(federated_porter, federated_alice, federated_bob, enacted_federated_policy): - random_bob_encrypting_key = UmbralPublicKey.from_bytes( + random_bob_encrypting_key = PublicKey.from_bytes( bytes.fromhex("026d1f4ce5b2474e0dae499d6737a8d987ed3c9ab1a55e00f57ad2d8e81fe9e9ac")) - random_treasure_map_id = "f6ec73c93084ce91d5542a4ba6070071f5565112fe19b26ae9c960f9d658903a" # federated is 32 bytes - random_treasure_map = b64decode("Qld7S8sbKFCv2B8KxfJo4oxiTOjZ4VPyqTK5K1xK6DND6TbLg2hvlGaMV69aiiC5QfadB82w/5q1" - "Sw+SNFHN2esWgAbs38QuUVUGCzDoWzQAAAGIAuhw12ZiPMNV8LaeWV8uUN+au2HGOjWilqtKsaP9f" - "mnLAzFiTUAu9/VCxOLOQE88BPoWk1H7OxRLDEhnBVYyflpifKbOYItwLLTtWYVFRY90LtNSAzS8d3v" - "NH4c3SHSZwYsCKY+5LvJ68GD0CqhydSxCcGckh0unttHrYGSOQsURUI4AAAEBsSMlukjA1WyYA+Fouq" - "kuRtk8bVHcYLqRUkK2n6dShEUGMuY1SzcAbBINvJYmQp+hhzK5m47AzCl463emXepYZQC/evytktG7y" - "Xxd3k8Ak+Qr7T4+G2VgJl4YrafTpIT6wowd+8u/SMSrrf/M41OhtLeBC4uDKjO3rYBQfVLTpEAgiX/9" - "jxB80RtNMeCwgcieviAR5tlw2IlxVTEhxXbFeopcOZmfEuhVWqgBUfIakqsNCXkkubV0XS2l5G1vtTM8" - "oNML0rP8PyKd4+0M5N6P/EQqFkHH93LCDD0IQBq9usm3MoJp0eT8N3m5gprI05drDh2xe/W6qnQfw3YXn" - "jdvf2A=") + random_treasure_map_id = "cc1c29dd2305483cc838cbcc5ecb5ef6edfd69ecadb0aa52b6b084b630989187" # federated is 32 bytes + random_treasure_map = b64decode("VE0AAZ3jsXPynMD9dm+Fjwi49bxkOzUjwsNI0Y0p8bGB9F60OXGmJqibK0Ki4FSWti2Y" + "vUDuxMBrx8BidK00ITuDVoz037tyvCyOL+5Wcy5/LRD8AAAIgQOfxCS16Gu9aw0iy/G9" + "9JUW/hfj6Mt3lM7+hIrLASpMZgJO1o5GbBumlzv0w90HAwXGNrJkhbTgUpRgO0vsGqtr" + "OtuWe0lUNvLqPwvLbq1r5FmBD6FmvlfsiKI3aoKUgChEAlXU5d/KqJjvMHIih/yQNpZv" + "5RFBK52YiOEAb8EO4FqyAAAH+tzB7Fk7m8iVP/UILgco37l8EF2edLJyZloxggpe9cN7" + "fs5hHwAxTgRBCI3fZCyKxkZxVyFlPnRuih1A6dZJLOqeQGtDCsPDA/3wi1ND1swM31ti" + "2PopqoLTmhqWJvu+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kj7YKG+" + "NJmZsC1Glrtz6sc7xmldEWFfk+Zb2j2HKLzJ99ekqGJpcrQSJAs6nXINplVnI8psrpOG8/" + "cTIqMsliL+i9qZxUX6sl//fj2eR4nzb0W1qItXyS2UOMC1t7MgzICsfn0VWzIT0da4f6za" + "EQEBjtYWEmj7UJTlVm+L+utlMFFtunRD6uCibBVTtqZY5oTN8IUyTYyGV+K7w5jpm1ceUm" + "0kSeqivSArWInnpk7S098lz8DtFsXxJwhsKUXyOjWXAyYOTzIuB8HxvQ92KyPKrD927iZL" + "5q8DYgC8q5fozFbWFJ6Do+6STVtqYtngNCizrIoBg2/OMx0pUUGkH+S9b7wfordn+czd6s" + "t8NoCij4F3nHx8dvA2ZKEoC5YlrEsJBjdKHZwRPtQ6H8bDj2C20K48t4jQ26GPqithBkYE" + "ogU/kE00AE+L0JJQAkgWotyF28V/+awu+rpeuJ4eKzUS0ig0YiLYSfSAsqCARahH25QljG" + "pYabC2hGmPwkD9pGEymtCcFnf47Zhi6v7LkrbatbLk8ebIMm21a6WLy") # ensure that random treasure map cannot be obtained since not available with pytest.raises(TreasureMap.NowhereToBeFound): diff --git a/tests/integration/porter/test_porter_specifications.py b/tests/integration/porter/test_porter_specifications.py index 3f2f4378f..9aa166337 100644 --- a/tests/integration/porter/test_porter_specifications.py +++ b/tests/integration/porter/test_porter_specifications.py @@ -18,12 +18,13 @@ import os from base64 import b64encode import pytest -from umbral.keys import UmbralPrivateKey from nucypher.characters.control.specifications.fields import TreasureMap from nucypher.control.specifications.exceptions import InvalidArgumentCombo, InvalidInputData +from nucypher.crypto.constants import ENCRYPTED_KFRAG_PAYLOAD_LENGTH from nucypher.crypto.powers import DecryptingPower -from nucypher.policy.collections import WorkOrder as WorkOrderClass +from nucypher.crypto.umbral_adapter import SecretKey +from nucypher.policy.orders import WorkOrder as WorkOrderClass from nucypher.policy.policies import Arrangement from nucypher.utilities.porter.control.specifications.fields.ursulainfo import UrsulaInfo from nucypher.utilities.porter.control.specifications.porter_schema import ( @@ -139,7 +140,7 @@ def test_alice_get_ursulas_schema(get_random_checksum_address): ursula_info = { "checksum_address": get_random_checksum_address(), "uri": f"https://127.0.0.1:{port+i}", - "encrypting_key": UmbralPrivateKey.gen_key().pubkey + "encrypting_key": SecretKey.random().public_key() } ursulas_info.append(ursula_info) @@ -269,19 +270,24 @@ def test_bob_exec_work_order(mock_ursula_reencrypts, federated_ursulas, get_random_checksum_address, federated_bob, - federated_alice): + federated_alice, + random_policy_label): # Setup ursula = list(federated_ursulas)[0] tasks = [mock_ursula_reencrypts(ursula) for _ in range(3)] material = [(task.capsule, task.signature, task.cfrag, task.cfrag_signature) for task in tasks] capsules, signatures, cfrags, cfrag_signatures = zip(*material) - arrangement_id = os.urandom(Arrangement.ID_LENGTH) - work_order = WorkOrderClass.construct_by_bob(arrangement_id=arrangement_id, + mock_kfrag = os.urandom(ENCRYPTED_KFRAG_PAYLOAD_LENGTH) + + # Test construction of WorkOrders by Bob + work_order = WorkOrderClass.construct_by_bob(encrypted_kfrag=mock_kfrag, bob=federated_bob, - alice_verifying=federated_alice.stamp.as_umbral_pubkey(), + relayer_verifying_key=federated_alice.stamp.as_umbral_pubkey(), + alice_verifying_key=federated_alice.stamp.as_umbral_pubkey(), ursula=ursula, - capsules=capsules) + capsules=capsules, + label=random_policy_label) # Test Work Order work_order_bytes = work_order.payload() diff --git a/tests/unit/characters/control/test_character_fields.py b/tests/unit/characters/control/test_character_fields.py index 9458c68d7..39bf2dc03 100644 --- a/tests/unit/characters/control/test_character_fields.py +++ b/tests/unit/characters/control/test_character_fields.py @@ -19,8 +19,7 @@ from base64 import b64encode, b64decode import maya import pytest -from umbral.keys import UmbralPrivateKey -from umbral.signing import Signer +from nucypher.crypto.umbral_adapter import SecretKey, Signer from nucypher.crypto.kits import UmbralMessageKit as UmbralMessageKitClass @@ -97,22 +96,22 @@ def test_date_time(): def test_key(): field = Key() - umbral_pub_key = UmbralPrivateKey.gen_key().pubkey - other_umbral_pub_key = UmbralPrivateKey.gen_key().pubkey + umbral_pub_key = SecretKey.random().public_key() + other_umbral_pub_key = SecretKey.random().public_key() serialized = field._serialize(value=umbral_pub_key, attr=None, obj=None) assert serialized == bytes(umbral_pub_key).hex() assert serialized != bytes(other_umbral_pub_key).hex() deserialized = field._deserialize(value=serialized, attr=None, data=None) - assert deserialized == umbral_pub_key - assert deserialized != other_umbral_pub_key + assert deserialized == bytes(umbral_pub_key) + assert deserialized != bytes(other_umbral_pub_key) - field._validate(value=umbral_pub_key.to_bytes()) - field._validate(value=other_umbral_pub_key.to_bytes()) + field._validate(value=bytes(umbral_pub_key)) + field._validate(value=bytes(other_umbral_pub_key)) with pytest.raises(InvalidInputData): - field._validate(value=b"UmbralPublicKey") + field._validate(value=b"PublicKey") def test_umbral_message_kit(enacted_federated_policy, federated_alice): @@ -139,12 +138,12 @@ def test_umbral_message_kit(enacted_federated_policy, federated_alice): def test_umbral_signature(): - umbral_priv_key = UmbralPrivateKey.gen_key() + umbral_priv_key = SecretKey.random() signer = Signer(umbral_priv_key) message = b'this is a message' - signature = signer(message) - other_signature = signer(b'this is a different message') + signature = signer.sign(message) + other_signature = signer.sign(b'this is a different message') field = UmbralSignature() serialized = field._serialize(value=signature, attr=None, obj=None) diff --git a/tests/unit/test_porter.py b/tests/unit/test_porter.py index 7a6a47e12..85edac2f0 100644 --- a/tests/unit/test_porter.py +++ b/tests/unit/test_porter.py @@ -18,11 +18,10 @@ import os from base64 import b64encode import pytest -from bytestring_splitter import VariableLengthBytestring from nucypher.control.specifications.exceptions import InvalidInputData -from nucypher.policy.collections import WorkOrder as WorkOrderClass -from nucypher.policy.policies import Arrangement +from nucypher.crypto.constants import ENCRYPTED_KFRAG_PAYLOAD_LENGTH +from nucypher.policy.orders import WorkOrder as WorkOrderClass from nucypher.utilities.porter.control.specifications.fields import ( TreasureMapID, UrsulaChecksumAddress, @@ -79,19 +78,24 @@ def test_work_order_field(mock_ursula_reencrypts, federated_ursulas, get_random_checksum_address, federated_bob, - federated_alice): + federated_alice, + random_policy_label): # Setup ursula = list(federated_ursulas)[0] tasks = [mock_ursula_reencrypts(ursula) for _ in range(3)] material = [(task.capsule, task.signature, task.cfrag, task.cfrag_signature) for task in tasks] capsules, signatures, cfrags, cfrag_signatures = zip(*material) - arrangement_id = os.urandom(Arrangement.ID_LENGTH) - work_order = WorkOrderClass.construct_by_bob(arrangement_id=arrangement_id, + mock_kfrag = os.urandom(ENCRYPTED_KFRAG_PAYLOAD_LENGTH) + + # Test construction of WorkOrders by Bob + work_order = WorkOrderClass.construct_by_bob(encrypted_kfrag=mock_kfrag, bob=federated_bob, - alice_verifying=federated_alice.stamp.as_umbral_pubkey(), + relayer_verifying_key=federated_alice.stamp.as_umbral_pubkey(), + alice_verifying_key=federated_alice.stamp.as_umbral_pubkey(), ursula=ursula, - capsules=capsules) + capsules=capsules, + label=random_policy_label) # Test Work Order work_order_bytes = work_order.payload() @@ -108,7 +112,7 @@ def test_work_order_field(mock_ursula_reencrypts, cfrag_byte_stream = bytes() for cfrag in cfrags: reencryption_signature = ursula.stamp(bytes(cfrag)) - cfrag_byte_stream += VariableLengthBytestring(cfrag) + reencryption_signature + cfrag_byte_stream += bytes(cfrag) + bytes(reencryption_signature) field = WorkOrderResult() serialized = field._serialize(value=cfrag_byte_stream, attr=None, obj=None)