JEP-0078: Non-SASL Authentication
?
SASL:Simple Authentication and Security Layer 簡單的認證及加密層
?
1、客戶端向服務器端發送XML流 |
<stream:stream to='shakespeare.lit' ???? xmlns='jabber:client' ?????????????? xmlns:stream='http://etherx.jabber.org/streams'> |
?
?
2、服務器返回消息 |
<iq type='get' to='shakespeare.lit' id='auth1'> ?<query xmlns='jabber:iq:auth'/> </iq> |
注意中間的ID,這個ID是服務器端返回給客戶端的驗證信息,驗證信息一般是以該ID號+用戶密碼通過SHA1(RFC3174)算法進行操作的。也就是說客戶端得到該ID和密碼經過SHA1算法加密后返回給服務器。 |
?
?
3、客戶端想服務器提交請求獲取登錄需要驗證的字段 |
<iq type='get' to='shakespeare.lit' id='auth1'> ?<query xmlns='jabber:iq:auth'/> </iq> |
?
?
4、服務器返回登錄需要驗證的字段 |
<iq type='result' id='auth1'> ?<query xmlns='jabber:iq:auth'> ??? <username/> ??? <password/> ??? <digest/>?這個digest就是上面經過SHA1算法得出的結果字段 ??? <resource/> ?</query> </iq> |
如果客戶端發送的字段包括了用戶名和IQ-GET的字段,服務器不應該返回錯誤消息(因為需要服務器判斷當前用戶名是否在使用),如果服務器不支持可插入的簡單認證及密碼模塊,那么必須返回一個<service-unavailable/>的錯誤;如果客戶端企圖使用SASL認證但是失敗,服務器必須返回<policy-violation/>錯誤信息 在認證過程中,jabber:iq:auth命名、用戶名和資源是必須要求客戶端提供的,而服務器返回的XML流中也必須提供<username/>和<resource/>這2個元素。 |
?
?
5、客戶端提交字段內容進行驗證 |
文本格式,非加密模式 <iq type='set' id='auth2'> ?<query xmlns='jabber:iq:auth'> ??? <username>bill</username> ??? <password>Calli0pe</password> ??? <resource>globe</resource> ?</query> </iq> 加密模式 <iq type='set' id='auth2'> ?<query xmlns='jabber:iq:auth'> ??? <username>bill</username> ??? <digest>48fc78be9ec8f86d8ce1c39c320c97c21d62334d</digest> ??? <resource>globe</resource> ?</query> </iq> |
?
6、登錄結果 |
成功 <iq type='result' id='auth2'/> 失敗 – 認證失敗,可能是用戶名密碼不匹配或數字驗證錯誤 <iq type='error' id='auth2'> ?<error code='401' type='auth'> ??? <not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> ?</error> </iq> 失敗 – 資源沖突/錯誤 <iq type='error' id='auth2'> ?<error code='409' type='cancel'> ??? <conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> ?</error> </iq> 失敗 – 沒有提供需要驗證的字段 <iq type='error' id='auth2'> ?<error code='406' type='modify'> ??? <not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> ?</error> </iq> ? ? |
?
其他的就沒什么重要的了,JEP-0078就到此了吧,剩余的重要工作就是如何配置SASL