Class: SASL::DigestMD5
Overview
RFC 2831: tools.ietf.org/html/rfc2831
Instance Attribute Summary collapse
-
#cnonce ⇒ Object
writeonly
Sets the attribute cnonce.
Attributes inherited from Mechanism
Instance Method Summary collapse
-
#initialize(*a) ⇒ DigestMD5
constructor
A new instance of DigestMD5.
- #receive(message_name, content) ⇒ Object
- #start ⇒ Object
Methods inherited from Mechanism
Constructor Details
#initialize(*a) ⇒ DigestMD5
Returns a new instance of DigestMD5.
10 11 12 13 |
# File 'lib/sasl/digest_md5.rb', line 10 def initialize(*a) super @nonce_count = 0 end |
Instance Attribute Details
#cnonce=(value) ⇒ Object (writeonly)
Sets the attribute cnonce
8 9 10 |
# File 'lib/sasl/digest_md5.rb', line 8 def cnonce=(value) @cnonce = value end |
Instance Method Details
#receive(message_name, content) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sasl/digest_md5.rb', line 25 def receive(, content) if == '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 ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/sasl/digest_md5.rb', line 15 def start @state = nil unless defined? @nonce ['auth', nil] else # reauthentication receive('challenge', '') end end |