JEP-0078: Non-SASL Authentication
?
SASL:Simple Authentication and Security Layer 簡單的認(rèn)證及加密層
?
1、客戶端向服務(wù)器端發(fā)送XML流 |
<stream:stream to='shakespeare.lit' ???? xmlns='jabber:client' ?????????????? xmlns:stream='http://etherx.jabber.org/streams'> |
?
?
2、服務(wù)器返回消息 |
<iq type='get' to='shakespeare.lit' id='auth1'> ?<query xmlns='jabber:iq:auth'/> </iq> |
注意中間的ID,這個ID是服務(wù)器端返回給客戶端的驗證信息,驗證信息一般是以該ID號+用戶密碼通過SHA1(RFC3174)算法進(jìn)行操作的。也就是說客戶端得到該ID和密碼經(jīng)過SHA1算法加密后返回給服務(wù)器。 |
?
?
3、客戶端想服務(wù)器提交請求獲取登錄需要驗證的字段 |
<iq type='get' to='shakespeare.lit' id='auth1'> ?<query xmlns='jabber:iq:auth'/> </iq> |
?
?
4、服務(wù)器返回登錄需要驗證的字段 |
<iq type='result' id='auth1'> ?<query xmlns='jabber:iq:auth'> ??? <username/> ??? <password/> ??? <digest/>?這個digest就是上面經(jīng)過SHA1算法得出的結(jié)果字段 ??? <resource/> ?</query> </iq> |
如果客戶端發(fā)送的字段包括了用戶名和IQ-GET的字段,服務(wù)器不應(yīng)該返回錯誤消息(因為需要服務(wù)器判斷當(dāng)前用戶名是否在使用),如果服務(wù)器不支持可插入的簡單認(rèn)證及密碼模塊,那么必須返回一個<service-unavailable/>的錯誤;如果客戶端企圖使用SASL認(rèn)證但是失敗,服務(wù)器必須返回<policy-violation/>錯誤信息 在認(rèn)證過程中,jabber:iq:auth命名、用戶名和資源是必須要求客戶端提供的,而服務(wù)器返回的XML流中也必須提供<username/>和<resource/>這2個元素。 |
?
?
5、客戶端提交字段內(nèi)容進(jìn)行驗證 |
文本格式,非加密模式 <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、登錄結(jié)果 |
成功 <iq type='result' id='auth2'/> 失敗 – 認(rèn)證失敗,可能是用戶名密碼不匹配或數(shù)字驗證錯誤 <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