Gaurav Parashar
Gaurav Parashar

Reputation: 1592

Integrity check with S3 upload

I am trying to ensure that the file i uploaded to an S3 bucket is not tampered with while uploading. I am trying this based on a trivial example, by following the steps listed here.

As I understand, reading through the docs, one needs to generate the md5 checksum and then pass that in the Content-MD5 header in the put command. Below are the steps that i took, but it is failing irrespective. What am i missing here?

openssl md5 -binary test-md5.txt | base64
Y7uGBT9hu26jZFre3slWqw==


aws s3api put-object --bucket cloudtrailmanual --key test-md5.txt --content-md5 Y7uGBT9hu26jZFre3slWqw==

An error occurred (BadDigest) when calling the PutObject operation (reached max retries: 4): The Content-MD5 you specified did not match what we received.

I have tried to generate the md5 checksum without passing the binary flag, base64 encoded that and then tried again, but that fails as well. What am i missing here?

Upvotes: 1

Views: 786

Answers (1)

Gaurav Parashar
Gaurav Parashar

Reputation: 1592

This was too dumb on my part, i missed specifying the body element, by default this was taking a zero byte body.

This will work as expected, posting this for someone who might find this handy.

aws s3api put-object --bucket cloudtrailmanual --key test-md5.txt --content-md5 Y7uGBT9hu26jZFre3slWqw== --body test-md5.txt

Upvotes: 2

Related Questions