Module: OverSIP::Modules::UserAssertion

Extended by:
Logger
Defined in:
lib/oversip/modules/user_assertion.rb

Class Method Summary collapse

Methods included from Logger

close, fg_system_msg2str, init_logger_mq, load_methods, log_id, syslog_system_msg2str, syslog_user_msg2str

Class Method Details

.add_pai(request) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/oversip/modules/user_assertion.rb', line 45

def self.add_pai request
  # Add P-Asserted-Identity if the user has previously been asserted but JUST
  # in case it matches request From URI !
  # NOTE: If the connection is not asserted (it's null) then it will not match this
  # comparisson, so OK.
  if request.cvars[:asserted_user] == request.from.uri
    # Don't add P-Asserted-Identity if the request contains P-Preferred-Identity header.
    unless request.headers["P-Preferred-Identity"]
      log_system_debug "user asserted, adding P-Asserted-Identity for #{request.log_id}"  if $oversip_debug
      request.set_header "P-Asserted-Identity", "<" << request.cvars[:asserted_user] << ">"
      return true
    else
      # Remove posible P-Asserted-Identity header!
      log_system_debug "user asserted but P-Preferred-Identity header present, P-Asserted-Identity not added for #{request.log_id}"  if $oversip_debug
      request.headers.delete "P-Asserted-Identity"
      return nil
    end

  # Otherwise ensure the request has no spoofed P-Asserted-Identity headers!
  else
    request.headers.delete "P-Asserted-Identity"
    return false

  end
end

.assert_connection(message) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/oversip/modules/user_assertion.rb', line 9

def self.assert_connection message
  case message
  when ::OverSIP::SIP::Request
    request = message
  when ::OverSIP::SIP::Response
    request = message.request
  else
    raise ::OverSIP::RuntimeError, "message must be a OverSIP::SIP::Request or OverSIP::SIP::Response"
  end

  # Don't do this stuf for UDP or for outbound connections.
  return false  unless request.connection.class.reliable_transport_listener?
  # Return if already set.
  return request.cvars[:asserted_user]  if request.cvars[:asserted_user]
  # Don't do this stuf in case of P-Preferred-Identity header is present.
  return false  if request.headers["P-Preferred-Identity"]

  log_system_debug "user #{request.from.uri} asserted to connection"  if $oversip_debug
  # Store the request From URI as "asserted_user" for this connection.
  request.cvars[:asserted_user] = request.from.uri
end

.revoke_assertion(message) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/oversip/modules/user_assertion.rb', line 31

def self.revoke_assertion message
  case message
  when ::OverSIP::SIP::Request
    request = message
  when ::OverSIP::SIP::Response
    request = message.request
  else
    raise ::OverSIP::RuntimeError, "message must be a OverSIP::SIP::Request or OverSIP::SIP::Response"
  end

  request.cvars.delete :asserted_user
  true
end