XMPP包含的一個保證流安全的方法(傳輸層安全協議[TLS]的頻道加密方法)來防止篡改和偷聽.
一個給定域的管理員可以要求客戶端和服務器通信以及服務器之間通信時使用TLS,或者兩者都要求。客戶端應該在嘗試完成 SASL握手之前使用 TLS,服務器應該在兩個域之間使用 TLS 以保證服務器間通信的安全。
當一個初始化實體用TLS保護一個和接收實體之間的流,其步驟如下:
步驟1:客戶端初始化流給服務器
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='example.com' version='1.0'>
步驟2:服務器發送一個流標簽給客戶端作為應答
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='c2s_123' from='example.com' version='1.0'>
步驟3:服務器發送 STARTTLS 范圍給客戶端(包括驗證機制和任何其他流特性)
<stream:features> <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'> <required/> </starttls> <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <mechanism>DIGEST-md5</mechanism> <mechanism>PLAIN</mechanism> </mechanisms></stream:features>
步驟4:客戶端發送 STARTTLS 命令給服務器
<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
步驟5:服務器通知客戶端可以繼續進行
<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
步驟 5 (或者): 服務器通知客戶端 TLS 握手失敗并關閉流和TCP連接
<failure xmlns='urn:ietf:params:xml:ns:xmpp-tls'/></stream:stream>
步驟 6: 客戶端和服務器嘗試通過已有的TCP連接完成 TLS 握手.
步驟 7: 如果 TLS 握手成功, 客戶端初始化一個新的流給服務器
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='c2s_234' version='1.0'> <stream:features> <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <mechanism>DIGEST-MD5</mechanism> <mechanism>PLAIN</mechanism> <mechanism>EXTERNAL</mechanism> </mechanisms></stream:features>
步驟 9: 客戶端繼續 SASL 握手
步驟1:Server1 初始化流給 Server2
<stream:stream xmlns='jabber:server' xmlns:stream='http://etherx.jabber.org/streams' to='example.com' version='1.0'>
步驟2:Server2 發送一個流標簽給 Server1 作為應答
<stream:stream xmlns='jabber:server' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='s2s_123' version='1.0'>
步驟3:Server2 發送 STARTTLS 范圍給 Server1 ,包括驗證機制和任何其他流特性
<stream:features> <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'> <required/> </starttls> <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <mechanism>DIGEST-MD5</mechanism> <mechanism>KERBEROS_V4</mechanism> </mechanisms></stream:features>
步驟 4: Server1 發送 STARTTLS 命令給 Server2
<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
步驟5:Server2 通知 Server1 允許繼續進行
<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
步驟 6: Server1 和 Server2 嘗試通過 TCP 完成 TLS 握手.
步驟 7: 如果 TLS 握手成功, Server1 初始化一個新的流給 Server2
<stream:stream xmlns='jabber:server' xmlns:stream='http://etherx.jabber.org/streams' to='example.com' version='1.0'>
步驟7(或者): 如果 TLS 握手不成功, Server2 關閉 TCP 連接.
步驟8 : Server2 發送一個包含任何可用流特性的流頭信息給 Server1
<stream:stream xmlns='jabber:server' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='s2s_234' version='1.0'> <stream:features> <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <mechanism>DIGEST-MD5</mechanism> <mechanism>KERBEROS_V4</mechanism> <mechanism>EXTERNAL</mechanism> </mechanisms></stream:features>
步驟9:Server1 繼續進行 SASL 握手
XMPP 有一個驗證流的方法,即XMPP特定的SASL(簡單驗證和安全層)[SASL]。SASL提供了一個通用的方法為基于連接的協議增加驗證支持,而XMPP使用了一個普通的XML名字空間來滿足SASL的需要。
一個初始化實體使用SASL和接收實體做驗證的步驟如下:
步驟1:客戶端初始化流給服務器
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='example.com' version='1.0'>
步驟2: 服務器向客戶端發送流標簽作為應答
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='c2s_234' from='example.com' version='1.0'>
步驟3: 服務器通知客戶端可用的驗證機制
<stream:features> <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <mechanism>DIGEST-MD5</mechanism> <mechanism>PLAIN</mechanism> </mechanisms></stream:features>
步驟4:客戶端選擇一個驗證機制
<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/>
步驟5:服務器發送一個 [BASE64] 編碼的挑戰給客戶端
<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> cmVhbG09InNvbWVyZWFsbSIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixxb3A9ImF1dGgiLGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNzCg==</challenge>
解碼后的挑戰信息是:
realm="somerealm",nonce="OA6MG9tEQGm2hh",/ qop="auth",charset=utf-8,algorithm=md5-sess步驟 5 (替代): 服務器返回一個錯誤給客戶端
<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <incorrect-encoding/></failure></stream:stream>
步驟 6: 客戶端發送一個[BASE64]編碼的回應這個挑戰:
<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> dXNlcm5hbWU9InNvbWVub2RlIixyZWFsbT0ic29tZXJlYWxtIixub25jZT0i T0E2TUc5dEVRR20yaGgiLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLG5jPTAw MDAwMDAxLHFvcD1hdXRoLGRpZ2VzdC11cmk9InhtcHAvZXhhbXBsZS5jb20i LHJlc3BvbnNlPWQzODhkYWQ5MGQ0YmJkNzYwYTE1MjMyMWYyMTQzYWY3LGNo YXJzZXQ9dXRmLTgK</response>
解碼后的回應信息是
username="somenode",realm="somerealm",/ nonce="OA6MG9tEQGm2hh",cnonce="OA6MHXh6VqTrRk",/ nc=00000001,qop=auth,digest-uri="xmpp/example.com",/ response=d388dad90d4bbd760a152321f2143af7,charset=utf-8步驟 7: 服務器發送另一個[BASE64]編碼的挑戰給客戶端
<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> cnNwYXV0aD1lYTQwZjYwMzM1YzQyN2I1NTI3Yjg0ZGJhYmNkZmZmZAo=</challenge>
解碼后的挑戰信息是:
rspauth=ea40f60335c427b5527b84dbabcdfffd
步驟 7 (或者): 服務器返回一個錯誤給客戶端:
<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <temporary-auth-failure/> </failure></stream:stream>
步驟 8: 客戶端應答這個挑戰
<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
步驟 9: 服務器通知客戶端驗證成功
<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
步驟 9 (或者): 服務器通知客戶端驗證失敗
<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <temporary-auth-failure/> </failure></stream:stream>
步驟 10: 客戶端發起一個新的流給服務器:
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='example.com' version='1.0'>
步驟 11: 服務器發送一個流頭信息回應客戶端,并附上任何可用的特性(或空的features元素)
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='c2s_345' from='example.com' version='1.0'> <stream:features> <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/> <session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></stream:features>
步驟 1: 服務器1 發起一個流給 服務器2
<stream:stream xmlns='jabber:server' xmlns:stream='http://etherx.jabber.org/streams' to='example.com' version='1.0'>
步驟 2: 服務器2 回應一個流標簽給 服務器1
<stream:stream xmlns='jabber:server' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='s2s_234' version='1.0'>
步驟 3: 服務器2 通知 服務器1 可用的驗證機制
<stream:features> <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <mechanism>DIGEST-MD5</mechanism> <mechanism>KERBEROS_V4</mechanism> </mechanisms></stream:features>
步驟 4: 服務器1 選擇一個驗證機制
<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/>
步驟 5: 服務器2 發送一個[BASE64]編碼的挑戰給 服務器1
<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> cmVhbG09InNvbWVyZWFsbSIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixxb3A9 ImF1dGgiLGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNz</challenge>
解碼后的挑戰信息是
realm="somerealm",nonce="OA6MG9tEQGm2hh",/qop="auth",charset=utf-8,algorithm=md5-sess步驟 5 (替代): 服務器2 返回一個錯誤給 服務器1
<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <incorrect-encoding/> </failure></stream:stream>
步驟 6: 服務器1 發送一個[BASE64]編碼的回應這個挑戰
<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> dXNlcm5hbWU9ImV4YW1wbGUub3JnIixyZWFsbT0ic29tZXJlYWxtIixub25j ZT0iT0E2TUc5dEVRR20yaGgiLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLG5j PTAwMDAwMDAxLHFvcD1hdXRoLGRpZ2VzdC11cmk9InhtcHAvZXhhbXBsZS5v cmciLHJlc3BvbnNlPWQzODhkYWQ5MGQ0YmJkNzYwYTE1MjMyMWYyMTQzYWY3 LGNoYXJzZXQ9dXRmLTgK</response>
解碼后的應答信息是
username="example.org",realm="somerealm",/ nonce="OA6MG9tEQGm2hh",cnonce="OA6MHXh6VqTrRk",/ nc=00000001,qop=auth,digest-uri="xmpp/example.org",/ response=d388dad90d4bbd760a152321f2143af7,charset=utf-8步驟 7: 服務器2 發送另外一個[BASE64]編碼的挑戰給 服務器1
<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> cnNwYXV0aD1lYTQwZjYwMzM1YzQyN2I1NTI3Yjg0ZGJhYmNkZmZmZAo=</challenge>
解碼后的挑戰信息是
rspauth=ea40f60335c427b5527b84dbabcdfffd
步驟 7 (或者): 服務器2 返回一個錯誤給 服務器1
<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <invalid-authzid/> </failure></stream:stream>
步驟 8: 服務器1 回應挑戰
<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
步驟 8 (或者): 服務器1 中止協商
<abort xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
步驟 9: 服務器2 通知 服務器1 驗證成功
<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
步驟 9 (或者): 服務器2 通知 服務器1 驗證失敗
<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> <aborted/> </failure></stream:stream>
步驟 10: 服務器1 重新發起一個新的流給 服務器2
<stream:stream xmlns='jabber:server' xmlns:stream='http://etherx.jabber.org/streams' to='example.com' version='1.0'>
步驟 11: 服務器2 發送一個流頭信息應答 服務器1 ,并附上任何可用的特性(或一個空的features元素).:
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='s2s_345' version='1.0'><stream:features/>
PS:資源文件來自Jabber /XMPP中文翻譯計劃
新聞熱點
疑難解答