Skip to content

Commit

Permalink
[gh-134] Fix the secret key being used as a wrong format when we use …
Browse files Browse the repository at this point in the history
…it to generate signed url in Akamai url generator
  • Loading branch information
vipulnsward committed Apr 27, 2024
1 parent 38090ce commit f6bf997
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/uploadcare/signed_url_generators/akamai_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class AkamaiGenerator < Uploadcare::SignedUrlGenerators::BaseGenerator
def generate_url(uuid, acl = uuid, wildcard: false)
raise ArgumentError, 'Must contain valid UUID' unless valid?(uuid)

formated_acl = build_acl(uuid, acl, wildcard: wildcard)
formatted_acl = build_acl(uuid, acl, wildcard: wildcard)
expire = build_expire
signature = build_signature(expire, formated_acl)
signature = build_signature(expire, formatted_acl)

TEMPLATE.gsub('{delimiter}', delimiter)
.sub('{cdn_host}', sanitized_string(cdn_host))
.sub('{uuid}', sanitized_string(uuid))
.sub('{acl}', formated_acl)
.sub('{acl}', formatted_acl)
.sub('{expiration}', expire)
.sub('{token}', signature)
end
Expand Down Expand Up @@ -46,8 +46,9 @@ def build_expire
end

def build_signature(expire, acl)
signature = %W[exp=#{expire} acl=#{acl}].join(delimiter)
OpenSSL::HMAC.hexdigest(algorithm, secret_key, signature)
signature = ["exp=#{expire}", "acl=#{acl}"].join(delimiter)
secret_key_bin = Array(secret_key.gsub(/\s/,'')).pack("H*")
OpenSSL::HMAC.hexdigest(algorithm, secret_key_bin, signature)
end

# rubocop:disable Style/SlicingWithRange
Expand Down

0 comments on commit f6bf997

Please sign in to comment.