securenative 0.1.5 → 0.1.16
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 +57 -0
- data/.github/workflows/publish.yml +60 -0
- data/.github/workflows/test.yml +45 -0
- data/.rakeTasks +7 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -1
- data/Gemfile.lock +28 -2
- data/README.md +134 -66
- data/Rakefile +5 -1
- data/VERSION +1 -0
- data/lib/securenative/api_manager.rb +30 -0
- data/lib/securenative/config/configuration_builder.rb +26 -0
- data/lib/securenative/config/configuration_manager.rb +53 -0
- data/lib/securenative/config/securenative_options.rb +18 -0
- data/lib/securenative/context/context_builder.rb +59 -0
- data/lib/securenative/context/securenative_context.rb +14 -0
- data/lib/securenative/enums/api_route.rb +4 -0
- data/lib/securenative/enums/event_types.rb +21 -0
- data/lib/securenative/enums/failover_strategy.rb +4 -0
- data/lib/securenative/enums/risk_level.rb +5 -0
- data/lib/securenative/event_manager.rb +122 -61
- data/lib/securenative/event_options_builder.rb +21 -0
- data/lib/securenative/exceptions/securenative_config_exception.rb +2 -0
- data/lib/securenative/exceptions/securenative_http_exception.rb +2 -0
- data/lib/securenative/exceptions/securenative_invalid_options_exception.rb +2 -0
- data/lib/securenative/exceptions/securenative_invalid_uri_exception.rb +2 -0
- data/lib/securenative/exceptions/securenative_parse_exception.rb +2 -0
- data/lib/securenative/exceptions/securenative_sdk_Illegal_state_exception.rb +2 -0
- data/lib/securenative/exceptions/securenative_sdk_exception.rb +2 -0
- data/lib/securenative/http/http_response.rb +10 -0
- data/lib/securenative/http/securenative_http_client.rb +30 -0
- data/lib/securenative/logger.rb +42 -0
- data/lib/securenative/models/client_token.rb +10 -0
- data/lib/securenative/models/device.rb +8 -0
- data/lib/securenative/models/event_options.rb +13 -0
- data/lib/securenative/models/request_context.rb +15 -0
- data/lib/securenative/models/request_options.rb +10 -0
- data/lib/securenative/models/sdk_event.rb +25 -0
- data/lib/securenative/models/user_traits.rb +10 -0
- data/lib/securenative/models/verify_result.rb +10 -0
- data/lib/securenative/securenative.iml +9 -0
- data/lib/securenative/securenative.rb +82 -0
- data/lib/securenative/utils/date_utils.rb +7 -0
- data/lib/securenative/utils/encryption_utils.rb +38 -0
- data/lib/securenative/utils/ip_utils.rb +22 -0
- data/lib/securenative/utils/request_utils.rb +21 -0
- data/lib/securenative/utils/signature_utils.rb +14 -0
- data/lib/securenative/utils/utils.rb +9 -0
- data/lib/securenative/utils/version_utils.rb +10 -0
- data/securenative.gemspec +4 -4
- metadata +51 -15
- data/lib/securenative.rb +0 -39
- data/lib/securenative/config.rb +0 -9
- data/lib/securenative/event_options.rb +0 -86
- data/lib/securenative/event_type.rb +0 -21
- data/lib/securenative/http_client.rb +0 -20
- data/lib/securenative/secure_native_sdk.rb +0 -62
- data/lib/securenative/securenative_options.rb +0 -17
- data/lib/securenative/sn_exception.rb +0 -5
- data/lib/securenative/utils.rb +0 -41
data/securenative.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
lib = File.expand_path("lib", __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
|
3
|
+
require_relative "lib/securenative/utils/version_utils"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "securenative"
|
7
|
-
spec.version =
|
7
|
+
spec.version = VersionUtils.version
|
8
8
|
spec.authors = ["SecureNative"]
|
9
9
|
spec.email = ["support@securenative.com"]
|
10
10
|
|
11
|
-
spec.summary = %q{SecureNative SDK for
|
11
|
+
spec.summary = %q{SecureNative SDK for Ruby}
|
12
12
|
spec.homepage = "https://www.securenative.com"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 2.0"
|
27
|
-
spec.add_development_dependency "rake", "~>
|
27
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: securenative
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SecureNative
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
description:
|
42
42
|
email:
|
43
43
|
- support@securenative.com
|
@@ -45,24 +45,60 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- ".github/workflows/ci.yml"
|
49
|
+
- ".github/workflows/publish.yml"
|
50
|
+
- ".github/workflows/test.yml"
|
48
51
|
- ".gitignore"
|
52
|
+
- ".rakeTasks"
|
53
|
+
- ".rspec"
|
54
|
+
- ".travis.yml"
|
49
55
|
- Gemfile
|
50
56
|
- Gemfile.lock
|
51
57
|
- LICENSE
|
52
58
|
- README.md
|
53
59
|
- Rakefile
|
60
|
+
- VERSION
|
54
61
|
- bin/console
|
55
62
|
- bin/setup
|
56
|
-
- lib/securenative.rb
|
57
|
-
- lib/securenative/config.rb
|
63
|
+
- lib/securenative/api_manager.rb
|
64
|
+
- lib/securenative/config/configuration_builder.rb
|
65
|
+
- lib/securenative/config/configuration_manager.rb
|
66
|
+
- lib/securenative/config/securenative_options.rb
|
67
|
+
- lib/securenative/context/context_builder.rb
|
68
|
+
- lib/securenative/context/securenative_context.rb
|
69
|
+
- lib/securenative/enums/api_route.rb
|
70
|
+
- lib/securenative/enums/event_types.rb
|
71
|
+
- lib/securenative/enums/failover_strategy.rb
|
72
|
+
- lib/securenative/enums/risk_level.rb
|
58
73
|
- lib/securenative/event_manager.rb
|
59
|
-
- lib/securenative/
|
60
|
-
- lib/securenative/
|
61
|
-
- lib/securenative/
|
62
|
-
- lib/securenative/
|
63
|
-
- lib/securenative/
|
64
|
-
- lib/securenative/
|
65
|
-
- lib/securenative/
|
74
|
+
- lib/securenative/event_options_builder.rb
|
75
|
+
- lib/securenative/exceptions/securenative_config_exception.rb
|
76
|
+
- lib/securenative/exceptions/securenative_http_exception.rb
|
77
|
+
- lib/securenative/exceptions/securenative_invalid_options_exception.rb
|
78
|
+
- lib/securenative/exceptions/securenative_invalid_uri_exception.rb
|
79
|
+
- lib/securenative/exceptions/securenative_parse_exception.rb
|
80
|
+
- lib/securenative/exceptions/securenative_sdk_Illegal_state_exception.rb
|
81
|
+
- lib/securenative/exceptions/securenative_sdk_exception.rb
|
82
|
+
- lib/securenative/http/http_response.rb
|
83
|
+
- lib/securenative/http/securenative_http_client.rb
|
84
|
+
- lib/securenative/logger.rb
|
85
|
+
- lib/securenative/models/client_token.rb
|
86
|
+
- lib/securenative/models/device.rb
|
87
|
+
- lib/securenative/models/event_options.rb
|
88
|
+
- lib/securenative/models/request_context.rb
|
89
|
+
- lib/securenative/models/request_options.rb
|
90
|
+
- lib/securenative/models/sdk_event.rb
|
91
|
+
- lib/securenative/models/user_traits.rb
|
92
|
+
- lib/securenative/models/verify_result.rb
|
93
|
+
- lib/securenative/securenative.iml
|
94
|
+
- lib/securenative/securenative.rb
|
95
|
+
- lib/securenative/utils/date_utils.rb
|
96
|
+
- lib/securenative/utils/encryption_utils.rb
|
97
|
+
- lib/securenative/utils/ip_utils.rb
|
98
|
+
- lib/securenative/utils/request_utils.rb
|
99
|
+
- lib/securenative/utils/signature_utils.rb
|
100
|
+
- lib/securenative/utils/utils.rb
|
101
|
+
- lib/securenative/utils/version_utils.rb
|
66
102
|
- securenative.gemspec
|
67
103
|
homepage: https://www.securenative.com
|
68
104
|
licenses:
|
@@ -84,8 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
120
|
- !ruby/object:Gem::Version
|
85
121
|
version: '0'
|
86
122
|
requirements: []
|
87
|
-
rubygems_version: 3.0.
|
123
|
+
rubygems_version: 3.0.3
|
88
124
|
signing_key:
|
89
125
|
specification_version: 4
|
90
|
-
summary: SecureNative SDK for
|
126
|
+
summary: SecureNative SDK for Ruby
|
91
127
|
test_files: []
|
data/lib/securenative.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require_relative 'securenative/sn_exception'
|
2
|
-
require_relative 'securenative/secure_native_sdk'
|
3
|
-
|
4
|
-
$securenative = nil
|
5
|
-
|
6
|
-
module SecureNative
|
7
|
-
def self.init(api_key, options: SecureNativeOptions.new)
|
8
|
-
if $securenative == nil
|
9
|
-
$securenative = SecureNativeSDK.new(api_key, options: options)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.track(event)
|
14
|
-
sdk = _get_or_throw
|
15
|
-
sdk.track(event)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.verify(event)
|
19
|
-
sdk = _get_or_throw
|
20
|
-
sdk.verify(event)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.verify_webhook(hmac_header, body)
|
24
|
-
sdk = _get_or_throw
|
25
|
-
sdk.verify_webhook(hmac_header = hmac_header, body = body)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.flush
|
29
|
-
sdk = _get_or_throw
|
30
|
-
sdk.flush
|
31
|
-
end
|
32
|
-
|
33
|
-
def self._get_or_throw
|
34
|
-
if $securenative == nil
|
35
|
-
raise SecureNativeSDKException.new
|
36
|
-
end
|
37
|
-
$securenative
|
38
|
-
end
|
39
|
-
end
|
data/lib/securenative/config.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
module Config
|
2
|
-
SDK_VERSION = '0.1.5'
|
3
|
-
MAX_ALLOWED_PARAMS = 6
|
4
|
-
API_URL_PROD = "https://api.securenative.com/collector/api/v1"
|
5
|
-
API_URL_STG = "https://api.securenative-stg.com/collector/api/v1"
|
6
|
-
TRACK_EVENT = "/track"
|
7
|
-
VERIFY_EVENT = "/verify"
|
8
|
-
FLOW_EVENT = "/flow"
|
9
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
|
3
|
-
class User
|
4
|
-
def initialize(user_id: "", user_email: "", user_name: "")
|
5
|
-
@user_id = user_id
|
6
|
-
@user_email = user_email
|
7
|
-
@user_name = user_name
|
8
|
-
end
|
9
|
-
|
10
|
-
attr_reader :user_id
|
11
|
-
attr_reader :user_email
|
12
|
-
attr_reader :user_name
|
13
|
-
end
|
14
|
-
|
15
|
-
class Event
|
16
|
-
def initialize(event_type, user: User(), ip: "127.0.0.1", remote_ip: "127.0.0.1", user_agent: "unknown", sn_cookie: nil, params: nil)
|
17
|
-
@event_type = event_type
|
18
|
-
@user = user
|
19
|
-
@ip = ip
|
20
|
-
@remote_ip = remote_ip
|
21
|
-
@user_agent = user_agent
|
22
|
-
@cid = ""
|
23
|
-
@fp = ""
|
24
|
-
|
25
|
-
if params
|
26
|
-
unless params.length > 0 && params[0].instance_of?(CustomParam)
|
27
|
-
raise ArgumentError("custom params should be a list of CustomParams")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
@params = params
|
31
|
-
|
32
|
-
if sn_cookie
|
33
|
-
@cid, @cid = Utils.parse_cookie(sn_cookie)
|
34
|
-
end
|
35
|
-
@vid = SecureRandom.uuid
|
36
|
-
@ts = Time.now.getutc.to_i
|
37
|
-
end
|
38
|
-
|
39
|
-
def to_hash
|
40
|
-
p = Array.new
|
41
|
-
if @params
|
42
|
-
@params.each do |param|
|
43
|
-
p << {:key => param.key, :value => param.value}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
{
|
48
|
-
:eventType => @event_type,
|
49
|
-
:user => {
|
50
|
-
:id => @user.user_id,
|
51
|
-
:email => @user.user_email,
|
52
|
-
:name => @user.user_name
|
53
|
-
},
|
54
|
-
:remoteIP => @remote_ip,
|
55
|
-
:ip => @ip,
|
56
|
-
:cid => @cid,
|
57
|
-
:fp => @fp,
|
58
|
-
:ts => @ts,
|
59
|
-
:vid => @vid,
|
60
|
-
:userAgent => @user_agent,
|
61
|
-
:device => Hash.new,
|
62
|
-
:params => p
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
attr_reader :cid
|
67
|
-
attr_reader :params
|
68
|
-
attr_reader :user_agent
|
69
|
-
attr_reader :user
|
70
|
-
attr_reader :remote_ip
|
71
|
-
attr_reader :event_type
|
72
|
-
attr_reader :fp
|
73
|
-
attr_reader :ip
|
74
|
-
attr_reader :ts
|
75
|
-
attr_reader :vid
|
76
|
-
end
|
77
|
-
|
78
|
-
class CustomParam
|
79
|
-
def initialize(key, value)
|
80
|
-
@key = key
|
81
|
-
@value = value
|
82
|
-
end
|
83
|
-
|
84
|
-
attr_reader :key
|
85
|
-
attr_reader :value
|
86
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module EventType
|
2
|
-
LOG_IN = "sn.user.login"
|
3
|
-
LOG_IN_CHALLENGE = "sn.user.login.challenge"
|
4
|
-
LOG_IN_FAILURE = "sn.user.login.failure"
|
5
|
-
LOG_OUT = "sn.user.logout"
|
6
|
-
SIGN_UP = "sn.user.signup"
|
7
|
-
AUTH_CHALLENGE = "sn.user.auth.challenge"
|
8
|
-
AUTH_CHALLENGE_SUCCESS = "sn.user.auth.challenge.success"
|
9
|
-
AUTH_CHALLENGE_FAILURE = "sn.user.auth.challenge.failure"
|
10
|
-
TWO_FACTOR_DISABLE = "sn.user.2fa.disable"
|
11
|
-
EMAIL_UPDATE = "sn.user.email.update"
|
12
|
-
PASSWORD_RESET = "sn.user.password.reset"
|
13
|
-
PASSWORD_RESET_SUCCESS = "sn.user.password.reset.success"
|
14
|
-
PASSWORD_UPDATE = "sn.user.password.update"
|
15
|
-
PASSWORD_RESET_FAILURE = "sn.user.password.reset.failure"
|
16
|
-
USER_INVITE = "sn.user.invite"
|
17
|
-
ROLE_UPDATE = "sn.user.role.update"
|
18
|
-
PROFILE_UPDATE = "sn.user.profile.update"
|
19
|
-
PAGE_VIEW = "sn.user.page.view"
|
20
|
-
VERIFY = "sn.verify"
|
21
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'httpclient'
|
2
|
-
|
3
|
-
class HttpClient
|
4
|
-
def initialize
|
5
|
-
@client = HTTPClient.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def headers(api_key)
|
9
|
-
{
|
10
|
-
"Content-Type" => 'application/json',
|
11
|
-
"User-Agent" => 'SecureNative-ruby',
|
12
|
-
"Sn-Version" => Config::SDK_VERSION,
|
13
|
-
"Authorization" => api_key
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
def post(url, api_key, body)
|
18
|
-
@client.post(url, body, self.headers(api_key))
|
19
|
-
end
|
20
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require_relative 'event_manager'
|
2
|
-
require_relative 'config'
|
3
|
-
require_relative 'sn_exception'
|
4
|
-
require_relative 'utils'
|
5
|
-
require 'json'
|
6
|
-
|
7
|
-
class SecureNativeSDK
|
8
|
-
def initialize(api_key, options: SecureNativeOptions.new)
|
9
|
-
if api_key == nil
|
10
|
-
raise SecureNativeSDKException.new
|
11
|
-
end
|
12
|
-
|
13
|
-
@api_key = api_key
|
14
|
-
@options = options
|
15
|
-
@event_manager = EventManager.new(@api_key, options: @options)
|
16
|
-
end
|
17
|
-
|
18
|
-
def api_key
|
19
|
-
@api_key
|
20
|
-
end
|
21
|
-
|
22
|
-
def version
|
23
|
-
Config::SDK_VERSION
|
24
|
-
end
|
25
|
-
|
26
|
-
def track(event)
|
27
|
-
validate_event(event)
|
28
|
-
@event_manager.send_async(event, Config::TRACK_EVENT)
|
29
|
-
end
|
30
|
-
|
31
|
-
def verify(event)
|
32
|
-
validate_event(event)
|
33
|
-
res = @event_manager.send_sync(event, Config::VERIFY_EVENT)
|
34
|
-
if res.status_code == 200
|
35
|
-
return JSON.parse(res.body)
|
36
|
-
end
|
37
|
-
nil
|
38
|
-
end
|
39
|
-
|
40
|
-
def flow(event) # Note: For future purposes
|
41
|
-
validate_event(event)
|
42
|
-
@event_manager.send_async(event, Config::FLOW_EVENT)
|
43
|
-
end
|
44
|
-
|
45
|
-
def verify_webhook(hmac_header, body)
|
46
|
-
Utils.verify_signature(@api_key, body, hmac_header)
|
47
|
-
end
|
48
|
-
|
49
|
-
def flush
|
50
|
-
@event_manager.flush
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def validate_event(event)
|
56
|
-
unless event.params.nil?
|
57
|
-
if event.params.length > Config::MAX_ALLOWED_PARAMS
|
58
|
-
event.params = event.params[0, Config::MAX_ALLOWED_PARAMS]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require_relative 'config'
|
2
|
-
|
3
|
-
class SecureNativeOptions
|
4
|
-
def initialize(api_url: Config::API_URL_PROD, interval: 1000, max_events: 1000, timeout: 1500, auto_send: true)
|
5
|
-
@timeout = timeout
|
6
|
-
@max_events = max_events
|
7
|
-
@api_url = api_url
|
8
|
-
@interval = interval
|
9
|
-
@auto_send = auto_send
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_reader :timeout
|
13
|
-
attr_reader :max_events
|
14
|
-
attr_reader :api_url
|
15
|
-
attr_reader :interval
|
16
|
-
attr_reader :auto_send
|
17
|
-
end
|
data/lib/securenative/utils.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require "base64"
|
2
|
-
require "json"
|
3
|
-
require 'openssl'
|
4
|
-
|
5
|
-
module Utils
|
6
|
-
def self.verify_signature(secret, text_body, header_signature)
|
7
|
-
begin
|
8
|
-
key = secret.encode('utf-8')
|
9
|
-
body = text_body.encode('utf-8')
|
10
|
-
calculated_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha512'), key, body)
|
11
|
-
calculated_signature.eql? header_signature
|
12
|
-
rescue Exception
|
13
|
-
return false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.parse_cookie(cookie = nil)
|
18
|
-
fp = ""
|
19
|
-
cid = ""
|
20
|
-
unless cookie
|
21
|
-
return fp, cid
|
22
|
-
end
|
23
|
-
|
24
|
-
begin
|
25
|
-
decoded_cookie = Base64.decode64(cookie)
|
26
|
-
unless decoded_cookie
|
27
|
-
decoded_cookie = "{}"
|
28
|
-
end
|
29
|
-
jsonified = JSON.generate(decoded_cookie)
|
30
|
-
if jsonified["fp"]
|
31
|
-
fp = jsonified["fp"]
|
32
|
-
end
|
33
|
-
if jsonified["cid"]
|
34
|
-
cid = jsonified["cid"]
|
35
|
-
end
|
36
|
-
rescue Exception
|
37
|
-
ensure
|
38
|
-
return fp, cid
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|