def __init__(self, ssh_channel, sock, sockname, peername, target, info=None): SocketConnection.__init__(self, ssh_channel, sockname, peername, target, "ssh", info) self._raw_socket = sock
def main(): import time import sys assert len(sys.argv)==2, "usage: %s :DISPLAY" % sys.argv[0] display = sys.argv[1] from xpra.scripts.config import make_defaults_struct opts = make_defaults_struct() from xpra.platform.dotxpra import DotXpra target = DotXpra().socket_path(display) print("will attempt to connect to socket: %s" % target) import socket sock = socket.socket(socket.AF_UNIX) sock.connect(target) from xpra.net.bytestreams import SocketConnection conn = SocketConnection(sock, sock.getsockname(), sock.getpeername(), target, "scroll-test") print("socket connection=%s" % conn) app = ServerMessenger(conn, opts) window = ScrolledWindowExample() vscroll_events = deque(maxlen=1000) hscroll_events = deque(maxlen=1000) def vscroll(scrollbar, scrolltype, value): #print("vscroll(%s) n=%s" % ((scrollbar, scrolltype, value), len(vscroll_events))) now = time.time() needs_reset = False if len(vscroll_events)>0: #get the previous event t, _ = vscroll_events[-1] #print("last vscroll event was %sms ago" % (now-t)) if now-t<1: #last event was less than a second ago print("lowering quality to jpeg @ 1%!") app.send("command_request", "encoding", "jpeg", "strict") app.send("command_request", "quality", 1, "*") app.send("command_request", "speed", 100, "*") needs_reset = True vscroll_events.append((now, value)) if needs_reset: def may_reset_quality(*args): #if no new events since, reset quality: t, _ = vscroll_events[-1] if now==t: print("resetting quality to h264") app.send("command_request", "encoding", "h264", "nostrict") app.send("command_request", "quality", -1, "*") #means auto app.send("command_request", "speed", -1, "*") #means auto gobject.timeout_add(1000, may_reset_quality) def hscroll(scrollbar, scrolltype, value): print("hscroll(%s)" % (scrollbar, scrolltype, value)) hscroll_events.append((time.time(), value)) window.vscroll.connect("change-value", vscroll) window.hscroll.connect("change-value", hscroll) try: app.run() finally: app.cleanup()
def new_control_connection(self, sock, address): if len(self.potential_protocols) >= self.max_connections: log.error("too many connections (%s), ignoring new one", len(self.potential_protocols)) sock.close() return True try: peername = sock.getpeername() except OSError: peername = str(address) sockname = sock.getsockname() target = peername or sockname #sock.settimeout(0) log( "new_control_connection() sock=%s, sockname=%s, address=%s, peername=%s", sock, sockname, address, peername) sc = SocketConnection(sock, sockname, address, target, "unix-domain") log.info("New proxy instance control connection received:") log.info(" '%s'", sc) protocol = Protocol(self, sc, self.process_control_packet) protocol.large_packets.append(b"info-response") self.potential_protocols.append(protocol) protocol.enable_default_encoder() protocol.start() self.timeout_add(SOCKET_TIMEOUT * 1000, self.verify_connection_accepted, protocol) return True
def test_DoS(client_class_constructor, args): """ utility method for running DoS tests See: test_DoS_*_client.py """ assert len(args) == 2, "usage: test_DoS_client :DISPLAY" log.enable_debug() opts = make_defaults_struct() opts.password_file = "" opts.encoding = "rgb24" opts.jpegquality = 70 opts.quality = 70 opts.compression_level = 1 opts.encryption = "" display = sys.argv[1] target = DotXpra().socket_path(display) print("will attempt to connect to socket: %s" % target) sock = socket.socket(socket.AF_UNIX) sock.connect(target) conn = SocketConnection(sock, sock.getsockname(), sock.getpeername(), target, "test_DoS") print("socket connection=%s" % conn) app = client_class_constructor(conn, opts) try: app.run() finally: app.cleanup() print("ended") print("")
def makeSocketConnection(sock, name): try: peername = sock.getpeername() except: peername = str(sock) return SocketConnection(sock, sock.getsockname(), peername, "test-client-socket")
def _new_connection(self, listener, *args): socktype = self.socket_types.get(listener, "") sock, address = listener.accept() if len(self._potential_protocols) >= self._max_connections: log.error("too many connections (%s), ignoring new one", len(self._potential_protocols)) sock.close() return True try: peername = sock.getpeername() except: peername = str(address) sockname = sock.getsockname() target = peername or sockname sock.settimeout(self._socket_timeout) log("new_connection(%s) sock=%s, sockname=%s, address=%s, peername=%s", args, sock, sockname, address, peername) sc = SocketConnection(sock, sockname, address, target, socktype) log.info("New connection received: %s", sc) protocol = Protocol(self, sc, self.process_packet) protocol.large_packets.append("info-response") protocol.authenticator = None protocol.invalid_header = self.invalid_header protocol.receive_aliases.update(self._aliases) self._potential_protocols.append(protocol) protocol.start() self.timeout_add(SOCKET_TIMEOUT * 1000, self.verify_connection_accepted, protocol) return True
def _new_connection(self, listener, *args): if self._closing: netlog.warn("ignoring new connection during shutdown") return False socktype = self.socket_types.get(listener) assert socktype, "cannot find socket type for %s" % listener try: sock, address = listener.accept() except socket.error as e: netlog.error("Error: cannot accept new connection:") netlog.error(" %s", e) return True if len(self._potential_protocols) >= self._max_connections: netlog.error("too many connections (%s), ignoring new one", len(self._potential_protocols)) sock.close() return True try: peername = sock.getpeername() except: peername = str(address) sockname = sock.getsockname() target = peername or sockname sock.settimeout(self._socket_timeout) netlog( "new_connection(%s) sock=%s, timeout=%s, sockname=%s, address=%s, peername=%s", args, sock, self._socket_timeout, sockname, address, peername) conn = SocketConnection(sock, sockname, address, target, socktype) netlog("socket connection: %s", conn) frominfo = "" if peername: frominfo = " from %s" % pretty_socket(peername) elif socktype == "unix-domain": frominfo = " on %s" % sockname return self.make_protocol(socktype, conn, frominfo)
def __init__(self): dotxpra = DotXpra() display = os.environ.get("DISPLAY") from xpra.scripts.config import make_defaults_struct opts = make_defaults_struct() target = dotxpra.socket_path(display) log.info("attempting to connect to socket: %s", target) sock = socket.socket(socket.AF_UNIX) sock.connect(target) conn = SocketConnection(sock, sock.getsockname(), sock.getpeername(), target, "scroll-test") log.info("successfully created our socket connection: %s", conn) self.server = ServerMessenger(conn, opts) self.vscroll_events = deque(maxlen=1000) self.hscroll_events = deque(maxlen=1000) browser = WebBrowser() #hook some events: browser.content_tabs.connect("focus-view-title-changed", self.title_changed) vscroll_listeners.append(self.vscroll) hscroll_listeners.append(self.hscroll) #the things we tune: self.quality = -1 self.speed = -1 self.encoding = None self.strict = False
def wait_for_connection(): conn, addr = sock.accept() s = SocketConnection(conn, sockpath, addr, sockpath, "unix") pc = self._init_auth("peercred", options={}, username="******", connection=s) assert not pc.requires_challenge() assert pc.get_uid()==os.getuid() verified.append(True) to_close.append(s)
def makeSocketConnection(sock, name): try: peername = sock.getpeername() except: peername = str(sock) sockname = sock.getsockname() target = peername or sockname return SocketConnection(sock, sockname, peername, target, "test-client-socket")
def _new_connection(self, listener, *args): if self._closing: netlog.warn("ignoring new connection during shutdown") return False socktype = self.socket_types.get(listener) assert socktype, "cannot find socket type for %s" % listener sock, address = listener.accept() if len(self._potential_protocols) >= self._max_connections: netlog.error("too many connections (%s), ignoring new one", len(self._potential_protocols)) sock.close() return True try: peername = sock.getpeername() except: peername = str(address) sockname = sock.getsockname() target = peername or sockname sock.settimeout(self._socket_timeout) netlog( "new_connection(%s) sock=%s, timeout=%s, sockname=%s, address=%s, peername=%s", args, sock, self._socket_timeout, sockname, address, peername) sc = SocketConnection(sock, sockname, address, target, socktype) netlog("socket connection: %s", sc) frominfo = "" if peername: frominfo = " from %s" % pretty_socket(peername) elif socktype == "unix-domain": frominfo = " on %s" % sockname netlog.info("New %s connection received%s", socktype, frominfo) protocol = Protocol(self, sc, self.process_packet) self._potential_protocols.append(protocol) protocol.large_packets.append("info-response") protocol.challenge_sent = False protocol.authenticator = None if socktype == "tcp": protocol.auth_class = self.tcp_auth_class protocol.encryption = self.tcp_encryption protocol.keyfile = self.tcp_encryption_keyfile else: protocol.auth_class = self.auth_class protocol.encryption = self.encryption protocol.keyfile = self.encryption_keyfile protocol.socket_type = socktype protocol.invalid_header = self.invalid_header protocol.receive_aliases.update(self._aliases) authlog("socktype=%s, auth class=%s, encryption=%s, keyfile=%s", socktype, protocol.auth_class, protocol.encryption, protocol.keyfile) if protocol.encryption and ENCRYPT_FIRST_PACKET: password = self.get_encryption_key(None, protocol.keyfile) protocol.set_cipher_in(protocol.encryption, DEFAULT_IV, password, DEFAULT_SALT, DEFAULT_ITERATIONS, INITIAL_PADDING) protocol.start() self.timeout_add(SOCKET_TIMEOUT * 1000, self.verify_connection_accepted, protocol) return True
def get_info(self) -> dict: i = SocketConnection.get_info(self) s = self._socket if s: i["ssh-channel"] = { "id" : s.get_id(), "name" : s.get_name(), } return i
def start_try(): sock = socket.socket(socket.AF_UNIX) sock.connect(target) conn = SocketConnection(sock, sock.getsockname(), sock.getpeername(), target, "trylogin") def stop_cb(client): try: clients.remove(client) except: pass if len(clients)<MAX_CLIENTS: start_try() def cracked_cb(password): sys.exit(0) tl = TryLogin(conn, opts, gen_password(), stop_cb, cracked_cb) clients.append(tl) tl.run()
def accept_connection(socktype, listener, timeout=None): log = get_network_logger() try: sock, address = listener.accept() except socket.error as e: log("rejecting new connection on %s", listener, exc_info=True) log.error("Error: cannot accept new connection:") log.error(" %s", e) return None #log("peercred(%s)=%s", sock, get_peercred(sock)) try: peername = sock.getpeername() except (OSError, IOError): peername = address sock.settimeout(timeout) sockname = sock.getsockname() from xpra.net.bytestreams import SocketConnection conn = SocketConnection(sock, sockname, address, peername, socktype) log("accept_connection(%s, %s, %s)=%s", listener, socktype, timeout, conn) return conn
def _new_connection(self, listener, *args): socktype = self.socket_types.get(listener) assert socktype, "cannot find socket type for %s" % listener sock, address = listener.accept() if len(self._potential_protocols) >= self._max_connections: netlog.error("too many connections (%s), ignoring new one", len(self._potential_protocols)) sock.close() return True try: peername = sock.getpeername() except: peername = str(address) sockname = sock.getsockname() target = peername or sockname sock.settimeout(self._socket_timeout) netlog( "new_connection(%s) sock=%s, timeout=%s, sockname=%s, address=%s, peername=%s", args, sock, self._socket_timeout, sockname, address, peername) sc = SocketConnection(sock, sockname, address, target, socktype) netlog("socket connection: %s", sc) frominfo = "" if peername: frominfo = " from %s" % str(peername) netlog.info("New %s connection received%s", socktype, frominfo) protocol = Protocol(self, sc, self.process_packet) self._potential_protocols.append(protocol) protocol.large_packets.append("info-response") protocol.challenge_sent = False protocol.authenticator = None if socktype == "tcp": protocol.auth_class = self.tcp_auth_class else: protocol.auth_class = self.auth_class protocol.socket_type = socktype protocol.invalid_header = self.invalid_header protocol.receive_aliases.update(self._aliases) protocol.start() self.timeout_add(SOCKET_TIMEOUT * 1000, self.verify_connection_accepted, protocol) return True
def _socket_connect(sock, endpoint, description, dtype): sock.connect(endpoint) sock.settimeout(None) return SocketConnection(sock, sock.getsockname(), sock.getpeername(), description, dtype)
def __init__(self, *args): SocketConnection.__init__(self, *args)
def __init__(self, socket, local, remote, target, info, ws_handler): SocketConnection.__init__(self, socket, local, remote, target, info) self.protocol_type = "websocket" self.ws_handler = ws_handler
def __init__(self, socket, local, remote, target, socktype, ws_handler): SocketConnection.__init__(self, socket, local, remote, target, socktype) self.protocol_type = "websocket" self.ws_handler = ws_handler self.pending_read = Queue()
def close(self): self.pending_read = Queue() SocketConnection.close(self)
def __init__(self, ssh_channel, sock, target, info={}): SocketConnection.__init__(self, ssh_channel, sock.getsockname(), sock.getpeername(), target, "ssh", info) self._raw_socket = sock
def __init__(self, socket, local, remote, target, info, ws_handler): SocketConnection.__init__(self, socket, local, remote, target, info) self.protocol_type = "websocket" self.ws_handler = ws_handler