Class: CryptoToolchain::SRP::Server
- Includes:
- Framework
- Defined in:
- lib/crypto_toolchain/srp/server.rb
Direct Known Subclasses
Constant Summary
Constants included from Framework
Instance Attribute Summary collapse
-
#client_pubkey ⇒ Object
readonly
Returns the value of attribute client_pubkey.
-
#v ⇒ Object
readonly
Returns the value of attribute v.
Attributes included from Framework
#email, #g, #k, #key, #n, #password, #privkey, #pubkey, #salt, #socket
Instance Method Summary collapse
- #hello_received(email, _client_pubkey) ⇒ Object
-
#initialize(**kargs) ⇒ Server
constructor
A new instance of Server.
- #verify_received(hmac) ⇒ Object
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_pubkey ⇒ Object (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 |
#v ⇒ Object (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 ("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 ("authentication_success") else ("error", "invalid_hmac") end end |