diff options
| author | Azul <azul@riseup.net> | 2012-10-04 10:47:19 +0200 | 
|---|---|---|
| committer | Azul <azul@riseup.net> | 2012-10-04 10:47:19 +0200 | 
| commit | 66c3ed01eb012cae84193b4864c7c48eb77c2a8c (patch) | |
| tree | b23d69a19f60cc46a1baa4328cb34c703bea4bbf /lib/srp | |
| parent | c73f7c1b4c1270d4d0ca47650a12893a6d13e796 (diff) | |
more cleanup - no more duplicate password and username in Client
A client has a set of pwd and login and tries to auth with this.
Diffstat (limited to 'lib/srp')
| -rw-r--r-- | lib/srp/client.rb | 22 | 
1 files changed, 12 insertions, 10 deletions
| diff --git a/lib/srp/client.rb b/lib/srp/client.rb index 22ed9f7..de17fb3 100644 --- a/lib/srp/client.rb +++ b/lib/srp/client.rb @@ -10,31 +10,33 @@ module SRP      def initialize(username, password, salt = nil)        @username = username        @password = password -      @salt = (salt || bigrand(4)).hex +      @salt = salt || bigrand(4).hex        @multiplier = multiplier # let's cache it        calculate_verifier      end -    def authenticate(server, username, password) -      x = calculate_x(username, password) +    def authenticate(server)        a = bigrand(32).hex        aa = modpow(GENERATOR, a) # A = g^a (mod N) -      bb = server.handshake(username, aa) +      bb = server.handshake(@username, aa)        u = calculate_u(aa, bb) -      client_s = calculate_client_s(x, a, bb, u) +      client_s = calculate_client_s(private_key, a, bb, u)        server.validate(calculate_m(aa, bb, client_s))      end      protected +      def calculate_verifier -      x = calculate_x -      @verifier = modpow(GENERATOR, x) -      @verifier +      @verifier ||= modpow(GENERATOR, private_key) +    end + +    def private_key +      @private_key ||= calculate_private_key      end -    def calculate_x(username = @username, password = @password) +    def calculate_private_key        shex = '%x' % [@salt] -      inner = sha256_str([username, password].join(':')) +      inner = sha256_str([@username, @password].join(':'))        sha256_hex(shex, inner).hex      end | 
