文档链接:《Extensible Messaging and Presence Protocol (XMPP): Core

客户和服务器之间端口为5222,服务器之间的端口为5269.

通信协议格式:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)|--------------------|
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream>           |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)|--------------------|
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<presence>         |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)|   
<show/>          |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</presence>        |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)|--------------------|
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<message to='foo'> |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)|   
<body/>          |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</message>         |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)|--------------------|
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<iq to='bar'>      |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)|   
<query/>         |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</iq>              |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)|--------------------|
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)                |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)|--------------------|
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream>          |
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

客户端和服务器之间维持一个TCP连接,服务器之间维持两个TCP连接

想传输数据之间必须得通过验证,否则不予处理

To:用于客户端到服务器端,

From:用于服务器到客户端

Id:用于服务器到客户端,是服务器端生成的会话id

Xml:lang:包括在客户端的初始流种,指定XML数据的字体,服务器端应该记住此设置,若客户端没有设置,则服务器使用其默认配置,并在应答流中通知给客户端。

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)         |  initiating to receiving  |  receiving to initiating
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)---------
+---------------------------+-----------------------
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)to       |  hostname of receiver     |  silently ignored
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)from     |  silently ignored         |  hostname of receiver
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)id       |  silently ignored         |  session key
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)xml
:lang |  default language         |  default language
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)version  |  signals XMPP 
1.0 support |  signals XMPP 1.0 support
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

若客户端在初始化流包中包含了版本字段,则服务器在应答中必须包含一个<features/>元素,从而让客户端知道服务器支持的特性是哪些,以便客户端和服务器就某些特性进行协商。

流级别的错误是不可恢复的,因此一旦出现,则探测到错误的实体必须发送一个流错误信息给对方,并且发送</stream>结束符,关闭底层TCP连接。

一次简单的会话示例:


《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)C: <?xml version='1.0'?>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)   
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       
to='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       xmlns
='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)S: 
<?xml version='1.0'?>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)   
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       
from='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       id
='someid'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       xmlns
='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  encryption, authentication, and resource binding 《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)C:   
<message from='juliet@example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)              to
='romeo@example.net'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)              xml:lang
='en'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)C:     
<body>Art thou not Romeo, and a Montague?</body>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)C:   
</message>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)S:   
<message from='romeo@example.net'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)              to
='juliet@example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)              xml:lang
='en'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)S:     
<body>Neither, fair saint, if either thee dislike.</body>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)S:   
</message>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)C: 
</stream:stream>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)S: 
</stream:stream>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

 

一次发生错误的会话:


《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)C: <?xml version='1.0'?>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)   
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       
to='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       xmlns
='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)S: 
<?xml version='1.0'?>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)   
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       
from='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       id
='someid'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       xmlns
='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)       version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  encryption, authentication, and resource binding 《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)C: 
<message xml:lang='en'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)     
<body>Bad XML, no closing body tag!
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)   
</message>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)S: 
<stream:error>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<xml-not-well-formed
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)        
xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)   
</stream:error>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)S: 
</stream:stream>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

 

出于安全性的考虑,在客户和服务器之间,服务器之间可能会要求先进行TLS 安全性的验证,而且必须在SASL协商之前完成。

客户到服务器示例:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 1: 客户端初始化到服务器端的流: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    to
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 2: 服务器的应答,回送一个
<stream>标签,并指明会话id: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    id
='c2s_123'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    from
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 3: 服务器发送STARTTLS extension 给客户端,并且指明验证机制和其他支持的流特性: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<required/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
</starttls>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>DIGEST-MD5</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>PLAIN</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
</mechanisms>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 4:客户端发送STARTTLS命令给服务器: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 5: 服务器通知客户端,它被允许继续处理: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 5 (alt): 服务器通知客户,TLS协商失败,关闭流和TCP连接: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<failure xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream:stream>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 6:客户端和服务器端准备在现有的TCP连接上完成TLS验证。
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 7: 若TLS验证成功,客户端初始化一个到服务器的新流: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    to
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 7 (alt): 若TLS验证失败,服务器关闭TCP连接
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 8:服务器回送应答信息,包含了一个流头部和其他可用的流特性: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    from
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    id
='c2s_234'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>DIGEST-MD5</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>PLAIN</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>EXTERNAL</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
</mechanisms>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 9: 客户端继续进行SASL验证。  
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

服务器到服务器示例:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 1: Server1 initiates stream to Server2: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:server'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    to
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 2: Server2 responds by sending a stream tag to Server1: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:server'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    from
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    id
='s2s_123'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 3: Server2 sends the STARTTLS extension to Server1 along with authentication mechanisms and any other stream features: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<required/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
</starttls>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>DIGEST-MD5</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>KERBEROS_V4</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
</mechanisms>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 4: Server1 sends the STARTTLS command to Server2: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 5: Server2 informs Server1 that it is allowed to proceed: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 5 (alt): Server2 informs Server1 that TLS negotiation has failed and closes stream: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<failure xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream:stream>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 6: Server1 and Server2 attempt to complete TLS negotiation via TCP. 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 7: If TLS negotiation is successful, Server1 initiates a new stream to Server2: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:server'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    to
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 7 (alt): If TLS negotiation is unsuccessful, Server2 closes TCP connection. 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 8: Server2 responds by sending a stream header to Server1 along with any available stream features: 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:server'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    from
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    id
='s2s_234'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>DIGEST-MD5</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>KERBEROS_V4</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>EXTERNAL</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
</mechanisms>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)Step 9: server1继续进行SASL验证 
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

TLS验证后,进行SASL验证

客户到服务器示例:

Step 1: 客户端初始到服务器的流:

 

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    to
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

Step 2:服务器发送应答:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    id
='c2s_234'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    from
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

  Step 3:服务器通知客户可选的验证机制:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>DIGEST-MD5</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
<mechanism>PLAIN</mechanism>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
</mechanisms>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

Step 4: 客户端选择一种验证机制:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)      mechanism
='DIGEST-MD5'/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

Step 5: 服务器发送BASE64编码过的应答数据给客户端:

 

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)cmVhbG09InNvbWVyZWFsbSIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixxb3A9ImF1dGgi
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)LGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNzCg==
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</challenge>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

 解码后的数据为:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)realm="somerealm",nonce="OA6MG9tEQGm2hh",\
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)qop="auth",charset=utf-8,algorithm=md5-sess
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

Step 5 (alt):服务器返回错误给客户端:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<incorrect-encoding/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</failure>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream:stream>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

 Step 6: 客户端发送一个BASE64编码的应答数据给服务器:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)dXNlcm5hbWU9InNvbWVub2RlIixyZWFsbT0ic29tZXJlYWxtIixub25jZT0i
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)T0E2TUc5dEVRR20yaGgiLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLG5jPTAw
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)MDAwMDAxLHFvcD1hdXRoLGRpZ2VzdC11cmk9InhtcHAvZXhhbXBsZS5jb20i
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)LHJlc3BvbnNlPWQzODhkYWQ5MGQ0YmJkNzYwYTE1MjMyMWYyMTQzYWY3LGNo
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)YXJzZXQ9dXRmLTgK
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</response>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

解码后的应答消息是:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)username="somenode",realm="somerealm",\
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)nonce="OA6MG9tEQGm2hh",cnonce="OA6MHXh6VqTrRk",\
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)nc=00000001,qop=auth,digest-uri="xmpp/example.com",\
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)response=d388dad90d4bbd760a152321f2143af7,charset=utf-8
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

Step 7: 服务器发送第二个BASE64编码的challenge数据给客户:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)cnNwYXV0aD1lYTQwZjYwMzM1YzQyN2I1NTI3Yjg0ZGJhYmNkZmZmZAo=
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</challenge>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

解码后的challenge:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)rspauth=ea40f60335c427b5527b84dbabcdfffd

Step 7 (alt): 服务器返回错误给客户:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<temporary-auth-failure/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</failure>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream:stream>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

Step 8: 客户返回应答消息给服务器:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>

Step 9: 服务器通知客户成功通过验证:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>

 Step 9 (alt):服务器通知客户验证失败:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<temporary-auth-failure/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</failure>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream:stream>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

Step 10:客户端初始化一个到服务器的新流:

 

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    to
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

Step 11: 服务器返回一个流头部,包含了服务器支持的流特性:

《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)<stream:stream
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    
xmlns='jabber:client'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    xmlns:stream
='http://etherx.jabber.org/streams'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    id
='c2s_345'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    from
='example.com'
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)    version
='1.0'>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
<stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)  
<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)
</stream:features>
《Extensible Messaging and Presence Protocol (XMPP): Core》阅读笔记(一)

 

相关文章:

  • 2021-09-06
  • 2022-01-23
  • 2022-03-09
  • 2021-08-18
  • 2021-12-14
  • 2021-12-22
  • 2021-05-20
  • 2021-08-11
猜你喜欢
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2021-06-25
  • 2021-08-25
相关资源
相似解决方案