securenative 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +5 -2
- data/.github/workflows/test.yml +5 -2
- data/.gitignore +3 -1
- data/Gemfile +5 -2
- data/Gemfile.lock +218 -10
- data/README.md +3 -3
- data/VERSION +1 -1
- data/lib/api_manager.rb +35 -0
- data/lib/config/configuration_builder.rb +30 -0
- data/lib/config/configuration_manager.rb +55 -0
- data/lib/config/securenative_options.rb +22 -0
- data/lib/context/hanami_context.rb +35 -0
- data/lib/context/rails_context.rb +41 -0
- data/lib/context/securenative_context.rb +67 -0
- data/lib/context/sinatra_context.rb +35 -0
- data/lib/enums/api_route.rb +6 -0
- data/lib/enums/event_types.rb +23 -0
- data/lib/enums/failover_strategy.rb +6 -0
- data/lib/enums/risk_level.rb +7 -0
- data/lib/errors/securenative_config_error.rb +4 -0
- data/lib/errors/securenative_http_error.rb +4 -0
- data/lib/errors/securenative_invalid_options_error.rb +4 -0
- data/lib/errors/securenative_invalid_uri_error.rb +4 -0
- data/lib/errors/securenative_parse_error.rb +4 -0
- data/lib/errors/securenative_sdk_Illegal_state_error.rb +4 -0
- data/lib/errors/securenative_sdk_error.rb +4 -0
- data/lib/event_manager.rb +156 -0
- data/lib/{securenative/event_options_builder.rb → event_options.rb} +5 -3
- data/lib/http/secure_native_http_response.rb +12 -0
- data/lib/http/securenative_http_client.rb +32 -0
- data/lib/{securenative/models → models}/client_token.rb +2 -0
- data/lib/{securenative/models → models}/device.rb +3 -1
- data/lib/models/event_options.rb +15 -0
- data/lib/models/request_context.rb +18 -0
- data/lib/models/request_options.rb +12 -0
- data/lib/models/sdk_event.rb +35 -0
- data/lib/models/user_traits.rb +13 -0
- data/lib/models/verify_result.rb +12 -0
- data/lib/securenative.rb +95 -0
- data/lib/utils/date_utils.rb +9 -0
- data/lib/{securenative/utils → utils}/encryption_utils.rb +1 -4
- data/lib/{securenative/utils → utils}/ip_utils.rb +7 -6
- data/lib/utils/request_utils.rb +54 -0
- data/lib/{securenative/logger.rb → utils/secure_native_logger.rb} +5 -3
- data/lib/{securenative/utils → utils}/signature_utils.rb +4 -2
- data/lib/utils/utils.rb +9 -0
- data/lib/{securenative/utils → utils}/version_utils.rb +3 -1
- data/{lib/securenative → out/production/securenative-ruby}/api_manager.rb +6 -5
- data/{lib/securenative → out/production/securenative-ruby}/config/configuration_builder.rb +7 -3
- data/{lib/securenative → out/production/securenative-ruby}/config/configuration_manager.rb +5 -3
- data/{lib/securenative → out/production/securenative-ruby}/config/securenative_options.rb +3 -1
- data/out/production/securenative-ruby/context/securenative_context.rb +40 -0
- data/out/production/securenative-ruby/enums/api_route.rb +6 -0
- data/out/production/securenative-ruby/enums/event_types.rb +23 -0
- data/out/production/securenative-ruby/enums/failover_strategy.rb +6 -0
- data/out/production/securenative-ruby/enums/risk_level.rb +7 -0
- data/out/production/securenative-ruby/errors/securenative_config_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_http_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_invalid_options_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_invalid_uri_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_parse_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_sdk_error.rb +4 -0
- data/out/production/securenative-ruby/event_manager.rb +156 -0
- data/out/production/securenative-ruby/event_options.rb +32 -0
- data/{lib/securenative → out/production/securenative-ruby}/http/http_response.rb +3 -1
- data/out/production/securenative-ruby/http/securenative_http_client.rb +32 -0
- data/out/production/securenative-ruby/models/client_token.rb +12 -0
- data/out/production/securenative-ruby/models/device.rb +10 -0
- data/{lib/securenative → out/production/securenative-ruby}/models/event_options.rb +3 -1
- data/{lib/securenative → out/production/securenative-ruby}/models/request_context.rb +5 -2
- data/out/production/securenative-ruby/models/request_options.rb +12 -0
- data/{lib/securenative → out/production/securenative-ruby}/models/sdk_event.rb +11 -3
- data/{lib/securenative → out/production/securenative-ruby}/models/user_traits.rb +3 -1
- data/{lib/securenative → out/production/securenative-ruby}/models/verify_result.rb +3 -1
- data/{lib/securenative → out/production/securenative-ruby}/securenative.rb +24 -15
- data/out/production/securenative-ruby/utils/date_utils.rb +9 -0
- data/out/production/securenative-ruby/utils/encryption_utils.rb +35 -0
- data/out/production/securenative-ruby/utils/ip_utils.rb +23 -0
- data/{lib/securenative → out/production/securenative-ruby}/utils/request_utils.rb +5 -3
- data/out/production/securenative-ruby/utils/secure_native_logger.rb +44 -0
- data/out/production/securenative-ruby/utils/signature_utils.rb +16 -0
- data/out/production/securenative-ruby/utils/utils.rb +9 -0
- data/out/production/securenative-ruby/utils/version_utils.rb +12 -0
- data/out/test/securenative-ruby/spec_api_manager.rb +81 -0
- data/out/test/securenative-ruby/spec_context_builder.rb +69 -0
- data/out/test/securenative-ruby/spec_date_utils.rb +13 -0
- data/out/test/securenative-ruby/spec_encryption_utils.rb +26 -0
- data/out/test/securenative-ruby/spec_event_manager.rb +59 -0
- data/out/test/securenative-ruby/spec_helper.rb +20 -0
- data/out/test/securenative-ruby/spec_ip_utils.rb +41 -0
- data/out/test/securenative-ruby/spec_securenative.rb +65 -0
- data/out/test/securenative-ruby/spec_securenative_http_client.rb +23 -0
- data/out/test/securenative-ruby/spec_signature_utils.rb +18 -0
- data/securenative.gemspec +1 -1
- metadata +89 -42
- data/.travis.yml +0 -6
- data/lib/securenative/context/context_builder.rb +0 -59
- data/lib/securenative/context/securenative_context.rb +0 -14
- data/lib/securenative/enums/api_route.rb +0 -4
- data/lib/securenative/enums/event_types.rb +0 -21
- data/lib/securenative/enums/failover_strategy.rb +0 -4
- data/lib/securenative/enums/risk_level.rb +0 -5
- data/lib/securenative/event_manager.rb +0 -150
- data/lib/securenative/exceptions/securenative_config_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_http_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_invalid_options_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_invalid_uri_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_parse_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_sdk_Illegal_state_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_sdk_exception.rb +0 -2
- data/lib/securenative/http/securenative_http_client.rb +0 -30
- data/lib/securenative/models/request_options.rb +0 -10
- data/lib/securenative/securenative.iml +0 -9
- data/lib/securenative/utils/date_utils.rb +0 -7
- data/lib/securenative/utils/utils.rb +0 -9
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class EventOptions
|
|
2
4
|
MAX_PROPERTIES_SIZE = 10
|
|
3
5
|
|
|
4
6
|
def initialize(event_type, user_id, user_traits, user_name, email, phone, created_at, context, properties, timestamp)
|
|
@@ -22,9 +24,9 @@ class EventOptionsBuilder
|
|
|
22
24
|
|
|
23
25
|
def build
|
|
24
26
|
if !@event_options.properties.nil? && @event_options.properties.length > MAX_PROPERTIES_SIZE
|
|
25
|
-
raise
|
|
27
|
+
raise SecureNativeInvalidOptionsError('You can have only up to {} custom properties', MAX_PROPERTIES_SIZE)
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
@event_options
|
|
29
31
|
end
|
|
30
|
-
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'httpclient'
|
|
4
|
+
|
|
5
|
+
class SecureNativeHttpClient
|
|
6
|
+
AUTHORIZATION_HEADER = 'Authorization'
|
|
7
|
+
VERSION_HEADER = 'SN-Version'
|
|
8
|
+
USER_AGENT_HEADER = 'User-Agent'
|
|
9
|
+
USER_AGENT_HEADER_VALUE = 'SecureNative-python'
|
|
10
|
+
CONTENT_TYPE_HEADER = 'Content-Type'
|
|
11
|
+
CONTENT_TYPE_HEADER_VALUE = 'application/json'
|
|
12
|
+
|
|
13
|
+
def initialize(securenative_options)
|
|
14
|
+
@options = securenative_options
|
|
15
|
+
@client = HTTPClient.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def _headers
|
|
19
|
+
{
|
|
20
|
+
CONTENT_TYPE_HEADER => CONTENT_TYPE_HEADER_VALUE,
|
|
21
|
+
USER_AGENT_HEADER => USER_AGENT_HEADER_VALUE,
|
|
22
|
+
VERSION_HEADER => VersionUtils.version,
|
|
23
|
+
AUTHORIZATION_HEADER => @options.api_key
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def post(path, body)
|
|
28
|
+
url = "#{@options.api_url}/#{path}"
|
|
29
|
+
headers = _headers
|
|
30
|
+
@client.post(url, body, headers)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class EventOptions
|
|
4
|
+
attr_reader :event, :user_id, :user_traits, :context, :properties, :timestamp
|
|
5
|
+
attr_writer :event, :user_id, :user_traits, :context, :properties, :timestamp
|
|
6
|
+
|
|
7
|
+
def initialize(event: nil, user_id: nil, user_traits: nil, context: nil, properties: nil, timestamp: nil)
|
|
8
|
+
@event = event
|
|
9
|
+
@user_id = user_id
|
|
10
|
+
@user_traits = user_traits
|
|
11
|
+
@context = context
|
|
12
|
+
@properties = properties
|
|
13
|
+
@timestamp = timestamp
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class RequestContext
|
|
4
|
+
attr_reader :cid, :vid, :fp, :ip, :remote_ip, :headers, :url, :http_method
|
|
5
|
+
attr_writer :cid, :vid, :fp, :ip, :remote_ip, :headers, :url, :http_method
|
|
6
|
+
|
|
7
|
+
def initialize(cid: nil, vid: nil, fp: nil, ip: nil, remote_ip: nil, headers: nil, url: nil, http_method: nil)
|
|
8
|
+
@cid = cid
|
|
9
|
+
@vid = vid
|
|
10
|
+
@fp = fp
|
|
11
|
+
@ip = ip
|
|
12
|
+
@remote_ip = remote_ip
|
|
13
|
+
@headers = headers
|
|
14
|
+
@url = url
|
|
15
|
+
@method = http_method
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class RequestOptions
|
|
4
|
+
attr_reader :url, :body, :retry_sending
|
|
5
|
+
attr_writer :url, :body, :retry_sending
|
|
6
|
+
|
|
7
|
+
def initialize(url, body, retry_sending)
|
|
8
|
+
@url = url
|
|
9
|
+
@body = body
|
|
10
|
+
@retry_sending = retry_sending
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'context/securenative_context'
|
|
4
|
+
require 'utils/encryption_utils'
|
|
5
|
+
|
|
6
|
+
class SDKEvent
|
|
7
|
+
attr_reader :context, :rid, :event_type, :user_id, :user_traits, :request, :timestamp, :properties
|
|
8
|
+
attr_writer :context, :rid, :event_type, :user_id, :user_traits, :request, :timestamp, :properties
|
|
9
|
+
|
|
10
|
+
def initialize(event_options, securenative_options)
|
|
11
|
+
@context = if !event_options.context.nil?
|
|
12
|
+
event_options.context
|
|
13
|
+
else
|
|
14
|
+
SecureNativeContext.default_context_builder
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
client_token = EncryptionUtils.decrypt(@context.client_token, securenative_options.api_key)
|
|
18
|
+
|
|
19
|
+
@rid = SecureRandom.uuid.to_str
|
|
20
|
+
@event_type = event_options.event
|
|
21
|
+
@user_id = event_options.user_id
|
|
22
|
+
@user_traits = event_options.user_traits
|
|
23
|
+
@request = RequestContext(client_token ? client_token.cid : '', client_token ? client_token.vid : '',
|
|
24
|
+
client_token ? client_token.fp : '', @context.ip,
|
|
25
|
+
@context.remote_ip, @context.headers, @context.url, @context.http_method)
|
|
26
|
+
|
|
27
|
+
@timestamp = DateUtils.to_timestamp(event_options.timestamp)
|
|
28
|
+
@properties = event_options.properties
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def to_s
|
|
32
|
+
"context: #{@context}, rid: #{@rid}, event_type: #{@event_type}, user_id: #{@user_id},
|
|
33
|
+
user_traits: #{@user_traits}, request: #{@request}, timestamp: #{@timestamp}, properties: #{@properties}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UserTraits
|
|
4
|
+
attr_reader :name, :email, :phone, :created_at
|
|
5
|
+
attr_writer :name, :email, :phone, :created_at
|
|
6
|
+
|
|
7
|
+
def initialize(name: nil, email: nil, phone: nil, created_at: nil)
|
|
8
|
+
@name = name
|
|
9
|
+
@email = email
|
|
10
|
+
@created_at = created_at
|
|
11
|
+
@phone = phone
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class VerifyResult
|
|
4
|
+
attr_reader :risk_level, :score, :triggers
|
|
5
|
+
attr_writer :risk_level, :score, :triggers
|
|
6
|
+
|
|
7
|
+
def initialize(risk_level: nil, score: nil, triggers: nil)
|
|
8
|
+
@risk_level = risk_level
|
|
9
|
+
@score = score
|
|
10
|
+
@triggers = triggers
|
|
11
|
+
end
|
|
12
|
+
end
|
data/lib/securenative.rb
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'utils/secure_native_logger'
|
|
4
|
+
require 'utils/signature_utils'
|
|
5
|
+
require 'utils/utils'
|
|
6
|
+
require 'errors/securenative_sdk_error'
|
|
7
|
+
require 'errors/securenative_sdk_Illegal_state_error'
|
|
8
|
+
require 'errors/securenative_config_error'
|
|
9
|
+
require 'enums/failover_strategy'
|
|
10
|
+
require 'config/configuration_builder'
|
|
11
|
+
require 'event_manager'
|
|
12
|
+
require 'api_manager'
|
|
13
|
+
|
|
14
|
+
class SecureNative
|
|
15
|
+
attr_reader :options
|
|
16
|
+
|
|
17
|
+
def initialize(options)
|
|
18
|
+
@securenative = nil
|
|
19
|
+
raise SecureNativeSDKError, 'You must pass your SecureNative api key' if Utils.null_or_empty?(options.api_key)
|
|
20
|
+
|
|
21
|
+
@options = options
|
|
22
|
+
@event_manager = EventManager.new(@options)
|
|
23
|
+
|
|
24
|
+
@event_manager.start_event_persist unless @options.api_url.nil?
|
|
25
|
+
|
|
26
|
+
@api_manager = ApiManager.new(@event_manager, @options)
|
|
27
|
+
SecureNativeLogger.init_logger(@options.log_level)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.init_with_options(options)
|
|
31
|
+
if @securenative.nil?
|
|
32
|
+
@securenative = SecureNative.new(options)
|
|
33
|
+
@securenative
|
|
34
|
+
else
|
|
35
|
+
SecureNativeLogger.debug('This SDK was already initialized.')
|
|
36
|
+
raise SecureNativeSDKError, 'This SDK was already initialized.'
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.init_with_api_key(api_key)
|
|
41
|
+
raise SecureNativeConfigError, 'You must pass your SecureNative api key' if Utils.null_or_empty?(api_key)
|
|
42
|
+
|
|
43
|
+
if @securenative.nil?
|
|
44
|
+
options = ConfigurationBuilder.new(api_key: api_key)
|
|
45
|
+
@securenative = SecureNative.new(options)
|
|
46
|
+
@securenative
|
|
47
|
+
else
|
|
48
|
+
SecureNativeLogger.debug('This SDK was already initialized.')
|
|
49
|
+
raise SecureNativeSDKError, 'This SDK was already initialized.'
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.init
|
|
54
|
+
options = ConfigurationManager.load_config
|
|
55
|
+
init_with_options(options)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.instance
|
|
59
|
+
raise SecureNativeSDKIllegalStateError if @securenative.nil?
|
|
60
|
+
|
|
61
|
+
@securenative
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def self.config_builder(api_key: nil, api_url: 'https://api.securenative.com/collector/api/v1', interval: 1000,
|
|
65
|
+
max_events: 1000, timeout: 1500, auto_send: true, disable: false, log_level: 'FATAL',
|
|
66
|
+
fail_over_strategy: FailOverStrategy::FAIL_OPEN)
|
|
67
|
+
ConfigurationBuilder.new(api_key: api_key, api_url: api_url, interval: interval, max_events: max_events,
|
|
68
|
+
timeout: timeout, auto_send: auto_send, disable: disable, log_level: log_level,
|
|
69
|
+
fail_over_strategy: fail_over_strategy)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.context_builder(client_token: nil, ip: nil, remote_ip: nil, headers: nil, url: nil, http_method: nil, body: nil)
|
|
73
|
+
SecureNativeContext.new(client_token: client_token, ip: ip, remote_ip: remote_ip, headers: headers,
|
|
74
|
+
url: url, http_method: http_method, body: body)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def track(event_options)
|
|
78
|
+
@api_manager.track(event_options)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def verify(event_options)
|
|
82
|
+
@api_manager.verify(event_options)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def self._flush
|
|
86
|
+
@securenative = nil
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def verify_request_payload(request)
|
|
90
|
+
request_signature = request.header[SignatureUtils.SIGNATURE_HEADER]
|
|
91
|
+
body = request.body
|
|
92
|
+
|
|
93
|
+
SignatureUtils.valid_signature?(@options.api_key, body, request_signature)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -11,9 +11,6 @@ class EncryptionUtils
|
|
|
11
11
|
cipher.padding = 0
|
|
12
12
|
|
|
13
13
|
if text.size % BLOCK_SIZE != 0
|
|
14
|
-
logger = Logger.new(STDOUT)
|
|
15
|
-
logger.level = Logger::WARN
|
|
16
|
-
logger.fatal('data not multiple of block length')
|
|
17
14
|
return nil
|
|
18
15
|
end
|
|
19
16
|
|
|
@@ -35,4 +32,4 @@ class EncryptionUtils
|
|
|
35
32
|
rv = cipher.update(s) + cipher.final
|
|
36
33
|
rv.strip
|
|
37
34
|
end
|
|
38
|
-
end
|
|
35
|
+
end
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "resolv"
|
|
4
4
|
|
|
5
|
+
class IpUtils
|
|
5
6
|
def self.ip_address?(ip_address)
|
|
6
|
-
return true if
|
|
7
|
-
return true if
|
|
7
|
+
return true if ip_address =~ Resolv::IPv4::Regex
|
|
8
|
+
return true if ip_address =~ Resolv::IPv6::Regex
|
|
8
9
|
|
|
9
10
|
false
|
|
10
11
|
end
|
|
@@ -19,4 +20,4 @@ class IpUtils
|
|
|
19
20
|
def self.loop_back?(ip_address)
|
|
20
21
|
IPAddr.new(ip_address).loopback?
|
|
21
22
|
end
|
|
22
|
-
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class RequestUtils
|
|
4
|
+
SECURENATIVE_COOKIE = '_sn'
|
|
5
|
+
SECURENATIVE_HEADER = 'x-securenative'
|
|
6
|
+
|
|
7
|
+
def self.get_secure_header_from_request(headers)
|
|
8
|
+
begin
|
|
9
|
+
return headers[SECURENATIVE_HEADER] unless headers.nil?
|
|
10
|
+
rescue StandardError
|
|
11
|
+
[]
|
|
12
|
+
end
|
|
13
|
+
[]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.get_client_ip_from_request(request)
|
|
17
|
+
begin
|
|
18
|
+
return request.ip unless request.ip.nil?
|
|
19
|
+
rescue NoMethodError
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
begin
|
|
23
|
+
x_forwarded_for = request.env['HTTP_X_FORWARDED_FOR']
|
|
24
|
+
return x_forwarded_for unless x_forwarded_for.nil?
|
|
25
|
+
rescue NoMethodError
|
|
26
|
+
begin
|
|
27
|
+
x_forwarded_for = request['HTTP_X_FORWARDED_FOR']
|
|
28
|
+
return x_forwarded_for unless x_forwarded_for.nil?
|
|
29
|
+
rescue NoMethodError
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
begin
|
|
34
|
+
x_forwarded_for = request.env['REMOTE_ADDR']
|
|
35
|
+
return x_forwarded_for unless x_forwarded_for.nil?
|
|
36
|
+
rescue NoMethodError
|
|
37
|
+
begin
|
|
38
|
+
x_forwarded_for = request['REMOTE_ADDR']
|
|
39
|
+
return x_forwarded_for unless x_forwarded_for.nil?
|
|
40
|
+
rescue NoMethodError
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
''
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.get_remote_ip_from_request(request)
|
|
48
|
+
begin
|
|
49
|
+
request.remote_ip
|
|
50
|
+
rescue NoMethodError
|
|
51
|
+
''
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'logger'
|
|
2
4
|
|
|
3
|
-
class
|
|
5
|
+
class SecureNativeLogger
|
|
4
6
|
@logger = Logger.new(STDOUT)
|
|
5
7
|
|
|
6
|
-
def self.init_logger(level)
|
|
8
|
+
def self.init_logger(level = 'DEBUG')
|
|
7
9
|
@logger.level = case level
|
|
8
10
|
when 'WARN'
|
|
9
11
|
Logger::WARN
|
|
@@ -39,4 +41,4 @@ class Logger
|
|
|
39
41
|
def self.error(msg)
|
|
40
42
|
@logger.error(msg)
|
|
41
43
|
end
|
|
42
|
-
end
|
|
44
|
+
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'openssl'
|
|
2
4
|
|
|
3
5
|
class SignatureUtils
|
|
4
|
-
SIGNATURE_HEADER = 'x-securenative'
|
|
6
|
+
SIGNATURE_HEADER = 'x-securenative'
|
|
5
7
|
|
|
6
8
|
def self.valid_signature?(api_key, payload, header_signature)
|
|
7
9
|
key = api_key.encode('utf-8')
|
|
@@ -11,4 +13,4 @@ class SignatureUtils
|
|
|
11
13
|
rescue StandardError
|
|
12
14
|
false
|
|
13
15
|
end
|
|
14
|
-
end
|
|
16
|
+
end
|