diff --git a/nucypher/characters/lawful.py b/nucypher/characters/lawful.py index 03f888fdd..4af88c7be 100644 --- a/nucypher/characters/lawful.py +++ b/nucypher/characters/lawful.py @@ -228,15 +228,16 @@ class Alice(Character, PolicyAuthor): try: request_data = json.loads(request.data) - bob_pubkey = bytes.fromhex(request_data['bob_encrypting_key']) + bob_pubkey_enc = bytes.fromhex(request_data['bob_encrypting_key']) + bob_pubkey_sig = bytes.fromhex(request_data['bob_signing_key']) label = b64decode(request_data['label']) # TODO: Do we change this to something like "threshold" m, n = request_data['m'], request_data['n'] federated_only = True # const for now - bob = Bob.from_public_keys({DecryptingPower: bob_pubkey, - SigningPower: None}, - federated_only=True) + bob = Bob.from_public_keys({DecryptingPower: bob_pubkey_enc, + SigningPower: bob_pubkey_sig}, + federated_only=federated_only) except (KeyError, JSONDecodeError) as e: return Response(str(e), status=400) @@ -608,6 +609,25 @@ class Bob(Character): return Response(json.dumps(response_data), status=200) + @bob_control.route('/public_keys', methods=['GET']) + def public_keys(): + """ + Character control endpoint for getting Bob's encrypting and signing public keys + """ + + signing_public_key = drone_bob.public_keys(SigningPower) + encrypting_public_key = drone_bob.public_keys(DecryptingPower) + + response_data = { + 'result': { + 'bob_encrypting_key': encrypting_public_key.to_bytes().hex(), + 'bob_signing_key': signing_public_key.to_bytes().hex(), + }, + 'version': str(nucypher.__version__) + } + + return Response(json.dumps(response_data), status=200) + return bob_control diff --git a/tests/characters/test_character_control.py b/tests/characters/test_character_control.py index 6119366bd..0ab549f89 100644 --- a/tests/characters/test_character_control.py +++ b/tests/characters/test_character_control.py @@ -167,10 +167,22 @@ def test_character_control_lifecycle(alice_control_test_client, random_label = random_policy_label.decode() # Unicode string + bob_keys_response = bob_control_test_client.get('/public_keys') + assert bob_keys_response.status_code == 200 + + response_data = json.loads(bob_keys_response.data) + assert str(nucypher.__version__) == response_data['version'] + bob_keys = response_data['result'] + assert 'bob_encrypting_key' in bob_keys + assert 'bob_signing_key' in bob_keys + + bob_encrypting_key_hex = bob_keys['bob_encrypting_key'] + bob_signing_key_hex = bob_keys['bob_signing_key'] + # Create a policy via Alice control alice_request_data = { - 'bob_signing_key': bytes(federated_bob.stamp).hex(), - 'bob_encrypting_key': bytes(federated_bob.public_keys(DecryptingPower)).hex(), + 'bob_encrypting_key': bob_encrypting_key_hex, + 'bob_signing_key': bob_signing_key_hex, 'm': 1, 'n': 1, 'label': random_label, # 'expiration_time': (maya.now() + datetime.timedelta(days=3)).iso8601(), # TODO