From b9d9b3649390aae9e26ffd178d85e8b3eea59a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kadu=20Di=C3=B3genes?= Date: Tue, 20 Nov 2018 20:47:17 -0200 Subject: [PATCH 1/2] Allows client to send calculated hash payload --- lib/aws_auth/authorization_header.ex | 6 +++++- lib/aws_auth/utils.ex | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/aws_auth/authorization_header.ex b/lib/aws_auth/authorization_header.ex index 416615c..a7914d7 100644 --- a/lib/aws_auth/authorization_header.ex +++ b/lib/aws_auth/authorization_header.ex @@ -18,7 +18,11 @@ defmodule AWSAuth.AuthorizationHeader do headers = Map.put_new(headers, "host", uri.host) - payload = AWSAuth.Utils.hash_sha256(payload) + payload = if payload != :hashed do + AWSAuth.Utils.hash_sha256(payload) + else + payload + end headers = Map.put_new(headers, "x-amz-content-sha256", payload) diff --git a/lib/aws_auth/utils.ex b/lib/aws_auth/utils.ex index bd188ce..e2387cb 100644 --- a/lib/aws_auth/utils.ex +++ b/lib/aws_auth/utils.ex @@ -13,9 +13,11 @@ defmodule AWSAuth.Utils do |> Enum.sort(&(&1 < &2)) |> Enum.join(";") - hashed_payload = if hashed_payload == :unsigned, - do: "UNSIGNED-PAYLOAD", - else: hashed_payload + hashed_payload = case hashed_payload do + :unsigned -> "UNSIGNED-PAYLOAD" + :hashed -> headers["x-amz-content-sha256"] + _ -> hashed_payload + end encoded_path = path From 01381d58f52424bba2ed813dcd83dd8e1afa9cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kadu=20Di=C3=B3genes?= Date: Wed, 21 Nov 2018 09:09:35 -0200 Subject: [PATCH 2/2] Update authorization_header.ex --- lib/aws_auth/authorization_header.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/aws_auth/authorization_header.ex b/lib/aws_auth/authorization_header.ex index a7914d7..b108a69 100644 --- a/lib/aws_auth/authorization_header.ex +++ b/lib/aws_auth/authorization_header.ex @@ -18,10 +18,10 @@ defmodule AWSAuth.AuthorizationHeader do headers = Map.put_new(headers, "host", uri.host) - payload = if payload != :hashed do - AWSAuth.Utils.hash_sha256(payload) - else + payload = if payload == :hashed do payload + else + AWSAuth.Utils.hash_sha256(payload) end headers = Map.put_new(headers, "x-amz-content-sha256", payload)