def __key_exchange(self): server_public_key_data = self.__socket.recv(BUFFER_SIZE) server_public_key = Cipher.unpack(server_public_key_data) to_send = self.__key.pack() + IN_PACK_SEPARATOR + Cipher.hash(self.__key.pack()) to_send = server_public_key.encrypt(to_send) self.__socket.send(to_send) return True
def __key_exchange(self, sock): sock.send(self.__public_key.public_key().pack()) data = sock.recv(BUFFER_SIZE) key = self.__public_key.decrypt(data) key, his_hashed_key = key.split(IN_PACK_SEPARATOR) if Cipher.hash(key) == his_hashed_key: key = Cipher.unpack(key) return key