Class: RubyHome::SRP::Client
- Inherits:
-
SRP::Client
- Object
- SRP::Client
- RubyHome::SRP::Client
- Defined in:
- lib/ruby_home-srp.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
writeonly
Sets the attribute a.
Instance Method Summary collapse
-
#initialize(group = 3072) ⇒ Client
constructor
A new instance of Client.
-
#process_challenge(username, password, xsalt, xbb) ⇒ String
Phase 2 : Step 1 : Process the salt and B values provided by the server.
-
#start_authentication ⇒ String
Phase 1 : Step 1 : Start the authentication process by generating the client ‘a’ and ‘A’ values.
Constructor Details
#initialize(group = 3072) ⇒ Client
Returns a new instance of Client.
183 184 185 186 187 |
# File 'lib/ruby_home-srp.rb', line 183 def initialize group=3072 # select modulus (N) and generator (g) @N, @g = SRP.Ng group @k = SRP.calc_k(@N, @g) end |
Instance Attribute Details
#a=(value) ⇒ Object (writeonly)
Sets the attribute a
181 182 183 |
# File 'lib/ruby_home-srp.rb', line 181 def a=(value) @a = value end |
Instance Method Details
#process_challenge(username, password, xsalt, xbb) ⇒ String
Phase 2 : Step 1 : Process the salt and B values provided by the server.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/ruby_home-srp.rb', line 207 def process_challenge(username, password, xsalt, xbb) raise ArgumentError, 'username must be a string' unless username.is_a?(String) && !username.empty? raise ArgumentError, 'password must be a string' unless password.is_a?(String) && !password.empty? raise ArgumentError, 'xsalt must be a string' unless xsalt.is_a?(String) raise ArgumentError, 'xsalt must be a hex string' unless xsalt =~ /^[a-fA-F0-9]+$/ raise ArgumentError, 'xbb must be a string' unless xbb.is_a?(String) raise ArgumentError, 'xbb must be a hex string' unless xbb =~ /^[a-fA-F0-9]+$/ # Convert the 'B' hex value to an Integer bb = xbb.to_i(16) # SRP-6a safety check return false if (bb % @N).zero? x = SRP.calc_x(username, password, xsalt) u = SRP.calc_u(@A, xbb, @N) # SRP-6a safety check return false if u.zero? # Calculate session key 'S' and secret key 'K' @S = '%x' % SRP.calc_client_S(bb, @a, @k, x, u, @N, @g.hex) @K = SRP.sha512_hex(@S) # Calculate the 'M' matcher @M = SRP.calc_M(username, xsalt, @A, xbb, @K, @N, @g) # Calculate the H(A,M,K) verifier @H_AMK = '%x' % SRP.calc_H_AMK(@A, '%x' % @M, @K, @N, @g) # Return the 'M' matcher to be sent to the server '%x' % @M end |
#start_authentication ⇒ String
Phase 1 : Step 1 : Start the authentication process by generating the client ‘a’ and ‘A’ values. Public ‘A’ should later be sent along with the username, to the server verifier to continue the auth process. The internal secret ‘a’ value should remain private.
195 196 197 198 |
# File 'lib/ruby_home-srp.rb', line 195 def start_authentication @a ||= SecureRandom.hex(32).hex @A = "%x" % SRP.calc_A(@a, @N, @g.hex) end |