Module: Quaff::Auth
- Defined in:
- lib/auth.rb
Overview
:nodoc:
Class Method Summary collapse
- .extract_rand(auth_line) ⇒ Object
- .gen_auth_header(auth_line, username, passwd, method, sip_uri, ha1 = "") ⇒ Object
- .gen_empty_auth_header(username) ⇒ Object
- .gen_nonce(auth_pairs, username, passwd, method, sip_uri, ha1 = "") ⇒ Object
Class Method Details
.extract_rand(auth_line) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/auth.rb', line 16 def Auth.extract_rand auth_line # Split auth line on commas auth_pairs = {} auth_line.sub("Digest ", "").split(",") .each do |pair| key, value = pair.split "=" auth_pairs[key.gsub(" ", "")] = value.gsub("\"", "").gsub(" ", "") end # First 128 bits are the RAND return Base64.decode64(auth_pairs["nonce"])[0..15] end |
.gen_auth_header(auth_line, username, passwd, method, sip_uri, ha1 = "") ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/auth.rb', line 34 def Auth.gen_auth_header auth_line, username, passwd, method, sip_uri, ha1="" # Split auth line on commas auth_pairs = {} auth_line.sub("Digest ", "").split(",") .each do |pair| key, value = pair.split "=" auth_pairs[key.gsub(" ", "")] = value.gsub("\"", "").gsub(" ", "") end digest = gen_nonce auth_pairs, username, passwd, method, sip_uri, ha1 return %Q!Digest username="#{username}",realm="#{auth_pairs['realm']}",nonce="#{auth_pairs['nonce']}",uri="#{sip_uri}",response="#{digest}",algorithm="#{auth_pairs['algorithm']}",opaque="#{auth_pairs['opaque']}"! # Return Authorization header with fields username, realm, nonce, uri, nc, cnonce, response, opaque end |
.gen_empty_auth_header(username) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/auth.rb', line 27 def Auth.gen_empty_auth_header username return %Q!Digest username="#{username}",realm="",nonce="",uri="",response=""! # Return Authorization header with only the username field set, # to indicate the private ID in cases where it isn't linked to # the SIP URI end |
.gen_nonce(auth_pairs, username, passwd, method, sip_uri, ha1 = "") ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/auth.rb', line 5 def Auth.gen_nonce auth_pairs, username, passwd, method, sip_uri, ha1="" if ha1.empty? a1 = username + ":" + auth_pairs["realm"] + ":" + passwd ha1 = Digest::MD5::hexdigest(a1) end a2 = method + ":" + sip_uri ha2 = Digest::MD5::hexdigest(a2) digest = Digest::MD5.hexdigest(ha1 + ":" + auth_pairs["nonce"] + ":" + ha2) return digest end |