Class: CryptoToolchain::SRP::Server

Inherits:
Object
  • Object
show all
Includes:
Framework
Defined in:
lib/crypto_toolchain/srp/server.rb

Direct Known Subclasses

SimpleServer

Constant Summary

Constants included from Framework

Framework::EVENT_WHITELIST

Instance Attribute Summary collapse

Attributes included from Framework

#email, #g, #k, #key, #n, #password, #privkey, #pubkey, #salt, #socket

Instance Method Summary collapse

Methods included from Framework

#error_received, #event_loop, #go!, #shutdown_received, #write_message

Constructor Details

#initialize(**kargs) ⇒ Server

Returns a new instance of Server.



8
9
10
11
12
13
14
15
# File 'lib/crypto_toolchain/srp/server.rb', line 8

def initialize(**kargs)
  super(**kargs)
  @salt = rand(1..0xffffffff)
  xH = Digest::SHA256.hexdigest("#{salt}#{password}")
  x = xH.to_i(16)
  @v = g.modpow(x, n)
  @pubkey = k*v + g.modpow(privkey, n)
end

Instance Attribute Details

#client_pubkeyObject (readonly)

Returns the value of attribute client_pubkey.



6
7
8
# File 'lib/crypto_toolchain/srp/server.rb', line 6

def client_pubkey
  @client_pubkey
end

#vObject (readonly)

Returns the value of attribute v.



6
7
8
# File 'lib/crypto_toolchain/srp/server.rb', line 6

def v
  @v
end

Instance Method Details

#hello_received(email, _client_pubkey) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/crypto_toolchain/srp/server.rb', line 17

def hello_received(email, _client_pubkey)
  @client_pubkey = _client_pubkey.to_i
  write_message("hello", salt, pubkey)
  uH = Digest::SHA256.hexdigest("#{client_pubkey}#{pubkey}")
  u = uH.to_i(16)
  #  S = (A * v**u) ** b % N
  secret = (client_pubkey * v.modpow(u, n)).modpow(privkey, n)
  puts "Server generated secret #{secret}" if DEBUG
  @key = Digest::SHA256.hexdigest(secret.to_s)
end

#verify_received(hmac) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/crypto_toolchain/srp/server.rb', line 28

def verify_received(hmac)
  valid_hmac = OpenSSL::HMAC.hexdigest("SHA256", key.to_s, salt.to_s)
  if hmac == valid_hmac
    write_message("authentication_success")
  else
    write_message("error", "invalid_hmac")
  end
end