經過ejabberd日誌分析客戶端登陸流程

經過ejabberd的日誌,整理了下客戶端登陸流程。 html

1. 經過TCP鏈接5222端口的流程: node

(1) 客戶端向服務器發送stream流 服務器

<stream:stream to="nba.com"
               xml:lang="*"
               version="1.0"
               xmlns:stream="http://etherx.jabber.org/streams"
               xmlns="jabber:client">
(2) 服務器應答stream
<?xml version='1.0'?>
<stream:stream xmlns='jabber:client'
               xmlns:stream='http://etherx.jabber.org/streams'
               id='4171758611'
               from='nba.com'
               version='1.0'
               xml:lang='en'>
(3) 服務器發送流特性
<stream:features>
	<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
	<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
		<mechanism>PLAIN</mechanism>
	</mechanisms>
	<c xmlns='http://jabber.org/protocol/caps'
	   hash='sha-1'
	   node='http://www.process-one.net/en/ejabberd/'
	   ver='AxFG3uvIZfHAbBjOUb9t3klmoos='/>
	<register xmlns='http://jabber.org/features/iq-register'/>
</stream:features>
(4)  客戶端發送tls請求
<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
(5) 服務器迴應並開始TLS握手
<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
(6) TLS握手完成後,客戶端從新初始化stream流
<stream:stream to="nba.com"
               xml:lang="*"
               version="1.0"
               xmlns:stream="http://etherx.jabber.org/streams"
               xmlns="jabber:client">
(7) 服務器應答
<?xml version='1.0'?>
<stream:stream xmlns='jabber:client'
               xmlns:stream='http://etherx.jabber.org/streams'
               id='703708799'
               from='nba.com'
               version='1.0'
               xml:lang='en'>
(8) 服務器告知客戶端支持的SASL驗證機制
<stream:features>
	<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
		<mechanism>PLAIN</mechanism>
	</mechanisms>
	<c xmlns='http://jabber.org/protocol/caps'
	   hash='sha-1'
	   node='http://www.process-one.net/en/ejabberd/'
	   ver='AxFG3uvIZfHAbBjOUb9t3klmoos='/>
	<register xmlns='http://jabber.org/features/iq-register'/>
</stream:features>
(9) 客戶端選擇簡單認證機制併發送用戶名密碼
<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">
AGNoZW53ZW5jYW4ja2VkYWNvbS5jb20AMjEyMThjY2E3NwgzNGQyYmExOTIyYzMzZTAxNTExMDU=
</auth>
(10) 服務器告訴客戶端校驗經過,SASL握手完成
<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
(11) 客戶端再次初始化stream流
<stream:stream to="nba.com"
               xml:lang="*"
               version="1.0"
               xmlns:stream="http://etherx.jabber.org/streams"
               xmlns="jabber:client">

(12) 服務器應答 session

<?xml version='1.0'?>
<stream:stream xmlns='jabber:client'
               xmlns:stream='http://etherx.jabber.org/streams'
               id='2767342509'
               from='nba.com'
               version='1.0'
               xml:lang='en'>

(13) 通知客戶端進行資源綁定 併發

<stream:features>
	<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
	<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
	<c xmlns='http://jabber.org/protocol/caps'
	   hash='sha-1'
	   node='http://www.process-one.net/en/ejabberd/'
	   ver='AxFG3uvIZfHAbBjOUb9t3klmoos='/>
	<register xmlns='http://jabber.org/features/iq-register'/>
</stream:features>

(14) 客戶端請求資源綁定 spa

<iq type="set" id="0">
	<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
	<resource>boston</resource>
	</bind>
</iq>

(15) 服務器應答 .net

<iq id='0' type='result'>
	<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
	<jid>rondo@nba.com/boston</jid>
	</bind>
</iq>

(16) 客戶端請求session綁定 rest

<iq type="set" id="1">
	<session xmlns="urn:ietf:params:xml:ns:xmpp-session"/>
</iq>

(17) 服務器應答 日誌

<iq type='result' id='1'>
	<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
</iq>
至此,可認爲登錄完成,後續進行能力協商,發送其餘請求消息,發送出息消息等。

2. 經過http鏈接5280端口的流程 code

http方式的交互是經過BOSH協議完成的,詳細可參見

http://xmpp.org/extensions/xep-0124.html

http://xmpp.org/xmpp-protocols/xmpp-extensions/

具體流程爲:

(1) 發起bosh會話

<body rid='16488487'
      xmlns='http://jabber.org/protocol/httpbind'
      to='nba.com'
      xml:lang='en'
      wait='60'
      hold='1'
      content='text/xml;charset=utf-8'
      ver='1.6'
      xmpp:version='1.0'
      xmlns:xmpp='urn:xmpp:xbosh'/>

(2) 服務器應答

<body xmlns='http://jabber.org/protocol/httpbind'
      sid='90582e464361adb537351e65ecfa66d1336ea486'
      wait='60'
      requests='2'
      inactivity='30'
      maxpause='120'
      polling='2'
      ver='1.8'
      from='nba.com'
      secure='true'
      authid='1145683568'
      xmlns:xmpp='urn:xmpp:xbosh'
      xmlns:stream='http://etherx.jabber.org/streams'
      xmpp:version='1.0'>
    <stream:features xmlns:stream='http://etherx.jabber.org/streams'>
        <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
            <mechanism>PLAIN</mechanism>
        </mechanisms>
        <c xmlns='http://jabber.org/protocol/caps'
           hash='sha-1'
	   node='http://www.process-one.net/en/ejabberd/'
	   ver='AxFG3uvIZfHAbBjOUb9t3klmoos='/>
        <register xmlns='http://jabber.org/features/iq-register'/>
    </stream:features>
</body>

(3) 客戶端發送用戶名密碼

<body rid='16488488'
      xmlns='http://jabber.org/protocol/httpbind'
      sid='90582e464361adb537351e65ecfa66d1336ea486'>
    <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>
        AGNoZW53ZW5jYW4ja2VkYWNvbS5jb20AMjEyMThjY2E3NwgzNGQyYmExOTIyYzMzZTAxNTExMDU=
    </auth>
</body>

(4) 服務器響應告知校驗結果

<body xmlns='http://jabber.org/protocol/httpbind'>
    <success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
</body>

(5) 客戶端從新初始化stream流

<body rid='16488489'
      xmlns='http://jabber.org/protocol/httpbind'
      sid='90582e464361adb537351e65ecfa66d1336ea486'
      to='nba.com'
      xml:lang='en'
      xmpp:restart='true'
      xmlns:xmpp='urn:xmpp:xbosh'/>

(6) 服務器通知完成資源綁定

<body xmlns='http://jabber.org/protocol/httpbind'
      sid='90582e464361adb537351e65ecfa66d1336ea486'
      wait='60'
      requests='2'
      inactivity='30'
      maxpause='120'
      polling='2'
      ver='1.8'
      from='nba.com'
      secure='true'
      authid='3855745118'
      xmlns:xmpp='urn:xmpp:xbosh'
      xmlns:stream='http://etherx.jabber.org/streams'
      xmpp:version='1.0'>
    <stream:features xmlns:stream='http://etherx.jabber.org/streams'>
        <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
        <session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
        <c xmlns='http://jabber.org/protocol/caps'
	   hash='sha-1'
	   node='http://www.process-one.net/en/ejabberd/'
	   ver='AxFG3uvIZfHAbBjOUb9t3klmoos='/>
	   <register xmlns='http://jabber.org/features/iq-register'/>
    </stream:features>
</body>

(7) 客戶端請求資源綁定

<body rid='16488490'
      xmlns='http://jabber.org/protocol/httpbind'
      sid='90582e464361adb537351e65ecfa66d1336ea486'>
    <iq type='set' id='_bind_auth_2' xmlns='jabber:client'>
	    <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
	    <resource>boston</resource>
	    </bind>
    </iq>
</body>

(8) 服務器應答

<body xmlns='http://jabber.org/protocol/httpbind'>
    <iq xmlns='jabber:client' id='_bind_auth_2' type='result'>
	    <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
	    <jid>rondo@nba.com/boston</jid>
	    </bind>
    </iq>
</body>

(9) 客戶端請求session綁定

<body rid='16488491'
      xmlns='http://jabber.org/protocol/httpbind'
      sid='90582e464361adb537351e65ecfa66d1336ea486'>
    <iq type='set' id='_session_auth_2' xmlns='jabber:client'>
	    <session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
    </iq>
</body>

(10) 服務器應答

<body xmlns='http://jabber.org/protocol/httpbind'>
    <iq xmlns='jabber:client' id='_session_auth_2' type='result'>
	    <session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
    </iq>
</body>
相關文章
相關標籤/搜索