Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, sock):
SocketStream.__init__(self)
self.sock = sock
self.tun = None
if keyfile is not None:
ssl_kwargs["keyfile"] = keyfile
if certfile is not None:
ssl_kwargs["certfile"] = certfile
if ca_certs is not None:
ssl_kwargs["ca_certs"] = ca_certs
ssl_kwargs["cert_reqs"] = ssl.CERT_REQUIRED
if cert_reqs is not None:
ssl_kwargs["cert_reqs"] = cert_reqs
if ssl_version is None:
ssl_kwargs["ssl_version"] = ssl.PROTOCOL_TLSv1
else:
ssl_kwargs["ssl_version"] = ssl_version
if ciphers is not None:
ssl_kwargs["ciphers"] = ciphers
s = SocketStream.ssl_connect(host, port, ssl_kwargs, ipv6=ipv6, keepalive=keepalive)
return connect_stream(s, service, config)
#context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH, cafile=server_cert)
#context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
# context.verify_mode = ssl.CERT_REQUIRED
# context.check_hostname = False
#context.load_verify_locations(server_cert)
#context.load_cert_chain(certfile = client_cert, keyfile = client_key)
family, socktype, proto, _, sockaddr = socket.getaddrinfo(host, port, family, socktype, proto)[0]
s = socket.socket(family, socktype, proto)
s.connect(sockaddr)
s2 = ssl.wrap_socket(s, do_handshake_on_connect = False, server_side = False, ssl_version=ssl.PROTOCOL_TLSv1_2, certfile = client_cert, keyfile = client_key)
s2.do_handshake()
#except ssl.SSLError as e:
# print(e)
return factory.connect_stream(SocketStream(s2), service = VoidService)
def close(self):
SocketStream.close(self)
if self.tun:
self.tun.close()
data.append(buf)
count -= len(buf)
return BYTES_LITERAL("").join(data)
def write(self, data):
try:
while data:
count = self.sock.send(data[:self.MAX_IO_CHUNK])
data = data[count:]
except socket.error:
ex = sys.exc_info()[1]
self.close()
raise EOFError(ex)
class TunneledSocketStream(SocketStream):
"""A socket stream over an SSH tunnel (terminates the tunnel when the connection closes)"""
__slots__ = ("tun",)
def __init__(self, sock):
self.sock = sock
self.tun = None
def close(self):
SocketStream.close(self)
if self.tun:
self.tun.close()
class PipeStream(Stream):
"""A stream over two simplex pipes (one used to input, another for output)"""
def _connect_sock(self):
if self.local_port is None:
# ParamikoMachine
return self.remote_machine.connect_sock(self.remote_port)
else:
return SocketStream._connect("localhost", self.local_port)
def server(listener=listener, args=args):
with closing(listener):
client = listener.accept()[0]
conn = connect_stream(SocketStream(client), service=remote_service, config=remote_config)
try:
for k in args:
conn._local_root.exposed_namespace[k] = args[k]
conn.serve_all()
except KeyboardInterrupt:
interrupt_main()
data.append(buf)
count -= len(buf)
return BYTES_LITERAL("").join(data)
def write(self, data):
try:
while data:
count = self.sock.send(data[:self.MAX_IO_CHUNK])
data = data[count:]
except socket.error:
ex = sys.exc_info()[1]
self.close()
raise EOFError(ex)
class TunneledSocketStream(SocketStream):
"""A socket stream over an SSH tunnel (terminates the tunnel when the connection closes)"""
__slots__ = ("tun",)
def __init__(self, sock):
SocketStream.__init__(self)
self.sock = sock
self.tun = None
def close(self):
SocketStream.close(self)
if self.tun:
self.tun.close()
class PipeStream(Stream):
return b"".join(map(bytes, stream))
rpyc.core.brine.dump = dump
import socket
def write(self, data):
try:
while data:
count = self.sock.send(buffer(data[:self.MAX_IO_CHUNK]))
data = data[count:]
except socket.error:
ex = sys.exc_info()[1]
self.close()
raise EOFError(ex)
rpyc.core.stream.SocketStream.write = write
else:
# This is only needed if the local is CPython and the remote is IronPython, doesn't
# really hurt otherwise
_netref_factory_orig = rpyc.core.protocol.Connection._netref_factory
def _netref_factory_str(self, id_pack):
return _netref_factory_orig(self, (str(id_pack[0]), id_pack[1], id_pack[2]))
rpyc.core.protocol.Connection._netref_factory = _netref_factory_str