如何在twisted portforward代理中添加SSL功能

2024-04-26 05:41:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下用于portforward代理的代码。如何添加 ssl支持,以便代理可以连接到使用ssl侦听的服务器。你知道吗

代码如下:

    from twisted.internet import reactor
    from twisted.protocols import portforward

    class ProxyServer(portforward.ProxyServer):
        def dataReceived(self, data)
        portforward.ProxyServer.dataReceived(self, data)

    class ProxyFactory(portforward.ProxyFactory):
        protocol = ProxyServer


        reactor.listenTCP(8080,ProxyFactory("127.0.0.1",443) )
        reactor.run()

Tags: 代码fromimportself服务器ssl代理data
1条回答
网友
1楼 · 发布于 2024-04-26 05:41:15

查看此链接。这段摘录可能与你要找的东西有关。 https://twistedmatrix.com/documents/13.2.0/core/howto/ssl.html

with open('server.pem') as keyAndCert:
    cert = ssl.PrivateCertificate.loadPEM(keyAndCert.read())

log.startLogging(sys.stdout)
factory = Factory()
factory.protocol = echoserv.Echo
reactor.listenSSL(8000, factory, cert.options())
reactor.run()

“请注意,在这些SSL版本中,echo客户端和服务器示例的TCP版本中的所有协议代码都是相同的(导入或重复的)-只有用于启动网络操作的reactor方法不同。”

相关问题 更多 >