mirror of https://github.com/nucypher/nucypher.git
Massive redlining of PolicyGroup.
parent
45ffae7ea4
commit
f0fe1012b9
|
@ -115,62 +115,6 @@ class PolicyManagerForAlice(PolicyManager):
|
|||
return policy
|
||||
|
||||
|
||||
class PolicyGroup(object):
|
||||
"""
|
||||
The terms and conditions by which Alice shares with Bob.
|
||||
"""
|
||||
|
||||
_id = None
|
||||
|
||||
def __init__(self, uri: bytes, alice: Alice, bob: Bob, policies=None) -> None:
|
||||
self.policies = policies or []
|
||||
self.alice = alice
|
||||
self.bob = bob
|
||||
self.uri = uri
|
||||
|
||||
|
||||
@staticmethod
|
||||
def hash(message):
|
||||
return keccak_digest(message)
|
||||
|
||||
# TODO: This is a stand-in; remove it.
|
||||
@property
|
||||
def pfrag(self):
|
||||
return self.policies[0].pfrag
|
||||
|
||||
def treasure_map_dht_key(self):
|
||||
"""
|
||||
We need a key that Bob can glean from knowledge he already has *and* which Ursula can verify came from us.
|
||||
Ursula will refuse to propagate this key if it she can't prove that our public key, which is included in it,
|
||||
was used to sign the payload.
|
||||
|
||||
Our public key (which everybody knows) and the hrac above.
|
||||
"""
|
||||
return self.hash(bytes(self.alice.seal) + self.hrac())
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
if not self._id:
|
||||
self._id = api.keccak_digest(bytes(self.alice.seal), api.keccak_digest(self.uri))
|
||||
return self._id
|
||||
|
||||
def publish_treasure_map(self):
|
||||
encrypted_treasure_map, signature_for_bob = self.alice.encrypt_for(self.bob,
|
||||
self.treasure_map.packed_payload())
|
||||
signature_for_ursula = self.alice.seal(self.hrac()) # TODO: Great use-case for Ciphertext class
|
||||
|
||||
# In order to know this is safe to propagate, Ursula needs to see a signature, our public key,
|
||||
# and, reasons explained in treasure_map_dht_key above, the uri_hash.
|
||||
dht_value = signature_for_ursula + self.alice.seal + self.hrac() + msgpack.dumps(
|
||||
encrypted_treasure_map) # TODO: Ideally, this is a Ciphertext object instead of msgpack (see #112)
|
||||
dht_key = self.treasure_map_dht_key()
|
||||
|
||||
setter = self.alice.server.set(dht_key, b"trmap" + dht_value)
|
||||
event_loop = asyncio.get_event_loop()
|
||||
event_loop.run_until_complete(setter)
|
||||
return encrypted_treasure_map, dht_value, signature_for_bob, signature_for_ursula
|
||||
|
||||
|
||||
class Policy(object):
|
||||
"""
|
||||
An individual agreement between Alice and Ursula. Together, all of the Policies by which
|
||||
|
|
Loading…
Reference in New Issue