从 Twisted 中的 SSL 套接字读取

发布于 2024-08-16 18:42:07 字数 1106 浏览 2 评论 0原文

我正在尝试在 Twisted 中实现一个 SSL 客户端,它只需连接到套接字并读取二进制数据(特别是数据元组)。我已经得到了代码,似乎可以成功连接和断开连接,但没有从套接字读取任何数据。

class FeedbackHandler(LineReceiver):
  MAX_LENGTH = 1024*1024

  def connectionMade(self):
    log.debug('feedbackHandler connectionMade')

  def rawDataReceived(self, data):
    log.debug('feedbackHandler rawDataReceived %s' % binascii.hexlify(data))
    self.io.write(data)

  def lineReceived(self, data):
    log.debug('feedbackHandler lineReceived %s' % binascii.hexlify(data))
    self.io.write(data)

  def connectionLost(self, reason):
    log.debug('feedbackHandler connectionLost %s' % reason)
    self.deferred.callback(self.io.getValue())
    io.close()

以及启动它的代码:

factory = self.clientProtocolFactory() # a ClientFactory instance
context = self.getContextFactory(CERT_FILE) # a ClientContextFactory 
reactor.connectSSL(server, port, factory, context)

但是,当它运行时,无论setRawMode如何,都不会调用任何接收到的方法。是否只是没有从服务器读取任何内容? connectionMadeconnectionLost 在连接时立即调用,并以 ConnectionDone 错误实例终止。

I'm trying to implement an SSL client in Twisted that simply must connect to a socket and read binary data (specifically, tuples of data). I've gotten the code to a point where it seems to connect and disconnect successfully but no data is ever read from the socket.

class FeedbackHandler(LineReceiver):
  MAX_LENGTH = 1024*1024

  def connectionMade(self):
    log.debug('feedbackHandler connectionMade')

  def rawDataReceived(self, data):
    log.debug('feedbackHandler rawDataReceived %s' % binascii.hexlify(data))
    self.io.write(data)

  def lineReceived(self, data):
    log.debug('feedbackHandler lineReceived %s' % binascii.hexlify(data))
    self.io.write(data)

  def connectionLost(self, reason):
    log.debug('feedbackHandler connectionLost %s' % reason)
    self.deferred.callback(self.io.getValue())
    io.close()

And the code that kicks it off:

factory = self.clientProtocolFactory() # a ClientFactory instance
context = self.getContextFactory(CERT_FILE) # a ClientContextFactory 
reactor.connectSSL(server, port, factory, context)

However when it runs none of the received methods are called, regardless of setRawMode. Is there just nothing to read from the server? connectionMade and connectionLost are called immediately when connecting and terminates with a ConnectionDone error instance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水染的天色ゝ 2024-08-23 18:42:07

查看 ssldump 或wireshark。由于您没有看到在此级别交付的任何数据,因此您应该将级别降低到其中一个工具。其中之一可能会揭示 SSL 协商错误,或者服务器从不发送任何字节,或者仅根据您目前发现的内容很难猜测其他内容。你可能仍然没有完整的答案,但你会得到更多的拼图。

Take a look at ssldump or wireshark. Since you're not seeing any data delivered at this level, you should drop down a level to one of these tools. One of them might reveal an SSL negotiation error, or that the server never sends any bytes, or something else that's hard to guess based just on what you've discovered so far. You still might not have the complete answer, but you'll have more pieces of the puzzle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文