Beispiel #1
0
    def get_treasure_map_from_known_ursulas(self, networky_stuff, map_id):
        """
        Iterate through swarm, asking for the TreasureMap.
        Return the first one who has it.
        TODO: What if a node gives a bunk TreasureMap?
        """
        from nkms.network.protocols import dht_value_splitter
        for node in self.known_nodes.values():
            response = networky_stuff.get_treasure_map_from_node(node, map_id)

            if response.status_code == 200 and response.content:
                # TODO: Make this prettier
                header, _signature_for_ursula, pubkey_sig_alice, hrac, encrypted_treasure_map = \
                    dht_with_hrac_splitter(response.content, return_remainder=True)
                tmap_messaage_kit = UmbralMessageKit.from_bytes(
                    encrypted_treasure_map)
                return tmap_messaage_kit
            else:
                assert False
Beispiel #2
0
    def receive_treasure_map(self, treasure_map_id_as_hex, request: http.Request):
        # TODO: This function is the epitome of #172.
        treasure_map_id = binascii.unhexlify(treasure_map_id_as_hex)

        header, signature_for_ursula, pubkey_sig_alice, hrac, tmap_message_kit = \
            dht_with_hrac_splitter(request.body, return_remainder=True)
        # TODO: This next line is possibly the worst in the entire codebase at the moment.  #172.
        # Also TODO: TTL?
        do_store = self.server.protocol.determine_legality_of_dht_key(
                    signature_for_ursula, pubkey_sig_alice, tmap_message_kit,
                    hrac, digest(treasure_map_id), request.body)
        if do_store:
            # TODO: Stop storing things in the protocol storage.  Do this better.  #227
            # TODO: Propagate to other nodes.  #235
            self.server.protocol.storage[digest(treasure_map_id)] = request.body
            return # TODO: Proper response here.
        else:
            # TODO: Make this a proper 500 or whatever.
            assert False
Beispiel #3
0
def test_treasure_map_stored_by_ursula_is_the_correct_one_for_bob(
        alice, bob, ursulas, enacted_policy):
    """
    The TreasureMap given by Alice to Ursula is the correct one for Bob; he can decrypt and read it.
    """
    treasure_map_as_set_on_network = ursulas[0].server.storage[digest(
        enacted_policy.treasure_map_dht_key())]

    header, _signature_for_ursula, pubkey_sig_alice, hrac, encrypted_treasure_map = dht_with_hrac_splitter(
        treasure_map_as_set_on_network, return_remainder=True)

    assert header == constants.BYTESTRING_IS_TREASURE_MAP

    tmap_message_kit = UmbralMessageKit.from_bytes(encrypted_treasure_map)
    verified, treasure_map_as_decrypted_by_bob = bob.verify_from(
        alice,
        tmap_message_kit,
        decrypt=True,
    )

    assert treasure_map_as_decrypted_by_bob == enacted_policy.treasure_map.packed_payload(
    )
    assert verified is True