Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
amazonwebservices committed Mar 25, 2011
1 parent 406dd51 commit 1a7232c
Show file tree
Hide file tree
Showing 24 changed files with 577 additions and 55 deletions.
2 changes: 1 addition & 1 deletion _compatibility_test/sdk_compatibility_test.php
Expand Up @@ -53,7 +53,7 @@

<style type="text/css">
body {
font:14px/1.4em "Helvetica Neue", Helvetica, "Lucida Grande", Verdana, Arial, Clean, Sans, sans-serif;
font:14px/1.4em "Helvetica Neue", Helvetica, "Lucida Grande", "Droid Sans", Ubuntu, Verdana, Arial, Clean, Sans, sans-serif;
letter-spacing:0px;
color:#333;
margin:0;
Expand Down
30 changes: 30 additions & 0 deletions _docs/CHANGELOG.md
@@ -1,3 +1,33 @@
# Changelog: 1.3.1 "Kraken"

Launched Friday, March 25, 2011

## New Features & Highlights (Summary)
* Fixed issues with Signature v3 authentication (SES).
* Added gzip decoding.
* Added support for converting data to more alternate formats.
* Bug fixes and enhancements:
* [Cannot send email](https://forums.aws.amazon.com/thread.jspa?threadID=62833)
* [AmazonCloudWatch get_metric_statistics returns gzipped body](https://forums.aws.amazon.com/thread.jspa?threadID=62625)

## Utility Classes
### CFArray
* **New:** The `to_json()` and `to_yaml()` methoda have been added to the class.

### CFGzipDecode
* **New:** Handles a variety of primary and edge cases around gzip/deflate decoding in PHP.

### CFRuntime
* **New:** Gzip decoding has been added to the SDK.
* **Fixed:** The previous release contained a regression in the Signature v3 support that affected AmazonSES. This has been resolved.
* **Fixed:** Completed support for Signature v3 over HTTP connections.

### CFSimpleXML
* **New:** The `to_stdClass()` and `to_yaml()` methoda have been added to the class.


----

# Changelog: 1.3 "Jecht"

Launched Tuesday, March 15, 2011
Expand Down
4 changes: 2 additions & 2 deletions _docs/NOTICE.md
Expand Up @@ -129,13 +129,13 @@ POSSIBILITY OF SUCH DAMAGE.
<http://opensource.org/licenses/bsd-license.php>


## SimplePie Compatibility Test
## SimplePie

<http://simplepie.org>

* Copyright 2004-2010 [Ryan Parman](http://ryanparman.com)
* Copyright 2005-2010 [Geoffrey Sneddon](http://gsnedders.com)
* Copyright 2008-2010 [Ryan McCue](http://ryanmccue.info)
* Copyright 2008-2011 [Ryan McCue](http://ryanmccue.info)

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
106 changes: 73 additions & 33 deletions sdk.class.php
Expand Up @@ -102,9 +102,9 @@ function __aws_sdk_ua_callback()
// INTERMEDIARY CONSTANTS

define('CFRUNTIME_NAME', 'aws-sdk-php');
define('CFRUNTIME_VERSION', '1.3');
define('CFRUNTIME_VERSION', '1.3.1');
// define('CFRUNTIME_BUILD', gmdate('YmdHis', filemtime(__FILE__))); // @todo: Hardcode for release.
define('CFRUNTIME_BUILD', '20110315164556');
define('CFRUNTIME_BUILD', '20110325210828');
define('CFRUNTIME_USERAGENT', CFRUNTIME_NAME . '/' . CFRUNTIME_VERSION . ' PHP/' . PHP_VERSION . ' ' . php_uname('s') . '/' . php_uname('r') . ' Arch/' . php_uname('m') . ' SAPI/' . php_sapi_name() . ' Integer/' . PHP_INT_MAX . ' Build/' . CFRUNTIME_BUILD . __aws_sdk_ua_callback());


Expand All @@ -115,7 +115,7 @@ function __aws_sdk_ua_callback()
* Core functionality and default settings shared across all SDK classes. All methods and properties in this
* class are inherited by the service-specific classes.
*
* @version 2011.03.14
* @version 2011.03.25
* @license See the included NOTICE.md file for more information.
* @copyright See the included NOTICE.md file for more information.
* @link http://aws.amazon.com/php/ PHP Developer Center
Expand Down Expand Up @@ -750,6 +750,7 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve

$method_arguments = func_get_args();
$headers = array();
$signed_headers = array();

// Use the caching flow to determine if we need to do a round-trip to the server.
if ($this->use_cache_flow)
Expand Down Expand Up @@ -788,8 +789,8 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve

// Determine signing values
$current_time = time() + $this->adjust_offset;
$date = gmdate($this->util->konst($this->util, 'DATE_FORMAT_RFC2616'), $current_time);
$timestamp = gmdate($this->util->konst($this->util, 'DATE_FORMAT_ISO8601'), $current_time);
$date = gmdate(CFUtilities::DATE_FORMAT_RFC2616, $current_time);
$timestamp = gmdate(CFUtilities::DATE_FORMAT_ISO8601, $current_time);
$nonce = $this->util->generate_guid();

// Manage the key-value pairs that are used in the query.
Expand Down Expand Up @@ -825,9 +826,9 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
uksort($query, 'strcmp');

// Normalize JSON input
if ($query['body'] === '[]')
if (isset($query['body']) && $query['body'] === '[]')
{
$query['body'] = '';
$query['body'] = '{}';
}

if ($this->use_aws_query)
Expand Down Expand Up @@ -892,7 +893,7 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
// Do we have an authentication token?
if ($this->auth_token)
{
$headers['x-amz-security-token'] = $this->auth_token;
$headers['X-Amz-Security-Token'] = $this->auth_token;
}

// Signing using X-Amz-Target is handled differently.
Expand Down Expand Up @@ -920,10 +921,11 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
// Add authentication headers
if ($signature_version === 3)
{
$headers['X-Amz-Nonce'] = $nonce;
$headers['Date'] = $date;
$headers['Content-Length'] = strlen($querystring);
$headers['Content-MD5'] = $this->util->hex_to_base64(md5($querystring));
$headers['x-amz-nonce'] = $nonce;
$headers['Host'] = $host_header;
}

// Sort headers
Expand All @@ -934,10 +936,10 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
// Prepare the string to sign (HTTPS)
$string_to_sign = $date . $nonce;
}
elseif ($signature_version === 3)
elseif ($signature_version === 3 && !$this->use_ssl)
{
// Prepare the string to sign (HTTP)
$string_to_sign = "POST\n$host_header\n$request_uri\n$canonical_query_string";
$string_to_sign = "POST\n$request_uri\n\n";
}

// Add headers to request and compute the string to sign
Expand All @@ -959,32 +961,47 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
if (
substr(strtolower($header_key), 0, 8) === 'content-' ||
strtolower($header_key) === 'date' ||
strtolower($header_key) === 'expires'
strtolower($header_key) === 'expires' ||
strtolower($header_key) === 'host' ||
substr(strtolower($header_key), 0, 6) === 'x-amz-'
)
{
$string_to_sign .= strtolower($header_key) . ':' . $header_value . "\n";
}
elseif (substr(strtolower($header_key), 0, 6) === 'x-amz-')
{
$string_to_sign .= strtolower($header_key) . ':' . $header_value . "\n";
$signed_headers[] = $header_key;
}
}
}

if ($signature_version === 3)
{
if ($this->use_ssl)
if (!$this->use_ssl)
{
$string_to_sign .= "\n";

if (isset($query['body']) && $query['body'] !== '')
{
$string_to_sign .= $query['body'];
}

// Convert from string-to-sign to bytes-to-sign
$bytes_to_sign = hash('sha256', $string_to_sign, true);

// Hash the AWS secret key and generate a signature for the request.
$signature = base64_encode(hash_hmac('sha256', $string_to_sign, $this->secret_key, true));
$request->add_header('X-Amzn-Authorization', 'AWS3-HTTPS AWSAccessKeyId=' . $this->key . ',Algorithm=HmacSHA256,Signature=' . $signature);
$signature = base64_encode(hash_hmac('sha256', $bytes_to_sign, $this->secret_key, true));
}
else
{
// Hash the AWS secret key and generate a signature for the request.
$signature = base64_encode(hash_hmac('sha256', $string_to_sign, $this->secret_key, true));
$request->add_header('X-Amzn-Authorization', 'AWS3 AWSAccessKeyId=' . $this->key . ',Algorithm=HmacSHA256,Signature=' . $signature);
}

$headers['X-Amzn-Authorization'] = 'AWS3' . ($this->use_ssl ? '-HTTPS' : '')
. ' AWSAccessKeyId=' . $this->key
. ',Algorithm=HmacSHA256'
. ',SignedHeaders=' . implode(';', $signed_headers)
. ',Signature=' . $signature;

$request->add_header('X-Amzn-Authorization', $headers['X-Amzn-Authorization']);
}

// Update RequestCore settings
Expand All @@ -994,7 +1011,7 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
$curlopts = array();

// Set custom CURLOPT settings
if (isset($opt['curlopts']))
if (is_array($opt) && isset($opt['curlopts']))
{
$curlopts = $opt['curlopts'];
unset($opt['curlopts']);
Expand Down Expand Up @@ -1028,13 +1045,15 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
// Send!
$request->send_request();

$request_headers = $headers;

// Prepare the response.
$headers = $request->get_response_header();
$headers['x-aws-stringtosign'] = $string_to_sign;
$headers['x-aws-request-headers'] = $request_headers;
$headers['x-aws-body'] = $querystring;

$mime = isset($headers['content-type']) ? $headers['content-type'] : null;
$data = new $this->response_class($headers, $this->parse_callback($request->get_response_body(), $mime), $request->get_response_code());
$data = new $this->response_class($headers, $this->parse_callback($request->get_response_body(), $headers), $request->get_response_code());

// Was it Amazon's fault the request failed? Retry the request until we reach $max_retries.
if ((integer) $request->get_response_code() === 500 || (integer) $request->get_response_code() === 503)
Expand Down Expand Up @@ -1153,19 +1172,14 @@ public function send($clear_after_send = true)
* @param string $content_type (Optional) The content-type to use when determining how to parse the content.
* @return CFResponse|string A parsed <CFResponse> object, or parsed XML.
*/
public function parse_callback($response, $content_type = null)
public function parse_callback($response, $headers = null)
{
// Shorten this so we have a (mostly) single code path
if (isset($response->body))
{
if (is_string($response->body))
{
$body = $response->body;

if (!$content_type)
{
$content_type = $response->header['content-type'];
}
}
else
{
Expand All @@ -1181,10 +1195,36 @@ public function parse_callback($response, $content_type = null)
return $response;
}

// Decompress gzipped content
if (isset($headers['content-encoding']))
{
switch (strtolower(trim($headers['content-encoding'], "\x09\x0A\x0D\x20")))
{
case 'gzip':
case 'x-gzip':
$decoder = new CFGzipDecode($body);
if ($decoder->parse())
{
$body = $decoder->data;
}
break;

case 'deflate':
if (($body = gzuncompress($body)) === false)
{
if (($body = gzinflate($body)) === false)
{
continue;
}
}
break;
}
}

// Look for XML cues
if (
($content_type && ($content_type === 'text/xml' || $content_type === 'application/xml')) || // We know it's XML
(!$content_type && (stripos($body, '<?xml') === 0 || strpos($body, '<Error>') === 0) || preg_match('/^<(\w*) xmlns="http(s?):\/\/(\w*).amazon(aws)?.com/im', $body)) // Sniff for XML
(isset($headers['content-type']) && ($headers['content-type'] === 'text/xml' || $headers['content-type'] === 'application/xml')) || // We know it's XML
(!isset($headers['content-type']) && (stripos($body, '<?xml') === 0 || strpos($body, '<Error>') === 0) || preg_match('/^<(\w*) xmlns="http(s?):\/\/(\w*).amazon(aws)?.com/im', $body)) // Sniff for XML
)
{
// Strip the default XML namespace to simplify XPath expressions
Expand All @@ -1195,8 +1235,8 @@ public function parse_callback($response, $content_type = null)
}
// Look for JSON cues
elseif (
($content_type && $content_type === 'application/json') || // We know it's JSON
(!$content_type && $this->util->is_json($body)) // Sniff for JSON
(isset($headers['content-type']) && $headers['content-type'] === 'application/json') || // We know it's JSON
(!isset($headers['content-type']) && $this->util->is_json($body)) // Sniff for JSON
)
{
// Normalize JSON to a CFSimpleXML object
Expand Down
2 changes: 1 addition & 1 deletion services/as.class.php
Expand Up @@ -47,7 +47,7 @@
*
* </ul>
*
* @version Tue Mar 15 11:06:05 PDT 2011
* @version Fri Mar 25 13:12:03 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/autoscaling/Amazon Auto-Scaling
Expand Down
2 changes: 1 addition & 1 deletion services/cloudformation.class.php
Expand Up @@ -33,7 +33,7 @@
* Amazon CloudFormation makes use of other AWS products. If you need additional technical information about a specific AWS
* product, you can find the product's technical documentation at http://aws.amazon.com/documentation/.
*
* @version Tue Mar 15 11:07:12 PDT 2011
* @version Fri Mar 25 13:12:48 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/cloudformation/Amazon CloudFormation
Expand Down
2 changes: 1 addition & 1 deletion services/cloudwatch.class.php
Expand Up @@ -31,7 +31,7 @@
* automatically make changes to the resources you are monitoring, based on rules that you define. For example, you can
* create alarms that initiate Auto Scaling and Simple Notification Service actions on your behalf.
*
* @version Tue Mar 15 11:08:01 PDT 2011
* @version Fri Mar 25 13:13:27 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/cloudwatch/Amazon CloudWatch
Expand Down
2 changes: 1 addition & 1 deletion services/ec2.class.php
Expand Up @@ -28,7 +28,7 @@
*
* Visit <a href="http://aws.amazon.com/ec2/">http://aws.amazon.com/ec2/</a> for more information.
*
* @version Tue Mar 15 11:09:51 PDT 2011
* @version Fri Mar 25 13:14:50 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/ec2/Amazon Elastic Compute Cloud
Expand Down
2 changes: 1 addition & 1 deletion services/elasticbeanstalk.class.php
Expand Up @@ -36,7 +36,7 @@
*
* </ul>
*
* @version Tue Mar 15 11:08:52 PDT 2011
* @version Fri Mar 25 13:14:04 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/elasticbeanstalk/AWS Elastic Beanstalk
Expand Down
2 changes: 1 addition & 1 deletion services/elb.class.php
Expand Up @@ -20,7 +20,7 @@
* of your application. It makes it easy for you to distribute application loads between two or more EC2 instances. Elastic
* Load Balancing enables availability through redundancy and supports traffic growth of your application.
*
* @version Tue Mar 15 11:11:03 PDT 2011
* @version Fri Mar 25 13:15:34 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/elasticloadbalancing/Amazon Elastic Load Balancing
Expand Down
2 changes: 1 addition & 1 deletion services/emr.class.php
Expand Up @@ -19,7 +19,7 @@
* This is the Amazon Elastic MapReduce API Reference Guide. This guide is for programmers who need detailed information
* about the Amazon Elastic MapReduce APIs.
*
* @version Tue Mar 15 11:12:53 PDT 2011
* @version Fri Mar 25 13:16:39 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/elasticmapreduce/Amazon Elastic MapReduce
Expand Down
2 changes: 1 addition & 1 deletion services/iam.class.php
Expand Up @@ -35,7 +35,7 @@
* We will refer to Amazon AWS Identity and Access Management using the abbreviated form IAM. All copyrights and legal
* protections still apply.
*
* @version Tue Mar 15 11:13:44 PDT 2011
* @version Fri Mar 25 13:17:16 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/iam/Amazon Identity and Access Management Service
Expand Down
2 changes: 1 addition & 1 deletion services/importexport.class.php
Expand Up @@ -22,7 +22,7 @@
* high-speed internal network and bypassing the Internet. For large data sets, AWS Import/Export is often faster than
* Internet transfer and more cost effective than upgrading your connectivity.
*
* @version Tue Mar 15 11:14:38 PDT 2011
* @version Fri Mar 25 13:17:53 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/importexport/Amazon Import/Export Service
Expand Down
2 changes: 1 addition & 1 deletion services/rds.class.php
Expand Up @@ -28,7 +28,7 @@
* flexible: you can scale your database instance's compute resources and storage capacity to meet your application's
* demand. As with all Amazon Web Services, there are no up-front investments, and you pay only for the resources you use.
*
* @version Tue Mar 15 11:15:28 PDT 2011
* @version Fri Mar 25 13:18:27 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/rds/Amazon Relational Database Service
Expand Down

0 comments on commit 1a7232c

Please sign in to comment.