jeudi 29 janvier 2015

AWS signature version 4 sha256 hash not signing correctly?

I am trying to use the AWS signature version 4 to submit a request to S3.


When I submit my request I get the message The request signature we calculated does not match the signature you provided. Check your key and signing method.


I am not sure where to go from here. I have tried several different hash algorithms (sha1, md5) but always get the same response. I have verified the Access Key and Secret Key. I just created a new one pair on AWS, and it still fails.


Any help is appreciated!





<?php
$date = date('Ymd');
$x_date = $date . "T000000Z";
$credential = AWS_ACCESS_KEY . '/' . $date . '/us-west-2/s3/aws4_request';
$redirect = 'http://ift.tt/18znq87';

$conditions = array(
array('bucket' => 'tracescope'),
array('starts-with', '$key', 'user/user1/'),
array('acl' => 'public-read'),
array('success_action_redirect' => $redirect),
array("starts-with", "\$Content-Type", "image/"),
array("x-amz-credential" => $credential),
array("x-amz-algorithm"=> "AWS4-HMAC-SHA256"),
array("x-amz-date" => $x_date),
);

$policy_b64 = $this->aws->getPolicy(3600 * 24, $conditions);
$signature = hash_hmac('sha256', $policy_b64, AWS_SECRET_KEY);
?>

<form action="http://ift.tt/1Kc7vIi" method="post" enctype="multipart/form-data">
<input type="input" name="key" value="test/${filename}"/><br/>
<input type="hidden" name="acl" value="public-read"/>
<input type="hidden" name="success_action_redirect" value="<?= $redirect; ?>"/>
<input type="input" name="Content-Type" value="image/jpeg"/><br/>
<input type="text" name="X-Amz-Credential" value="<?= $credential; ?>"/>
<input type="text" name="X-Amz-Algorithm" value="AWS4-HMAC-SHA256"/>
<input type="text" name="X-Amz-Date" value="<?= $x_date; ?>"/>
<input type="hidden" name="Policy" value="<?= $policy_b64; ?>" />
<input type="hidden" name="X-Amz-Signature" value="<?= $signature; ?>"/>

<input type="file" name="file"/> <br/>

<input type="submit" name="submit" value="Upload to Amazon S3"/>
</form>






Aucun commentaire:

Enregistrer un commentaire