使用的套接字上的 NSStream SSL
我正在编写一个在 iPhone 上使用 NSStream 的 SSL 功能的应用程序。我知道 SSL 正在运行,因为我可以使用 SSL 直接连接服务器。
我遇到了一个问题,使用 starttls 的协议要求我在不安全的套接字上进行通信,发送 starttls 命令,然后为 SSL 重用相同的套接字。据我所知,nsstream 连接无法重复使用,并且在打开连接后我无法在它们上启动 SSL。
我考虑过创建自己的套接字,手动在其上进行通信,然后使用现有套接字设置 NSstream 并以这种方式启动 SSL。但是,套接字上的通信似乎将其置于无法启动 SSL 的状态。任何尝试将套接字用于 nsstream 都会导致错误。
有什么想法吗?
I am writing an application that uses NSStream's SSL functions on the iphone. I know that SSL is working because I can directly connect servers using SSL.
I have encountered a problem where protocols that use starttls require me to communicate on the socket with unsecured, send the starttls command and then reuse the same socket for SSL. As far as i know nsstream connections cannot be reused and i can't start SSL on them after i have opened the connection.
I thought about creating my own socket, communicating on it manually and then setting up an NSstream using the existing socket and start SSL that way. However, it appears the communicating on the socket places it in a state where i cant start SSL on it. Any attempt to use the socket for nsstream results in an error.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是执行此操作的正确方法。虽然这样做(在套接字连接后设置属性)没有记录,但这是直接来自我的 Monal xmpp 客户端的代码,并且苹果从未在应用程序商店中给我带来任何问题。
连接打开后,您会收到 NSStreamEventOpenCompleted 并且 startTLS 命令已从客户端发送到主机:
This is the correct way to do this. while doing this (setting the property after socket connection) is undocumented, this is code directly from my Monal xmpp client and apple has never given me any problems in the app store.
Once the connection has been opened and you get NSStreamEventOpenCompleted and the startTLS command has been sent to the host from the client: