论坛首页 Java企业应用论坛

XMPP HTTP-BIND 认证交互的消息流

浏览 9017 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-10-09  
XMPP定义的BOSH规范(XEP 1024)是为了在HTTP协议上承载XMPP消息。下面是XEP 1024定义的非安全方式下的认证消息流。只有在 SSL (or TLS) HTTP连接保护下的消息才是安全的消息,否则为非安全的消息。XEP 1024定义了主键系列的方式保护非安全的消息,这种方案只能防御到不能修改消息内容的攻击者;如果需要彻底的保护消息,只能使用SSL或者TLS。为了清楚地截取交互过程,下面的流程基于非安全的方式。

主键系列生成算法:
        K(1) = hex(SHA-1(seed))
K(2) = hex(SHA-1(K(1)))
...
K(n) = hex(SHA-1(K(n-1)))

交互的XMPP消息流中 第一个消息包含newkey的属性,其值为第一个主键系列的值。
后续的客户端给服务器端发送的消息必须带上SID及key的值,每个key的值由前一个key的值计算而来。当循环用到最后一个key值
的时候,可以同时设置newkey的属性,开始新的一系列key值。
下面的交互过程从jwchat与openfire3.3.2的http-bind模块通信中截取。
xml 代码
 
  1. Accept-Language: zh-cn  
  2. Referer: http://191.1.11.56:8082/CIM/index.htm?jid=user1.org1&server=191.1.11.77&pass=123456&nickname=........  
  3. Content-Type: text/xml; charset=utf-8  
  4. Accept-Encoding: gzip, deflate  
  5. User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)  
  6. Host: 191.1.11.77:8080  
  7. Content-Length: 151  
  8. Connection: Keep-Alive  
  9. Cache-Control: no-cache  
  10.   
  11. <body hold='1' xmlns='http://jabber.org/protocol/httpbind' to='191.1.11.77'   
  12. wait='300' rid='803757' newkey='b543ff6c4c105dba31d70c6f1c7304ed7bece24b'/>  
Server返回一个SID,并给出认证的选择。
xml 代码
 
  1. HTTP/1.1 200 OK  
  2. Content-Type: text/xml; charset=utf-8  
  3. Content-Length: 662  
  4. Server: Jetty(6.1.x)  
  5.   
  6.   
  7.   
  8. <body xmlns="http://jabber.org/protocol/httpbind" 
  9. xmlns:stream="http://etherx.jabber.org/streams"
  10. authid="1fc3b503" sid="1fc3b503" secure="true"
  11. requests="2" inactivity="30" polling="0" wait="10">
  12. <stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">  
  13. <mechanism>DIGEST-MD5<!---->mechanism>  
  14. <mechanism>JIVE-SHAREDSECRET<!---->mechanism>  
  15. <mechanism>PLAIN<!---->mechanism>  
  16. <mechanism>ANONYMOUS<!---->mechanism>  
  17. <mechanism>CRAM-MD5<!---->mechanism><!---->mechanisms>  
  18. <compression xmlns="http://jabber.org/features/compress">
  19. <method>zlib<!---->method><!---->compression>
  20. <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/>
  21. <session xmlns="urn:ietf:params:xml:ns:xmpp-session"/><!---->stream:features><!---->body>  
下面是客户端发送认证

请求。digest的值为sha1(sid + password)
xml 代码
 
  1. POST /http-bind/ HTTP/1.1  
  2. Accept: */*  
  3. Accept-Language: zh-cn  
  4. Referer:http://191.1.11.56:8082/CIM/index.htm?jid=user1.org1&server=191.1.11.77&pass=123456&nickname=........  
  5. Content-Type: text/xml; charset=utf-8  
  6. Accept-Encoding: gzip, deflate  
  7. User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)  
  8. Host: 191.1.11.77:8080  
  9. Content-Length: 346  
  10. Connection: Keep-Alive  
  11. Cache-Control: no-cache  
  12.   
  13. <body rid='803759' sid='1fc3b503' xmlns='http://jabber.org/protocol/httpbind'   
  14. key='aabcfc3ad7a327fa9542da51b24d024361d4b6f1' >  
  15. <iq xmlns="jabber:client" type="set" id="auth2">  
  16. <query xmlns="jabber:iq:auth">  
  17. <username>user1.org1<!---->username>  
  18. <resource>............<!---->resource>  
  19. <digest>33f2e458193401a8eb12443b0f459c16079463d9<!---->digest><!---->query><!---->iq>  
  20. <!---->body>  
xml 代码
 
  1. HTTP/1.1 200 OK  
  2. Content-Type: text/xml; charset=utf-8  
  3. Content-Length: 136  
  4. Server: Jetty(6.1.x)  
  5.   
  6. <body xmlns='http://jabber.org/protocol/httpbind'>
  7. <iq type="result" id="auth2" to="user1.org1@domainname/............"/>
  8. <!---->body>  
认证结束,客户端发送呈现的消息流,查询用户的状态
xml 代码
 
  1. POST /http-bind/ HTTP/1.1  
  2. Accept: */*  
  3. Accept-Language: zh-cn  
  4. Referer:http://191.1.11.56:8082/CIM/index.htm?jid=user1.org1&server=191.1.11.77&pass=123456&nickname=........  
  5. Content-Type: text/xml; charset=utf-8  
  6. Accept-Encoding: gzip, deflate  
  7. User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)  
  8. Host: 191.1.11.77:8080  
  9. Content-Length: 266  
  10. Connection: Keep-Alive  
  11. Cache-Control: no-cache  
  12.   
  13. <body rid='803761' sid='1fc3b503' xmlns='http://jabber.org/protocol/httpbind'
  14. key='d32ea55815de2c52f1b736080a79825cc227e09d' >
  15. <iq xmlns="jabber:client" type="get" id="jwchat_state">
  16. <query xmlns="jabber:iq:private"><jwchat xmlns="jwchat:state"/><!---->query><!---->iq>  
  17. <!---->body>  
查询状态返回:
xml 代码
 
  1. HTTP/1.1 200 OK  
  2. Content-Type: text/xml; charset=utf-8  
  3. Content-Length: 265  
  4. Server: Jetty(6.1.x)  
  5.   
  6. <body xmlns='http://jabber.org/protocol/httpbind'>
  7. <iq type="result" id="jwchat_state" to="user1.org1@domainname/............">
  8. <query xmlns="jabber:iq:private">
  9. <jwchat xmlns="jwchat:state">
  10. <presence>available<!---->presence>
  11. <onlmsg/>
  12. <!---->jwchat><!---->query><!---->iq><!---->body>  
发布呈现信息
xml 代码
 
  1. POST /http-bind/ HTTP/1.1  
  2. Accept: */*  
  3. Accept-Language: zh-cn  
  4. Referer: http://191.1.11.56:8082/CIM/index.htm?jid=user1.org1&server=191.1.11.77&pass=123456&nickname=........  
  5. Content-Type: text/xml; charset=utf-8  
  6. Accept-Encoding: gzip, deflate  
  7. User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)  
  8. Host: 191.1.11.77:8080  
  9. Content-Length: 620  
  10. Connection: Keep-Alive  
  11. Cache-Control: no-cache  
  12.   
  13. <body rid='803763' sid='1fc3b503' xmlns='http://jabber.org/protocol/httpbind'
  14. key='192ed9480229081924997e91a275411df3bdfb0f' >
  15. <presence xmlns="jabber:client"><priority>10<!---->priority><!---->presence>  
  16. <iq xmlns="jabber:client" to="191.1.11.77" type="get" id="disco_item_1">
  17. <query xmlns="http://jabber.org/protocol/disco#items"/><!---->iq>
  18. <iq xmlns="jabber:client" type="get" id="storage_bookmarks">
  19. <query xmlns="jabber:iq:private"><storage xmlns="storage:bookmarks"/><!---->query><!---->iq> 
  20. <iq xmlns="jabber:client" type="get" id="jwchat_notes">
  21. <query xmlns="jabber:iq:private"><storage xmlns="storage:rosternotes"/><!---->query><!---->iq>
  22. <!---->body>  
返回
xml 代码
 
  1. HTTP/1.1 200 OK  
  2. Content-Type: text/xml; charset=utf-8  
  3. Content-Length: 201  
  4. Server: Jetty(6.1.x)  
  5.   
  6. <body xmlns='http://jabber.org/protocol/httpbind'>
  7. <presence from="user1.org1@domainname/............"
  8. to="user1.org1@domainname/............"><priority>10<!---->priority>
  9. <!---->presence><!---->body>  
   发表时间:2007-11-26  
我现在正在用JSJAC库连接OPENFIRE。。。


不知道为什么,接的时候老是异常。
0 请登录后投票
   发表时间:2007-12-27  
配置没对巴,要看是什么异常。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics