Sha256: 8fe641d58160b31af9d60599a4d3e760e7b31a31fef9d2bcaa673e5340aa8567

Contents?: true

Size: 893 Bytes

Versions: 5

Compression:

Stored size: 893 Bytes

Contents

module SRP
  class Client

    include SRP::Util

    attr_reader :salt, :verifier, :username

    def initialize(username, options)
      @username = username
      if options[:password]
        @password = options[:password]
        @salt = options[:salt] || bigrand(4).hex
        calculate_verifier
      else
        @verifier = options[:verifier]
        @salt = options[:salt]
      end
    end

    def authenticate(server)
      @session = SRP::Session.new(self)
      @session.handshake(server)
      @session.validate(server)
    end

    def private_key
      @private_key ||= calculate_private_key
    end

    protected

    def calculate_verifier
      @verifier ||= modpow(GENERATOR, private_key)
    end

    def calculate_private_key
      shex = '%x' % [@salt]
      inner = sha256_str([@username, @password].join(':'))
      sha256_hex(shex, inner).hex
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-srp-0.2.1 lib/srp/client.rb
ruby-srp-0.2.0 lib/srp/client.rb
ruby-srp-0.1.7 lib/srp/client.rb
ruby-srp-0.1.6 lib/srp/client.rb
ruby-srp-0.1.5 lib/srp/client.rb