首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

SRP6 java版本 密码应验

2012-10-13 
SRP6 java版本 密码验证在游戏账号登陆过程中,我们需要对账号密码做验证的同时,还要防止有可能被黑客截取

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 ? ? ? ? ? ? ? ? ? ? ? ? 服务器下发验证结果




附件包含了上述逻辑的一个测试用例,有兴趣的朋友可以下载看看

?

热点排行