SASL::DigestMD5

RFC 2831: tools.ietf.org/html/rfc2831

Attributes

cnonce[W]

Public Class Methods

new(*a) click to toggle source
# File lib/sasl/digest_md5.rb, line 10
def initialize(*a)
  super
  @nonce_count = 0
end

Public Instance Methods

receive(message_name, content) click to toggle source
# File lib/sasl/digest_md5.rb, line 25
def receive(message_name, content)
  if message_name == 'challenge'
    c = decode_challenge(content)

    unless c['rspauth']
      response = {}
      if defined?(@nonce) && response['nonce'].nil?
        # Could be reauth
      else
        # No reauth:
        @nonce_count = 0
      end
      @nonce ||= c['nonce']
      response['nonce'] = @nonce
      response['charset'] = 'utf-8'
      response['username'] = preferences.username
      response['realm'] = c['realm'] || preferences.realm
      @cnonce = generate_nonce unless defined? @cnonce
      response['cnonce'] = @cnonce
      @nc = next_nc
      response['nc'] = @nc
      @qop = c['qop'] || 'auth'
      response['qop'] = 'auth' #@qop
      response['digest-uri'] = preferences.digest_uri
      response['response'] = response_value(response['nonce'], response['nc'], response['cnonce'], response['qop'], response['realm'])
      ['response', encode_response(response)]
    else
      rspauth_expected = response_value(@nonce, @nc, @cnonce, @qop, '')
      #p :rspauth_received=>c['rspauth'], :rspauth_expected=>rspauth_expected
      if c['rspauth'] == rspauth_expected
        ['response', nil]
      else
        # Bogus server?
        @state = :failure
        ['failure', nil]
      end
    end
  else
    # No challenge? Might be success or failure
    super
  end
end
start() click to toggle source
# File lib/sasl/digest_md5.rb, line 15
def start
  @state = nil
  unless defined? @nonce
    ['auth', nil]
  else
    # reauthentication
    receive('challenge', '')
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.