Class: SRP::Verifier
- Inherits:
-
Object
- Object
- SRP::Verifier
- Defined in:
- lib/srp-rb.rb
Instance Attribute Summary collapse
-
#A ⇒ Object
readonly
Returns the value of attribute A.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#B ⇒ Object
readonly
Returns the value of attribute B.
-
#g ⇒ Object
readonly
Returns the value of attribute g.
-
#H_AMK ⇒ Object
readonly
Returns the value of attribute H_AMK.
-
#k ⇒ Object
readonly
Returns the value of attribute k.
-
#K ⇒ Object
readonly
Returns the value of attribute K.
-
#M ⇒ Object
readonly
Returns the value of attribute M.
-
#N ⇒ Object
readonly
Returns the value of attribute N.
-
#S ⇒ Object
readonly
Returns the value of attribute S.
Instance Method Summary collapse
-
#generate_B(xverifier) ⇒ Object
generates challenge input verifier in hex.
-
#generate_userauth(username, password) ⇒ Object
Initial user creation for the persistance layer.
-
#get_challenge_and_proof(username, xverifier, xsalt, xaa) ⇒ Object
Authentication phase 1 - create challenge.
-
#initialize(group = 1024, hash = 'sha-1') ⇒ Verifier
constructor
A new instance of Verifier.
- #random_bignum ⇒ Object
- #random_salt ⇒ Object
-
#verify_session(proof, client_M) ⇒ Object
returns H_AMK on success, None on failure User -> Host: M = H(H(N) xor H(g), H(I), s, A, B, K) Host -> User: H(A, M, K).
Constructor Details
#initialize(group = 1024, hash = 'sha-1') ⇒ Verifier
Returns a new instance of Verifier.
339 340 341 342 343 344 |
# File 'lib/srp-rb.rb', line 339 def initialize(group = 1024, hash = 'sha-1') # select modulus (N) and generator (g) @N, @g = SRP.Ng(group) @hash = hash @k = SRP.calc_k(@N, @g, @hash) end |
Instance Attribute Details
#A ⇒ Object (readonly)
Returns the value of attribute A.
337 338 339 |
# File 'lib/srp-rb.rb', line 337 def A @A end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
337 338 339 |
# File 'lib/srp-rb.rb', line 337 def b @b end |
#B ⇒ Object (readonly)
Returns the value of attribute B.
337 338 339 |
# File 'lib/srp-rb.rb', line 337 def B @B end |
#g ⇒ Object (readonly)
Returns the value of attribute g.
337 338 339 |
# File 'lib/srp-rb.rb', line 337 def g @g end |
#H_AMK ⇒ Object (readonly)
Returns the value of attribute H_AMK.
337 338 339 |
# File 'lib/srp-rb.rb', line 337 def H_AMK @H_AMK end |
#k ⇒ Object (readonly)
Returns the value of attribute k.
337 338 339 |
# File 'lib/srp-rb.rb', line 337 def k @k end |
#K ⇒ Object (readonly)
Returns the value of attribute K.
337 338 339 |
# File 'lib/srp-rb.rb', line 337 def K @K end |
#M ⇒ Object (readonly)
Returns the value of attribute M.
337 338 339 |
# File 'lib/srp-rb.rb', line 337 def M @M end |
#N ⇒ Object (readonly)
Returns the value of attribute N.
337 338 339 |
# File 'lib/srp-rb.rb', line 337 def N @N end |
#S ⇒ Object (readonly)
Returns the value of attribute S.
337 338 339 |
# File 'lib/srp-rb.rb', line 337 def S @S end |
Instance Method Details
#generate_B(xverifier) ⇒ Object
generates challenge input verifier in hex
416 417 418 419 420 |
# File 'lib/srp-rb.rb', line 416 def generate_B xverifier v = xverifier.to_i(16) @b ||= random_bignum @B = "%x" % SRP.calc_B(@b, k, v, @N, @g) end |
#generate_userauth(username, password) ⇒ Object
Initial user creation for the persistance layer. Not part of the authentication process. Returns { <username>, <password verifier>, <salt> }
349 350 351 352 353 354 355 |
# File 'lib/srp-rb.rb', line 349 def generate_userauth username, password @salt ||= random_salt # warn "salt: #{@salt}" x = SRP.calc_x(username, password, @salt, @hash) v = SRP.calc_v(x, @N, @g) return {:username => username, :verifier => "%x" % v, :salt => @salt} end |
#get_challenge_and_proof(username, xverifier, xsalt, xaa) ⇒ Object
Authentication phase 1 - create challenge. Returns Hash with challenge for client and proof to be stored on server. Parameters should be given in hex.
360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/srp-rb.rb', line 360 def get_challenge_and_proof username, xverifier, xsalt, xaa # SRP-6a safety check return false if (xaa.to_i(16) % @N) == 0 generate_B(xverifier) # warn "A: #{xaa}" return { :challenge => {:B => @B, :salt => xsalt}, :proof => {:A => xaa, :B => @B, :b => "%x" % @b, :I => username, :s => xsalt, :v => xverifier} } end |
#random_bignum ⇒ Object
410 411 412 |
# File 'lib/srp-rb.rb', line 410 def random_bignum SRP.bigrand(32).hex end |
#random_salt ⇒ Object
406 407 408 |
# File 'lib/srp-rb.rb', line 406 def random_salt "%x" % SRP.bigrand(16).hex end |
#verify_session(proof, client_M) ⇒ Object
returns H_AMK on success, None on failure User -> Host: M = H(H(N) xor H(g), H(I), s, A, B, K) Host -> User: H(A, M, K)
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/srp-rb.rb', line 375 def verify_session proof, client_M @A = proof[:A] @B = proof[:B] @b = proof[:b].to_i(16) # warn "b: #{@b}" username = proof[:I] xsalt = proof[:s] v = proof[:v].to_i(16) u = SRP.calc_u(@A, @B, @N, @hash) # SRP-6a safety check return false if u == 0 # calculate session key @S = "%x" % SRP.calc_server_S(@A.to_i(16), @b, v, u, @N) @K = SRP.sha1_hex(@S, @hash) # warn "K: #{@K}" # calculate match @M = "%x" % SRP.calc_M1(@A, @B, @K, @N, @hash) if @M == client_M # authentication succeeded @H_AMK = "%x" % SRP.calc_M2(@A, @M, @K, @N, @hash) return @H_AMK end return false end |