无法使用 ssl 连接到我的 rpyc 服务器

时间:2021-07-14 10:26:40

标签: python authentication ssl rpyc

我正在尝试使用 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')")

server.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

0 个答案:

没有答案