Created
July 31, 2019 16:48
-
-
Save arvindkalra/92de0e36e74c81fe6204019b0d846964 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I just made a simple change in this function, which is making cache=True over here in the function defination | |
def retrieve(self, message_kit, data_source, alice_verifying_key, label, cache=True): | |
print("changed") | |
# Try our best to get an UmbralPublicKey from input | |
alice_verifying_key = UmbralPublicKey.from_bytes(bytes(alice_verifying_key)) | |
capsule = message_kit.capsule # TODO: generalize for WorkOrders with more than one capsule | |
hrac, map_id = self.construct_hrac_and_map_id(alice_verifying_key, label) | |
_unknown_ursulas, _known_ursulas, m = self.follow_treasure_map(map_id=map_id, block=True) | |
already_retrieved = len(message_kit.capsule._attached_cfrags) >= m | |
if already_retrieved: | |
if cache: | |
must_do_new_retrieval = False | |
else: | |
raise TypeError("Not using cached retrievals, but the MessageKit's capsule has attached CFrags. Not sure what to do.") | |
else: | |
must_do_new_retrieval = True | |
capsule.set_correctness_keys( | |
delegating=data_source.policy_pubkey, | |
receiving=self.public_keys(DecryptingPower), | |
verifying=alice_verifying_key) | |
cleartexts = [] | |
if must_do_new_retrieval: | |
# TODO: Consider blocking until map is done being followed. #1114 | |
work_orders = self.generate_work_orders(map_id, capsule, cache=cache) | |
the_airing_of_grievances = [] | |
# TODO: Of course, it's possible that we have cached CFrags for one of these and thus need to retrieve for one WorkOrder and not another. | |
for work_order in work_orders.values(): | |
try: | |
cfrags = self.get_reencrypted_cfrags(work_order) | |
except requests.exceptions.ConnectTimeout: | |
continue | |
except NotFound: | |
# This Ursula claims not to have a matching KFrag. Maybe this has been revoked? | |
# TODO: What's the thing to do here? Do we want to track these Ursulas in some way in case they're lying? | |
continue | |
cfrag = cfrags[0] # TODO: generalize for WorkOrders with more than one capsule/task | |
try: | |
message_kit.capsule.attach_cfrag(cfrag) | |
if len(message_kit.capsule._attached_cfrags) >= m: | |
break | |
except UmbralCorrectnessError: | |
task = work_order.tasks[0] # TODO: generalize for WorkOrders with more than one capsule/task | |
from nucypher.policy.models import IndisputableEvidence | |
evidence = IndisputableEvidence(task=task, work_order=work_order) | |
# I got a lot of problems with you people ... | |
the_airing_of_grievances.append(evidence) | |
else: | |
raise Ursula.NotEnoughUrsulas("Unable to snag m cfrags.") | |
if the_airing_of_grievances: | |
# ... and now you're gonna hear about it! | |
raise self.IncorrectCFragsReceived(the_airing_of_grievances) | |
# TODO: Find a better strategy for handling incorrect CFrags #500 | |
# - There maybe enough cfrags to still open the capsule | |
# - This line is unreachable when NotEnoughUrsulas | |
delivered_cleartext = self.verify_from(data_source, message_kit, decrypt=True) | |
cleartexts.append(delivered_cleartext) | |
return cleartexts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: Run the ursula cli using command (nucypher ursula run --dev --federated-only) | |
Step 2: Run the alice cli using command (nucypher alice run --dev --federated-onlly --teacher localhost:10151) | |
Step 3: Run the bob cli using command (nucypher bob run --dev --federated-only --teacher localhost:10151 --controller-port 4000) | |
Step 4: Make "/derive_policy_encrypting_key/songs" request on alice | |
Step 5: Run the enrico cli using command using the policy_encrypting_key received from previous request | |
(nucypher enrico run --policy-encrypting-key 033557bab67f23f5b55e4c287e600ba6231260431129f40a3c1bcf9b8371074e25 --http-port 3000) | |
Step 6: Make "/grant" request on alice | |
Step 7: Make "/encrypt_message" request on enrico | |
Step 8: Make "/retrieve" request on bob, received the correct object ie: | |
{ | |
"result": { | |
"cleartexts": [ | |
"test message hello" | |
] | |
}, | |
"version": "0.1.0-alpha.23", | |
"id": "1564590909", | |
"duration": "0:11:46" | |
} | |
Step 9: Make same request as in step 8 without changing anything, received the following error "Unable to snag m cfrags." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment