Module: NewRelic::Security::Agent::Control::ControlCommand

Extended by:
ControlCommand
Included in:
ControlCommand
Defined in:
lib/newrelic_security/agent/control/control_command.rb

Instance Method Summary collapse

Instance Method Details

#define_transform_keysObject



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/newrelic_security/agent/control/control_command.rb', line 70

def define_transform_keys
  ::Hash.class_eval do
    def transform_keys
      result = {}
      each_key do |key|
        result[yield(key)] = self[key]
      end
      result
    end
  end
end

#handle_ic_command(message) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
67
68
# File 'lib/newrelic_security/agent/control/control_command.rb', line 11

def handle_ic_command(message)
  message_json = parse_message(message)
  define_transform_keys unless message_json.respond_to?(:transform_keys)
  message_object = message_json.transform_keys(&:to_sym)
  return if message_object.nil?

  if message_object.has_key?(:controlCommand)
    case message_object[:controlCommand]
    when 4
      
    when 5
      NewRelic::Security::Agent.logger.debug "Control command : '5', #{message_object}"
    when 6

    when 7
      NewRelic::Security::Agent.logger.debug "Control command : '7', #{message_object}"
    when 10
      NewRelic::Security::Agent.logger.debug "Control command : '10', #{message_object}"
    when 11
      NewRelic::Security::Agent.logger.debug "Control command : '11', #{message_object.to_json}"
      NewRelic::Security::Agent.config.update_port = message_object[:reflectedMetaData][LISTEN_PORT].to_i unless NewRelic::Security::Agent.config[:listen_port]
      NewRelic::Security::Agent.agent.iast_client.last_fuzz_cc_timestamp = current_time_millis
      fuzz_request = NewRelic::Security::Agent::Control::FuzzRequest.new(message_object[:id])
      fuzz_request.request = prepare_fuzz_request(message_object)
      fuzz_request.case_type = message_object[:arguments][1]
      fuzz_request. = message_object[:reflectedMetaData]
      NewRelic::Security::Agent.agent.iast_client.pending_request_ids << message_object[:id]
      NewRelic::Security::Agent.agent.iast_client.enqueue(fuzz_request)
      fuzz_request = nil
    when 12
      NewRelic::Security::Agent.logger.info "Validator asked to reconnect(CC#12), calling reconnect_at_will"
      reconnect_at_will
    when 13
      NewRelic::Security::Agent.logger.debug "Control command : '13', #{message_object}"
      NewRelic::Security::Agent.logger.debug "Received IAST cooldown. Waiting for next : #{message_object[:data]} Seconds"
      NewRelic::Security::Agent.agent.iast_client.cooldown_till_timestamp = current_time_millis + (message_object[:data] * 1000)
    when 14
      NewRelic::Security::Agent.logger.debug "Control command : '14', #{message_object}"
      NewRelic::Security::Agent.logger.debug "Purging confirmed IAST processed records count : #{message_object[:arguments].size}"
      message_object[:arguments].each { |processed_id| NewRelic::Security::Agent.agent.iast_client.completed_requests.delete(processed_id) }
    when 100
      NewRelic::Security::Agent.logger.debug "Control command : '100', #{message_object.to_json}"
    when 101

    when 102
      NewRelic::Security::Agent.logger.error "Update policy failed at validator with error : #{message_object}"
      # TODO: Apply initial policy here
    when 1006
      # TODO: abnormal closure in which case LC anyway have to reconnect
    when 1013
      # TODO: ndicates that the service is experiencing overload. A client should only connect to a different IP (when there are multiple for the target) or 	reconnect to the same IP upon user action.
    else
      NewRelic::Security::Agent.logger.error "Unrecognized control command : #{message_object}"
    end
  else
    NewRelic::Security::Agent.logger.error "Control command is missing in IC message : #{message_object}"
  end
end