securenative 0.1.17 → 0.1.23
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 +6 -4
- data/Gemfile.lock +234 -25
- data/README.md +37 -32
- data/lib/api_manager.rb +39 -0
- data/lib/config/configuration_builder.rb +27 -0
- data/lib/config/configuration_manager.rb +56 -0
- data/lib/config/securenative_options.rb +23 -0
- data/lib/context/hanami_context.rb +42 -0
- data/lib/context/rails_context.rb +44 -0
- data/lib/context/securenative_context.rb +67 -0
- data/lib/context/sinatra_context.rb +42 -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 +157 -0
- data/lib/{securenative/http/http_response.rb → http/secure_native_http_response.rb} +4 -2
- data/lib/http/securenative_http_client.rb +50 -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 +37 -0
- data/lib/{securenative/models → models}/request_context.rb +7 -4
- data/lib/models/request_options.rb +12 -0
- data/lib/models/sdk_event.rb +49 -0
- data/lib/{securenative/models → models}/user_traits.rb +4 -2
- data/lib/{securenative/models → models}/verify_result.rb +8 -2
- data/lib/securenative.rb +83 -0
- data/lib/utils/date_utils.rb +9 -0
- data/lib/utils/encryption_utils.rb +49 -0
- data/lib/{securenative/utils → utils}/ip_utils.rb +7 -6
- data/lib/utils/request_utils.rb +69 -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/utils/version_utils.rb +11 -0
- data/out/production/securenative-ruby/api_manager.rb +39 -0
- data/out/production/securenative-ruby/config/configuration_builder.rb +27 -0
- data/out/production/securenative-ruby/config/configuration_manager.rb +56 -0
- data/out/production/securenative-ruby/config/securenative_options.rb +23 -0
- data/out/production/securenative-ruby/context/hanami_context.rb +42 -0
- data/out/production/securenative-ruby/context/rails_context.rb +44 -0
- data/out/production/securenative-ruby/context/securenative_context.rb +67 -0
- data/out/production/securenative-ruby/context/sinatra_context.rb +42 -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 +157 -0
- data/out/production/securenative-ruby/http/secure_native_http_response.rb +12 -0
- data/out/production/securenative-ruby/http/securenative_http_client.rb +50 -0
- data/out/production/securenative-ruby/models/client_token.rb +12 -0
- data/out/production/securenative-ruby/models/device.rb +10 -0
- data/out/production/securenative-ruby/models/event_options.rb +37 -0
- data/out/production/securenative-ruby/models/request_context.rb +18 -0
- data/out/production/securenative-ruby/models/request_options.rb +12 -0
- data/out/production/securenative-ruby/models/sdk_event.rb +49 -0
- data/out/production/securenative-ruby/models/user_traits.rb +13 -0
- data/out/production/securenative-ruby/models/verify_result.rb +16 -0
- data/out/production/securenative-ruby/securenative.rb +83 -0
- data/out/production/securenative-ruby/utils/date_utils.rb +9 -0
- data/out/production/securenative-ruby/utils/encryption_utils.rb +49 -0
- data/out/production/securenative-ruby/utils/ip_utils.rb +23 -0
- data/out/production/securenative-ruby/utils/request_utils.rb +69 -0
- 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 +11 -0
- data/out/test/securenative-ruby/spec_api_manager.rb +87 -0
- data/out/test/securenative-ruby/spec_context_builder.rb +87 -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 +93 -0
- data/out/test/securenative-ruby/spec_helper.rb +28 -0
- data/out/test/securenative-ruby/spec_ip_utils.rb +41 -0
- data/out/test/securenative-ruby/spec_request_utils.rb +25 -0
- data/out/test/securenative-ruby/spec_sdk_event.rb +24 -0
- data/out/test/securenative-ruby/spec_securenative.rb +61 -0
- data/out/test/securenative-ruby/spec_securenative_http_client.rb +31 -0
- data/out/test/securenative-ruby/spec_signature_utils.rb +18 -0
- data/out/test/securenative-ruby/spec_version_util.rb +10 -0
- data/securenative.gemspec +2 -2
- metadata +93 -43
- data/.travis.yml +0 -6
- data/VERSION +0 -1
- data/lib/securenative/api_manager.rb +0 -30
- data/lib/securenative/config/configuration_builder.rb +0 -26
- data/lib/securenative/config/configuration_manager.rb +0 -53
- data/lib/securenative/config/securenative_options.rb +0 -18
- 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/event_options_builder.rb +0 -30
- 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/event_options.rb +0 -13
- data/lib/securenative/models/request_options.rb +0 -10
- data/lib/securenative/models/sdk_event.rb +0 -25
- data/lib/securenative/securenative.iml +0 -9
- data/lib/securenative/securenative.rb +0 -82
- data/lib/securenative/utils/date_utils.rb +0 -7
- data/lib/securenative/utils/encryption_utils.rb +0 -38
- data/lib/securenative/utils/request_utils.rb +0 -21
- data/lib/securenative/utils/utils.rb +0 -9
- data/lib/securenative/utils/version_utils.rb +0 -10
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'httpclient'
|
2
|
-
|
3
|
-
class SecureNativeHttpClient
|
4
|
-
AUTHORIZATION_HEADER = 'Authorization'.freeze
|
5
|
-
VERSION_HEADER = 'SN-Version'.freeze
|
6
|
-
USER_AGENT_HEADER = 'User-Agent'.freeze
|
7
|
-
USER_AGENT_HEADER_VALUE = 'SecureNative-python'.freeze
|
8
|
-
CONTENT_TYPE_HEADER = 'Content-Type'.freeze
|
9
|
-
CONTENT_TYPE_HEADER_VALUE = 'application/json'.freeze
|
10
|
-
|
11
|
-
def __init__(securenative_options)
|
12
|
-
@options = securenative_options
|
13
|
-
@client = HTTPClient.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def _headers
|
17
|
-
{
|
18
|
-
CONTENT_TYPE_HEADER => CONTENT_TYPE_HEADER_VALUE,
|
19
|
-
USER_AGENT_HEADER => USER_AGENT_HEADER_VALUE,
|
20
|
-
VERSION_HEADER => VersionUtils.version,
|
21
|
-
AUTHORIZATION_HEADER => options.api_key
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
def post(path, body)
|
26
|
-
url = '{}/{}'.format(@options.api_url, path)
|
27
|
-
headers = _headers
|
28
|
-
@client.post(url, body, headers)
|
29
|
-
end
|
30
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class EventOptions
|
2
|
-
attr_reader :event, :user_id, :user_traits, :context, :properties, :timestamp
|
3
|
-
attr_writer :event, :user_id, :user_traits, :context, :properties, :timestamp
|
4
|
-
|
5
|
-
def initialize(event, user_id = nil, user_traits = nil, context = nil, properties = nil, timestamp = nil)
|
6
|
-
@event = event
|
7
|
-
@user_id = user_id
|
8
|
-
@user_traits = user_traits
|
9
|
-
@context = context
|
10
|
-
@properties = properties
|
11
|
-
@timestamp = timestamp
|
12
|
-
end
|
13
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
class SDKEvent
|
2
|
-
attr_reader :context, :rid, :event_type, :user_id, :user_traits, :request, :timestamp, :properties
|
3
|
-
attr_writer :context, :rid, :event_type, :user_id, :user_traits, :request, :timestamp, :properties
|
4
|
-
|
5
|
-
def initialize(event_options, securenative_options)
|
6
|
-
@context = if !event_options.context.nil?
|
7
|
-
event_options.context
|
8
|
-
else
|
9
|
-
ContextBuilder.default_context_builder
|
10
|
-
end
|
11
|
-
|
12
|
-
client_token = EncryptionUtils.decrypt(@context.client_token, securenative_options.api_key)
|
13
|
-
|
14
|
-
@rid = SecureRandom.uuid.to_str
|
15
|
-
@event_type = event_options.event
|
16
|
-
@user_id = event_options.user_id
|
17
|
-
@user_traits = event_options.user_traits
|
18
|
-
@request = RequestContext(cid = client_token ? client_token.cid : '', vid = client_token ? client_token.vid : '',
|
19
|
-
fp = client_token ? client_token.fp : '', ip = @context.ip, remote_ip = @context.remote_ip,
|
20
|
-
method = @context.method, url = @context.url, headers = @context.headers)
|
21
|
-
|
22
|
-
@timestamp = DateUtils.to_timestamp(event_options.timestamp)
|
23
|
-
@properties = event_options.properties
|
24
|
-
end
|
25
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<module type="RUBY_MODULE" version="4">
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
-
<exclude-output />
|
5
|
-
<content url="file://$MODULE_DIR$" />
|
6
|
-
<orderEntry type="jdk" jdkName="ruby-2.7.1-p83" jdkType="RUBY_SDK" />
|
7
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
8
|
-
</component>
|
9
|
-
</module>
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require_relative 'logger'
|
2
|
-
require_relative 'utils/signature_utils'
|
3
|
-
|
4
|
-
class SecureNative
|
5
|
-
attr_reader :options
|
6
|
-
|
7
|
-
def initialize(options)
|
8
|
-
@securenative = nil
|
9
|
-
raise SecureNativeSDKException('You must pass your SecureNative api key') if Utils.null_or_empty?(options.api_key)
|
10
|
-
|
11
|
-
@options = options
|
12
|
-
@event_manager = EventManager(@options)
|
13
|
-
|
14
|
-
@event_manager.start_event_persist unless @options.api_url.nil?
|
15
|
-
|
16
|
-
@api_manager = ApiManager.new(@event_manager, @options)
|
17
|
-
Logger.init_logger(@options.log_level)
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.init_with_options(options)
|
21
|
-
if @securenative.nil?
|
22
|
-
@securenative = SecureNative.new(options)
|
23
|
-
@securenative
|
24
|
-
else
|
25
|
-
Logger.debug('This SDK was already initialized.')
|
26
|
-
raise SecureNativeSDKException('This SDK was already initialized.')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.init_with_api_key(api_key)
|
31
|
-
raise SecureNativeConfigException('You must pass your SecureNative api key') if Utils.null_or_empty?(api_key)
|
32
|
-
|
33
|
-
if @securenative.nil?
|
34
|
-
options = ConfigurationBuilder(api_key = api_key)
|
35
|
-
@securenative = SecureNative.new(options)
|
36
|
-
@securenative
|
37
|
-
else
|
38
|
-
Logger.debug('This SDK was already initialized.')
|
39
|
-
raise SecureNativeSDKException(u('This SDK was already initialized.'))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.init
|
44
|
-
options = ConfigurationManager.load_config
|
45
|
-
init_with_options(options)
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.instance
|
49
|
-
raise SecureNativeSDKIllegalStateException() if @securenative.nil?
|
50
|
-
|
51
|
-
@securenative
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.config_builder(api_key = nil, api_url = 'https://api.securenative.com/collector/api/v1', interval = 1000,
|
55
|
-
max_events = 1000, timeout = 1500, auto_send = true, disable = false, log_level = 'FATAL',
|
56
|
-
fail_over_strategy = FailOverStrategy::FAIL_OPEN)
|
57
|
-
ConfigurationBuilder(api_key, api_url, interval, max_events, timeout, auto_send, disable, log_level, fail_over_strategy)
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.context_builder(client_token = nil, ip = nil, remote_ip = nil, headers = nil, url = nil, method = nil, body = nil)
|
61
|
-
ContextBuilder(client_token, ip, remote_ip, headers, url, method, body)
|
62
|
-
end
|
63
|
-
|
64
|
-
def track(event_options)
|
65
|
-
@api_manager.track(event_options)
|
66
|
-
end
|
67
|
-
|
68
|
-
def verify(event_options)
|
69
|
-
@api_manager.verify(event_options)
|
70
|
-
end
|
71
|
-
|
72
|
-
def self._flush
|
73
|
-
@securenative = nil
|
74
|
-
end
|
75
|
-
|
76
|
-
def verify_request_payload(request)
|
77
|
-
request_signature = request.header[SignatureUtils.SIGNATURE_HEADER]
|
78
|
-
body = request.body
|
79
|
-
|
80
|
-
SignatureUtils.valid_signature?(@options.api_key, body, request_signature)
|
81
|
-
end
|
82
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'openssl'
|
4
|
-
|
5
|
-
class EncryptionUtils
|
6
|
-
BLOCK_SIZE = 16
|
7
|
-
KEY_SIZE = 32
|
8
|
-
|
9
|
-
def self.encrypt(text, cipher_key)
|
10
|
-
cipher = OpenSSL::Cipher::AES.new(KEY_SIZE, :CBC).encrypt
|
11
|
-
cipher.padding = 0
|
12
|
-
|
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
|
-
return nil
|
18
|
-
end
|
19
|
-
|
20
|
-
cipher_key = Digest::SHA1.hexdigest cipher_key
|
21
|
-
cipher.key = cipher_key.slice(0, BLOCK_SIZE)
|
22
|
-
s = cipher.update(text) + cipher.final
|
23
|
-
|
24
|
-
s.unpack('H*')[0].upcase
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.decrypt(encrypted, cipher_key)
|
28
|
-
cipher = OpenSSL::Cipher::AES.new(KEY_SIZE, :CBC).decrypt
|
29
|
-
cipher.padding = 0
|
30
|
-
|
31
|
-
cipher_key = Digest::SHA1.hexdigest cipher_key
|
32
|
-
cipher.key = cipher_key.slice(0, BLOCK_SIZE)
|
33
|
-
s = [encrypted].pack('H*').unpack('C*').pack('c*')
|
34
|
-
|
35
|
-
rv = cipher.update(s) + cipher.final
|
36
|
-
rv.strip
|
37
|
-
end
|
38
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
class RequestUtils
|
2
|
-
SECURENATIVE_COOKIE = '_sn'.freeze
|
3
|
-
SECURENATIVE_HEADER = 'x-securenative'.freeze
|
4
|
-
|
5
|
-
def self.get_secure_header_from_request(headers)
|
6
|
-
return headers[RequestUtils.SECURENATIVE_HEADER] unless headers.nil?
|
7
|
-
|
8
|
-
[]
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.get_client_ip_from_request(request)
|
12
|
-
x_forwarded_for = request.env['HTTP_X_FORWARDED_FOR']
|
13
|
-
return x_forwarded_for unless x_forwarded_for.nil?
|
14
|
-
|
15
|
-
request.env['REMOTE_ADDR']
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.get_remote_ip_from_request(request)
|
19
|
-
request.remote_ip
|
20
|
-
end
|
21
|
-
end
|