Class: SRP::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/srp-rb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, hash) ⇒ Client

Returns a new instance of Client.



427
428
429
430
431
432
# File 'lib/srp-rb.rb', line 427

def initialize(group, hash)
  # select modulus (N) and generator (g)
  @N, @g = SRP.Ng(group)
  @hash = hash
  @k = SRP.calc_k(@N, @g, @hash)
end

Instance Attribute Details

#AObject (readonly)

Returns the value of attribute A.



425
426
427
# File 'lib/srp-rb.rb', line 425

def A
  @A
end

#aObject (readonly)

Returns the value of attribute a.



425
426
427
# File 'lib/srp-rb.rb', line 425

def a
  @a
end

#gObject (readonly)

Returns the value of attribute g.



425
426
427
# File 'lib/srp-rb.rb', line 425

def g
  @g
end

#H_AMKObject (readonly)

Returns the value of attribute H_AMK.



425
426
427
# File 'lib/srp-rb.rb', line 425

def H_AMK
  @H_AMK
end

#kObject (readonly)

Returns the value of attribute k.



425
426
427
# File 'lib/srp-rb.rb', line 425

def k
  @k
end

#KObject (readonly)

Returns the value of attribute K.



425
426
427
# File 'lib/srp-rb.rb', line 425

def K
  @K
end

#MObject (readonly)

Returns the value of attribute M.



425
426
427
# File 'lib/srp-rb.rb', line 425

def M
  @M
end

#NObject (readonly)

Returns the value of attribute N.



425
426
427
# File 'lib/srp-rb.rb', line 425

def N
  @N
end

#SObject (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_AObject



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_bignumObject



472
473
474
# File 'lib/srp-rb.rb', line 472

def random_bignum
  SRP.bigrand(32).hex
end

#start_authenticationObject



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