def decryptWrapperData(self): packets = self.bufWrapper.getChunks() content = BitArray() for packet in packets: content.append('0b' + packet.content.bin) bytescontent = content.tobytes() decryptcontent = self.rc4.crypt(bytescontent) return decryptcontent
def generateReinitResponse(self, packet): p = Packet() p.session_id = self.sid self.seqnumber = 1 p.seq_number = BitArray(uint=self.seqnumber, length=Header.SEQ_NUMBER) p.ack = packet.seq_number p.data_len = BitArray(bin='0' * Header.DATA_LEN) p.flags = BitArray(bin='0' * Header.FLAGS) p.content = BitArray() return p
def generateAuthResponsePacket(self, req, sessionID): p = Packet() p.session_id = sessionID p.seq_number = BitArray(uint=1, length=Header.SEQ_NUMBER) p.ack = req.seq_number p.data_len = BitArray(bin='0' * Header.DATA_LEN) p.flags = BitArray(uint=Flags.SYNC, length=Header.FLAGS) p.optional_headers = True p.sync_type = BitArray(uint=Sync.RESPONSE_AUTH, length=OptionalHeader.SYNC_TYPE) p.content = BitArray() return p
def generateTerminatePacket(self,packt): p = Packet() p.session_id = self.sid self.seqnumber+=1 p.seq_number = BitArray(uint=self.seqnumber,length=Header.SEQ_NUMBER) p.ack = packt.seq_number p.data_len = BitArray(bin='0'*Header.DATA_LEN) p.flags = BitArray(uint=Flags.SYNC,length=Header.FLAGS) p.optional_headers = True p.sync_type = BitArray(uint=Sync.SESSION_TERMINATION,length=OptionalHeader.SYNC_TYPE) p.content = BitArray() return p
def generateReintializationPacket(self,packt): p = Packet() p.session_id = self.sid self.seqnumber+=1 p.seq_number = BitArray(uint=self.seqnumber,length=Header.SEQ_NUMBER) p.ack = packt.seq_number p.data_len = BitArray(bin='0'*Header.DATA_LEN) p.flags = BitArray(uint=Flags.SYNC,length=Header.FLAGS) p.optional_headers = True p.sync_type = BitArray(uint=Sync.REINITIALIZING,length=OptionalHeader.SYNC_TYPE) p.content = BitArray() return p
def newSessionID(self): while True: sessionID = BitArray(uint=randint(1, ((2**Header.SESSION_ID) - 1)), length=Header.SESSION_ID) if not self.sessionAlreadyExists(sessionID): break return sessionID
def buildPacket(header, body): p = Packet() p.session_id = header[0:Offsets.SESSION_ID] p.seq_number = header[Offsets.SESSION_ID:Offsets.SEQ_NUMBER] p.ack = header[Offsets.SEQ_NUMBER:Offsets.ACK] p.data_len = header[Offsets.ACK:Offsets.DATA_LEN] p.flags = header[Offsets.DATA_LEN:Offsets.FLAGS] p.sync_type = None p.content = None if p.isFlagActive(Flags.SYNC): p.sync_type = BitArray(bin=body.bin[0:Offsets.SYNC_TYPE]) p.content = BitArray(bin=body.bin[Offsets.SYNC_TYPE:]) p.optional_headers = True else: p.sync_type = BitArray() p.content = BitArray(bin=body.bin) return p
def generateInitPacket(self): p = Packet() p.session_id = BitArray(bin='0'*Header.SESSION_ID) p.seq_number = BitArray(uint=self.seqnumber,length=Header.SEQ_NUMBER) p.ack = BitArray(bin='0'*Header.ACK) p.data_len = BitArray(uint=len(self.tag),length=Header.DATA_LEN) p.flags = BitArray(uint=Flags.SYNC,length=Header.FLAGS) p.optional_headers = True p.sync_type = BitArray(uint=Sync.REQUEST_AUTH,length=OptionalHeader.SYNC_TYPE) p.content = BitArray(bytes=BitArray(hex=self.tag).bytes, length=Sizes.TAG) return p
def generateTransferPacket(self, packt, content, push): p = Packet() p.session_id = self.sid self.seqnumber += 1 p.seq_number = BitArray(uint=self.seqnumber, length=Header.SEQ_NUMBER) p.ack = packt.seq_number p.data_len = BitArray(uint=len(content), length=Header.DATA_LEN) if push: p.flags = BitArray(uint=Flags.PUSH, length=Header.FLAGS) else: p.flags = BitArray(bin='0' * Header.FLAGS) p.sync_type = BitArray() p.content = BitArray(bytes=content) return p
def fromBytesToBitArray(data): return BitArray(bytes=data)
def toBytes(self): data = BitArray() data.append('0b' + self.session_id.bin) data.append('0b' + self.seq_number.bin) data.append('0b' + self.ack.bin) data.append('0b' + self.data_len.bin) data.append('0b' + self.flags.bin) if self.optional_headers: data.append('0b' + self.sync_type.bin) if any(self.content): data.append('0b' + self.content.bin) return data.tobytes()