SRP6 java版本 密碼驗證

在遊戲賬號登陸過程中,我們需要對賬號密碼做驗證的同時,還要防止有可能被黑客截取協議數據,盜取賬號密碼.通常會要使用一些加密算法和協議防止密碼的泄漏.

在這裏要推薦的就是SRP6.

SRP全稱Secure Remote Password(安全遠程密碼).使用SRP的客戶機和服務器不會在網絡上傳送明文密碼,這樣可以消除直接密碼嗅探行爲,另外使用高強度的算法保證了不可能使用字典法攻擊嗅探到的數據.

開源的MaNGOS-Zero也使用的是這個算法做賬號密碼的校驗:

http://www.cnblogs.com/ychellboy/archive/2011/10/30/2229509.html


而在這裏要說的就是SRP的java版本

http://www.jordanzimmerman.com/index.php?n=2


首先下載 SRP Library. 得到SRP_1_0.zip,裏面有三個目錄

+doc

+example

+src


想必大家都知道接下來要幹什麼了,直接運行裏面的example看看到底怎麼使用srp

example.java裏面很直觀的告訴了我們要如何操作srp做加密和驗證


運行它的main方法,輸入help

 

 

Mode must be one of the following values:

password: outputs a verifier (v and s) for the given password.

server: runs an example server (that repeats all lines sent to it). You will be asked for the server port and the v and s values.

client: runs an example client (that sends lines to the server). You will be asked for the server port and address and the password.

runner server: runs a server that directly uses the runner APIs. This server is not TCP/IP. You must copy/paste values to/from the client.

runner client: runs a client that directly uses the runner APIs. This client is not TCP/IP. You must copy/paste values to/from the client.

manual server: runs a server that uses the low level SRP APIs. This server is not TCP/IP. You must copy/paste values to/from the client.

manual client: runs a client that uses the low level SRP APIs. This client is not TCP/IP. You must copy/paste values to/from the client.
 

password//通過明文獲取v和s值

server//建立一個server示例,需要設置端口,v和s值

client//建立一個client示例,通過使用密碼連接server

上面這兩個是一對,驗證密碼後,在客戶端輸入任意字符串,服務器會返回對應的字符串.按我的理解應該是協議加密的使用方式

runner server

runner client

這兩個是一對,這裏要注意的是運行這對示例的時候,需要兩邊複製值完成校驗.按我的理解其實就是manual的一種版本沒有顯示A,B,M1,M2而已


manual server

manual client

這兩個是要手動輸入v和s值,一步一步校驗.

下面的協議邏輯也主要根據這個示例來得以實現.


協議設定順序:

客戶端                                                                      服務器


賬號 c->s 根據賬號從數據庫取出v和s值

//這裏要注意的是Mangos保存了密碼p, 是錯誤的. 服務器不應該保存密碼或其散列值.

//應該在創建用戶時, 由客戶端取s值, 計算v, 將{I, s, v}傳輸到服務器並保存.(I==賬號名)
//登錄時, 特定用戶的s, v應該是固定的, 從數據庫讀取, 而不是每次登錄時隨機.


客戶端得到 s和B值     c<-s                         從數據庫取出s,v後把s和公鑰B下發


//客戶端通過 服務器下發的S值獲取到公鑰A,通過服務器下發的公鑰B得到M1值



客戶端發送公鑰A和M1   c->s                     服務器用得到的公鑰A和M1做校驗


//服務器校驗M1值


客戶端獲取登陸結果     c-<s                         服務器下發驗證結果




附件包含了上述邏輯的一個測試用例,有興趣的朋友可以下載看看

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章