Module: Quaff::Auth

Defined in:
lib/auth.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.extract_rand(auth_line) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/auth.rb', line 14

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) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/auth.rb', line 32

def Auth.gen_auth_header auth_line, username, passwd, method, sip_uri
  # 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
  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



25
26
27
28
29
30
# File 'lib/auth.rb', line 25

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) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/auth.rb', line 5

def Auth.gen_nonce auth_pairs, username, passwd, method, sip_uri
  a1 = username + ":" + auth_pairs["realm"] + ":" + passwd
  a2 = method + ":" + sip_uri
  ha1 = Digest::MD5::hexdigest(a1)
  ha2 = Digest::MD5::hexdigest(a2)
  digest = Digest::MD5.hexdigest(ha1 + ":" + auth_pairs["nonce"] + ":" + ha2)
  return digest
end