Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS authentication requires a valid Date or x-amz-date header curl

I am trying for simple image upload using cURL by passing the required headers that is requested by AWS but I'm getting the below error...

<Code>AccessDenied</Code><Message>AWS authentication requires a valid Date or x-amz-date header</Message>

Below is the authorization header I'm passing in..

curl -X PUT -T "/some/file.jpg" \
-H "Host: bucket.s3.amazonaws.com" \
-H "Date: date" \
-H "Content-Type: image/jpg" \
-H "Authorization: AWS XXXXXXX:XXXXXXXXXX" \
  https://bucket.s3.amazonaws.com/

and below is how the signature is made,

signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`

I've tried passing the date in stringToSign and in the headers, but no luck.. Please help ..

like image 805
avinoth Avatar asked Mar 26 '15 10:03

avinoth


People also ask

What is X-AMZ-date?

X-Amz-DateThe date that is used to create the signature. The format must be ISO 8601 basic format (YYYYMMDD'T'HHMMSS'Z'). For example, the following date time is a valid X-Amz-Date value: 20120325T120000Z .

How do I create an authorization header in AWS?

In order to create an authorization header, you need an AWS Access Key Id and a Secret Access Key. In ECS, the AWS Access Key Id maps to the ECS user id (UID). An AWS Access Key ID has 20 characters (some S3 clients, such as the S3 Browser, check this), but ECS data service does not have this limitation.

What is AWS4 Hmac SHA256?

AWS4-HMAC-SHA256. The algorithm that was used to calculate the signature. You must provide this value when you use AWS Signature Version 4 for authentication.


1 Answers

Fixed the issue.. Turns out the HTTP header need to be in RFC 7231 format. I formatted it and it worked., below is the format I used,

date -jnu +%a,\ %d\ %h\ %Y\ %T\ %Z

like image 118
avinoth Avatar answered Oct 11 '22 07:10

avinoth