Exemplo n.º 1
0
    def send_browse_request(self, search_criteria, key, challenge):
        stream = StreamOut(self.settings)
        stream.add(search_criteria)
        buffer = stream.get()

        stream = StreamOut(self.settings)
        stream.u8(0)  #Packet type
        stream.u32(len(buffer))
        stream.write(buffer)

        if self.settings.get("pia.lan_version") != 0:
            self.nonce_counter += 1

            stream.u8(self.settings.get("pia.lan_version"))
            stream.bool(self.settings.get("pia.crypto_enabled"))
            stream.u64(self.nonce_counter)
            stream.write(key)

            if self.settings.get("pia.crypto_enabled"):
                challenge = self.generate_challenge(key, challenge)
            else:
                challenge = secrets.token_bytes(16 + 256)
            stream.write(challenge)

        self.s.send(stream.get(), self.broadcast)
Exemplo n.º 2
0
	def send_session_reply(self, station, session_info):
		logger.debug("Sending session reply")
		
		stream = StreamOut(self.settings)
		stream.add(session_info)
		data = stream.get()
		
		rand_value = random.randint(0, 0xFFFFFFFF)
		
		fragments = (len(data) - 1) // 800 + 1
		for i in range(fragments):
			stream = StreamOut(self.settings)
			stream.u8(self.MESSAGE_SESSION_REPLY)
			stream.pad(11)
			stream.u32(rand_value)
			stream.u16(self.session_reply_id)
			stream.u8(i)
			stream.u8(fragments)
			
			body = data[i * 800 : (i + 1) * 800]
			stream.u32(len(body))
			stream.write(body)
			
			message = PIAMessage()
			message.protocol_id = self.get_protocol_type()
			message.payload = stream.get()
			self.transport.send(station, message)
			
		self.session_reply_id += 1
Exemplo n.º 3
0
    def send_connection_request(self, station, inverse_id=None):
        logger.debug("Sending connection request")

        is_inverse = inverse_id is not None

        local = self.session.local_station()
        local_info = local.connection_info
        target_info = station.connection_info

        stream = StreamOut(self.settings)
        stream.u8(self.MESSAGE_CONNECTION_REQUEST)
        stream.u8(station.connection_id_out_temp)
        stream.u8(self.version)
        stream.bool(is_inverse)

        if self.version >= 7:
            stream.pid(target_info.local.pid)
        if self.version >= 8:
            stream.u32(target_info.local.cid)
            if is_inverse:
                stream.u8(inverse_id)
            else:
                stream.u8(0)

        if self.version == 8:
            stream.add(local_info)
        else:
            stream.add(local_info.local)

        message = PIAMessage()
        message.protocol_id = self.get_protocol_type()
        message.payload = stream.get()

        self.resender.send(station, message)
Exemplo n.º 4
0
 def encode(self, stream):
     if stream.settings.get("pia.version") < 51000:
         stream.add(self.connection_info)
     else:
         substream = StreamOut(stream.settings)
         substream.add(self.connection_info.local)
         substream.pad(0x3E - substream.size())
         stream.write(substream.get())
     stream.u8(self.index)
     stream.align(4)
Exemplo n.º 5
0
    def generate_browse_reply(self, challenge):
        stream = StreamOut(self.settings)
        stream.add(self.session_info)
        buffer = stream.get()

        stream = StreamOut(self.settings)
        stream.u8(1)  #Packet type
        stream.u32(len(buffer))
        stream.write(buffer)

        if self.settings.get("pia.lan_version") != 0:
            stream.u8(self.settings.get("pia.lan_version"))
            stream.bool(self.settings.get("pia.crypto_enabled"))
            stream.write(challenge)

        return stream.get()
Exemplo n.º 6
0
    def send_join_request(self, station):
        logger.debug("Sending join request")

        local_station = self.session.local_station()
        local_address = local_station.connection_info.local.local

        stream = StreamOut(self.settings)
        stream.u8(self.MESSAGE_JOIN_REQUEST)
        stream.u8(local_station.index)

        if self.settings.get("pia.version") >= 51100:
            stream.pad(2)
            stream.add(local_address)

        message = PIAMessage()
        message.protocol_id = self.get_protocol_type()
        message.protocol_port = self.PORT_UNRELIABLE
        message.payload = stream.get()

        self.resender.send(station, message)
Exemplo n.º 7
0
	def send_host_reply(self, station, session_info):
		logger.debug("Sending host reply")
		
		stream = StreamOut(self.settings)
		stream.u8(self.MESSAGE_HOST_REPLY)
		stream.pad(11)
		stream.u32(session_info.session_id)
		
		host = self.session.host_station()
		if self.settings.get("pia.version") < 51000:
			stream.add(host.connection_info)
		else:
			stream.add(host.connection_info.local)
		
		message = PIAMessage()
		message.protocol_id = self.get_protocol_type()
		message.payload = stream.get()
		
		for i in range(3):
			self.transport.send(station, message)