Class: CryptoToolchain::SRP::Client
- Includes:
- Framework
- Defined in:
- lib/crypto_toolchain/srp/client.rb
Direct Known Subclasses
Constant Summary
Constants included from Framework
Instance Attribute Summary collapse
-
#authenticated ⇒ Object
(also: #authenticated?)
readonly
Returns the value of attribute authenticated.
-
#server_pubkey ⇒ Object
readonly
Returns the value of attribute server_pubkey.
Attributes included from Framework
#email, #g, #k, #key, #n, #password, #privkey, #pubkey, #salt, #socket
Instance Method Summary collapse
- #authentication_success_received ⇒ Object
- #calculate_secret ⇒ Object
- #hello_received(_salt, _server_pubkey) ⇒ Object
-
#initialize(**kargs) ⇒ Client
constructor
A new instance of Client.
- #send_hello ⇒ Object
- #send_verify ⇒ Object
Methods included from Framework
#error_received, #event_loop, #go!, #shutdown_received, #write_message
Constructor Details
#initialize(**kargs) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/crypto_toolchain/srp/client.rb', line 9 def initialize(**kargs) provided_pubkey = kargs.delete(:pubkey) super(**kargs) @pubkey = provided_pubkey || g.modpow(privkey, n) end |
Instance Attribute Details
#authenticated ⇒ Object (readonly) Also known as: authenticated?
Returns the value of attribute authenticated.
6 7 8 |
# File 'lib/crypto_toolchain/srp/client.rb', line 6 def authenticated @authenticated end |
#server_pubkey ⇒ Object (readonly)
Returns the value of attribute server_pubkey.
6 7 8 |
# File 'lib/crypto_toolchain/srp/client.rb', line 6 def server_pubkey @server_pubkey end |
Instance Method Details
#authentication_success_received ⇒ Object
33 34 35 36 37 |
# File 'lib/crypto_toolchain/srp/client.rb', line 33 def authentication_success_received @authenticated = true ("shutdown") raise ShutdownSignal end |
#calculate_secret ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/crypto_toolchain/srp/client.rb', line 39 def calculate_secret return 0 if [0, n, n**2, n**3].include?(pubkey) xH = Digest::SHA256.hexdigest("#{salt}#{password}") x = xH.to_i(16) uH = Digest::SHA256.hexdigest("#{pubkey}#{server_pubkey}") u = uH.to_i(16) # S = (B - k * g**x)**(a + u * x) % N (server_pubkey - k * g.modpow(x, n)).modpow(privkey + u * x, n) end |
#hello_received(_salt, _server_pubkey) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/crypto_toolchain/srp/client.rb', line 24 def hello_received(_salt, _server_pubkey) @salt = _salt.to_i @server_pubkey = _server_pubkey.to_i secret = calculate_secret puts "Client generated secret #{secret}" if DEBUG @key = Digest::SHA256.hexdigest(secret.to_s) send_verify end |
#send_hello ⇒ Object
15 16 17 |
# File 'lib/crypto_toolchain/srp/client.rb', line 15 def send_hello ("hello", email, pubkey) end |
#send_verify ⇒ Object
19 20 21 22 |
# File 'lib/crypto_toolchain/srp/client.rb', line 19 def send_verify hmac = OpenSSL::HMAC.hexdigest("SHA256", key.to_s, salt.to_s) ("verify", hmac) end |