-
Notifications
You must be signed in to change notification settings - Fork 156
Append x-amz-checksum headers when using hashing algorithm other than MD5 #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
defp get_hash_config() do | ||
Application.get_env(:ex_aws_s3, :content_hash_algorithm) || :md5 | ||
end | ||
|
||
# Supported hash algorithms: | ||
# https://www.erlang.org/doc/man/crypto.html#type-hash_algorithm | ||
@spec hash_header(atom()) :: binary() | ||
defp hash_header(alg) when is_atom(alg), do: "content-#{to_string(alg)}" | ||
defp hash_header(:md5), do: "content-md5" | ||
defp hash_header(alg) when is_atom(alg), do: "x-amz-checksum-#{to_string(alg)}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I noticed the "spec" seems to be using x-amz-checksum
, seems like this will be a good addition
defp hash_header(alg) when is_atom(alg), do: "content-#{to_string(alg)}" | ||
@spec hash_header(hash_algorithm()) :: binary() | ||
defp hash_header(:md5), do: "content-md5" | ||
defp hash_header(:sha), do: "x-amz-checksum-sha1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed that erlang uses sha
but S3 expects sha1
so mapping that here.
Hey there @bernardd, would you be able to give this a look? Thanks :) |
Hi @bernardd, just wanted to check in on this! Let me know if there is anything you need on my end. Thanks! |
Hi @d3caf - sorry about taking so long to get to this. All looks good - thanks especially for the docs and tests :) |
@bernardd sorry to bug you, but do you have an idea of when a new release will be made including this? Trying to get an idea of when I can transition off of my forked version. Happy to help prepare a release as well, if you'd like! |
While it was possible to specify an alternate hashing algorithm to ex_aws_s3, the header wasn't correctly appended to the request and was instead appended as
Content-<hash algo>
. AWS looks to require eitherContent-MD5
orx-amz-checksum-<hash algo>
so this implements that behavior.I also added some unit tests around this. Open to suggestions as to how to improve them since I was a little unsure about modifying the application env during a test.