从 Twisted 中的 SSL 套接字读取
我正在尝试在 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
如何,都不会调用任何接收到的方法。是否只是没有从服务器读取任何内容? connectionMade
和 connectionLost
在连接时立即调用,并以 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 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.