Class: SRP::Client
- Inherits:
-
Object
- Object
- SRP::Client
- Defined in:
- lib/srp-rb.rb
Instance Attribute Summary collapse
-
#A ⇒ Object
readonly
Returns the value of attribute A.
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#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_A ⇒ Object
-
#initialize(group, hash) ⇒ Client
constructor
A new instance of Client.
-
#process_challenge(username, password, xsalt, xbb) ⇒ Object
Process initiated authentication challenge.
- #random_bignum ⇒ Object
- #start_authentication ⇒ Object
- #verify(server_HAMK) ⇒ Object
Constructor Details
Instance Attribute Details
#A ⇒ Object (readonly)
Returns the value of attribute A.
425 426 427 |
# File 'lib/srp-rb.rb', line 425 def A @A end |
#a ⇒ Object (readonly)
Returns the value of attribute a.
425 426 427 |
# File 'lib/srp-rb.rb', line 425 def a @a end |
#g ⇒ Object (readonly)
Returns the value of attribute g.
425 426 427 |
# File 'lib/srp-rb.rb', line 425 def g @g end |
#H_AMK ⇒ Object (readonly)
Returns the value of attribute H_AMK.
425 426 427 |
# File 'lib/srp-rb.rb', line 425 def H_AMK @H_AMK end |
#k ⇒ Object (readonly)
Returns the value of attribute k.
425 426 427 |
# File 'lib/srp-rb.rb', line 425 def k @k end |
#K ⇒ Object (readonly)
Returns the value of attribute K.
425 426 427 |
# File 'lib/srp-rb.rb', line 425 def K @K end |
#M ⇒ Object (readonly)
Returns the value of attribute M.
425 426 427 |
# File 'lib/srp-rb.rb', line 425 def M @M end |
#N ⇒ Object (readonly)
Returns the value of attribute N.
425 426 427 |
# File 'lib/srp-rb.rb', line 425 def N @N end |
#S ⇒ Object (readonly)
Returns the value of attribute S.
425 426 427 |
# File 'lib/srp-rb.rb', line 425 def S @S end |
Instance Method Details
#generate_A ⇒ Object
476 477 478 479 480 |
# File 'lib/srp-rb.rb', line 476 def generate_A @a ||= random_bignum # warn "a: #{@a}" @A = "%x" % SRP.calc_A(@a, @N, @g) end |
#process_challenge(username, password, xsalt, xbb) ⇒ Object
Process initiated authentication challenge. Returns M if authentication is successful, false otherwise. Salt and B should be given in hex.
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/srp-rb.rb', line 443 def process_challenge username, password, xsalt, xbb bb = xbb.to_i(16) # SRP-6a safety check return false if (bb % @N) == 0 x = SRP.calc_x(username, password, xsalt, @hash) u = SRP.calc_u(@A, xbb, @N, @hash) # SRP-6a safety check return false if u == 0 # calculate session key @S = "%x" % SRP.calc_client_S(bb, @a, @k, x, u, @N, @g) @K = SRP.sha1_hex(@S, hash) # calculate match @M = "%x" % SRP.calc_M1(@A, xbb, @K, @N, @hash) # calculate verifier @H_AMK = "%x" % SRP.calc_M2(@A, @M, @K, @N, @hash) return @M end |
#random_bignum ⇒ Object
472 473 474 |
# File 'lib/srp-rb.rb', line 472 def random_bignum SRP.bigrand(32).hex end |
#start_authentication ⇒ Object
434 435 436 437 438 |
# File 'lib/srp-rb.rb', line 434 def start_authentication a = generate_A # warn "A: #{a.to_s(16)}" a end |
#verify(server_HAMK) ⇒ Object
467 468 469 470 |
# File 'lib/srp-rb.rb', line 467 def verify server_HAMK return false unless @H_AMK @H_AMK == server_HAMK end |