Class: SRP::Session
Constant Summary
Constants included from Util
Util::BIG_PRIME_N, Util::GENERATOR, Util::PRIME_N
Instance Attribute Summary collapse
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #aa ⇒ Object
- #authenticate(client_auth) ⇒ Object
- #authenticate!(client_auth) ⇒ Object
-
#bb ⇒ Object
B = g^b + k v (mod N).
-
#handshake(server) ⇒ Object
client -> server: I, A = g^a.
-
#initialize(user, aa = nil) ⇒ Session
constructor
params: user: user object that represents and account (username, salt, verifier) aa: SRPs A ephemeral value.
-
#internal_state ⇒ Object
for debugging use:.
- #to_hash ⇒ Object
- #to_json(options = {}) ⇒ Object
-
#validate(server) ⇒ Object
client -> server: M = H(H(N) xor H(g), H(I), s, A, B, K).
Methods included from Util
#bigrand, #hn_xor_hg, #modpow, #multiplier, #sha256_hex, #sha256_int, #sha256_str
Constructor Details
#initialize(user, aa = nil) ⇒ Session
params: user: user object that represents and account (username, salt, verifier) aa: SRPs A ephemeral value. encoded as a hex string.
9 10 11 12 |
# File 'lib/srp/session.rb', line 9 def initialize(user, aa=nil) @user = user aa ? initialize_server(aa) : initialize_client end |
Instance Attribute Details
#user ⇒ Object
Returns the value of attribute user.
4 5 6 |
# File 'lib/srp/session.rb', line 4 def user @user end |
Instance Method Details
#aa ⇒ Object
65 66 67 |
# File 'lib/srp/session.rb', line 65 def aa @aa ||= modpow(GENERATOR, @a).to_s(16) # A = g^a (mod N) end |
#authenticate(client_auth) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/srp/session.rb', line 28 def authenticate(client_auth) if(client_auth == m) @authenticated = true return @user end end |
#authenticate!(client_auth) ⇒ Object
24 25 26 |
# File 'lib/srp/session.rb', line 24 def authenticate!(client_auth) authenticate(client_auth) || raise(SRP::WrongPassword) end |
#bb ⇒ Object
B = g^b + k v (mod N)
70 71 72 |
# File 'lib/srp/session.rb', line 70 def bb @bb ||= calculate_bb.to_s(16) end |
#handshake(server) ⇒ Object
client -> server: I, A = g^a
15 16 17 |
# File 'lib/srp/session.rb', line 15 def handshake(server) @bb = server.handshake(user.username, aa) end |
#internal_state ⇒ Object
for debugging use:
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/srp/session.rb', line 51 def internal_state { username: @user.username, salt: @user.salt.to_s(16), verifier: @user.verifier.to_s(16), aa: aa, bb: bb, s: secret.to_s(16), k: k, m: m, m2: m2 } end |
#to_hash ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/srp/session.rb', line 35 def to_hash if @authenticated { :M2 => m2 } else { :B => bb, # :b => @b.to_s(16), # only use for debugging :salt => @user.salt.to_s(16) } end end |
#to_json(options = {}) ⇒ Object
46 47 48 |
# File 'lib/srp/session.rb', line 46 def to_json(={}) to_hash.to_json() end |
#validate(server) ⇒ Object
client -> server: M = H(H(N) xor H(g), H(I), s, A, B, K)
20 21 22 |
# File 'lib/srp/session.rb', line 20 def validate(server) server.validate(m) end |