def should_handle_ClientData(self): if not self.buffer_in: self.vprint("Client idle time maxed out.") raise self.CLOSE_NOTIFY() p = self.buffer_in[0] self.buffer_in = self.buffer_in[1:] recv_data = b"" if isinstance(p, TLSApplicationData): print("> Received: %r" % p.data) recv_data = p.data lines = recv_data.split(b"\n") stop = False for l in lines: if l.startswith(b"stop_server"): stop = True break if stop: raise self.CLOSE_NOTIFY_FINAL() elif isinstance(p, TLSAlert): print("> Received: %r" % p) raise self.CLOSE_NOTIFY() else: print("> Received: %r" % p) if recv_data.startswith(b"GET / HTTP/1.1"): p = TLSApplicationData(data=self.http_sessioninfo()) if self.is_echo_server or recv_data.startswith(b"GET / HTTP/1.1"): self.add_record() self.add_msg(p) raise self.ADDED_SERVERDATA() raise self.HANDLED_CLIENTDATA()
def add_ClientData(self): r""" The user may type in: GET / HTTP/1.1\r\nHost: testserver.com\r\n\r\n Special characters are handled so that it becomes a valid HTTP request. """ if not self.data_to_send: data = six.moves.input().replace('\\r', '\r').replace( '\\n', '\n').encode() # noqa: E501 else: data = self.data_to_send.pop() if data == b"quit": return # Command to skip sending elif data == b"wait": raise self.WAITING_SERVERDATA() # Command to perform a key_update (for a TLS 1.3 session) elif data == b"key_update": if self.cur_session.tls_version >= 0x0304: self.add_record() self.add_msg(TLS13KeyUpdate(request_update="update_requested")) raise self.ADDED_CLIENTDATA() if self.linebreak: data += b"\n" self.add_record() self.add_msg(TLSApplicationData(data=data)) raise self.ADDED_CLIENTDATA()
def add_ClientData(self): """ The user may type in: GET / HTTP/1.1\r\nHost: testserver.com\r\n\r\n Special characters are handled so that it becomes a valid HTTP request. """ if not self.data_to_send: data = six.moves.input().replace('\\r', '\r').replace('\\n', '\n').encode() # noqa: E501 else: data = self.data_to_send.pop() if data == b"quit": return if self.linebreak: data += b"\n" self.add_record() self.add_msg(TLSApplicationData(data=data)) raise self.ADDED_CLIENTDATA()
def add_ClientData(self): """ The user may type in: GET / HTTP/1.1\r\nHost: testserver.com\r\n\r\n Special characters are handled so that it becomes a valid HTTP request. """ if not self.data_to_send: data = raw_input() data = data.replace("\\r", "\r") data = data.replace("\\n", "\n") else: data = self.data_to_send.pop() if data == "quit": return if self.linebreak: data += "\n" self.add_record() self.add_msg(TLSApplicationData(data=data)) raise self.ADDED_CLIENTDATA()