Пример #1
0
    def test_on_data_invalid_encoding(self):
        """
        When on_data receives an invalid encryption, crypto_in() should throw a CryptoException.
        """
        # Prepare crypto and settings
        tunnel_crypto = object.__new__(TunnelCrypto)
        self.tunnel_community.settings = TunnelSettings()
        # Register a valid circuit
        circuit = Circuit(42L)
        hop = Hop(tunnel_crypto.generate_key(u"curve25519"))
        hop.session_keys = tunnel_crypto.generate_session_keys("1234")
        circuit.add_hop(hop)
        self.tunnel_community.circuits[42] = circuit

        # Encode data with a truncated encrypted string (empty in this case)
        packet = TunnelConversion.encode_data(42, ("127.0.0.1", 1337),
                                              ("127.0.0.1", 1337), "")

        # Simulate on_data()
        _, encrypted = TunnelConversion.split_encrypted_packet(packet, u"data")
        self.assertRaises(CryptoException,
                          self.tunnel_community.crypto_in,
                          42,
                          encrypted,
                          is_data=True)
Пример #2
0
 def create_e2e(self, circuit, sock_addr, info_hash, public_key):
     hop = Hop(self.crypto.key_from_public_bin(public_key))
     hop.dh_secret, hop.dh_first_part = self.crypto.generate_diffie_secret()
     if self.notifier:
         self.notifier.notify(NTFY_TUNNEL, NTFY_CREATE_E2E, info_hash.encode('hex')[:6])
     self.tunnel_logger.info("Create end to end initiated here")
     cache = self.request_cache.add(E2ERequestCache(self, info_hash, circuit, hop, sock_addr))
     meta = self.get_meta_message(u'create-e2e')
     message = meta.impl(distribution=(self.global_time,), payload=(cache.number, info_hash, hop.node_id,
                                                                    hop.node_public_key, hop.dh_first_part))
     circuit.tunnel_data(sock_addr, TUNNEL_PREFIX + message.packet)
Пример #3
0
 def create_e2e(self, circuit, sock_addr, info_hash, public_key):
     hop = Hop(self.crypto.key_from_public_bin(public_key))
     hop.dh_secret, hop.dh_first_part = self.crypto.generate_diffie_secret()
     if self.notifier:
         self.notifier.notify(NTFY_TUNNEL, NTFY_CREATE_E2E, info_hash.encode('hex')[:6])
     self.tunnel_logger.info("Create end to end initiated here")
     cache = self.request_cache.add(E2ERequestCache(self, info_hash, circuit, hop, sock_addr))
     meta = self.get_meta_message(u'create-e2e')
     message = meta.impl(distribution=(self.global_time,), payload=(cache.number, info_hash, hop.node_id,
                                                                    hop.node_public_key, hop.dh_first_part))
     circuit.tunnel_data(sock_addr, TUNNEL_PREFIX + message.packet)
Пример #4
0
    def test_reconstruct_candidate_on_relay_remove(self):
        """
        Notifications of NTFY_TUNNEL NTFY_REMOVE should report candidates even though they are no longer tracked

        The notification should still have a valid Candidate object for the reference of third parties.
        For example, Dispersy might determine a Candidate is no longer needed for the TunnelCommunity, but the
        TrustChainCommunity will still be interested in the Candidate object tied to a removed circuit.
        """
        class MockNotifier(object):
            def __init__(self):
                self.candidate = None
                self.called = False

            def notify(self, subject, change_type, tunnel, candidate):
                self.called = True
                self.candidate = candidate

        # Prepare crypto
        tunnel_crypto = object.__new__(TunnelCrypto)
        # Register mock notifier
        self.tunnel_community.notifier = MockNotifier()
        # Register a valid circuit
        circuit = Circuit(42L)
        circuit.first_hop = ("127.0.0.1", 1337)
        hop = Hop(tunnel_crypto.generate_key(u"curve25519").pub())
        circuit.add_hop(hop)
        # Register the first hop with dispersy and the community
        circuit.mid = self.tunnel_community.dispersy.get_member(
            public_key=hop.node_public_key).mid.encode("HEX")
        self.tunnel_community.create_or_update_walkcandidate(
            circuit.first_hop, circuit.first_hop, circuit.first_hop, True,
            u'unknown')
        self.tunnel_community.circuits[42] = circuit
        #Register a RelayRoute
        self.tunnel_community.relay_from_to[circuit.circuit_id] = RelayRoute(
            circuit.circuit_id, circuit.first_hop, mid=circuit.mid)

        # Simulate a candidate cleanup
        self.tunnel_community.remove_candidate(circuit.first_hop)

        # Remove the circuit, causing the notification
        self.tunnel_community.remove_relay(42)

        self.assertTrue(self.tunnel_community.notifier.called)
        self.assertNotEqual(self.tunnel_community.notifier.candidate, None)
Пример #5
0
    def found_community(self, tunnel_community):
        self.tunnel_community = tunnel_community

        self.my_address = Hop(self.tunnel_community.my_member._ec.pub())
        self.my_address.address = ('127.0.0.1', "SELF")

        self.circuit_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnUpdateCircuits, self.circuit_timer)
        self.circuit_timer.Start(5000)

        if self.fullscreen:
            self.session.add_observer(
                self.OnExtended, NTFY_TUNNEL,
                [NTFY_CREATED, NTFY_EXTENDED, NTFY_BROKEN])
            self.session.add_observer(self.OnSelect, NTFY_TUNNEL,
                                      [NTFY_SELECT])
            self.session.add_observer(self.OnJoined, NTFY_TUNNEL,
                                      [NTFY_JOINED])
            self.session.add_observer(self.OnExtendedFor, NTFY_TUNNEL,
                                      [NTFY_EXTENDED_FOR])
            self.session.add_observer(self.OnIpRemoved, NTFY_TUNNEL,
                                      [NTFY_IP_REMOVED])
            self.session.add_observer(self.OnRpRemoved, NTFY_TUNNEL,
                                      [NTFY_RP_REMOVED])
            self.session.add_observer(self.OnIpRecreate, NTFY_TUNNEL,
                                      [NTFY_IP_RECREATE])
            self.session.add_observer(self.OnDhtLookup, NTFY_TUNNEL,
                                      [NTFY_DHT_LOOKUP])
            self.session.add_observer(self.OnKeyRequest, NTFY_TUNNEL,
                                      [NTFY_KEY_REQUEST])
            self.session.add_observer(self.OnKeyRespond, NTFY_TUNNEL,
                                      [NTFY_KEY_RESPOND])
            self.session.add_observer(self.OnKeyResponse, NTFY_TUNNEL,
                                      [NTFY_KEY_RESPONSE])
            self.session.add_observer(self.OnCreateE2E, NTFY_TUNNEL,
                                      [NTFY_CREATE_E2E])
            self.session.add_observer(self.OnCreatedE2E, NTFY_TUNNEL,
                                      [NTFY_ONCREATED_E2E])
            self.session.add_observer(self.OnIpCreated, NTFY_TUNNEL,
                                      [NTFY_IP_CREATED])
            self.session.add_observer(self.OnRpCreated, NTFY_TUNNEL,
                                      [NTFY_RP_CREATED])
Пример #6
0
    def test_valid_member_on_tunnel_remove(self):
        """
        Notifications of NTFY_TUNNEL NTFY_REMOVE should report candidates with valid member associations
        """
        class MockNotifier(object):
            def __init__(self):
                self.candidate = None
                self.called = False

            def notify(self, subject, change_type, tunnel, candidate):
                self.called = True
                self.candidate = candidate

        # Prepare crypto
        tunnel_crypto = object.__new__(TunnelCrypto)
        # Register mock notifier
        self.tunnel_community.notifier = MockNotifier()
        # Register a valid circuit
        circuit = Circuit(42L)
        circuit.first_hop = ("127.0.0.1", 1337)
        hop = Hop(tunnel_crypto.generate_key(u"curve25519").pub())
        circuit.add_hop(hop)
        # Register the first hop with dispersy and the community
        circuit.mid = self.tunnel_community.dispersy.get_member(
            public_key=hop.node_public_key).mid.encode("HEX")
        self.tunnel_community.create_or_update_walkcandidate(
            circuit.first_hop, circuit.first_hop, circuit.first_hop, True,
            u'unknown')
        self.tunnel_community.circuits[42] = circuit

        # Remove the circuit, causing the notification
        self.tunnel_community.remove_circuit(42)

        self.assertTrue(self.tunnel_community.notifier.called)
        self.assertNotEqual(self.tunnel_community.notifier.candidate, None)
        self.assertNotEqual(
            self.tunnel_community.notifier.candidate.get_member(), None)