0

我正在尝试使用 ssl 进行连接,因为我不希望互联网上的每个人都能看到该连接 [将我最常使用的计算机连接到 vps 和我的其他本地计算机] 但是,我在获取 ssl 时遇到了很多困难在 rpyc 上工作。我花了几天时间这样做...

client.py 位于 ubuntu 机器上,而 server.py 在 Windows 10 机器上运行。

我可以使用 ssh 从 ubuntu 机器使用端口 22 连接到 Windows 机器。

我在 windows 机器上也有端口转发端口 1337

另外,我在windows防火墙上启用了1337端口

在 client.py 示例中,我没有提供密钥文件或证书文件,但这似乎没有什么区别,因为我还创建了一个使用证书和密钥文件的 client.py,但它仍然给了我同样的结果。

我也可以 tcptraceroute 10.0.0.144 到端口 1337 与预期的结果

客户端.py

import rpyc

conn = rpyc.ssl_connect("10.0.0.144", port=1337,
                    keyfile=None,
                    certfile=None)
conn.execute("print ('world')")

服务器.py

import rpyc


class MyService(rpyc.Service):
    def on_connect(self):
        # code that runs when a connection is created
        # (to init the serivce, if needed)
        pass

    def on_disconnect(self):
        # code that runs when the connection has already closed
        # (to finalize the service, if needed)
        pass

    def exposed_get_answer(self):  # this is an exposed method
        return 42

    def get_question(self):  # while this method is not exposed
        return "what is the airspeed velocity of an unladen swallow?"


if __name__ == "__main__":
    from rpyc.utils.server import ThreadedServer
    from rpyc.utils.authenticators import SSLAuthenticator

    authenticator = SSLAuthenticator("../certs/server.key", "../certs/server.crt")
    server = ThreadedServer(MyService, port=1337, authenticator=authenticator)
    server.start()

客户回溯

Traceback (most recent call last):
  File "/home/nubonix/PycharmProjects/NBM2/utils/remoting/TESTING/remoting8_4.py", line 3, in <module>
    conn = rpyc.ssl_connect("10.0.0.144", port=1337,
  File "/home/nubonix/PycharmProjects/NBM2/venv/lib/python3.8/site-packages/rpyc/utils/factory.py", line 160, in ssl_connect
    s = SocketStream.ssl_connect(host, port, ssl_kwargs, ipv6=ipv6, keepalive=keepalive)
  File "/home/nubonix/PycharmProjects/NBM2/venv/lib/python3.8/site-packages/rpyc/core/stream.py", line 214, in ssl_connect
    s2 = ssl.wrap_socket(s, **ssl_kwargs)
  File "/usr/lib/python3.8/ssl.py", line 1405, in wrap_socket
    return context.wrap_socket(
  File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL] internal error (_ssl.c:1131)

Process finished with exit code 1
4

0 回答 0