diff options
author | Azul <azul@riseup.net> | 2012-10-04 11:23:00 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2012-10-04 11:41:53 +0200 |
commit | 0e5f57d3e07db606a779485e1537d4db8b5d3da2 (patch) | |
tree | 90733e690fac48da221f3fa7db04aa23ba5423b7 /lib/srp/client.rb | |
parent | 66c3ed01eb012cae84193b4864c7c48eb77c2a8c (diff) |
created session class to hold aa, bb and so forth - done for client
We have a session in the server already - duplication there now, merge next
Diffstat (limited to 'lib/srp/client.rb')
-rw-r--r-- | lib/srp/client.rb | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/lib/srp/client.rb b/lib/srp/client.rb index de17fb3..94e36af 100644 --- a/lib/srp/client.rb +++ b/lib/srp/client.rb @@ -5,23 +5,23 @@ module SRP include Util - attr_reader :salt, :verifier + attr_reader :salt, :verifier, :username def initialize(username, password, salt = nil) @username = username @password = password @salt = salt || bigrand(4).hex - @multiplier = multiplier # let's cache it calculate_verifier end def authenticate(server) - a = bigrand(32).hex - aa = modpow(GENERATOR, a) # A = g^a (mod N) - bb = server.handshake(@username, aa) - u = calculate_u(aa, bb) - client_s = calculate_client_s(private_key, a, bb, u) - server.validate(calculate_m(aa, bb, client_s)) + @session = SRP::Session.new(self) + @session.handshake(server) + @session.validate(server) + end + + def private_key + @private_key ||= calculate_private_key end protected @@ -30,23 +30,12 @@ module SRP @verifier ||= modpow(GENERATOR, private_key) end - def private_key - @private_key ||= calculate_private_key - end - def calculate_private_key shex = '%x' % [@salt] inner = sha256_str([@username, @password].join(':')) sha256_hex(shex, inner).hex end - def calculate_client_s(x, a, bb, u) - base = bb - base += BIG_PRIME_N * @multiplier - base -= modpow(GENERATOR, x) * @multiplier - base = base % BIG_PRIME_N - modpow(base, x * u + a) - end end end |