blob: 91bbffc93b13c946046543c3a98f5d0481207e71 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
class User
def self.current
@current
end
def self.current=(user)
@current = user
end
attr_accessor :login
attr_accessor :salt
attr_accessor :verifier
attr_accessor :active
attr_accessor :srp
def initialize(login)
self.login = login
self.salt = "5d3055e0acd3ddcfc15".hex
# OpenSSL::Random.random_bytes(10).unpack("H*")[0]
self.active = false
User.current = self
end
def initialize_auth(params)
self.srp = SRP::Server.new(self.salt, self.verifier)
bb, u = self.srp.initialize_auth(params.delete('A').hex)
return {:s => self.salt.to_s(16), :B => bb.to_s(16)}
end
def authenticate(params)
if m2 = self.srp.authenticate(params.delete('M').hex)
self.active = true
return {:M => m2.to_s(16)}
else
self.active = false
return {:error => "Access Denied"}
end
end
end
|