From 187f627e363877ddbf569e1047a02a95799a3a5a Mon Sep 17 00:00:00 2001 From: tuxxy Date: Sun, 10 Feb 2019 11:31:20 -0700 Subject: [PATCH] Fill out alice_control.grant --- .../character_control/alice_control.py | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/nucypher/network/character_control/alice_control.py b/nucypher/network/character_control/alice_control.py index 751e6ee51..6049c7369 100644 --- a/nucypher/network/character_control/alice_control.py +++ b/nucypher/network/character_control/alice_control.py @@ -1,4 +1,5 @@ from flask import Flask, request, Response +import maya from nucypher.characters.lawful import Alice, Bob from nucypher.crypto.powers import DecryptingPower, SigningPower @@ -13,7 +14,8 @@ def make_alice_control(drone_alice: Alice): Character control endpoint for creating a policy and making arrangements with Ursulas. """ - # TODO: Needs input cleansing + # TODO: Needs input cleansing and validation + # TODO: Provide more informative errors try: bob_pubkey = bytes.fromhex(request.args['bob_encrypting_key']) label = bytes.fromhex(request.args['label']) @@ -24,20 +26,42 @@ def make_alice_control(drone_alice: Alice): bob = Bob.from_public_keys({DecryptingPower: bob_pubkey, SigningPower: None}, - federated_only=True) + federated_only=True) except KeyError as e: return Response(str(e), status=500) new_policy = drone_alice.create_policy(bob, label, m, n, - federated=federated_only) + federated=federated_only) # TODO: Serialize the policy return Response('Policy created!', status=200) - @alice_control.route("/grant", methods=['POST']) + @alice_control.route("/grant", methods=['PUT']) def grant(): """ Character control endpoint for policy granting. """ - pass + # TODO: Needs input cleansing and validation + # TODO: Provide more informative errors + try: + bob_pubkey = bytes.fromhex(request.args['bob_encrypting_key']) + label = bytes.fromhex(request.args['label']) + # TODO: Do we change this to something like "threshold" + m, n = int(request.args['m']), int(request.args['n']) + expiration_time = maya.MayaDT.from_iso8601( + request.args['expiration_time']) + payment_details = request.args['payment'] + federated_only = True # const for now + + bob = Bob.from_public_keys({DecryptingPower: bob_pubkey, + SigningPower: None}, + federated_only=True) + except KeyError as e: + return Response(str(e), status=500) + + new_policy = drone_alice.grant(bob, label, m=m, n=n, + expiration=expiration_time) + # TODO: Serialize the policy + import pudb; pudb.set_trace() + return Response(bytes(new_policy.treasure_map), status=200) return alice_control