smile-identity-core 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4632631c9d5d1180a47ba34c74c5fd759d888d4f2bee913a002fd011f30e2354
4
- data.tar.gz: 4e8a6febb9f7ebf199650c79db18f4d9c65fed6a6246cbd03bf17bfc78eae50f
3
+ metadata.gz: 2c6c2b9d1846e6939c1a1f8407b24d08f40eb54492f302ff682f0070afbd837a
4
+ data.tar.gz: 46d3ef6830ee732870ea1657faeb3d1feb8f020b05dd715b615d313541e90bfe
5
5
  SHA512:
6
- metadata.gz: 816929a769bc1ceb3dde1afc9957885dccf3ebb73c901b7d119277dedc64e3c59e14f2a7f1aa8304521314c262e4fa1393b3c74e562224c0b3f90ee7bcafc8a9
7
- data.tar.gz: d6c20e2a4947ecdf24fc0eabd2d24820277c60a4dd857b3ce74bff2b465cbbbea3b9530a8380069437b5309aa8fecaa0f461e822b4d21b8656234a7739e840d1
6
+ metadata.gz: 6548acb1e3cb5efa6cd2d73b048449e99ef74c8e3dde60fa06373c6535353f97bc46eb950446ed825c5938b95559db85d58870ce8909f258bcd7066bedae0085
7
+ data.tar.gz: 4a0b84d72c3ce4b69c051c944d2cc95d4c02bb58244fd2b47bc532d7f6a67ab5e7bb5d7cccb89c8e4a7fc0f217c3548a457ae1a6783ed6bdd2e9b3b18ed80d7d
data/.travis.yml CHANGED
@@ -4,4 +4,7 @@ language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
6
  - 2.5.1
7
- before_install: gem install bundler -v 2.0.2
7
+ - 2.6
8
+ - 2.7
9
+ - 3.0
10
+ before_install: gem install bundler -v 2.2.6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smile-identity-core (1.0.1)
4
+ smile-identity-core (1.1.0)
5
5
  rubyzip (~> 1.2, >= 1.2.3)
6
6
  typhoeus (~> 1.0, >= 1.0.1)
7
7
 
@@ -12,8 +12,8 @@ GEM
12
12
  docile (1.1.5)
13
13
  ethon (0.12.0)
14
14
  ffi (>= 1.3.0)
15
- ffi (1.11.3)
16
- json (2.2.0)
15
+ ffi (1.13.1)
16
+ json (2.5.1)
17
17
  rake (10.5.0)
18
18
  rspec (3.8.0)
19
19
  rspec-core (~> 3.8.0)
@@ -34,7 +34,7 @@ GEM
34
34
  json (>= 1.8, < 3)
35
35
  simplecov-html (~> 0.10.0)
36
36
  simplecov-html (0.10.2)
37
- typhoeus (1.3.1)
37
+ typhoeus (1.4.0)
38
38
  ethon (>= 0.9.0)
39
39
 
40
40
  PLATFORMS
@@ -48,4 +48,4 @@ DEPENDENCIES
48
48
  smile-identity-core!
49
49
 
50
50
  BUNDLED WITH
51
- 2.0.2
51
+ 2.2.6
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # SmileIdentityCore
1
+ # SmileIdentityCore [![Build Status](https://travis-ci.com/smileidentity/smile-identity-core-ruby.svg?branch=master)](https://travis-ci.com/smileidentity/smile-identity-core-ruby)
2
2
 
3
3
  The official Smile Identity gem exposes four classes namely; the Web Api class, the ID Api class, the Signature class and the Utilities class.
4
4
 
@@ -20,7 +20,7 @@ The **Utilities Class** allows you as the Partner to have access to our general
20
20
 
21
21
  This gem requires specific input parameters, for more detail on these parameters please refer to our [documentation for Web API](https://docs.smileidentity.com).
22
22
 
23
- Please note that you will have to be a Smile Identity Partner to be able to query our services. You can sign up on the [Portal](https://test-smileid.herokuapp.com/signup?products[]=1-IDVALIDATION&products[]=2-AUTHENTICATION).
23
+ Please note that you will have to be a Smile Identity Partner to be able to query our services. You can sign up on the [Portal](https://portal.smileidentity.com/signup).
24
24
 
25
25
  ## Installation
26
26
 
@@ -8,8 +8,8 @@ module SmileIdentityCore
8
8
  @sid_server = sid_server
9
9
  if !(sid_server =~ URI::regexp)
10
10
  sid_server_mapping = {
11
- 0 => 'https://3eydmgh10d.execute-api.us-west-2.amazonaws.com/test',
12
- 1 => 'https://la7am6gdm8.execute-api.us-west-2.amazonaws.com/prod'
11
+ 0 => 'https://testapi.smileidentity.com/v1',
12
+ 1 => 'https://api.smileidentity.com/v1',
13
13
  }
14
14
  @url = sid_server_mapping[sid_server.to_i]
15
15
  else
@@ -17,12 +17,10 @@ module SmileIdentityCore
17
17
  end
18
18
  end
19
19
 
20
- def submit_job(partner_params, id_info)
20
+ def submit_job(partner_params, id_info, options = {})
21
21
  self.partner_params = symbolize_keys partner_params
22
-
23
- @timestamp = Time.now.to_i
24
-
25
22
  self.id_info = symbolize_keys id_info
23
+ @use_new_signature = symbolize_keys(options || {}).fetch(:signature, false)
26
24
 
27
25
  if @partner_params[:job_type].to_i != 5
28
26
  raise ArgumentError.new('Please ensure that you are setting your job_type to 5 to query ID Api')
@@ -99,20 +97,28 @@ module SmileIdentityCore
99
97
  end
100
98
 
101
99
  def configure_json
102
- body = {
103
- timestamp: @timestamp,
104
- sec_key: determine_sec_key,
105
- partner_id: @partner_id,
106
- partner_params: @partner_params
107
- }
108
-
109
- body.merge!(@id_info)
110
- JSON.generate(body)
100
+ request_security(use_new_signature: @use_new_signature)
101
+ .merge(@id_info)
102
+ .merge(
103
+ partner_id: @partner_id,
104
+ partner_params: @partner_params)
105
+ .to_json
111
106
  end
112
107
 
113
- def determine_sec_key
114
- @sec_key = SmileIdentityCore::Signature.new(@partner_id, @api_key).generate_sec_key(@timestamp)[:sec_key]
108
+ def request_security(use_new_signature: true)
109
+ if use_new_signature
110
+ @timestamp = Time.now.to_s
111
+ {
112
+ signature: SmileIdentityCore::Signature.new(@partner_id, @api_key).generate_signature(@timestamp)[:signature],
113
+ timestamp: @timestamp,
114
+ }
115
+ else
116
+ @timestamp = Time.now.to_i
117
+ {
118
+ sec_key: SmileIdentityCore::Signature.new(@partner_id, @api_key).generate_sec_key(@timestamp)[:sec_key],
119
+ timestamp: @timestamp,
120
+ }
121
+ end
115
122
  end
116
-
117
123
  end
118
124
  end
@@ -3,7 +3,7 @@ module SmileIdentityCore
3
3
 
4
4
  def initialize(partner_id, api_key)
5
5
  @api_key = api_key
6
- @partner_id = partner_id.to_i
6
+ @partner_id = partner_id
7
7
  end
8
8
 
9
9
  def generate_sec_key(timestamp=Time.now.to_i)
@@ -36,5 +36,21 @@ module SmileIdentityCore
36
36
  raise e
37
37
  end
38
38
  end
39
+
40
+ def generate_signature(timestamp=Time.now.to_s)
41
+ hmac = OpenSSL::HMAC.new(@api_key, 'sha256')
42
+ hmac.update(timestamp.to_s)
43
+ hmac.update(@partner_id)
44
+ hmac.update("sid_request")
45
+ signature = Base64.strict_encode64(hmac.digest())
46
+ return {
47
+ signature: signature,
48
+ timestamp: timestamp.to_s
49
+ }
50
+ end
51
+
52
+ def confirm_signature(timestamp, msg_signature)
53
+ generate_signature(timestamp)[:signature] == msg_signature
54
+ end
39
55
  end
40
56
  end
@@ -7,8 +7,8 @@ module SmileIdentityCore
7
7
 
8
8
  if !(sid_server =~ URI::regexp)
9
9
  sid_server_mapping = {
10
- 0 => 'https://3eydmgh10d.execute-api.us-west-2.amazonaws.com/test',
11
- 1 => 'https://la7am6gdm8.execute-api.us-west-2.amazonaws.com/prod'
10
+ 0 => 'https://testapi.smileidentity.com/v1',
11
+ 1 => 'https://api.smileidentity.com/v1',
12
12
  }
13
13
  @url = sid_server_mapping[sid_server.to_i]
14
14
  else
@@ -20,16 +20,12 @@ module SmileIdentityCore
20
20
  end
21
21
 
22
22
  def get_job_status(user_id, job_id, options = {})
23
+ options = symbolize_keys(options || {})
24
+ options[:return_history] ||= false
25
+ options[:return_image_links] ||= false
23
26
 
24
- if(options.nil? || options.empty?)
25
- options = {
26
- return_history: false,
27
- return_job_status: false
28
- }
29
- end
30
-
31
- @timestamp = Time.now.to_i
32
- return query_job_status(user_id, job_id, symbolize_keys(options))
27
+ security = request_security(use_new_signature: options.fetch(:signature, false))
28
+ query_job_status(configure_job_query(user_id, job_id, options).merge(security))
33
29
  end
34
30
 
35
31
  private
@@ -38,21 +34,30 @@ module SmileIdentityCore
38
34
  (params.is_a?(Hash)) ? Hash[params.map{ |k, v| [k.to_sym, v] }] : params
39
35
  end
40
36
 
41
- def query_job_status(user_id, job_id, options)
37
+ def query_job_status(request_json_data)
42
38
  url = "#{@url}/job_status"
43
39
 
44
40
  request = Typhoeus::Request.new(
45
41
  url,
46
42
  headers: {'Content-Type': 'application/json', 'Accept': 'application/json'},
47
43
  method: :post,
48
- body: configure_job_query(user_id, job_id, options)
44
+ body: request_json_data.to_json
49
45
  )
50
46
 
51
47
  request.on_complete do |response|
52
48
  begin
53
49
  body = JSON.parse(response.body)
54
50
 
55
- valid = @signature_connection.confirm_sec_key(body['timestamp'], body['signature'])
51
+ # NB: we have to trust that the server will return the right kind of
52
+ # timestamp (integer or string) for the signature, and the right kind
53
+ # of signature in the "signature" field. The best way to know what
54
+ # kind of validation to perform is by remembering which kind of
55
+ # security we started with.
56
+ if request_json_data.has_key?(:sec_key)
57
+ valid = @signature_connection.confirm_sec_key(body['timestamp'], body['signature'])
58
+ else
59
+ valid = @signature_connection.confirm_signature(body['timestamp'], body['signature'])
60
+ end
56
61
 
57
62
  if(!valid)
58
63
  raise "Unable to confirm validity of the job_status response"
@@ -67,17 +72,30 @@ module SmileIdentityCore
67
72
  request.run
68
73
  end
69
74
 
75
+ def request_security(use_new_signature: false)
76
+ if use_new_signature
77
+ @timestamp = Time.now.to_s
78
+ {
79
+ signature: @signature_connection.generate_signature(@timestamp)[:signature],
80
+ timestamp: @timestamp,
81
+ }
82
+ else
83
+ @timestamp = Time.now.to_i
84
+ {
85
+ sec_key: @signature_connection.generate_sec_key(@timestamp)[:sec_key],
86
+ timestamp: @timestamp,
87
+ }
88
+ end
89
+ end
90
+
70
91
  def configure_job_query(user_id, job_id, options)
71
- return {
72
- sec_key: @signature_connection.generate_sec_key(@timestamp)[:sec_key],
73
- timestamp: @timestamp,
92
+ {
74
93
  user_id: user_id,
75
94
  job_id: job_id,
76
95
  partner_id: @partner_id,
77
- image_links: options[:return_image_links] || false,
78
- history: options[:return_history] || false
79
- }.to_json
96
+ image_links: options[:return_image_links],
97
+ history: options[:return_history]
98
+ }
80
99
  end
81
-
82
100
  end
83
101
  end
@@ -1,3 +1,8 @@
1
1
  module SmileIdentityCore
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
+
4
+ def self.version_as_hash
5
+ major, minor, patch = *VERSION.split('.')
6
+ { majorVersion: major, minorVersion: minor, buildNumber: patch }
7
+ end
3
8
  end
@@ -18,8 +18,8 @@ module SmileIdentityCore
18
18
  @sid_server = sid_server
19
19
  if !(sid_server =~ URI::regexp)
20
20
  sid_server_mapping = {
21
- 0 => 'https://3eydmgh10d.execute-api.us-west-2.amazonaws.com/test',
22
- 1 => 'https://la7am6gdm8.execute-api.us-west-2.amazonaws.com/prod'
21
+ 0 => 'https://testapi.smileidentity.com/v1',
22
+ 1 => 'https://api.smileidentity.com/v1',
23
23
  }
24
24
  @url = sid_server_mapping[sid_server.to_i]
25
25
  else
@@ -35,8 +35,6 @@ module SmileIdentityCore
35
35
  end
36
36
 
37
37
  self.images = images
38
- @timestamp = Time.now.to_i
39
-
40
38
  self.id_info = symbolize_keys id_info
41
39
  self.options = symbolize_keys options
42
40
 
@@ -130,19 +128,13 @@ module SmileIdentityCore
130
128
  end
131
129
 
132
130
  def options=(options)
133
- updated_options = options
134
-
135
- if updated_options.nil?
136
- updated_options = {}
137
- end
131
+ updated_options = options || {}
138
132
 
139
- [:optional_callback, :return_job_status, :return_image_links, :return_history].map do |key|
140
- if key != :optional_callback
141
- updated_options[key] = check_boolean(key, options)
142
- else
143
- updated_options[key] = check_string(key, options)
144
- end
145
- end
133
+ updated_options[:optional_callback] = check_string(:optional_callback, options)
134
+ updated_options[:return_job_status] = check_boolean(:return_job_status, options)
135
+ updated_options[:return_image_links] = check_boolean(:return_image_links, options)
136
+ updated_options[:return_history] = check_boolean(:return_history, options)
137
+ @use_new_signature = updated_options.fetch(:signature, false)
146
138
 
147
139
  @options = updated_options
148
140
  end
@@ -176,6 +168,7 @@ module SmileIdentityCore
176
168
 
177
169
  return obj[key]
178
170
  end
171
+ # zeKn:WFL7t2X/+4
179
172
 
180
173
  def check_string(key, obj)
181
174
  if (!obj || !obj[key])
@@ -185,23 +178,30 @@ module SmileIdentityCore
185
178
  end
186
179
  end
187
180
 
188
- def determine_sec_key
189
- @sec_key = SmileIdentityCore::Signature.new(@partner_id, @api_key).generate_sec_key(@timestamp)[:sec_key]
181
+ def request_security(use_new_signature: true)
182
+ if use_new_signature
183
+ @timestamp = Time.now.to_s
184
+ {
185
+ signature: SmileIdentityCore::Signature.new(@partner_id, @api_key).generate_signature(@timestamp)[:signature],
186
+ timestamp: @timestamp,
187
+ }
188
+ else
189
+ @timestamp = Time.now.to_i
190
+ {
191
+ sec_key: SmileIdentityCore::Signature.new(@partner_id, @api_key).generate_sec_key(@timestamp)[:sec_key],
192
+ timestamp: @timestamp,
193
+ }
194
+ end
190
195
  end
191
196
 
192
197
  def configure_prep_upload_json
193
-
194
- body = {
198
+ request_security(use_new_signature: @use_new_signature).merge(
195
199
  file_name: 'selfie.zip',
196
- timestamp: @timestamp,
197
- sec_key: determine_sec_key,
198
200
  smile_client_id: @partner_id,
199
201
  partner_params: @partner_params,
200
202
  model_parameters: {}, # what is this for
201
203
  callback_url: @callback_url
202
- }
203
-
204
- JSON.generate(body)
204
+ ).to_json
205
205
  end
206
206
 
207
207
  def setup_requests
@@ -216,6 +216,12 @@ module SmileIdentityCore
216
216
 
217
217
  request.on_complete do |response|
218
218
  if response.success?
219
+ # TODO: if/when we sign these responses, verify the signature here and raise if it's off.
220
+ # if updated_options[:signature]
221
+ # SmileIdentityCore::Signature.new(@partner_id, @api_key).generate_signature(@timestamp)
222
+ # else
223
+ # SmileIdentityCore::Signature.new(@partner_id, @api_key).generate_sec_key(@timestamp)
224
+ # end
219
225
 
220
226
  prep_upload_response = JSON.parse(response.body)
221
227
  info_json = configure_info_json(prep_upload_response)
@@ -239,18 +245,12 @@ module SmileIdentityCore
239
245
  def configure_info_json(server_information)
240
246
  info = {
241
247
  "package_information": {
242
- "apiVersion": {
243
- "buildNumber": 0,
244
- "majorVersion": 2,
245
- "minorVersion": 0
246
- },
248
+ "apiVersion": SmileIdentityCore.version_as_hash,
247
249
  "language": "ruby"
248
250
  },
249
- "misc_information": {
250
- "sec_key": @sec_key,
251
+ "misc_information": request_security(use_new_signature: @use_new_signature).merge(
251
252
  "retry": "false",
252
253
  "partner_params": @partner_params,
253
- "timestamp": @timestamp,
254
254
  "file_name": "selfie.zip", # figure out what to do here
255
255
  "smile_client_id": @partner_id,
256
256
  "callback_url": @callback_url,
@@ -266,7 +266,7 @@ module SmileIdentityCore
266
266
  "countryCode": "+",
267
267
  "countryName": ""
268
268
  }
269
- },
269
+ ),
270
270
  "id_info": @id_info,
271
271
  "images": configure_image_payload,
272
272
  "server_information": server_information
@@ -276,7 +276,7 @@ module SmileIdentityCore
276
276
 
277
277
  def configure_image_payload
278
278
  @images.map { |i|
279
- if isImageFile?i[:image_type_id]
279
+ if image_file?(i[:image_type_id])
280
280
  {
281
281
  image_type_id: i[:image_type_id],
282
282
  image: '',
@@ -292,7 +292,7 @@ module SmileIdentityCore
292
292
  }
293
293
  end
294
294
 
295
- def isImageFile?type
295
+ def image_file?(type)
296
296
  type.to_i == 0 || type.to_i == 1
297
297
  end
298
298
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smile-identity-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ridhwana
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-16 00:00:00.000000000 Z
11
+ date: 2021-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,7 +130,6 @@ files:
130
130
  - lib/smile-identity-core/version.rb
131
131
  - lib/smile-identity-core/web_api.rb
132
132
  - smile-identity-core.gemspec
133
- - travis.yml
134
133
  homepage: https://www.smileidentity.com/
135
134
  licenses:
136
135
  - MIT
@@ -139,7 +138,7 @@ metadata:
139
138
  source_code_uri: https://github.com/smileidentity/smile-identity-core-ruby
140
139
  documentation_uri: https://docs.smileidentity.com
141
140
  changelog_uri: https://github.com/smileidentity/smile-identity-core/blob/master/CHANGELOG.md
142
- post_install_message:
141
+ post_install_message:
143
142
  rdoc_options: []
144
143
  require_paths:
145
144
  - lib
@@ -154,9 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
153
  - !ruby/object:Gem::Version
155
154
  version: '0'
156
155
  requirements: []
157
- rubyforge_project:
158
- rubygems_version: 2.7.6
159
- signing_key:
156
+ rubygems_version: 3.2.3
157
+ signing_key:
160
158
  specification_version: 4
161
159
  summary: The Smile Identity Web API allows the user to access most of the features
162
160
  of the Smile Identity system through direct server to server queries.
data/travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.5.1
4
-
5
- script:
6
- - bundle exec rake spec
7
-
8
- before_install:
9
- - gem install bundle