Skip to content

Commit b350b15

Browse files
authored
Merge pull request #15 from skylab-tech/SCR-3-hmac
Scr 3 hmac
2 parents 9de9702 + e745add commit b350b15

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
ruby-version: 2.7
2020

2121
- name: Install libvips
22-
run: sudo apt install libvips-dev --no-install-recommends
22+
run: sudo apt-get install --fix-missing -qq -o Acquire::Retries=3 libvips
2323

2424
- name: Install Bundler
2525
run: gem install bundler -v '~>2.4.22'

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,24 @@ client.download_photo(photo_id, "/output/folder/path") # download photo with ori
273273
client.download_photo(photo_id, "/output/folder/test.jpg") # download photo with new filename to a directory
274274
```
275275
276+
#### Validate hmac headers
277+
278+
Applicable if you utilize the job callback url. Use to validate the job payload integrity.
279+
280+
- secret_key (string): Obtain from Skylab
281+
282+
- job_json_string (string): Raw json string obtained from callback PATCH request body
283+
284+
- request_timestamp (string): Obtained from callback PATCH request header 'X-Skylab-Timestamp'
285+
286+
- signature (string): Signature generated by Skylab to compare. Obtained from callback PATCH request header 'X-Skylab-Signature'
287+
288+
Returns **True** or **False** based on whether or not the signatures match.
289+
290+
```ruby
291+
api.validate_hmac_headers(secret_key, job_json_string, request_timestamp, signature)
292+
```
293+
276294
## Errors
277295
278296
The following errors may be generated:

lib/skylab_studio/client.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ def download_all_photos(photos_list, profile, output_path)
229229
end
230230
end
231231

232+
def validate_hmac_headers(secret_key, job_json_string, request_timestamp, signature)
233+
message = "#{request_timestamp}:#{job_json_string}".encode('utf-8')
234+
235+
# Create the HMAC signature using SHA-256
236+
hmac_digest = OpenSSL::HMAC.digest('sha256', secret_key.encode('utf-8'), message)
237+
generated_sig = Base64.strict_encode64(hmac_digest).force_encoding('utf-8')
238+
239+
# Compare the provided signature with the generated signature
240+
signature == generated_sig
241+
end
242+
232243
private
233244

234245
def get_upload_url(options = { use_cache_upload: false })

lib/skylab_studio/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module SkylabStudio
4-
VERSION = '1.0.7'
4+
VERSION = '1.0.8'
55
end

0 commit comments

Comments
 (0)