Moving Enrico control onto Enrico.

pull/760/head
jMyles 2019-02-13 13:51:04 -07:00
parent 0866abaaac
commit ff06ceb998
5 changed files with 42 additions and 72 deletions

View File

@ -553,14 +553,12 @@ class Bob(Character):
except (KeyError, JSONDecodeError) as e:
return Response(e, status=400)
policy_pubkey_enc = UmbralPublicKey.from_bytes(policy_pubkey_enc)
policy_encrypting_key = UmbralPublicKey.from_bytes(policy_pubkey_enc)
alice_pubkey_sig = UmbralPublicKey.from_bytes(alice_pubkey_sig)
message_kit = UmbralMessageKit.from_bytes(message_kit)
datasource_pubkey_sig = bytes(message_kit.sender_pubkey_sig)
data_source = DataSource.from_public_keys(policy_pubkey_enc,
datasource_pubkey_sig,
data_source = Enrico.from_public_keys({SigningPower: message_kit.sender_pubkey_sig},
policy_encrypting_key=policy_encrypting_key,
label=label)
drone_bob.join_policy(label=label, alice_pubkey_sig=alice_pubkey_sig)
plaintexts = drone_bob.retrieve(message_kit=message_kit,
@ -579,9 +577,6 @@ class Bob(Character):
return bob_control
class Ursula(Teacher, Character, Miner):
_alice_class = Alice
@ -1078,7 +1073,8 @@ class Enrico(Character):
self.label = label
# Encrico never uses the blockchain, hence federated_only)
super().__init__(federated_only=True, *args, **kwargs)
kwargs['federated_only'] = True
super().__init__(*args, **kwargs)
def encrypt_message(self,
message: bytes
@ -1088,3 +1084,32 @@ class Enrico(Character):
signer=self.stamp)
message_kit.policy_pubkey = self.policy_pubkey # TODO: We can probably do better here.
return message_kit, signature
def make_wsgi_app(drone_enrico):
enrico_control = Flask("enrico-control")
@enrico_control.route('/encrypt_message', methods=['POST'])
def encrypt_message():
"""
Character control endpoint for encrypting data for a policy and
receiving the messagekit (and signature) to give to Bob.
"""
try:
request_data = json.loads(request.data)
message = b64decode(request_data['message'])
except (KeyError, JSONDecodeError) as e:
return Response(str(e), status=400)
message_kit, signature = drone_enrico.encrypt_message(message)
response_data = {
'result': {
'message_kit': b64encode(message_kit.to_bytes()).decode(),
'signature': b64encode(bytes(signature)).decode(),
}
}
return Response(json.dumps(response_data), status=200)
return enrico_control

View File

@ -1,9 +0,0 @@
import json
import maya
from base64 import b64encode, b64decode
from json.decoder import JSONDecodeError
from nucypher.characters.lawful import Alice, Bob, Ursula
from nucypher.crypto.powers import DecryptingPower, SigningPower

View File

@ -1,11 +0,0 @@
import json
from base64 import b64encode, b64decode
from flask import Flask, request, Response
from json.decoder import JSONDecodeError
from umbral.keys import UmbralPublicKey
from nucypher.characters.lawful import Bob, Ursula
from nucypher.crypto.kits import UmbralMessageKit
from nucypher.characters.lawful import Enrico

View File

@ -1,37 +0,0 @@
import json
from base64 import b64encode, b64decode
from flask import Flask, request, Response
from json.decoder import JSONDecodeError
from nucypher.characters.lawful import Enrico
def make_enrico_control(drone_enrico: Enrico):
enrico_control = Flask("enrico-control")
@enrico_control.route('/encrypt_message', methods=['POST'])
def encrypt_message():
"""
Character control endpoint for encrypting data for a policy and
receiving the messagekit (and signature) to give to Bob.
"""
try:
request_data = json.loads(request.data)
message = b64decode(request_data['message'])
except (KeyError, JSONDecodeError) as e:
return Response(str(e), status=400)
message_kit, signature = drone_enrico.encrypt_message(message)
response_data = {
'result': {
'message_kit': b64encode(message_kit.to_bytes()).decode(),
'signature': b64encode(bytes(signature)).decode(),
}
}
return Response(json.dumps(response_data), status=200)
return enrico_control

View File

@ -29,6 +29,7 @@ from nucypher.blockchain.eth.deployers import PolicyManagerDeployer, NucypherTok
from nucypher.blockchain.eth.interfaces import BlockchainDeployerInterface
from nucypher.blockchain.eth.registry import InMemoryEthereumContractRegistry
from nucypher.blockchain.eth.sol.compile import SolidityCompiler
from nucypher.characters.lawful import Bob, Enrico
from nucypher.config.characters import UrsulaConfiguration, AliceConfiguration, BobConfiguration
from nucypher.config.constants import BASE_DIR
from nucypher.config.node import NodeConfiguration
@ -257,11 +258,11 @@ def enacted_blockchain_policy(idle_blockchain_policy, blockchain_ursulas):
@pytest.fixture(scope="module")
def capsule_side_channel(enacted_federated_policy):
data_source = Enrico(policy_encrypting_key=enacted_federated_policy.public_key,
enrico = Enrico(policy_encrypting_key=enacted_federated_policy.public_key,
label=enacted_federated_policy.label
)
message_kit, _signature = data_source.encrypt_message(b"Welcome to the flippering.")
return message_kit, data_source
message_kit, _signature = enrico.encrypt_message(b"Welcome to the flippering.")
return message_kit, enrico
#
@ -331,7 +332,7 @@ def alice_control(federated_alice, federated_ursulas):
@pytest.fixture(scope='module')
def bob_control(federated_bob, federated_ursulas):
teacher_node = list(federated_ursulas)[0]
bob_control = Bob.make_wsgi_app(federated_bob, teacher_node)
bob_control = federated_bob.make_wsgi_app(teacher_node)
bob_control.config['DEBUG'] = True
bob_control.config['TESTING'] = True
yield bob_control.test_client()
@ -340,7 +341,8 @@ def bob_control(federated_bob, federated_ursulas):
@pytest.fixture(scope='module')
def enrico_control(capsule_side_channel):
_, data_source = capsule_side_channel
enrico_control = make_enrico_control(data_source)
message_kit, enrico = capsule_side_channel
enrico_control = enrico.make_wsgi_app()
enrico_control.config['DEBUG'] = True
enrico_control.config['TESTING'] = True
yield enrico_control.test_client()