예제 #1
0
    def create_circuit_hop1(self) -> int:
        """
		The function to setup circuit with the first hop in the circuit. Creates the CREATE/CREATE2 cell and sends it
		down the socket. It assumes that the open_connection was called on the first node and the socket is connected
		to the first node
		:return: Returns a status code. 0 --> Success DH Handshake and -1 --> Means error in processing the cell or the DH Handshake.
		On error it closes the socket to node 1
		"""
        # First create a CREATE2 Cell.
        x, x_bytes, gx, gx_bytes = CoreCryptoDH.generate_dh_priv_key()
        create_cell = Builder.build_create_cell(
            'TAP', x_bytes, gx_bytes, self.circ_id,
            self.node_container[1].onion_key_pub)

        # Sending a JSON String down the socket
        self.skt.client_send_data(ComplexStructEncoder.encode(create_cell))
        # self.skt.client_send_data(Serialize.obj_to_json(create_cell).encode('utf-8'))

        # Get the created cell in response and convert it to python Cell Object
        cell_bytes = self.skt.client_recv_data()
        created_cell = Parser.parse_encoded_created_cell(cell_bytes)

        self.session_key01 = Processor.process_created_cell(
            created_cell, self.circ_id, x_bytes)
        if self.session_key01 is None:
            self.skt.close()
            return -1

        return 0
예제 #2
0
	def handle_created_cell(self, cell_bytes, direction):
		created_cell = Parser.parse_encoded_created_cell(cell_bytes)

		# process created cell
		hlen, hdata = Processor.process_created_cell_for_extended(created_cell)

		# Create extended cell
		extended_cell = Builder.build_extended_cell_from_created_cell(self.circ_id, hlen, hdata)

		# send extended to conn
		self.conn.sendall(ComplexStructEncoder.encode(extended_cell))
		self.is_last_node = False
		print("Extended cell sent")