du5739 2019-04-16 21:11
浏览 132
已采纳

XMPP与TLS实现

How can I connect to XMPP server over TLS? I've read both the book and the RFC doc about it and the instructions are clear on the high overview, but I'm missing details.

I am constructing my own XMPP library and once I open the socket to the client on port 5222 I am sending initial XML to start the conversation followed by:

<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>

Server responds with:

<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>

After this it get's unclear about what should I do, as supposedly somehow the TLS magic should happen here, getting the server to send the certificate to the client. How is that done, and how do I know it is received?

After that the documents say that the stream should be terminated, and another one started...does that mean that I need to disconnect the socket or just close the stream by sending </stream:stream>?

  • 写回答

1条回答 默认 最新

  • doufang2023 2019-04-23 15:04
    关注

    I have found out the solution to the problem. My mistake was that after I got the <proceed> I was closing the socket in order to switch it to port 443, change the protocol, and other similar stuff.

    The solution was not to close the connection, but rather enabling crypto on existing connection by using:

    stream_socket_enable_crypto($this->socket->connection, 
                                true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
    

    And then opening the communication once again with

    <?xml version='1.0' encoding='UTF-8'?>
    <stream:stream to=.....
    

    After that you will get back the "real" response about how you can authenticate (i.e. PLAIN).

    It is all implemented within my library so you can check it out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题