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
def encode(self): payload = self.encrypt(self.payload) stream = StreamOut(self.settings) stream.u32(0x32AB9864) header_version = self.settings.get("pia.header_version") crypto_enabled = self.settings.get("pia.crypto_enabled") if header_version > 0: stream.u8((crypto_enabled << 7) | header_version) else: stream.u8(crypto_enabled + 1) stream.u8(self.connection_id) stream.u16(self.sequence_id) if header_version == 0: stream.u16(self.session_timer) stream.u16(self.rtt_timer) if self.settings.get( "pia.encryption_method") == EncryptionMethod.AES_GCM: stream.u64(self.nonce) stream.write(self.signature) stream.write(payload) stream.write(self.calc_signature(stream.get())) return stream.get()