I am wondering if anyone has successfully generated an EC2 v2 signature for there API using php. All examples/libraries I can find online are for v1 of the signature and that has been deprecated due to insecurities. An existing library that implements the signature generation would be appreciated too.
A:
Here's a PHP Library that supports V2. I haven't tried it though.
Ólafur Waage
2009-04-08 00:04:56
A:
Here's some code I've written and have been using:
define("AWSKEY", "Your AWS Key");
define("AWSSECRET", "Your AWS Secret");
public function get($parameters, $host) {
// Build out the variables
$domain = "https://$host/";
$parameters['AWSAccessKeyId'] = AWSKEY;
$parameters['Timestamp'] = date('c');
$parameters['Version'] = '2007-11-07';
$parameters['SignatureMethod'] = 'HmacSHA256';
$parameters['SignatureVersion'] = 2;
// Write the signature
$signature = "GET\n";
$signature .= "$host\n";
$signature .= "/\n";
$sigparams = $parameters;
ksort($sigparams);
$first = true;
foreach($sigparams as $key=>$param) {
$signature .= (!$first ? '&' : '') . rawurlencode($key) . '=' . rawurlencode($param);
$first = false;
}
$signature = hash_hmac('sha256', $signature, $AWSKEY, true);
$signature = base64_encode($signature);
$parameters['Signature'] = $signature;
$url = $domain . '?';
$first = true;
foreach($parameters as $key=>$param) {
$url .= (!$first ? '&' : '') . rawurlencode($key) . '=' . rawurlencode($param);
$first = false;
}
$ch = curl_init(trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
return $output;
}
Here's how you'd use it:
$params = array(
'Action' => 'ListDomains'
);
$db->get($params, 'sdb.amazonaws.com');
This would perform a ListDomains
query on SimpleDB. The function itself will return Amazon's output. For more complicated commands, (i.e.: PUT, POST, etc.) there aren't any major modifications that need to be made.
mattbasta
2009-11-25 00:25:09
A:
http://mierendo.com/software/aws%5Fsigned%5Fquery/
I believe that's V2
Frank Farmer
2009-11-25 00:34:04